|
@@ -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;
|
|
@@ -19,8 +19,6 @@ import com.dragoninfo.dcuc.auth.auth.po.ServiceAuthResultPO;
|
|
|
import com.dragoninfo.dcuc.auth.auth.service.IAuthFlowService;
|
|
|
import com.dragoninfo.dcuc.auth.auth.service.IServiceAuthResultService;
|
|
|
import com.dragoninfo.dcuc.auth.auth.vo.ServiceAuthenticationResVO;
|
|
|
-import com.dragoninfo.dcuc.auth.util.DcucConstantsUtil;
|
|
|
-import com.dragoninfo.dcuc.user.user.facade.IUserInfoFacade;
|
|
|
import com.dragonsoft.duceap.base.entity.http.ResponseDTO;
|
|
|
import com.dragonsoft.duceap.base.enums.BooleanEnum;
|
|
|
import com.dragonsoft.duceap.commons.util.collections.CollectionUtils;
|
|
@@ -40,7 +38,6 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.util.*;
|
|
|
-import java.util.concurrent.TimeUnit;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -53,7 +50,7 @@ import java.util.stream.Collectors;
|
|
|
public class ServiceAuthResultServiceImpl implements IServiceAuthResultService {
|
|
|
|
|
|
@Resource(name = "redisTemplate")
|
|
|
- private RedisTemplate<String, Object> redisTemplate;
|
|
|
+ private RedisTemplate<String, String> redisTemplate;
|
|
|
|
|
|
@Autowired
|
|
|
private IApplyInfoFacade applyInfoFacade;
|
|
@@ -62,7 +59,7 @@ public class ServiceAuthResultServiceImpl implements IServiceAuthResultService {
|
|
|
private ServiceAuthResultBPO serviceAuthResultBPO;
|
|
|
|
|
|
@Autowired
|
|
|
- IServiceResourceFacade iServiceResourceFacade;
|
|
|
+ private IServiceResourceFacade iServiceResourceFacade;
|
|
|
|
|
|
@Autowired
|
|
|
private PermssionServiceUpdateEventBus permssionServiceUpdateEventBus;
|
|
@@ -73,9 +70,6 @@ public class ServiceAuthResultServiceImpl implements IServiceAuthResultService {
|
|
|
@Autowired
|
|
|
private IAuthFlowService authFlowService;
|
|
|
|
|
|
- @Autowired
|
|
|
- private IUserInfoFacade userInfoFacade;
|
|
|
-
|
|
|
@Override
|
|
|
public ServiceAuthResult saveAuthResult(ServiceAuthResult serviceAuthResult) {
|
|
|
serviceAuthResult.setCreateTime(new Date());
|
|
@@ -87,8 +81,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)) {
|
|
@@ -138,14 +132,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));
|
|
|
+ .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;
|
|
|
}
|
|
|
|
|
|
//新增的服务
|
|
@@ -157,76 +152,84 @@ public class ServiceAuthResultServiceImpl implements IServiceAuthResultService {
|
|
|
List<ServiceAuthResult> allAuthResults = getByAppCode(appCode);
|
|
|
Map<String, ServiceAuthResult> allAuthResultMap = allAuthResults
|
|
|
.stream()
|
|
|
- .collect(Collectors.toMap(ServiceAuthResult::getServiceCode, item -> item, (old, last) -> last));
|
|
|
- Date date = new Date();
|
|
|
+ .collect(Collectors.toMap(ServiceAuthResult::getServiceCode, item -> item,(old,last)->last));
|
|
|
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.containsKey(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.containsKey(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
|
|
|
* @param addServiceCodes
|
|
|
* @param delServiceCodes
|
|
@@ -234,8 +237,8 @@ public class ServiceAuthResultServiceImpl implements IServiceAuthResultService {
|
|
|
private void sendPermssionService(String appCode, List<String> addServiceCodes, List<String> delServiceCodes) {
|
|
|
//使用异步事件发送消息
|
|
|
//服务变更消息通知
|
|
|
- AppServiceCodeDto appServiceCodeDto = new AppServiceCodeDto(appCode, addServiceCodes, delServiceCodes);
|
|
|
- List<AppServiceCodeDto> appServiceCodeDtoList = new ArrayList<>();
|
|
|
+ AppServiceCodeDto appServiceCodeDto=new AppServiceCodeDto(appCode,addServiceCodes,delServiceCodes);
|
|
|
+ List<AppServiceCodeDto> appServiceCodeDtoList=new ArrayList<>();
|
|
|
appServiceCodeDtoList.add(appServiceCodeDto);
|
|
|
permssionServiceUpdateEventBus.post(appServiceCodeDtoList);
|
|
|
}
|
|
@@ -243,11 +246,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);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 服务鉴权
|
|
|
*
|
|
@@ -255,90 +263,89 @@ public class ServiceAuthResultServiceImpl implements IServiceAuthResultService {
|
|
|
*/
|
|
|
@Override
|
|
|
public Object serviceAuthentication(String appCode) {
|
|
|
- String redisKey = DcucConstantsUtil.AUTHENTICATION_SPACE + appCode;
|
|
|
- //PermissionUpdateService已存入鉴权结果
|
|
|
- Object redisValue = redisTemplate.opsForValue().get(redisKey);
|
|
|
- //当缓存找不到时候去数据库查询
|
|
|
- if (redisValue == null) {
|
|
|
- List<ServiceAuthResult> results = serviceAuthResultBPO.serviceAuthResultList(appCode);
|
|
|
- List<ServiceAuthenticationResVO> list = new ArrayList<>();
|
|
|
- for (ServiceAuthResult result : results) {
|
|
|
- ServiceAuthenticationResVO serviceAuthenticationResVO = new ServiceAuthenticationResVO();
|
|
|
- serviceAuthenticationResVO.setServiceCode(result.getServiceCode());
|
|
|
- list.add(serviceAuthenticationResVO);
|
|
|
- }
|
|
|
- //鉴权结果存到缓存
|
|
|
- setAuthtionResultToRedis(appCode, list);
|
|
|
- return list;
|
|
|
- } else {
|
|
|
- return redisValue;
|
|
|
+// String redisKey = DcucConstantsUtil.AUTHENTICATION_SPACE + appCode;
|
|
|
+// //PermissionUpdateService已存入鉴权结果
|
|
|
+// Object redisValue = redisTemplate.opsForValue().get(redisKey);
|
|
|
+// //当缓存找不到时候去数据库查询
|
|
|
+// if (redisValue == null) {
|
|
|
+ List<ServiceAuthResult> results = serviceAuthResultBPO.serviceAuthResultList(appCode);
|
|
|
+ List<ServiceAuthenticationResVO> list = new ArrayList<>();
|
|
|
+ for (ServiceAuthResult result : results) {
|
|
|
+ ServiceAuthenticationResVO serviceAuthenticationResVO = new ServiceAuthenticationResVO();
|
|
|
+ serviceAuthenticationResVO.setServiceCode(result.getServiceCode());
|
|
|
+ list.add(serviceAuthenticationResVO);
|
|
|
}
|
|
|
+ //鉴权结果存到缓存
|
|
|
+ // permissionUpdateService.setAuthtionResultToRedis(appCode, list);
|
|
|
+ return list;
|
|
|
+// } else {
|
|
|
+// return redisValue;
|
|
|
+// }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 保存
|
|
|
- *
|
|
|
* @param dto
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
- public ResponseDTO saveServiceAuthResult(ServiceAuthResultDTO dto) {
|
|
|
- try {
|
|
|
-
|
|
|
- ServiceAuthResult result = new ServiceAuthResult();
|
|
|
- BeanUtils.copyProperties(dto, result);
|
|
|
- ApplyInfo app = applyInfoFacade.applyDetail(dto.getAppId());
|
|
|
- Boolean aBoolean = serviceAuthResultBPO.serviceCodeCheck(app.getApplyCode(), dto.getServiceCode(), null);
|
|
|
- if (aBoolean) {
|
|
|
- return ResponseDTO.fail("保存失败,重复的服务授权", new ServiceAuthResult());
|
|
|
- }
|
|
|
- result.setAppId(app.getId());
|
|
|
- result.setAppCode(app.getApplyCode());
|
|
|
- result.setDeleted(BooleanEnum.FALSE.value);
|
|
|
- ServiceResource serviceResource = serviceResourceFacade.detailByCode(dto.getServiceCode());
|
|
|
- result.setServiceId(serviceResource.getId());
|
|
|
- this.saveAuthResult(result);
|
|
|
- List<String> addServiceCodes = new ArrayList<>();
|
|
|
- addServiceCodes.add(result.getServiceCode());
|
|
|
- this.sendPermssionService(result.getAppCode(), addServiceCodes, new ArrayList<>());
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("save ServiceAuthResult error :", e);
|
|
|
- return ResponseDTO.fail("保存失败", new ServiceAuthResult());
|
|
|
- }
|
|
|
- return ResponseDTO.success("保存成功", null);
|
|
|
+ public ResponseDTO saveServiceAuthResult(ServiceAuthResultDTO dto){
|
|
|
+ try{
|
|
|
+
|
|
|
+ ServiceAuthResult result=new ServiceAuthResult();
|
|
|
+ BeanUtils.copyProperties(dto,result);
|
|
|
+ ApplyInfo app = applyInfoFacade.applyDetail(dto.getAppId());
|
|
|
+ Boolean aBoolean = serviceAuthResultBPO.serviceCodeCheck(app.getApplyCode(), dto.getServiceCode(),null);
|
|
|
+ if (aBoolean){
|
|
|
+ return ResponseDTO.fail("保存失败,重复的服务授权",new ServiceAuthResult());
|
|
|
+ }
|
|
|
+ result.setAppId(app.getId());
|
|
|
+ result.setAppCode(app.getApplyCode());
|
|
|
+ result.setDeleted(BooleanEnum.FALSE.value);
|
|
|
+ ServiceResource serviceResource = serviceResourceFacade.detailByCode(dto.getServiceCode());
|
|
|
+ result.setServiceId(serviceResource.getId());
|
|
|
+ result.setAuthStatus("1");
|
|
|
+ this.saveAuthResult(result);
|
|
|
+ List<String> addServiceCodes=new ArrayList<>();
|
|
|
+ addServiceCodes.add(result.getServiceCode());
|
|
|
+ this.sendPermssionService(result.getAppCode(),addServiceCodes,new ArrayList<>());
|
|
|
+ }catch (Exception e){
|
|
|
+ log.error("save ServiceAuthResult error :",e);
|
|
|
+ return ResponseDTO.fail("保存失败",new ServiceAuthResult());
|
|
|
+ }
|
|
|
+ return ResponseDTO.success("保存成功",null);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 删除
|
|
|
- *
|
|
|
- * @param id
|
|
|
+ * @param serviceAuthResultDTO
|
|
|
* @return ResponseDTO
|
|
|
*/
|
|
|
@Override
|
|
|
- public ResponseDTO delServiceAuthResult(String id) {
|
|
|
- ServiceAuthResult result = serviceAuthResultBPO.get(id);
|
|
|
+ public ResponseDTO delServiceAuthResult(ServiceAuthResultDTO serviceAuthResultDTO){
|
|
|
+ ServiceAuthResult result = serviceAuthResultBPO.get(serviceAuthResultDTO.getId());
|
|
|
result.setDeleted(BooleanEnum.TRUE.value);
|
|
|
+ result.setReason(serviceAuthResultDTO.getReason());
|
|
|
serviceAuthResultBPO.update(result);
|
|
|
//发送消息
|
|
|
- List<String> delServiceCodes = new ArrayList<>();
|
|
|
+ List<String> delServiceCodes=new ArrayList<>();
|
|
|
delServiceCodes.add(result.getServiceCode());
|
|
|
- this.sendPermssionService(result.getAppCode(), new ArrayList<>(), delServiceCodes);
|
|
|
- return ResponseDTO.success("删除成功", null);
|
|
|
+ this.sendPermssionService(result.getAppCode(),new ArrayList<>(),delServiceCodes);
|
|
|
+ return ResponseDTO.success("删除成功",null);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 修改
|
|
|
- *
|
|
|
* @param dto
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
- public ResponseDTO updateServiceAuthResult(ServiceAuthResultDTO dto) {
|
|
|
- Boolean aBoolean = serviceAuthResultBPO.serviceCodeCheck(dto.getAppCode(), dto.getServiceCode(), dto.getId());
|
|
|
- if (aBoolean) {
|
|
|
- return ResponseDTO.fail("保存失败,重复的服务授权", new ServiceAuthResult());
|
|
|
+ public ResponseDTO updateServiceAuthResult(ServiceAuthResultDTO dto){
|
|
|
+ Boolean aBoolean = serviceAuthResultBPO.serviceCodeCheck(dto.getAppCode(), dto.getServiceCode(),dto.getId());
|
|
|
+ if (aBoolean){
|
|
|
+ return ResponseDTO.fail("保存失败,重复的服务授权",new ServiceAuthResult());
|
|
|
}
|
|
|
- ServiceAuthResult result = serviceAuthResultBPO.get(dto.getId());
|
|
|
+ ServiceAuthResult result=serviceAuthResultBPO.get(dto.getId());
|
|
|
//BeanUtils.copyProperties(result,dto);
|
|
|
ApplyInfo app = applyInfoFacade.applyDetail(dto.getAppId());
|
|
|
result.setAppId(app.getId());
|
|
@@ -351,24 +358,25 @@ public class ServiceAuthResultServiceImpl implements IServiceAuthResultService {
|
|
|
result.setUpdateTime(new Date());
|
|
|
serviceAuthResultBPO.update(result);
|
|
|
//发送消息 todo 算新增还是修改?
|
|
|
- List<String> addServiceCodes = new ArrayList<>();
|
|
|
+ List<String> addServiceCodes=new ArrayList<>();
|
|
|
addServiceCodes.add(result.getServiceCode());
|
|
|
- this.sendPermssionService(result.getAppCode(), addServiceCodes, new ArrayList<>());
|
|
|
- return ResponseDTO.success("修改成功", null);
|
|
|
+ this.sendPermssionService(result.getAppCode(),addServiceCodes,new ArrayList<>());
|
|
|
+ return ResponseDTO.success("修改成功",null);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ *
|
|
|
* @param searchable
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
- public Page<ServiceAuthResultDTO> serviceAuthResultPage(Searchable searchable) {
|
|
|
+ public Page<ServiceAuthResultDTO> serviceAuthResultPage(Searchable searchable){
|
|
|
searchable.addSearchFilter("deleted", SearchOperator.eq, BooleanEnum.FALSE.getValue());
|
|
|
Page<ServiceAuthResultPO> paging = serviceAuthResultBPO.serviceAuthResultPage(searchable);
|
|
|
- List<ServiceAuthResultDTO> dtos = new ArrayList<>();
|
|
|
- paging.forEach(item -> {
|
|
|
- ServiceAuthResultDTO dto = new ServiceAuthResultDTO();
|
|
|
- BeanUtils.copyProperties(item, dto);
|
|
|
+ List<ServiceAuthResultDTO> dtos=new ArrayList<>();
|
|
|
+ paging.forEach(item->{
|
|
|
+ ServiceAuthResultDTO dto=new ServiceAuthResultDTO();
|
|
|
+ BeanUtils.copyProperties(item,dto);
|
|
|
dto.setAuthStatus(item.getServiceStatus());
|
|
|
dtos.add(dto);
|
|
|
});
|
|
@@ -410,51 +418,49 @@ public class ServiceAuthResultServiceImpl implements IServiceAuthResultService {
|
|
|
|
|
|
@Override
|
|
|
public ServiceAuthResultDTO getDetail(String id) {
|
|
|
- ServiceAuthResult result = serviceAuthResultBPO.get(id);
|
|
|
- ServiceAuthResultDTO dto = new ServiceAuthResultDTO();
|
|
|
- BeanUtils.copyProperties(result, dto);
|
|
|
+ ServiceAuthResult result=serviceAuthResultBPO.get(id);
|
|
|
+ ServiceAuthResultDTO dto=new ServiceAuthResultDTO();
|
|
|
+ BeanUtils.copyProperties(result,dto);
|
|
|
return dto;
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查询结果
|
|
|
- *
|
|
|
* @param appCode
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
- public List<ServiceAuthResult> serviceAuthResultList(String appCode) {
|
|
|
+ public List<ServiceAuthResult> serviceAuthResultList(String appCode){
|
|
|
return this.serviceAuthResultBPO.serviceAuthResultList(appCode);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 发送删除服务的消息
|
|
|
- *
|
|
|
* @param serviceCode
|
|
|
*/
|
|
|
@Override
|
|
|
- public void sendPermssionServiceUpdate(String serviceCode, String type) {
|
|
|
- Map map = new HashMap();
|
|
|
- map.put("serviceCode", serviceCode);
|
|
|
- map.put("deleted", BooleanEnum.FALSE.value);
|
|
|
+ public void sendPermssionServiceUpdate(String serviceCode,String type){
|
|
|
+ Map map=new HashMap();
|
|
|
+ map.put("serviceCode",serviceCode);
|
|
|
+ map.put("deleted",BooleanEnum.FALSE.value);
|
|
|
|
|
|
List<ServiceAuthResult> serviceAuthResultList = this.serviceAuthResultBPO.andsearch(ServiceAuthResult.class, map);
|
|
|
- Set<String> appCodes = new HashSet<>();
|
|
|
+ Set<String> appCodes=new HashSet<>();
|
|
|
//挑出要变更服务涉及到的app并去重
|
|
|
- serviceAuthResultList.forEach(item -> {
|
|
|
+ serviceAuthResultList.forEach(item->{
|
|
|
appCodes.add(item.getAppCode());
|
|
|
});
|
|
|
//拼接数据
|
|
|
- List<AppServiceCodeDto> dtos = new ArrayList<>();
|
|
|
- appCodes.forEach(appCode -> {
|
|
|
- AppServiceCodeDto dto = new AppServiceCodeDto();
|
|
|
- List<String> addServiceCodes = new ArrayList<>();
|
|
|
- List<String> delServiceCodes = new ArrayList<>();
|
|
|
- serviceAuthResultList.forEach(result -> {
|
|
|
- if ("DELETED".equals(type) && appCode.equals(result.getAppCode())) {
|
|
|
+ List<AppServiceCodeDto> dtos=new ArrayList<>();
|
|
|
+ appCodes.forEach(appCode->{
|
|
|
+ AppServiceCodeDto dto=new AppServiceCodeDto();
|
|
|
+ List<String> addServiceCodes=new ArrayList<>();
|
|
|
+ List<String> delServiceCodes=new ArrayList<>();
|
|
|
+ serviceAuthResultList.forEach(result->{
|
|
|
+ if ("DELETED".equals(type)&&appCode.equals(result.getAppCode())){
|
|
|
delServiceCodes.add(result.getServiceCode());
|
|
|
- } else {
|
|
|
+ }else {
|
|
|
addServiceCodes.add(result.getServiceCode());
|
|
|
}
|
|
|
});
|
|
@@ -463,25 +469,11 @@ public class ServiceAuthResultServiceImpl implements IServiceAuthResultService {
|
|
|
dto.setDelServiceCodes(delServiceCodes);
|
|
|
dtos.add(dto);
|
|
|
});
|
|
|
- if (CollectionUtils.isNotEmpty(dtos)) {
|
|
|
+ if (CollectionUtils.isNotEmpty(dtos)){
|
|
|
permssionServiceUpdateEventBus.post(dtos);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 设置鉴权结果到redis
|
|
|
- *
|
|
|
- * @param appCode
|
|
|
- * @param list
|
|
|
- */
|
|
|
- @Override
|
|
|
- public void setAuthtionResultToRedis(String appCode, List<ServiceAuthenticationResVO> list) {
|
|
|
- if (CollectionUtils.isNotEmpty(list)) {
|
|
|
- redisTemplate.opsForValue().set(DcucConstantsUtil.AUTHENTICATION_SPACE + appCode, list, 1, TimeUnit.HOURS);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
@Override
|
|
|
public ServiceAuthResultDTO getDetailByAppAndService(String appCode, String serviceCode) {
|
|
|
ServiceAuthResult authBpo = serviceAuthResultBPO.getDetailByAppAndService(appCode, serviceCode);
|
|
@@ -500,7 +492,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());
|
|
@@ -508,4 +499,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;
|
|
|
+ }
|
|
|
+
|
|
|
}
|