Browse Source

授权申请回调处理

mazq 1 year ago
parent
commit
ddf555dcc8
16 changed files with 324 additions and 26 deletions
  1. 16 0
      dcuc-auth-model/src/main/java/com/dragoninfo/dcuc/auth/api/vo/zerotrust/authapply/ApiServiceAuthContentVo.java
  2. 11 0
      dcuc-auth-model/src/main/java/com/dragoninfo/dcuc/auth/auth/dto/zerotrust/authapply/RoleAuthApplyDto.java
  3. 12 0
      dcuc-auth-model/src/main/java/com/dragoninfo/dcuc/auth/auth/dto/zerotrust/authapply/ServiceAuthApplyDto.java
  4. 13 0
      dcuc-auth-model/src/main/java/com/dragoninfo/dcuc/auth/auth/entity/zerotrust/RoleAuthApply.java
  5. 13 0
      dcuc-auth-model/src/main/java/com/dragoninfo/dcuc/auth/auth/entity/zerotrust/ServiceAuthApply.java
  6. 1 2
      dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/auth/facade/api/ZeroTrustAuthApplyFacade.java
  7. 7 9
      dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/auth/service/IServiceAuthResultService.java
  8. 7 0
      dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/auth/service/IStaffAssignAuthInfoService.java
  9. 9 5
      dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/auth/service/impl/ServiceAuthResultServiceImpl.java
  10. 9 0
      dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/auth/service/impl/StaffAssignAuthInfoService.java
  11. 4 0
      dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/auth/service/impl/zerotrust/RoleAuthApplyServiceImpl.java
  12. 4 0
      dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/auth/service/impl/zerotrust/ServiceAuthApplyServiceImpl.java
  13. 103 2
      dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/business/impl/zerotrust/RoleAuthCallbackHandler.java
  14. 105 2
      dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/business/impl/zerotrust/ServiceAuthCallbackHandler.java
  15. 9 5
      dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/business/impl/zerotrust/ZeroTrustAuthApplyBusinessImpl.java
  16. 1 1
      dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/business/zerotrust/IZeroTrustAuthApplyBusiness.java

+ 16 - 0
dcuc-auth-model/src/main/java/com/dragoninfo/dcuc/auth/api/vo/zerotrust/authapply/ApiServiceAuthContentVo.java

@@ -1,10 +1,14 @@
 package com.dragoninfo.dcuc.auth.api.vo.zerotrust.authapply;
 
+import com.fasterxml.jackson.annotation.JsonFormat;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
+import org.springframework.format.annotation.DateTimeFormat;
 
 import javax.validation.constraints.NotEmpty;
+import javax.validation.constraints.NotNull;
+import java.util.Date;
 import java.util.List;
 
 /**
@@ -18,6 +22,18 @@ public class ApiServiceAuthContentVo {
     @ApiModelProperty(value = "需要申请授权的应用资源编码")
     private String appCode;
 
+    @NotNull
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
+    @ApiModelProperty(value = "开始时间")
+    private Date startTime;
+
+    @NotNull
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
+    @ApiModelProperty(value = "结束时间")
+    private Date endTime;
+
     @NotEmpty
     @ApiModelProperty(value = "需要授权的服务资源编码集合")
     private List<String> serviceCodes;

+ 11 - 0
dcuc-auth-model/src/main/java/com/dragoninfo/dcuc/auth/auth/dto/zerotrust/authapply/RoleAuthApplyDto.java

@@ -4,6 +4,7 @@ import com.dragoninfo.dcuc.auth.auth.vo.zerotrust.roleauthapply.ApplyRoleInVo;
 import com.dragoninfo.dcuc.auth.sub.vo.AuthUserVo;
 import lombok.Data;
 
+import java.util.Date;
 import java.util.List;
 
 /**
@@ -24,4 +25,14 @@ public class RoleAuthApplyDto {
      */
     private List<ApplyRoleInVo> applyRoleIns;
 
