Browse Source

Merge remote-tracking branch 'origin/V1.0.11_performance' into V1.0.11_performance

jingyuanchao 11 months ago
parent
commit
4288df3949
36 changed files with 702 additions and 230 deletions
  1. 2 0
      soc-api/soc-api-system/src/main/java/com/xunmei/system/api/RemoteUserService.java
  2. 12 0
      soc-api/soc-api-system/src/main/java/com/xunmei/system/api/model/LoginUser.java
  3. 9 0
      soc-api/soc-api-system/src/main/java/com/xunmei/system/api/vo/SysOrgVO.java
  4. 8 0
      soc-auth/src/main/java/com/xunmei/auth/SocAuthApplication.java
  5. 1 1
      soc-auth/src/main/java/com/xunmei/auth/controller/TokenController.java
  6. 20 24
      soc-auth/src/main/java/com/xunmei/auth/service/SysLoginService.java
  7. 57 2
      soc-common/soc-common-core/src/main/java/com/xunmei/common/core/constant/CacheConstants.java
  8. 4 0
      soc-common/soc-common-core/src/main/java/com/xunmei/common/core/constant/SecurityConstants.java
  9. 11 0
      soc-common/soc-common-core/src/main/java/com/xunmei/common/core/utils/JwtUtils.java
  10. 52 55
      soc-common/soc-common-security/src/main/java/com/xunmei/common/security/service/TokenService.java
  11. 10 0
      soc-common/soc-common-security/src/main/java/com/xunmei/common/security/utils/SecurityUtils.java
  12. 21 34
      soc-gateway/src/main/java/com/xunmei/gateway/filter/AuthFilter.java
  13. 0 1
      soc-modules/soc-modules-core/src/main/java/com/xunmei/core/board/dto/web/TaskStatisticDto.java
  14. 7 4
      soc-modules/soc-modules-core/src/main/java/com/xunmei/core/drill/service/impl/CoreDrillTaskServiceImpl.java
  15. 13 1
      soc-modules/soc-modules-core/src/main/java/com/xunmei/core/letter/service/impl/CoreIntroduceLetterServiceImpl.java
  16. 52 49
      soc-modules/soc-modules-core/src/main/java/com/xunmei/core/panel/service/impl/PanelServiceImpl.java
  17. 45 27
      soc-modules/soc-modules-core/src/main/java/com/xunmei/core/question/service/impl/QuestionServiceImpl.java
  18. 1 0
      soc-modules/soc-modules-core/src/main/java/com/xunmei/core/resumption/gx/service/ResumptionServiceImpl.java
  19. 11 1
      soc-modules/soc-modules-core/src/main/java/com/xunmei/core/weather/service/impl/WeatherWarningServiceImpl.java
  20. 3 0
      soc-modules/soc-modules-system/src/main/java/com/xunmei/system/SocSystemApplication.java
  21. 93 0
      soc-modules/soc-modules-system/src/main/java/com/xunmei/system/controller/CacheController.java
  22. 20 2
      soc-modules/soc-modules-system/src/main/java/com/xunmei/system/controller/SysDeptController.java
  23. 1 1
      soc-modules/soc-modules-system/src/main/java/com/xunmei/system/controller/SysMenuController.java
  24. 4 1
      soc-modules/soc-modules-system/src/main/java/com/xunmei/system/controller/SysOrgController.java
  25. 37 10
      soc-modules/soc-modules-system/src/main/java/com/xunmei/system/controller/SysUserController.java
  26. 11 4
      soc-modules/soc-modules-system/src/main/java/com/xunmei/system/controller/SysUserRoleController.java
  27. 3 0
      soc-modules/soc-modules-system/src/main/java/com/xunmei/system/service/ISysMenuService.java
  28. 5 0
      soc-modules/soc-modules-system/src/main/java/com/xunmei/system/service/ISysUserService.java
  29. 59 5
      soc-modules/soc-modules-system/src/main/java/com/xunmei/system/service/impl/SysDeptServiceImpl.java
  30. 22 0
      soc-modules/soc-modules-system/src/main/java/com/xunmei/system/service/impl/SysMenuServiceImpl.java
  31. 9 2
      soc-modules/soc-modules-system/src/main/java/com/xunmei/system/service/impl/SysOrgExtendServiceImpl.java
  32. 16 1
      soc-modules/soc-modules-system/src/main/java/com/xunmei/system/service/impl/SysOrgServiceImpl.java
  33. 11 1
      soc-modules/soc-modules-system/src/main/java/com/xunmei/system/service/impl/SysRoleServiceImpl.java
  34. 22 1
      soc-modules/soc-modules-system/src/main/java/com/xunmei/system/service/impl/SysUserRoleServiceImpl.java
  35. 48 3
      soc-modules/soc-modules-system/src/main/java/com/xunmei/system/service/impl/SysUserServiceImpl.java
  36. 2 0
      soc-modules/soc-modules-system/src/main/resources/mapper/system/SysOrgMapper.xml

+ 2 - 0
soc-api/soc-api-system/src/main/java/com/xunmei/system/api/RemoteUserService.java

@@ -11,6 +11,7 @@ import com.xunmei.system.api.domain.SysUser;
 import com.xunmei.system.api.factory.RemoteUserFallbackFactory;
 import com.xunmei.system.api.model.LoginUser;
 import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.web.bind.annotation.*;
 
 import java.util.Date;
