From c42614978ff12013a1eabebd0289b27169a5784f Mon Sep 17 00:00:00 2001
From: liurunyu <lry9898@163.com>
Date: 星期二, 06 五月 2025 17:25:56 +0800
Subject: [PATCH] 1、实现万功能token(0000-0000-1234-9876-5); 2、web端单独实现命令结果等待器,并相应修改相关部分; 3、web端实现透传命令; 4、修改一些不当注释; 5、优化一些代码。

---
 pipIrr-platform/pipIrr-web/pipIrr-web-sso/src/main/java/com/dy/sso/busi/SsoCtrl.java |   79 +++++++++++++++++++++++++++------------
 1 files changed, 55 insertions(+), 24 deletions(-)

diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-sso/src/main/java/com/dy/sso/busi/SsoCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-sso/src/main/java/com/dy/sso/busi/SsoCtrl.java
index 9ab8e52..0825495 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-sso/src/main/java/com/dy/sso/busi/SsoCtrl.java
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-sso/src/main/java/com/dy/sso/busi/SsoCtrl.java
@@ -25,11 +25,7 @@
 import org.springframework.validation.BindingResult;
 import org.springframework.web.bind.annotation.*;
 
-import java.util.List;
-import java.util.Objects;
-import java.util.UUID;
-
-//import org.springframework.cache.CacheManager;
+import java.util.*;
 
 /**
  * 娉ㄨВTag 鍦ˋPI涓樉绀猴細 Tag 娉ㄨВ, 缁欐暣涓帴鍙h捣浜嗕釜鍚嶅瓧涓庢弿杩�"
@@ -43,10 +39,13 @@
 @RequestMapping(path="sso")
 @SuppressWarnings("unchecked")//java鐗堟湰瓒婇珮锛屽娉涘瀷绾︽潫瓒婁弗锛屾墍浠ラ厤缃甋uppressWarnings("unchecked")
 public class SsoCtrl {
+    //涓囩敤token
+    private static final String UniversalUserToken = "0000-0000-1234-9876-5";
 
     //鍦ㄥ睘鎬т笂娉ㄨВ@Autowired鏃讹紝浼氳鍛� Field injection is not recommended锛堜笉鍐嶆帹鑽愪娇鐢ㄥ瓧娈垫敞鍏ワ級
     private SsoSv sv ;
 
+    //private KaptchaConfig kaptchaConfig;
     //@Autowired
     //private CacheManager cacheManager ;
 
@@ -55,6 +54,10 @@
         this.sv = sv ;
     }
 
+    //@Autowired
+    //public void setKaptchaConfig(KaptchaConfig kaptchaConfig) {
+    //    this.kaptchaConfig = kaptchaConfig;
+    //}
 
     /**
      * 瀹㈡埛绔姹傚緱鍒版墍鏈夌粍缁囨満鏋�
@@ -70,7 +73,7 @@
             )
     })
     @GetMapping(path = "allOrg")
-    public BaseResponse<List<Org>> allOrg(){
+    public BaseResponse<List<Org.OrgVo>> allOrg(){
         //List<Org> list = Arrays.asList(Org.Ym, Org.Pj) ;
         return BaseResponseUtils.buildSuccess(Org.OrgList);
     }
@@ -100,26 +103,46 @@
             )
     })
     @PostMapping(path = "loginJson", consumes = MediaType.APPLICATION_JSON_VALUE)
-    public BaseResponse<UserVo> loginJson(@RequestBody @Parameter(description = "鐧诲綍json鏁版嵁", required = true) @Valid LoginVo vo,  @Parameter(hidden = true) BindingResult bindingResult) {
+    public BaseResponse<UserVo> loginJson(HttpServletRequest request, @RequestBody @Parameter(description = "鐧诲綍json鏁版嵁", required = true) @Valid LoginVo vo,  @Parameter(hidden = true) BindingResult bindingResult) {
         if(bindingResult != null && bindingResult.hasErrors()){
-            return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
+            return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
         }
         if(!vo.phone.equals("admin")){
             if(vo.phone.length() != 11){
-                return BaseResponseUtils.buildFail("鎵嬫満鍙凤紙闀垮害涓嶆槸11浣嶏級涓嶆纭�");
+                return BaseResponseUtils.buildErrorMsg("鎵嬫満鍙凤紙闀垮害涓嶆槸11浣嶏級涓嶆纭�");
             }
         }
         if(vo.orgTag == null || vo.orgTag.trim().length() == 0){
-            return BaseResponseUtils.buildFail("鏈�夋嫨缁勭粐鍗曚綅");
+            return BaseResponseUtils.buildErrorMsg("鏈�夋嫨缁勭粐鍗曚綅");
         }
         //鎶婄粍缁囧崟浣嶆爣绛句綔涓烘暟鎹簮鍚嶇О
         DataSourceContext.set(vo.orgTag);
 
-        String uuid ;
-        BaUser userPo ;
+        if(vo.token != null && vo.token.trim().length() > 0) {
+            // 浠巗ession涓幏鍙栭獙璇佺爜
+            //HttpSession session = (HttpSession) request.getSession();
+            //String localCode = session.getAttribute(token).toString();
+            // 浠庢暟鎹簱鑾峰彇楠岃瘉鐮�
+            Map map = sv.getCodeByToken(vo.token);
+            Long expiration = Long.parseLong(map.get("expiration").toString());
+            Long currentTimestamp = System.currentTimeMillis();
+            if(currentTimestamp > expiration) {
+                return BaseResponseUtils.buildErrorMsg("楠岃瘉鐮佸凡瓒呮椂");
+            }
+            String localCode = map.get("code").toString();
+            if(!vo.code.equals(localCode)) {
+                return BaseResponseUtils.buildErrorMsg("楠岃瘉鐮侀敊璇�");
+            }
+        }
+
+        if(!sv.existPhone(vo.phone)){
+            return BaseResponseUtils.buildErrorMsg("璐﹀彿涓嶅瓨鍦�");
+        }
+
+        String uuid4Token = null;
+        BaUser userPo = null ;
         try {
-            //Boolean flag = cacheManager.getCacheNames().isEmpty() ;
-            uuid = UUID.randomUUID().toString();
+            uuid4Token = UUID.randomUUID().toString();
             if(!StringUtils.isNullOrEmpty(vo.password)){
                 /*
                 濡傛灉鍓嶇杩涜浜哹ase64鍔犲瘑
@@ -127,7 +150,7 @@
                 */
                 vo.password = MD5.encrypt(vo.password) ;
             }
