Kaynağa Gözat

Merge branches 'develop' and 'release/v2.1.1-beta' of 192.168.0.144:dcuc-tjdsj/auth-service into develop

 Conflicts:
	dcuc-auth-api/pom.xml
	dcuc-auth-model/pom.xml
	dcuc-auth-service/pom.xml
	dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/auth/facade/ServiceAuthFacade.java
	dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/auth/service/IServiceAuthResultService.java
	dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/auth/service/impl/ServiceAuthResultServiceImpl.java
	pom.xml
huangzqa 4 yıl önce
ebeveyn
işleme
30cb249d41
38 değiştirilmiş dosya ile 1004 ekleme ve 220 silme
  1. 1 1
      dcuc-auth-api/pom.xml
  2. 17 0
      dcuc-auth-api/src/main/java/com/dragoninfo/dcuc/auth/auth/facade/IBimBusinessFacade.java
  3. 11 1
      dcuc-auth-api/src/main/java/com/dragoninfo/dcuc/auth/auth/facade/IServiceAuthFlowFacade.java
  4. 2 2
      dcuc-auth-api/src/main/java/com/dragoninfo/dcuc/auth/auth/facade/IServiceAuthResultFacade.java
  5. 1 1
      dcuc-auth-model/pom.xml
  6. 6 3
      dcuc-auth-model/src/main/java/com/dragoninfo/dcuc/auth/auth/dto/ServiceAuthResultDTO.java
  7. 7 1
      dcuc-auth-model/src/main/java/com/dragoninfo/dcuc/auth/auth/entity/ServiceAuthResult.java
  8. 65 0
      dcuc-auth-model/src/main/java/com/dragoninfo/dcuc/auth/auth/enumresources/ApproveResultEnum.java
  9. 51 0
      dcuc-auth-model/src/main/java/com/dragoninfo/dcuc/auth/auth/enumresources/ServiceAuthStatusEnum.java
  10. 36 0
      dcuc-auth-model/src/main/java/com/dragoninfo/dcuc/auth/auth/enumresources/WorkFlowApplyTypeEnum.java
  11. 31 6
      dcuc-auth-model/src/main/java/com/dragoninfo/dcuc/auth/auth/enumresources/WorkFlowStatusEnum.java
  12. 5 0
      dcuc-auth-model/src/main/java/com/dragoninfo/dcuc/auth/auth/po/ServiceAuthResultPO.java
  13. 20 0
      dcuc-auth-model/src/main/java/com/dragoninfo/dcuc/auth/auth/vo/bim/BimGetAppTokenItemRespVO.java
  14. 20 0
      dcuc-auth-model/src/main/java/com/dragoninfo/dcuc/auth/auth/vo/bim/BimGetAppTokenReqVO.java
  15. 23 0
      dcuc-auth-model/src/main/java/com/dragoninfo/dcuc/auth/auth/vo/bim/BimGetAppTokenRespVO.java
  16. 34 0
      dcuc-auth-model/src/main/java/com/dragoninfo/dcuc/auth/auth/vo/bim/BimGetUserTokenItemRespVO.java
  17. 39 0
      dcuc-auth-model/src/main/java/com/dragoninfo/dcuc/auth/auth/vo/bim/BimGetUserTokenReqVO.java
  18. 23 0
      dcuc-auth-model/src/main/java/com/dragoninfo/dcuc/auth/auth/vo/bim/BimGetUserTokenRespVO.java
  19. 1 1
      dcuc-auth-service/pom.xml
  20. 12 2
      dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/AuthRedisConstant.java
  21. 0 2
      dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/auth/async/subscribe/PermissionServiceUpdateMessage.java
  22. 16 6
      dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/auth/bpo/ServiceAuthResultBPO.java
  23. 11 0
      dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/auth/business/IServiceAuthBusiness.java
  24. 31 5
      dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/auth/business/impl/ServiceAuthBusinessImpl.java
  25. 10 0
      dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/auth/facade/BimBusinessFacade.java
  26. 116 0
      dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/auth/facade/ServiceAuthFlowFacade.java
  27. 3 3
      dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/auth/facade/ServiceAuthResultFacade.java
  28. 19 0
      dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/auth/service/IAuthFlowService.java
  29. 16 6
      dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/auth/service/IServiceAuthResultService.java
  30. 31 0
      dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/auth/service/impl/AuthFlowServiceImpl.java
  31. 180 174
      dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/auth/service/impl/ServiceAuthResultServiceImpl.java
  32. 17 0
      dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/business/IBimBusiness.java
  33. 119 0
      dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/business/impl/BimBusinessImpl.java
  34. 11 2
      dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/config/DcucAuthConfig.java
  35. 9 3
      dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/msg/WorkFlowResultListener.java
  36. 4 0
      dcuc-auth-service/src/main/resources/config/mysql/V4_3_0006__Add_AuthResult.sql
  37. 5 0
      dcuc-auth-service/src/main/resources/config/sql/V4_3_0007__Add_AuthResult.sql
  38. 1 1
      pom.xml

+ 1 - 1
dcuc-auth-api/pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>dcuc-auth</artifactId>
         <groupId>com.dragoninfo</groupId>
-        <version>2.2.0-tjdsj-SNAPSHOT</version>
+        <version>2.1.1-tjdsj-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 

+ 17 - 0
dcuc-auth-api/src/main/java/com/dragoninfo/dcuc/auth/auth/facade/IBimBusinessFacade.java

@@ -51,4 +51,21 @@ public interface IBimBusinessFacade {
     @GetMapping("getUserInfoByUserToken")
     BimUserInfoItemRespVO getUserInfoByUserToken(@RequestParam("userToken") String userToken);
 
+    /**
+     * 获取用户令牌
+     *
+     * @param needReGet 需要重新获取
+     * @return 用户令牌
+     */
+    @GetMapping("getUserToken")
+    String getUserToken(@RequestParam("needReGet") boolean needReGet);
+
+    /**
+     * 获取应用令牌
+     *
+     * @param needReGet 需要重新获取
+     * @return 应用令牌
+     */
+    @GetMapping("getAppToken")
+    String getAppToken(@RequestParam("userToken") String userToken, @RequestParam("needReGet") boolean needReGet);
 }

+ 11 - 1
dcuc-auth-api/src/main/java/com/dragoninfo/dcuc/auth/auth/facade/IServiceAuthFacade.java → dcuc-auth-api/src/main/java/com/dragoninfo/dcuc/auth/auth/facade/IServiceAuthFlowFacade.java

@@ -8,6 +8,7 @@ import com.dragonsoft.duceap.base.entity.http.ResponseDTO;
 import com.dragonsoft.duceap.base.entity.search.SearchDTO;
 import org.springframework.cloud.openfeign.FeignClient;
 import org.springframework.data.domain.Page;
+import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestParam;
@@ -21,7 +22,7 @@ import java.util.Map;
  * @create 2020-11-25 14:21
  */
 @FeignClient(name = "dcuc-auth", path = "/dcuc/auth/serviceAuthFacade")
