|
@@ -1,34 +1,17 @@
|
|
|
package com.dragoninfo.dcuc.auth.auth.facade;
|
|
|
|
|
|
-import com.alibaba.fastjson.JSON;
|
|
|
-import com.alibaba.fastjson.TypeReference;
|
|
|
-import com.dragoninfo.dcuc.app.enumresources.DataResourceEnum;
|
|
|
-import com.dragoninfo.dcuc.app.facade.IDataResourceFacade;
|
|
|
-import com.dragoninfo.dcuc.app.vo.DataResourceClassifyVo;
|
|
|
-import com.dragoninfo.dcuc.app.vo.DataResourceTreeVo;
|
|
|
import com.dragoninfo.dcuc.auth.auth.business.IDataAuthBusiness;
|
|
|
-import com.dragoninfo.dcuc.auth.auth.dto.ResourceTypeQueryDTO;
|
|
|
import com.dragoninfo.dcuc.auth.auth.dto.data.*;
|
|
|
-import com.dragoninfo.dcuc.auth.auth.service.IBusService;
|
|
|
import com.dragoninfo.dcuc.auth.auth.service.IDataAuthService;
|
|
|
import com.dragoninfo.dcuc.auth.auth.service.impl.DataAuthServiceImpl;
|
|
|
import com.dragoninfo.dcuc.auth.auth.vo.BusResultVO;
|
|
|
import com.dragonsoft.duceap.base.entity.search.SearchDTO;
|
|
|
-import com.dragonsoft.duceap.commons.util.MapUtils;
|
|
|
-import com.dragonsoft.duceap.commons.util.collections.CollectionUtils;
|
|
|
-import com.dragonsoft.duceap.core.search.Searchable;
|
|
|
-import com.dragonsoft.duceap.core.search.enums.SearchOperator;
|
|
|
-import com.dragonsoft.duceap.core.search.filter.Condition;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.util.StopWatch;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
-import java.util.*;
|
|
|
-import java.util.concurrent.CompletableFuture;
|
|
|
-import java.util.stream.Collectors;
|
|
|
+import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* @author mazq
|
|
@@ -39,20 +22,12 @@ import java.util.stream.Collectors;
|
|
|
@RequestMapping(value = "/dcuc/auth/dataAuthFacade")
|
|
|
public class DataAuthFacade implements IDataAuthFacade {
|
|
|
|
|
|
- public static String idJoin = "|";
|
|
|
-
|
|
|
@Autowired
|
|
|
private IDataAuthService dataAuthService;
|
|
|
|
|
|
@Autowired
|
|
|
private IDataAuthBusiness dataAuthBusiness;
|
|
|
|
|
|
- @Autowired
|
|
|
- private IBusService busService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private IDataResourceFacade dataResourceFacade;
|
|
|
-
|
|
|
private static final String[] dataResourceClassifyLable = new String[]{DataAuthServiceImpl.dataLabelOneCodeStr,DataAuthServiceImpl.dataLabelTwoCodeStr,DataAuthServiceImpl.dataLabelThreeCodeStr,DataAuthServiceImpl.dataLabelFourCodeStr,DataAuthServiceImpl.dataLabelFiveCodeStr};
|
|
|
|
|
|
@Override
|
|
@@ -112,155 +87,8 @@ public class DataAuthFacade implements IDataAuthFacade {
|
|
|
|
|
|
@Override
|
|
|
public List<DataResourceDTO> userDataTreeByIdcard(String idcard, String authType) {
|
|
|
- List<DataResourceDTO> resourceDTOS = new ArrayList<>();
|
|
|
- //获取有权限的数据
|
|
|
- List<DataClassifyDTO> dataClassifyDTOS = userDataAuthInfoByIdcard(idcard, authType);
|
|
|
- if(CollectionUtils.isEmpty(dataClassifyDTOS)) {
|
|
|
- return resourceDTOS;
|
|
|
- }
|
|
|
- //获取数据资源树
|
|
|
- Map<String, DataResourceTreeVo> allTreeVosMap = getDataResourceTree(dataClassifyDTOS);
|
|
|
-
|
|
|
- if(MapUtils.isEmpty(allTreeVosMap)){
|
|
|
- return resourceDTOS;
|
|
|
- }
|
|
|
- //筛选有权限的树节点
|
|
|
- List<DataResourceTreeVo> authTreeVoList = filterAuthTreeNode(dataClassifyDTOS, allTreeVosMap);
|
|
|
-
|
|
|
- if(CollectionUtils.isEmpty(authTreeVoList)){
|
|
|
- return resourceDTOS;
|
|
|
- }
|
|
|
-
|
|
|
- List<DataResourceDTO> dataResourceDTOS = new ArrayList<>();
|
|
|
- //将有权限的节点组装成树结构
|
|
|
- List<DataResourceTreeVo> topTreeNodes = authTreeVoList.stream().filter(item -> item.getPId() == null).collect(Collectors.toList());
|
|
|
- List<DataResourceTreeVo> childTreeNodes = authTreeVoList.stream().filter(item -> item.getPId() != null).collect(Collectors.toList());
|
|
|
- for (DataResourceTreeVo topTreeNode : topTreeNodes) {
|
|
|
- DataResourceTreeDTO topTreeDTO = convertToTreeDTO(topTreeNode, childTreeNodes);
|
|
|
- //构建分级分类DTO
|
|
|
- String id = topTreeDTO.getId();
|
|
|
- DataResourceEnum dataEnum = DataResourceEnum.getByCode(id);
|
|
|
- DataResourceDTO dataResourceDTO = new DataResourceDTO(dataEnum.getCode(),dataEnum.getLabel(),dataEnum.getAttrType().getValue());
|
|
|
- dataResourceDTO.setNodes(new ArrayList<DataResourceTreeDTO>(){{add(topTreeDTO);}});
|
|
|
- dataResourceDTOS.add(dataResourceDTO);
|
|
|
- }
|
|
|
- return dataResourceDTOS;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 将TreeVo转为DTO
|
|
|
- * @param topTreeNode 顶级节点
|
|
|
- * @param childTreeNodes 有权限的子节点
|
|
|
- * @return
|
|
|
- */
|
|
|
- private DataResourceTreeDTO convertToTreeDTO(DataResourceTreeVo topTreeNode, List<DataResourceTreeVo> childTreeNodes) {
|
|
|
- DataResourceTreeDTO dto = new DataResourceTreeDTO();
|
|
|
- BeanUtils.copyProperties(topTreeNode,dto,"child");
|
|
|
- String id = topTreeNode.getId();
|
|
|
- List<DataResourceTreeVo> childList = childTreeNodes.stream().filter(item -> item.getPId().equals(id)).collect(Collectors.toList());
|
|
|
- if(CollectionUtils.isEmpty(childList)){
|
|
|
- dto.setChild(null);
|
|
|
- dto.setTreeNode(false);
|
|
|
- }else {
|
|
|
- List<DataResourceTreeDTO> list = new ArrayList<>();
|
|
|
- for (DataResourceTreeVo child : childList) {
|
|
|
- DataResourceTreeDTO childDTO = convertToTreeDTO(child,childTreeNodes);
|
|
|
- list.add(childDTO);
|
|
|
- }
|
|
|
- dto.setChild(list);
|
|
|
- dto.setTreeNode(true);
|
|
|
- }
|
|
|
- return dto;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 过滤有权限的树节点
|
|
|
- * @param dataClassifyDTOS 有权限的分级分类数据
|
|
|
- * @param allTreeVosMap 平铺的树节点
|
|
|
- * @return
|
|
|
- */
|
|
|
- private List<DataResourceTreeVo> filterAuthTreeNode(List<DataClassifyDTO> dataClassifyDTOS, Map<String, DataResourceTreeVo> allTreeVosMap) {
|
|
|
- List<SubDataDTO> authDatas = dataClassifyDTOS.stream()
|
|
|
- .map(item -> item.getTickedDatas())
|
|
|
- .flatMap(List::stream)
|
|
|
- .collect(Collectors.toList());
|
|
|
- Set<String> dataIds = authDatas.stream()
|
|
|
- .map(item -> item.getClassifyCode() + idJoin + item.getDataId())
|
|
|
- .collect(Collectors.toSet());
|
|
|
- Set<String> authDataIds = new HashSet<>();
|
|
|
- dataIds.stream().forEach(id->{
|
|
|
- authDataIds.add(id);
|
|
|
- String dataId = id;
|
|
|
- int index;
|
|
|
- while ((index = dataId.lastIndexOf(idJoin)) != -1){
|
|
|
- authDataIds.add(dataId = dataId.substring(0, index));
|
|
|
- }
|
|
|
- });
|
|
|
- //过滤有权限的树节点
|
|
|
- return allTreeVosMap.entrySet().stream()
|
|
|
- .filter(item -> authDataIds.contains(item.getKey()))
|
|
|
- .collect(Collectors.mapping(Map.Entry::getValue, Collectors.toList()));
|
|
|
+ return dataAuthBusiness.userDataTreeByIdcard(idcard, authType);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 获取所有数据资源树
|
|
|
- * @param dataClassifyDTOS 有权限的分级分类数据
|
|
|
- * @return 平铺的树节点
|
|
|
- */
|
|
|
- private Map<String, DataResourceTreeVo> getDataResourceTree(List<DataClassifyDTO> dataClassifyDTOS) {
|
|
|
- Set<String> attrTypeSet = dataClassifyDTOS
|
|
|
- .stream()
|
|
|
- .map(dataClassifyDTO -> dataClassifyDTO.getAttrType())
|
|
|
- .collect(Collectors.toSet());
|
|
|
- StopWatch stopWatch = new StopWatch();
|
|
|
- stopWatch.start("get data resource tree");
|
|
|
- //所有数据资源Map
|
|
|
- Map<String, DataResourceTreeVo> allTreeVosMap = new HashMap<>();
|
|
|
- List<CompletableFuture<List<DataResourceTreeVo>>> futureList = new ArrayList<>();
|
|
|
-
|
|
|
- for (String attrType : attrTypeSet) {
|
|
|
- //future多线程任务
|
|
|
- //将树结构平铺成Map
|
|
|
- //id唯一
|
|
|
- CompletableFuture<List<DataResourceTreeVo>> cf = CompletableFuture.supplyAsync(()->{
|
|
|
- List<DataResourceClassifyVo> dataResource = dataResourceFacade.getAllDataResourceTree(attrType);
|
|
|
- List<DataResourceTreeVo> topTreeVos = dataResource.stream()
|
|
|
- .map(item -> item.getNodes())
|
|
|
- .flatMap(List::stream).collect(Collectors.toList());
|
|
|
- return topTreeVos;
|
|
|
- });
|
|
|
- futureList.add(cf);
|
|
|
- }
|
|
|
- List<DataResourceTreeVo> result = CompletableFuture
|
|
|
- .allOf(futureList.toArray(new CompletableFuture[futureList.size()]))
|
|
|
- .thenApply(e -> futureList.stream().map(CompletableFuture::join).flatMap(List::stream).collect(Collectors.toList()))
|
|
|
- .join();
|
|
|
- convertTreeToMap(result,allTreeVosMap);
|
|
|
- stopWatch.stop();
|
|
|
- log.info("get data resource tree cost time:{}",stopWatch.getTotalTimeMillis());
|
|
|
- return allTreeVosMap;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 将树结构平铺成Map
|
|
|
- * id唯一 key
|
|
|
- * @param topTreeVos 顶级树节点
|
|
|
- * @param allTreeVosMap
|
|
|
- * @return
|
|
|
- */
|
|
|
- private void convertTreeToMap(List<DataResourceTreeVo> topTreeVos, Map<String, DataResourceTreeVo> allTreeVosMap) {
|
|
|
- for (DataResourceTreeVo topTreeVo : topTreeVos) {
|
|
|
- String id = topTreeVo.getId();
|
|
|
- allTreeVosMap.put(id, topTreeVo);
|
|
|
- List<DataResourceTreeVo> child = topTreeVo.getChild();
|
|
|
- if(CollectionUtils.isNotEmpty(child)){
|
|
|
- convertTreeToMap(child, allTreeVosMap);
|
|
|
- //将子级设置为null
|
|
|
- topTreeVo.setChild(null);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
|
|
|
}
|