|
@@ -2,11 +2,16 @@ package com.persagy.proxy.adm.service.impl;
|
|
|
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.ConcurrentLinkedQueue;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
+import com.persagy.dmp.basic.dto.GraphParentMes;
|
|
|
import com.persagy.dmp.common.context.AppContext;
|
|
|
+import com.persagy.dmp.common.utils.JsonHelper;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -331,7 +336,6 @@ public class RelationReportService implements IRelationReportService {
|
|
|
String projectId, RelationDefine relationDefine,
|
|
|
String zoneType) throws JsonProcessingException {
|
|
|
ObjectNode objectNode = objectMapper.createObjectNode();
|
|
|
- // 缺少业务分区类型
|
|
|
objectNode.put("groupCode", groupCode);
|
|
|
objectNode.put("projectId", projectId);
|
|
|
objectNode.put("id", IdWorker.getIdStr());
|
|
@@ -346,7 +350,7 @@ public class RelationReportService implements IRelationReportService {
|
|
|
objectNode.put("systemType", relationDefine.getSystemType()); // 风系统1,水系统0
|
|
|
objectNode.put("computeVersion", 0); // 计算版本
|
|
|
objectNode.put("mepSystemType", CollUtil.isNotEmpty(relationDefine.getMepSystemType())
|
|
|
- ?objectMapper.writeValueAsString(relationDefine.getMepSystemType()):null); // 机电系统类型
|
|
|
+ ? objectMapper.valueToTree(relationDefine.getMepSystemType()) :objectMapper.createArrayNode()); // 机电系统类型
|
|
|
objectNode.put("creator", AdmCommonConstant.USER_ID); // 创建人
|
|
|
objectNode.put("modifier", AdmCommonConstant.USER_ID); // 最后修改人
|
|
|
return objectNode;
|
|
@@ -362,7 +366,7 @@ public class RelationReportService implements IRelationReportService {
|
|
|
if (StrUtil.isBlank(content)) {
|
|
|
this.createRelationProjectCal(AppContext.getContext().getGroupCode(), AppContext.getContext().getProjectId());
|
|
|
}
|
|
|
- List<JSONObject> parentList = new ArrayList<JSONObject>();
|
|
|
+ List<JSONObject> parentList = new ArrayList<>();
|
|
|
// 获取树结构
|
|
|
this.getGraphRelationProjectTree(parentList, AppContext.getContext().getGroupCode(),
|
|
|
AppContext.getContext().getProjectId(), content);
|
|
@@ -385,61 +389,106 @@ public class RelationReportService implements IRelationReportService {
|
|
|
*/
|
|
|
private void getGraphRelationProjectTree(List<JSONObject> parentList, String groupCode, String projectId, String content) {
|
|
|
boolean isQuery = StringUtils.isNotBlank(content);
|
|
|
- // 获取所有的一级图类型定义
|
|
|
+ // 1.获取所有的一级,二级图类型定义
|
|
|
QueryCriteria parentCriteria = new QueryCriteria();
|
|
|
- List<GraphDefine> topList = DigitalGraphDefineFacade.query(groupCode, projectId, AdmCommonConstant.APP_ID, AdmCommonConstant.USER_ID, parentCriteria);
|
|
|
- for (int i = topList.size() - 1; i >= 0; i--) {
|
|
|
- // 获取所有的二级图类型定义
|
|
|
- QueryCriteria childCriteria = new QueryCriteria();
|
|
|
- List<GraphDefine> childList = DigitalGraphDefineFacade.query(groupCode, projectId, AdmCommonConstant.APP_ID, AdmCommonConstant.USER_ID, childCriteria);
|
|
|
- if (CollectionUtil.isEmpty(childList)) {
|
|
|
- if (isQuery) {
|
|
|
- topList.remove(i); //移除
|
|
|
- }
|
|
|
+ List<GraphDefine> graphDefines = DigitalGraphDefineFacade.query(groupCode, projectId,
|
|
|
+ AdmCommonConstant.APP_ID, AdmCommonConstant.USER_ID, parentCriteria);
|
|
|
+ if (CollUtil.isEmpty(graphDefines)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 2.查询所有的边类型定义
|
|
|
+ List<RelationDefine> relationDefines = DigitalRelationDefineFacade.query(groupCode, projectId,
|
|
|
+ AdmCommonConstant.APP_ID, AdmCommonConstant.USER_ID, parentCriteria);
|
|
|
+ if (CollUtil.isEmpty(relationDefines)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Map<String, RelationDefine> relationDefineMap = relationDefines.stream()
|
|
|
+ .collect(Collectors.toMap(relationDefine ->
|
|
|
+ relationDefine.getGraphCode() + StrUtil.UNDERLINE + relationDefine.getCode(),
|
|
|
+ relationDefine -> relationDefine, (k1, k2) -> k1));
|
|
|
+ // 3.查询出对应项目关系计算数据
|
|
|
+ QueryCriteria projectCriteria = new QueryCriteria();
|
|
|
+ ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
|
|
|
+ ObjectNode criteria = objectMapper.createObjectNode();
|
|
|
+ criteria.put("projectId", projectId);
|
|
|
+ if (isQuery) {
|
|
|
+ ObjectNode condition = objectMapper.createObjectNode();
|
|
|
+ condition.put("$like", content);
|
|
|
+ criteria.putPOJO("name", condition); // 模糊查询
|
|
|
+ }
|
|
|
+ projectCriteria.setCriteria(criteria);
|
|
|
+ projectCriteria.setOrders(Collections.singletonList(OrderItem.asc("relCode")));
|
|
|
+ List<ObjectNode> projectRelList = DigitalRelationProjectCalFacade.query(groupCode, projectId, AdmCommonConstant.APP_ID, AdmCommonConstant.USER_ID, projectCriteria);
|
|
|
+ if (CollUtil.isEmpty(projectRelList)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Map<String,List<JSONObject>> levelMap = new HashMap<>();
|
|
|
+ Map<String, AdmRelationTypeEnum> graphRelTypeMap = AdmRelationTypeEnum.getGraphRelTypeMap();
|
|
|
+ for (ObjectNode projectRel : projectRelList) {
|
|
|
+ if (!projectRel.has("relCode")
|
|
|
+ || StrUtil.isBlank(projectRel.get("relCode").asText())){
|
|
|
continue;
|
|
|
}
|
|
|
-
|
|
|
- GraphDefine topGraph = topList.get(i);
|
|
|
- JSONObject parent = this.transfer(topGraph);
|
|
|
- // 二级数据封装
|
|
|
- for (int j = childList.size() - 1; j >= 0; j--) {
|
|
|
- GraphDefine childGraph = topList.get(i);
|
|
|
- JSONObject child = this.transfer(childGraph);
|
|
|
- // 查询出对应项目关系计算数据
|
|
|
- QueryCriteria projectCriteria = new QueryCriteria();
|
|
|
- ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
|
|
|
- ObjectNode criteria = objectMapper.createObjectNode();
|
|
|
- criteria.put("projectId", projectId);
|
|
|
- if (isQuery) {
|
|
|
- ObjectNode condition = objectMapper.createObjectNode();
|
|
|
- condition.put("$like", content);
|
|
|
- criteria.putPOJO("name", condition); // 模糊查询
|
|
|
- }
|
|
|
- projectCriteria.setCriteria(criteria);
|
|
|
- projectCriteria.setOrders(Collections.singletonList(OrderItem.asc("relCode")));
|
|
|
- List<ObjectNode> projectList = DigitalRelationProjectCalFacade.query(groupCode, projectId, AdmCommonConstant.APP_ID, AdmCommonConstant.USER_ID, projectCriteria);
|
|
|
- if (CollectionUtil.isEmpty(projectList)) {
|
|
|
- if (isQuery) {
|
|
|
- childList.remove(i); //移除
|
|
|
- }
|
|
|
- continue;
|
|
|
- }
|
|
|
- // 三级数据封装
|
|
|
- for (ObjectNode objectNode : projectList) {
|
|
|
- this.transfer(objectNode, childGraph.getId());
|
|
|
- }
|
|
|
- child.put("relationTypeProjectList", projectList);
|
|
|
+ String relCode = projectRel.get("relCode").asText();
|
|
|
+ String graphCode = projectRel.get("graphCode").asText();
|
|
|
+ if (!graphRelTypeMap.containsKey(graphCode+StrUtil.UNDERLINE+relCode)){
|
|
|
+ continue;
|
|
|
}
|
|
|
- // 再判断一次,防止当二级有数据但被清除了的情况下,一级还会存在
|
|
|
- if (isQuery && CollectionUtil.isEmpty(childList)) {
|
|
|
- childList.remove(i); //移除
|
|
|
+ List<JSONObject> sonList = levelMap.getOrDefault(graphCode, new ArrayList<>());
|
|
|
+ JSONObject son = this.transfer(projectRel, graphCode,relCode,graphRelTypeMap,relationDefineMap);
|
|
|
+ sonList.add(son);
|
|
|
+ sonList.sort(Comparator.comparing(b -> b.getString("relationTypeCode")));
|
|
|
+ levelMap.put(graphCode,sonList);
|
|
|
+ }
|
|
|
+ // 3.使用图类型定义的二级标签作为第一级
|
|
|
+ List<JSONObject> topList = new ArrayList<>();
|
|
|
+ for (GraphDefine graphDefine : graphDefines) {
|
|
|
+ GraphParentMes secondCategoryMes = graphDefine.getSecondCategoryMes();
|
|
|
+ if (null==secondCategoryMes){
|
|
|
continue;
|
|
|
}
|
|
|
- parent.put("childGraphicTypeList", childList);
|
|
|
- parentList.add(parent);
|
|
|
+ if (!levelMap.containsKey(secondCategoryMes.getId())){
|
|
|
+ topList.add(this.transfer(secondCategoryMes));
|
|
|
+ }
|
|
|
+ List<JSONObject> sonList = levelMap.getOrDefault(secondCategoryMes.getId(), new ArrayList<>());
|
|
|
+ JSONObject secondLevel = this.transfer(graphDefine);
|
|
|
+ secondLevel.put("relationTypeProjectList",levelMap.getOrDefault(graphDefine.getCode(),new ArrayList<>()));
|
|
|
+ sonList.add(secondLevel);
|
|
|
+ sonList.sort(Comparator.comparing(b -> b.getString("graphTypeCode")));
|
|
|
+ levelMap.put(secondCategoryMes.getId(),sonList);
|
|
|
+ }
|
|
|
+ if (CollUtil.isEmpty(topList)){
|
|
|
+ return;
|
|
|
}
|
|
|
+ for (JSONObject top : topList) {
|
|
|
+ top.put("childGraphicTypeList",levelMap.getOrDefault(top.getString("graphTypeId"),new ArrayList<>()));
|
|
|
+ }
|
|
|
+ // 顶级按sort排序
|
|
|
+ topList.sort(Comparator.comparing(b -> b.getIntValue("sort")));
|
|
|
+ parentList.addAll(topList);
|
|
|
}
|
|
|
-
|
|
|
+ /***
|
|
|
+ * Description: 创建一级返回数据
|
|
|
+ * @param graphParentMes : 一级信息对象
|
|
|
+ * @return : com.alibaba.fastjson.JSONObject
|
|
|
+ * @author : lijie
|
|
|
+ * @date :2021/10/14 20:56
|
|
|
+ * Update By lijie 2021/10/14 20:56
|
|
|
+ */
|
|
|
+ private JSONObject transfer(GraphParentMes graphParentMes) {
|
|
|
+ JSONObject top = new JSONObject();
|
|
|
+ top.put("sort", graphParentMes.getSort());
|
|
|
+ top.put("note", "");
|
|
|
+ top.put("statistics", new JSONObject());
|
|
|
+ top.put("graphTypeName", graphParentMes.getName());
|
|
|
+ top.put("graphTypeId", graphParentMes.getId());
|
|
|
+ top.put("graphTypeCode", graphParentMes.getCode());
|
|
|
+ top.put("code", graphParentMes.getCode());
|
|
|
+ top.put("lastUpdate", DateUtil.format(new Date(),"yyyy-MM-dd HH:mm:ss"));
|
|
|
+ top.put("createTime", DateUtil.format(new Date(),"yyyy-MM-dd HH:mm:ss"));
|
|
|
+ return top;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 获取转换后的数据,图类型数据转换
|
|
|
*
|
|
@@ -448,12 +497,13 @@ public class RelationReportService implements IRelationReportService {
|
|
|
*/
|
|
|
private JSONObject transfer(GraphDefine graphDefine) {
|
|
|
JSONObject top = new JSONObject();
|
|
|
- top.put("sort", 1);
|
|
|
+ top.put("sort", 10);
|
|
|
top.put("note", "");
|
|
|
- top.put("statistics", Lists.newArrayList());
|
|
|
+ top.put("statistics", new JSONObject());
|
|
|
top.put("graphTypeName", graphDefine.getName());
|
|
|
top.put("graphTypeId", graphDefine.getId());
|
|
|
top.put("graphTypeCode", graphDefine.getCode());
|
|
|
+ top.put("code", graphDefine.getCode());
|
|
|
top.put("lastUpdate", graphDefine.getModifiedTime() == null ? null : graphDefine.getModifiedTime().toString(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
|
|
top.put("createTime", graphDefine.getCreationTime() == null ? null : graphDefine.getCreationTime().toString(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
|
|
return top;
|
|
@@ -462,23 +512,42 @@ public class RelationReportService implements IRelationReportService {
|
|
|
/**
|
|
|
* 获取转换后的数据,项目计算数据转换
|
|
|
*
|
|
|
- * @param relationProject
|
|
|
+ * @param relationProject :项目对象
|
|
|
+ * @param relCode :边类型编码
|
|
|
+ * @param graphRelTypeMap :与旧数据中心的code的映射关系
|
|
|
+ * @param relationDefineMap
|
|
|
* @return
|
|
|
*/
|
|
|
- private void transfer(ObjectNode relationProject, String graphicId) {
|
|
|
- String relCode = relationProject.get("relCode") == null ? null : relationProject.get("relCode").asText();
|
|
|
-
|
|
|
- relationProject.put("graphicId", graphicId);
|
|
|
- relationProject.putPOJO("statistics", Lists.newArrayList());
|
|
|
- relationProject.put("automatic", "1".equals(relationProject.get("automaticFlag") == null ? null : relationProject.get("automaticFlag").asText()));
|
|
|
- relationProject.put("source", "1".equals(relationProject.get("sourceFlag") == null ? null : relationProject.get("sourceFlag").asText()));
|
|
|
- relationProject.put("conneObject", ObjTypeMapping.getConneObject(relCode));
|
|
|
+ private JSONObject transfer(ObjectNode relationProject, String graphicId, String relCode,
|
|
|
+ Map<String, AdmRelationTypeEnum> graphRelTypeMap,
|
|
|
+ Map<String, RelationDefine> relationDefineMap) {
|
|
|
+ String key = graphicId + StrUtil.UNDERLINE + relCode;
|
|
|
+ AdmRelationTypeEnum typeEnum = graphRelTypeMap.get(key);
|
|
|
+ RelationDefine relationDefine = relationDefineMap.getOrDefault(key,new RelationDefine());
|
|
|
+ JSONObject result = new JSONObject();
|
|
|
+ result.put("graphicId", graphicId);
|
|
|
+ result.put("computationalState",relationProject.has("computationalState")?relationProject.get("computationalState").asText():null);
|
|
|
+ result.put("id",relationProject.has("id")?relationProject.get("id").asText():null);
|
|
|
+ result.put("manual",relationProject.has("manual")?relationProject.get("manual").asText():null);
|
|
|
+ result.put("projectId",relationProject.has("projectId")?relationProject.get("projectId").asText():null);
|
|
|
+ result.put("relationType",typeEnum.getRelationType());
|
|
|
+ result.put("relManualType",typeEnum.getRelationType());
|
|
|
+ result.put("relationTypeCode",relationProject.has("relCode")?relationProject.get("relCode").asText():null);
|
|
|
+ result.put("code", relationProject.has("relCode")?relationProject.get("relCode").asText():null);
|
|
|
+ result.put("relationTypeName",relationProject.has("relCodeName")?relationProject.get("relCodeName").asText():null);
|
|
|
+ result.put("statistics", new JSONObject());
|
|
|
+ result.put("automatic", relationProject.has("automaticFlag") && relationProject.get("automaticFlag").asBoolean());
|
|
|
+ result.put("source", relationProject.has("sourceFlag") && relationProject.get("sourceFlag").asBoolean());
|
|
|
+ result.put("conneObject", relationDefine.getTargetObjs());
|
|
|
|
|
|
Long modifiedTime = relationProject.get("modifiedTime") == null ? null : relationProject.get("modifiedTime").asLong();
|
|
|
Long creationTime = relationProject.get("creationTime") == null ? null : relationProject.get("creationTime").asLong();
|
|
|
-
|
|
|
- relationProject.put("lastUpdate", modifiedTime == null ? null : new DateTime(modifiedTime).toString());
|
|
|
- relationProject.put("createTime", creationTime == null ? null : new DateTime(creationTime).toString());
|
|
|
+
|
|
|
+ result.put("lastUpdate", modifiedTime == null ? null : new DateTime(modifiedTime).toString());
|
|
|
+ result.put("createTime", creationTime == null ? null : new DateTime(creationTime).toString());
|
|
|
+ result.put("mainObject", relationDefine.getFromObjType());
|
|
|
+ result.put("fromObject", relationDefine.getToObjType());
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
}
|