瀏覽代碼

feature: 角色授权申请审批回调

mazq 1 年之前
父節點
當前提交
ad6cae4379

+ 12 - 0
dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/auth/repo/zerotrust/RoleAuthApplyRepository.java

@@ -2,6 +2,9 @@ package com.dragoninfo.dcuc.auth.auth.repo.zerotrust;
 
 
 import com.dragoninfo.dcuc.auth.auth.entity.zerotrust.RoleAuthApply;
 import com.dragoninfo.dcuc.auth.auth.entity.zerotrust.RoleAuthApply;
 import com.dragonsoft.duceap.core.persistent.repository.BaseRepository;
 import com.dragonsoft.duceap.core.persistent.repository.BaseRepository;
+import org.springframework.data.jpa.repository.Modifying;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.query.Param;
 import org.springframework.stereotype.Repository;
 import org.springframework.stereotype.Repository;
 
 
 /**
 /**
@@ -10,4 +13,13 @@ import org.springframework.stereotype.Repository;
  */
  */
 @Repository
 @Repository
 public interface RoleAuthApplyRepository extends BaseRepository<RoleAuthApply, String> {
 public interface RoleAuthApplyRepository extends BaseRepository<RoleAuthApply, String> {
+
+    /**
+     * 更新审批结果
+     * @param processInstId
+     * @param approvalResult
+     */
+    @Modifying
+    @Query(value = "UPDATE T_AUTH_ROLE_AUTH_APPLY SET APPROVAL_RESULT = :approvalResult WHERE PROCESS_INST_ID = :processInstId AND DELETED = '0'", nativeQuery = true)
+    void updateApprovalResult(@Param("processInstId") String processInstId, @Param("approvalResult") String approvalResult);
 }
 }

+ 15 - 0
dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/auth/service/impl/zerotrust/RoleAuthApplyServiceImpl.java

@@ -22,6 +22,7 @@ import com.dragonsoft.duceap.commons.util.UUIDUtils;
 import com.dragonsoft.duceap.commons.util.json.JsonUtils;
 import com.dragonsoft.duceap.commons.util.json.JsonUtils;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Example;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.transaction.annotation.Transactional;
 
 
@@ -121,6 +122,20 @@ public class RoleAuthApplyServiceImpl implements IRoleAuthApplyService {
         return ResponseDTO.success("", (Object) null);
         return ResponseDTO.success("", (Object) null);
     }
     }
 
 
+    @Override
+    public List<RoleAuthApply> getByProcessInstId(String processInstId) {
+        RoleAuthApply roleAuthApply = new RoleAuthApply();
+        roleAuthApply.setProcessInstId(processInstId);
+        Example<RoleAuthApply> example = Example.of(roleAuthApply);
+        return repository.findAll(example);
+    }
+
+    @Transactional(rollbackFor = Exception.class)
+    @Override
+    public void updateApprovalResult(String processInstId, String approvalResult) {
+        repository.updateApprovalResult(processInstId, approvalResult);
+    }
+
     private Map<String, String> getBizData(RoleAuthApplySaveVo saveVo, AuthUserInfo userInfo) {
     private Map<String, String> getBizData(RoleAuthApplySaveVo saveVo, AuthUserInfo userInfo) {
         Map<String, String> bizData = new HashMap<>();
         Map<String, String> bizData = new HashMap<>();
         // 授权主体人员信息
         // 授权主体人员信息

+ 17 - 0
dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/auth/service/zerotrust/IRoleAuthApplyService.java

@@ -1,8 +1,11 @@
 package com.dragoninfo.dcuc.auth.auth.service.zerotrust;
 package com.dragoninfo.dcuc.auth.auth.service.zerotrust;
 
 
+import com.dragoninfo.dcuc.auth.auth.entity.zerotrust.RoleAuthApply;
 import com.dragoninfo.dcuc.auth.auth.vo.zerotrust.roleauthapply.RoleAuthApplySaveVo;
 import com.dragoninfo.dcuc.auth.auth.vo.zerotrust.roleauthapply.RoleAuthApplySaveVo;
 import com.dragonsoft.duceap.base.entity.http.ResponseStatus;
 import com.dragonsoft.duceap.base.entity.http.ResponseStatus;
 
 
+import java.util.List;
+
 /**
 /**
  * 角色授权申请Service
  * 角色授权申请Service
  * @author mazq
  * @author mazq
@@ -16,4 +19,18 @@ public interface IRoleAuthApplyService {
      * @return
      * @return
      */
      */
     ResponseStatus roleAuthApply(RoleAuthApplySaveVo saveVo);
     ResponseStatus roleAuthApply(RoleAuthApplySaveVo saveVo);
+
+    /**
+     * 根据流程实例id查询申请内容
+     * @param processInstId
+     * @return
+     */
+    List<RoleAuthApply> getByProcessInstId(String processInstId);
+
+    /**
+     * 更新审批结果
+     * @param processInstId
+     * @param approvalResult
+     */
+    void updateApprovalResult(String processInstId, String approvalResult);
 }
 }

