Kaynağa Gözat

Merge branch 'release/v2.1.0-beta' of 192.168.0.144:dcuc-tjdsj/auth-service into yica_update_auth_210513

yica 4 yıl önce
ebeveyn
işleme
78a8d4dbdf
15 değiştirilmiş dosya ile 387 ekleme ve 87 silme
  1. 11 1
      dcuc-auth-api/src/main/java/com/dragoninfo/dcuc/auth/auth/facade/IServiceAuthFlowFacade.java
  2. 1 3
      dcuc-auth-model/src/main/java/com/dragoninfo/dcuc/auth/auth/dto/ServiceAuthResultDTO.java
  3. 65 0
      dcuc-auth-model/src/main/java/com/dragoninfo/dcuc/auth/auth/enumresources/ApproveResultEnum.java
  4. 51 0
      dcuc-auth-model/src/main/java/com/dragoninfo/dcuc/auth/auth/enumresources/ServiceAuthStatusEnum.java
  5. 15 6
      dcuc-auth-model/src/main/java/com/dragoninfo/dcuc/auth/auth/enumresources/WorkFlowStatusEnum.java
  6. 5 0
      dcuc-auth-model/src/main/java/com/dragoninfo/dcuc/auth/auth/po/ServiceAuthResultPO.java
  7. 5 5
      dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/auth/bpo/ServiceAuthResultBPO.java
  8. 11 0
      dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/auth/business/IServiceAuthBusiness.java
  9. 30 2
      dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/auth/business/impl/ServiceAuthBusinessImpl.java
  10. 12 2
      dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/auth/facade/ServiceAuthFlowFacade.java
  11. 19 0
      dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/auth/service/IAuthFlowService.java
  12. 14 0
      dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/auth/service/IServiceAuthResultService.java
  13. 31 0
      dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/auth/service/impl/AuthFlowServiceImpl.java
  14. 92 66
      dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/auth/service/impl/ServiceAuthResultServiceImpl.java
  15. 25 2
      dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/msg/WorkFlowResultListener.java

+ 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);
 }

+ 1 - 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;
 

+ 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;
+    }
+}

+ 15 - 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;

+ 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;
+
 }

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

@@ -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" +

+ 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);
 }

+ 30 - 2
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());
@@ -130,7 +143,7 @@ public class ServiceAuthBusinessImpl implements IServiceAuthBusiness {
             dto.setAppManagerOrgCode(managerOrgInfo.getCode());
         }
         //保存
-        authFlowService.serviceAuthFlowSave(dto);
+        ServiceAuthFlow serviceAuthFlow = authFlowService.serviceAuthFlowSave(dto);
 
         //将工作单推送给审批服务
         ResponseDTO responseDTO = null;
@@ -139,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) {
@@ -148,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);
+    }
+
     /**
      * 将服务授权工作单推送给审批服务
      *

+ 12 - 2
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/facade/ServiceAuthFlowFacade.java

@@ -7,10 +7,11 @@ 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.IPermissionUpdateService;
 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;
@@ -21,9 +22,13 @@ import java.util.List;
 import java.util.Map;
 
 
+/**
+ * 服务授权工单service
+ * @author mazq
+ */
 @RestController
 @RequestMapping(value = "/dcuc/auth/serviceAuthFacade")
-public class ServiceAuthFacade implements IServiceAuthFacade {
+public class ServiceAuthFlowFacade implements IServiceAuthFlowFacade {
 
     @Autowired
     private IAuthFlowService authFlowService;
@@ -103,4 +108,9 @@ public class ServiceAuthFacade implements IServiceAuthFacade {
     public boolean checkApplicantId(String applicantId) {
         return authFlowService.checkApplicantId(applicantId);
     }
+
+    @Override
+    public ResponseDTO authFlowRepeatCheck(String appCode, List<String> serviceCodes) {
+       return serviceAuthBusiness.authFlowRepeatCheck(appCode, serviceCodes);
+    }
 }

+ 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);
 }

+ 14 - 0
dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/auth/service/IServiceAuthResultService.java

@@ -52,6 +52,12 @@ public interface IServiceAuthResultService {
      */
     List<ServiceAuthResult> getByAppCode(String appCode);
 
+    /**
+     * 根据查询条件查询
+     */
+    List<ServiceAuthResult> find(Searchable searchable);
+
+
     /**
      * 服务授权工作单审批结果处理
      * @param
@@ -109,4 +115,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);
+    }
+
 }

+ 92 - 66
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;
@@ -75,9 +75,6 @@ public class ServiceAuthResultServiceImpl implements IServiceAuthResultService {
     @Autowired
     private IAuthFlowService authFlowService;
 
-    @Autowired
-    private IUserInfoFacade userInfoFacade;
-
     @Override
     public ServiceAuthResult saveAuthResult(ServiceAuthResult serviceAuthResult) {
         serviceAuthResult.setCreateTime(new Date());
@@ -89,8 +86,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)) {
@@ -140,14 +137,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));
 
         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;
         }
 
         //新增的服务
@@ -160,72 +158,81 @@ public class ServiceAuthResultServiceImpl implements IServiceAuthResultService {
         Map<String, ServiceAuthResult> allAuthResultMap = allAuthResults
                 .stream()
                 .collect(Collectors.toMap(ServiceAuthResult::getServiceCode, item -> item,(old,last)->last));
-        Date date = new Date();
         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.keySet().contains(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.keySet().contains(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
@@ -244,11 +251,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);
+    }
+
     /**
      * 服务鉴权
      *
@@ -483,7 +495,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());
@@ -491,4 +502,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;
+    }
+
 }

+ 25 - 2
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,37 @@ public class WorkFlowResultListener {
                 logger.info("info set is empty");
                 return;
             }
+            String result = map.get("approveResult");
+            WorkFlowStatusEnum statusEnum = 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);
         }
     }
 
+    private 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;
+        }
+    }
+
 }