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