|
@@ -1,12 +1,12 @@
|
|
|
package com.persagy.proxy.adm.service.impl;
|
|
|
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Set;
|
|
|
+import java.util.*;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
+import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
+import com.persagy.dmp.common.context.AppContext;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -123,7 +123,7 @@ public class RelationReportService implements IRelationReportService {
|
|
|
objectNode.put("conneObject", relationDefine.getTargetObjs());
|
|
|
objectNode.put("relationTypeCode", relationDefine.getCode());
|
|
|
objectNode.put("relationTypeName", relationDefine.getName());
|
|
|
- objectNode.put("automatic", (null == relationDefine.getAutomaticFlag() || 0 == relationDefine.getAutomaticFlag()) ? false : true);
|
|
|
+ objectNode.put("automatic", (null == relationDefine.getAutomaticFlag() || relationDefine.getAutomaticFlag()) ? false : true);
|
|
|
}
|
|
|
|
|
|
String prefix = ObjTypeMapping.getRelCodePrefix(relationTypeEnum.getRelCode());
|
|
@@ -266,82 +266,112 @@ public class RelationReportService implements IRelationReportService {
|
|
|
List<ObjectRelation> objectRelations = DigitalRelationFacade.query(groupCode, projectId, AdmCommonConstant.APP_ID, AdmCommonConstant.USER_ID, queryCriteria);
|
|
|
return CollectionUtil.isEmpty(objectRelations) ? Lists.newArrayList() : objectRelations;
|
|
|
}
|
|
|
-
|
|
|
+ /**
|
|
|
+ * 初始化项目关系计算数据
|
|
|
+ *
|
|
|
+ * @param groupCode: 集团编码
|
|
|
+ * @param projectId: 项目id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@Override
|
|
|
- public boolean createRelationProjectCal(String groupCode, String projectId) {
|
|
|
+ public boolean createRelationProjectCal(String groupCode, String projectId) throws JsonProcessingException {
|
|
|
groupCode = StrUtil.isBlank(groupCode) ? defaultCode : groupCode;
|
|
|
-
|
|
|
- // 验证是否已经添加过
|
|
|
+ // 1.验证是否已经添加过
|
|
|
QueryCriteria queryCriteria = new QueryCriteria();
|
|
|
queryCriteria.setOnlyCount(true);
|
|
|
- CommonResult<List<ObjectNode>> prototype = DigitalRelationProjectCalFacade.queryPrototype(groupCode, projectId, AdmCommonConstant.APP_ID, AdmCommonConstant.USER_ID, queryCriteria);
|
|
|
+ CommonResult<List<ObjectNode>> prototype = DigitalRelationProjectCalFacade.queryPrototype(groupCode, projectId,
|
|
|
+ AdmCommonConstant.APP_ID, AdmCommonConstant.USER_ID, queryCriteria);
|
|
|
if (prototype != null && prototype.getCount() != null && prototype.getCount() > 0) {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
- // 获取所有的边类型
|
|
|
+ // 2.获取所有的边类型
|
|
|
QueryCriteria criteria = new QueryCriteria();
|
|
|
- List<RelationDefine> list = DigitalRelationDefineFacade.query(groupCode, projectId, AdmCommonConstant.APP_ID, AdmCommonConstant.USER_ID, criteria);
|
|
|
+ List<RelationDefine> list = DigitalRelationDefineFacade.query(groupCode, projectId,
|
|
|
+ AdmCommonConstant.APP_ID, AdmCommonConstant.USER_ID, criteria);
|
|
|
if (CollectionUtil.isEmpty(list)) {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
- // 组装关系计算数据
|
|
|
+ // 3.组装关系计算数据
|
|
|
List<ObjectNode> nodes = new ArrayList<ObjectNode>();
|
|
|
ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
|
|
|
for (RelationDefine relationDefine : list) {
|
|
|
- ObjectNode objectNode = objectMapper.createObjectNode();
|
|
|
-
|
|
|
- String key = relationDefine.getGraphCode() + AdmCommonConstant.UNDERLINE + relationDefine.getCode();
|
|
|
- AdmRelationTypeEnum typeEnum = AdmCommonConstant.GRAPH_RELATION_TYPE_MAP.get(key);
|
|
|
-
|
|
|
- // 缺少业务分区类型
|
|
|
-
|
|
|
- objectNode.put("projectId", projectId);
|
|
|
- objectNode.put("id", IdUtil.fastSimpleUUID());
|
|
|
- objectNode.put("graphCode", relationDefine.getGraphCode());
|
|
|
- objectNode.put("name", relationDefine.getName());
|
|
|
- objectNode.put("relCode", relationDefine.getCode());
|
|
|
- objectNode.put("sourceFlag", typeEnum == null ? null : typeEnum.getSourceFlag()); // 是否需要配置源末端
|
|
|
- objectNode.put("automaticFlag", relationDefine.getAutomaticFlag()); // 是否自动计算类型
|
|
|
- objectNode.put("manual", typeEnum == null ? null : typeEnum.getManualFlag()); // 手动计算类型 1 禁用 2提示引导 3手动维护
|
|
|
- //objectNode.put("computingTime", relationDefine.getGraphCode()); // 最后一次自动计算时间
|
|
|
- objectNode.put("computationalState", 1); // 计算状态 1初始状态 2需要计算 3计算中 4等待中 5计算失败(如果处于计算中状态,则不再次调用)
|
|
|
- //objectNode.put("zoneType", relationDefine.getGraphCode()); // 业务分区类型
|
|
|
- objectNode.put("systemType", typeEnum == null ? null : typeEnum.getSystemType()); // 风系统1,水系统0
|
|
|
- objectNode.put("relManualType", typeEnum == null ? null : typeEnum.getRelationType()); // 手动计算关系类型
|
|
|
- //objectNode.put("computeVersion", relationDefine.getGraphCode()); // 计算版本
|
|
|
- objectNode.put("creator", AdmCommonConstant.USER_ID); // 创建人
|
|
|
- objectNode.put("modifier", AdmCommonConstant.USER_ID); // 最后修改人
|
|
|
- //objectNode.put("valid", relationDefine.getGraphCode()); // 合法标识
|
|
|
-
|
|
|
- nodes.add(objectNode);
|
|
|
+ // 3.1 判断是否需要加入项目
|
|
|
+ if (null==relationDefine.getCalFlag()
|
|
|
+ || !relationDefine.getCalFlag()){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ // 3.2 判断zoneTypes是否为多个,如果多个则根据zoneType创建
|
|
|
+ if (CollUtil.isNotEmpty(relationDefine.getZoneTypes())){
|
|
|
+ for (String zoneType : relationDefine.getZoneTypes()) {
|
|
|
+ nodes.add(createRelationProjectCalInternal(objectMapper,groupCode,projectId,relationDefine,zoneType));
|
|
|
+ }
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ // 3.3 如果没有分区则直接创建一个
|
|
|
+ nodes.add(createRelationProjectCalInternal(objectMapper,groupCode,projectId,relationDefine,null));
|
|
|
}
|
|
|
-
|
|
|
- List<ObjectRelationProjectCal> result = DigitalRelationProjectCalFacade.create(groupCode, projectId, AdmCommonConstant.APP_ID, AdmCommonConstant.USER_ID, nodes);
|
|
|
+ List<ObjectRelationProjectCal> result = DigitalRelationProjectCalFacade.create(groupCode, projectId,
|
|
|
+ AdmCommonConstant.APP_ID, AdmCommonConstant.USER_ID, nodes);
|
|
|
return CollectionUtil.isNotEmpty(result);
|
|
|
}
|
|
|
+ /***
|
|
|
+ * Description: 创建存储的对象
|
|
|
+ * @param groupCode : 集团编码
|
|
|
+ * @param projectId : 项目id
|
|
|
+ * @param relationDefine : 关系定义
|
|
|
+ * @param zoneType : 空间分区类型
|
|
|
+ * @return : void
|
|
|
+ * @author : lijie
|
|
|
+ * @date :2021/10/14 16:14
|
|
|
+ * Update By lijie 2021/10/14 16:14
|
|
|
+ */
|
|
|
+ private ObjectNode createRelationProjectCalInternal(ObjectMapper objectMapper, String groupCode,
|
|
|
+ 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());
|
|
|
+ objectNode.put("graphCode", relationDefine.getGraphCode());
|
|
|
+ objectNode.put("relCodeName", relationDefine.getName());
|
|
|
+ objectNode.put("relCode", relationDefine.getCode());
|
|
|
+ objectNode.put("sourceFlag", relationDefine.getSourceFlag()); // 是否需要配置源末端
|
|
|
+ objectNode.put("automaticFlag", relationDefine.getAutomaticFlag()); // 是否自动计算类型
|
|
|
+ objectNode.put("manual", relationDefine.getManual()); // 手动计算类型 1 禁用 2提示引导 3手动维护
|
|
|
+ objectNode.put("computationalState", 1); // 计算状态 1初始状态 2需要计算 3计算中 4等待中 5计算失败(如果处于计算中状态,则不再次调用)
|
|
|
+ objectNode.put("zoneType", zoneType); // 业务分区类型
|
|
|
+ objectNode.put("systemType", relationDefine.getSystemType()); // 风系统1,水系统0
|
|
|
+ objectNode.put("computeVersion", 0); // 计算版本
|
|
|
+ objectNode.put("mepSystemType", CollUtil.isNotEmpty(relationDefine.getMepSystemType())
|
|
|
+ ?objectMapper.writeValueAsString(relationDefine.getMepSystemType()):null); // 机电系统类型
|
|
|
+ objectNode.put("creator", AdmCommonConstant.USER_ID); // 创建人
|
|
|
+ objectNode.put("modifier", AdmCommonConstant.USER_ID); // 最后修改人
|
|
|
+ return objectNode;
|
|
|
+ }
|
|
|
|
|
|
+ /**
|
|
|
+ * 查询关系总览(空表,先插入)
|
|
|
+ * @param content: 模糊查询卡片名称关键字
|
|
|
+ */
|
|
|
@Override
|
|
|
- public JSONObject overview(String groupCode, String projectId, String content) {
|
|
|
+ public JSONObject overview(String content) throws JsonProcessingException {
|
|
|
JSONObject result = new JSONObject();
|
|
|
-
|
|
|
if (StrUtil.isBlank(content)) {
|
|
|
- this.createRelationProjectCal(groupCode, projectId);
|
|
|
+ this.createRelationProjectCal(AppContext.getContext().getGroupCode(), AppContext.getContext().getProjectId());
|
|
|
}
|
|
|
-
|
|
|
List<JSONObject> parentList = new ArrayList<JSONObject>();
|
|
|
-
|
|
|
// 获取树结构
|
|
|
- this.getGraphRelationProjectTree(parentList, groupCode, projectId, content);
|
|
|
-
|
|
|
+ this.getGraphRelationProjectTree(parentList, AppContext.getContext().getGroupCode(),
|
|
|
+ AppContext.getContext().getProjectId(), content);
|
|
|
result.put("content", parentList);
|
|
|
result.put("message", "");
|
|
|
result.put("pageNumber", 1);
|
|
|
result.put("pageSize", 1000);
|
|
|
result.put("result", "success");
|
|
|
result.put("total", parentList.size());
|
|
|
-
|
|
|
return result;
|
|
|
}
|
|
|
|
|
@@ -371,12 +401,10 @@ public class RelationReportService implements IRelationReportService {
|
|
|
|
|
|
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);
|
|
@@ -388,7 +416,7 @@ public class RelationReportService implements IRelationReportService {
|
|
|
criteria.putPOJO("name", condition); // 模糊查询
|
|
|
}
|
|
|
projectCriteria.setCriteria(criteria);
|
|
|
- projectCriteria.setOrders(Arrays.asList(OrderItem.asc("relCode")));
|
|
|
+ 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) {
|
|
@@ -396,20 +424,17 @@ public class RelationReportService implements IRelationReportService {
|
|
|
}
|
|
|
continue;
|
|
|
}
|
|
|
-
|
|
|
// 三级数据封装
|
|
|
for (ObjectNode objectNode : projectList) {
|
|
|
this.transfer(objectNode, childGraph.getId());
|
|
|
}
|
|
|
child.put("relationTypeProjectList", projectList);
|
|
|
}
|
|
|
-
|
|
|
// 再判断一次,防止当二级有数据但被清除了的情况下,一级还会存在
|
|
|
if (isQuery && CollectionUtil.isEmpty(childList)) {
|
|
|
childList.remove(i); //移除
|
|
|
continue;
|
|
|
}
|
|
|
-
|
|
|
parent.put("childGraphicTypeList", childList);
|
|
|
parentList.add(parent);
|
|
|
}
|