-public interface IServiceAuthFacade {
+public interface IServiceAuthFlowFacade {
 
     /**
      * 服务授权查询
@@ -68,4 +69,13 @@ public interface IServiceAuthFacade {
     @PostMapping(value = "checkApplicantId")
     boolean checkApplicantId(@RequestParam("applicantId")String applicantId);
 
+    /**
+     * 服务授权申请查询是否有重复的授权申请
+     * @param appCode
+     * @param serviceCodes
+     * @return 存在申请中的重复授权单 返回响应状态'300' 内容为重复的服务code集合
+     *         存在申请中的重复授权单 返回响应状态'200'
+     */
+    @GetMapping("authRepeatCheck")
+    ResponseDTO authFlowRepeatCheck(@RequestParam("appCode") String appCode, @RequestParam("serviceCodes") List<String> serviceCodes);
 }

+ 2 - 2
dcuc-auth-api/src/main/java/com/dragoninfo/dcuc/auth/auth/facade/IServiceAuthResultFacade.java

@@ -26,11 +26,11 @@ public interface IServiceAuthResultFacade {
     ResponseDTO saveServiceAuthResult(@RequestBody ServiceAuthResultDTO dto);
     /**
      * 删除
-     * @param id
+     * @param serviceAuthResultDTO
      * @return ResponseDTO
      */
     @PostMapping(value = "delServiceAuthResult")
-    ResponseDTO delServiceAuthResult(@RequestParam("id") String id);
+    ResponseDTO delServiceAuthResult(@RequestBody ServiceAuthResultDTO serviceAuthResultDTO);
     /**
      * 修改
      * @param dto

+ 1 - 1
dcuc-auth-model/pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>dcuc-auth</artifactId>
         <groupId>com.dragoninfo</groupId>
-        <version>2.2.0-tjdsj-SNAPSHOT</version>
+        <version>2.1.1-tjdsj-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 

+ 6 - 3
dcuc-auth-model/src/main/java/com/dragoninfo/dcuc/auth/auth/dto/ServiceAuthResultDTO.java

@@ -83,9 +83,7 @@ public class ServiceAuthResultDTO implements Serializable {
     private String serviceStatus;
 
     /**
-     * 授权状态-取决于应用和服务共同作用的状态
-     * 暂时不维护这个字段
-     * 不要使用
+     * 服务授权状态
      */
     private String authStatus;
 
@@ -159,4 +157,9 @@ public class ServiceAuthResultDTO implements Serializable {
      * 授权审批通过时间
      */
     private Date authTime;
+
+    /**
+     * 理由
+     */
+    private String reason;
 }

+ 7 - 1
dcuc-auth-model/src/main/java/com/dragoninfo/dcuc/auth/auth/entity/ServiceAuthResult.java

@@ -84,7 +84,7 @@ public class ServiceAuthResult implements IdEntity<String> {
     private Date endTime;
 
     /**
-     * 授权结果状态
+     * 授权结果状态 0:未到启用时间,1.正常 2.回收
      */
     @Column(name = "AUTH_STATUS")
     private String authStatus;
@@ -100,4 +100,10 @@ public class ServiceAuthResult implements IdEntity<String> {
      */
     @Column(name = "DELETE_TIME")
     private Date deleteTime;
+
+    /**
+     * 理由
+     */
+    @Column(name = "REASON")
+    private String reason;
 }

+ 65 - 0
dcuc-auth-model/src/main/java/com/dragoninfo/dcuc/auth/auth/enumresources/ApproveResultEnum.java

@@ -0,0 +1,65 @@
+package com.dragoninfo.dcuc.auth.auth.enumresources;
+
+/**
+ * 审批服务处理结果枚举类
+ * @author mazq
+ * @date 2021/5/13
+ */
+public enum  ApproveResultEnum {
+    /**
+     * 完成(同意)
+     */
+    COMPLETE_AGREE("complete-agree", "完成(同意)"),
+
+    /**
+     * 完成(不同意)
+     */
+    COMPLETE_DISAGREE("complete-disagree", "完成(不同意)"),
+
+    /**
+     * 退回
+     */
+    BACK("back", "退回"),
+
+    /**
+     * 撤回
+     */
+    RECALL("recall", "撤回");
+
+    private String label;
+    private String value;
+
+    public static ApproveResultEnum getByValue(String value){
+        for (ApproveResultEnum approveResultEnum : ApproveResultEnum.values()) {
+            if(approveResultEnum.getValue().equals(value)){
+                return approveResultEnum;
+            }
+        }
+        return null;
+    }
+
+
+    ApproveResultEnum(String value, String label) {
+        this.value = value;
+        this.label = label;
+    }
+
+    public String getLabel() {
+        return label;
+    }
+
+    public void setLabel(String label) {
+        this.label = label;
+    }
+
+    public String getValue() {
+        return value;
+    }
+
+    public void setValue(String value) {
+        this.value = value;
+    }
+
+
+
+}

+ 51 - 0
dcuc-auth-model/src/main/java/com/dragoninfo/dcuc/auth/auth/enumresources/ServiceAuthStatusEnum.java

@@ -0,0 +1,51 @@
+package com.dragoninfo.dcuc.auth.auth.enumresources;
+
+/**
+ * 服务授权结果状态枚举类
+ * @author mazq
+ * @date 2021/5/12
+ */
+public enum  ServiceAuthStatusEnum {
+
+    /**
+     * 服务授权申请审批通过后权限有效期时间未到启用时间
+     */
+    NOT_START("未到启动时间","0"),
+    /**
+     * 正常启用状态
+     */
+    START("正常","1"),
+    /**
+     * 授权被回收
+     */
+    CANCEL("回收","2"),
+    /**
+     * 权限超过有效期
+     */
+    OVER_DUE("过期","3");
+
+    private String label;
+
+    private String value;
+
+    ServiceAuthStatusEnum(String label, String value) {
+        this.label = label;
+        this.value = value;
+    }
+
+    public String getLable() {
+        return label;
+    }
+
+    public void setLable(String lable) {
+        this.label = lable;
+    }
+
+    public String getValue() {
+        return value;
+    }
+
+    public void setValue(String value) {
+        this.value = value;
+    }
+}

+ 36 - 0
dcuc-auth-model/src/main/java/com/dragoninfo/dcuc/auth/auth/enumresources/WorkFlowApplyTypeEnum.java

@@ -0,0 +1,36 @@
+package com.dragoninfo.dcuc.auth.auth.enumresources;
+
+/**
+ * @Author yica
+ * @Date 2021/5/13 16:05
+ **/
+public enum WorkFlowApplyTypeEnum {
+
+    AUTHORIZE("1", "授权"),
+    REMOVE_AUTHORIZE("2", "销权");
+
+
+    private String value;
+    private String label;
+
+    WorkFlowApplyTypeEnum(String value, String label) {
+        this.value = value;
+        this.label = label;
+    }
+
+    public String getValue() {
+        return value;
+    }
+
+    public void setValue(String value) {
+        this.value = value;
+    }
+
+    public String getLabel() {
+        return label;
+    }
+
+    public void setLabel(String label) {
+        this.label = label;
+    }
+}

+ 31 - 6
dcuc-auth-model/src/main/java/com/dragoninfo/dcuc/auth/auth/enumresources/WorkFlowStatusEnum.java

@@ -10,22 +10,31 @@ public enum WorkFlowStatusEnum {
      * 申请中
      */
     APPLYING("0", "申请中"),
+
     /**
      * 待审批
      */
     TO_BE_APPROVED("1", "待审批"),
+
     /**
-     * 撤销中
+     * 驳回(流程未走完)
      */
-    CANCLEING("2", "撤销中"),
+    ROLL_BACK("2", "驳回"),
+
     /**
-     * 撤销
+     * 撤销
      */
-    CANCLED("3", "已撤销"),
+    CANCEL("3", "撤销"),
+
     /**
-     * 审批完成
+     * 同意
      */
-    SUCCESS("4", "审批完成");
+    SUCCESS("4", "同意"),
+
+    /**
+     * 不同意(流程走完)
+     */
+    FAIL("5","不同意");
 
     private String label;
     private String value;
@@ -50,4 +59,20 @@ public enum WorkFlowStatusEnum {
     public void setValue(String value) {
         this.value = value;
     }
+
+    public static WorkFlowStatusEnum getStatusByApproveResult(String result) {
+        ApproveResultEnum approveResultEnum = ApproveResultEnum.getByValue(result);
+        switch (approveResultEnum){
+            case BACK:
+                return WorkFlowStatusEnum.ROLL_BACK;
+            case RECALL:
+                return WorkFlowStatusEnum.CANCEL;
+            case COMPLETE_AGREE:
+                return WorkFlowStatusEnum.SUCCESS;
+            case COMPLETE_DISAGREE:
+                return WorkFlowStatusEnum.FAIL;
+            default:
+                return null;
+        }
+    }
 }

+ 5 - 0
dcuc-auth-model/src/main/java/com/dragoninfo/dcuc/auth/auth/po/ServiceAuthResultPO.java

@@ -151,4 +151,9 @@ public class ServiceAuthResultPO {
      */
     private String applicantOrgCode;
 
+    /**
+     * 服务授权状态
+     */
+    private String authStatus;
+
 }

+ 20 - 0
dcuc-auth-model/src/main/java/com/dragoninfo/dcuc/auth/auth/vo/bim/BimGetAppTokenItemRespVO.java

@@ -0,0 +1,20 @@
+package com.dragoninfo.dcuc.auth.auth.vo.bim;
+
+import lombok.Data;
+
+/**
+ * @author huangzqa
+ * @date 2021/4/9
+ **/
+@Data
+public class BimGetAppTokenItemRespVO {
+
+    private String messageId;
+
+    private Boolean result;
+
+    private String message;
+
+    private String appToken;
+
+}

+ 20 - 0
dcuc-auth-model/src/main/java/com/dragoninfo/dcuc/auth/auth/vo/bim/BimGetAppTokenReqVO.java

@@ -0,0 +1,20 @@
+package com.dragoninfo.dcuc.auth.auth.vo.bim;
+
+import lombok.Data;
+
+/**
+ * @author huangzqa
+ * @date 2021/4/9
+ **/
+@Data
+public class BimGetAppTokenReqVO {
+
+    private String token;
+
+    private String messageId;
+
+    private String appId;
+
+    private String userToken;
+
+}

+ 23 - 0
dcuc-auth-model/src/main/java/com/dragoninfo/dcuc/auth/auth/vo/bim/BimGetAppTokenRespVO.java

@@ -0,0 +1,23 @@
+package com.dragoninfo.dcuc.auth.auth.vo.bim;
+
+import lombok.Data;
+
+/**
+ * @author huangzqa
+ * @date 2021/4/9
+ **/
+@Data
+public class BimGetAppTokenRespVO {
+
+    private Boolean success;
+
+    private BimGetAppTokenItemRespVO data;
+
+    private String errorCode;
+
+    private String errorMessage;
+
+    private BimRespException errorException;
+
+
+}

+ 34 - 0
dcuc-auth-model/src/main/java/com/dragoninfo/dcuc/auth/auth/vo/bim/BimGetUserTokenItemRespVO.java

@@ -0,0 +1,34 @@
+package com.dragoninfo.dcuc.auth.auth.vo.bim;
+
+import lombok.Data;
+
+/**
+ * 获取用户令牌返回
+ *
+ * @author huangzqa
+ * @date 2021/4/9
+ **/
+@Data
+public class BimGetUserTokenItemRespVO {
+
+    /**
+     * 消息ID
+     */
+    private String messageId;
+
+    /**
+     * 状态
+     */
+    private Boolean result;
+
+    /**
+     * 信息
+     */
+    private String message;
+
+    /**
+     * 用户令牌
+     */
+    private String userToken;
+
+}

+ 39 - 0
dcuc-auth-model/src/main/java/com/dragoninfo/dcuc/auth/auth/vo/bim/BimGetUserTokenReqVO.java

@@ -0,0 +1,39 @@
+package com.dragoninfo.dcuc.auth.auth.vo.bim;
+
+import lombok.Data;
+
+/**
+ * 请求创建用户令牌
+ *
+ * @author huangzqa
+ * @date 2021/4/9
+ **/
+@Data
+public class BimGetUserTokenReqVO {
+
+    /**
+     * 接口验证token
+     */
+    private String token;
+
+    /**
+     * 消息ID
+     */
+    private String messageId;
+
+    /**
+     * 用户名
+     */
+    private String username;
+
+    /**
+     * 密码
+     */
+    private String password;
+
+    /**
+     * 客户端IP
+     */
+    private String clientIp;
+
+}

+ 23 - 0
dcuc-auth-model/src/main/java/com/dragoninfo/dcuc/auth/auth/vo/bim/BimGetUserTokenRespVO.java

@@ -0,0 +1,23 @@
+package com.dragoninfo.dcuc.auth.auth.vo.bim;
+
+import lombok.Data;
+
+/**
+ * @author huangzqa
+ * @date 2021/4/9
+ **/
+@Data
+public class BimGetUserTokenRespVO {
+
+    private Boolean success;
+
+    private BimGetUserTokenItemRespVO data;
+
+    private String errorCode;
+
+    private String errorMessage;
+
+    private BimRespException errorException;
+
+
+}

+ 1 - 1
dcuc-auth-service/pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>dcuc-auth</artifactId>
         <groupId>com.dragoninfo</groupId>
-        <version>2.2.0-tjdsj-SNAPSHOT</version>
+        <version>2.1.1-tjdsj-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
     <artifactId>dcuc-auth-service</artifactId>

+ 12 - 2
dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/AuthRedisConstant.java

@@ -13,7 +13,7 @@ public class AuthRedisConstant {
     /**
      * 令牌命名空间
      */
-    public static final String REDIS_TOKEN_NAMESPACE = "DCUC-USER:";
+    public static final String REDIS_TOKEN_NAMESPACE = "DCUC-AUTH:";
     /**
      * 用户令牌命名空间
      */
@@ -22,5 +22,15 @@ public class AuthRedisConstant {
     /**
      * BIM token命名空间
      */
-    public static final String REDIS_BIM_TOKEN_NAMESPACE = REDIS_TOKEN_NAMESPACE + "TOKEN:";
+    public static final String REDIS_BIM_TOKEN_NAMESPACE = REDIS_TOKEN_NAMESPACE + "TOKEN";
+
+    /**
+     * BIM USER_TOKEN命名空间
+     */
+    public static final String REDIS_BIM_USER_TOKEN_NAMESPACE = REDIS_TOKEN_NAMESPACE + "TASK_USER_TOKEN";
+
+    /**
+     * BIM APP_TOKEN命名空间
+     */
+    public static final String REDIS_BIM_APP_TOKEN_NAMESPACE = REDIS_TOKEN_NAMESPACE + "TASK_APP_TOKEN";
 }

+ 0 - 2
dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/auth/async/subscribe/PermissionServiceUpdateMessage.java

@@ -7,7 +7,6 @@ import com.dragoninfo.dcuc.auth.auth.entity.ServiceAuthResult;
 import com.dragoninfo.dcuc.auth.auth.service.IServiceAuthResultService;
 import com.dragoninfo.dcuc.auth.auth.vo.ServiceAuthenticationResVO;
 import com.dragoninfo.dcuc.auth.config.DcucAuthConfig;
-import com.dragoninfo.dcuc.auth.util.DcucConstantsUtil;
 import com.dragonsoft.duceap.commons.util.UUIDUtils;
 import com.dragonsoft.duceap.commons.util.json.JsonUtils;
 import com.dragonsoft.duceap.commons.util.string.StringUtils;
@@ -68,7 +67,6 @@ public class PermissionServiceUpdateMessage {
                     vo.setServiceCode(item.getServiceCode());
                     serviceAuthenticationResVOS.add(vo);
                 });
-                serviceAuthResultService.setAuthtionResultToRedis(appServiceCodeDto.getAppCode(), serviceAuthenticationResVOS);
             }
         }
     }

+ 16 - 6
dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/auth/bpo/ServiceAuthResultBPO.java

@@ -56,7 +56,7 @@ public class ServiceAuthResultBPO extends BaseBPO<ServiceAuthResult,String> {
     public List<ServiceAuthResult> serviceAuthResultList(String appCode){
         String sql=" SELECT t.* FROM T_SERVICE_AUTH_RESULT t, T_SERVICE_RESOURCE r \n" +
                 " where t.service_id=r.id and t.deleted='0' and r.deleted='0'\n" +
-                " and r.service_status='1' and app_code=? \n";
+                " and r.service_status='1' and auth_status ='1' and app_code=? \n";
         return PersistentFactory.getJdbcDao().queryForList(sql,ServiceAuthResult.class,new Object[]{appCode});
     }
 
@@ -67,16 +67,16 @@ public class ServiceAuthResultBPO extends BaseBPO<ServiceAuthResult,String> {
     }
 
     public Page<ServiceAuthResultPO> serviceResultPageJoinFlow(Searchable searchable) {
-        String sql = "SELECT t.app_code, t.service_code, t.create_time as auth_time,t.deleted as deleted," +
+        String sql = "SELECT t.app_code, t.service_code, t.auth_status, t.create_time as auth_time, t.deleted as deleted," +
                      "a.apply_name as app_name, a.apply_status as app_status, a.org_name as app_org_name, a.manager_org_name as app_manager_org_name," +
                      "f.applicant_name, f.applicant_org_code, f.create_time as apply_time, f.applicant_org_name, f.applicant_idcard, f.applicant_phone_no," +
                      "f.app_org_code as app_org_code, f.app_manager_org_code as app_manager_org_code," +
                      "s.service_name, s.service_status, s.build_unit as service_org_name, s.manager_unit as service_manager_org_name, " +
                      "s.manager_unit_code as service_manager_org_code, s.build_unit_code as service_org_code," +
-                     "t.app_code as appCode, t.service_code as serviceCode, a.apply_name as appName," +
-                     "a.org_name as appOrgName, f.applicant_name as applicantName, s.service_name as serviceName, s.manager_unit as serviceManagerOrgName," +
-                     "f.app_org_code as appOrgCode, a.apply_status as appStatus, a.manager_org_name as appManagerOrgName, s.service_status as serviceStatus, a.deleted as app_deleted, " +
-                     "s.manager_unit_code as serviceManagerOrgCode, s.deleted as service_deleted" +
+                     "t.app_code as appCode, t.service_code as serviceCode," +
+                     "a.org_name as appOrgName, a.apply_status as appStatus, a.manager_org_name as appManagerOrgName, a.apply_name as appName, a.deleted as app_deleted," +
+                     "f.app_org_code as appOrgCode, f.applicant_name as applicantName," +
+                     "s.service_status as serviceStatus, s.service_name as serviceName, s.manager_unit as serviceManagerOrgName, s.manager_unit_code as serviceManagerOrgCode, s.deleted as service_deleted" +
                      " FROM T_SERVICE_AUTH_RESULT t" +
                      " INNER JOIN T_SERVICE_RESOURCE s ON t.service_id = s.id" +
                      " INNER JOIN T_APPLY_INFO a ON t.app_id = a.id" +
@@ -84,4 +84,14 @@ public class ServiceAuthResultBPO extends BaseBPO<ServiceAuthResult,String> {
         Page<ServiceAuthResultPO> paging = PersistentFactory.getJdbcDao().paging(sql, searchable,ServiceAuthResultPO.class);
         return paging;
     }
+
+    /**
+     * 删除结果 根据条件
+     * @param appCode 应用code
+     * @param serviceCode 服务code
+     */
+    public void delByAppCodeAndServiceId(String appCode,String serviceCode){
+        String sql= "update t_service_auth_result set deleted='1' where service_code= ? and app_code= ?";
+        PersistentFactory.getJdbcDao().update(sql,new Object[]{serviceCode,appCode});
+    }
 }

+ 11 - 0
dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/auth/business/IServiceAuthBusiness.java

@@ -4,6 +4,8 @@ import com.dragoninfo.dcuc.auth.auth.dto.ServiceAuthFlowDTO;
 import com.dragoninfo.dcuc.auth.auth.dto.WorkFlowResutlAcceptDTO;
 import com.dragonsoft.duceap.base.entity.http.ResponseDTO;
 
+import java.util.List;
+
 /**
  * 工作流处理business层
  * @author mazq
@@ -24,4 +26,13 @@ public interface IServiceAuthBusiness {
      * @return
      */
     ResponseDTO serviceAuthFlowSave(ServiceAuthFlowDTO dto);
+
+    /**
+     * 服务授权申请查询是否有重复的授权申请
+     * @param appCode
+     * @param serviceCodes
+     * @return 存在申请中的重复授权单 返回响应状态'300' 内容为重复的服务code集合
+     *         存在申请中的重复授权单 返回响应状态'200'
+     */
+    ResponseDTO authFlowRepeatCheck(String appCode, List<String> serviceCodes);
 }

+ 31 - 5
dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/auth/business/impl/ServiceAuthBusinessImpl.java

@@ -12,6 +12,8 @@ import com.dragoninfo.dcuc.auth.auth.dto.ServiceAuthFlowDTO;
 import com.dragoninfo.dcuc.auth.auth.dto.WorkFlowDTO;
 import com.dragoninfo.dcuc.auth.auth.dto.WorkFlowResutlAcceptDTO;
 import com.dragoninfo.dcuc.auth.auth.entity.ServiceAuthFlow;
+import com.dragoninfo.dcuc.auth.auth.entity.ServiceAuthResult;
+import com.dragoninfo.dcuc.auth.auth.enumresources.ServiceAuthStatusEnum;
 import com.dragoninfo.dcuc.auth.auth.enumresources.WokrFlowPermissionTypeEnum;
 import com.dragoninfo.dcuc.auth.auth.enumresources.WorkFlowStatusEnum;
 import com.dragoninfo.dcuc.auth.auth.service.IAuthFlowService;
@@ -24,7 +26,11 @@ import com.dragoninfo.dcuc.org.entity.OrgInfo;
 import com.dragoninfo.dcuc.org.facade.IOrgInfoFacade;
 import com.dragonsoft.duceap.base.entity.http.ResponseDTO;
 import com.dragonsoft.duceap.base.entity.http.ResponseStatus;
+import com.dragonsoft.duceap.base.enums.BooleanEnum;
 import com.dragonsoft.duceap.commons.util.UUIDUtils;
+import com.dragonsoft.duceap.commons.util.collections.CollectionUtils;
+import com.dragonsoft.duceap.core.search.Searchable;
+import com.dragonsoft.duceap.core.search.enums.SearchOperator;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.http.Header;
 import org.apache.http.message.BasicHeader;
@@ -75,12 +81,14 @@ public class ServiceAuthBusinessImpl implements IServiceAuthBusiness {
             logger.info("dealAuthFlowResult>>get work flow null,message id:{}",messageId);
             return false;
         }
-        if (WorkFlowStatusEnum.SUCCESS.getValue().equals(flow.getFlowStatus())) {
+        //幂等性
+        if (!WorkFlowStatusEnum.APPLYING.getValue().equals(flow.getFlowStatus())) {
             return true;
         }
         flow.setRemark(dto.getRemark());
         flow.setFlowStatus(dto.getApproveResult());
         flow.setFlowId(flowId);
+        //处理服务授权结果
         authResultService.dealAuthFlowResult(flow);
         //更新工作单状态
         authFlowService.update(flow);
@@ -108,6 +116,11 @@ public class ServiceAuthBusinessImpl implements IServiceAuthBusiness {
                 return ResponseDTO.fail(ResponseStatus.FAIL_CODE ,String.format("服务代码 %s 不存在", serviceCode),null);
             }
         }
+        //校验服务授权是否存在重复申请
+        ResponseDTO checkRepeat = authFlowRepeatCheck(dto.getAppCode(), Arrays.asList(serviceCodArray));
+        if(!ResponseStatus.SUCCESS_CODE.equals(checkRepeat.getStatusCode())){
+            return checkRepeat;
+        }
         String flowStatus = WorkFlowStatusEnum.APPLYING.getValue();
         //生成消息id
         dto.setMessageId(UUIDUtils.getUUID());
@@ -117,8 +130,7 @@ public class ServiceAuthBusinessImpl implements IServiceAuthBusiness {
         String orgId = applyInfo.getOrgId();
         String managerOrgId = applyInfo.getManagerOrgId();
         List<OrgInfo> orgsByIds = orgInfoFacade.getOrgsByIds(String.join(StrUtil.COMMA, orgId, managerOrgId));
-        Map<String, OrgInfo> orgInfoMap = orgsByIds
-                .stream()
+        Map<String, OrgInfo> orgInfoMap = orgsByIds.stream()
                 .collect(Collectors.toMap(OrgInfo::getId, item -> item, (old, laset) -> laset));
         OrgInfo orgInfo = orgInfoMap.get(orgId);
         OrgInfo managerOrgInfo = orgInfoMap.get(managerOrgId);
@@ -131,7 +143,7 @@ public class ServiceAuthBusinessImpl implements IServiceAuthBusiness {
             dto.setAppManagerOrgCode(managerOrgInfo.getCode());
         }
         //保存
-        authFlowService.serviceAuthFlowSave(dto);
+        ServiceAuthFlow serviceAuthFlow = authFlowService.serviceAuthFlowSave(dto);
 
         //将工作单推送给审批服务
         ResponseDTO responseDTO = null;
@@ -140,6 +152,8 @@ public class ServiceAuthBusinessImpl implements IServiceAuthBusiness {
             responseDTO = pushWorkFlowToServer(dto);
             logger.info("-------pushWorkFlowToServer END---------------");
             if(!ResponseStatus.SUCCESS_CODE.equals(responseDTO.getStatusCode())){
+                //删除工单
+                authFlowService.delById(serviceAuthFlow.getId());
                 return new ResponseDTO(ResponseStatus.FAIL_CODE,"approve service faild :"+responseDTO.getMessage(),null);
             }
         } catch (Exception e) {
@@ -149,6 +163,19 @@ public class ServiceAuthBusinessImpl implements IServiceAuthBusiness {
         return responseDTO;
     }
 
+    @Override
+    public ResponseDTO authFlowRepeatCheck(String appCode, List<String> serviceCodes) {
+        List<String> list = authFlowService.authFlowApplyRepeatCheck(appCode, serviceCodes);
+        if(!CollectionUtils.isEmpty(list)) {
+            return ResponseDTO.fail(ResponseStatus.FAIL_CODE, String.format("服务授权申请中,申请中的服务代码:%s ", list), list);
+        }
+        List<String> exist = authResultService.authResultRepeatCheck(appCode, serviceCodes);
+        if(!CollectionUtils.isEmpty(exist)) {
+            return ResponseDTO.fail(ResponseStatus.FAIL_CODE, String.format("您已经提交过此申请,并通过审批,可正常使用该服务。已开通的服务代码:%s ", exist), exist);
+        }
+        return ResponseDTO.success(ResponseStatus.SUCCESS_CODE,null);
+    }
+
     /**
      * 将服务授权工作单推送给审批服务
      *
@@ -207,7 +234,6 @@ public class ServiceAuthBusinessImpl implements IServiceAuthBusiness {
         logger.info("work flow push result:{}", response);
         ResponseDTO responseDTO = JSON.parseObject(response, ResponseDTO.class);
         return responseDTO;
-
     }
 
 }

+ 10 - 0
dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/auth/facade/BimBusinessFacade.java

@@ -36,4 +36,14 @@ public class BimBusinessFacade implements IBimBusinessFacade {
     public BimUserInfoItemRespVO getUserInfoByUserToken(String userToken) {
         return bimBusiness.getUserInfoByUserToken(userToken);
     }
+
+    @Override
+    public String getUserToken(boolean needReGet) {
+        return bimBusiness.getUserToken(needReGet);
+    }
+
+    @Override
+    public String getAppToken(String userToken, boolean needReGet) {
+        return bimBusiness.getAppToken(userToken, needReGet);
+    }
 }

+ 116 - 0
dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/auth/facade/ServiceAuthFlowFacade.java

@@ -0,0 +1,116 @@
+package com.dragoninfo.dcuc.auth.auth.facade;
+
+import com.dragoninfo.dcuc.auth.auth.async.PermssionServiceUpdateEventBus;
+import com.dragoninfo.dcuc.auth.auth.business.IServiceAuthBusiness;
+import com.dragoninfo.dcuc.auth.auth.dto.AppServiceCodeDto;
+import com.dragoninfo.dcuc.auth.auth.dto.ServiceAuthFlowDTO;
+import com.dragoninfo.dcuc.auth.auth.dto.WorkFlowResutlAcceptDTO;
+import com.dragoninfo.dcuc.auth.auth.entity.ServiceAuthResult;
+import com.dragoninfo.dcuc.auth.auth.service.IAuthFlowService;
+import com.dragoninfo.dcuc.auth.auth.service.IServiceAuthResultService;
+import com.dragonsoft.duceap.base.entity.http.ResponseDTO;
+import com.dragonsoft.duceap.base.entity.http.ResponseStatus;
+import com.dragonsoft.duceap.base.entity.search.SearchDTO;
+import com.dragonsoft.duceap.commons.util.collections.CollectionUtils;
+import com.dragonsoft.duceap.core.search.Searchable;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Page;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+
+/**
+ * 服务授权工单service
+ * @author mazq
+ */
+@RestController
+@RequestMapping(value = "/dcuc/auth/serviceAuthFacade")
+public class ServiceAuthFlowFacade implements IServiceAuthFlowFacade {
+
+    @Autowired
+    private IAuthFlowService authFlowService;
+
+    @Autowired
+    private IServiceAuthResultService authResultService;
+
+    @Autowired
+    private IServiceAuthBusiness serviceAuthBusiness;
+    @Autowired
+    private PermssionServiceUpdateEventBus permssionServiceUpdateEventBus;
+
+
+
+    @Override
+    public ResponseDTO serviceAuthFlowSave(ServiceAuthFlowDTO dto) {
+       return serviceAuthBusiness.serviceAuthFlowSave(dto);
+    }
+
+    @Override
+    public Page<ServiceAuthFlowDTO> serviceAuthFlowPage(SearchDTO searchDTO) {
+        Searchable searchable = Searchable.toSearchable(searchDTO);
+        Page<ServiceAuthFlowDTO> page = authFlowService.page(searchable);
+        return page;
+    }
+
+    @Override
+    public boolean dealAuthFlowResult(WorkFlowResutlAcceptDTO dto) {
+        return serviceAuthBusiness.dealAuthFlowResult(dto);
+    }
+    @Override
+    public List<ServiceAuthResult> getByAppCode(String appCode){
+       return authResultService.getByAppCode(appCode);
+    }
+
+    /**
+     * 服务变更通知(测试接口)
+     * @param map
+     */
+    @Override
+    public void serviceChangeNotice(Map<String,Object> map){
+        Object appCode = map.get("appCode");
+        Object addServiceCodes = map.get("addServiceCodes");
+
+        List<String> resultAdd = new ArrayList<>();
+        if (addServiceCodes instanceof ArrayList<?>) {
+            for (Object o : (List<?>) addServiceCodes) {
+                resultAdd.add(String.class.cast(o));
+            }
+        }
+        Object delServiceCodes = map.get("delServiceCodes");
+        List<String> resultDel = new ArrayList<>();
+        if (addServiceCodes instanceof ArrayList<?>) {
+            for (Object o : (List<?>) delServiceCodes) {
+                resultDel.add(String.class.cast(o));
+            }
+        }
+        //服务变更消息通知
+        AppServiceCodeDto appServiceCodeDto=new AppServiceCodeDto((String) appCode,resultAdd,resultDel);
+        List<AppServiceCodeDto> appServiceCodeDtoList=new ArrayList<>();
+        appServiceCodeDtoList.add(appServiceCodeDto);
+        permssionServiceUpdateEventBus.post(appServiceCodeDtoList);
+        //System.out.println("123123");
+    }
+
+
+    /**
+     * 服务鉴权
+     * @param appCode
+     */
+    @Override
+    public Object serviceAuthentication(String appCode){
+        return authResultService.serviceAuthentication(appCode);
+    }
+
+    @Override
+    public boolean checkApplicantId(String applicantId) {
+        return authFlowService.checkApplicantId(applicantId);
+    }
+
+    @Override
+    public ResponseDTO authFlowRepeatCheck(String appCode, List<String> serviceCodes) {
+       return serviceAuthBusiness.authFlowRepeatCheck(appCode, serviceCodes);
+    }
+}

+ 3 - 3
dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/auth/facade/ServiceAuthResultFacade.java

@@ -39,13 +39,13 @@ public class ServiceAuthResultFacade implements IServiceAuthResultFacade {
 
     /**
      * 删除
-     * @param id
+     * @param serviceAuthResultDTO
      * @return ResponseDTO
      */
     @Override
-    public ResponseDTO delServiceAuthResult(String id){
+    public ResponseDTO delServiceAuthResult(ServiceAuthResultDTO serviceAuthResultDTO){
 
-        return serviceAuthResultService.delServiceAuthResult(id);
+        return serviceAuthResultService.delServiceAuthResult(serviceAuthResultDTO);
     }
 
     /**

+ 19 - 0
dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/auth/service/IAuthFlowService.java

@@ -36,6 +36,11 @@ public interface IAuthFlowService {
      */
     Page<ServiceAuthFlowDTO> page(Searchable searchable);
 
+    /**
+     * 根据查询条件查询
+     */
+    List<ServiceAuthFlow> find(Searchable searchable);
+
     /**
      * 根据工单号查询工单
      * @param messageId 工单号
@@ -64,4 +69,18 @@ public interface IAuthFlowService {
      * @return
      */
     boolean checkApplicantId(String applicantId);
+
+    /**
+     * 服务授权申请查询是否有重复的授权申请
+     * @param appCode
+     * @param serviceCodes
+     * @return
+     */
+    List<String> authFlowApplyRepeatCheck(String appCode, List<String> serviceCodes);
+
+    /**
+     * 根据id删除工单
+     * @param id
+     */
+    void delById(String id);
 }

+ 16 - 6
dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/auth/service/IServiceAuthResultService.java

@@ -4,7 +4,6 @@ package com.dragoninfo.dcuc.auth.auth.service;
 import com.dragoninfo.dcuc.auth.auth.dto.ServiceAuthResultDTO;
 import com.dragoninfo.dcuc.auth.auth.entity.ServiceAuthFlow;
 import com.dragoninfo.dcuc.auth.auth.entity.ServiceAuthResult;
-import com.dragoninfo.dcuc.auth.auth.vo.ServiceAuthenticationResVO;
 import com.dragonsoft.duceap.base.entity.http.ResponseDTO;
 import com.dragonsoft.duceap.core.search.Searchable;
 import org.springframework.data.domain.Page;
@@ -58,6 +57,12 @@ public interface IServiceAuthResultService {
      */
     List<ServiceAuthResult> getByAppCode(String appCode);
 
+    /**
+     * 根据查询条件查询
+     */
+    List<ServiceAuthResult> find(Searchable searchable);
+
+
     /**
      * 服务授权工作单审批结果处理
      *
@@ -83,12 +88,10 @@ public interface IServiceAuthResultService {
 
     /**
      * 删除
-     *
-     * @param id
+     * @param serviceAuthResultDTO
      * @return ResponseDTO
      */
-    ResponseDTO delServiceAuthResult(String id);
-
+    ResponseDTO delServiceAuthResult(ServiceAuthResultDTO serviceAuthResultDTO);
     /**
      * 修改
      *
@@ -116,7 +119,6 @@ public interface IServiceAuthResultService {
      */
     void sendPermssionServiceUpdate(String serviceCode, String type);
 
-    void setAuthtionResultToRedis(String appCode, List<ServiceAuthenticationResVO> serviceCodes);
 
     ServiceAuthResultDTO getDetailByAppAndService(String appCode, String serviceCode);
 
@@ -126,4 +128,12 @@ public interface IServiceAuthResultService {
      * @return
      */
     Page<ServiceAuthResultDTO> serviceResultPageJoinFlow(Searchable toSearchable);
+
+    /**
+     * 服务授权结果重复记录校验
+     * @param appCode
+     * @param serviceCodes
+     * @return
+     */
+    List<String> authResultRepeatCheck(String appCode, List<String> serviceCodes);
 }

+ 31 - 0
dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/auth/service/impl/AuthFlowServiceImpl.java

@@ -2,14 +2,17 @@ package com.dragoninfo.dcuc.auth.auth.service.impl;
 
 
 import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.util.StrUtil;
 import com.dragoninfo.dcuc.auth.auth.bpo.ServiceAuthFlowBPO;
 import com.dragoninfo.dcuc.auth.auth.dto.ServiceAuthFlowDTO;
 import com.dragoninfo.dcuc.auth.auth.entity.ServiceAuthFlow;
+import com.dragoninfo.dcuc.auth.auth.enumresources.WorkFlowStatusEnum;
 import com.dragoninfo.dcuc.auth.auth.enumresources.WorkFlowTypeEnum;
 import com.dragoninfo.dcuc.auth.auth.service.IAuthFlowService;
 import com.dragonsoft.duceap.base.enums.BooleanEnum;
 import com.dragonsoft.duceap.commons.util.collections.CollectionUtils;
 import com.dragonsoft.duceap.commons.util.json.JsonUtils;
+import com.dragonsoft.duceap.commons.util.string.StringUtils;
 import com.dragonsoft.duceap.core.entity.page.PageImpl;
 import com.dragonsoft.duceap.core.entity.page.PageRequest;
 import com.dragonsoft.duceap.core.search.Searchable;
@@ -24,8 +27,10 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Date;
 import java.util.List;
+import java.util.stream.Collectors;
 
 /**
  * @author mazq
@@ -74,6 +79,11 @@ public class AuthFlowServiceImpl implements IAuthFlowService {
         return new PageImpl<>(dtos, newPageable, totalElements);
     }
 
+    @Override
+    public List<ServiceAuthFlow> find(Searchable searchable) {
+        return serviceAuthFlowBPO.find(ServiceAuthFlow.class,searchable);
+    }
+
     @Override
     public ServiceAuthFlow getByMessageId(String messageId) {
         Searchable searchable = Searchable.newSearchable();
@@ -119,4 +129,25 @@ public class AuthFlowServiceImpl implements IAuthFlowService {
         return serviceAuthFlowBPO.checkApplicantId(applicantId);
     }
 
+    @Override
+    public List<String> authFlowApplyRepeatCheck(String appCode, List<String> serviceCodes) {
+        Searchable searchable = Searchable.newSearchable();
+        searchable.addSearchFilter("app_code",SearchOperator.eq,appCode);
+        searchable.addSearchFilter("flow_status",SearchOperator.eq, WorkFlowStatusEnum.APPLYING.getValue());
+        searchable.addSearchFilter("deleted",SearchOperator.eq, WorkFlowStatusEnum.APPLYING.getValue());
+        List<ServiceAuthFlow> existFlows = serviceAuthFlowBPO.find(ServiceAuthFlow.class, searchable);
+        List<String> existServiceCodes = existFlows.stream()
+                .filter(item -> StringUtils.isNotBlank(item.getServiceCodes()))
+                .flatMap(item -> Arrays.stream(item.getServiceCodes().split(StrUtil.COMMA)))
+                .filter(item -> serviceCodes.contains(item))
+                .distinct()
+                .collect(Collectors.toList());
+        return existServiceCodes;
+    }
+
+    @Override
+    public void delById(String id) {
+        serviceAuthFlowBPO.delete(id);
+    }
+
 }

+ 180 - 174
dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/auth/service/impl/ServiceAuthResultServiceImpl.java

@@ -1,7 +1,6 @@
 package com.dragoninfo.dcuc.auth.auth.service.impl;
 
 
-import cn.hutool.core.util.StrUtil;
 import com.dragoninfo.dcuc.app.entity.ApplyInfo;
 import com.dragoninfo.dcuc.app.entity.ServiceResource;
 import com.dragoninfo.dcuc.app.facade.IApplyInfoFacade;
@@ -12,6 +11,7 @@ import com.dragoninfo.dcuc.auth.auth.dto.AppServiceCodeDto;
 import com.dragoninfo.dcuc.auth.auth.dto.ServiceAuthResultDTO;
 import com.dragoninfo.dcuc.auth.auth.entity.ServiceAuthFlow;
 import com.dragoninfo.dcuc.auth.auth.entity.ServiceAuthResult;
+import com.dragoninfo.dcuc.auth.auth.enumresources.ServiceAuthStatusEnum;
 import com.dragoninfo.dcuc.auth.auth.enumresources.WokrFlowPermissionTypeEnum;
 import com.dragoninfo.dcuc.auth.auth.enumresources.WorkFlowStatusEnum;
 import com.dragoninfo.dcuc.auth.auth.enumresources.WorkFlowTypeEnum;
@@ -19,8 +19,6 @@ import com.dragoninfo.dcuc.auth.auth.po.ServiceAuthResultPO;
 import com.dragoninfo.dcuc.auth.auth.service.IAuthFlowService;
 import com.dragoninfo.dcuc.auth.auth.service.IServiceAuthResultService;
 import com.dragoninfo.dcuc.auth.auth.vo.ServiceAuthenticationResVO;
-import com.dragoninfo.dcuc.auth.util.DcucConstantsUtil;
-import com.dragoninfo.dcuc.user.user.facade.IUserInfoFacade;
 import com.dragonsoft.duceap.base.entity.http.ResponseDTO;
 import com.dragonsoft.duceap.base.enums.BooleanEnum;
 import com.dragonsoft.duceap.commons.util.collections.CollectionUtils;
@@ -40,7 +38,6 @@ import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
 import java.util.*;
-import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
 
 /**
@@ -53,7 +50,7 @@ import java.util.stream.Collectors;
 public class ServiceAuthResultServiceImpl implements IServiceAuthResultService {
 
     @Resource(name = "redisTemplate")
-    private RedisTemplate<String, Object> redisTemplate;
+    private RedisTemplate<String, String> redisTemplate;
 
     @Autowired
     private IApplyInfoFacade applyInfoFacade;
@@ -62,7 +59,7 @@ public class ServiceAuthResultServiceImpl implements IServiceAuthResultService {
     private ServiceAuthResultBPO serviceAuthResultBPO;
 
     @Autowired
-    IServiceResourceFacade iServiceResourceFacade;
+    private IServiceResourceFacade iServiceResourceFacade;
 
     @Autowired
     private PermssionServiceUpdateEventBus permssionServiceUpdateEventBus;
@@ -73,9 +70,6 @@ public class ServiceAuthResultServiceImpl implements IServiceAuthResultService {
     @Autowired
     private IAuthFlowService authFlowService;
 
-    @Autowired
-    private IUserInfoFacade userInfoFacade;
-
     @Override
     public ServiceAuthResult saveAuthResult(ServiceAuthResult serviceAuthResult) {
         serviceAuthResult.setCreateTime(new Date());
@@ -87,8 +81,8 @@ public class ServiceAuthResultServiceImpl implements IServiceAuthResultService {
     @Override
     public ServiceAuthResult getByAppServiceCode(String appCode, String serviceCode) {
         Searchable searchable = Searchable.newSearchable();
-        searchable.addSearchFilter("serviceCode", SearchOperator.eq, serviceCode);
-        searchable.addSearchFilter("appCode", SearchOperator.eq, appCode);
+        searchable.addSearchFilter("service_code", SearchOperator.eq, serviceCode);
+        searchable.addSearchFilter("app_code", SearchOperator.eq, appCode);
         searchable.addSearchFilter("deleted", SearchOperator.eq, BooleanEnum.FALSE.getValue());
         List<ServiceAuthResult> authResults = serviceAuthResultBPO.find(ServiceAuthResult.class, searchable);
         if (CollectionUtils.isEmpty(authResults)) {
@@ -138,14 +132,15 @@ public class ServiceAuthResultServiceImpl implements IServiceAuthResultService {
 
         //待处理的服务
         List<ServiceResource> resources = iServiceResourceFacade.getServiceByServiceCodes(list);
-        Map<String, ServiceResource> map = resources
+        Map<String, ServiceResource> serviceResourceMap = resources
                 .stream()
-                .collect(Collectors.toMap(ServiceResource::getServiceCode, item -> item, (old, last) -> last));
+                .collect(Collectors.toMap(ServiceResource::getServiceCode, item -> item,(old,last)->last));
 
         String appCode = serviceAuthFlow.getAppCode();
         String appId = applyInfoFacade.codeConvertToId(appCode);
-        if (StrUtil.isBlank(appId)) {
+        if (StringUtils.isBlank(appId)) {
             log.error("AppCode {} is not exits", appCode);
+            return false;
         }
 
         //新增的服务
@@ -157,76 +152,84 @@ public class ServiceAuthResultServiceImpl implements IServiceAuthResultService {
         List<ServiceAuthResult> allAuthResults = getByAppCode(appCode);
         Map<String, ServiceAuthResult> allAuthResultMap = allAuthResults
                 .stream()
-                .collect(Collectors.toMap(ServiceAuthResult::getServiceCode, item -> item, (old, last) -> last));
-        Date date = new Date();
+                .collect(Collectors.toMap(ServiceAuthResult::getServiceCode, item -> item,(old,last)->last));
         if (WorkFlowTypeEnum.SERVICE_AUTH.getValue().equals(serviceAuthFlow.getFlowType())) {
-            //判断工作单是长期还是自定义
-            Date startTime = null;
-            Date endTime = null;
-            String authStatus = BooleanEnum.TRUE.getValue();
-            String permissionValidType = serviceAuthFlow.getPermissionValidType();
-            if (StringUtils.isNotBlank(permissionValidType)
-                    && WokrFlowPermissionTypeEnum.TEMP.getValue().equals(permissionValidType)) {
-                startTime = serviceAuthFlow.getStartTime();
-                endTime = serviceAuthFlow.getEndTime();
-                if (date.before(startTime) || date.after(endTime)) {
-                    authStatus = BooleanEnum.FALSE.getValue();
-                }
-            }
-            //授权工作单
-            //新增授权
-            for (String serviceCode : map.keySet()) {
-                //已经存在的更新
-                if (allAuthResultMap.containsKey(serviceCode)) {
-                    ServiceAuthResult serviceAuthResult = allAuthResultMap.get(serviceCode);
-                    serviceAuthResult.setStartTime(startTime);
-                    serviceAuthResult.setEndTime(endTime);
-                    serviceAuthResult.setAuthStatus(authStatus);
-                    serviceAuthResult.setUpdateTime(date);
-                    serviceAuthResult.setFlowId(serviceAuthFlow.getFlowId());
-                    serviceAuthResult.setMessageId(serviceAuthFlow.getMessageId());
-                    serviceAuthResultBPO.update(serviceAuthResult);
-                } else {
-                    //不存在的新增
-                    ServiceAuthResult serviceAuthResult = new ServiceAuthResult();
-                    serviceAuthResult.setAppCode(appCode);
-                    serviceAuthResult.setServiceCode(serviceCode);
-                    ServiceResource serviceResource = map.get(serviceCode);
-                    if (serviceResource == null) {
-                        log.error("ServiceCode {} is not exits.", serviceCode);
-                    }
-                    serviceAuthResult.setStartTime(startTime);
-                    serviceAuthResult.setEndTime(endTime);
-                    serviceAuthResult.setAuthStatus(authStatus);
-                    serviceAuthResult.setServiceId(serviceResource.getId());
-                    serviceAuthResult.setAppId(appId);
-                    serviceAuthResult.setFlowId(serviceAuthFlow.getFlowId());
-                    serviceAuthResult.setMessageId(serviceAuthFlow.getMessageId());
-                    saveAuthResult(serviceAuthResult);
-                }
-            }
+            addServiceAuthResult(serviceAuthFlow, serviceResourceMap, appId, allAuthResultMap);
         } else {
             //撤销权限工作单
             //删除权限
-            List<ServiceAuthResult> result = allAuthResults.stream()
-                    .filter(item -> map.containsKey(item.getServiceCode()))
-                    .collect(Collectors.toList());
-            for (ServiceAuthResult serviceAuthResult : result) {
-                serviceAuthResult.setDeleted(BooleanEnum.TRUE.getValue());
-                serviceAuthResult.setDeleteTime(date);
-                serviceAuthFlow.setFlowId(serviceAuthFlow.getFlowId());
-                serviceAuthResultBPO.update(serviceAuthResult);
-            }
-
+            cancelServiceAuthResult(serviceAuthFlow, serviceResourceMap, allAuthResults);
         }
         //使用异步事件发送消息
         sendPermssionService(appCode, addServiceCodes, delServiceCodes);
         return true;
     }
 
+    private void cancelServiceAuthResult(ServiceAuthFlow serviceAuthFlow, Map<String, ServiceResource> serviceResourceMap, List<ServiceAuthResult> allAuthResults) {
+        Date date = new Date();
+        List<ServiceAuthResult> result = allAuthResults.stream()
+                .filter(item -> serviceResourceMap.containsKey(item.getServiceCode()))
+                .collect(Collectors.toList());
+        for (ServiceAuthResult serviceAuthResult : result) {
+            serviceAuthResult.setDeleted(BooleanEnum.TRUE.getValue());
+            serviceAuthResult.setDeleteTime(date);
+            serviceAuthFlow.setFlowId(serviceAuthFlow.getFlowId());
+            serviceAuthResultBPO.update(serviceAuthResult);
+        }
+    }
+
+    private void addServiceAuthResult(ServiceAuthFlow serviceAuthFlow, Map<String, ServiceResource> serviceResourceMap, String appId, Map<String, ServiceAuthResult> allAuthResultMap) {
+        Date date = new Date();
+        String appCode = serviceAuthFlow.getAppCode();
+        //判断工作单是长期还是自定义
+        Date startTime = null;
+        Date endTime = null;
+        String authStatus = ServiceAuthStatusEnum.START.getValue();
+        String permissionValidType = serviceAuthFlow.getPermissionValidType();
+        if (StringUtils.isNotBlank(permissionValidType)
+                && WokrFlowPermissionTypeEnum.TEMP.getValue().equals(permissionValidType)) {
+            startTime = serviceAuthFlow.getStartTime();
+            endTime = serviceAuthFlow.getEndTime();
+            if (date.before(startTime)) {
+                authStatus = ServiceAuthStatusEnum.NOT_START.getValue();
+            }
+            if (date.after(endTime)) {
+                authStatus = ServiceAuthStatusEnum.OVER_DUE.getValue();
+            }
+        }
+        //授权工作单
+        //新增授权
+        for (String serviceCode : serviceResourceMap.keySet()) {
+                //已经存在的更新
+            if (allAuthResultMap.containsKey(serviceCode)) {
+                ServiceAuthResult serviceAuthResult = allAuthResultMap.get(serviceCode);
+                serviceAuthResult.setStartTime(startTime);
+                serviceAuthResult.setEndTime(endTime);
+                serviceAuthResult.setAuthStatus(authStatus);
+                serviceAuthResult.setUpdateTime(date);
+                serviceAuthResult.setFlowId(serviceAuthFlow.getFlowId());
+                serviceAuthResult.setMessageId(serviceAuthFlow.getMessageId());
+                serviceAuthResultBPO.update(serviceAuthResult);
+            } else {
+                //不存在的新增
+                ServiceAuthResult serviceAuthResult = new ServiceAuthResult();
+                serviceAuthResult.setAppCode(appCode);
+                serviceAuthResult.setServiceCode(serviceCode);
+                ServiceResource serviceResource = serviceResourceMap.get(serviceCode);
+                serviceAuthResult.setStartTime(startTime);
+                serviceAuthResult.setEndTime(endTime);
+                serviceAuthResult.setAuthStatus(authStatus);
+                serviceAuthResult.setServiceId(serviceResource.getId());
+                serviceAuthResult.setAppId(appId);
+                serviceAuthResult.setFlowId(serviceAuthFlow.getFlowId());
+                serviceAuthResult.setMessageId(serviceAuthFlow.getMessageId());
+                saveAuthResult(serviceAuthResult);
+            }
+        }
+    }
+
     /**
      * 使用异步事件发送消息
-     *
      * @param appCode
      * @param addServiceCodes
      * @param delServiceCodes
@@ -234,8 +237,8 @@ public class ServiceAuthResultServiceImpl implements IServiceAuthResultService {
     private void sendPermssionService(String appCode, List<String> addServiceCodes, List<String> delServiceCodes) {
         //使用异步事件发送消息
         //服务变更消息通知
-        AppServiceCodeDto appServiceCodeDto = new AppServiceCodeDto(appCode, addServiceCodes, delServiceCodes);
-        List<AppServiceCodeDto> appServiceCodeDtoList = new ArrayList<>();
+        AppServiceCodeDto appServiceCodeDto=new AppServiceCodeDto(appCode,addServiceCodes,delServiceCodes);
+        List<AppServiceCodeDto> appServiceCodeDtoList=new ArrayList<>();
         appServiceCodeDtoList.add(appServiceCodeDto);
         permssionServiceUpdateEventBus.post(appServiceCodeDtoList);
     }
@@ -243,11 +246,16 @@ public class ServiceAuthResultServiceImpl implements IServiceAuthResultService {
     @Override
     public List<ServiceAuthResult> getByAppCode(String appCode) {
         Searchable searchable = Searchable.newSearchable();
-        searchable.addSearchFilter("appCode", SearchOperator.eq, appCode);
+        searchable.addSearchFilter("app_code", SearchOperator.eq, appCode);
         searchable.addSearchFilter("deleted", SearchOperator.eq, BooleanEnum.FALSE.getValue());
         return serviceAuthResultBPO.find(ServiceAuthResult.class, searchable);
     }
 
+    @Override
+    public List<ServiceAuthResult> find(Searchable searchable) {
+        return serviceAuthResultBPO.find(ServiceAuthResult.class, searchable);
+    }
+
     /**
      * 服务鉴权
      *
@@ -255,90 +263,89 @@ public class ServiceAuthResultServiceImpl implements IServiceAuthResultService {
      */
     @Override
     public Object serviceAuthentication(String appCode) {
-        String redisKey = DcucConstantsUtil.AUTHENTICATION_SPACE + appCode;
-        //PermissionUpdateService已存入鉴权结果
-        Object redisValue = redisTemplate.opsForValue().get(redisKey);
-        //当缓存找不到时候去数据库查询
-        if (redisValue == null) {
-            List<ServiceAuthResult> results = serviceAuthResultBPO.serviceAuthResultList(appCode);
-            List<ServiceAuthenticationResVO> list = new ArrayList<>();
-            for (ServiceAuthResult result : results) {
-                ServiceAuthenticationResVO serviceAuthenticationResVO = new ServiceAuthenticationResVO();
-                serviceAuthenticationResVO.setServiceCode(result.getServiceCode());
-                list.add(serviceAuthenticationResVO);
-            }
-            //鉴权结果存到缓存
-            setAuthtionResultToRedis(appCode, list);
-            return list;
-        } else {
-            return redisValue;
+//        String redisKey = DcucConstantsUtil.AUTHENTICATION_SPACE + appCode;
+//        //PermissionUpdateService已存入鉴权结果
+//        Object redisValue = redisTemplate.opsForValue().get(redisKey);
+//        //当缓存找不到时候去数据库查询
+//        if (redisValue == null) {
+        List<ServiceAuthResult> results = serviceAuthResultBPO.serviceAuthResultList(appCode);
+        List<ServiceAuthenticationResVO> list = new ArrayList<>();
+        for (ServiceAuthResult result : results) {
+            ServiceAuthenticationResVO serviceAuthenticationResVO = new ServiceAuthenticationResVO();
+            serviceAuthenticationResVO.setServiceCode(result.getServiceCode());
+            list.add(serviceAuthenticationResVO);
         }
+            //鉴权结果存到缓存
+         //   permissionUpdateService.setAuthtionResultToRedis(appCode, list);
+          return list;
+//        } else {
+//            return redisValue;
+//        }
     }
 
     /**
      * 保存
-     *
      * @param dto
      * @return
      */
     @Override
-    public ResponseDTO saveServiceAuthResult(ServiceAuthResultDTO dto) {
-        try {
-
-            ServiceAuthResult result = new ServiceAuthResult();
-            BeanUtils.copyProperties(dto, result);
-            ApplyInfo app = applyInfoFacade.applyDetail(dto.getAppId());
-            Boolean aBoolean = serviceAuthResultBPO.serviceCodeCheck(app.getApplyCode(), dto.getServiceCode(), null);
-            if (aBoolean) {
-                return ResponseDTO.fail("保存失败,重复的服务授权", new ServiceAuthResult());
-            }
-            result.setAppId(app.getId());
-            result.setAppCode(app.getApplyCode());
-            result.setDeleted(BooleanEnum.FALSE.value);
-            ServiceResource serviceResource = serviceResourceFacade.detailByCode(dto.getServiceCode());
-            result.setServiceId(serviceResource.getId());
-            this.saveAuthResult(result);
-            List<String> addServiceCodes = new ArrayList<>();
-            addServiceCodes.add(result.getServiceCode());
-            this.sendPermssionService(result.getAppCode(), addServiceCodes, new ArrayList<>());
-        } catch (Exception e) {
-            log.error("save ServiceAuthResult error :", e);
-            return ResponseDTO.fail("保存失败", new ServiceAuthResult());
-        }
-        return ResponseDTO.success("保存成功", null);
+    public ResponseDTO saveServiceAuthResult(ServiceAuthResultDTO dto){
+       try{
+
+           ServiceAuthResult result=new ServiceAuthResult();
+           BeanUtils.copyProperties(dto,result);
+           ApplyInfo app = applyInfoFacade.applyDetail(dto.getAppId());
+           Boolean aBoolean = serviceAuthResultBPO.serviceCodeCheck(app.getApplyCode(), dto.getServiceCode(),null);
+           if (aBoolean){
+               return ResponseDTO.fail("保存失败,重复的服务授权",new ServiceAuthResult());
+           }
+           result.setAppId(app.getId());
+           result.setAppCode(app.getApplyCode());
+           result.setDeleted(BooleanEnum.FALSE.value);
+           ServiceResource serviceResource = serviceResourceFacade.detailByCode(dto.getServiceCode());
+           result.setServiceId(serviceResource.getId());
+           result.setAuthStatus("1");
+           this.saveAuthResult(result);
+           List<String> addServiceCodes=new ArrayList<>();
+           addServiceCodes.add(result.getServiceCode());
+           this.sendPermssionService(result.getAppCode(),addServiceCodes,new ArrayList<>());
+       }catch (Exception e){
+            log.error("save ServiceAuthResult error :",e);
+           return ResponseDTO.fail("保存失败",new ServiceAuthResult());
+       }
+       return ResponseDTO.success("保存成功",null);
     }
 
     /**
      * 删除
-     *
-     * @param id
+     * @param serviceAuthResultDTO
      * @return ResponseDTO
      */
     @Override
-    public ResponseDTO delServiceAuthResult(String id) {
-        ServiceAuthResult result = serviceAuthResultBPO.get(id);
+    public ResponseDTO delServiceAuthResult(ServiceAuthResultDTO serviceAuthResultDTO){
+        ServiceAuthResult result = serviceAuthResultBPO.get(serviceAuthResultDTO.getId());
         result.setDeleted(BooleanEnum.TRUE.value);
+        result.setReason(serviceAuthResultDTO.getReason());
         serviceAuthResultBPO.update(result);
         //发送消息
-        List<String> delServiceCodes = new ArrayList<>();
+        List<String> delServiceCodes=new ArrayList<>();
         delServiceCodes.add(result.getServiceCode());
-        this.sendPermssionService(result.getAppCode(), new ArrayList<>(), delServiceCodes);
-        return ResponseDTO.success("删除成功", null);
+        this.sendPermssionService(result.getAppCode(),new ArrayList<>(),delServiceCodes);
+        return ResponseDTO.success("删除成功",null);
     }
 
     /**
      * 修改
-     *
      * @param dto
      * @return
      */
     @Override
-    public ResponseDTO updateServiceAuthResult(ServiceAuthResultDTO dto) {
-        Boolean aBoolean = serviceAuthResultBPO.serviceCodeCheck(dto.getAppCode(), dto.getServiceCode(), dto.getId());
-        if (aBoolean) {
-            return ResponseDTO.fail("保存失败,重复的服务授权", new ServiceAuthResult());
+    public ResponseDTO updateServiceAuthResult(ServiceAuthResultDTO dto){
+        Boolean aBoolean = serviceAuthResultBPO.serviceCodeCheck(dto.getAppCode(), dto.getServiceCode(),dto.getId());
+        if (aBoolean){
+            return ResponseDTO.fail("保存失败,重复的服务授权",new ServiceAuthResult());
         }
-        ServiceAuthResult result = serviceAuthResultBPO.get(dto.getId());
+        ServiceAuthResult result=serviceAuthResultBPO.get(dto.getId());
         //BeanUtils.copyProperties(result,dto);
         ApplyInfo app = applyInfoFacade.applyDetail(dto.getAppId());
         result.setAppId(app.getId());
@@ -351,24 +358,25 @@ public class ServiceAuthResultServiceImpl implements IServiceAuthResultService {
         result.setUpdateTime(new Date());
         serviceAuthResultBPO.update(result);
         //发送消息 todo 算新增还是修改?
-        List<String> addServiceCodes = new ArrayList<>();
+        List<String> addServiceCodes=new ArrayList<>();
         addServiceCodes.add(result.getServiceCode());
-        this.sendPermssionService(result.getAppCode(), addServiceCodes, new ArrayList<>());
-        return ResponseDTO.success("修改成功", null);
+        this.sendPermssionService(result.getAppCode(),addServiceCodes,new ArrayList<>());
+        return ResponseDTO.success("修改成功",null);
     }
 
     /**
+     *
      * @param searchable
      * @return
      */
     @Override
-    public Page<ServiceAuthResultDTO> serviceAuthResultPage(Searchable searchable) {
+    public Page<ServiceAuthResultDTO> serviceAuthResultPage(Searchable searchable){
         searchable.addSearchFilter("deleted", SearchOperator.eq, BooleanEnum.FALSE.getValue());
         Page<ServiceAuthResultPO> paging = serviceAuthResultBPO.serviceAuthResultPage(searchable);
-        List<ServiceAuthResultDTO> dtos = new ArrayList<>();
-        paging.forEach(item -> {
-            ServiceAuthResultDTO dto = new ServiceAuthResultDTO();
-            BeanUtils.copyProperties(item, dto);
+        List<ServiceAuthResultDTO> dtos=new ArrayList<>();
+        paging.forEach(item->{
+            ServiceAuthResultDTO dto=new ServiceAuthResultDTO();
+            BeanUtils.copyProperties(item,dto);
             dto.setAuthStatus(item.getServiceStatus());
             dtos.add(dto);
         });
@@ -410,51 +418,49 @@ public class ServiceAuthResultServiceImpl implements IServiceAuthResultService {
 
     @Override
     public ServiceAuthResultDTO getDetail(String id) {
-        ServiceAuthResult result = serviceAuthResultBPO.get(id);
-        ServiceAuthResultDTO dto = new ServiceAuthResultDTO();
-        BeanUtils.copyProperties(result, dto);
+        ServiceAuthResult result=serviceAuthResultBPO.get(id);
+        ServiceAuthResultDTO dto=new ServiceAuthResultDTO();
+        BeanUtils.copyProperties(result,dto);
         return dto;
 
     }
 
     /**
      * 查询结果
-     *
      * @param appCode
      * @return
      */
     @Override
-    public List<ServiceAuthResult> serviceAuthResultList(String appCode) {
+    public List<ServiceAuthResult> serviceAuthResultList(String appCode){
         return this.serviceAuthResultBPO.serviceAuthResultList(appCode);
     }
 
     /**
      * 发送删除服务的消息
-     *
      * @param serviceCode
      */
     @Override
-    public void sendPermssionServiceUpdate(String serviceCode, String type) {
-        Map map = new HashMap();
-        map.put("serviceCode", serviceCode);
-        map.put("deleted", BooleanEnum.FALSE.value);
+    public void sendPermssionServiceUpdate(String serviceCode,String type){
+        Map map=new HashMap();
+        map.put("serviceCode",serviceCode);
+        map.put("deleted",BooleanEnum.FALSE.value);
 
         List<ServiceAuthResult> serviceAuthResultList = this.serviceAuthResultBPO.andsearch(ServiceAuthResult.class, map);
-        Set<String> appCodes = new HashSet<>();
+        Set<String> appCodes=new HashSet<>();
         //挑出要变更服务涉及到的app并去重
-        serviceAuthResultList.forEach(item -> {
+        serviceAuthResultList.forEach(item->{
             appCodes.add(item.getAppCode());
         });
         //拼接数据
-        List<AppServiceCodeDto> dtos = new ArrayList<>();
-        appCodes.forEach(appCode -> {
-            AppServiceCodeDto dto = new AppServiceCodeDto();
-            List<String> addServiceCodes = new ArrayList<>();
-            List<String> delServiceCodes = new ArrayList<>();
-            serviceAuthResultList.forEach(result -> {
-                if ("DELETED".equals(type) && appCode.equals(result.getAppCode())) {
+        List<AppServiceCodeDto> dtos=new ArrayList<>();
+        appCodes.forEach(appCode->{
+            AppServiceCodeDto dto=new AppServiceCodeDto();
+            List<String> addServiceCodes=new ArrayList<>();
+            List<String> delServiceCodes=new ArrayList<>();
+            serviceAuthResultList.forEach(result->{
+                if ("DELETED".equals(type)&&appCode.equals(result.getAppCode())){
                     delServiceCodes.add(result.getServiceCode());
-                } else {
+                }else {
                     addServiceCodes.add(result.getServiceCode());
                 }
             });
@@ -463,25 +469,11 @@ public class ServiceAuthResultServiceImpl implements IServiceAuthResultService {
             dto.setDelServiceCodes(delServiceCodes);
             dtos.add(dto);
         });
-        if (CollectionUtils.isNotEmpty(dtos)) {
+        if (CollectionUtils.isNotEmpty(dtos)){
             permssionServiceUpdateEventBus.post(dtos);
         }
     }
 
-    /**
-     * 设置鉴权结果到redis
-     *
-     * @param appCode
-     * @param list
-     */
-    @Override
-    public void setAuthtionResultToRedis(String appCode, List<ServiceAuthenticationResVO> list) {
-        if (CollectionUtils.isNotEmpty(list)) {
-            redisTemplate.opsForValue().set(DcucConstantsUtil.AUTHENTICATION_SPACE + appCode, list, 1, TimeUnit.HOURS);
-        }
-    }
-
-
     @Override
     public ServiceAuthResultDTO getDetailByAppAndService(String appCode, String serviceCode) {
         ServiceAuthResult authBpo = serviceAuthResultBPO.getDetailByAppAndService(appCode, serviceCode);
@@ -500,7 +492,6 @@ public class ServiceAuthResultServiceImpl implements IServiceAuthResultService {
         paging.forEach(item->{
             ServiceAuthResultDTO dto=new ServiceAuthResultDTO();
             BeanUtils.copyProperties(item,dto);
-            dto.setAuthStatus(item.getServiceStatus());
             dtos.add(dto);
         });
         Pageable newPageable = new PageRequest(paging.getNumber(), paging.getSize());
@@ -508,4 +499,19 @@ public class ServiceAuthResultServiceImpl implements IServiceAuthResultService {
         return pageResult;
     }
 
+    @Override
+    public List<String> authResultRepeatCheck(String appCode, List<String> serviceCodes) {
+        Searchable searchable = Searchable.newSearchable();
+        searchable.addSearchFilter("app_code", SearchOperator.eq, appCode);
+        searchable.addSearchFilter("deleted", SearchOperator.eq, BooleanEnum.FALSE.getValue());
+        searchable.addSearchFilter("auth_status", SearchOperator.eq, ServiceAuthStatusEnum.START.getValue());
+        List<ServiceAuthResult> authResults = serviceAuthResultBPO.find(ServiceAuthResult.class, searchable);
+        List<String> exist = authResults.stream()
+                .map(item -> item.getServiceCode())
+                .filter(item -> serviceCodes.contains(item))
+                .distinct()
+                .collect(Collectors.toList());
+        return exist;
+    }
+
 }

+ 17 - 0
dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/business/IBimBusiness.java

@@ -59,4 +59,21 @@ public interface IBimBusiness {
      * @return 用户信息
      */
     BimUserInfoItemRespVO getUserInfoByUserToken(String userToken);
+
+    /**
+     * 获取用户令牌
+     *
+     * @param needReGet 需要重新获取
+     * @return 用户令牌
+     */
+    String getUserToken(boolean needReGet);
+
+    /**
+     * 获取应用令牌
+     *
+     * @param userToken 用户令牌
+     * @param needReGet 需要重新获取
+     * @return 应用令牌
+     */
+    String getAppToken(String userToken, boolean needReGet);
 }

+ 119 - 0
dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/business/impl/BimBusinessImpl.java

@@ -2,6 +2,8 @@ package com.dragoninfo.dcuc.auth.business.impl;
 
 import cn.hutool.core.util.StrUtil;
 import cn.hutool.http.HttpRequest;
+import cn.hutool.system.HostInfo;
+import cn.hutool.system.SystemUtil;
 import com.dragoninfo.dcuc.auth.AuthRedisConstant;
 import com.dragoninfo.dcuc.auth.auth.enumresources.BimTokenResultEnum;
 import com.dragoninfo.dcuc.auth.auth.vo.bim.*;
@@ -272,4 +274,121 @@ public class BimBusinessImpl implements IBimBusiness {
 
         return bimRespVo.getData();
     }
+
+    @Override
+    public String getUserToken(boolean needReGet) {
+        String redisUserToken = String.valueOf(redisTemplate.opsForValue().get(AuthRedisConstant.REDIS_BIM_USER_TOKEN_NAMESPACE));
+
+        String userToken = "";
+
+        if (StrUtil.isNotBlank(redisUserToken)) {
+            userToken = redisUserToken;
+        }
+
+        if (needReGet) {
+            userToken = httpGetUseToken();
+        }
+        return userToken;
+    }
+
+    @Override
+    public String getAppToken(String userToken, boolean needReGet) {
+
+        String redisAppToken = String.valueOf(redisTemplate.opsForValue().get(AuthRedisConstant.REDIS_BIM_APP_TOKEN_NAMESPACE));
+
+        String appToken = "";
+
+        if (StrUtil.isNotBlank(redisAppToken)) {
+            appToken = redisAppToken;
+        }
+
+        if (needReGet) {
+            appToken = httpGetAppToken(userToken);
+        }
+        return appToken;
+    }
+
+    /**
+     * 获取用户令牌
+     *
+     * @return 用户令牌
+     */
+    private String httpGetUseToken() {
+        String messageId = UUIDUtils.getUUID();
+        String token = getToken();
+        String bimUsername = dcucAuthConfig.getBimUsername();
+        String bimPassword = dcucAuthConfig.getBimPassword();
+        HostInfo hostInfo = SystemUtil.getHostInfo();
+        String address = hostInfo.getAddress();
+
+        BimGetUserTokenReqVO bimGetUserTokenReqVO = new BimGetUserTokenReqVO();
+        bimGetUserTokenReqVO.setUsername(bimUsername);
+        bimGetUserTokenReqVO.setPassword(bimPassword);
+        bimGetUserTokenReqVO.setClientIp(address);
+        bimGetUserTokenReqVO.setMessageId(messageId);
+        bimGetUserTokenReqVO.setToken(token);
+
+        String reqJson = JsonUtils.toJSONString(bimGetUserTokenReqVO);
+
+        log.info("getUserToken req :{}", reqJson);
+
+        String url = dcucAuthConfig.getBimUrl() + "/api/rest/customization/ExpApiCustomDragonitService/getUserToken";
+
+        log.info("getUserToken req url:{}", reqJson);
+        String postResp = HttpRequest.post(url)
+                .body(reqJson)
+                .execute()
+                .body();
+        log.info("getUserToken resp :{}", postResp);
+
+        BimGetUserTokenRespVO bimRespVo = JsonUtils.parseObject(postResp, BimGetUserTokenRespVO.class);
+
+        if (!bimRespVo.getSuccess()) {
+            log.error("getUserToken error:{}", postResp);
+        }
+
+        BimGetUserTokenItemRespVO data = bimRespVo.getData();
+        return data.getUserToken();
+    }
+
+    /**
+     * 获取应用令牌
+     *
+     * @param userToken 用户令牌
+     * @return 应用令牌
+     */
+    private String httpGetAppToken(String userToken) {
+        String messageId = UUIDUtils.getUUID();
+        String token = getToken();
+
+        String appCode = dcucAuthConfig.getAppCode();
+
+        BimGetAppTokenReqVO bimGetAppTokenReqVO = new BimGetAppTokenReqVO();
+        bimGetAppTokenReqVO.setAppId(appCode);
+        bimGetAppTokenReqVO.setMessageId(messageId);
+        bimGetAppTokenReqVO.setToken(token);
+        bimGetAppTokenReqVO.setUserToken(userToken);
+
+        String reqJson = JsonUtils.toJSONString(bimGetAppTokenReqVO);
+
+        log.info("getAppToken req :{}", reqJson);
+
+        String url = dcucAuthConfig.getBimUrl() + "/api/rest/customization/ExpApiCustomDragonitService/getAppToken";
+
+        log.info("getAppToken req url:{}", reqJson);
+        String postResp = HttpRequest.post(url)
+                .body(reqJson)
+                .execute()
+                .body();
+        log.info("getAppToken resp :{}", postResp);
+
+        BimGetAppTokenRespVO bimRespVo = JsonUtils.parseObject(postResp, BimGetAppTokenRespVO.class);
+
+        if (!bimRespVo.getSuccess()) {
+            log.error("getAppToken error:{}", postResp);
+        }
+
+        BimGetAppTokenItemRespVO data = bimRespVo.getData();
+        return data.getAppToken();
+    }
 }

+ 11 - 2
dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/config/DcucAuthConfig.java

@@ -49,10 +49,19 @@ public class DcucAuthConfig {
      */
     private String bimLoginId;
 
-
     /**
-     * 竹云调用方密
+     * 竹云应用方秘
      */
     private String bimSecretKey;
 
+    /**
+     * 竹云调用方用户名
+     */
+    private String bimUsername;
+
+    /**
+     * 竹云调用方密码
+     */
+    private String bimPassword;
+
 }

+ 9 - 3
dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/msg/WorkFlowResultListener.java

@@ -3,6 +3,7 @@ package com.dragoninfo.dcuc.auth.msg;
 import com.alibaba.fastjson.JSON;
 import com.dragoninfo.dcuc.auth.auth.business.IServiceAuthBusiness;
 import com.dragoninfo.dcuc.auth.auth.dto.WorkFlowResutlAcceptDTO;
+import com.dragoninfo.dcuc.auth.auth.enumresources.ApproveResultEnum;
 import com.dragoninfo.dcuc.auth.auth.enumresources.WorkFlowStatusEnum;
 import com.dragonsoft.duceap.commons.util.collections.CollectionUtils;
 import com.dragonsoft.mq.client.model.entity.MessageInfoDTO;
@@ -49,15 +50,20 @@ public class WorkFlowResultListener {
                 logger.info("info set is empty");
                 return;
             }
+            String result = map.get("approveResult");
+            WorkFlowStatusEnum statusEnum = WorkFlowStatusEnum.getStatusByApproveResult(result);
+            if(null == statusEnum){
+                logger.info("status enum is null");
+                return;
+            }
             WorkFlowResutlAcceptDTO dto = new WorkFlowResutlAcceptDTO();
-            dto.setApproveResult(WorkFlowStatusEnum.SUCCESS.getValue());
             dto.setMessageId(map.get("messageId"));
             dto.setProcessInstanceId(map.get("processInstanceId"));
-            logger.info("processDTO work flow id:{}, message id:{}", dto.getProcessInstanceId(), dto.getMessageId());
+            dto.setApproveResult(statusEnum.getValue());
+            logger.info("WorkFlowResultListener------ work flow dto:{}", JSON.toJSONString(dto));
             serviceAuthBusiness.dealAuthFlowResult(dto);
         } catch (Exception e) {
             logger.error("receiveMessage error.", e);
         }
     }
-
 }

+ 4 - 0
dcuc-auth-service/src/main/resources/config/mysql/V4_3_0006__Add_AuthResult.sql

@@ -0,0 +1,4 @@
+ALTER TABLE `T_SERVICE_AUTH_RESULT` ADD `reason` varchar(200) DEFAULT NULL COMMENT '理由';
+-- 处理手动添加的历史数据
+UPDATE `t_service_auth_result` set `auth_status` = '1' where `deleted` = '0' AND `start_time` is NULL and `end_time` is NULL;
+

+ 5 - 0
dcuc-auth-service/src/main/resources/config/sql/V4_3_0007__Add_AuthResult.sql

@@ -0,0 +1,5 @@
+alter table T_SERVICE_AUTH_RESULT add reason varchar2(200);
+comment on column T_SERVICE_AUTH_RESULT.reason is '理由';
+
+-- 处理手动添加的历史数据
+UPDATE T_SERVICE_AUTH_RESULT set AUTH_STATUS = '1' where DELETED = '0' AND START_TIME is NULL and END_TIME is NULL;

+ 1 - 1
pom.xml

@@ -4,7 +4,7 @@
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     <modelVersion>4.0.0</modelVersion>
     <groupId>com.dragoninfo</groupId>
-    <version>2.2.0-tjdsj-SNAPSHOT</version>
+    <version>2.1.1-tjdsj-SNAPSHOT</version>
     <artifactId>dcuc-auth</artifactId>
     <packaging>pom</packaging>
     <modules>