From c0a1e58617d69fa78cceebb27376e57e324a562e Mon Sep 17 00:00:00 2001
From: zhubaomin <zhubaomin>
Date: 星期三, 21 八月 2024 08:51:51 +0800
Subject: [PATCH] Merge branch 'master' of http://8.140.179.55:20000/r/pipIrr-SV

---
 pipIrr-platform/pipIrr-web/pipIrr-web-sso/src/main/java/com/dy/sso/busi/SsoCtrl.java |  211 +++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 198 insertions(+), 13 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 321f2c2..b15cb61 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
@@ -1,10 +1,14 @@
 package com.dy.sso.busi;
 
 import com.dy.common.aop.SsoVo;
+import com.dy.common.multiDataSource.DataSourceContext;
+import com.dy.common.util.MD5;
 import com.dy.common.webUtil.BaseResponse;
 import com.dy.common.webUtil.BaseResponseUtils;
 import com.dy.common.webUtil.ResultCodeMsg;
 import com.dy.pipIrrGlobal.pojoBa.BaUser;
+import com.dy.pipIrrGlobal.util.Org;
+import com.mysql.cj.util.StringUtils;
 import io.swagger.v3.oas.annotations.Hidden;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.Parameter;
@@ -17,11 +21,11 @@
 import jakarta.validation.Valid;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
-//import org.springframework.cache.CacheManager;
 import org.springframework.http.MediaType;
 import org.springframework.validation.BindingResult;
 import org.springframework.web.bind.annotation.*;
 
+import java.util.List;
 import java.util.Objects;
 import java.util.UUID;
 
@@ -44,7 +48,6 @@
     //@Autowired
     //private CacheManager cacheManager ;
 
-
     @Autowired
     public void setSv(SsoSv sv ){
         this.sv = sv ;
@@ -52,8 +55,28 @@
 
 
     /**
+     * 瀹㈡埛绔姹傚緱鍒版墍鏈夌粍缁囨満鏋�
+     * @return 鎵�鏈夌粍缁囨満鏋勬暟鎹�
+     */
+    @Operation(summary = "鎵�鏈夌粍缁囨満鏋�", description = "杩斿洖鎵�鏈夋墍鏈夌粍缁囨満鏋勬暟鎹�")
+    @ApiResponses(value = {
+            @ApiResponse(
+                    responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE,
+                    description = "杩斿洖鎵�鏈夌粍缁囨満鏋勬暟鎹紙BaseResponse.content:[ { \"tag\":\"ym\", \"name\":\"鍏冭皨\" }, { \"tag\":\"鐗囪\", \"name\":\"鐗囪闀嘰" }]锛�",
+                    content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
+                            schema = @Schema(implementation = Org.class))}
+            )
+    })
+    @GetMapping(path = "allOrg")
+    public BaseResponse<List<Org.OrgVo>> allOrg(){
+        //List<Org> list = Arrays.asList(Org.Ym, Org.Pj) ;
+        return BaseResponseUtils.buildSuccess(Org.OrgList);
+    }
+
+    /**
      * 瀹㈡埛绔姹傜敤鎴风櫥褰曪紝瀹㈡埛绔彁浜son鏁版嵁
      * @param vo 鐢ㄦ埛鐧诲綍鍊煎璞�
+     * @param bindingResult 杈撳叆楠岃瘉
      * @return 鐧诲綍鐢ㄦ埛鍊煎璞�
      */
     @Operation(summary = "鍗曠偣鐧诲綍", description = "鎻愪氦鐧诲綍鐢ㄦ埛鍊煎璞★紙json鏍煎紡锛夛紝杩涜鍗曠偣鐧诲綍")
@@ -75,17 +98,34 @@
             )
     })
     @PostMapping(path = "loginJson", consumes = MediaType.APPLICATION_JSON_VALUE)
-    public BaseResponse<UserVo> loginJson(@Valid @RequestBody LoginVo vo,  @Parameter(hidden = true) BindingResult bindingResult) {
+    public BaseResponse<UserVo> loginJson(@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());
         }
