From af99adcdd1198af865d091204b8566e2b81e389d Mon Sep 17 00:00:00 2001
From: ludc
Date: 星期二, 22 十月 2024 09:50:19 +0800
Subject: [PATCH] UI授权相关更改

---
 Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/LoginServiceImpl.java |  690 ++++++++++++++++++++++++++++++++++++++------------------
 1 files changed, 466 insertions(+), 224 deletions(-)

diff --git a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/LoginServiceImpl.java b/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/LoginServiceImpl.java
index eef1f76..bb4ab4f 100644
--- a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/LoginServiceImpl.java
+++ b/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/LoginServiceImpl.java
@@ -1,33 +1,53 @@
 package com.vci.web.service.impl;
 
+import com.vci.corba.common.PLException;
+import com.vci.corba.framework.data.DeptInfo;
+import com.vci.corba.framework.data.LoginResult;
+import com.vci.corba.framework.data.LoginState;
+import com.vci.corba.framework.data.MachineInfo;
 import com.vci.frameworkcore.ajaxTask.SmUserUnLockTask;
 import com.vci.frameworkcore.ajaxTask.SmUserUnLockTaskManager;
 import com.vci.frameworkcore.compatibility.ISmFunctionQueryService;
-import com.vci.frameworkcore.compatibility.SmRoleQueryServiceI;
+import com.vci.frameworkcore.compatibility.SmPwdStrategyQueryServiceI;
 import com.vci.frameworkcore.compatibility.SmUserQueryServiceI;
-import com.vci.frameworkcore.pagemodel.SmUserVO;
+import com.vci.frameworkcore.enumpck.ResourceControlTypeEnum;
+import com.vci.frameworkcore.lcstatuspck.FrameworkDataLCStatus;
+import com.vci.pagemodel.SmFunctionVO;
+import com.vci.pagemodel.SmPasswordStrategyVO;
+import com.vci.pagemodel.SmUserVO;
 import com.vci.frameworkcore.properties.VciSecurityManageProperties;
-import com.vci.starter.web.annotation.bus.*;
+import com.vci.starter.web.annotation.bus.VciLoginAfter;
+import com.vci.starter.web.annotation.bus.VciLogoutBefore;
+import com.vci.starter.web.annotation.bus.VciLogoutPlugin;
+import com.vci.starter.web.constant.VConstant;
 import com.vci.starter.web.exception.VciBaseException;
 import com.vci.starter.web.interceptor.VciSessionForLoginI;
 import com.vci.starter.web.pagemodel.RequestClientInfo;
 import com.vci.starter.web.pagemodel.SessionInfo;
-import com.vci.starter.web.util.ApplicationContextProvider;
-import com.vci.starter.web.util.Md5;
-import com.vci.starter.web.util.VciBaseUtil;
-import com.vci.web.bo.LoginResultBO;
-import com.vci.web.dto.LoginUserDTO;
+import com.vci.starter.web.pagemodel.TokenVO;
+import com.vci.starter.web.util.*;
+
+import com.vci.bo.LoginResultBO;
+import com.vci.constant.CacheNameConstant;
+import com.vci.dto.LoginUserDTO;
+import com.vci.web.properties.WebProperties;
+import com.vci.starter.web.redis.RedisService;
 import com.vci.web.service.LoginServiceI;
-import com.vci.web.util.BusAnnotationUtil;
+import com.vci.web.util.Func;
+import com.vci.web.util.PlatformClientUtil;
 import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
 
+import javax.annotation.Resource;
 import java.lang.reflect.Method;
-import java.util.Map;
+import java.text.MessageFormat;
+import java.util.*;
+import java.util.stream.Collectors;
+
+import static com.vci.constant.FrameWorkBusLangCodeConstant.*;
 
 /**
  * 鐧诲綍鐨勬湇鍔�
@@ -45,38 +65,68 @@
     /**
      * 浼氳瘽澶勭悊
      */
-    @Autowired
+    @Resource
     private VciSessionForLoginI sessionForLogin;
 
     /**
      * 瑙i攣浠诲姟
      */
-    @Autowired
+    @Resource
     private SmUserUnLockTaskManager unLockTaskManager;
 
     /**
      * 鏉冮檺绠$悊鐨勭浉鍏抽厤缃�
      */
-    @Autowired
+    @Resource
     private VciSecurityManageProperties securityManageProperties;
 
     /**
      * 鐢ㄦ埛鏌ヨ鏈嶅姟锛屽彲浠ュ吋瀹硅�佸钩鍙�
      */
-    @Autowired()
+    @Resource
     private SmUserQueryServiceI userQueryService;
+
+    /**
+     * 瀵嗙爜绛栫暐鏌ヨ鏈嶅姟
+     */
+    @Resource
+    private SmPwdStrategyQueryServiceI pwdStrategyQueryService;
+
+    /**
+     * 鍔熻兘鑿滃崟鐨勬煡璇㈡湇鍔�
+     */
+    @Resource
+    private ISmFunctionQueryService functionQueryService;
 
     /**
      * 瑙掕壊鐨勬煡璇㈡湇鍔★紝鍙互鍏煎鑰佸钩鍙�
      */
-    @Autowired
-    private SmRoleQueryServiceI roleQueryService;
+    //@Resource
+    //private SmRoleQueryServiceI roleQueryService;
 
     /**
      * 鏉冮檺鐨勬煡璇㈡湇鍔★紝鍙互鍏煎鑰佸钩鍙�
      */
-    @Autowired
-    private ISmFunctionQueryService functionQueryService;
+    //@Resource
+    //private ISmFunctionQueryService functionQueryService;
+
+    /**
+     * redis鏈嶅姟
+     */
+    @Resource
+    private RedisService redisService;
+
+    /**
+     * 瀹㈡埛绔厤缃枃浠�
+     */
+    @Resource
+    private WebProperties webProperties;
+
+    /**
+     * 骞冲彴璋冪敤瀹㈡埛绔�
+     */
+    @Resource
+    private PlatformClientUtil platformClientUtil;
 
     /**
      * 鎵ц鐧诲綍
@@ -85,7 +135,7 @@
      * @throws VciBaseException 鐧诲綍鍙戠敓寮傚父鐨勬椂鍊欏嚭鐜颁簡閿欒
      */
     @Override