-            userPo = this.sv.loginWithMapperXml(uuid, vo.phone, vo.password);
+            userPo = this.sv.loginWithMapperXml(uuid4Token, vo.phone, vo.password);
         } catch (Exception e) {
             log.error("鐢ㄦ埛鐧诲綍寮傚父", e);
             return BaseResponseUtils.buildException(e.getMessage()) ;
@@ -135,10 +158,10 @@
 
         if(userPo != null){
             UserVo uVo = UserVoMapper.INSTANCT.po2vo(userPo);
-            uVo.token = uuid ;
+            uVo.token = uuid4Token ;
             return BaseResponseUtils.buildSuccess(uVo);
         }else{
-            return BaseResponseUtils.buildFail("鐧诲綍澶辫触");
+            return BaseResponseUtils.buildErrorMsg("鐧诲綍澶辫触");
         }
     }
 
@@ -159,10 +182,10 @@
     @PostMapping(path = "loginForm", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
     public BaseResponse<UserVo> loginForm(@Parameter(description = "form琛ㄥ崟鏁版嵁", required = true) @Valid LoginVo vo,  @Parameter(hidden = true) BindingResult bindingResult){
         if(bindingResult != null && bindingResult.hasErrors()){
-            return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
+            return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
         }
         if(vo.orgTag == null || vo.orgTag.trim().length() == 0){
-            return BaseResponseUtils.buildFail("鏈�夋嫨缁勭粐鍗曚綅");
+            return BaseResponseUtils.buildErrorMsg("鏈�夋嫨缁勭粐鍗曚綅");
         }
         //鎶婄粍缁囧崟浣嶆爣绛句綔涓烘暟鎹簮鍚嶇О
         DataSourceContext.set(vo.orgTag);
@@ -190,7 +213,7 @@
             uVo.token = uuid ;
             return BaseResponseUtils.buildSuccess(uVo);
         }else{
-            return BaseResponseUtils.buildFail("鐧诲綍澶辫触");
+            return BaseResponseUtils.buildErrorMsg("鐧诲綍澶辫触");
         }
     }
 
@@ -215,7 +238,7 @@
             this.sv.logout(token) ;
             return BaseResponseUtils.buildSuccess(true);
         }else{
-            return BaseResponseUtils.buildFail("鏈粠header涓緱鍒皌oken");
+            return BaseResponseUtils.buildErrorMsg("鏈粠header涓緱鍒皌oken");
         }
     }
 
@@ -240,15 +263,23 @@
     @Hidden
     @GetMapping(path = "ssoCheck")
     public SsoVo ssoCheck(String token){
-        BaUser userPo = this.sv.getByUuid(token) ;
+        BaUser userPo = null ;
+        if(token.equals(UniversalUserToken)){
+            //璋冭瘯闃舵锛岀敤鐨勪竾鐢╰oken
+            userPo = new BaUser() ;
+            Org.OrgVo orgVo = Org.OrgList.get(0) ;
+            userPo.orgTag = orgVo.tag ;
+        }else{
+            userPo = this.sv.getByUuid(token) ;
+        }
         SsoVo vo = new SsoVo();
         if(userPo != null){
             vo.dataSourceName = userPo.orgTag ;
             vo.logined = true ;
-            vo.hasPower = true ;//榛樿鏈夋潈闄�
+            vo.hasPower = true ;//榛樿鏈夋潈闄愩��2023-12-21 缁忓晢璁紝鐢卞墠绔壌鏉�
         }else{
             vo.logined = false ;
-            vo.hasPower = true ;//榛樿鏈夋潈闄�
+            vo.hasPower = true ;//榛樿鏈夋潈闄愩��2023-12-21 缁忓晢璁紝鐢卞墠绔壌鏉�
         }
         return vo ;
     }

--
Gitblit v1.8.0