+        if(!vo.phone.equals("admin")){
+            if(vo.phone.length() != 11){
+                return BaseResponseUtils.buildFail("鎵嬫満鍙凤紙闀垮害涓嶆槸11浣嶏級涓嶆纭�");
+            }
+        }
+        if(vo.orgTag == null || vo.orgTag.trim().length() == 0){
+            return BaseResponseUtils.buildFail("鏈�夋嫨缁勭粐鍗曚綅");
+        }
+        //鎶婄粍缁囧崟浣嶆爣绛句綔涓烘暟鎹簮鍚嶇О
+        DataSourceContext.set(vo.orgTag);
 
         String uuid ;
         BaUser userPo ;
         try {
             //Boolean flag = cacheManager.getCacheNames().isEmpty() ;
             uuid = UUID.randomUUID().toString();
-            userPo = this.sv.login(uuid, vo.phone, vo.password);
+            if(!StringUtils.isNullOrEmpty(vo.password)){
+                /*
+                濡傛灉鍓嶇杩涜浜哹ase64鍔犲瘑
+                po.password = new String(Base64.getDecoder().decode(po.password)) ;
+                */
+                vo.password = MD5.encrypt(vo.password) ;
+            }
+            userPo = this.sv.loginWithMapperXml(uuid, vo.phone, vo.password);
         } catch (Exception e) {
             log.error("鐢ㄦ埛鐧诲綍寮傚父", e);
             return BaseResponseUtils.buildException(e.getMessage()) ;
@@ -119,13 +159,25 @@
         if(bindingResult != null && bindingResult.hasErrors()){
             return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
         }
+        if(vo.orgTag == null || vo.orgTag.trim().length() == 0){
+            return BaseResponseUtils.buildFail("鏈�夋嫨缁勭粐鍗曚綅");
+        }
+        //鎶婄粍缁囧崟浣嶆爣绛句綔涓烘暟鎹簮鍚嶇О
+        DataSourceContext.set(vo.orgTag);
 
         String uuid ;
         BaUser userPo ;
         try {
             //Boolean flag = cacheManager.getCacheNames().isEmpty() ;
             uuid = UUID.randomUUID().toString();
-            userPo = this.sv.login(uuid, vo.phone, vo.password);
+            if(!StringUtils.isNullOrEmpty(vo.password)){
+                /*
+                濡傛灉鍓嶇杩涜浜哹ase64鍔犲瘑
+                po.password = new String(Base64.getDecoder().decode(po.password)) ;
+                */
+                vo.password = MD5.encrypt(vo.password) ;
+            }
+            userPo = this.sv.loginWithMapperXml(uuid, vo.phone, vo.password);
         } catch (Exception e) {
             log.error("鐢ㄦ埛鐧诲綍寮傚父", e);
             return BaseResponseUtils.buildException(e.getMessage()) ;
@@ -177,25 +229,63 @@
         BaUser userPo = this.sv.getByUuid(token) ;
         return userPo == null ? null : userPo.id ;
     }
-
     /**
      * 姝ゆ柟娉曚緵瀛愭ā鍧楃郴缁熻皟鐢紝鎵�浠ヤ笉鍏紑鍦ˋPI鎺ュ彛涓�
-     * 鏂规硶鍔熻兘锛氶獙璇佹槸鍚﹀凡缁忕櫥褰曪紝濡傛灉鐧诲綍浜嗭紝鍐嶉獙璇佹潈闄�
+     * 鏂规硶鍔熻兘锛氶獙璇佹槸鍚﹀凡缁忕櫥褰�
      * @param token 鐧诲綍鐢ㄦ埛token
-     * @param power 楠岃瘉涓�涓潈闄�
-     * @param allPower 楠岃瘉鎵�鏈夋潈闄�
-     * @param anyPower 楠岃瘉浠讳綍涓�涓潈闄�
      * @return SsoVo
      */
     @Hidden
     @GetMapping(path = "ssoCheck")
-    public SsoVo ssoCheck(String token, String power, String[] allPower, String[] anyPower){
+    public SsoVo ssoCheck(String token){
         BaUser userPo = this.sv.getByUuid(token) ;
         SsoVo vo = new SsoVo();
         if(userPo != null){
+            vo.dataSourceName = userPo.orgTag ;
             vo.logined = true ;
-            vo.hasPower = true ;
-            vo.dataSourceName = userPo.getOrgTag() ;
+            vo.hasPower = true ;//榛樿鏈夋潈闄愩��2023-12-21 缁忓晢璁紝鐢卞墠绔壌鏉�
+        }else{
+            vo.logined = false ;
+            vo.hasPower = true ;//榛樿鏈夋潈闄愩��2023-12-21 缁忓晢璁紝鐢卞墠绔壌鏉�
+        }
+        return vo ;
+    }
+    /**
+     * 姝ゆ柟娉曚緵瀛愭ā鍧楃郴缁熻皟鐢紝鎵�浠ヤ笉鍏紑鍦ˋPI鎺ュ彛涓�
+     * 鏂规硶鍔熻兘锛氶獙璇佹槸鍚﹀凡缁忕櫥褰曪紝濡傛灉鐧诲綍浜嗭紝鍐嶉獙璇佹潈闄�
+     * @param token 鐧诲綍鐢ㄦ埛token
+     * @param privilege 楠岃瘉涓�涓潈闄�
+     * @param allPrivilege 楠岃瘉鎵�鏈夋潈闄�
+     * @param anyPrivilege 楠岃瘉浠讳綍涓�涓潈闄�
+     * @return SsoVo
+     */
+    @Hidden
+    @GetMapping(path = "ssoPowerCheck")
+    public SsoVo ssoPowerCheck(String token, String privilege, String[] allPrivilege, String[] anyPrivilege){
+        BaUser userPo = this.sv.getByUuid(token) ;
+        SsoVo vo = new SsoVo();
+        if(userPo != null){
+            vo.dataSourceName = userPo.orgTag ;
+            vo.logined = true ;
+            vo.hasPower = false ;//榛樿鏄棤鏉冮檺
+            if(userPo.supperAdmin != null && userPo.supperAdmin == 1){
+                vo.hasPower = true ;
+            }else{
+                if(privilege.equals("-1")){
+                    //鏃犻渶鏉冮檺楠岃瘉
+                    vo.hasPower = true ;
+                }else{
+                    if(userPo.privileges != null && userPo.privileges.size() > 0){
+                        vo.hasPower = this.hasOnePrivilege(privilege, userPo) ;
+                        if(!vo.hasPower){
+                            vo.hasPower = this.hasAllPrivilege(allPrivilege, userPo) ;
+                            if(!vo.hasPower){
+                                vo.hasPower = this.hasAnyPrivilege(anyPrivilege, userPo) ;
+                            }
+                        }
+                    }
+                }
+            }
         }else{
             vo.logined = false ;
             vo.hasPower = false ;
@@ -203,5 +293,100 @@
         return vo ;
     }
 
+    /**
+     * 鑾峰緱褰撳墠鐧诲綍鐢ㄦ埛
+     * @param token 鐧诲綍鐢ㄦ埛token
+     * @return SsoVo
+     */
+    @Hidden
+    @GetMapping(path = "ssoCurUser")
+    public CurUserVo ssoCurUser(String token){
+        BaUser userPo = this.sv.getByUuid(token) ;
+        CurUserVo vo = new CurUserVo();
+        if(userPo != null){
+            vo.id = userPo.id ;
+            vo.name = userPo.userName;
+        }
+        return vo ;
+    }
+    /////////////////////////////////////////////////////////////////
+    //
+    // 浠ヤ笅绉佹湁鏂规硶
+    //
+    /////////////////////////////////////////////////////////////////
+    /**
+     * 鍒ゆ柇鐧诲綍鐢ㄦ埛鏄惁鎷ユ湁鎸囧畾鐨勪竴涓潈闄�
+     * @param privilege 鎸囧畾鐨勪竴涓潈闄�
+     * @param userPo 褰撳墠鐧诲綍鐢ㄦ埛
+     * @return 鏄惁鏈夋潈闄�
+     */
+    private boolean hasOnePrivilege(String privilege, BaUser userPo){
+        boolean hasPrivilege  = false ;
+        if (privilege != null && !privilege.trim().equals("")) {
+            int intPri = Integer.parseInt(privilege);
+            for (Integer pri : userPo.privileges) {
+                if (pri == intPri) {
+                    hasPrivilege = true;
+                    break;
+                }
+            }
+        }
+        return hasPrivilege ;
+    }
+
+    /**
+     * 鍒ゆ柇鐧诲綍鐢ㄦ埛鏄惁鎷ユ湁鎸囧畾鐨勫涓潈闄�
+     * @param allPrivilege 鎸囧畾鐨勫涓潈闄�
+     * @param userPo 褰撳墠鐧诲綍鐢ㄦ埛
+     * @return 鏄惁鏈夋潈闄�
+     */
+    private boolean hasAllPrivilege(String[] allPrivilege, BaUser userPo){
+        boolean hasPrivilege  = false ;
+        if(allPrivilege != null && allPrivilege.length > 0){
+            int intPri ;
+            int count = 0 ;
+            for(String strPri : allPrivilege){
+                intPri = Integer.parseInt(strPri) ;
+                for(Integer pri : userPo.privileges){
+                    if(pri == intPri){
+                        count++ ;
+                        break ;
+                    }
+                }
+            }
+            if(count  == allPrivilege.length){
+                hasPrivilege = true ;
+            }
+        }
+        return hasPrivilege ;
+    }
+
+
+    /**
+     * 鍒ゆ柇鐧诲綍鐢ㄦ埛鏄惁鎷ユ湁鎸囧畾鐨勬煇涓潈闄�
+     * @param anyPrivilege 鎸囧畾鐨勫涓潈闄�
+     * @param userPo 褰撳墠鐧诲綍鐢ㄦ埛
+     * @return 鏄惁鏈夋潈闄�
+     */
+    private boolean hasAnyPrivilege(String[] anyPrivilege, BaUser userPo){
+        boolean hasPrivilege  = false ;
+        int intPri ;
+        if(anyPrivilege != null && anyPrivilege.length > 0){
+            for(String strPri : anyPrivilege){
+                intPri = Integer.parseInt(strPri) ;
+                for(Integer pri : userPo.privileges){
+                    if(pri == intPri){
+                        hasPrivilege = true ;
+                        break ;
+                    }
+                }
+                if(hasPrivilege){
+                    break ;
+                }
+            }
+        }
+        return hasPrivilege ;
+    }
+
 
 }

--
Gitblit v1.8.0