+    /**
+     * 权限开始时间
+     */
+    private Date startTime;
+
+    /**
+     * 权限结束时间
+     */
+    private Date endTime;
+
 }

+ 12 - 0
dcuc-auth-model/src/main/java/com/dragoninfo/dcuc/auth/auth/dto/zerotrust/authapply/ServiceAuthApplyDto.java

@@ -4,6 +4,7 @@ import com.dragoninfo.dcuc.auth.sub.vo.ApplyInfoVo;
 import com.dragoninfo.dcuc.auth.sub.vo.ServiceResourceVo;
 import lombok.Data;
 
+import java.util.Date;
 import java.util.List;
 
 /**
@@ -25,4 +26,15 @@ public class ServiceAuthApplyDto {
     private List<ServiceResourceVo> serviceVos;
 
 
+    /**
+     * 权限开始时间
+     */
+    private Date startTime;
+
+    /**
+     * 权限结束时间
+     */
+    private Date endTime;
+
+
 }

+ 13 - 0
dcuc-auth-model/src/main/java/com/dragoninfo/dcuc/auth/auth/entity/zerotrust/RoleAuthApply.java

@@ -8,6 +8,7 @@ import org.hibernate.annotations.GenericGenerator;
 import org.hibernate.annotations.Where;
 
 import javax.persistence.*;
+import java.util.Date;
 
 /**
  * 角色授权申请操作内容
@@ -49,6 +50,18 @@ public class RoleAuthApply extends BaseUpdateEntity implements IdEntity<String>
     @Column(name = "ROLE_CODE")
     private String roleCode;
 
+    /**
+     * 权限开始时间
+     */
+    @Column(name = "START_TIME")
+    private Date startTime;
+
+    /**
+     * 权限结束时间
+     */
+    @Column(name = "END_TIME")
+    private Date endTime;
+
     /**
      * 流程实例id
      */

+ 13 - 0
dcuc-auth-model/src/main/java/com/dragoninfo/dcuc/auth/auth/entity/zerotrust/ServiceAuthApply.java

@@ -8,6 +8,7 @@ import org.hibernate.annotations.GenericGenerator;
 import org.hibernate.annotations.Where;
 
 import javax.persistence.*;
+import java.util.Date;
 
 /**
  * 角色授权申请操作内容
@@ -42,6 +43,18 @@ public class ServiceAuthApply extends BaseEntity implements IdEntity<String> {
      */
     @Column(name = "SERVICE_ID")
     private String serviceId;
+    
+    /**
+     * 权限开始时间
+     */
+    @Column(name = "START_TIME")
+    private Date startTime;
+
+    /**
+     * 权限结束时间
+     */
+    @Column(name = "END_TIME")
+    private Date endTime;
 
     /**
      * 流程实例id

+ 1 - 2
dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/auth/facade/api/ZeroTrustAuthApplyFacade.java

@@ -15,7 +15,6 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
-import javax.validation.Valid;
 import java.util.List;
 
 /**
@@ -43,7 +42,7 @@ public class ZeroTrustAuthApplyFacade implements IZeroTrustAuthApplyFacade {
     }
 
     @Override
-    public ZeroTrustDataRespVO<AuthApplyRespVo> serviceAuthApply(@Valid ApiServiceAuthReqVo reqVo) {
+    public ZeroTrustDataRespVO<AuthApplyRespVo> serviceAuthApply(ApiServiceAuthReqVo reqVo) {
         return zeroTrustAuthApplyBusiness.serviceAuthApply(reqVo);
     }
 

+ 7 - 9
dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/auth/service/IServiceAuthResultService.java

@@ -50,15 +50,6 @@ public interface IServiceAuthResultService {
      */
     List<ServiceAuthResult> find(Searchable searchable);
 