@@ -64,6 +65,7 @@ public interface RemoteUserService {
      * @return
      */
     @PostMapping("/user/userLoginInfo")
+    @Async
     R<Boolean> userLoginInfo(@RequestParam("id") Long id,@RequestParam("loginTime") Date loginTime,@RequestParam("loginIp") String loginIp,@RequestHeader(SecurityConstants.FROM_SOURCE) String source);
 
     @GetMapping("/user/allUserList")

+ 12 - 0
soc-api/soc-api-system/src/main/java/com/xunmei/system/api/model/LoginUser.java

@@ -1,5 +1,6 @@
 package com.xunmei.system.api.model;
 
+import com.xunmei.system.api.domain.SysOrg;
 import com.xunmei.system.api.domain.SysUser;
 
 import java.io.Serializable;
@@ -94,7 +95,18 @@ public class LoginUser implements Serializable
      * 来源 0:系统添加.1:fjnx同步
      */
     private Integer source;
+    /**
+     * 机构信息
+     */
+    private SysOrg sysOrg;
 
+    public SysOrg getSysOrg() {
+        return sysOrg;
+    }
+
+    public void setSysOrg(SysOrg sysOrg) {
+        this.sysOrg = sysOrg;
+    }
 
     public String getPlatformType() {
         return platformType;

+ 9 - 0
soc-api/soc-api-system/src/main/java/com/xunmei/system/api/vo/SysOrgVO.java

@@ -33,6 +33,15 @@ public class SysOrgVO {
     private String shortName;
     private String treeShowPath;
     private String guid;
+    /**
+     * 地区
+     */
+    private String affiliatedArea;
+    /**
+     * 行社
+     */
+    private String affiliatedBank;
+
     private Integer sort;
     @JsonSerialize(using = ToStringSerializer.class)
     private Long treeShowParentId;

+ 8 - 0
soc-auth/src/main/java/com/xunmei/auth/SocAuthApplication.java

@@ -1,12 +1,18 @@
 package com.xunmei.auth;
 
+import com.xunmei.common.core.constant.SecurityConstants;
 import com.xunmei.common.security.annotation.EnableSocFeignClients;
 import com.xunmei.common.swagger.annotation.EnableCustomSwagger2;
+import com.xunmei.system.api.RemoteUserService;
+import com.xunmei.system.api.domain.SysUser;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
 import org.springframework.cloud.context.config.annotation.RefreshScope;
 
+import javax.annotation.PostConstruct;
+
 /**
  * 认证授权中心
  * 
@@ -23,4 +29,6 @@ public class SocAuthApplication
         SpringApplication.run(SocAuthApplication.class, args);
         System.out.println("(♥◠‿◠)ノ゙  认证授权中心启动成功   ლ(´ڡ`ლ)゙ ");
     }
+
+
 }

+ 1 - 1
soc-auth/src/main/java/com/xunmei/auth/controller/TokenController.java

@@ -181,7 +181,7 @@ public class TokenController {
                 if(userInfo == null){
                     return R.fail("无效的用户数据");
                 }
-                 Map<String, Object> systemToken = tokenService.createToken(userInfo);
+                Map<String, Object> systemToken = tokenService.createToken(userInfo);
                 logger.debug("token登录:5、生成系统自身Token完成,token:{}",token);
                 return R.ok(systemToken);
             }else{

+ 20 - 24
soc-auth/src/main/java/com/xunmei/auth/service/SysLoginService.java

@@ -26,7 +26,7 @@ import org.springframework.stereotype.Component;
  * @author xunmei
  */
 @Component
-public class SysLoginService{
+public class SysLoginService {
     @Autowired
     private RemoteUserService remoteUserService;
 
@@ -40,7 +40,6 @@ public class SysLoginService{
     private FJNXLoginService fjnxLoginService;
 
 
-
     /**
      * 登录
      */
@@ -69,6 +68,7 @@ public class SysLoginService{
             throw new ServiceException("很遗憾,访问IP已被列入系统黑名单");
         }
         // 查询用户信息
+        //TODO 优化点2 : 考虑使用缓存,减少数据库查询
         R<LoginUser> userResult = remoteUserService.getUserInfo(username, SecurityConstants.INNER);
 
         if (StringUtils.isNull(userResult) || StringUtils.isNull(userResult.getData())) {
@@ -92,45 +92,40 @@ public class SysLoginService{
             throw new ServiceException("对不起,您的账号:" + username + " 已停用");
         }
         // 如果人员是从统一门户同步过来的人, 先尝试走行方的账号密码验证
-        if(ObjectUtil.equal(userInfo.getSource(),1))
-        {
-            try{
-                LoginBody login=new LoginBody();
+        if (ObjectUtil.equal(userInfo.getSource(), 1)) {
+            try {
+                LoginBody login = new LoginBody();
                 login.setUsername(username);
                 login.setPassword(SecurityUtils.decryptSm4(password));
                 //登录统一运营
                 String token = fjnxLoginService.webLoginByPass(login);
                 // 如果统一门户验证失败, 再走本系统默认密码验证
-                if(StringUtils.isEmpty(token)){
+                if (StringUtils.isEmpty(token)) {
                     passwordService.validate(user, password, platformType);
                 }
             }
             // 如果统一门户验证失败, 再走本系统默认密码验证
-            catch (Exception e){
+            catch (Exception e) {
                 // 发现是因为这两种错误登录失败,将错误抛出
-                if("登录失败,账号或密码错误".equals(e.getMessage()) || "登录失败,请到统一运营门户输入账号完成维护".equals(e.getMessage()))
-                {
+                if ("登录失败,账号或密码错误".equals(e.getMessage()) || "登录失败,请到统一运营门户输入账号完成维护".equals(e.getMessage())) {
                     throw e;
                 }
                 passwordService.validate(user, password, platformType);
             }
-        }
-        else
-        {
+        } else {
             passwordService.validate(user, password, platformType);
         }
         recordLogService.recordLogininfor(username, Constants.LOGIN_SUCCESS, "登录成功", platformType);
         return userInfo;
     }
 
-    public LoginUser switchUser(Long subUserId,String platformType) {
+    public LoginUser switchUser(Long subUserId, String platformType) {
 
         SysUser swichUser = remoteUserService.getUserById(subUserId, SecurityConstants.INNER);
-        if(ObjectUtil.isEmpty(swichUser))
-        {
+        if (ObjectUtil.isEmpty(swichUser)) {
             throw new ServiceException("切换用户:" + subUserId + " 不存在");
         }
-        String username=swichUser.getUsername();
+        String username = swichUser.getUsername();
         // 用户名不在指定范围内 错误
         if (username.length() < UserConstants.USERNAME_MIN_LENGTH
                 || username.length() > UserConstants.USERNAME_MAX_LENGTH) {
@@ -177,25 +172,26 @@ public class SysLoginService{
 
     /**
      * 用户名登录
+     *
      * @param username
      * @param loginType
      * @return
      */
-    public LoginUser loginToken(String username,String loginType){
+    public LoginUser loginToken(String username, String loginType) {
         R<LoginUser> userResult = remoteUserService.getUserInfo(username, SecurityConstants.INNER);
-        if(StringUtils.isNull(userResult) || StringUtils.isNull(userResult.getData())){
-            recordLogService.recordLogininfor(username,Constants.LOGIN_FAIL,"登录用户不存在",loginType);
-            throw new RuntimeException("登录用户:"+ username + "不存在");
+        if (StringUtils.isNull(userResult) || StringUtils.isNull(userResult.getData())) {
+            recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "登录用户不存在", loginType);
+            throw new RuntimeException("登录用户:" + username + "不存在");
         }
 
-        if(R.FAIL == userResult.getCode()){
+        if (R.FAIL == userResult.getCode()) {
             throw new RuntimeException(userResult.getMsg());
         }
 
-        LoginUser userInfo= userResult.getData();
+        LoginUser userInfo = userResult.getData();
         userInfo.setPlatformType(loginType);
         passwordService.clearLoginRecordCache(username);
-        recordLogService.recordLogininfor(username,Constants.LOGIN_SUCCESS,"登录成功",loginType);
+        recordLogService.recordLogininfor(username, Constants.LOGIN_SUCCESS, "登录成功", loginType);
         return userInfo;
     }
 }

+ 57 - 2
soc-common/soc-common-core/src/main/java/com/xunmei/common/core/constant/CacheConstants.java

@@ -8,9 +8,9 @@ package com.xunmei.common.core.constant;
 public class CacheConstants
 {
     /**
-     * 缓存有效期,默认720(分钟)
+     * 缓存有效期,默认480(分钟) ,8小时
      */
-    public final static long EXPIRATION = 1500;
+    public final static long EXPIRATION = 480;
 
     /**
      * 缓存刷新时间,默认120(分钟)
@@ -107,4 +107,59 @@ public class CacheConstants
      */
     public static final String CHANNEL_KEY = "channel_base_info_uid";
 
+    /**
+     * 内部调用获取 单机构、用户信息 缓存过期时间 (单位秒)
+     */
+    public static final int ORG_USER_EXPIRATION_TIME = 120*60;
+
+    /**
+     * 单机构缓存
+     */
+    public static final String ORG_CACHE_SINGLE_KEY = "sys_single_org:";
+
+    /**
+     * 机构树
+     */
+    public static final String DEPT_TREE_CACHE_SINGLE_KEY = "sys_dept_org_tree:";
+
+    /**
+     * 行社机构数据
+     */
+    public static final String DEPT_HANGSHE_TREE_CACHE_SINGLE_KEY = "sys_dept_hs_org_tree:";
+
+    /**
+     * 地区+行社+机构名称 的机构名称缓存
+     */
+    public static final String ORG_CACHE_CONCAT_NAME = "sys_concat_org_name:";
+
+    public static final String ORG_EXTEND_CACHE_CONCAT_INFO = "sys_org_extend_info:";
+
+    /**
+     * 用户角色ID缓存
+     */
+    public static final String USER_CACHE_ROLE_ID_KEY = "sys_single_user_roleId:";
+
+    /**
+     * 用户角色对象缓存
+     */
+    public static final String USER_CACHE_ROLE_OBJECT_KEY = "sys_single_user_role:";
+
+    /**
+     * 单用户信息缓存
+     */
+    public static final String USER_CACHE_SINGLE_KEY = "sys_single_user:";
+
+    /**
+     * user角色权限字段缓存
+     */
+    public static final String USER_ROLE_PERMISSION_CACHE_KEY = "sys_user_role_permission:";
+
+    /**
+     * 角色权限字段缓存
+     */
+    public static final String ROLE_PERMISSION_CACHE_KEY = "sys_role_permission:";
+
+//    public static final String CONFIG_CACHE_KEY = "sys_config:";
+
+
 }

+ 4 - 0
soc-common/soc-common-core/src/main/java/com/xunmei/common/core/constant/SecurityConstants.java

@@ -57,4 +57,8 @@ public class SecurityConstants
      * 角色权限
      */
     public static final String ROLE_PERMISSION = "role_permission";
+    /**
+     * 客户端类型
+     */
+    public static final String PLATFORM_TYPE = "platform_type";
 }

+ 11 - 0
soc-common/soc-common-core/src/main/java/com/xunmei/common/core/utils/JwtUtils.java

@@ -101,6 +101,17 @@ public class JwtUtils
     }
 
     /**
+     * 根据token令牌 获取客户端类型
+     * @param token 令牌
+     * @return 客户端类型
+     */
+    public static String getPlatformType(String token)
+    {
+        Claims claims = parseToken(token);
+        return getValue(claims, SecurityConstants.PLATFORM_TYPE);
+    }
+
+    /**
      * 根据身份信息获取用户ID
      * 
      * @param claims 身份信息

+ 52 - 55
soc-common/soc-common-security/src/main/java/com/xunmei/common/security/service/TokenService.java

@@ -58,30 +58,27 @@ public class TokenService {
      * 创建令牌
      */
     public Map<String, Object> createToken(LoginUser loginUser) {
-        Long userId = loginUser.getSysUser().getId();
 
+        Long userId = loginUser.getSysUser().getId();
         String userName = loginUser.getSysUser().getName();
-        if(StringUtils.isEmpty(loginUser.getToken())){
-            String token = userId + "_"+ loginUser.getPlatformType()+"_" + IdUtils.fastUUID();
-            loginUser.setToken(token);
-        }
-
+        String token = IdUtils.fastUUID();
+        loginUser.setToken(token);
         loginUser.setUserid(userId);
         loginUser.setUsername(userName);
         loginUser.setOrgId(loginUser.getSysUser().getOrgId());
         loginUser.setName(loginUser.getSysUser().getName());
         loginUser.setIpaddr(IpUtils.getIpAddr());
-        long configExpireTime =  getTokenExpireTime(loginUser.getPlatformType());
-        refreshTokenNew(loginUser,configExpireTime);
+        long configExpireTime = getTokenExpireTime(loginUser.getPlatformType());
+        refreshTokenNew(loginUser, configExpireTime);
 
         // Jwt存储信息
         Map<String, Object> claimsMap = new HashMap<String, Object>();
         claimsMap.put(SecurityConstants.USER_KEY, loginUser.getToken());
+        claimsMap.put(SecurityConstants.PLATFORM_TYPE, loginUser.getPlatformType());
         claimsMap.put(SecurityConstants.DETAILS_USER_ID, userId);
         claimsMap.put(SecurityConstants.DETAILS_USERNAME, userName);
         claimsMap.put(SecurityConstants.DETAILS_MASTER_USER_ID, loginUser.getMasterUserId());
         claimsMap.put(SecurityConstants.DETAILS_MASTERUSERNAME, loginUser.getMasterUserName());
-
         // 接口返回信息
         Map<String, Object> rspMap = new HashMap<String, Object>();
         rspMap.put("access_token", JwtUtils.createToken(claimsMap));
@@ -91,7 +88,6 @@ public class TokenService {
 
     /**
      * 创建令牌
-     *
      */
     public Map<String, Object> createTokenNew(LoginUser loginUser, Integer loginFrom) {
         //现场大屏登录也是 走APP登录接口,但是请求携带了 loginFrom 参数;根据 loginFrom 转换 PlatformType 值
@@ -157,13 +153,14 @@ public class TokenService {
         try {
             if (StringUtils.isNotEmpty(token)) {
                 String userkey = JwtUtils.getUserKey(token);
-                user = RedisUtils.getCacheObject(getTokenKey(userkey));
-                //user = redisService.getCacheObject(getTokenKey(userkey));
-                return user;
+                String userId = JwtUtils.getUserId(token);
+                String platformType = JwtUtils.getPlatformType(token);
+                user = RedisUtils.getCacheObject(getTokenKey(userkey, userId, platformType));
             }
+            return user;
         } catch (Exception e) {
+            return user;
         }
-        return user;
     }
 
     /**
@@ -181,8 +178,10 @@ public class TokenService {
     public void delLoginUser(String token) {
         if (StringUtils.isNotEmpty(token)) {
             String userkey = JwtUtils.getUserKey(token);
+            String userId = JwtUtils.getUserId(token);
+            String platformType = JwtUtils.getPlatformType(token);
             //redisService.deleteObject(getTokenKey(userkey));
-            RedisUtils.deleteObject(getTokenKey(userkey));
+            RedisUtils.deleteObject(getTokenKey(userkey, userId, platformType));
         }
     }
 
@@ -195,7 +194,7 @@ public class TokenService {
         long expireTime = loginUser.getExpireTime();
         long currentTime = System.currentTimeMillis();
         if (expireTime - currentTime <= MILLIS_MINUTE_TEN) {
-            logger.info("Token 即将过期,刷新Token 有效时间,{}",loginUser.getToken());
+            logger.info("Token 即将过期,刷新Token 有效时间,{}", loginUser.getToken());
             refreshToken(loginUser);
         }
     }
@@ -220,7 +219,7 @@ public class TokenService {
 //        RedisUtils.setCacheObject(userKey, loginUser, Duration.ofMinutes(expireTime));
 //        //redisService.deleteByPrefix(userKey);
 //        // redisService.setCacheObject(userKey, loginUser, expireTime, TimeUnit.MINUTES);
-        refreshTokenNew(loginUser,expireTime);
+        refreshTokenNew(loginUser, expireTime);
     }
 
     /**
@@ -228,66 +227,66 @@ public class TokenService {
      *
      * @param loginUser 登录信息
      */
-    public void refreshTokenNew(LoginUser loginUser,long configExpireTime) {
+    public void refreshTokenNew(LoginUser loginUser, long configExpireTime) {
         loginUser.setLoginTime(System.currentTimeMillis());
         loginUser.setExpireTime(loginUser.getLoginTime() + configExpireTime * MILLIS_MINUTE);
         // 根据uuid将loginUser缓存
-        String userKey = getTokenKey(loginUser.getToken());
+        String userKey = getTokenKey(loginUser.getToken(), String.valueOf(loginUser.getUserid()), loginUser.getPlatformType());
 //        remoteUserService.userLoginInfo(loginUser.getUserid(), DateUtils.getNowDate(), loginUser.getIpaddr(), SecurityConstants.INNER);
         //登陆后删除之前的token
         // admin 用户的 ID 是1 按前缀删除缓存时 会把其他人的Token都删除掉, 固排除 admin
-        if(!"admin".equals(loginUser.getSysUser().getUsername())){
-            String userKeyPrefix= getTokenKey(loginUser.getUserid().toString()+"_"+loginUser.getPlatformType());
+ /*       if (!"admin".equals(loginUser.getSysUser().getUsername())) {
+            String userKeyPrefix = getTokenKey(loginUser.getUserid().toString() + "_" + loginUser.getPlatformType());
             RedisUtils.deleteByPrefix(userKeyPrefix);
-        }
+        }*/
 
         RedisUtils.setCacheObject(userKey, loginUser, Duration.ofMinutes(configExpireTime));
         //redisService.deleteByPrefix(userKey);
         // redisService.setCacheObject(userKey, loginUser, expireTime, TimeUnit.MINUTES);
     }
 
-    private String getTokenKey(String token) {
-        return ACCESS_TOKEN + token;
+    /**
+     * 登录token记录数据
+     *
+     * @param token       令牌
+     * @param userId      用户id
+     * @param patformType 平台类型
+     * @return
+     */
+    private String getTokenKey(String token, String userId, String patformType) {
+        return ACCESS_TOKEN + userId + ":" + patformType + ":" + token;
     }
 
-    private Long getTokenExpireTime(String platformType)
-    {
+    private Long getTokenExpireTime(String platformType) {
         long configExpireTime = 0;
         String configExpireTimeStr = "";
-        if(platformType != null){
-            if(Constants.LOGIN_TYPE_2.equals(platformType)){
+        if (platformType != null) {
+            if (Constants.LOGIN_TYPE_2.equals(platformType)) {
                 //大屏
-                String screenCacheKey=CacheConstants.SYS_CONFIG_KEY+SystemParameterConstant.TOKEN_LARGESCREEN_EXPIRETIME;
-                configExpireTimeStr= getConfigValueFromRedis(screenCacheKey);
-            }
-            else if(Constants.LOGIN_TYPE_0.equals(platformType)){
+                String screenCacheKey = CacheConstants.SYS_CONFIG_KEY + SystemParameterConstant.TOKEN_LARGESCREEN_EXPIRETIME;
+                configExpireTimeStr = getConfigValueFromRedis(screenCacheKey);
+            } else if (Constants.LOGIN_TYPE_0.equals(platformType)) {
                 //app
-                String appCacheKey=CacheConstants.SYS_CONFIG_KEY+SystemParameterConstant.TOKEN_APP_EXPIRETIME;
-                configExpireTimeStr= getConfigValueFromRedis(appCacheKey);
-            }else if(Constants.LOGIN_TYPE_1.equals(platformType)){
+                String appCacheKey = CacheConstants.SYS_CONFIG_KEY + SystemParameterConstant.TOKEN_APP_EXPIRETIME;
+                configExpireTimeStr = getConfigValueFromRedis(appCacheKey);
+            } else if (Constants.LOGIN_TYPE_1.equals(platformType)) {
                 //web
-                String webCacheKey=CacheConstants.SYS_CONFIG_KEY+SystemParameterConstant.TOKEN_WEB_EXPIRETIME;
-                configExpireTimeStr= getConfigValueFromRedis(webCacheKey);
+                String webCacheKey = CacheConstants.SYS_CONFIG_KEY + SystemParameterConstant.TOKEN_WEB_EXPIRETIME;
+                configExpireTimeStr = getConfigValueFromRedis(webCacheKey);
             }
         }
-        if(StringUtils.isNotEmpty(configExpireTimeStr))
-        {
-            configExpireTime=  Long.parseLong(configExpireTimeStr);
-        }
-        else{
-            configExpireTime=expireTime;
+        if (StringUtils.isNotEmpty(configExpireTimeStr)) {
+            configExpireTime = Long.parseLong(configExpireTimeStr);
+        } else {
+            configExpireTime = expireTime;
         }
         return configExpireTime;
     }
 
-    private String getConfigValueFromRedis(String cacheKey)
-    {
-        if(RedisUtils.hasKey(cacheKey))
-        {
+    private String getConfigValueFromRedis(String cacheKey) {
+        if (RedisUtils.hasKey(cacheKey)) {
             return RedisUtils.getCacheObject(cacheKey);
-        }
-        else
-        {
+        } else {
             return null;
         }
     }
@@ -297,17 +296,15 @@ public class TokenService {
         // loginFrom 0 大屏,1 app ,2 web
         // 大屏登录时会带入 logFrom 参数
         //移动端端登录
-        if (logFrom==null || logFrom==1) {
+        if (logFrom == null || logFrom == 1) {
             // app
             return Constants.LOGIN_TYPE_0;
         }
-        if(logFrom==0)
-        {
+        if (logFrom == 0) {
             // 大屏
             return Constants.LOGIN_TYPE_2;
         }
-        if(logFrom==2)
-        {
+        if (logFrom == 2) {
             // web
             return Constants.LOGIN_TYPE_1;
         }

+ 10 - 0
soc-common/soc-common-security/src/main/java/com/xunmei/common/security/utils/SecurityUtils.java

@@ -12,6 +12,7 @@ import com.xunmei.common.core.constant.TokenConstants;
 import com.xunmei.common.core.context.SecurityContextHolder;
 import com.xunmei.common.core.utils.ServletUtils;
 import com.xunmei.common.core.utils.StringUtils;
+import com.xunmei.system.api.domain.SysOrg;
 import com.xunmei.system.api.model.LoginUser;
 import org.apache.commons.codec.digest.DigestUtils;
 import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
@@ -122,6 +123,15 @@ public class SecurityUtils {
     }
 
     /**
+     * 获取机构信息
+     * @return
+     */
+    public static SysOrg getUserSysOrg(){
+        LoginUser loginUser = SecurityContextHolder.get(SecurityConstants.LOGIN_USER, LoginUser.class);
+        return loginUser.getSysOrg();
+    }
+
+    /**
      * 获取请求token
      */
     public static String getToken() {

+ 21 - 34
soc-gateway/src/main/java/com/xunmei/gateway/filter/AuthFilter.java

@@ -30,8 +30,7 @@ import java.util.List;
  * @author xunmei
  */
 @Component
-public class AuthFilter implements GlobalFilter, Ordered
-{
+public class AuthFilter implements GlobalFilter, Ordered {
     private static final Logger log = LoggerFactory.getLogger(AuthFilter.class);
 
     // 排除过滤的 uri 地址,nacos自行添加
@@ -39,40 +38,35 @@ public class AuthFilter implements GlobalFilter, Ordered
     private IgnoreWhiteProperties ignoreWhite;
 
 
-
     @Override
-    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain)
-    {
+    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
         ServerHttpRequest request = exchange.getRequest();
         ServerHttpRequest.Builder mutate = request.mutate();
 
         String url = request.getURI().getPath();
         // 跳过不需要验证的路径
-        if (StringUtils.matches(url, ignoreWhite.getWhites()))
-        {
+        if (StringUtils.matches(url, ignoreWhite.getWhites())) {
             return chain.filter(exchange);
         }
         String token = getToken(request);
-        if (StringUtils.isEmpty(token))
-        {
+        if (StringUtils.isEmpty(token)) {
             return unauthorizedResponse(exchange, "令牌不能为空");
         }
         Claims claims = JwtUtils.parseToken(token);
-        if (claims == null)
-        {
+        if (claims == null) {
             return unauthorizedResponse(exchange, "令牌已过期或验证不正确!");
         }
         String userkey = JwtUtils.getUserKey(claims);
-        boolean islogin = RedisUtils.hasKey(getTokenKey(userkey));
+        String userId = JwtUtils.getUserId(claims);
+        String platformType = JwtUtils.getPlatformType(token);
+        boolean islogin = RedisUtils.hasKey(getTokenKey(userkey,userId,platformType));
         //boolean islogin = redisService.hasKey(getTokenKey(userkey));
-        if (!islogin)
-        {
+        if (!islogin) {
             return unauthorizedResponse(exchange, "登录状态已过期");
         }
         String userid = JwtUtils.getUserId(claims);
         String username = JwtUtils.getUserName(claims);
-        if (StringUtils.isEmpty(userid) || StringUtils.isEmpty(username))
-        {
+        if (StringUtils.isEmpty(userid) || StringUtils.isEmpty(username)) {
             return unauthorizedResponse(exchange, "令牌验证失败");
         }
 
@@ -91,10 +85,8 @@ public class AuthFilter implements GlobalFilter, Ordered
         return chain.filter(exchange.mutate().request(mutate.build()).build());
     }
 
-    private void addHeader(ServerHttpRequest.Builder mutate, String name, Object value)
-    {
-        if (value == null)
-        {
+    private void addHeader(ServerHttpRequest.Builder mutate, String name, Object value) {
+        if (value == null) {
             return;
         }
         String valueStr = value.toString();
@@ -102,13 +94,11 @@ public class AuthFilter implements GlobalFilter, Ordered
         mutate.header(name, valueEncode);
     }
 
-    private void removeHeader(ServerHttpRequest.Builder mutate, String name)
-    {
+    private void removeHeader(ServerHttpRequest.Builder mutate, String name) {
         mutate.headers(httpHeaders -> httpHeaders.remove(name)).build();
     }
 
-    private Mono<Void> unauthorizedResponse(ServerWebExchange exchange, String msg)
-    {
+    private Mono<Void> unauthorizedResponse(ServerWebExchange exchange, String msg) {
         log.error("[鉴权异常处理]请求路径:{}", exchange.getRequest().getPath());
         return ServletUtils.webFluxResponseWriter(exchange.getResponse(), msg, HttpStatus.UNAUTHORIZED);
     }
@@ -116,35 +106,32 @@ public class AuthFilter implements GlobalFilter, Ordered
     /**
      * 获取缓存key
      */
-    private String getTokenKey(String token)
-    {
-        return CacheConstants.LOGIN_TOKEN_KEY + token;
+    private String getTokenKey(String token, String userId, String platformType) {
+        return CacheConstants.LOGIN_TOKEN_KEY + userId + ":" + platformType + ":" + token;
     }
 
+
     /**
      * 获取请求token
      */
-    private String getToken(ServerHttpRequest request)
-    {
+    private String getToken(ServerHttpRequest request) {
         String token = request.getHeaders().getFirst(TokenConstants.AUTHENTICATION);
 
-        if(StringUtils.isEmpty(token)){
+        if (StringUtils.isEmpty(token)) {
             MultiValueMap<String, String> queryParams = request.getQueryParams();
             List<String> values = queryParams.get(TokenConstants.AUTHENTICATION);
             token = values != null && !values.isEmpty() ? values.get(0) : null;
         }
 
         // 如果前端设置了令牌前缀,则裁剪掉前缀
-        if (StringUtils.isNotEmpty(token) && token.startsWith(TokenConstants.PREFIX))
-        {
+        if (StringUtils.isNotEmpty(token) && token.startsWith(TokenConstants.PREFIX)) {
             token = token.replaceFirst(TokenConstants.PREFIX, StringUtils.EMPTY);
         }
         return token;
     }
 
     @Override
-    public int getOrder()
-    {
+    public int getOrder() {
         return -200;
     }
 }

+ 0 - 1
soc-modules/soc-modules-core/src/main/java/com/xunmei/core/board/dto/web/TaskStatisticDto.java

@@ -1,6 +1,5 @@
 package com.xunmei.core.board.dto.web;
 
-import jdk.nashorn.internal.runtime.arrays.IntElements;
 import lombok.Data;
 
 import javax.validation.constraints.NotNull;

+ 7 - 4
soc-modules/soc-modules-core/src/main/java/com/xunmei/core/drill/service/impl/CoreDrillTaskServiceImpl.java

@@ -62,6 +62,7 @@ import com.xunmei.system.api.domain.SysDictData;
 import com.xunmei.system.api.domain.SysOrg;
 import com.xunmei.system.api.domain.SysUser;
 import com.xunmei.system.api.function.RemoteCallHandlerExecutor;
+import com.xunmei.system.api.model.LoginUser;
 import com.xunmei.system.api.vo.SysOrgVO;
 import io.netty.util.internal.StringUtil;
 import lombok.extern.slf4j.Slf4j;
@@ -1362,8 +1363,9 @@ public class CoreDrillTaskServiceImpl extends ServiceImpl<CoreDrillTaskMapper, C
 
     @Override
     public List<PanelListVo> selectCurUserTaskList(PanelListDto panelListDto) {
-        SysOrg sysOrg = RemoteCallHandlerExecutor.executeRemoteCall(() ->
-                orgService.selectSysOrgById(panelListDto.getOrgId(), SecurityConstants.FROM_SOURCE), ErrorMsgConstants.QUERY_ORG_DATA_ERROR);
+/*        SysOrg sysOrg = RemoteCallHandlerExecutor.executeRemoteCall(() ->
+                orgService.selectSysOrgById(panelListDto.getOrgId(), SecurityConstants.FROM_SOURCE), ErrorMsgConstants.QUERY_ORG_DATA_ERROR);*/
+        SysOrg sysOrg = SecurityUtils.getUserSysOrg();
         panelListDto.setOrgType(sysOrg.getType());
         panelListDto.setOrgPath(sysOrg.getPath());
         List<Integer> statusList = new ArrayList<>();
@@ -1402,8 +1404,9 @@ public class CoreDrillTaskServiceImpl extends ServiceImpl<CoreDrillTaskMapper, C
 
     @Override
     public List<PanelListVo> selectRecList(PanelListDto panelListDto) {
-        SysOrg sysOrg = RemoteCallHandlerExecutor.executeRemoteCall(() ->
-                orgService.selectSysOrgById(panelListDto.getOrgId(), SecurityConstants.FROM_SOURCE), ErrorMsgConstants.QUERY_ORG_DATA_ERROR);
+        /*SysOrg sysOrg = RemoteCallHandlerExecutor.executeRemoteCall(() ->
+                orgService.selectSysOrgById(panelListDto.getOrgId(), SecurityConstants.FROM_SOURCE), ErrorMsgConstants.QUERY_ORG_DATA_ERROR);*/
+        SysOrg sysOrg = SecurityUtils.getUserSysOrg();
         panelListDto.setOrgType(sysOrg.getType());
         panelListDto.setOrgPath(sysOrg.getPath());
         List<PanelListVo> waitRecTaskList = new ArrayList<>();

+ 13 - 1
soc-modules/soc-modules-core/src/main/java/com/xunmei/core/letter/service/impl/CoreIntroduceLetterServiceImpl.java

@@ -9,6 +9,7 @@ import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.core.toolkit.IdWorker;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.xunmei.common.core.constant.CacheConstants;
 import com.xunmei.common.core.constant.DictConstants;
 import com.xunmei.common.core.constant.ErrorMsgConstants;
 import com.xunmei.common.core.constant.SecurityConstants;
@@ -22,6 +23,7 @@ import com.xunmei.common.core.domain.panel.vo.WebPanelResult;
 import com.xunmei.common.core.util.BeanHelper;
 import com.xunmei.common.core.utils.DateUtils;
 import com.xunmei.common.core.web.page.TableDataInfo;
+import com.xunmei.common.redis.utils.RedisUtils;
 import com.xunmei.common.security.utils.DictUtils;
 import com.xunmei.common.security.utils.SecurityUtils;
 import com.xunmei.core.letter.mapper.CoreIntroduceLetterOutInRequestMapper;
@@ -345,7 +347,17 @@ public class CoreIntroduceLetterServiceImpl extends ServiceImpl<CoreIntroduceLet
     @Override
     public List<PanelListVo> selectToDoApproveListForAPP(PanelListDto panelListDto) {
         List<PanelListVo> resultList = new ArrayList<>();
-        SysRole role = roleService.getRoleByName("网点负责人", SecurityConstants.INNER);
+        SysRole tempRole =null;
+        List<SysRole> cacheRoleList = RedisUtils.getCacheList(CacheConstants.ROLE_CACHE_LIST_KEY);
+        if(ObjectUtil.isNotEmpty(cacheRoleList) && cacheRoleList.stream().anyMatch(x->"网点负责人".equals(x.getRoleName())))
+        {
+            tempRole= cacheRoleList.stream().filter(x->"网点负责人".equals(x.getRoleName())).findFirst().get();
+        }
+        else {
+            tempRole = roleService.getRoleByName("网点负责人", SecurityConstants.INNER);
+        }
+
+        SysRole role =tempRole;
         // 没有角色
         if (ObjectUtil.isEmpty(panelListDto.getRoleIdList())) {
             return resultList;

+ 52 - 49
soc-modules/soc-modules-core/src/main/java/com/xunmei/core/panel/service/impl/PanelServiceImpl.java

@@ -18,6 +18,7 @@ import com.xunmei.common.core.domain.panel.vo.PanelListVo;
 import com.xunmei.common.core.domain.panel.vo.PanelResultVo;
 import com.xunmei.common.core.domain.panel.vo.WebPanelResult;
 import com.xunmei.common.core.web.page.TableDataInfo;
+import com.xunmei.common.redis.utils.RedisUtils;
 import com.xunmei.common.security.utils.SecurityUtils;
 import com.xunmei.core.drill.service.ICoreDrillTaskService;
 import com.xunmei.core.edu.service.ICoreEduTrainingTaskService;
@@ -61,7 +62,7 @@ import java.util.stream.Stream;
 @Service
 public class PanelServiceImpl implements PanelService {
 
-    public static final int TIMEOUT = 3;
+    public static final int TIMEOUT = 10;
     @Autowired
     private ResumptionService resumptionService;
     @Autowired
@@ -100,18 +101,28 @@ public class PanelServiceImpl implements PanelService {
     @Override
     public List<PanelResultVo> selectPage() throws ExecutionException, InterruptedException, TimeoutException {
         Long userId = SecurityUtils.getUserId();
-        Long orgId =SecurityUtils.getLoginUser().getOrgId();
-        return getListByUserId(userId,orgId);
+        Long orgId = SecurityUtils.getLoginUser().getOrgId();
+        return getListByUserId(userId, orgId);
     }
 
-    private List<PanelResultVo> getListByUserId(Long userId,Long orgId) throws ExecutionException, InterruptedException, TimeoutException
-    {
-        List<Long> roles = RemoteCallHandlerExecutor.executeRemoteCall(
+    private List<PanelResultVo> getListByUserId(Long userId, Long orgId) throws ExecutionException, InterruptedException, TimeoutException {
+        /*List<Long> roles = RemoteCallHandlerExecutor.executeRemoteCall(
                 () -> roleService.getUserRoleId(userId, SecurityConstants.FROM_SOURCE),
-                ErrorMsgConstants.QUERY_USER_ROLE_ERROR);
+                ErrorMsgConstants.QUERY_USER_ROLE_ERROR);*/
+        List<Long> roleIds = null;
+        if (ObjectUtil.equal(SecurityUtils.getUserId(), userId)) {
+            Set<String> roles = SecurityUtils.getLoginUser().getRoles();
+            //获取roles id 集合
+            roleIds = roles.stream().map(Long::valueOf).collect(Collectors.toList());
+        } else {
+            roleIds = RemoteCallHandlerExecutor.executeRemoteCall(
+                    () -> roleService.getUserRoleId(userId, SecurityConstants.FROM_SOURCE),
+                    ErrorMsgConstants.QUERY_USER_ROLE_ERROR);
+        }
+
 
         PanelListDto panelListDto = PanelAdapter.getMapperSelectParam(orgId,
-                roles, userId);
+                roleIds, userId);
         if (ObjectUtil.isEmpty(panelListDto.getRoleIdList())) {
             return new ArrayList<>();
         }
@@ -121,11 +132,11 @@ public class PanelServiceImpl implements PanelService {
                 resumptionService.selectCurUserTaskList(panelListDto), threadPoolTaskExecutor
         );
 
-        //布撤防
+    /*    //布撤防
         CompletableFuture<List<PanelListVo>> protectionTaskFuture = CompletableFuture.supplyAsync(() ->
                 protectionService.selectCurUserTaskList(panelListDto), threadPoolTaskExecutor
         );
-
+*/
         //监控调阅任务
         CompletableFuture<List<PanelListVo>> monitorTaskFuture = CompletableFuture.supplyAsync(() ->
                 coreMonitoringRetrievalTaskService.selectCurUserTaskList(panelListDto), threadPoolTaskExecutor
@@ -145,13 +156,13 @@ public class PanelServiceImpl implements PanelService {
                 drillTaskService.selectCurUserTaskList(panelListDto), threadPoolTaskExecutor
         );
         //预案演练-推优评优任务
-        CompletableFuture<List<PanelListVo>> recLitFuture = CompletableFuture.supplyAsync(() ->{
-                PanelListDto tempReqest=new PanelListDto();
-                BeanUtils.copyProperties(panelListDto,tempReqest);
-                tempReqest.setStartTime(DateUtil.offsetMonth(DateUtil.beginOfQuarter(new Date()),-3));
-                tempReqest.setEndTime(DateUtil.endOfQuarter(new Date()));
-                return drillTaskService.selectRecList(tempReqest);
-            }, threadPoolTaskExecutor
+        CompletableFuture<List<PanelListVo>> recLitFuture = CompletableFuture.supplyAsync(() -> {
+                    PanelListDto tempReqest = new PanelListDto();
+                    BeanUtils.copyProperties(panelListDto, tempReqest);
+                    tempReqest.setStartTime(DateUtil.offsetMonth(DateUtil.beginOfQuarter(new Date()), -3));
+                    tempReqest.setEndTime(DateUtil.endOfQuarter(new Date()));
+                    return drillTaskService.selectRecList(tempReqest);
+                }, threadPoolTaskExecutor
         );
 
         //教育培训任务
@@ -171,14 +182,14 @@ public class PanelServiceImpl implements PanelService {
         );
 
         CompletableFuture<Void> allQueries = CompletableFuture.allOf(
-                resumptionTaskFuture, protectionTaskFuture, monitorTaskFuture, evaluateTaskFuture,
+                resumptionTaskFuture, monitorTaskFuture, evaluateTaskFuture,
                 safetyTaskFuture, drillTaskFuture, eduTrainingTaskFuture, recLitFuture, questionTaskFuture, letterOutInFuture
         );
 
         allQueries.get(TIMEOUT, TimeUnit.SECONDS);
 
         List<PanelListVo> resultList = Stream.of(
-                        resumptionTaskFuture.join(), protectionTaskFuture.join(), monitorTaskFuture.join(), evaluateTaskFuture.join(),
+                        resumptionTaskFuture.join(), monitorTaskFuture.join(), evaluateTaskFuture.join(),
                         safetyTaskFuture.join(), drillTaskFuture.join(), eduTrainingTaskFuture.join(), recLitFuture.join(),
                         questionTaskFuture.join(), letterOutInFuture.join()
                 )
@@ -195,26 +206,23 @@ public class PanelServiceImpl implements PanelService {
             List<PanelListVo> data = map.getValue();
             vo.setNums(data.size());
             vo.setTaskTypeText(PanelTypeEnums.getName(map.getKey()));
-            if(ObjectUtil.equal(map.getKey(),PanelTypeEnums.SAFETY_CHECK.getCode())){
-                if(data.size()>0)
-                {
+            if (ObjectUtil.equal(map.getKey(), PanelTypeEnums.SAFETY_CHECK.getCode())) {
+                if (data.size() > 0) {
                     Map<String, List<PanelListVo>> groupedItems = data.stream()
                             .collect(Collectors.groupingBy(PanelListVo::getTaskName));
-                    List<PanelListVo> tempData=new ArrayList<>();
+                    List<PanelListVo> tempData = new ArrayList<>();
 
                     for (Map.Entry<String, List<PanelListVo>> entry : groupedItems.entrySet()) {
-                        PanelListVo parentItem=new PanelListVo();
-                        BeanUtils.copyProperties(entry.getValue().get(0),parentItem);
+                        PanelListVo parentItem = new PanelListVo();
+                        BeanUtils.copyProperties(entry.getValue().get(0), parentItem);
                         parentItem.setUncompleted(entry.getValue());
                         tempData.add(parentItem);
                     }
                     vo.setDataList(tempData);
-                }
-                else {
+                } else {
                     vo.setDataList(data);
                 }
-            }
-            else {
+            } else {
 
                 vo.setDataList(data);
             }
@@ -226,16 +234,13 @@ public class PanelServiceImpl implements PanelService {
 
     @Override
     public List<UserUnDoVo> selectUserUnDoList(List<UserUnDoTaskRequestDto> userList) throws ExecutionException, InterruptedException, TimeoutException {
-        List<UserUnDoVo> result=new ArrayList<>();
-        if(ObjectUtil.isNotEmpty(userList))
-        {
-            userList.forEach(user->{
+        List<UserUnDoVo> result = new ArrayList<>();
+        if (ObjectUtil.isNotEmpty(userList)) {
+            userList.forEach(user -> {
                 try {
-                    UserUnDoVo tempVo= getUserUnDo(user.getUserId(),user.getOrgId());
+                    UserUnDoVo tempVo = getUserUnDo(user.getUserId(), user.getOrgId());
                     result.add(tempVo);
-                }
-                catch (Exception ex)
-                {
+                } catch (Exception ex) {
 
                 }
             });
@@ -243,14 +248,13 @@ public class PanelServiceImpl implements PanelService {
         return result;
     }
 
-    private UserUnDoVo getUserUnDo(Long userId,Long orgId) throws ExecutionException, InterruptedException, TimeoutException
-    {
-        UserUnDoVo vo =new UserUnDoVo();
-        List<PanelResultVo> unDoTaskList = getListByUserId(userId,orgId);
+    private UserUnDoVo getUserUnDo(Long userId, Long orgId) throws ExecutionException, InterruptedException, TimeoutException {
+        UserUnDoVo vo = new UserUnDoVo();
+        List<PanelResultVo> unDoTaskList = getListByUserId(userId, orgId);
         vo.setUserId(userId);
-        vo.setHaveUnDoTask(unDoTaskList.size()>0);
+        vo.setHaveUnDoTask(unDoTaskList.size() > 0);
 //        vo.setUnDoTaskList(unDoTaskList);
-        return  vo;
+        return vo;
     }
 
 
@@ -350,14 +354,13 @@ public class PanelServiceImpl implements PanelService {
         req.setOrgId(sysOrg.getId());
         final TableDataInfo tableDataInfo = materialsService.selectPage(req);
         final List<SysLearningMaterialsPageVo> rows = tableDataInfo.getRows();
-        List<SysLearningMaterialsPageVo> resultList=new ArrayList<>();
+        List<SysLearningMaterialsPageVo> resultList = new ArrayList<>();
         if (ObjectUtil.isEmpty(rows)) {
             hashMap.put("index2", new ArrayList<>());
         } else {
 //            List<String> fileLit = new ArrayList<>();
             for (SysLearningMaterialsPageVo vo : rows) {
-                if(vo.getIsOpen().equals(0))
-                {
+                if (vo.getIsOpen().equals(0)) {
                     continue;
                 }
                 final String json = vo.getFileList();
@@ -365,9 +368,9 @@ public class PanelServiceImpl implements PanelService {
                     continue;
                 }
                 List<FileObject> objects = new ArrayList<>();
-                List<String> lista =  com.alibaba.fastjson2.JSON.parseArray(json, String.class);
-                for(String str:lista){
-                    FileObject object = JSONObject.parseObject(str,FileObject.class);
+                List<String> lista = com.alibaba.fastjson2.JSON.parseArray(json, String.class);
+                for (String str : lista) {
+                    FileObject object = JSONObject.parseObject(str, FileObject.class);
                     objects.add(object);
                 }
                 vo.setFileObjectList(objects);

+ 45 - 27
soc-modules/soc-modules-core/src/main/java/com/xunmei/core/question/service/impl/QuestionServiceImpl.java

@@ -12,7 +12,9 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.xunmei.common.core.constant.CacheConstants;
 import com.xunmei.common.core.constant.DictConstants;
+import com.xunmei.common.core.constant.ErrorMsgConstants;
 import com.xunmei.common.core.constant.SecurityConstants;
 import com.xunmei.common.core.domain.panel.dto.PanelListDto;
 import com.xunmei.common.core.domain.panel.enums.PanelTypeEnums;
@@ -21,6 +23,7 @@ import com.xunmei.common.core.domain.panel.vo.WebPanelResult;
 import com.xunmei.common.core.exception.ServiceException;
 import com.xunmei.common.core.utils.EasyExcelStyleUtils;
 import com.xunmei.common.core.web.page.TableDataInfo;
+import com.xunmei.common.redis.utils.RedisUtils;
 import com.xunmei.common.security.utils.DictUtils;
 import com.xunmei.common.security.utils.SecurityUtils;
 import com.xunmei.core.question.QuestionConfirmEnum;
@@ -42,6 +45,9 @@ import com.xunmei.core.safetyCheck.domain.CoreSafetyTaskDataRemarkimg;
 import com.xunmei.core.safetyCheck.service.ICoreSafetyTaskDataRemarkimgService;
 import com.xunmei.system.api.RemoteOrgService;
 import com.xunmei.system.api.RemoteUserService;
+import com.xunmei.system.api.domain.SysOrg;
+import com.xunmei.system.api.function.RemoteCallHandlerExecutor;
+import com.xunmei.system.api.vo.SysOrgVO;
 import io.netty.util.internal.StringUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.poi.ss.usermodel.BorderStyle;
@@ -54,9 +60,7 @@ import org.springframework.transaction.annotation.Propagation;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.servlet.http.HttpServletResponse;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
+import java.util.*;
 import java.util.stream.Collectors;
 
 import static org.apache.poi.ss.usermodel.BorderStyle.*;
@@ -342,7 +346,7 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
      */
     @Override
     public WebPanelResult selectWebIndexData(PanelListDto req) {
-        Long confirmButton = 2353L;
+        String confirmButton = "question:list:confirm";
         LambdaQueryWrapper<Question> wrapper = generateCurUserTaskWrapper(req, confirmButton, null, null);
         int waitConfirm = 0;
         if (!wrapper.isEmptyOfWhere()) {
@@ -366,7 +370,7 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
      */
     @Override
     public WebPanelResult selectWebIndexData2(PanelListDto req) {
-        LambdaQueryWrapper<Question> wrapper = generateCurUserTaskWrapper(req, null, null, 2355L);
+        LambdaQueryWrapper<Question> wrapper = generateCurUserTaskWrapper(req, null, null, "question:reform:reform");
         int waitRectification = 0;
         if (!wrapper.isEmptyOfWhere()) {
             waitRectification = baseMapper.selectCount(wrapper).intValue();
@@ -404,43 +408,47 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
      */
     @Override
     public List<PanelListVo> selectCurUserTaskList(PanelListDto panelListDto) {
-        Long confirmButton = 2353L;
+        /**
+         * kkk
+         *question:list:confirm
+         * question:list:confirmDissent
+         * question:reform:reform
+         */
+        String confirmKey = "question:list:confirm";
+        String confirmDissentKey = "question:list:confirmDissent";
+        String reformKey = "question:reform:reform";
+ /*       Long confirmButton = 2353L;
         Long dissentButton = 2354L;
-        Long reformButton = 2355L;
-        return selectCurUserTaskList(panelListDto, confirmButton, dissentButton, reformButton);
+        Long reformButton = 2355L;*/
+        return selectCurUserTaskList(panelListDto, confirmKey, confirmDissentKey, reformKey);
     }
 
-    private LambdaQueryWrapper<Question> generateCurUserTaskWrapper(PanelListDto panelListDto, Long confirmButton, Long dissentButton, Long reformButton) {
+    private LambdaQueryWrapper<Question> generateCurUserTaskWrapper(PanelListDto panelListDto, String confirmButton, String dissentButton, String reformButton) {
         LambdaQueryWrapper<Question> wrapper = new LambdaQueryWrapper<>();
-        List<Long> btns = new ArrayList<>();
-        if (ObjectUtil.isNotNull(confirmButton)) {
-            btns.add(confirmButton);
-        }
-        if (ObjectUtil.isNotNull(dissentButton)) {
-            btns.add(dissentButton);
-        }
-        if (ObjectUtil.isNotNull(reformButton)) {
-            btns.add(reformButton);
-        }
+        boolean isCheckSub = ObjectUtil.isNull(confirmButton) &&
+                ObjectUtil.isNull(dissentButton) &&
+                ObjectUtil.isNull(reformButton);
 
-        if (ObjectUtil.isEmpty(btns)) {
-            throw new ServiceException("至少需要一个按钮权限");
+        if (isCheckSub) {
+            throw new ServiceException("至少需要一个按钮权限: confirmButton, dissentButton, reformButton 均为 null");
         }
 
 //        if (!ObjectUtil.equal(userId, SecurityUtils.getUserId())) {
 //            log.error("用户id不一致:" + userId + "-" + SecurityUtils.getUserId());
 //        }
+        Set<String> permissions = SecurityUtils.getLoginUser().getPermissions();
+        // permissions 包含字符串
 
-        List<Long> ownPermission = remoteUserService.checkUserPermission(btns, panelListDto.getUserId(), SecurityConstants.INNER);
-        if (ownPermission.contains(reformButton)) {
+        /*List<Long> ownPermission = remoteUserService.checkUserPermission(btns, panelListDto.getUserId(), SecurityConstants.INNER);*/
+        if (permissions.contains(reformButton)) {
             wrapper.or(w -> w.eq(Question::getOrgId, panelListDto.getOrgId()).eq(Question::getReformStatus, QuestionReformEnum.Unreform.getValue()));
         }
 
-        if (ownPermission.contains(confirmButton)) {
+        if (permissions.contains(confirmButton)) {
             wrapper.or(w -> w.eq(Question::getOrgId, panelListDto.getOrgId()).eq(Question::getConfirmStatus, QuestionConfirmEnum.Unconfirm.getValue()));
         }
 
-        if (ownPermission.contains(dissentButton)) {
+        if (permissions.contains(dissentButton)) {
             wrapper.or(w -> w.eq(Question::getSubmitorId, panelListDto.getUserId())
                     .eq(Question::getConfirmStatus, QuestionConfirmEnum.Dissent.getValue()));
         }
@@ -448,12 +456,13 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
         return wrapper;
     }
 
-    private List<PanelListVo> selectCurUserTaskList(PanelListDto panelListDto, Long confirmButton, Long dissentButton, Long reformButton) {
+    private List<PanelListVo> selectCurUserTaskList(PanelListDto panelListDto, String confirmButton, String dissentButton, String reformButton) {
         LambdaQueryWrapper<Question> wrapper = generateCurUserTaskWrapper(panelListDto, confirmButton, dissentButton, reformButton);
         wrapper.orderByAsc(Question::getConfirmStatus).orderByDesc(Question::getReformDeadline);
         if (wrapper.isEmptyOfWhere()) {
             return new ArrayList<>();
         } else {
+
             wrapper.select(Question::getId,
                     Question::getQuestionDesc,
                     Question::getOrgId,
@@ -465,7 +474,16 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
             List<PanelListVo> vos = list.stream().map(item -> {
                 PanelListVo vo = new PanelListVo();
                 vo.setId(item.getId());
-                vo.setOrgName( orgService.concatOrgName(item.getOrgId(),SecurityConstants.INNER));
+                String concatOrgName =null;
+                String cacheKey=CacheConstants.ORG_CACHE_CONCAT_NAME+item.getOrgId().toString();
+                if(RedisUtils.hasKey(cacheKey))
+                {
+                    concatOrgName= RedisUtils.getCacheObject(cacheKey);
+                }
+                else {
+                    concatOrgName =  orgService.concatOrgName(item.getOrgId(),SecurityConstants.INNER);
+                }
+                vo.setOrgName(concatOrgName);
                 vo.setEndTime(item.getReformDeadline());
                 vo.setTaskName(item.getQuestionDesc());
                 vo.setStartTime(item.getSubmitTime());

+ 1 - 0
soc-modules/soc-modules-core/src/main/java/com/xunmei/core/resumption/gx/service/ResumptionServiceImpl.java

@@ -197,6 +197,7 @@ public class ResumptionServiceImpl implements ResumptionService {
                     if (ObjectUtil.isNull(point.getRectificationDeadline()) || !NumberUtil.isNumber(point.getRectificationDeadline())) {
                         throw new ServiceException("整改期限为空或不是有效的数值");
                     }
+                    //TODO 获取机构数据,应从缓存中获取
                     SysOrg org = remoteOrgService.selectSysOrgById(sysResumption.getOrgId(), SecurityConstants.INNER);
 
                     Question question = Question.builder()

+ 11 - 1
soc-modules/soc-modules-core/src/main/java/com/xunmei/core/weather/service/impl/WeatherWarningServiceImpl.java

@@ -11,6 +11,7 @@ import com.alibaba.fastjson.TypeReference;
 import com.alibaba.nacos.common.utils.CollectionUtils;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.xunmei.common.core.constant.CacheConstants;
 import com.xunmei.common.core.constant.ErrorMsgConstants;
 import com.xunmei.common.core.constant.SecurityConstants;
 import com.xunmei.common.core.constant.SystemParameterConstant;
@@ -21,6 +22,7 @@ import com.xunmei.common.core.domain.weather.vo.CityInfoVo;
 import com.xunmei.common.core.domain.weather.vo.SelectCityInfoVo;
 import com.xunmei.common.core.utils.KeyValue;
 import com.xunmei.common.core.web.page.TableDataInfo;
+import com.xunmei.common.redis.utils.RedisUtils;
 import com.xunmei.core.weather.mapper.WeatherWarningMapper;
 import com.xunmei.core.weather.service.IWeatherWarningService;
 import com.xunmei.core.weather.utils.HttpUtils;
@@ -177,7 +179,15 @@ public class WeatherWarningServiceImpl extends ServiceImpl<WeatherWarningMapper,
 
     @Override
     public List<WeatherWarning> getTheAreaWeather(Long orgId) {
-        SysOrgExtend orgExtend = RemoteCallHandlerExecutor.executeRemoteCall(() -> orgService.selectSysOrgExtendById(orgId, SecurityConstants.INNER), ErrorMsgConstants.QUERY_ORG_DATA_ERROR);
+        SysOrgExtend orgExtend =null;
+        String cacheKey= CacheConstants.ORG_EXTEND_CACHE_CONCAT_INFO+orgId.toString();
+        if(RedisUtils.hasKey(cacheKey))
+        {
+            orgExtend= RedisUtils.getCacheObject(cacheKey);
+        }
+        else {
+            orgExtend = RemoteCallHandlerExecutor.executeRemoteCall(() -> orgService.selectSysOrgExtendById(orgId, SecurityConstants.INNER), ErrorMsgConstants.QUERY_ORG_DATA_ERROR);
+        }
         List<WeatherWarning> list = null;
         if(ObjectUtil.isNotEmpty(orgExtend)){
             String key = "wearth_areaid_"+orgExtend.getWeatherAreaCode();

+ 3 - 0
soc-modules/soc-modules-system/src/main/java/com/xunmei/system/SocSystemApplication.java

@@ -11,6 +11,8 @@ import org.springframework.context.annotation.Bean;
 import org.springframework.scheduling.annotation.EnableAsync;
 import org.springframework.web.client.RestTemplate;
 
+import javax.annotation.PostConstruct;
+
 /**
  * 系统模块
  * 
@@ -35,4 +37,5 @@ public class SocSystemApplication
     public RestTemplate restTemplate(){
         return new RestTemplate();
     }
+
 }

+ 93 - 0
soc-modules/soc-modules-system/src/main/java/com/xunmei/system/controller/CacheController.java

@@ -0,0 +1,93 @@
+package com.xunmei.system.controller;
+
+import com.xunmei.common.core.constant.CacheConstants;
+import com.xunmei.common.redis.utils.RedisUtils;
+import com.xunmei.system.service.ExportSqlService;
+import com.xunmei.system.service.ISysOrgService;
+import com.xunmei.system.service.ISysUserService;
+import io.swagger.annotations.Api;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.servlet.http.HttpServletResponse;
+import java.util.List;
+
+@Slf4j
+@Api(description = "中台", tags = {"清理缓存工具"})
+@RestController
+@RequestMapping("/cache")
+public class CacheController {
+
+    @Autowired
+    private ISysOrgService sysOrgService;
+
+    @Autowired
+    private ISysUserService userService;
+
+    @GetMapping("/clean/org")
+    public Object cleanOrgCache(){
+        try {
+            sysOrgService.clearOrgCache();
+            return "清理成功";
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    @GetMapping("/clean/user")
+    public Object cleanUserCache(){
+        try {
+            userService.clearUserCache();
+            return "清理成功";
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    @GetMapping("/clean/role")
+    public Object cleanRoleCache(){
+        try {
+            RedisUtils.deleteByPrefix(CacheConstants.ROLE_PERMISSION_CACHE_KEY);
+            RedisUtils.deleteByPrefix(CacheConstants.USER_ROLE_PERMISSION_CACHE_KEY);
+            return "清理成功";
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    /**
+     * 清楚新增的所有缓存 (清除为优化性能 新增的缓存)
+     */
+    @GetMapping("/clean/all")
+    public Object cleanAllCache(){
+        try {
+            //用户
+            RedisUtils.deleteByPrefix(CacheConstants.USER_CACHE_SINGLE_KEY);
+            RedisUtils.deleteByPrefix(CacheConstants.USER_CACHE_ROLE_ID_KEY);
+            RedisUtils.deleteByPrefix(CacheConstants.USER_CACHE_ROLE_OBJECT_KEY);
+            RedisUtils.deleteByPrefix(CacheConstants.USER_ROLE_PERMISSION_CACHE_KEY);
+            //机构
+            RedisUtils.deleteByPrefix(CacheConstants.ORG_CACHE_SINGLE_KEY);
+            RedisUtils.deleteByPrefix(CacheConstants.ORG_CACHE_CONCAT_NAME);
+            RedisUtils.deleteByPrefix(CacheConstants.ORG_EXTEND_CACHE_CONCAT_INFO);
+            RedisUtils.deleteByPrefix(CacheConstants.DEPT_TREE_CACHE_SINGLE_KEY);
+            RedisUtils.deleteByPrefix(CacheConstants.DEPT_HANGSHE_TREE_CACHE_SINGLE_KEY);
+            //角色对应的权限字段
+            RedisUtils.deleteByPrefix(CacheConstants.ROLE_PERMISSION_CACHE_KEY);
+            return "清理成功";
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+
+
+
+
+
+
+}

+ 20 - 2
soc-modules/soc-modules-system/src/main/java/com/xunmei/system/controller/SysDeptController.java

@@ -4,6 +4,7 @@ import cn.hutool.core.util.ObjectUtil;
 import com.alibaba.excel.EasyExcel;
 import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.xunmei.common.core.constant.CacheConstants;
 import com.xunmei.common.core.constant.Constants;
 import com.xunmei.common.core.domain.OrgTreeReq;
 import com.xunmei.common.core.domain.OrgTreeResp;
@@ -14,6 +15,7 @@ import com.xunmei.common.core.web.controller.BaseController;
 import com.xunmei.common.core.web.domain.AjaxResult;
 import com.xunmei.common.log.annotation.Log;
 import com.xunmei.common.log.enums.BusinessType;
+import com.xunmei.common.redis.utils.RedisUtils;
 import com.xunmei.common.security.annotation.InnerAuth;
 import com.xunmei.common.security.annotation.RequiresPermissions;
 import com.xunmei.common.security.utils.SecurityUtils;
@@ -40,6 +42,7 @@ import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletResponse;
 import java.net.URLEncoder;
+import java.time.Duration;
 import java.util.ArrayList;
 import java.util.Comparator;
 import java.util.Date;
@@ -334,7 +337,15 @@ public class SysDeptController extends BaseController {
 
     @GetMapping("/selectSysOrgById")
     public SysOrg selectSysOrgById(Long id) {
-        return orgService.getById(id);
+        String cacheKey=CacheConstants.ORG_CACHE_SINGLE_KEY+id.toString();
+        if(RedisUtils.hasKey(cacheKey))
+        {
+            return RedisUtils.getCacheObject(cacheKey);
+        }
+        SysOrg org =  orgService.getById(id);
+        RedisUtils.setCacheObject(cacheKey,org,Duration.ofSeconds(CacheConstants.ORG_USER_EXPIRATION_TIME));
+        return org;
+
     }
 
     @GetMapping("/listByIds")
@@ -552,7 +563,14 @@ public class SysDeptController extends BaseController {
     @InnerAuth
     @GetMapping("/concatOrgName/{orgId}")
     String concatOrgName(@PathVariable("orgId") Long orgId){
-        return orgService.concatOrgName(orgId);
+        String cacheKey=CacheConstants.ORG_CACHE_CONCAT_NAME+orgId.toString();
+        if(RedisUtils.hasKey(cacheKey))
+        {
+            return RedisUtils.getCacheObject(cacheKey);
+        }
+        String concatOrgName =  orgService.concatOrgName(orgId);
+        RedisUtils.setCacheObject(cacheKey,concatOrgName,Duration.ofSeconds(CacheConstants.ORG_USER_EXPIRATION_TIME));
+        return concatOrgName;
     }
 
     @GetMapping("/findDisableOrgAndClearData")

+ 1 - 1
soc-modules/soc-modules-system/src/main/java/com/xunmei/system/controller/SysMenuController.java

@@ -103,7 +103,7 @@ public class SysMenuController extends BaseController {
             return error("修改菜单'" + menu.getMenuName() + "'失败,上级菜单不能选择自己");
         }
         menu.setUpdateBy(SecurityUtils.getUsername());
-        //menuService.clearCacheMenu();
+        menuService.clearCacheMenu();
         return toAjax(menuService.updateMenu(menu));
     }
 

+ 4 - 1
soc-modules/soc-modules-system/src/main/java/com/xunmei/system/controller/SysOrgController.java

@@ -3,6 +3,7 @@ package com.xunmei.system.controller;
 import cn.hutool.core.util.NumberUtil;
 import cn.hutool.core.util.ObjectUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.xunmei.common.core.constant.CacheConstants;
 import com.xunmei.common.core.domain.R;
 import com.xunmei.common.core.vo.IdNameVo;
 import com.xunmei.common.core.web.controller.BaseController;
@@ -10,6 +11,7 @@ import com.xunmei.common.core.web.domain.AjaxResult;
 import com.xunmei.common.core.web.page.TableDataInfo;
 import com.xunmei.common.log.annotation.Log;
 import com.xunmei.common.log.enums.BusinessType;
+import com.xunmei.common.redis.utils.RedisUtils;
 import com.xunmei.common.security.annotation.InnerAuth;
 import com.xunmei.common.security.annotation.RequiresPermissions;
 import com.xunmei.system.api.domain.SysOrg;
@@ -20,6 +22,7 @@ import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import java.time.Duration;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
@@ -131,7 +134,7 @@ public class SysOrgController extends BaseController {
     @InnerAuth
     @GetMapping("/{orgId}")
     public SysOrg selectSysOrgById(@PathVariable("orgId") Long orgId) {
-        return sysOrgService.getById(orgId);
+        return sysOrgService.selectSysOrgById(orgId);
     }
 
     /**

+ 37 - 10
soc-modules/soc-modules-system/src/main/java/com/xunmei/system/controller/SysUserController.java

@@ -7,6 +7,7 @@ import com.alibaba.excel.event.AnalysisEventListener;
 import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.xunmei.common.core.domain.R;
 import com.xunmei.common.core.domain.message.domain.CoreAnnouncementNotificationToRole;
 import com.xunmei.common.core.domain.reminder.dto.CoreReminderUserQueryDto;
@@ -80,6 +81,9 @@ public class SysUserController extends BaseController {
     @Autowired
     private SysOrgMapper orgMapper;
 
+    @Autowired
+    private ISysOrgService sysOrgService;
+
     /**
      * 获取用户列表
      */
@@ -150,14 +154,18 @@ public class SysUserController extends BaseController {
             return R.fail("用户名或密码错误");
         }
         //获取当前用户的角色数据。
-        List<SysRole> sysRoles = roleService.selectRolesByUserId(sysUser.getId());
-        sysUser.setRoles(sysRoles);
+   /*     List<SysRole> sysRoles = roleService.selectRolesByUserId(sysUser.getId());
+        sysUser.setRoles(sysRoles);*/
 
         // 角色集合
         Set<String> roles = permissionService.getRolePermission(sysUser);
         // 权限集合
         Set<String> permissions = permissionService.getMenuPermission(sysUser);
+        // 获取机构数据
+        SysOrg sysOrg = orgMapper.selectById(sysUser.getOrgId());
+
         LoginUser sysUserVo = new LoginUser();
+        sysUserVo.setSysOrg(sysOrg);
         sysUserVo.setOrgId(sysUser.getOrgId());
         sysUserVo.setName(sysUser.getName());
         sysUserVo.setSource(sysUser.getSource());
@@ -191,9 +199,11 @@ public class SysUserController extends BaseController {
     @GetMapping("getInfo")
     public AjaxResult getInfo() {
         SysUser user = userService.selectUserById(SecurityUtils.getUserId());
-        SysOrg org = orgMapper.selectOne(new LambdaQueryWrapper<SysOrg>()
-                .eq(SysOrg::getId, user.getOrgId())
-                .select(SysOrg::getType, SysOrg::getShortName, SysOrg::getPath));
+
+        SysOrg org = sysOrgService.selectSysOrgById(user.getOrgId());
+//        SysOrg org = orgMapper.selectOne(new LambdaQueryWrapper<SysOrg>()
+//                .eq(SysOrg::getId, user.getOrgId())
+//                .select(SysOrg::getType, SysOrg::getShortName, SysOrg::getPath));
         if (ObjectUtil.isNotEmpty(org)) {
             user.setOrgType(org.getType());
             user.setOrgShortName(org.getShortName());
@@ -364,6 +374,8 @@ public class SysUserController extends BaseController {
         }
 //        user.setOriginalOrgId(user.getOrgId());
         user.setUpdateBy(SecurityUtils.getUsername());
+        userService.clearUserCacheByUserId(user.getId());
+        userService.clearUserCacheByUserName(user.getUsername());
         return toAjax(userService.updateUser(user));
     }
 
@@ -393,6 +405,8 @@ public class SysUserController extends BaseController {
         user.setSalt(salt);
         user.setPassword(SecurityUtils.encryptPassword(user.getPassword(), salt));
         user.setUpdateBy(SecurityUtils.getUsername());
+        userService.clearUserCacheByUserId(user.getId());
+        userService.clearUserCacheByUserName(user.getUsername());
         return toAjax(userService.resetPwd(user));
     }
 
@@ -406,6 +420,8 @@ public class SysUserController extends BaseController {
         userService.checkUserAllowed(user);
         userService.checkUserDataScope(user.getId());
         user.setUpdateBy(SecurityUtils.getUsername());
+        userService.clearUserCacheByUserId(user.getId());
+        userService.clearUserCacheByUserName(user.getUsername());
         return toAjax(userService.updateUserStatus(user));
     }
 
@@ -473,14 +489,23 @@ public class SysUserController extends BaseController {
     @ApiOperation(value = "记录用户最后一次登录")
     @InnerAuth
     @PostMapping("/userLoginInfo")
-    public R<Boolean> userLoginInfo(Long id, Date loginTime, String loginIp) {
-        SysUser sysUser = userService.selectUserById(id);
-        sysUser.setLastIp(loginIp);
+    public R<Boolean> userLoginInfo(Long id, Date loginTime, String loginIp) throws InterruptedException {
+        // 为减少查询,直接更新
+//        SysUser sysUser = userService.selectUserById(id);
+//        sysUser.setLastIp(loginIp);
+//        if (null == loginTime) {
+//            loginTime = DateUtils.getNowDate();
+//        }
+//        sysUser.setLastTime(loginTime);
+
         if (null == loginTime) {
             loginTime = DateUtils.getNowDate();
         }
-        sysUser.setLastTime(loginTime);
-        userService.saveOrUpdate(sysUser);
+        LambdaUpdateWrapper<SysUser> wrapper =new LambdaUpdateWrapper<>();
+        wrapper.eq(SysUser::getId,id);
+        wrapper.set(SysUser::getLastTime,loginTime);
+        wrapper.set(SysUser::getLastIp,loginIp);
+        userService.update(wrapper);
         return R.ok(true);
     }
 
@@ -784,6 +809,8 @@ public class SysUserController extends BaseController {
         SysUser updateUser = new SysUser();
         updateUser.setId(SecurityUtils.getUserId());
         updateUser.setSignatureSeal(user.getSignatureSeal());
+        userService.clearUserCacheByUserId(SecurityUtils.getUserId());
+        userService.clearUserCacheByUserName(SecurityUtils.getUsername());
         return toAjax(userService.updateById(updateUser));
     }
 

+ 11 - 4
soc-modules/soc-modules-system/src/main/java/com/xunmei/system/controller/SysUserRoleController.java

@@ -1,9 +1,10 @@
 package com.xunmei.system.controller;
 
+import java.time.Duration;
 import java.util.List;
-import java.io.IOException;
-import javax.servlet.http.HttpServletResponse;
 
+import com.xunmei.common.core.constant.CacheConstants;
+import com.xunmei.common.redis.utils.RedisUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 import com.xunmei.common.log.annotation.Log;
@@ -15,7 +16,6 @@ import com.xunmei.common.core.web.controller.BaseController;
 import com.xunmei.common.core.web.domain.AjaxResult;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.xunmei.common.core.web.page.TableDataInfo;
 
 /**
@@ -89,6 +89,13 @@ public class SysUserRoleController extends BaseController {
 
     @GetMapping("/getUserRoleId")
     List<Long> getUserRoleId(@RequestParam(value = "userId") Long userId) {
-        return sysUserRoleService.getUserRoleId(userId);
+        String cacheKey= CacheConstants.USER_CACHE_ROLE_ID_KEY +userId.toString();
+        if(RedisUtils.hasKey(cacheKey))
+        {
+            return RedisUtils.getCacheObject(cacheKey);
+        }
+        List<Long> roleIds= sysUserRoleService.getUserRoleId(userId);
+        RedisUtils.setCacheObject(cacheKey,roleIds, Duration.ofSeconds(CacheConstants.ORG_USER_EXPIRATION_TIME));
+        return roleIds;
     }
 }

+ 3 - 0
soc-modules/soc-modules-system/src/main/java/com/xunmei/system/service/ISysMenuService.java

@@ -144,4 +144,7 @@ public interface ISysMenuService extends IService<SysMenu>
      * @return 结果
      */
     boolean checkMenuNameUnique(SysMenu menu);
+
+    void clearCacheMenu();
+
 }

+ 5 - 0
soc-modules/soc-modules-system/src/main/java/com/xunmei/system/service/ISysUserService.java

@@ -273,4 +273,9 @@ public interface ISysUserService extends IService<SysUser> {
     void insertUserMapper(Long masterUserId, Long[] mapperUserIds,Integer userSource);
 
     void importRole(MultipartFile file, HttpServletResponse response);
+
+    void clearUserCache();
+    void clearUserCacheByUserId(Long userId);
+
+    void clearUserCacheByUserName(String userName);
 }

+ 59 - 5
soc-modules/soc-modules-system/src/main/java/com/xunmei/system/service/impl/SysDeptServiceImpl.java

@@ -34,6 +34,7 @@ import org.apache.commons.lang3.ObjectUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.time.Duration;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -117,9 +118,43 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
      */
     @Override
     public List<SysOrgVO> selectDeptTreeList(SysOrg dept) {
-        Long s = System.currentTimeMillis();
-        SysOrg sysOrg = null;
-        sysOrg = getLoginUserOrg();
+        SysOrg sysOrg = getLoginUserOrg();
+        String removeId="";
+        if(ObjectUtil.isNotNull(dept.getRemoveId()) ){
+            removeId="_"+dept.getRemoveId().toString();
+        }
+        String cacheKey=CacheConstants.DEPT_TREE_CACHE_SINGLE_KEY+sysOrg.getId().toString()+removeId;
+        if(RedisUtils.hasKey(cacheKey))
+        {
+            return RedisUtils.getCacheObject(cacheKey);
+        }
+        List<SysOrgVO> orgs = buildDeptTreeList(sysOrg,dept);
+        RedisUtils.setCacheObject(cacheKey,orgs, Duration.ofSeconds(CacheConstants.ORG_USER_EXPIRATION_TIME));
+        return orgs;
+
+//        List<SysOrgVO> cacheList = getOrgCache();
+//        List<SysOrgVO> orgs = new ArrayList<>();
+//        for (SysOrgVO org : cacheList) {
+//            String path = org.getPath();
+//            if (StringUtils.isEmpty(path) || !path.startsWith(sysOrg.getPath())) {
+//                continue;
+//            }
+//
+//            if (StringUtils.isEmpty(org.getShortName())) {
+//                org.setShortName(org.getName());
+//            }
+//            if (org.getSort() == null) {
+//                org.setSort(100000);
+//            }
+//            orgs.add(org);
+//        }
+//        if (dept.getRemoveId() != null) {
+//            orgs.removeIf(d -> d.getTreeShowPath().endsWith(dept.getId() + "-"));
+//        }
+//        return generateTree(orgs, sysOrg);
+    }
+
+    private List<SysOrgVO> buildDeptTreeList(SysOrg sysOrg,SysOrg dept){
         List<SysOrgVO> cacheList = getOrgCache();
         List<SysOrgVO> orgs = new ArrayList<>();
         for (SysOrgVO org : cacheList) {
@@ -150,12 +185,20 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
      */
     @Override
     public List<SysOrgVO> selectTreeByOrgType(Boolean includeUp, Boolean includeBangshichu, OrgTypeEnum orgType) {
+
+
         String path = "";
         SysOrg sysOrg = getLoginUserOrg();
         path = sysOrg.getPath();
+        Long orgId=sysOrg.getId();
         if (includeUp) {
             sysOrg = null;
         }
+        String cacheKey=CacheConstants.DEPT_HANGSHE_TREE_CACHE_SINGLE_KEY+orgId.toString()+"_"+includeUp.toString()+"_"+includeBangshichu.toString();
+        if(RedisUtils.hasKey(cacheKey))
+        {
+            return RedisUtils.getCacheObject(cacheKey);
+        }
 
         List<SysOrgVO> orglist = getWholePathInCache(includeUp, path, orgType);
         if (!includeBangshichu) {
@@ -163,6 +206,7 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
                     .collect(Collectors.toList());
         }
         List<SysOrgVO> r = generateTree(orglist, sysOrg);
+        RedisUtils.setCacheObject(cacheKey,r, Duration.ofSeconds(CacheConstants.ORG_USER_EXPIRATION_TIME));
         return r;
     }
 
@@ -384,8 +428,18 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
     }
 
     private SysOrg getLoginUserOrg() {
-        Long userId = SecurityUtils.getUserId();
-        SysOrg sysOrg = orgMapper.selectSysOrgByUserId(userId);
+        Long orgId= SecurityUtils.getLoginUser().getOrgId();
+        SysOrg sysOrg =null;
+        if(ObjectUtil.isNotNull(orgId))
+        {
+            // 有缓存
+            sysOrg=orgService.selectSysOrgById(orgId);
+        }
+        else{
+            Long userId = SecurityUtils.getUserId();
+            sysOrg = orgMapper.selectSysOrgByUserId(userId);
+        }
+
         if (ObjectUtil.isNull(sysOrg)) {
             throw new ServiceException("当前用户没有机构信息");
         }

+ 22 - 0
soc-modules/soc-modules-system/src/main/java/com/xunmei/system/service/impl/SysMenuServiceImpl.java

@@ -3,10 +3,12 @@ package com.xunmei.system.service.impl;
 import cn.hutool.core.util.ObjectUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.xunmei.common.core.constant.CacheConstants;
 import com.xunmei.common.core.constant.Constants;
 import com.xunmei.common.core.constant.UserConstants;
 import com.xunmei.common.core.utils.IDHelper;
 import com.xunmei.common.core.utils.StringUtils;
+import com.xunmei.common.redis.utils.RedisUtils;
 import com.xunmei.system.api.domain.SysRole;
 import com.xunmei.system.api.domain.SysUser;
 import com.xunmei.system.domain.SysMenu;
@@ -21,6 +23,7 @@ import com.xunmei.system.service.ISysMenuService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.time.Duration;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -82,6 +85,11 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
      */
     @Override
     public Set<String> selectMenuPermsByUserId(Long userId) {
+        String cacheKey= CacheConstants.USER_ROLE_PERMISSION_CACHE_KEY +userId.toString();
+        if(RedisUtils.hasKey(cacheKey))
+        {
+            return RedisUtils.getCacheObject(cacheKey);
+        }
         List<String> perms = menuMapper.selectMenuPermsByUserId(userId);
         Set<String> permsSet = new HashSet<>();
         for (String perm : perms) {
@@ -89,6 +97,7 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
                 permsSet.addAll(Arrays.asList(perm.trim().split(",")));
             }
         }
+        RedisUtils.setCacheObject(cacheKey,permsSet, Duration.ofSeconds(CacheConstants.ORG_USER_EXPIRATION_TIME));
         return permsSet;
     }
 
@@ -100,6 +109,11 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
      */
     @Override
     public Set<String> selectMenuPermsByRoleId(Long roleId) {
+        String cacheKey= CacheConstants.ROLE_PERMISSION_CACHE_KEY +roleId.toString();
+        if(RedisUtils.hasKey(cacheKey))
+        {
+            return RedisUtils.getCacheObject(cacheKey);
+        }
         List<String> perms = menuMapper.selectMenuPermsByRoleId(roleId);
         Set<String> permsSet = new HashSet<>();
         for (String perm : perms) {
@@ -107,6 +121,8 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
                 permsSet.addAll(Arrays.asList(perm.trim().split(",")));
             }
         }
+        RedisUtils.setCacheObject(cacheKey,permsSet, Duration.ofSeconds(CacheConstants.ORG_USER_EXPIRATION_TIME));
+
         return permsSet;
     }
 
@@ -318,6 +334,12 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
         return UserConstants.UNIQUE;
     }
 
+    @Override
+    public void clearCacheMenu() {
+        RedisUtils.deleteByPrefix(CacheConstants.ROLE_PERMISSION_CACHE_KEY);
+        RedisUtils.deleteByPrefix(CacheConstants.USER_ROLE_PERMISSION_CACHE_KEY);
+    }
+
     /**
      * 获取路由名称
      *

+ 9 - 2
soc-modules/soc-modules-system/src/main/java/com/xunmei/system/service/impl/SysOrgExtendServiceImpl.java

@@ -1,5 +1,6 @@
 package com.xunmei.system.service.impl;
 
+import java.time.Duration;
 import java.util.List;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@@ -9,7 +10,6 @@ import com.xunmei.common.core.utils.DateUtils;
 import com.xunmei.common.core.utils.StringUtils;
 import com.xunmei.common.redis.utils.RedisUtils;
 import com.xunmei.system.api.domain.SysOrg;
-import com.xunmei.system.api.vo.SysOrgVO;
 import com.xunmei.system.domain.SysPhysicalDefenseConstruction;
 import com.xunmei.system.dto.SysOrgExtendDto;
 import com.xunmei.system.mapper.SysOrgMapper;
@@ -93,7 +93,14 @@ public class SysOrgExtendServiceImpl extends ServiceImpl<SysOrgExtendMapper, Sys
 
     @Override
     public SysOrgExtend selectSysOrgExtendByOrgId(Long id) {
-        return sysOrgExtendMapper.selectOne(new QueryWrapper<SysOrgExtend>().eq("org_id", id));
+        String cacheKey=CacheConstants.ORG_EXTEND_CACHE_CONCAT_INFO+id.toString();
+        if(RedisUtils.hasKey(cacheKey))
+        {
+            return RedisUtils.getCacheObject(cacheKey);
+        }
+        SysOrgExtend sysOrgExtend = sysOrgExtendMapper.selectOne(new QueryWrapper<SysOrgExtend>().eq("org_id", id));
+        RedisUtils.setCacheObject(cacheKey, sysOrgExtend, Duration.ofSeconds(CacheConstants.ORG_USER_EXPIRATION_TIME));
+        return sysOrgExtend;
     }
 
     /**

+ 16 - 1
soc-modules/soc-modules-system/src/main/java/com/xunmei/system/service/impl/SysOrgServiceImpl.java

@@ -56,6 +56,7 @@ import javax.annotation.PostConstruct;
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 import java.net.URLEncoder;
+import java.time.Duration;
 import java.time.LocalDate;
 import java.util.*;
 import java.util.concurrent.TimeUnit;
@@ -623,7 +624,14 @@ public class SysOrgServiceImpl extends ServiceImpl<SysOrgMapper, SysOrg> impleme
      */
     @Override
     public SysOrg selectSysOrgById(Long id) {
-        return sysOrgMapper.selectById(id);
+        String cacheKey=CacheConstants.ORG_CACHE_SINGLE_KEY+id.toString();
+        if(RedisUtils.hasKey(cacheKey))
+        {
+            return RedisUtils.getCacheObject(cacheKey);
+        }
+        SysOrg org =sysOrgMapper.selectById(id);
+        RedisUtils.setCacheObject(cacheKey,org, Duration.ofSeconds(CacheConstants.ORG_USER_EXPIRATION_TIME));
+        return org;
     }
 
     @Override
@@ -839,6 +847,13 @@ public class SysOrgServiceImpl extends ServiceImpl<SysOrgMapper, SysOrg> impleme
         RedisUtils.deleteObject(CacheConstants.ORG_CACHE_LIST_KEY);
         RedisUtils.deleteObject(CacheConstants.HS_ORG_CACHE_LIST_KEY);
         //redisService.deleteObject(CacheConstants.ORG_CACHE_LIST_KEY);
+        RedisUtils.deleteByPrefix(CacheConstants.ORG_CACHE_SINGLE_KEY);
+        RedisUtils.deleteByPrefix(CacheConstants.ORG_CACHE_CONCAT_NAME);
+        RedisUtils.deleteByPrefix(CacheConstants.ORG_EXTEND_CACHE_CONCAT_INFO);
+        RedisUtils.deleteByPrefix(CacheConstants.DEPT_TREE_CACHE_SINGLE_KEY);
+        RedisUtils.deleteByPrefix(CacheConstants.DEPT_HANGSHE_TREE_CACHE_SINGLE_KEY);
+
+
     }
 
     @Override

+ 11 - 1
soc-modules/soc-modules-system/src/main/java/com/xunmei/system/service/impl/SysRoleServiceImpl.java

@@ -30,6 +30,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.PostConstruct;
+import java.time.Duration;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -100,7 +101,13 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
      */
     @Override
     public List<SysRole> selectRolesByUserId(Long userId) {
+        String cacheKey= CacheConstants.USER_CACHE_ROLE_OBJECT_KEY+userId.toString();
+        if(RedisUtils.hasKey(cacheKey))
+        {
+            return RedisUtils.getCacheObject(cacheKey);
+        }
         List<SysRole> userRoles = roleMapper.selectRolePermissionByUserId(userId);
+        RedisUtils.setCacheObject(cacheKey,userRoles, Duration.ofSeconds(CacheConstants.ORG_USER_EXPIRATION_TIME));
         return userRoles;
     }
 
@@ -112,7 +119,8 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
      */
     @Override
     public Set<String> selectRolePermissionByUserId(Long userId) {
-        List<SysRole> perms = roleMapper.selectRolePermissionByUserId(userId);
+//        List<SysRole> perms = roleMapper.selectRolePermissionByUserId(userId);
+        List<SysRole> perms =this.selectRolesByUserId(userId);
         Set<String> permsSet = new HashSet<>();
         for (SysRole perm : perms) {
             if (StringUtils.isNotNull(perm)) {
@@ -519,6 +527,8 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
     @Override
     public void clearRoleCache() {
         RedisUtils.deleteObject(CacheConstants.ROLE_CACHE_LIST_KEY);
+        RedisUtils.deleteByPrefix(CacheConstants.ROLE_PERMISSION_CACHE_KEY);
+        RedisUtils.deleteByPrefix(CacheConstants.USER_ROLE_PERMISSION_CACHE_KEY);
     }
 
     @Override

+ 22 - 1
soc-modules/soc-modules-system/src/main/java/com/xunmei/system/service/impl/SysUserRoleServiceImpl.java

@@ -1,17 +1,21 @@
 package com.xunmei.system.service.impl;
 
+import cn.hutool.core.util.ObjectUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.xunmei.common.core.web.page.TableDataInfo;
+import com.xunmei.system.api.domain.SysRole;
 import com.xunmei.system.domain.SysUserRole;
 import com.xunmei.system.domain.vo.UserRoleVo;
 import com.xunmei.system.mapper.SysUserRoleMapper;
+import com.xunmei.system.service.ISysRoleService;
 import com.xunmei.system.service.ISysUserRoleService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
 import java.util.List;
 
 /**
@@ -25,6 +29,11 @@ public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleMapper, SysUs
     @Autowired
     private SysUserRoleMapper sysUserRoleMapper;
 
+    @Autowired
+    private ISysRoleService sysRoleService;
+
+
+
     @Override
     public TableDataInfo<SysUserRole> selectPage(SysUserRole sysUserRole) {
         Page<SysUserRole> page;
@@ -41,8 +50,20 @@ public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleMapper, SysUs
 
     @Override
     public List<UserRoleVo> selectUserRoleVoList(Long userId) {
+        List<UserRoleVo> resultList=new ArrayList<>();
+        final List<SysRole> sysRoles = sysRoleService.selectRolesByUserId(userId);
+        if(ObjectUtil.isEmpty(sysRoles))
+            return resultList;
 
-        return sysUserRoleMapper.selectUserRoleVoList(userId);
+        for (SysRole role:sysRoles) {
+            UserRoleVo userRoleVo =new UserRoleVo();
+            userRoleVo.setRoleId(role.getId());
+            userRoleVo.setUserId(userId);
+            userRoleVo.setRoleName(role.getRoleName());
+            resultList.add(userRoleVo);
+        }
+        return resultList;
+//        return sysUserRoleMapper.selectUserRoleVoList(userId);
     }
 
     /**

+ 48 - 3
soc-modules/soc-modules-system/src/main/java/com/xunmei/system/service/impl/SysUserServiceImpl.java

@@ -11,6 +11,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.google.common.collect.Lists;
+import com.xunmei.common.core.constant.CacheConstants;
 import com.xunmei.common.core.constant.UserConstants;
 import com.xunmei.common.core.domain.OrgTreeReq;
 import com.xunmei.common.core.domain.OrgTreeResp;
@@ -22,6 +23,7 @@ import com.xunmei.common.core.utils.StringUtils;
 import com.xunmei.common.core.utils.bean.BeanValidators;
 import com.xunmei.common.core.web.page.TableDataInfo;
 import com.xunmei.common.datascope.annotation.DataScope;
+import com.xunmei.common.redis.utils.RedisUtils;
 import com.xunmei.common.security.utils.SecurityUtils;
 import com.xunmei.system.api.domain.SysOrg;
 import com.xunmei.system.api.domain.SysRole;
@@ -40,6 +42,7 @@ import com.xunmei.system.util.SecurityUserExport;
 import com.xunmei.system.util.UserExport;
 import com.xunmei.system.util.UserImport;
 import com.xunmei.system.util.UserImportErrorMsg;
+import org.redisson.api.redisnode.RedisSingle;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -52,6 +55,7 @@ import org.springframework.web.multipart.MultipartFile;
 import javax.servlet.http.HttpServletResponse;
 import javax.validation.Validator;
 import java.net.URLEncoder;
+import java.time.Duration;
 import java.time.LocalDate;
 import java.time.ZoneId;
 import java.time.temporal.ChronoUnit;
@@ -256,7 +260,14 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
      */
     @Override
     public SysUser selectUserByUserName(String userName) {
-        return userMapper.selectOne(new QueryWrapper<SysUser>().eq("username", userName).eq("deleted", 0));
+        String cacheKey= CacheConstants.USER_CACHE_SINGLE_KEY+userName;
+        if(RedisUtils.hasKey(cacheKey))
+        {
+            return RedisUtils.getCacheObject(cacheKey);
+        }
+        SysUser user = userMapper.selectOne(new QueryWrapper<SysUser>().eq("username", userName).eq("deleted", 0));
+        RedisUtils.setCacheObject(cacheKey,user, Duration.ofSeconds(CacheConstants.ORG_USER_EXPIRATION_TIME));
+        return user;
     }
 
     /**
@@ -267,7 +278,14 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
      */
     @Override
     public SysUser selectUserById(Long userId) {
-        return userMapper.selectById(userId);
+        String cacheKey= CacheConstants.USER_CACHE_SINGLE_KEY+userId.toString();
+        if(RedisUtils.hasKey(cacheKey))
+        {
+            return RedisUtils.getCacheObject(cacheKey);
+        }
+        SysUser user = userMapper.selectById(userId);
+        RedisUtils.setCacheObject(cacheKey,user, Duration.ofSeconds(CacheConstants.ORG_USER_EXPIRATION_TIME));
+        return user;
     }
 
     /**
@@ -683,7 +701,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
                 log.error("同步人员批量保存 batchSaveOrUpdate ,失败原因:{}", ex.getMessage()+ex.getStackTrace());
             }
         }
-        // this.clearUserCache();
+        this.clearUserCache();
     }
 
 
@@ -1037,6 +1055,33 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
 
     }
 
+    @Override
+    public void clearUserCache() {
+        RedisUtils.deleteByPrefix(CacheConstants.USER_CACHE_SINGLE_KEY);
+        RedisUtils.deleteByPrefix(CacheConstants.USER_CACHE_ROLE_ID_KEY);
+        RedisUtils.deleteByPrefix(CacheConstants.USER_CACHE_ROLE_OBJECT_KEY);
+        RedisUtils.deleteByPrefix(CacheConstants.USER_ROLE_PERMISSION_CACHE_KEY);
+    }
+
+    @Override
+    public void clearUserCacheByUserId(Long userId) {
+        RedisUtils.deleteObject(CacheConstants.USER_CACHE_SINGLE_KEY+userId.toString());
+        RedisUtils.deleteObject(CacheConstants.USER_CACHE_ROLE_ID_KEY+userId.toString());
+        RedisUtils.deleteObject(CacheConstants.USER_CACHE_ROLE_OBJECT_KEY+userId.toString());
+        RedisUtils.deleteObject(CacheConstants.USER_ROLE_PERMISSION_CACHE_KEY+userId.toString());
+    }
+
+    @Override
+    public void clearUserCacheByUserName(String userName) {
+        if(StringUtils.isEmpty(userName))
+        {
+            RedisUtils.deleteByPrefix(CacheConstants.USER_CACHE_SINGLE_KEY);
+        }
+        else {
+            RedisUtils.deleteObject(CacheConstants.USER_CACHE_SINGLE_KEY+userName);
+        }
+    }
+
     private void saveUserRole(Long userId, List<Long> roleIdList) {
         List<SysUserRole> list = new ArrayList<>();
         for (Long roleId : roleIdList) {

+ 2 - 0
soc-modules/soc-modules-system/src/main/resources/mapper/system/SysOrgMapper.xml

@@ -653,6 +653,8 @@
                type,
                tree_show_parent_id,
                tree_show_path,
+               affiliated_bank,
+               affiliated_area,
                if(sort is null,0,sort) as sort
         FROM sys_org
         WHERE deleted = 0