|
@@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.date.DateTime;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.hutool.core.map.MapUtil;
|
|
|
import cn.hutool.core.util.EnumUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
@@ -267,7 +268,6 @@ public class RelationReportService implements IRelationReportService {
|
|
|
return this.fillRelationProjectCal(objectNode, relationTypeEnum.getGraphCode(), relationTypeEnum.getRelCode(),
|
|
|
graphRelTypeMap, relationDefineMap,relCountMap);
|
|
|
}
|
|
|
-
|
|
|
return new JSONObject();
|
|
|
}
|
|
|
|
|
@@ -537,9 +537,7 @@ public class RelationReportService implements IRelationReportService {
|
|
|
if (StrUtil.isBlank(content)) {
|
|
|
this.createRelationProjectCal(AppContext.getContext().getGroupCode(), AppContext.getContext().getProjectId());
|
|
|
}
|
|
|
- List<JSONObject> parentList = new ArrayList<>();
|
|
|
- // 获取树结构
|
|
|
- this.getGraphRelationProjectTree(parentList, AppContext.getContext().getGroupCode(),
|
|
|
+ List<JSONObject> parentList = getGraphRelationProjectTree(AppContext.getContext().getGroupCode(),
|
|
|
AppContext.getContext().getProjectId(), content);
|
|
|
result.put("content", parentList);
|
|
|
result.put("message", "");
|
|
@@ -711,86 +709,92 @@ public class RelationReportService implements IRelationReportService {
|
|
|
|
|
|
/**
|
|
|
* 获取图类型下的边类型的项目计算关系数据,并形成三级树结构
|
|
|
- *
|
|
|
- * @param parentList
|
|
|
* @param groupCode
|
|
|
* @param projectId
|
|
|
* @param content
|
|
|
*/
|
|
|
- private void getGraphRelationProjectTree(List<JSONObject> parentList, String groupCode, String projectId, String content) {
|
|
|
- //boolean isQuery = StringUtils.isNotBlank(content);
|
|
|
+ private List<JSONObject> getGraphRelationProjectTree(String groupCode, String projectId, String content) {
|
|
|
+ List<JSONObject> resultList = new ArrayList<>();
|
|
|
// 1.获取所有的一级,二级图类型定义
|
|
|
QueryCriteria parentCriteria = new QueryCriteria();
|
|
|
List<GraphDefine> graphDefines = DigitalGraphDefineFacade.query(groupCode, projectId,
|
|
|
AdmCommonConstant.APP_ID, AdmCommonConstant.USER_ID, parentCriteria);
|
|
|
if (CollUtil.isEmpty(graphDefines)){
|
|
|
- return;
|
|
|
+ return resultList;
|
|
|
}
|
|
|
// 2.查询所有的边类型定义
|
|
|
Map<String, RelationDefine> relationDefineMap = queryAllRelationDefineMap(groupCode,projectId);
|
|
|
// 3.查询出对应项目关系计算数据
|
|
|
List<ObjectNode> projectRelList = queryRelationProjectCalsByProjectId(groupCode,projectId,content);
|
|
|
if (CollUtil.isEmpty(projectRelList)){
|
|
|
- return;
|
|
|
+ return resultList;
|
|
|
}
|
|
|
- Map<String,List<JSONObject>> levelMap = new HashMap<>();
|
|
|
+ Map<String, GraphDefine> graphDefineMap = CollUtil.fieldValueMap(graphDefines, "code");
|
|
|
+ Map<String, JSONObject> typeMap = new HashMap<>();
|
|
|
+ Map<String, Map<String, JSONObject>> graphMap = new HashMap<>();
|
|
|
+ Map<String, Map<String, JSONObject>> relMap = new HashMap<>();
|
|
|
Map<String, AdmRelationTypeEnum> graphRelTypeMap = AdmRelationTypeEnum.getGraphRelTypeMap();
|
|
|
Map<String, Integer> relCountMap = queryAllRelationCountMap(groupCode,projectId);
|
|
|
+ // 按关系计算数据循环
|
|
|
for (ObjectNode projectRel : projectRelList) {
|
|
|
if (!projectRel.has("relCode")
|
|
|
|| StrUtil.isBlank(projectRel.get("relCode").asText())){
|
|
|
continue;
|
|
|
}
|
|
|
+ // 准备数据
|
|
|
String relCode = projectRel.get("relCode").asText();
|
|
|
String graphCode = projectRel.get("graphCode").asText();
|
|
|
- if (!graphRelTypeMap.containsKey(graphCode+StrUtil.UNDERLINE+relCode)){
|
|
|
+ GraphDefine graphDefine = graphDefineMap.get(graphCode);
|
|
|
+ if(graphDefine == null) {
|
|
|
continue;
|
|
|
}
|
|
|
- List<JSONObject> sonList = levelMap.getOrDefault(graphCode, new ArrayList<>());
|
|
|
- JSONObject son = this.fillRelationProjectCal(projectRel, graphCode,relCode,graphRelTypeMap,
|
|
|
- relationDefineMap,relCountMap);
|
|
|
- sonList.add(son);
|
|
|
- sonList.sort(Comparator.comparing(b -> b.getString("relationTypeCode")));
|
|
|
- levelMap.put(graphCode,sonList);
|
|
|
- }
|
|
|
- // 3.使用图类型定义的二级标签作为第一级
|
|
|
- List<JSONObject> topList = new ArrayList<>();
|
|
|
- Set<String> categoryIds = new HashSet<>();
|
|
|
- for (GraphDefine graphDefine : graphDefines) {
|
|
|
- GraphParentMes secondCategoryMes = graphDefine.getSecondCategoryMes();
|
|
|
- if (null==secondCategoryMes){
|
|
|
+ // 构建类型
|
|
|
+ GraphParentMes parentGraph = graphDefine.getSecondCategoryMes();
|
|
|
+ if(parentGraph == null) {
|
|
|
continue;
|
|
|
}
|
|
|
- if (!categoryIds.contains(secondCategoryMes.getId())){
|
|
|
- categoryIds.add(secondCategoryMes.getId());
|
|
|
- topList.add(this.transfer(secondCategoryMes));
|
|
|
+ if(!typeMap.containsKey(parentGraph.getId())) {
|
|
|
+ typeMap.put(parentGraph.getId(), transfer(parentGraph));
|
|
|
+ graphMap.put(parentGraph.getId(), new HashMap<>(16));
|
|
|
}
|
|
|
- List<JSONObject> threeLevelList = levelMap.getOrDefault(graphDefine.getCode(), new ArrayList<>());
|
|
|
- if (CollUtil.isEmpty(threeLevelList)){
|
|
|
- continue;
|
|
|
+ // 构建图
|
|
|
+ Map<String, JSONObject> graphs = graphMap.get(parentGraph.getId());
|
|
|
+ if(!graphs.containsKey(graphCode)) {
|
|
|
+ graphs.put(graphCode, transfer(graphDefine));
|
|
|
+ relMap.put(graphCode, new HashMap<>(16));
|
|
|
}
|
|
|
- List<JSONObject> sonList = levelMap.getOrDefault(secondCategoryMes.getId(), new ArrayList<>());
|
|
|
- JSONObject secondLevel = this.transfer(graphDefine);
|
|
|
- secondLevel.put("relationTypeProjectList",threeLevelList);
|
|
|
- sonList.add(secondLevel);
|
|
|
- sonList.sort(Comparator.comparing(b -> b.getString("graphTypeCode")));
|
|
|
- levelMap.put(secondCategoryMes.getId(),sonList);
|
|
|
- }
|
|
|
- if (CollUtil.isEmpty(topList)){
|
|
|
- return;
|
|
|
+ // 构建边
|
|
|
+ Map<String, JSONObject> rels = relMap.get(graphCode);
|
|
|
+ if(!rels.containsKey(relCode)) {
|
|
|
+ rels.put(relCode, fillRelationProjectCal(projectRel, graphCode, relCode, graphRelTypeMap, relationDefineMap, relCountMap));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(MapUtil.isEmpty(relMap)) {
|
|
|
+ return resultList;
|
|
|
}
|
|
|
- for (int i = topList.size() - 1; i >= 0; i--) {
|
|
|
- JSONObject top = topList.get(i);
|
|
|
- List<JSONObject> secondLevelList = levelMap.getOrDefault(top.getString("graphTypeId"), new ArrayList<>());
|
|
|
- if (CollUtil.isEmpty(secondLevelList)){
|
|
|
- topList.remove(i);
|
|
|
+ // 组装&排序
|
|
|
+ resultList = CollUtil.sort(typeMap.values(), Comparator.comparing(b -> b.getIntValue("sort")));
|
|
|
+ for(JSONObject result:resultList) {
|
|
|
+ String typeId = result.getString("graphTypeId");
|
|
|
+ // 处理图
|
|
|
+ Map<String, JSONObject> graphs = graphMap.get(typeId);
|
|
|
+ if(MapUtil.isEmpty(graphs)) {
|
|
|
continue;
|
|
|
}
|
|
|
- top.put("childGraphicTypeList",secondLevelList);
|
|
|
+ List<JSONObject> graphList = CollUtil.sort(graphs.values(), Comparator.comparing(b -> b.getString("graphTypeCode")));
|
|
|
+ result.put("childGraphicTypeList", graphList);
|
|
|
+ // 处理边
|
|
|
+ for(JSONObject graph:graphList) {
|
|
|
+ String graphCode = graph.getString("graphTypeCode");
|
|
|
+ Map<String, JSONObject> rels = relMap.get(graphCode);
|
|
|
+ if(MapUtil.isEmpty(rels)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ List<JSONObject> relList = CollUtil.sort(rels.values(), Comparator.comparing(b -> b.getString("relationTypeCode")));
|
|
|
+ graph.put("relationTypeProjectList", relList);
|
|
|
+ }
|
|
|
}
|
|
|
- // 顶级按sort排序
|
|
|
- topList.sort(Comparator.comparing(b -> b.getIntValue("sort")));
|
|
|
- parentList.addAll(topList);
|
|
|
+ return resultList;
|
|
|
}
|
|
|
|
|
|
/***
|
|
@@ -883,7 +887,6 @@ public class RelationReportService implements IRelationReportService {
|
|
|
|
|
|
/**
|
|
|
* 获取转换后的数据,项目计算数据转换
|
|
|
- *
|
|
|
* @param relationProject :项目对象
|
|
|
* @param relCode :边类型编码
|
|
|
* @param graphRelTypeMap :与旧数据中心的code的映射关系
|
|
@@ -894,7 +897,7 @@ public class RelationReportService implements IRelationReportService {
|
|
|
Map<String, AdmRelationTypeEnum> graphRelTypeMap,
|
|
|
Map<String, RelationDefine> relationDefineMap,Map<String, Integer> relCountMap) {
|
|
|
String key = graphicId + StrUtil.UNDERLINE + relCode;
|
|
|
- AdmRelationTypeEnum typeEnum = graphRelTypeMap.get(key);
|
|
|
+ AdmRelationTypeEnum typeEnum = MapUtil.get(graphRelTypeMap, key, AdmRelationTypeEnum.class);
|
|
|
RelationDefine relationDefine = relationDefineMap.getOrDefault(key,new RelationDefine());
|
|
|
JSONObject result = new JSONObject();
|
|
|
result.put("count", relCountMap.getOrDefault(key,0));
|