-
-//    /**
-//     * 服务授权工作单审批结果处理
-//     *
-//     * @param
-//     * @param
-//     */
-//    void dealAuthFlowResult(ServiceAuthFlow flow);
-
     /**
      * 服务授权工作单审批结果处理
      * @param
@@ -148,4 +139,11 @@ public interface IServiceAuthResultService {
      * @return
      */
     List<ServiceAuthResult> findAll();
+
+    /**
+     * 批量保存服务授权
+     * @param serviceAuthResult
+     */
+    void batchSave(List<ServiceAuthResult> serviceAuthResult);
+
 }

+ 7 - 0
dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/auth/service/IStaffAssignAuthInfoService.java

@@ -170,4 +170,11 @@ public interface IStaffAssignAuthInfoService  {
      * @return
      */
     ResponseStatus apiStaffRoleAuth(StaffRoleAuthReqVo reqVo);
+
+    /**
+     * 批量保存
+     * @param roleAuths
+     */
+    void batchSave(List<StaffAssignAuthInfo> roleAuths);
+
 }

+ 9 - 5
dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/auth/service/impl/ServiceAuthResultServiceImpl.java

@@ -38,11 +38,9 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.PageImpl;
 import org.springframework.data.domain.Pageable;
-import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
-import javax.annotation.Resource;
 import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.stream.Collectors;
@@ -56,9 +54,6 @@ import java.util.stream.Collectors;
 @Service
 public class ServiceAuthResultServiceImpl implements IServiceAuthResultService {
 
-    @Resource(name = "redisTemplate")
-    private RedisTemplate<String, String> redisTemplate;
-
     @Autowired
     private IApplyInfoFacade applyInfoFacade;
 
@@ -629,4 +624,13 @@ public class ServiceAuthResultServiceImpl implements IServiceAuthResultService {
         return serviceAuthResultBPO.findAll();
     }
 
+    @Transactional(rollbackFor = Exception.class)
+    @Override
+    public void batchSave(List<ServiceAuthResult> serviceAuthResult) {
+        if (CollectionUtils.isEmpty(serviceAuthResult)) {
+            return;
+        }
+        serviceAuthResult.forEach(e-> serviceAuthResultBPO.save(e));
+    }
+
 }

+ 9 - 0
dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/auth/service/impl/StaffAssignAuthInfoService.java

@@ -1092,6 +1092,15 @@ public class StaffAssignAuthInfoService implements IStaffAssignAuthInfoService {
         return saveStaff(dto);
     }
 
