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