+ 35 - 0
dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/business/impl/zerotrust/ApprovalBusinessImpl.java

@@ -11,11 +11,13 @@ import com.dragoninfo.dcuc.auth.auth.constance.zerotrust.approval.ApprovalConsta
 import com.dragoninfo.dcuc.auth.auth.dto.zerotrust.approval.*;
 import com.dragoninfo.dcuc.auth.auth.dto.zerotrust.approval.*;
 import com.dragoninfo.dcuc.auth.auth.entity.RoleInfo;
 import com.dragoninfo.dcuc.auth.auth.entity.RoleInfo;
 import com.dragoninfo.dcuc.auth.auth.entity.zerotrust.ApprovalResult;
 import com.dragoninfo.dcuc.auth.auth.entity.zerotrust.ApprovalResult;
+import com.dragoninfo.dcuc.auth.auth.entity.zerotrust.RoleAuthApply;
 import com.dragoninfo.dcuc.auth.auth.entity.zerotrust.RoleOperateContent;
 import com.dragoninfo.dcuc.auth.auth.entity.zerotrust.RoleOperateContent;
 import com.dragoninfo.dcuc.auth.auth.enumresources.YesNotEnum;
 import com.dragoninfo.dcuc.auth.auth.enumresources.YesNotEnum;
 import com.dragoninfo.dcuc.auth.auth.enumresources.zerotrust.approval.*;
 import com.dragoninfo.dcuc.auth.auth.enumresources.zerotrust.approval.*;
 import com.dragoninfo.dcuc.auth.auth.service.IRoleInfoService;
 import com.dragoninfo.dcuc.auth.auth.service.IRoleInfoService;
 import com.dragoninfo.dcuc.auth.auth.service.zerotrust.IApprovalResultService;
 import com.dragoninfo.dcuc.auth.auth.service.zerotrust.IApprovalResultService;
+import com.dragoninfo.dcuc.auth.auth.service.zerotrust.IRoleAuthApplyService;
 import com.dragoninfo.dcuc.auth.auth.service.zerotrust.IRoleOperateApplyService;
 import com.dragoninfo.dcuc.auth.auth.service.zerotrust.IRoleOperateApplyService;
 import com.dragoninfo.dcuc.auth.auth.vo.zerotrust.approval.ApprovalCallBackReqVO;
 import com.dragoninfo.dcuc.auth.auth.vo.zerotrust.approval.ApprovalCallBackReqVO;
 import com.dragoninfo.dcuc.auth.business.zerotrust.IApprovalBusiness;
 import com.dragoninfo.dcuc.auth.business.zerotrust.IApprovalBusiness;
@@ -31,10 +33,12 @@ import com.dragonsoft.duceap.base.entity.http.ResponseStatus;
 import com.dragonsoft.duceap.base.enums.BooleanEnum;
 import com.dragonsoft.duceap.base.enums.BooleanEnum;
 import com.dragonsoft.duceap.base.utils.UserContextUtils;
 import com.dragonsoft.duceap.base.utils.UserContextUtils;
 import com.dragonsoft.duceap.commons.util.ObjectUtils;
 import com.dragonsoft.duceap.commons.util.ObjectUtils;