+    @Transactional(rollbackFor = Exception.class)
+    @Override
+    public void batchSave(List<StaffAssignAuthInfo> roleAuths) {
+        if (CollectionUtils.isEmpty(roleAuths)) {
+            return;
+        }
+        roleAuths.forEach(e-> staffAssignAuthInfoBPO.save(e));
+    }
+
     private void setUserContext(AuthUserInfo manageUser) {
         SecurityUser securityUser = new SecurityUser();
         securityUser.setId(manageUser.getId());

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

@@ -124,6 +124,8 @@ public class RoleAuthApplyServiceImpl implements IRoleAuthApplyService {
         String processInstId = flowSubmitRespDTO.getProcessInstId();
 
         // 推送成功之后保存角色授权内容
+        Date startTime = roleAuthApplyDto.getStartTime();
+        Date endTime = roleAuthApplyDto.getEndTime();
         List<ApplyRoleInVo> applyRoleIns = roleAuthApplyDto.getApplyRoleIns();
         AuthUserVo userInfo = roleAuthApplyDto.getUserInfo();
         List<RoleAuthApply> collect = applyRoleIns.stream().map(e -> {
@@ -132,6 +134,8 @@ public class RoleAuthApplyServiceImpl implements IRoleAuthApplyService {
             roleAuthApply.setProcessInstId(processInstId);
             roleAuthApply.setAppId(e.getAppId());
             roleAuthApply.setRoleCode(e.getRoleCode());
+            roleAuthApply.setStartTime(startTime);
+            roleAuthApply.setEndTime(endTime);
             roleAuthApply.setApprovalResult(AuthApplyStatusEnum.APPLYING.getValue());
             return roleAuthApply;
         }).collect(Collectors.toList());

+ 4 - 0
dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/auth/service/impl/zerotrust/ServiceAuthApplyServiceImpl.java

@@ -100,6 +100,8 @@ public class ServiceAuthApplyServiceImpl implements IServiceAuthApplyService {
         String processInstId = flowSubmitRespDTO.getProcessInstId();
 
         // 推送成功之后保存角色授权内容
+        Date startTime = authApplyDto.getStartTime();
+        Date endTime = authApplyDto.getEndTime();
         ApplyInfoVo applyInfoVo = authApplyDto.getApplyInfoVo();
         List<ServiceResourceVo> serviceVos = authApplyDto.getServiceVos();
         List<ServiceAuthApply> collect = serviceVos.stream().map(e -> {
@@ -108,6 +110,8 @@ public class ServiceAuthApplyServiceImpl implements IServiceAuthApplyService {
             authApply.setAppId(applyInfoVo.getId());
             authApply.setServiceId(e.getId());
             authApply.setApprovalResult(AuthApplyStatusEnum.APPLYING.getValue());
+            authApply.setStartTime(startTime);
+            authApply.setEndTime(endTime);
             return authApply;
         }).collect(Collectors.toList());
 

+ 103 - 2
dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/business/impl/zerotrust/RoleAuthCallbackHandler.java

@@ -1,16 +1,24 @@
 package com.dragoninfo.dcuc.auth.business.impl.zerotrust;
 
 import com.dragoninfo.dcuc.auth.auth.dto.zerotrust.approval.ApprovalBaseRespDto;
+import com.dragoninfo.dcuc.auth.auth.entity.RoleInfo;
+import com.dragoninfo.dcuc.auth.auth.entity.StaffAssignAuthInfo;
 import com.dragoninfo.dcuc.auth.auth.entity.zerotrust.RoleAuthApply;
 import com.dragoninfo.dcuc.auth.auth.enumresources.zerotrust.approval.AuthApplyStatusEnum;
+import com.dragoninfo.dcuc.auth.auth.service.IRoleInfoService;
+import com.dragoninfo.dcuc.auth.auth.service.IStaffAssignAuthInfoService;
 import com.dragoninfo.dcuc.auth.auth.service.zerotrust.IRoleAuthApplyService;
 import com.dragoninfo.dcuc.auth.business.zerotrust.IRoleAuthCallbackHandler;
+import com.dragoninfo.dcuc.auth.sub.entity.AuthUserInfo;
+import com.dragoninfo.dcuc.auth.sub.service.IAuthUserInfoService;
 import com.dragonsoft.duceap.commons.util.collections.CollectionUtils;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
-import java.util.List;
+import java.text.SimpleDateFormat;
+import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * @author mazq
@@ -22,6 +30,27 @@ public class RoleAuthCallbackHandler implements IRoleAuthCallbackHandler {
 
     private IRoleAuthApplyService roleAuthApplyService;
 
+    private IStaffAssignAuthInfoService staffAssignAuthInfoService;
+
+    private IRoleInfoService roleInfoService;
+
+    private IAuthUserInfoService userInfoService;
+
+    @Autowired
+    public void setUserInfoService(IAuthUserInfoService userInfoService) {
+        this.userInfoService = userInfoService;
+    }
+
+    @Autowired
+    public void setRoleInfoService(IRoleInfoService roleInfoService) {
+        this.roleInfoService = roleInfoService;
+    }
+
+    @Autowired
+    public void setStaffAssignAuthInfoService(IStaffAssignAuthInfoService staffAssignAuthInfoService) {
+        this.staffAssignAuthInfoService = staffAssignAuthInfoService;
+    }
+
     @Autowired
     public void setRoleAuthApplyService(IRoleAuthApplyService roleAuthApplyService) {
         this.roleAuthApplyService = roleAuthApplyService;
@@ -41,8 +70,80 @@ public class RoleAuthCallbackHandler implements IRoleAuthCallbackHandler {
         if (!AuthApplyStatusEnum.AGREE.getValue().equals(applyStatus)) {
             return new ApprovalBaseRespDto().success();
         }
-        // 角色授权暂时不做处理,只为演示审批风险。
+
+        // 保存角色授权
+        saveRoleAuth(authApplies);
+
         return new ApprovalBaseRespDto().success();
     }
 
+    /**
+     * 保存角色授权申请
+     * @param authApplies
+     */
+    private void saveRoleAuth(List<RoleAuthApply> authApplies) {
+        // 查询申请人员
+        List<String> userIds = authApplies.stream().map(RoleAuthApply::getUserId).distinct().collect(Collectors.toList());
+        List<AuthUserInfo> userInfos = userInfoService.findByIds(userIds);
+        Map<String, AuthUserInfo> userMap = userInfos.stream().collect(Collectors.toMap(AuthUserInfo::getId, e -> e));
+
+        // 查询应用中的角色
+        List<String> appIds = authApplies.stream().map(RoleAuthApply::getAppId).distinct().collect(Collectors.toList());
+        List<RoleInfo> roles = roleInfoService.getRolesByAppIds(appIds);
+        Map<String, Map<String, String>> appRoleMap = roles.stream().collect(Collectors.groupingBy(RoleInfo::getAppId,
+                Collectors.collectingAndThen(Collectors.toList(),
+                        e -> e.stream().collect(Collectors.toMap(RoleInfo::getCode, RoleInfo::getId)))));
+
+        List<StaffAssignAuthInfo> roleAuths = getStaffAssignAuthInfos(authApplies, appRoleMap, userMap);
+        if (CollectionUtils.isNotEmpty(roleAuths)) {
+            staffAssignAuthInfoService.batchSave(roleAuths);
+        }
+    }
+
+    private List<StaffAssignAuthInfo> getStaffAssignAuthInfos(List<RoleAuthApply> authApplies, Map<String, Map<String, String>> appRoleMap,
+                                                              Map<String, AuthUserInfo> userMap) {
+        Date createTime = new Date();
+        // 过滤申请中的但还未审批通过的角色和已过期的申请
+        authApplies = authApplies.stream().filter(e-> {
+            Date endTime = e.getEndTime();
+            if (Objects.nonNull(endTime) && createTime.after(endTime)) {
+                return false;
+            }
+            String appId = e.getAppId();
+            Map<String, String> roleCods = appRoleMap.get(appId);
+            return Objects.nonNull(roleCods) && roleCods.containsKey(e.getRoleCode());
+        }).collect(Collectors.toList());
+
+        if (CollectionUtils.isEmpty(authApplies)) {
+            return Collections.emptyList();
+        }
+        String activeTime = getActiveTime(authApplies);
+
+        return authApplies.stream().map(e -> {
+            StaffAssignAuthInfo authInfo = new StaffAssignAuthInfo();
+            String roleId = appRoleMap.get(e.getAppId()).get(e.getRoleCode());
+            authInfo.setRoleId(roleId);
+            authInfo.setAppId(e.getAppId());
+
+            AuthUserInfo authUserInfo = userMap.get(e.getUserId());
+            authInfo.setStaffId(e.getUserId());
+            authInfo.setStaffOrgId(authUserInfo.getOrgId());
+
+            authInfo.setCreateTime(createTime);
+            authInfo.setActiveTime(activeTime);
+            return authInfo;
+        }).filter(Objects::nonNull).collect(Collectors.toList());
+    }
+
+    private String getActiveTime(List<RoleAuthApply> authApplies) {
+        RoleAuthApply roleAuthApply = authApplies.get(0);
+        Date endTime = roleAuthApply.getEndTime();
+        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        if (Objects.isNull(endTime)) {
+            return "长期";
+        } else {
+            return format.format(endTime);
+        }
+    }
+
 }

+ 105 - 2
dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/business/impl/zerotrust/ServiceAuthCallbackHandler.java

@@ -1,8 +1,15 @@
 package com.dragoninfo.dcuc.auth.business.impl.zerotrust;
 
+import com.dragoninfo.dcuc.app.entity.ApplyInfo;
+import com.dragoninfo.dcuc.app.facade.IApplyInfoFacade;
+import com.dragoninfo.dcuc.app.facade.IServiceResourceFacade;
+import com.dragoninfo.dcuc.app.vo.ServiceResourceVo;
 import com.dragoninfo.dcuc.auth.auth.dto.zerotrust.approval.ApprovalBaseRespDto;
+import com.dragoninfo.dcuc.auth.auth.entity.ServiceAuthResult;
 import com.dragoninfo.dcuc.auth.auth.entity.zerotrust.ServiceAuthApply;
+import com.dragoninfo.dcuc.auth.auth.enumresources.AuthStatusEnum;
 import com.dragoninfo.dcuc.auth.auth.enumresources.zerotrust.approval.AuthApplyStatusEnum;
+import com.dragoninfo.dcuc.auth.auth.service.IServiceAuthResultService;
 import com.dragoninfo.dcuc.auth.auth.service.zerotrust.IServiceAuthApplyService;
 import com.dragoninfo.dcuc.auth.business.zerotrust.IServiceAuthCallbackHandler;
 import com.dragonsoft.duceap.commons.util.collections.CollectionUtils;
@@ -10,7 +17,8 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
-import java.util.List;
+import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * @author mazq
@@ -22,6 +30,27 @@ public class ServiceAuthCallbackHandler implements IServiceAuthCallbackHandler {
 
     private IServiceAuthApplyService serviceAuthApplyService;
 
+    private IServiceResourceFacade serviceResourceFacade;
+
+    private IApplyInfoFacade applyInfoFacade;
+
+    private IServiceAuthResultService serviceAuthResultService;
+
+    @Autowired
+    public void setServiceAuthResultService(IServiceAuthResultService serviceAuthResultService) {
+        this.serviceAuthResultService = serviceAuthResultService;
+    }
+
+    @Autowired
+    public void setServiceResourceFacade(IServiceResourceFacade serviceResourceFacade) {
+        this.serviceResourceFacade = serviceResourceFacade;
+    }
+
+    @Autowired
+    public void setApplyInfoFacade(IApplyInfoFacade applyInfoFacade) {
+        this.applyInfoFacade = applyInfoFacade;
+    }
+
     @Autowired
     public void setServiceAuthApplyService(IServiceAuthApplyService serviceAuthApplyService) {
         this.serviceAuthApplyService = serviceAuthApplyService;
@@ -41,7 +70,81 @@ public class ServiceAuthCallbackHandler implements IServiceAuthCallbackHandler {
         if (!AuthApplyStatusEnum.AGREE.getValue().equals(applyStatus)) {
             return new ApprovalBaseRespDto().success();
         }
-        // 服务授权暂时不做处理,只为演示审批风险。
+
+        // 保存服务授权
+        saveServiceAuth(authApplies);
+
         return new ApprovalBaseRespDto().success();
     }
+
+    private void saveServiceAuth(List<ServiceAuthApply> authApplies) {
+        List<ServiceAuthResult> serviceAuthResult = getServiceAuthResult(authApplies);
+        if (CollectionUtils.isNotEmpty(serviceAuthResult)) {
+            serviceAuthResultService.batchSave(serviceAuthResult);
+        }
+    }
+
+    private List<ServiceAuthResult> getServiceAuthResult(List<ServiceAuthApply> authApplies) {
+        List<String> appIds = authApplies.stream().map(ServiceAuthApply::getAppId).distinct().collect(Collectors.toList());
+        List<String> serviceIds = authApplies.stream().map(ServiceAuthApply::getServiceId).distinct().collect(Collectors.toList());
+        List<ApplyInfo> appInfos = applyInfoFacade.getAppById(appIds);
+        List<ServiceResourceVo> serviceResourceVos = serviceResourceFacade.getServiceByIds(serviceIds);
+        Map<String, ApplyInfo> appMap = appInfos.stream().collect(Collectors.toMap(ApplyInfo::getId, e -> e));
+        Map<String, ServiceResourceVo> serviceMap = serviceResourceVos.stream().collect(Collectors.toMap(ServiceResourceVo::getId, e -> e));
+
+        Date createTime = new Date();
+        authApplies = authApplies.stream().filter(e-> {
+            Date endTime = e.getEndTime();
+            return Objects.isNull(endTime) || createTime.before(endTime);
+        }).collect(Collectors.toList());
+        if (CollectionUtils.isEmpty(authApplies)) {
+            return Collections.emptyList();
+        }
+
+        ServiceAuthApply authApply = authApplies.get(0);
+        String authStatus = getStatus(createTime, authApply.getStartTime(), authApply.getEndTime());
+
+        return authApplies.stream().map(e -> {
+            Date endTime = e.getEndTime();
+            ServiceAuthResult authResult = new ServiceAuthResult();
+            String serviceId = e.getServiceId();
+            String appId = e.getAppId();
+            ServiceResourceVo serviceResourceVo = serviceMap.get(serviceId);
+            authResult.setServiceId(serviceId);
+            authResult.setServiceCode(serviceResourceVo.getServiceCode());
+            authResult.setAppId(appId);
+            authResult.setAppCode(appMap.get(appId).getApplyCode());
+
+            Date startTime = e.getStartTime();
+            authResult.setAuthStatus(authStatus);
+            authResult.setStartTime(startTime);
+            authResult.setEndTime(endTime);
+            authResult.setCreateTime(createTime);
+            authResult.setServiceResourceId(serviceResourceVo.getResourceId());
+
+            return authResult;
+        }).collect(Collectors.toList());
+    }
+
+    private String getStatus(Date createTime, Date startTime, Date endTime) {
+        startTime = Optional.ofNullable(startTime).orElse(createTime);
+        endTime = Optional.ofNullable(endTime).orElse(createTime);
+        if (startTime.before(createTime) && endTime.after(createTime)) {
+            return AuthStatusEnum.START.getValue();
+        }
+        if (startTime.after(createTime)) {
+            return AuthStatusEnum.NOT_START.getValue();
+        }
+        if (startTime.before(createTime)) {
+            return AuthStatusEnum.START.getValue();
+        }
+        if (endTime.before(createTime)) {
+            return AuthStatusEnum.CANCEL.getValue();
+        }
+        if (endTime.after(createTime)) {
+            return AuthStatusEnum.START.getValue();
+        }
+
+        return AuthStatusEnum.START.getValue();
+    }
 }

+ 9 - 5
dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/business/impl/zerotrust/ZeroTrustAuthApplyBusinessImpl.java

@@ -178,7 +178,7 @@ public class ZeroTrustAuthApplyBusinessImpl implements IZeroTrustAuthApplyBusine
         setSecurityUser(appTokenDetail);
 
         // 组装批量申请dto
-        RoleAuthApplyDto applyDto = getRoleAuthApplyDto(tokenUserInfo, applyInfoVo, roles);
+        RoleAuthApplyDto applyDto = getRoleAuthApplyDto(reqVo, tokenUserInfo, applyInfoVo, roles);
 
         ResponseStatus status = roleAuthApplyService.applyAndPushToApproval(applyDto, null);
         if (ResponseUtil.isFail(status)) {
@@ -202,7 +202,7 @@ public class ZeroTrustAuthApplyBusinessImpl implements IZeroTrustAuthApplyBusine
     }
 
     @Override
-    public ZeroTrustDataRespVO<AuthApplyRespVo> serviceAuthApply(@Valid ApiServiceAuthReqVo reqVo) {
+    public ZeroTrustDataRespVO<AuthApplyRespVo> serviceAuthApply(ApiServiceAuthReqVo reqVo) {
         log.info("服务授权申请,应用令牌:{}, 申请内容:{}", reqVo.getAppTokenId(), JSONUtil.toJsonStr(reqVo));
 
         // 校验应用令牌
@@ -232,7 +232,7 @@ public class ZeroTrustAuthApplyBusinessImpl implements IZeroTrustAuthApplyBusine
 
         // 组装批量申请dto
         ApplyInfoVo applyInfoVo = appResult.getContent();
-        ServiceAuthApplyDto applyDto = getServiceAuthApplyDto(applyInfoVo, serviceInfos);
+        ServiceAuthApplyDto applyDto = getServiceAuthApplyDto(reqVo, applyInfoVo, serviceInfos);
 
         ResponseStatus status = serviceAuthApplyService.applyAndPushToApproval(applyDto, null);
         if (ResponseUtil.isFail(status)) {
@@ -242,12 +242,14 @@ public class ZeroTrustAuthApplyBusinessImpl implements IZeroTrustAuthApplyBusine
         return ZeroTrustDataRespVO.success(null);
     }
 
-    private ServiceAuthApplyDto getServiceAuthApplyDto(ApplyInfoVo applyInfoVo, List<ServiceResourceDTO> serviceInfos) {
+    private ServiceAuthApplyDto getServiceAuthApplyDto(ApiServiceAuthReqVo reqVo, ApplyInfoVo applyInfoVo, List<ServiceResourceDTO> serviceInfos) {
         ServiceAuthApplyDto dto = new ServiceAuthApplyDto();
         dto.setApplyInfoVo(applyInfoVo);
         List<ServiceResourceVo> list = DcucBeanUtil.createCopyToObjectList(serviceInfos, ServiceResourceVo.class);
         list.forEach(e -> e.setAppName(applyInfoVo.getApplyName()));
         dto.setServiceVos(list);
+        dto.setStartTime(reqVo.getContents().getStartTime());
+        dto.setEndTime(reqVo.getContents().getEndTime());
         return dto;
     }
 
@@ -308,7 +310,7 @@ public class ZeroTrustAuthApplyBusinessImpl implements IZeroTrustAuthApplyBusine
         return ZeroTrustDataRespVO.resultEnumMessage(ZeroTrustBusinessRespEnum.OPERATE_FAIL, vo);
     }
 
-    private RoleAuthApplyDto getRoleAuthApplyDto(AuthUserVo userVo, ApplyInfoVo applyInfoVo, List<RoleInfo> roleList) {
+    private RoleAuthApplyDto getRoleAuthApplyDto(ApiRoleAuthReqVo reqVo, AuthUserVo userVo, ApplyInfoVo applyInfoVo, List<RoleInfo> roleList) {
         RoleAuthApplyDto applyDto = new RoleAuthApplyDto();
         applyDto.setUserInfo(userVo);
         List<ApplyRoleInVo> collect = roleList.stream().map(r -> {
@@ -321,6 +323,8 @@ public class ZeroTrustAuthApplyBusinessImpl implements IZeroTrustAuthApplyBusine
             return applyVo;
         }).collect(Collectors.toList());
         applyDto.setApplyRoleIns(collect);
+        applyDto.setStartTime(reqVo.getContents().getStartTime());
+        applyDto.setEndTime(reqVo.getContents().getEndTime());
         return applyDto;
 
     }

+ 1 - 1
dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/business/zerotrust/IZeroTrustAuthApplyBusiness.java

@@ -40,5 +40,5 @@ public interface IZeroTrustAuthApplyBusiness {
      * @param reqVo
      * @return
      */
-    ZeroTrustDataRespVO<AuthApplyRespVo> serviceAuthApply(@Valid ApiServiceAuthReqVo reqVo);
+    ZeroTrustDataRespVO<AuthApplyRespVo> serviceAuthApply(ApiServiceAuthReqVo reqVo);
 }