Explorar o código

人员基本信息缓存

lighter %!s(int64=3) %!d(string=hai) anos
pai
achega
f9457f04a0

+ 10 - 0
src/main/java/thyyxxk/webserver/dao/his/redislike/RedisLikeDao.java

@@ -4,6 +4,9 @@ import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
 import thyyxxk.webserver.entity.dictionary.PureCodeName;
+import thyyxxk.webserver.entity.login.UserInfo;
+
+import java.util.List;
 
 @Mapper
 public interface RedisLikeDao {
@@ -35,4 +38,11 @@ public interface RedisLikeDao {
 
     @Select("select rtrim(name) from zd_country_code where code=#{code}")
     String selectCountryName(@Param("code") String code);
+
+    @Select("select a.code, a.name, password, a.code_rs,rtrim(b.yb_code) as ybCode, rtrim(b.dept_code) as deptCode " +
+            "from dj_user_base a, a_employee_mi b where a.code=#{code} and isnull(b.del_flag,0)!=1 and a.code=b.code")
+    UserInfo selectUserInfo(@Param("code") String code);
+
+    @Select("select role_id from dj_user_role where user_code=#{code}")
+    List<Integer> selectUserRoles(@Param("code") String code);
 }

+ 29 - 0
src/main/java/thyyxxk/webserver/service/redislike/RedisLikeService.java

@@ -3,9 +3,11 @@ package thyyxxk.webserver.service.redislike;
 import org.springframework.stereotype.Service;
 import thyyxxk.webserver.dao.his.redislike.RedisLikeDao;
 import thyyxxk.webserver.entity.dictionary.PureCodeName;
+import thyyxxk.webserver.entity.login.UserInfo;
 import thyyxxk.webserver.utils.StringUtil;
 
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 @Service
@@ -18,6 +20,7 @@ public class RedisLikeService {
     private final static Map<String, String> wjwDepartmentMap = new HashMap<>();
     private final static Map<String, String> wjwNationMap = new HashMap<>();
     private final static Map<String, String> countryMap = new HashMap<>();
+    private final static Map<String, UserInfo> userMap = new HashMap<>();
     private final RedisLikeDao dao;
 
     public RedisLikeService(RedisLikeDao dao) {
@@ -133,4 +136,30 @@ public class RedisLikeService {
         }
         return name;
     }
+
+    public UserInfo getUserInfo(String code) {
+        if (StringUtil.invalidValue(code)) {
+            return null;
+        }
+        UserInfo userInfo = userMap.get(code);
+        if (null == userInfo) {
+            userInfo = dao.selectUserInfo(code);
+            userInfo.setDeptName(getDeptName(userInfo.getDeptCode()));
+            userInfo.setRoles(dao.selectUserRoles(code));
+            userMap.put(code, userInfo);
+        }
+        return userInfo;
+    }
+
+    public void handleUserRoleChanged(String code) {
+        UserInfo userInfo = getUserInfo(code);
+        userInfo.setRoles(dao.selectUserRoles(code));
+        userMap.replace(code, userInfo);
+    }
+
+    public void handleUserPwdChanged(String code, String pwd) {
+        UserInfo userInfo = getUserInfo(code);
+        userInfo.setPassword(pwd);
+        userMap.replace(code, userInfo);
+    }
 }

+ 7 - 1
src/main/java/thyyxxk/webserver/service/settings/SettingsService.java

@@ -21,6 +21,7 @@ import thyyxxk.webserver.entity.settings.users.ChangePwdParam;
 import thyyxxk.webserver.entity.settings.users.WorkIntegrationPlatformAdvice;
 import thyyxxk.webserver.service.PublicServer;
 import thyyxxk.webserver.service.externalhttp.CorpWxSrvc;
+import thyyxxk.webserver.service.redislike.RedisLikeService;
 import thyyxxk.webserver.utils.*;
 import thyyxxk.webserver.websocket.WebSocketServer;
 
@@ -36,11 +37,14 @@ public class SettingsService {
     private final CorpWxSrvc srvc;
     private final PublicServer publicServer;
 
+    private final RedisLikeService redis;
+
     @Autowired
-    public SettingsService(SettingsDao dao, CorpWxSrvc srvc, PublicServer publicServer) {
+    public SettingsService(SettingsDao dao, CorpWxSrvc srvc, PublicServer publicServer, RedisLikeService redis) {
         this.dao = dao;
         this.srvc = srvc;
         this.publicServer = publicServer;
+        this.redis = redis;
     }
 
     public ResultVo<UserInfo> getUserInfo() {
@@ -66,6 +70,7 @@ public class SettingsService {
             return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "新密码不能包含空格,请检查!");
         }
         dao.updatePassword(code, param.getNewPassword());
+        redis.handleUserPwdChanged(code, param.getNewPassword());
         return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION, "密码修改成功,请重新登录。");
     }
 
@@ -135,6 +140,7 @@ public class SettingsService {
             return ResultVoUtil.success();
         }
         dao.insertUserRoles(param.getCode(), param.getRoles());
+        redis.handleUserRoleChanged(param.getCode());
         log.info("更改人员角色 => 操作员:{},数据:{}", TokenUtil.getTokenUserId(), param);
         return ResultVoUtil.success();
     }