From 58ce721674ab0a5b2b48b914f1d7c841633a0709 Mon Sep 17 00:00:00 2001 From: paulGao Date: Wed, 3 Nov 2021 15:25:28 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E5=A2=9E=E5=8A=A0es=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/search/serviceimpl/EsGoodsIndexServiceImpl.java | 4 +++- .../cn/lili/controller/other/ElasticsearchController.java | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/framework/src/main/java/cn/lili/modules/search/serviceimpl/EsGoodsIndexServiceImpl.java b/framework/src/main/java/cn/lili/modules/search/serviceimpl/EsGoodsIndexServiceImpl.java index 65b3254a..3f8fdfd0 100644 --- a/framework/src/main/java/cn/lili/modules/search/serviceimpl/EsGoodsIndexServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/search/serviceimpl/EsGoodsIndexServiceImpl.java @@ -542,8 +542,10 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements goodsWords.setSort(0); goodsWordsService.save(goodsWords); } - } catch (MyBatisSystemException e) { + } catch (MyBatisSystemException me) { log.error(words + "关键字已存在!"); + } catch (Exception e) { + log.error("关键字入库异常!", e); } } diff --git a/manager-api/src/main/java/cn/lili/controller/other/ElasticsearchController.java b/manager-api/src/main/java/cn/lili/controller/other/ElasticsearchController.java index 4770c933..a4cac7dc 100644 --- a/manager-api/src/main/java/cn/lili/controller/other/ElasticsearchController.java +++ b/manager-api/src/main/java/cn/lili/controller/other/ElasticsearchController.java @@ -26,6 +26,7 @@ import cn.lili.modules.store.entity.dos.StoreGoodsLabel; import cn.lili.modules.store.service.StoreGoodsLabelService; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import io.swagger.annotations.Api; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.web.bind.annotation.GetMapping; @@ -47,6 +48,7 @@ import java.util.Map; @RestController @Api(tags = "ES初始化接口") @RequestMapping("/manager/elasticsearch") +@Slf4j public class ElasticsearchController { @Autowired @@ -133,6 +135,7 @@ public class ElasticsearchController { } catch (Exception e) { cache.put(CachePrefix.INIT_INDEX_PROCESS.getPrefix(), null); cache.put(CachePrefix.INIT_INDEX_FLAG.getPrefix(), false); + log.error("初始化索引异常", e); } }); return ResultUtil.success(); From 10c3e90f54ccfcdf44450b2e75cb105c799adea4 Mon Sep 17 00:00:00 2001 From: paulGao Date: Thu, 4 Nov 2021 14:38:26 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E6=9B=B4=E6=94=B9mongo=E8=BF=9E=E6=8E=A5?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E5=8F=82=E6=95=B0=E4=B8=BA=E5=8F=AF=E9=9B=86?= =?UTF-8?q?=E7=BE=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- buyer-api/src/main/resources/application.yml | 3 +-- common-api/src/main/resources/application.yml | 3 +-- config/application.yml | 3 +-- consumer/src/main/resources/application.yml | 3 +-- .../lili/cache/config/mongo/MongoConfig.java | 19 ++++++++++++------- .../src/main/resources/application.yml | 3 +-- seller-api/src/main/resources/application.yml | 3 +-- 7 files changed, 18 insertions(+), 19 deletions(-) diff --git a/buyer-api/src/main/resources/application.yml b/buyer-api/src/main/resources/application.yml index 9ed3cc2a..2a84e6be 100644 --- a/buyer-api/src/main/resources/application.yml +++ b/buyer-api/src/main/resources/application.yml @@ -46,8 +46,7 @@ spring: # mongodb data: mongodb: - host: 127.0.0.1 - port: 27017 + uri: 127.0.0.1:27017 database: lilishop username: root password: lilishop diff --git a/common-api/src/main/resources/application.yml b/common-api/src/main/resources/application.yml index fb53aa1c..04869a91 100644 --- a/common-api/src/main/resources/application.yml +++ b/common-api/src/main/resources/application.yml @@ -32,8 +32,7 @@ spring: # mongodb data: mongodb: - host: 127.0.0.1 - port: 27017 + uri: 127.0.0.1:27017 database: lilishop username: root password: lilishop diff --git a/config/application.yml b/config/application.yml index c729b183..796fb0ee 100644 --- a/config/application.yml +++ b/config/application.yml @@ -28,8 +28,7 @@ spring: # mongodb data: mongodb: - host: 192.168.0.116 - port: 27017 + uri: 192.168.0.116:27017 database: lilishop username: root password: lilishop diff --git a/consumer/src/main/resources/application.yml b/consumer/src/main/resources/application.yml index 65dffa3c..5359452a 100644 --- a/consumer/src/main/resources/application.yml +++ b/consumer/src/main/resources/application.yml @@ -35,8 +35,7 @@ spring: # mongodb data: mongodb: - host: 127.0.0.1 - port: 27017 + uri: 127.0.0.1:27017 database: lilishop username: root password: lilishop diff --git a/framework/src/main/java/cn/lili/cache/config/mongo/MongoConfig.java b/framework/src/main/java/cn/lili/cache/config/mongo/MongoConfig.java index 9fee65e3..1420ec23 100644 --- a/framework/src/main/java/cn/lili/cache/config/mongo/MongoConfig.java +++ b/framework/src/main/java/cn/lili/cache/config/mongo/MongoConfig.java @@ -8,7 +8,8 @@ import org.springframework.context.annotation.Configuration; import org.springframework.data.mongodb.config.AbstractMongoClientConfiguration; import org.springframework.data.mongodb.repository.config.EnableMongoRepositories; -import java.util.Collections; +import java.util.ArrayList; +import java.util.List; /** * @author paulG @@ -21,11 +22,8 @@ public class MongoConfig extends AbstractMongoClientConfiguration { @Value("${spring.data.mongodb.database}") private String databaseName; - @Value("${spring.data.mongodb.host}") - private String host; - - @Value("${spring.data.mongodb.port}") - private Integer port; + @Value("${spring.data.mongodb.uri}") + private List uri = new ArrayList<>(); @Value("${spring.data.mongodb.username}") private String username; @@ -44,7 +42,14 @@ public class MongoConfig extends AbstractMongoClientConfiguration { @Override protected void configureClientSettings(MongoClientSettings.Builder builder) { builder.credential(MongoCredential.createCredential(username, authenticationDatabase, password.toCharArray())) - .applyToClusterSettings(settings -> settings.hosts(Collections.singletonList(new ServerAddress(host, port)))); + .applyToClusterSettings(settings -> { + List serverAddresses = new ArrayList<>(); + for (String s : uri) { + String[] node = s.split(":"); + serverAddresses.add(new ServerAddress(node[0], Integer.parseInt(node[1]))); + } + settings.hosts(serverAddresses); + }); } } diff --git a/manager-api/src/main/resources/application.yml b/manager-api/src/main/resources/application.yml index 08e14ecd..0050ed5f 100644 --- a/manager-api/src/main/resources/application.yml +++ b/manager-api/src/main/resources/application.yml @@ -32,8 +32,7 @@ spring: # mongodb data: mongodb: - host: 127.0.0.1 - port: 27017 + uri: 127.0.0.1:27017 database: lilishop username: root password: lilishop diff --git a/seller-api/src/main/resources/application.yml b/seller-api/src/main/resources/application.yml index 95886ca4..5c233ca7 100644 --- a/seller-api/src/main/resources/application.yml +++ b/seller-api/src/main/resources/application.yml @@ -32,8 +32,7 @@ spring: # mongodb data: mongodb: - host: 127.0.0.1 - port: 27017 + uri: 127.0.0.1:27017 database: lilishop username: root password: lilishop From c5f5128b1bfbe1f574a559a63cd0d3cc7434bcf6 Mon Sep 17 00:00:00 2001 From: paulGao Date: Thu, 4 Nov 2021 14:39:59 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E4=BC=98=E5=8C=96LOGBACK=E6=96=87=E4=BB=B6?= =?UTF-8?q?=EF=BC=8Clogstash=E5=8F=82=E6=95=B0=E8=AF=BB=E5=8F=96spring?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin/src/main/resources/logback-spring.xml | 3 ++- buyer-api/src/main/resources/logback-spring.xml | 3 ++- common-api/src/main/resources/logback-spring.xml | 3 ++- consumer/src/main/resources/logback-spring.xml | 3 ++- manager-api/src/main/resources/logback-spring.xml | 3 ++- seller-api/src/main/resources/logback-spring.xml | 3 ++- 6 files changed, 12 insertions(+), 6 deletions(-) diff --git a/admin/src/main/resources/logback-spring.xml b/admin/src/main/resources/logback-spring.xml index 8e2f8cac..a8d0eba6 100644 --- a/admin/src/main/resources/logback-spring.xml +++ b/admin/src/main/resources/logback-spring.xml @@ -7,6 +7,7 @@ + ${APP_NAME} @@ -22,7 +23,7 @@ - 127.0.0.1:4560 + ${LOGSTASH_SERVER} diff --git a/buyer-api/src/main/resources/logback-spring.xml b/buyer-api/src/main/resources/logback-spring.xml index 8e2f8cac..a8d0eba6 100644 --- a/buyer-api/src/main/resources/logback-spring.xml +++ b/buyer-api/src/main/resources/logback-spring.xml @@ -7,6 +7,7 @@ + ${APP_NAME} @@ -22,7 +23,7 @@ - 127.0.0.1:4560 + ${LOGSTASH_SERVER} diff --git a/common-api/src/main/resources/logback-spring.xml b/common-api/src/main/resources/logback-spring.xml index 8e2f8cac..a8d0eba6 100644 --- a/common-api/src/main/resources/logback-spring.xml +++ b/common-api/src/main/resources/logback-spring.xml @@ -7,6 +7,7 @@ + ${APP_NAME} @@ -22,7 +23,7 @@ - 127.0.0.1:4560 + ${LOGSTASH_SERVER} diff --git a/consumer/src/main/resources/logback-spring.xml b/consumer/src/main/resources/logback-spring.xml index 8e2f8cac..a8d0eba6 100644 --- a/consumer/src/main/resources/logback-spring.xml +++ b/consumer/src/main/resources/logback-spring.xml @@ -7,6 +7,7 @@ + ${APP_NAME} @@ -22,7 +23,7 @@ - 127.0.0.1:4560 + ${LOGSTASH_SERVER} diff --git a/manager-api/src/main/resources/logback-spring.xml b/manager-api/src/main/resources/logback-spring.xml index 8e2f8cac..a8d0eba6 100644 --- a/manager-api/src/main/resources/logback-spring.xml +++ b/manager-api/src/main/resources/logback-spring.xml @@ -7,6 +7,7 @@ + ${APP_NAME} @@ -22,7 +23,7 @@ - 127.0.0.1:4560 + ${LOGSTASH_SERVER} diff --git a/seller-api/src/main/resources/logback-spring.xml b/seller-api/src/main/resources/logback-spring.xml index 8e2f8cac..a8d0eba6 100644 --- a/seller-api/src/main/resources/logback-spring.xml +++ b/seller-api/src/main/resources/logback-spring.xml @@ -7,6 +7,7 @@ + ${APP_NAME} @@ -22,7 +23,7 @@ - 127.0.0.1:4560 + ${LOGSTASH_SERVER} From 8ddd39d6e574f36e4814d1773a8cb698f5270101 Mon Sep 17 00:00:00 2001 From: paulGao Date: Thu, 4 Nov 2021 14:41:01 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E4=BC=98=E5=8C=96xss=E8=BF=87=E6=BB=A4?= =?UTF-8?q?=EF=BC=8C=E5=A2=9E=E5=8A=A0=E5=BF=BD=E7=95=A5xss=E8=BF=87?= =?UTF-8?q?=E6=BB=A4=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../filter/XssHttpServletRequestWrapper.java | 39 ++++++++++++------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/framework/src/main/java/cn/lili/common/security/filter/XssHttpServletRequestWrapper.java b/framework/src/main/java/cn/lili/common/security/filter/XssHttpServletRequestWrapper.java index 2ef2100b..4973d0c0 100644 --- a/framework/src/main/java/cn/lili/common/security/filter/XssHttpServletRequestWrapper.java +++ b/framework/src/main/java/cn/lili/common/security/filter/XssHttpServletRequestWrapper.java @@ -16,6 +16,7 @@ import java.io.InputStreamReader; import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.LinkedHashMap; +import java.util.Locale; import java.util.Map; /** @@ -39,7 +40,10 @@ public class XssHttpServletRequestWrapper extends HttpServletRequestWrapper { public String[] getParameterValues(String name) { String[] values = super.getParameterValues(name); if (values == null) { - return null; + return new String[0]; + } + if (ignoreXss(name)) { + return values; } int count = values.length; String[] encodedValues = new String[count]; @@ -58,7 +62,7 @@ public class XssHttpServletRequestWrapper extends HttpServletRequestWrapper { if (value == null) { return null; } - return cleanXSS(value); + return ignoreXss(name) ? value : cleanXSS(value); } /** @@ -67,6 +71,9 @@ public class XssHttpServletRequestWrapper extends HttpServletRequestWrapper { @Override public Object getAttribute(String name) { Object value = super.getAttribute(name); + if (ignoreXss(name)) { + return value; + } if (value instanceof String) { value = cleanXSS((String) value); } @@ -82,7 +89,7 @@ public class XssHttpServletRequestWrapper extends HttpServletRequestWrapper { if (value == null) { return null; } - return cleanXSS(value); + return ignoreXss(name) ? value : cleanXSS(value); } @Override @@ -96,12 +103,14 @@ public class XssHttpServletRequestWrapper extends HttpServletRequestWrapper { for (Map.Entry entry : parameterMap.entrySet()) { //根据key获取value String[] values = entry.getValue(); - //遍历数组 - for (int i = 0; i < values.length; i++) { - String value = values[i]; - value = cleanXSS(value); - //将转义后的数据放回数组中 - values[i] = value; + if (!ignoreXss(entry.getKey())) { + //遍历数组 + for (int i = 0; i < values.length; i++) { + String value = values[i]; + value = cleanXSS(value); + //将转义后的数据放回数组中 + values[i] = value; + } } //将转义后的数组put到linkMap当中 params.put(entry.getKey(), values); @@ -113,8 +122,8 @@ public class XssHttpServletRequestWrapper extends HttpServletRequestWrapper { /** * 获取输入流 * - * @return - * @throws IOException + * @return 过滤后的输入流 + * @throws IOException 异常信息 */ @Override public ServletInputStream getInputStream() throws IOException { @@ -145,7 +154,7 @@ public class XssHttpServletRequestWrapper extends HttpServletRequestWrapper { //遍历数组 for (Map.Entry entry : map.entrySet()) { //如果map.get(key)获取到的是字符串就需要进行转义,如果不是直接存储resultMap - if (map.get(entry.getKey()) instanceof String) { + if (map.get(entry.getKey()) instanceof String && !ignoreXss(entry.getKey())) { resultMap.put(entry.getKey(), cleanXSS(entry.getValue().toString())); } else { resultMap.put(entry.getKey(), entry.getValue()); @@ -171,7 +180,6 @@ public class XssHttpServletRequestWrapper extends HttpServletRequestWrapper { @Override public void setReadListener(ReadListener readListener) { - } @Override @@ -215,4 +223,9 @@ public class XssHttpServletRequestWrapper extends HttpServletRequestWrapper { } return value; } + + private boolean ignoreXss(String name) { + return CharSequenceUtil.containsAny(name.toLowerCase(Locale.ROOT), "logo", "url", "photo", "intro"); + } + } From a44f06b3e8b2ca82e89a570ff7f14e5dbceb60b4 Mon Sep 17 00:00:00 2001 From: paulGao Date: Thu, 4 Nov 2021 14:42:12 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E7=AB=AF=E7=99=BB=E5=BD=95=EF=BC=8C=E6=9D=83=E9=99=90=E8=8F=9C?= =?UTF-8?q?=E5=8D=95=E8=AF=BB=E5=8F=96=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/cn/lili/cache/CachePrefix.java | 10 +++- .../sensitive/SensitiveJsonSerializer.java | 12 +--- .../permission/service/MenuService.java | 10 +++- .../serviceimpl/MenuServiceImpl.java | 59 ++++++++++++------- .../serviceimpl/RoleMenuServiceImpl.java | 29 +++++++-- .../permission/MenuManagerController.java | 8 +-- 6 files changed, 88 insertions(+), 40 deletions(-) diff --git a/framework/src/main/java/cn/lili/cache/CachePrefix.java b/framework/src/main/java/cn/lili/cache/CachePrefix.java index 24b5daeb..8b3bab3f 100644 --- a/framework/src/main/java/cn/lili/cache/CachePrefix.java +++ b/framework/src/main/java/cn/lili/cache/CachePrefix.java @@ -1,7 +1,7 @@ package cn.lili.cache; -import cn.lili.common.security.enums.UserEnums; import cn.lili.common.enums.PromotionTypeEnum; +import cn.lili.common.security.enums.UserEnums; /** * 缓存前缀 @@ -469,6 +469,14 @@ public enum CachePrefix { * 店铺分类 */ STORE_CATEGORY, + /** + * 用户菜单 + */ + MENU_USER_ID, + /** + * 用户菜单 + */ + USER_MENU, /** * 订单暂时缓存 */ diff --git a/framework/src/main/java/cn/lili/common/security/sensitive/SensitiveJsonSerializer.java b/framework/src/main/java/cn/lili/common/security/sensitive/SensitiveJsonSerializer.java index 7fba151f..506e8c41 100644 --- a/framework/src/main/java/cn/lili/common/security/sensitive/SensitiveJsonSerializer.java +++ b/framework/src/main/java/cn/lili/common/security/sensitive/SensitiveJsonSerializer.java @@ -78,22 +78,14 @@ public class SensitiveJsonSerializer extends JsonSerializer //如果是店铺 if (authUser.getRole().equals(UserEnums.STORE)) { //店铺需要进行脱敏,则脱敏处理 - if (systemSettingProperties.getSensitiveLevel() == 2) { - return true; - } - //默认不需要 - return false; + return systemSettingProperties.getSensitiveLevel() == 2; } //如果是店铺 if (authUser.getRole().equals(UserEnums.MANAGER)) { //店铺需要进行脱敏,则脱敏处理 - if (systemSettingProperties.getSensitiveLevel() >= 1) { - return true; - } - //默认不需要 - return false; + return systemSettingProperties.getSensitiveLevel() >= 1; } return false; diff --git a/framework/src/main/java/cn/lili/modules/permission/service/MenuService.java b/framework/src/main/java/cn/lili/modules/permission/service/MenuService.java index ede5b5d0..1d91e510 100644 --- a/framework/src/main/java/cn/lili/modules/permission/service/MenuService.java +++ b/framework/src/main/java/cn/lili/modules/permission/service/MenuService.java @@ -1,7 +1,7 @@ package cn.lili.modules.permission.service; -import cn.lili.modules.permission.entity.dto.MenuSearchParams; import cn.lili.modules.permission.entity.dos.Menu; +import cn.lili.modules.permission.entity.dto.MenuSearchParams; import cn.lili.modules.permission.entity.vo.MenuVO; import com.baomidou.mybatisplus.extension.service.IService; import org.springframework.cache.annotation.CacheConfig; @@ -63,4 +63,12 @@ public interface MenuService extends IService { */ void deleteIds(List ids); + /** + * 添加更新菜单 + * + * @param menu 菜单数据 + * @return 是否成功 + */ + boolean saveOrUpdateMenu(Menu menu); + } diff --git a/framework/src/main/java/cn/lili/modules/permission/serviceimpl/MenuServiceImpl.java b/framework/src/main/java/cn/lili/modules/permission/serviceimpl/MenuServiceImpl.java index 007913a9..ed1fdf59 100644 --- a/framework/src/main/java/cn/lili/modules/permission/serviceimpl/MenuServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/permission/serviceimpl/MenuServiceImpl.java @@ -1,11 +1,12 @@ package cn.lili.modules.permission.serviceimpl; +import cn.hutool.core.text.CharSequenceUtil; +import cn.lili.cache.Cache; +import cn.lili.cache.CachePrefix; import cn.lili.common.enums.ResultCode; import cn.lili.common.exception.ServiceException; import cn.lili.common.security.AuthUser; import cn.lili.common.security.context.UserContext; -import cn.lili.mybatis.util.PageUtil; -import cn.lili.common.utils.StringUtils; import cn.lili.common.vo.SearchVO; import cn.lili.modules.permission.entity.dos.Menu; import cn.lili.modules.permission.entity.dos.RoleMenu; @@ -14,15 +15,14 @@ import cn.lili.modules.permission.entity.vo.MenuVO; import cn.lili.modules.permission.mapper.MenuMapper; import cn.lili.modules.permission.service.MenuService; import cn.lili.modules.permission.service.RoleMenuService; +import cn.lili.mybatis.util.PageUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.List; +import java.util.*; /** * 权限业务层实现 @@ -39,6 +39,9 @@ public class MenuServiceImpl extends ServiceImpl implements Me @Autowired private RoleMenuService roleMenuService; + @Autowired + private Cache> cache; + @Override public void deleteIds(List ids) { QueryWrapper queryWrapper = new QueryWrapper<>(); @@ -53,8 +56,8 @@ public class MenuServiceImpl extends ServiceImpl implements Me @Override public List findUserTree() { - AuthUser authUser = UserContext.getCurrentUser(); - if (authUser.getIsSuper()) { + AuthUser authUser = Objects.requireNonNull(UserContext.getCurrentUser()); + if (Boolean.TRUE.equals(authUser.getIsSuper())) { return this.tree(); } List userMenus = this.baseMapper.findByUserId(authUser.getId()); @@ -63,7 +66,28 @@ public class MenuServiceImpl extends ServiceImpl implements Me @Override public List findUserList(String userId) { - return this.baseMapper.findByUserId(userId); + String cacheKey = CachePrefix.MENU_USER_ID.getPrefix() + userId; + List menuList = cache.get(cacheKey); + if (menuList == null) { + menuList = this.baseMapper.findByUserId(userId); + cache.put(cacheKey, menuList); + } + return menuList; + } + + /** + * 添加更新菜单 + * + * @param menu 菜单数据 + * @return 是否成功 + */ + @Override + public boolean saveOrUpdateMenu(Menu menu) { + if (CharSequenceUtil.isNotEmpty(menu.getId())) { + cache.vagueDel(CachePrefix.MENU_USER_ID.getPrefix()); + cache.vagueDel(CachePrefix.USER_MENU.getPrefix()); + } + return this.saveOrUpdate(menu); } @Override @@ -77,12 +101,12 @@ public class MenuServiceImpl extends ServiceImpl implements Me public List searchList(MenuSearchParams menuSearchParams) { //title 需要特殊处理 String title = null; - if (StringUtils.isNotEmpty(menuSearchParams.getTitle())) { + if (CharSequenceUtil.isNotEmpty(menuSearchParams.getTitle())) { title = menuSearchParams.getTitle(); menuSearchParams.setTitle(null); } - QueryWrapper queryWrapper = PageUtil.initWrapper(menuSearchParams, new SearchVO()); - if (StringUtils.isNotEmpty(title)) { + QueryWrapper queryWrapper = PageUtil.initWrapper(menuSearchParams, new SearchVO()); + if (CharSequenceUtil.isNotEmpty(title)) { queryWrapper.like("title", title); } queryWrapper.orderByDesc("sort_order"); @@ -98,14 +122,14 @@ public class MenuServiceImpl extends ServiceImpl implements Me } catch (Exception e) { log.error("菜单树错误", e); } - return null; + return Collections.emptyList(); } /** * 传入自定义菜单集合 * - * @param menus - * @return + * @param menus 自定义菜单集合 + * @return 修改后的自定义菜单集合 */ private List tree(List menus) { List tree = new ArrayList<>(); @@ -117,12 +141,7 @@ public class MenuServiceImpl extends ServiceImpl implements Me } }); //对一级菜单排序 - tree.sort(new Comparator() { - @Override - public int compare(MenuVO o1, MenuVO o2) { - return o1.getSortOrder().compareTo(o2.getSortOrder()); - } - }); + tree.sort(Comparator.comparing(Menu::getSortOrder)); return tree; } diff --git a/framework/src/main/java/cn/lili/modules/permission/serviceimpl/RoleMenuServiceImpl.java b/framework/src/main/java/cn/lili/modules/permission/serviceimpl/RoleMenuServiceImpl.java index b5d0acaa..5a72298a 100644 --- a/framework/src/main/java/cn/lili/modules/permission/serviceimpl/RoleMenuServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/permission/serviceimpl/RoleMenuServiceImpl.java @@ -1,13 +1,17 @@ package cn.lili.modules.permission.serviceimpl; +import cn.lili.cache.Cache; +import cn.lili.cache.CachePrefix; import cn.lili.modules.permission.entity.dos.RoleMenu; import cn.lili.modules.permission.entity.vo.UserMenuVO; import cn.lili.modules.permission.mapper.MenuMapper; import cn.lili.modules.permission.mapper.RoleMenuMapper; import cn.lili.modules.permission.service.RoleMenuService; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import groovy.util.logging.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -31,16 +35,26 @@ public class RoleMenuServiceImpl extends ServiceImpl i @Resource private MenuMapper menuMapper; + + @Autowired + private Cache cache; + @Override public List findByRoleId(String roleId) { - QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("role_id", roleId); + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(RoleMenu::getRoleId, roleId); return this.baseMapper.selectList(queryWrapper); } @Override public List findAllMenu(String userId) { - return menuMapper.getUserRoleMenu(userId); + String cacheKey = CachePrefix.USER_MENU.getPrefix() + userId; + List menuList = (List) cache.get(cacheKey); + if (menuList == null) { + menuList = menuMapper.getUserRoleMenu(userId); + cache.put(cacheKey, menuList); + } + return menuList; } @@ -51,8 +65,10 @@ public class RoleMenuServiceImpl extends ServiceImpl i this.deleteRoleMenu(roleId); //重新保存角色菜单关系 this.saveBatch(roleMenus); + cache.vagueDel(CachePrefix.MENU_USER_ID.getPrefix()); + cache.vagueDel(CachePrefix.USER_MENU.getPrefix()); } catch (Exception e) { - log.error("修改用户权限错误",e); + log.error("修改用户权限错误", e); } } @@ -62,12 +78,17 @@ public class RoleMenuServiceImpl extends ServiceImpl i QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("role_id", roleId); this.remove(queryWrapper); + cache.vagueDel(CachePrefix.MENU_USER_ID.getPrefix()); + cache.vagueDel(CachePrefix.USER_MENU.getPrefix()); } + @Override public void deleteRoleMenu(List roleId) { //删除 QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.in("role_id", roleId); this.remove(queryWrapper); + cache.vagueDel(CachePrefix.MENU_USER_ID.getPrefix()); + cache.vagueDel(CachePrefix.USER_MENU.getPrefix()); } } \ No newline at end of file diff --git a/manager-api/src/main/java/cn/lili/controller/permission/MenuManagerController.java b/manager-api/src/main/java/cn/lili/controller/permission/MenuManagerController.java index 82f6806e..5169eb44 100644 --- a/manager-api/src/main/java/cn/lili/controller/permission/MenuManagerController.java +++ b/manager-api/src/main/java/cn/lili/controller/permission/MenuManagerController.java @@ -2,7 +2,6 @@ package cn.lili.controller.permission; import cn.lili.common.enums.ResultUtil; import cn.lili.common.vo.ResultMessage; -import cn.lili.modules.system.aspect.annotation.DemoSite; import cn.lili.modules.permission.entity.dos.Menu; import cn.lili.modules.permission.entity.dto.MenuSearchParams; import cn.lili.modules.permission.entity.vo.MenuVO; @@ -29,6 +28,7 @@ import java.util.List; @Api(tags = "管理端,菜单管理接口") @RequestMapping("/manager/menu") public class MenuManagerController { + @Autowired private MenuService menuService; @@ -43,9 +43,9 @@ public class MenuManagerController { @DemoSite public ResultMessage add(Menu menu) { try { - menuService.save(menu); + menuService.saveOrUpdateMenu(menu); } catch (Exception e) { - log.error("添加菜单错误",e); + log.error("添加菜单错误", e); } return ResultUtil.data(menu); } @@ -57,7 +57,7 @@ public class MenuManagerController { @DemoSite public ResultMessage edit(@PathVariable String id, Menu menu) { menu.setId(id); - menuService.updateById(menu); + menuService.saveOrUpdateMenu(menu); return ResultUtil.data(menu); }