+import com.dragonsoft.duceap.commons.util.collections.CollectionUtils;
 import com.dragonsoft.duceap.commons.util.date.DateConst;
 import com.dragonsoft.duceap.commons.util.date.DateConst;
 import com.dragonsoft.duceap.commons.util.date.DateUtils;
 import com.dragonsoft.duceap.commons.util.date.DateUtils;
 import com.dragonsoft.duceap.commons.util.enums.EnumUtils;
 import com.dragonsoft.duceap.commons.util.enums.EnumUtils;
 import com.dragonsoft.duceap.commons.util.string.StringUtils;
 import com.dragonsoft.duceap.commons.util.string.StringUtils;
+import com.gentlyweb.utils.CollectionsUtils;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.redis.core.StringRedisTemplate;
 import org.springframework.data.redis.core.StringRedisTemplate;
@@ -68,6 +72,12 @@ public class ApprovalBusinessImpl implements IApprovalBusiness {
 
 
     private IApproveRemoteCallBusiness approveRemoteCallBusiness;
     private IApproveRemoteCallBusiness approveRemoteCallBusiness;
 
 
+    private IRoleAuthApplyService roleAuthApplyService;
+
+    @Autowired
+    public void setRoleAuthApplyService(IRoleAuthApplyService roleAuthApplyService) {
+        this.roleAuthApplyService = roleAuthApplyService;
+    }
 
 
     @Autowired
     @Autowired
     public void setApproveRemoteCallBusiness(IApproveRemoteCallBusiness approveRemoteCallBusiness) {
     public void setApproveRemoteCallBusiness(IApproveRemoteCallBusiness approveRemoteCallBusiness) {
@@ -287,6 +297,8 @@ public class ApprovalBusinessImpl implements IApprovalBusiness {
             ApprovalBaseRespDto approvalBaseRespDto = new ApprovalBaseRespDto().success();
             ApprovalBaseRespDto approvalBaseRespDto = new ApprovalBaseRespDto().success();
             if (ApprovalApplyTypeEnum.ROLE_OPERATE.getValue().equals(applyType)) {
             if (ApprovalApplyTypeEnum.ROLE_OPERATE.getValue().equals(applyType)) {
                 approvalBaseRespDto = roleOperateCallBackHandle(processInstId, type, endFlag);
                 approvalBaseRespDto = roleOperateCallBackHandle(processInstId, type, endFlag);
+            } else if (ApprovalApplyTypeEnum.ROLE_AUTH_APPLY.getValue().equals(applyType)) {
+                approvalBaseRespDto = roleAuthCallBackHandle(processInstId, type, endFlag);
             }
             }
 
 
             // 更新审批结果
             // 更新审批结果
@@ -301,6 +313,24 @@ public class ApprovalBusinessImpl implements IApprovalBusiness {
 
 
     }
     }
 
 
+    private ApprovalBaseRespDto roleAuthCallBackHandle(String processInstId, String type, String endFlag) {
+        log.info("开始处理角色权限申请");
+        List<RoleAuthApply> authApplies = roleAuthApplyService.getByProcessInstId(processInstId);
+        if (CollectionUtils.isEmpty(authApplies)) {
+            log.info("查询不到权限申请内容");
+            return new ApprovalBaseRespDto().success();
+        }
+        // 回调修改流程状态
+        String approvalResult = getApplyStatus(type, endFlag);
+        roleAuthApplyService.updateApprovalResult(processInstId, approvalResult);
+
+        if (!AuthApplyStatusEnum.AGREE.getValue().equals(approvalResult)) {
+            return new ApprovalBaseRespDto().success();
+        }
+        // 开始角色授权
+        return new ApprovalBaseRespDto().success();
+    }
+
     private void updateApprovalResult(ApprovalResult approvalResult, ApprovalCallBackReqVO approvalCallBackReqVO) {
     private void updateApprovalResult(ApprovalResult approvalResult, ApprovalCallBackReqVO approvalCallBackReqVO) {
         BeanUtil.copyProperties(approvalCallBackReqVO, approvalResult, "taskId", "businessKey");
         BeanUtil.copyProperties(approvalCallBackReqVO, approvalResult, "taskId", "businessKey");
         approvalResult.setCallBack(BooleanEnum.TRUE.value);
         approvalResult.setCallBack(BooleanEnum.TRUE.value);
@@ -310,6 +340,7 @@ public class ApprovalBusinessImpl implements IApprovalBusiness {
     private ApprovalBaseRespDto roleOperateCallBackHandle(String processInstId, String type, String endFlag) {
     private ApprovalBaseRespDto roleOperateCallBackHandle(String processInstId, String type, String endFlag) {
         RoleOperateContent roleOperateContent = roleOperateApplyService.getByProcessInstIdId(processInstId);
         RoleOperateContent roleOperateContent = roleOperateApplyService.getByProcessInstIdId(processInstId);
         if (null == roleOperateContent) {
         if (null == roleOperateContent) {
+            log.info("查询不到角色申请内容");
             return new ApprovalBaseRespDto().success();
             return new ApprovalBaseRespDto().success();
         }
         }
 
 
@@ -318,6 +349,7 @@ public class ApprovalBusinessImpl implements IApprovalBusiness {
     }
     }
 
 
     private ApprovalBaseRespDto handleRoleOperateApproval(RoleOperateContent roleOperateContent, String type, String endFlag) {
     private ApprovalBaseRespDto handleRoleOperateApproval(RoleOperateContent roleOperateContent, String type, String endFlag) {
+        log.info("开始处理角色申请");
         String id = roleOperateContent.getId();
         String id = roleOperateContent.getId();
         // 流程被删除对应删除本地申请
         // 流程被删除对应删除本地申请
         if (FlowCallBackTypeEnum.DELETE.getValue().equals(type)) {
         if (FlowCallBackTypeEnum.DELETE.getValue().equals(type)) {
@@ -341,9 +373,11 @@ public class ApprovalBusinessImpl implements IApprovalBusiness {
             if (null != roleInfoByCode) {
             if (null != roleInfoByCode) {
                 log.info("角色代码已存在:{}", roleInfo.getCode());
                 log.info("角色代码已存在:{}", roleInfo.getCode());
             } else {
             } else {
+                log.info("保存新增角色");
                 roleInfoService.save(roleInfo);
                 roleInfoService.save(roleInfo);
             }
             }
         } else if (OperateTypeEnum.DELETE.getValue().equals(operateType)) {
         } else if (OperateTypeEnum.DELETE.getValue().equals(operateType)) {
+            log.info("删除角色:{}", roleOperateContent.getRoleId());
             roleInfoService.deleteRole(roleOperateContent.getRoleId());
             roleInfoService.deleteRole(roleOperateContent.getRoleId());
         } else if (OperateTypeEnum.UPDATE.getValue().equals(operateType)) {
         } else if (OperateTypeEnum.UPDATE.getValue().equals(operateType)) {
             RoleInfo roleInfo = getNewRoleInfo(roleOperateContent);
             RoleInfo roleInfo = getNewRoleInfo(roleOperateContent);
@@ -353,6 +387,7 @@ public class ApprovalBusinessImpl implements IApprovalBusiness {
             if (null != roleInfoByCode && !roleInfoByCode.getId().equals(roleInfo.getId())) {
             if (null != roleInfoByCode && !roleInfoByCode.getId().equals(roleInfo.getId())) {
                 log.info("角色代码已存在");
                 log.info("角色代码已存在");
             } else {
             } else {
+                log.info("更新角色:{}", roleInfo.getId());
                 roleInfoService.update(roleInfo);
                 roleInfoService.update(roleInfo);
             }
             }
         }
         }