-    public LoginResultBO login(LoginUserDTO userDTO, RequestClientInfo clientInfo) throws VciBaseException {
+    public LoginResultBO login(LoginUserDTO userDTO, RequestClientInfo clientInfo) throws PLException {
         return login(userDTO,clientInfo,true);
     }
 
@@ -97,201 +147,378 @@
      * @return 鎵ц缁撴灉
      * @throws VciBaseException 鍙傛暟閿欒锛岀敤鎴蜂笉鑳界櫥褰曠瓑浼氭姏鍑哄紓甯�
      */
-    private LoginResultBO login(LoginUserDTO userDTO, RequestClientInfo clientInfo, boolean checkPassword) throws VciBaseException {
+    private LoginResultBO login(LoginUserDTO userDTO, RequestClientInfo clientInfo, boolean checkPassword/*鍗曠偣鐧诲綍涓嶉渶瑕佹牎楠屽瘑鐮�*/) throws VciBaseException {
         LoginResultBO loginResult = new LoginResultBO();
         loginResult.setSuccess(false);
-        //1.鍒ゆ柇鐢ㄦ埛鐨勫熀鏈俊鎭�
-//        VciBaseUtil.alertNotNull(userDTO, "鐧诲綍淇℃伅", userDTO.getUserId(), "鐢ㄦ埛璐﹀彿");
-//        if (checkPassword) {
-//            VciBaseUtil.alertNotNull(userDTO.getPassword(), "鐧诲綍瀵嗙爜");
-//        }
-        //鐧诲綍涔嬪墠璋冪敤鎻掍欢
-        BusAnnotationUtil.callForAnnotation(VciLoginPlugin.class,VciLoginBefore.class,userDTO,clientInfo);
 
-//        String loginInfo = checkIsLogined(userDTO.getUserId());
-//        if (!userDTO.isForceLogin() && securityManageProperties.isUserOneLogin()) {
-//            //闇�瑕佺湅鐪嬫槸鍚﹀凡缁忕櫥褰曚簡
-//            if (StringUtils.isNotBlank(loginInfo)) {
-//                loginResult.setFailCode(USER_IS_LOGINED);
-//                loginResult.setFailMsg(loginInfo);
-//                return loginResult;
-//            }
-//        }
-        //2.鑾峰彇鐢ㄦ埛鐨勫璞�.杩欓噷闇�瑕佸吋瀹硅�佸钩鍙板拰鑰乸dm锛岃�佺紪鐮佸拰鑰佸钩鍙版槸涓�涓〃
-//        SmUserVO user = userQueryService.getUserByUserId(userDTO.getUserId().trim());
-//        if (user == null || StringUtils.isEmpty(user.getOid())) {
-//            loginResult.setFailCode(USER_NOT_FOUND);
-//            loginResult.setFailMsgArray(new String[]{userDTO.getUserId()});
-//            return loginResult;
-//        }
+        //1.鍒ゆ柇鐢ㄦ埛鐨勫熀鏈俊鎭�
+        VciBaseUtil.alertNotNull(userDTO, "鐧诲綍淇℃伅", userDTO.getUserId(), "鐢ㄦ埛璐﹀彿");
+        if (checkPassword) {
+            VciBaseUtil.alertNotNull(userDTO.getPassword(), "鐧诲綍瀵嗙爜");
+        }
+        //2銆佸垽鏂崟璁惧鐧诲綍,鏄惁宸茬粡鐧诲綍浜�
+        String userIdTokenKey = CacheNameConstant.cacheKey(CacheNameConstant.USERID_TOKEN_KEY, userDTO.getUserId().trim());
+        if(redisService.hasKey(userIdTokenKey) && !userDTO.isForceLogin() && securityManageProperties.isUserOneLogin()){
+            loginResult.setFailCode(USER_IS_LOGINED);
+            loginResult.setFailMsg("褰撳墠鐢ㄦ埛宸茬粡鍦ㄥ叾浠栧湴鏂圭櫥褰曪紒");
+            return loginResult;
+        }
+        //璇存槑宸茬粡鐧诲綍浜嗭紝閭e簲璇ュ彇娑堝師鏉ョ殑鐧诲綍
+        if (redisService.hasKey(userIdTokenKey) && userDTO.isForceLogin() && securityManageProperties.isUserOneLogin()) {
+            String tokenKey = redisService.getCacheObject(userIdTokenKey);
+            redisService.deleteObject(tokenKey);
+            redisService.deleteObject(userIdTokenKey);
+            redisService.decreOnlineUser(VConstant.CURRENT_LOGGED_USERS_KEY);
+        }
+
+        //3.鑾峰彇鐢ㄦ埛鐨勫璞★紙瀵硅薄涓寘鍚鑹查儴闂ㄨ繕鏈夊瘑鐮佺瓥鐣ヤ俊鎭�(褰撳墠鐢ㄦ埛娌¤缃瘑鐮佺瓥鐣ュ氨鏄彇鐨勯粯璁ゅ瘑鐮佺瓥鐣�)锛�
+        SmUserVO user = getUserByUserId(userDTO.getUserId().trim());
+        if (user == null || StringUtils.isBlank(user.getOid())) {
+            loginResult.setFailCode(USER_NOT_FOUND);
+            loginResult.setFailMsgArray(new String[]{userDTO.getUserId()});
+            return loginResult;
+        }
+
+        //4銆佸垽鏂瘑鐮佹槸鍚︽纭紙骞冲彴鐨刢heckLogin鏂规硶濂藉儚鏈夊瀵嗙爜杩涜姣斿鐨勬柟娉曪級
+        /*if (checkPassword) {
+            boolean passwordIsEqual = userQueryService.checkPasswordEqual(userDTO.getPassword(), user.getOid());
+            if (!passwordIsEqual) {
+                if (logger.isDebugEnabled()) {
+                    logger.debug("{}瀵嗙爜涓嶆纭�", user.getId());
+                }
+            }
+        }*/
+
+        //5銆佽皟鐢ㄥ钩鍙扮櫥褰曟帴鍙o紝杩涜鐧诲綍
+        MachineInfo machine = getMachieInfo(clientInfo);
+        machine.country = clientInfo.getCountry();
+        machine.language = clientInfo.getLanguage();
+        machine.osUser = clientInfo.getOsUser();
+        machine.machine = clientInfo.getMachine();
+        String token = null;
+        try {
+            //鍓嶇浼犺繃鏉ョ殑瀵嗙爜鏄粡杩囧姞瀵嗕紶杈撶殑锛屾墍浠ラ渶瑕佹寜鐓х害瀹氳В瀵嗭紝鍐嶄紶缁欏钩鍙拌繘琛屾瘮瀵�
+            userDTO.setPassword(Func.decryptAes(userDTO.getPassword(),"daliantan0v0vcip"));
+            LoginResult chkRes = platformClientUtil.getFrameworkService().checkLogin(userDTO.getUserId(),userDTO.getPassword(), machine);
+            loginResult.setFailCode(getErrorCode(chkRes));
+            //loginResult.setFailMsgArray(new String[]{userDTO.getUserId(), String.valueOf(chkRes.auxInfo)});
+            loginResult.setFailMsgArray(new String[]{String.valueOf(chkRes.auxInfo)});
+            //鏍规嵁涓嶅悓鐘舵�佸鐞嗗钩鍙拌繑鍥炵殑淇℃伅
+            if(chkRes.state.equals(LoginState.Error) || chkRes.state.equals(LoginState.Locked) || chkRes.state.equals(LoginState.Freeze)){
+                return loginResult;
+            }
+            //鍏充簬瀵嗙爜绛栫暐鐩稿叧鐨勮繑鍥炰俊鎭鐞�
+            if(chkRes.state.equals(LoginState.InitialPW)){
+                loginResult.setMustChangePassword(true);
+                loginResult.setPasswordInfo("鎮ㄧ殑瀵嗙爜鏄鐞嗗憳鍒濆鐨勫瘑鐮侊紝闇�瑕佷慨鏀瑰瘑鐮佹墠鑳借繘琛屽叾瀹冩搷浣�!");
+                return loginResult;
+            }else if(chkRes.state.equals(LoginState.PWExpired)){
+                //闇�瑕佺珛鍗充慨鏀瑰瘑鐮�
+                loginResult.setMustChangePassword(true);
+                loginResult.setPasswordInfo("鎮ㄧ殑瀵嗙爜宸茬粡杩囨湡,璇疯繘琛屼慨鏀癸紒");
+                return loginResult;
+            }else if(chkRes.state.equals(LoginState.PWPolicyUpdated)){
+                //绛栫暐淇敼锛岀洿鎺ヨ繑鍥為檺鍒剁敤鎴峰悗缁搷浣�
+                loginResult.setMustChangePassword(true);
+                loginResult.setPasswordInfo("鎮ㄧ殑瀵嗙爜绛栫暐宸茬粡淇敼锛岄渶瑕佷慨鏀瑰瘑鐮佹墠鑳借繘琛屽叾瀹冩搷浣�!");
+                return loginResult;
+            }else if(chkRes.state.equals(LoginState.PWWillExpire)){
+                loginResult.setPasswordInfo(String.format("鎮ㄧ殑瀵嗙爜鏈夋晥鏈熻繕鏈�%s澶�,璇锋敞鎰忎慨鏀�!",chkRes.auxInfo));
+            }
+            token = chkRes.token;
+        } catch (Exception e) {
+            loginResult.setFailCode(SYSTEM_ERROR);
+            loginResult.setFailMsgArray(new String[]{userDTO.getUserId()});
+            return loginResult;
+        }
+        if(StringUtils.isBlank(token)){
+            loginResult.setFailMsg(TOKEN_EMPTY);
+            loginResult.setFailMsgArray(new String[]{userDTO.getUserId()});
+            return loginResult;
+        }
+        //6銆佺櫥褰曟垚鍔熶箣鍚庨渶瑕佸鐞嗙殑閫昏緫
+        user.setLastLoginTime(new Date());//鏈�鍚庣櫥褰曟椂闂�
+        user.setPwdWrongCount(0);//瀵嗙爜閿欒娆℃暟娓�0
+        //澶勭悊鐢ㄦ埛鐧诲綍鎴愬姛鐨剆ession
+        SessionInfo sessionInfo = new SessionInfo();
+        sessionInfo.setToken(token);
+        //鍒濆鍖栧钩鍙扮殑token
+        sessionForLogin.initInvocationInfo(sessionInfo);
+        //璁板綍褰撳墠鐧诲綍浜烘暟鐨勬�绘暟
+        redisService.increOnlineUser(VConstant.CURRENT_LOGGED_USERS_KEY);
+        //鎷疯礉鐢ㄦ埛鍒版柊鐨剆ession浼氳瘽涓�
+        copyUser2SessionInfo(user, sessionInfo, userDTO.getLangCode());
+        //鎷疯礉璇锋眰淇℃伅鍒皊ession浼氳瘽涓�
+        copyRequest2SessionInfo(clientInfo, sessionInfo);
+
+        //鏌ョ湅浜嗗钩鍙扮殑鐧诲綍鏂规硶鍏跺疄鏄湁澶勭悊閮ㄩ棬瑙掕壊绛夌浉鍏充俊鎭殑浣嗘槸涓嶇煡閬撲负浠�涔堟棤娉曡幏鍙栧埌
+        //閮ㄩ棬淇℃伅澶勭悊
+        sessionInfo.setDeptOid(user.getPkDepartment());
+        sessionInfo.setDeptName(user.getPkDepartmentName());
+        sessionInfo.setDeptNum(user.getPkDepartmentNum());
+        //瑙掕壊淇℃伅澶勭悊
+        String roleOids = user.getPkPerson();
+        String roleNames = user.getPkPersonName();
+        HashMap<String, String> roleOidNameMap = new HashMap<>();
+        if(Func.isNotBlank(roleOids) && Func.isNotBlank(roleOids)){
+            String[] oids = roleOids.split(",");
+            String[] names = roleNames.split(",");
+            for (int i = 0; i < oids.length; i++) {
+                roleOidNameMap.put(oids[i],names[i]);
+            }
+        }
+        sessionInfo.setRolesName(roleOidNameMap);
+
+        //鏌ヨ鎵�鏈夌殑鏉冮檺
+        List<SmFunctionVO> functionVOList = functionQueryService.listFunctionByUserOid(user.getOid(), null, ResourceControlTypeEnum.BS);
+        if (!CollectionUtils.isEmpty(functionVOList)) {
+            List<String> functionOidList = functionVOList.stream().map(s -> s.getOid()).collect(Collectors.toList());
+            sessionInfo.setFunctionOids(functionOidList);
+        } else {
+            sessionInfo.setFunctionOids(new ArrayList());
+        }
+
+        //娣诲姞鍒颁細璇濅俊鎭�
+        TokenVO tokenVO = saveSessionInfo(sessionInfo);
+        loginResult.setTokenVO(tokenVO);
+        loginResult.setSuccess(true);
+        return loginResult;
+    }
+
+    /**
+     * 鐧诲綍_搴熷純鏂规硶锛屼富瑕佺敤鏉ュ浠�
+     * @param userDTO 鐢ㄦ埛鐨勬暟鎹紶杈撳璞�
+     * @param clientInfo 瀹㈡埛绔殑淇℃伅
+     * @param checkPassword 鏄惁鏍¢獙瀵嗙爜
+     * @return 鎵ц缁撴灉
+     * @throws VciBaseException 鍙傛暟閿欒锛岀敤鎴蜂笉鑳界櫥褰曠瓑浼氭姏鍑哄紓甯�
+     */
+    private LoginResultBO login_old(LoginUserDTO userDTO, RequestClientInfo clientInfo, boolean checkPassword/*鍗曠偣鐧诲綍涓嶉渶瑕佹牎楠屽瘑鐮�*/) throws VciBaseException, PLException {
+        LoginResultBO loginResult = new LoginResultBO();
+        loginResult.setSuccess(false);
+
+        //1.鍒ゆ柇鐢ㄦ埛鐨勫熀鏈俊鎭�
+        VciBaseUtil.alertNotNull(userDTO, "鐧诲綍淇℃伅", userDTO.getUserId(), "鐢ㄦ埛璐﹀彿");
+        if (checkPassword) {
+            VciBaseUtil.alertNotNull(userDTO.getPassword(), "鐧诲綍瀵嗙爜");
+        }
+        //2銆佸垽鏂崟璁惧鐧诲綍,鏄惁宸茬粡鐧诲綍浜�
+        String userIdTokenKey = CacheNameConstant.cacheKey(CacheNameConstant.USERID_TOKEN_KEY, userDTO.getUserId().trim());
+        if(redisService.hasKey(userIdTokenKey) && !userDTO.isForceLogin() && securityManageProperties.isUserOneLogin()){
+            loginResult.setFailCode(USER_IS_LOGINED);
+            loginResult.setFailMsg("褰撳墠鐢ㄦ埛宸茬粡鍦ㄥ叾浠栧湴鏂圭櫥褰曪紒");
+            return loginResult;
+        }
+        //璇存槑宸茬粡鐧诲綍浜嗭紝閭e簲璇ュ彇娑堝師鏉ョ殑鐧诲綍
+        if (redisService.hasKey(userIdTokenKey) && userDTO.isForceLogin() && securityManageProperties.isUserOneLogin()) {
+            String tokenKey = redisService.getCacheObject(userIdTokenKey);
+            redisService.deleteObject(tokenKey);
+            redisService.deleteObject(userIdTokenKey);
+        }
+
+        //3.鑾峰彇鐢ㄦ埛鐨勫璞★紙瀵硅薄涓寘鍚鑹查儴闂ㄨ繕鏈夊瘑鐮佺瓥鐣ヤ俊鎭級
+        SmUserVO user = getUserByUserId(userDTO.getUserId().trim());
+        if (user == null || StringUtils.isBlank(user.getOid())) {
+            loginResult.setFailCode(USER_NOT_FOUND);
+            loginResult.setFailMsgArray(new String[]{userDTO.getUserId()});
+            return loginResult;
+        }
+
+        //3銆佸垽鏂瘑鐮佹槸鍚︽纭�
+        if (checkPassword) {
+            boolean passwordIsEqual = userQueryService.checkPasswordEqual(userDTO.getPassword(), user.getOid());
+            if (!passwordIsEqual) {
+                if (logger.isDebugEnabled()) {
+                    logger.debug("{}瀵嗙爜涓嶆纭�", user.getId());
+                }
+            }
+        }
+
+        //4銆佽皟鐢ㄥ钩鍙扮櫥褰曟帴鍙o紝杩涜鐧诲綍
+        MachineInfo machine = getMachieInfo(clientInfo);
+        machine.country = clientInfo.getCountry();
+        machine.language = clientInfo.getLanguage();
+        machine.osUser = clientInfo.getOsUser();
+        machine.machine = clientInfo.getMachine();
+        String token = null;
+        try {
+            LoginResult chkRes = platformClientUtil.getFrameworkService().checkLogin(userDTO.getUserId(),userDTO.getPassword(), machine);
+            loginResult.setFailCode(getErrorCode(chkRes));
+            loginResult.setFailMsgArray(new String[]{userDTO.getUserId(), String.valueOf(chkRes.auxInfo)});
+            if(chkRes.state == LoginState.Error || chkRes.state == LoginState.Locked || chkRes.state == LoginState.Freeze){
+                return loginResult;
+            }
+            token = chkRes.token;
+        } catch (Exception e) {
+            loginResult.setFailCode(SYSTEM_ERROR);
+            loginResult.setFailMsgArray(new String[]{userDTO.getUserId()});
+            return loginResult;
+        }
+        if(StringUtils.isBlank(token)){
+            loginResult.setFailMsg(TOKEN_EMPTY);
+            loginResult.setFailMsgArray(new String[]{userDTO.getUserId()});
+            return loginResult;
+        }
+
         //濡傛灉鐢ㄦ埛宸茬粡琚仠鐢ㄥ拰閿佸畾锛屼笉鑳界櫥褰�
+        if (FrameworkDataLCStatus.DISABLED.getValue().equals(user.getLcStatus())) {
+            loginResult.setFailCode(USER_IS_DISABLED);
+            loginResult.setFailMsgArray(new String[]{userDTO.getUserId()});
+            return loginResult;
+        }
+        if (userQueryService.checkUserLock(user, user.getPwdWrongCount())) {
+            loginResult.setFailCode(USER_IS_LOCK);
+            loginResult.setFailMsgArray(new String[]{userDTO.getUserId()});
+            return loginResult;
+        }
+
         //濡傛灉鐢ㄦ埛鐨勫け鏁堟棩鏈熷凡缁忚秴杩囦簡褰撳墠鏃堕棿锛屼笉鑳界櫥褰�
         //鍙湁鏂板钩鍙扮殑鐢ㄦ埛鎵嶅垽鏂け鏁�
-//        if (FrameworkDataLCStatus.DISABLED.getValue().equals(user.getLcStatus())) {
-//            loginResult.setFailCode(USER_IS_DISABLED);
-//            loginResult.setFailMsgArray(new String[]{userDTO.getUserId()});
-//            return loginResult;
-//        }
-//        if (userQueryService.checkUserLock(user, user.getPwdWrongCount())) {
-//            loginResult.setFailCode(USER_IS_LOCK);
-//            loginResult.setFailMsgArray(new String[]{userDTO.getUserId()});
-//            return loginResult;
-//        }
-//        if (user.getDisabledate() != null) {
-//            //2021鐗堟湰鎵嶆湁杩欎釜灞炴�х殑鍊硷紝褰撳墠杩欎釜娌℃湁杩欎釜鍊�
-//            Date disableDate = VciDateUtil.addOrSubDate(user.getDisabledate(), Calendar.DATE, 1);
-//            if (disableDate != null && disableDate.getTime() < System.currentTimeMillis()) {
-//                loginResult.setFailCode(USER_MORE_THAN_DISABLE_DATE);
-//                loginResult.setFailMsgArray(new String[]{userDTO.getUserId()});
-//                return loginResult;
-//            }
-//        }
-//        if (user.getPwdWrongCount() == null) {
-//            user.setPwdWrongCount(0);
-//        }
-//        SmPasswordStrategyVO passwordStrategyVO = userQueryService.getPasswordStrategyVOByUserOid(user.getOid());
-//        if (checkPassword) {
-//            boolean passwordIsEqual = userQueryService.checkPasswordEqual(userDTO.getPassword(), user.getOid());
-//            //3.鍒ゆ柇鐢ㄦ埛鐨勫瘑鐮佹槸鍚︽纭�
-//            if (!passwordIsEqual) {
-//                //鍓嶇闇�瑕佸厛md5涓�娆★紝鐒跺悗鍚庡彴鍐峂D5涓�娆★紝
-//                if (logger.isDebugEnabled()) {
-//                    logger.debug("{}瀵嗙爜涓嶆纭�", user.getId());
-//                }
-//                if (passwordStrategyVO == null) {
-//                    //鍙兘鏁版嵁闂娌℃湁璁剧疆瀵嗙爜绛栫暐
-//                    passwordStrategyVO = new SmPasswordStrategyVO();
-//                    passwordStrategyVO.setRetryTime(6);
-//                    passwordStrategyVO.setLockTime(30);
-//                }
-//                if (passwordStrategyVO.getRetryTime() <= (user.getPwdWrongCount() + 1)) {
-//                    user.setLockFlag(true);
-//                    updateUserPwdWrongCount(user.getOid(), user.getPwdWrongCount() + 1);
-//                    addUserToUnLock(userDTO.getUserId(), passwordStrategyVO.getLockTime());
-//                    updateUserPwdWrongCount(user.getOid(), user.getPwdWrongCount() + 1);
-//                    loginResult.setFailCode(USER_PWD_LOCK);
-//                    loginResult.setFailMsgArray(new String[]{userDTO.getUserId(), passwordStrategyVO.getLockTime() + ""});
-//                    return loginResult;
-//                } else {
-//                    //杩樻病鏈夊埌閿佸畾鐨勬鏁�
-//                    updateUserPwdWrongCount(user.getOid(), user.getPwdWrongCount() + 1);
-//                    //5, 杩欐槸绗竴娆¢敊璇紝鍓╀笅鐨勬槸 5- 锛�0+1锛�
-//                    loginResult.setFailCode(USER_PWD_NOT_EQUAL);
-//                    loginResult.setFailMsgArray(new String[]{userDTO.getUserId(), (passwordStrategyVO.getRetryTime() - (user.getPwdWrongCount() + 1)) + ""});
-//                    return loginResult;
-//                }
-//            }
-//        }
+        /*if (user.getDisabledate() != null) {
+            //2021鐗堟湰鎵嶆湁杩欎釜灞炴�х殑鍊硷紝褰撳墠杩欎釜娌℃湁杩欎釜鍊�
+            Date disableDate = VciDateUtil.addOrSubDate(user.getDisabledate(), Calendar.DATE, 1);
+            if (disableDate != null && disableDate.getTime() < System.currentTimeMillis()) {
+                loginResult.setFailCode(USER_MORE_THAN_DISABLE_DATE);
+                loginResult.setFailMsgArray(new String[]{userDTO.getUserId()});
+                return loginResult;
+            }
+        }*/
+        //褰撳墠鐢ㄦ埛娌℃湁閰嶇疆灏辨煡璇㈤粯璁ょ殑瀵嗙爜绛栫暐
+        SmPasswordStrategyVO passwordStrategyVO = pwdStrategyQueryService.getPasswordStrategyVOByUserOid(user.getOid());
+        if (checkPassword) {
+            //鍓嶇闇�瑕佸厛md5涓�娆★紝鐒跺悗鍚庡彴鍐峂D5涓�娆★紝
+            if (logger.isDebugEnabled()) {
+                logger.debug("{}瀵嗙爜涓嶆纭�", user.getId());
+            }
+            //鍙鏁版嵁娌℃湁闂灏变笉瀛樺湪瀵嗙爜绛栫暐涓虹┖鐨勬儏鍐�
+            if (passwordStrategyVO == null) {
+                //鍙兘鏁版嵁闂娌℃湁璁剧疆瀵嗙爜绛栫暐
+                passwordStrategyVO = new SmPasswordStrategyVO();
+                passwordStrategyVO.setRetryTime(6);
+                passwordStrategyVO.setLockTime(30);
+            }
+            //鍒ゆ柇瀵嗙爜閿欒娆℃暟鏄惁杈惧埌涓婇檺
+            if (passwordStrategyVO.getRetryTime() <= (user.getPwdWrongCount() + 1)) {
+                user.setLockFlag(true);
+                updateUserPwdWrongCount(user.getOid(), user.getPwdWrongCount() + 1);
+                addUserToUnLock(userDTO.getUserId(), passwordStrategyVO.getLockTime());
+                //updateUserPwdWrongCount(user.getOid(), user.getPwdWrongCount() + 1);
+                loginResult.setFailCode(USER_PWD_LOCK);
+                loginResult.setFailMsgArray(new String[]{userDTO.getUserId(), passwordStrategyVO.getLockTime() + ""});
+                return loginResult;
+            } else {
+                //杩樻病鏈夊埌閿佸畾鐨勬鏁�
+                updateUserPwdWrongCount(user.getOid(), user.getPwdWrongCount() + 1);
+                //5, 杩欐槸绗竴娆¢敊璇紝鍓╀笅鐨勬槸 5- 锛�0+1锛�
+                loginResult.setFailCode(USER_PWD_NOT_EQUAL);
+                loginResult.setFailMsgArray(new String[]{userDTO.getUserId(), (passwordStrategyVO.getRetryTime() - (user.getPwdWrongCount() + 1)) + ""});
+                return loginResult;
+            }
+        }
+
+        //妫�鏌ユ槸鍚﹁淇敼瀵嗙爜
+        if (!clientInfo.isSso() && checkPassword) {
+            //鏈�鍚庝慨鏀规椂闂� + 澶辨晥鏃堕棿锛屽ぇ浜庣瓑浜庡綋鍓嶆棩鏈燂紝鍒欓渶瑕侀┈涓婁慨鏀瑰瘑鐮�
+            Date currentDay = null;
+            try {
+                currentDay = VciDateUtil.getNow(VciDateUtil.DateFormat);
+            } catch (Throwable e) {
+                if (logger.isErrorEnabled()) {
+                    logger.error("鑾峰彇褰撳墠鏃ユ湡", e);
+                }
+            }
+            if (currentDay != null && passwordStrategyVO != null && passwordStrategyVO.getValidDay() != null) {
+                Date inValidDay = null;
+                if (user.getLastModifyPasswordTime() == null) {
+                    //浠庢潵娌℃湁鐧诲綍杩�
+                    loginResult.setMustChangePassword(true);
+                } else {
+                    inValidDay = VciDateUtil.addOrSubDate(user.getLastModifyPasswordTime(), Calendar.DATE, passwordStrategyVO.getValidDay());
+                    if (inValidDay.getTime() <= (currentDay).getTime()) {
+                        loginResult.setMustChangePassword(true);
+                    }
+                }
+                if (!loginResult.isMustChangePassword()) {
+                    if (VciDateUtil.addOrSubDate(inValidDay, Calendar.DATE, -(passwordStrategyVO.getRemindDay())).getTime()
+                            <= (currentDay).getTime()) {
+                        //鎮ㄧ殑瀵嗙爜杩樻湁{0}澶╄繃鏈燂紝璇峰強鏃朵慨鏀瑰瘑鐮�
+                        long remainDay = VciDateUtil.getDaySub(inValidDay, currentDay);
+                        loginResult.setPasswordInfo(MessageFormat.format(PASSWORD_REMAIN_DAY, new String[]{String.valueOf(remainDay)}));
+                    }
+                }
+            }
+        }
+
         //璇存槑瀵嗙爜姝g‘鐨�
-//        if (logger.isDebugEnabled()) {
-//            logger.debug("{}鐨勫瘑鐮佹纭�", user.getId());
-//        }
-//        user.setLastLoginTime(new Date());
-//        user.setPwdWrongCount(0);
-        SmUserVO user = new SmUserVO();
-        user.setId("1");
-        user.setName("1");
-        user.setOid("1");
-        user.setUserType("1");
-        user.setUserTypeText("1");
-        user.setSecretGrade(1);
-        user.setSecretGradeText("1");
-        user.setSex("1");
-        user.setSexText("1");
-        user.setPkPerson("1");
-        user.setPkPersonName("1");
-        user.setPkDepartment("1");
-        user.setPkDepartmentName("1");
-        user.setPkDuty("1");
-        user.setPkDutyName("1");
-        user.setEmail("1");
-        user.setTel("1");
-        user.setRtxNo("1");
-        user.setIMNo("1");
-
-
-
+        if (logger.isDebugEnabled()) {
+            logger.debug("{}鐨勫瘑鐮佹纭�", user.getId());
+        }
+        user.setLastLoginTime(new Date());
+        user.setPwdWrongCount(0);
 
         SessionInfo sessionInfo = new SessionInfo();
+        sessionInfo.setToken(token);
+
+        //鍒濆鍖栧钩鍙扮殑token
+        sessionForLogin.initInvocationInfo(sessionInfo);
+
         //鎷疯礉鐢ㄦ埛鐨勬柊鍒皊ession浼氳瘽涓�
         copyUser2SessionInfo(user, sessionInfo, userDTO.getLangCode());
         //鎷疯礉璇锋眰淇℃伅鍒皊ession浼氳瘽涓�
         copyRequest2SessionInfo(clientInfo, sessionInfo);
-        //鏌ヨ鎵�鏈夌殑瑙掕壊
-//        List<SmRoleVO> roleVOList = roleQueryService.listRoleByUserOid(user.getOid(), null);
-//        if (!CollectionUtils.isEmpty(roleVOList)) {
-//            Map<String, String> roleOidNameMap = roleVOList.stream().collect(Collectors.toMap(s -> s.getOid(), t -> t.getName()));
-//            sessionInfo.setRolesName(roleOidNameMap);
-//        } else {
-//            sessionInfo.setRolesName(new HashMap());
-//        }
-        //鏌ヨ鎵�鏈夌殑鏉冮檺
-//        List<SmFunctionVO> functionVOList = functionQueryService.listFunctionByUserOid(user.getOid(), null, ResourceControlTypeEnum.BS);
-//        if (!CollectionUtils.isEmpty(functionVOList)) {
-//            List<String> functionOidList = functionVOList.stream().map(s -> s.getOid()).collect(Collectors.toList());
-//            sessionInfo.setFunctionOids(functionOidList);
-//        } else {
-//            sessionInfo.setFunctionOids(new ArrayList());
-//        }
 
-        loginResult.setSuccess(true);
-        //妫�鏌ユ槸鍚﹁淇敼瀵嗙爜
-//        if (!clientInfo.isSso() && checkPassword) {
-//            //鏈�鍚庝慨鏀规椂闂�+ 澶辨晥鏃堕棿锛屽ぇ浜庣瓑浜庡綋鍓嶆棩鏈燂紝鍒欓渶瑕侀┈涓婁慨鏀瑰瘑鐮�
-//            Date currentDay = null;
-//            try {
-//                currentDay = VciDateUtil.getNow(VciDateUtil.DateFormat);
-//            } catch (Throwable e) {
-//                if (logger.isErrorEnabled()) {
-//                    logger.error("鑾峰彇褰撳墠鏃ユ湡", e);
-//                }
-//            }
-//            if (currentDay != null && passwordStrategyVO != null && passwordStrategyVO.getValidDay() != null) {
-//                Date inValidDay = null;
-//                if (user.getLastModifyPasswordTime() == null) {
-//                    //閲嶆潵娌℃湁鐧诲綍杩�
-//                    loginResult.setMustChangePassword(true);
-//                } else {
-//                    inValidDay = VciDateUtil.addOrSubDate(user.getLastModifyPasswordTime(), Calendar.DATE, passwordStrategyVO.getValidDay());
-//                    if (inValidDay.getTime() <= (currentDay).getTime()) {
-//                        loginResult.setMustChangePassword(true);
-//                    }
-//                }
-//                if (!loginResult.isMustChangePassword()) {
-//                    if (VciDateUtil.addOrSubDate(inValidDay, Calendar.DATE, -(passwordStrategyVO.getRemindDay())).getTime()
-//                            <= (currentDay).getTime()) {
-//                        //鎮ㄧ殑瀵嗙爜杩樻湁{0}澶╄繃鏈燂紝璇峰強鏃朵慨鏀瑰瘑鐮�
-//                        long remainDay = VciDateUtil.getDaySub(inValidDay, currentDay);
-//                        loginResult.setPasswordInfo(MessageFormat.format(PASSWORD_REMAIN_DAY, new String[]{String.valueOf(remainDay)}));
-//                    }
-//                }
-//            }
-//        }
+        //鑾峰彇浜哄憳鎵�灞炵殑閮ㄩ棬淇℃伅
+        try {
+            DeptInfo deptInfo = platformClientUtil.getFrameworkService().fetchDeptByUserId(user.getOid());
+            sessionInfo.setDeptOid(deptInfo.id);
+            sessionInfo.setDeptName(deptInfo.name);
+            sessionInfo.setDeptNum(deptInfo.num);
+        } catch (PLException e) {
+            throw new VciBaseException("鑾峰彇鐢ㄦ埛鎵�灞為儴闂ㄥけ璐�:"+e.getMessage());
+        }
 
-        //鍘熸湰鎯充娇鐢╦wt鏉ョ敓鎴恡oken锛屼絾鏄湁浠ヤ笅闂
-        //1.jwt涓嶈兘澶勭悊娉ㄩ攢鐨勯棶棰�
-        //2.jwt鐢熸垚鐨則oken澶暱浜�
-        //3.鍥犱负鏈钩鍙颁笉鏄簰鑱旂綉绯荤粺锛屽彧闇�瑕佽В鍐冲垎甯冨紡鐢ㄦ埛淇℃伅鐨勮幏鍙栧拰鏉冮檺鐨勬牎楠屽嵆鍙��
-        //4.骞冲彴寮曠敤浜唕edis鍜屾暟鎹簱鏉ュ瓨鍌ㄤ細璇濈殑淇℃伅锛屽彧闇�瑕佷繚璇佹牴鎹畉oken鑳借幏鍙栧埌浼氳瘽淇℃伅鍗冲彲
-        //5.鍦ㄦ湇鍔″惎鍔ㄧ殑鏃跺�欙紝灏嗕細璇濅俊鎭竻闄わ紝鍦ㄦ敞閿�鐨勬椂鍊欏皢浼氳瘽淇℃伅娓呴櫎
-        //uuid鍦ㄩ珮骞跺彂鐨勬儏鍐典笅浼氶噸澶嶏紝浣嗘槸浼犵粺杞欢骞跺彂寰堝皬锛屾墍浠ュ嚭鐜扮殑閲嶅鐨勬鐜囧緢灏�
-
-        sessionInfo.setToken(Md5.md5(VciBaseUtil.getPk() + "_" + user.getId()));
-        loginResult.setSessionInfo(sessionInfo);
-//        updateUserForLoginSuccess(user.getOid());
-//        if (StringUtils.isNotBlank(loginInfo) && userDTO.isForceLogin() && securityManageProperties.isUserOneLogin()) {
-//            //璇存槑宸茬粡鐧诲綍浜嗭紝閭e簲璇ュ彇娑堝師鏉ョ殑鐧诲綍
-//            popUser(userDTO.getUserId());
-//        }
+        /** //鏌ヨ鎵�鏈夌殑瑙掕壊
+         List<SmRoleVO> roleVOList = roleQueryService.listRoleByUserOid(user.getOid(), null);
+         if (!CollectionUtils.isEmpty(roleVOList)) {
+         Map<String, String> roleOidNameMap = roleVOList.stream().collect(Collectors.toMap(s -> s.getOid(), t -> t.getName()));
+         sessionInfo.setRolesName(roleOidNameMap);
+         } else {
+         sessionInfo.setRolesName(new HashMap());
+         }
+         //鏌ヨ鎵�鏈夌殑鏉冮檺
+         List<SmFunctionVO> functionVOList = functionQueryService.listFunctionByUserOid(user.getOid(), null, ResourceControlTypeEnum.BS);
+         if (!CollectionUtils.isEmpty(functionVOList)) {
+         List<String> functionOidList = functionVOList.stream().map(s -> s.getOid()).collect(Collectors.toList());
+         sessionInfo.setFunctionOids(functionOidList);
+         } else {
+         sessionInfo.setFunctionOids(new ArrayList());
+         }*/
 
         //娣诲姞鍒颁細璇濅俊鎭�
-//        saveSessionInfo(sessionInfo);
+        TokenVO tokenVO = saveSessionInfo(sessionInfo);
+        loginResult.setTokenVO(tokenVO);
 
-        //鐧诲綍鍚庢墽琛�
-//        BusAnnotationUtil.callForAnnotation(VciLoginPlugin.class,VciLoginAfter.class,userDTO,clientInfo,loginResult);
+        loginResult.setSuccess(true);
         return loginResult;
     }
 
+    private MachineInfo getMachieInfo(RequestClientInfo clientInfo) {
+        MachineInfo machine = new MachineInfo();
+        machine.country = clientInfo.getCountry();
+        machine.language = clientInfo.getLanguage();
+        machine.osUser = clientInfo.getOsUser();
+        machine.machine = clientInfo.getMachine();
+        return machine;
+    }
+
+    /**
+     * 鑾峰彇鐢ㄦ埛淇℃伅
+     * @param userId userId
+     * @Return com.vci.frameworkcore.pagemodel.SmUserVO
+     */
+    private SmUserVO getUserByUserId(String userId) {
+        return userQueryService.getUserByUserId(userId);
+    }
 
     /**
      * 鍗曠偣鐧诲綍
@@ -302,7 +529,7 @@
      * @throws VciBaseException 鐧诲綍澶辫触鐨勬椂鍊欐姏鍑哄紓甯�
      */
     @Override
-    public LoginResultBO singleLogin(LoginUserDTO userDTO, RequestClientInfo clientInfo) throws VciBaseException {
+    public LoginResultBO singleLogin(LoginUserDTO userDTO, RequestClientInfo clientInfo) throws PLException {
         return login(userDTO,clientInfo,false);
     }
 
@@ -335,6 +562,8 @@
                 }
             });
         }
