|
@@ -16,7 +16,6 @@ import com.dragoninfo.dcuc.auth.auth.enumresources.WokrFlowPermissionTypeEnum;
|
|
|
import com.dragoninfo.dcuc.auth.auth.enumresources.WorkFlowStatusEnum;
|
|
|
import com.dragoninfo.dcuc.auth.auth.enumresources.WorkFlowTypeEnum;
|
|
|
import com.dragoninfo.dcuc.auth.auth.po.ServiceAuthResultPO;
|
|
|
-import com.dragoninfo.dcuc.auth.auth.service.IPermissionUpdateService;
|
|
|
import com.dragoninfo.dcuc.auth.auth.service.IServiceAuthResultService;
|
|
|
import com.dragoninfo.dcuc.auth.auth.vo.ServiceAuthenticationResVO;
|
|
|
import com.dragoninfo.dcuc.auth.util.DcucConstantsUtil;
|
|
@@ -39,6 +38,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -51,7 +51,7 @@ import java.util.stream.Collectors;
|
|
|
public class ServiceAuthResultServiceImpl implements IServiceAuthResultService {
|
|
|
|
|
|
@Resource(name = "redisTemplate")
|
|
|
- private RedisTemplate<String, String> redisTemplate;
|
|
|
+ private RedisTemplate<String, Object> redisTemplate;
|
|
|
|
|
|
@Autowired
|
|
|
private IApplyInfoFacade applyInfoFacade;
|
|
@@ -61,8 +61,6 @@ public class ServiceAuthResultServiceImpl implements IServiceAuthResultService {
|
|
|
|
|
|
@Autowired
|
|
|
IServiceResourceFacade iServiceResourceFacade;
|
|
|
- @Autowired
|
|
|
- private IPermissionUpdateService permissionUpdateService;
|
|
|
|
|
|
@Autowired
|
|
|
private PermssionServiceUpdateEventBus permssionServiceUpdateEventBus;
|
|
@@ -134,7 +132,7 @@ public class ServiceAuthResultServiceImpl implements IServiceAuthResultService {
|
|
|
List<ServiceResource> resources = iServiceResourceFacade.getServiceByServiceCodes(list);
|
|
|
Map<String, ServiceResource> map = 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);
|
|
@@ -151,7 +149,7 @@ 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));
|
|
|
+ .collect(Collectors.toMap(ServiceAuthResult::getServiceCode, item -> item, (old, last) -> last));
|
|
|
Date date = new Date();
|
|
|
if (WorkFlowTypeEnum.SERVICE_AUTH.getValue().equals(serviceAuthFlow.getFlowType())) {
|
|
|
//判断工作单是长期还是自定义
|
|
@@ -170,8 +168,8 @@ public class ServiceAuthResultServiceImpl implements IServiceAuthResultService {
|
|
|
//授权工作单
|
|
|
//新增授权
|
|
|
for (String serviceCode : map.keySet()) {
|
|
|
- //已经存在的更新
|
|
|
- if(allAuthResultMap.keySet().contains(serviceCode)){
|
|
|
+ //已经存在的更新
|
|
|
+ if (allAuthResultMap.keySet().contains(serviceCode)) {
|
|
|
ServiceAuthResult serviceAuthResult = allAuthResultMap.get(serviceCode);
|
|
|
serviceAuthResult.setStartTime(startTime);
|
|
|
serviceAuthResult.setEndTime(endTime);
|
|
@@ -179,7 +177,7 @@ public class ServiceAuthResultServiceImpl implements IServiceAuthResultService {
|
|
|
serviceAuthResult.setUpdateTime(date);
|
|
|
serviceAuthResult.setFlowId(serviceAuthFlow.getFlowId());
|
|
|
serviceAuthResultBPO.update(serviceAuthResult);
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
//不存在的新增
|
|
|
ServiceAuthResult serviceAuthResult = new ServiceAuthResult();
|
|
|
serviceAuthResult.setAppCode(appCode);
|
|
@@ -218,6 +216,7 @@ public class ServiceAuthResultServiceImpl implements IServiceAuthResultService {
|
|
|
|
|
|
/**
|
|
|
* 使用异步事件发送消息
|
|
|
+ *
|
|
|
* @param appCode
|
|
|
* @param addServiceCodes
|
|
|
* @param delServiceCodes
|
|
@@ -225,8 +224,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);
|
|
|
}
|
|
@@ -259,7 +258,7 @@ public class ServiceAuthResultServiceImpl implements IServiceAuthResultService {
|
|
|
list.add(serviceAuthenticationResVO);
|
|
|
}
|
|
|
//鉴权结果存到缓存
|
|
|
- permissionUpdateService.setAuthtionResultToRedis(appCode, list);
|
|
|
+ setAuthtionResultToRedis(appCode, list);
|
|
|
return list;
|
|
|
} else {
|
|
|
return redisValue;
|
|
@@ -268,65 +267,68 @@ public class ServiceAuthResultServiceImpl implements IServiceAuthResultService {
|
|
|
|
|
|
/**
|
|
|
* 保存
|
|
|
+ *
|
|
|
* @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());
|
|
|
+ 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
|
|
|
* @return ResponseDTO
|
|
|
*/
|
|
|
@Override
|
|
|
- public ResponseDTO delServiceAuthResult(String id){
|
|
|
+ public ResponseDTO delServiceAuthResult(String id) {
|
|
|
ServiceAuthResult result = serviceAuthResultBPO.get(id);
|
|
|
result.setDeleted(BooleanEnum.TRUE.value);
|
|
|
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());
|
|
@@ -339,25 +341,24 @@ 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);
|
|
|
});
|
|
@@ -368,49 +369,51 @@ 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());
|
|
|
}
|
|
|
});
|
|
@@ -419,9 +422,23 @@ 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|