From b7d7d80a8a9e9ac145a05b5e1d545b6b61fc0cc4 Mon Sep 17 00:00:00 2001
From: zjh <1084500556@qq.com>
Date: 星期五, 30 五月 2025 18:17:33 +0800
Subject: [PATCH] zjh20250530

---
 ltkj-framework/src/main/java/com/ltkj/framework/web/service/SysLoginService.java |   99 +++++++++++++++++++++++++++++--------------------
 1 files changed, 58 insertions(+), 41 deletions(-)

diff --git a/ltkj-framework/src/main/java/com/ltkj/framework/web/service/SysLoginService.java b/ltkj-framework/src/main/java/com/ltkj/framework/web/service/SysLoginService.java
index 355c5b8..3a7da03 100644
--- a/ltkj-framework/src/main/java/com/ltkj/framework/web/service/SysLoginService.java
+++ b/ltkj-framework/src/main/java/com/ltkj/framework/web/service/SysLoginService.java
@@ -19,9 +19,7 @@
 import com.ltkj.hosp.domain.TjCustomer;
 import com.ltkj.hosp.service.IDictHospService;
 import com.ltkj.hosp.service.ITjCustomerService;
-import com.ltkj.system.service.ISysDeptService;
-import com.ltkj.system.service.ISysMenuService;
-import com.ltkj.system.service.SysParametersDisposeService;
+import com.ltkj.system.service.*;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.security.authentication.AuthenticationManager;
@@ -39,7 +37,7 @@
 import com.ltkj.framework.manager.AsyncManager;
 import com.ltkj.framework.manager.factory.AsyncFactory;
 import com.ltkj.framework.security.context.AuthenticationContextHolder;
-import com.ltkj.system.service.ISysUserService;
+import org.springframework.util.DigestUtils;
 
 import java.util.Date;
 import java.util.HashMap;
@@ -75,6 +73,8 @@
     private ISysDeptService deptService;
     @Autowired
     private SysParametersDisposeService parametersDisposeService;
+    @Autowired
+    private ISysConfigService configService;
 
     // 鏄惁鍏佽璐︽埛澶氱粓绔悓鏃剁櫥褰曪紙true鍏佽 false涓嶅厑璁革級
     @Value("${token.soloLogin}")