+        //娓呴櫎瀛樺綋鍓嶇櫥褰曠殑鐢ㄦ埛锛堟�绘暟-1锛�
+        redisService.decreOnlineUser(VConstant.CURRENT_LOGGED_USERS_KEY);
         sessionForLogin.logout(userToken);
         if(!CollectionUtils.isEmpty(logoutpluginBeanMap)){
             logoutpluginBeanMap.forEach((k,v) -> {
@@ -358,37 +587,15 @@
     }
 
     /**
-     * 鏍¢獙鏄惁鐧诲綍
-     * @param userId 鐢ㄦ埛鍚�
-     * @return 宸茬粡鐧诲綍鏃讹紝
-     */
-    private String checkIsLogined(String userId) {
-        if(sessionForLogin == null){
-            throw new VciBaseException("娌℃湁閰嶇疆浼氳瘽瀛樺偍鐨勬湇鍔�");
-        }
-        return sessionForLogin.checkIsLogined(userId);
-    }
-
-    /**
-     * 鎶婁互鍓嶇殑鐧诲綍淇℃伅绉婚櫎
-     * @param userId 鐢ㄦ埛鍚�
-     */
-    private void popUser(String userId){
-        if(sessionForLogin == null){
-            throw new VciBaseException("娌℃湁閰嶇疆浼氳瘽瀛樺偍鐨勬湇鍔�");
-        }
-        sessionForLogin.popUser(userId);
-    }
-
-    /**
      * 淇濆瓨浼氳瘽淇℃伅
      * @param sessionInfo 浼氳瘽淇℃伅
      */
-    private void saveSessionInfo(SessionInfo sessionInfo){
+    private TokenVO saveSessionInfo(SessionInfo sessionInfo){
         if(sessionForLogin == null){
             throw new VciBaseException("娌℃湁閰嶇疆浼氳瘽瀛樺偍鐨勬湇鍔�");
         }
-        sessionForLogin.saveSessionInfo(sessionInfo);
+        WebThreadLocalUtil.setCurrentUserSessionInfoInThread(sessionInfo);
+        return sessionForLogin.createToken(sessionInfo);
     }
 
     /**
@@ -438,10 +645,7 @@
         sessionInfo.setRtxNo(user.getRtxNo());
         sessionInfo.setIMId(user.getIMNo());
         sessionInfo.setPortalId(user.getId());
-
-//        sessionInfo.setWorkNo(user.getWorkNo());
-//        sessionInfo.setWorkTypeOid(user.getPkWorkType());
-//        sessionInfo.setWorkTypeName(user.getPkWorkTypeText());
+        sessionInfo.setLastLoginTime(user.getLastLoginTime()!=null?user.getLastLoginTime().getTime(): VciDateUtil.getNowTime());
     }
 
     /**
@@ -475,4 +679,42 @@
     private void updateUserForLoginSuccess(String userOid){
         userQueryService.updateUserLoginTime(userOid);
     }
+
+    /**
+     * 鑾峰彇鐧诲綍閿欒鐮�
+     * @param chkRes 骞冲彴鐧诲綍鏍¢獙缁撴灉
+     * @Return java.lang.String
+     */
+    public String getErrorCode(LoginResult chkRes){
+        String message = "";
+        switch(chkRes.state.value())
+        {
+            case 0:
+                return UNKNOWN;
+            case 1:
+                return LOGIN_SUCCESS;
+            case 10:
+                return USER_NOT_FOUND;
+            case 11:
+                return USER_PWD_NOT_EQUAL;
+            case 12:
+                return USER_IS_DISABLED;
+            case 13:
+                return USER_IS_LOCK;
+            case 14:
+                return PASSWORD_INIT;
+            case 15:
+                return PASSWORD_REMAIN_DAY;
+            case 16:
+                return PASSWORD_EXPIRE;
+            case 17:
+                return PASSWORD_POLICY_UPDATED;
+            case 20:
+                return SYSTEM_ERROR;
+            default:
+                message = SYSTEM_ERROR;
+                break;
+        }
+        return message;
+    }
 }

--
Gitblit v1.9.3