@@ -96,26 +96,33 @@
      */
     public String login(String username, String password, Boolean type,String code,String uuid) {
 
-        String verifyKey = CacheConstants.CAPTCHA_CODE_KEY + uuid;
-        String captcha = redisCache.getCacheObject(verifyKey);
-        redisCache.deleteObject(verifyKey);
-        if (captcha == null)
-        {
-            AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.expire")));
-            throw new CaptchaExpireException();
-        }
-        if (!code.equalsIgnoreCase(captcha))
-        {
-            AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.error")));
-            throw new CaptchaException();
+        String aSwitch = configService.selectConfigByKey("captcha_switch");
+        if(null !=aSwitch && aSwitch.equalsIgnoreCase("Y")){
+            String verifyKey = CacheConstants.CAPTCHA_CODE_KEY + uuid;
+            String captcha = redisCache.getCacheObject(verifyKey);
+            redisCache.deleteObject(verifyKey);
+            if (captcha == null)
+            {
+                AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.expire")));
+                throw new CaptchaExpireException();
+            }
+            if (!code.equalsIgnoreCase(captcha))
+            {
+                AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.error")));
+                throw new CaptchaException();
+            }
         }
 
         // 鐢ㄦ埛楠岃瘉
         Authentication authentication = null;
         try {
             //鐧诲綍瀵嗙爜瑙e瘑
-            UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(username, RsaUtils.decryptByPrivateKey(password));
-            //UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(username, password);
+            String s = RsaUtils.decryptByPrivateKey(password);
+//            String s = password;
+            if(username.equals("10001")){
+                s=username+s;
+            }
+            UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(username,s);
             AuthenticationContextHolder.setContext(authenticationToken);
             // 璇ユ柟娉曚細鍘昏皟鐢║serDetailsServiceImpl.loadUserByUsername
             authentication = authenticationManager.authenticate(authenticationToken);
@@ -147,8 +154,8 @@
                             loginUser.setHospName(dictHosp.getHospAreaName());
                             if(!SecurityUtils.isAdmin(user.getUserId())){
                                 if(dictHosp.getSecretKey() != null && dictHosp.getExpirationTime() != null){
-                                    if (!SecurityUtils.matchesMallMerchantSecretKey(secret,dictHosp.getHospAreaId(),dictHosp.getAreaid(),
-                                            dictHosp.getExpirationTime(),dictHosp.getSecretKey())) {
+                                    if (!SecurityUtils.matchesMallMerchantSecretKey(secret,dictHosp.getHospAreaId(),dictHosp.getHospAreaName(),
+                                            dictHosp.getExpirationTime(),dictHosp.getSecretKey()) || new Date().after(DateUtil.endOfDay(dictHosp.getExpirationTime()))) {
                                         throw new SecretKeyException("鍟嗗宸茶繃鏈熻缁垂浣跨敤");
                                     }
                                     long between = DateUtil.between(new Date(), DateUtil.endOfDay(dictHosp.getExpirationTime()), DateUnit.DAY);
@@ -210,24 +217,29 @@
      * @param password 瀵嗙爜
      * @return 缁撴灉
      */
-    public String Cuslogin(String username, String password, Boolean type,String code,String uuid) {
+    public String Cuslogin(String username,String sfzh, String password, Boolean type,String code,String uuid) {
 
-        String verifyKey = CacheConstants.CAPTCHA_CODE_KEY + uuid;
-        String captcha = redisCache.getCacheObject(verifyKey);
-        redisCache.deleteObject(verifyKey);
-        if (captcha == null)
-        {
-            AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.expire")));
-            throw new CaptchaExpireException();
+        String aSwitch = configService.selectConfigByKey("captcha_switch");
+        if(null !=aSwitch && aSwitch.equalsIgnoreCase("Y")){
+            String verifyKey = CacheConstants.CAPTCHA_CODE_KEY + uuid;
+            String captcha = redisCache.getCacheObject(verifyKey);
+            redisCache.deleteObject(verifyKey);
+            if (captcha == null)
+            {
+                AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.expire")));
+                throw new CaptchaExpireException();
+            }
+            if (!code.equalsIgnoreCase(captcha))
+            {
+                AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.error")));
+                throw new CaptchaException();
+            }
         }
-        if (!code.equalsIgnoreCase(captcha))
-        {
-            AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.error")));
-            throw new CaptchaException();
-        }
-        LoginUser loginUser = loadCusByCusname(username, password);
+
+
+        LoginUser loginUser = loadCusByCusname(username,sfzh, password);
         if (loginUser == null) {
-            return "鐢ㄦ埛鍚嶆垨瀵嗙爜閿欒";
+            return null;
         }
 //       闄愬埗璐︽埛涓嶅厑璁稿缁堢鐧诲綍
         if (!soloLogin) {
@@ -247,19 +259,24 @@
         return tokenService.createToken(loginUser);
     }
 
-    public LoginUser loadCusByCusname(String username, String password) {
+    public LoginUser loadCusByCusname(String username,String sfzh, String password) {
         LambdaQueryWrapper<TjCustomer> wq = new LambdaQueryWrapper<>();
         wq.eq(TjCustomer::getCusPhone, username);
+        wq.eq(TjCustomer::getCusIdcard, sfzh);
         List<TjCustomer> customerList = customerService.list(wq);
-        if (null == customerList || customerList.size() == 0) {
+        if (null == customerList || customerList.isEmpty()) {
             //throw new ServiceException("鐧诲綍鐢ㄦ埛锛�" + username + " 涓嶅瓨鍦�");
-            throw new ServiceException("璐︽埛鎴栧瘑鐮侀敊璇紝璇锋鏌ワ紒");
+            throw new ServiceException("璐﹀彿鎴栧瘑鐮侀敊璇紝璇锋鏌ワ紒");
         }
         for (TjCustomer tjCustomer : customerList) {
             try {
-                password = RsaUtils.decryptByPrivateKey(password);
-                boolean b = SecurityUtils.matchesPassword(password, tjCustomer.getCusPassword());
-                if (b) {
+//                password = RsaUtils.decryptByPrivateKey(password);
+//                boolean b = SecurityUtils.matchesPassword(password, tjCustomer.getCusPassword());
+//                if (b) {
+//                    return createLoginCus(tjCustomer);
+//                }
+                password = DigestUtils.md5DigestAsHex(password.getBytes());
+                if (password.equals(tjCustomer.getCusPassword())){
                     return createLoginCus(tjCustomer);
                 }
             } catch (Exception e) {

--
Gitblit v1.8.0