Quellcode durchsuchen

初步完成项目关系数据查询

zhangqiankun vor 3 Jahren
Ursprung
Commit
6553bb6273

+ 15 - 0
src/main/java/com/persagy/proxy/adm/constant/ObjTypeMapping.java

@@ -3,6 +3,8 @@ package com.persagy.proxy.adm.constant;
 import java.util.HashMap;
 import java.util.Map;
 
+import org.apache.commons.lang.StringUtils;
+
 import cn.hutool.core.util.StrUtil;
 
 /**
@@ -93,4 +95,17 @@ public class ObjTypeMapping {
 		return StrUtil.isBlank(relCode) ? AdmCommonConstant.EMPTY : relCode.substring(3, 5);
 	}
 	
+	/**
+	 * 获取中台中边类型对应的描述
+	 * 
+	 * @param objType 最低5位,不然抛异常
+	 * @return 空字符串或者对应后缀
+	 */
+	public static String getConneObject(String relCode) {
+		if (StringUtils.isBlank(relCode) || relCode.length() < 5) {
+			return AdmCommonConstant.EMPTY;
+		}
+		return PREFIX_NAME.get(relCode.substring(0, 2)) + AdmCommonConstant.RIGHT_ARROW +  PREFIX_NAME.get(relCode.substring(3, 5));
+	}
+	
 }

+ 133 - 2
src/main/java/com/persagy/proxy/adm/service/impl/RelationReportService.java

@@ -1,14 +1,18 @@
 package com.persagy.proxy.adm.service.impl;
 
+import java.time.format.DateTimeFormatter;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import org.apache.commons.lang.StringUtils;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
+import com.baomidou.mybatisplus.core.metadata.OrderItem;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.node.ObjectNode;
 import com.google.common.collect.Lists;
@@ -293,9 +297,12 @@ public class RelationReportService implements IRelationReportService {
 			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());	// 是否自动计算类型
@@ -304,7 +311,7 @@ public class RelationReportService implements IRelationReportService {
 			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", relationDefine.getGraphCode());	// 手动计算关系类型
+			objectNode.put("relManualType", typeEnum.getRelationType());	// 手动计算关系类型
 			//objectNode.put("computeVersion", relationDefine.getGraphCode());	// 计算版本
 			objectNode.put("creator", AdmCommonConstant.USER_ID);	// 创建人
 			objectNode.put("creationTime", now);	// 创建时间
@@ -319,11 +326,135 @@ public class RelationReportService implements IRelationReportService {
 
 	@Override
 	public void overview(String groupCode, String projectId, String content) {
+		JSONObject result = new JSONObject();
+		
 		if (StrUtil.isBlank(content)) {
 			this.createRelationProjectCal(groupCode, projectId);
+		}
+		
+		List<JSONObject> parentList = new ArrayList<JSONObject>();
+		
+		// 获取树结构
+		this.getGraphRelationProjectTree(parentList, groupCode, projectId, 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());
+	}
+	
+	/**
+	 * 获取图类型下的边类型的项目计算关系数据,并形成三级树结构
+	 * 
+	 * @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);
+		// 获取所有的一级图类型定义
+		QueryCriteria parentCriteria = new QueryCriteria();
+		List<GraphDefine> topList = DigitalGraphDefineFacade.query(groupCode, null, 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, null, AdmCommonConstant.APP_ID, AdmCommonConstant.USER_ID, childCriteria);
+			if (CollectionUtil.isEmpty(childList)) {
+				if (isQuery) {
+					topList.remove(i);		//移除
+				}
+				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(Arrays.asList(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);
+			}
+			
+			// 再判断一次,防止当二级有数据但被清除了的情况下,一级还会存在
+			if (isQuery && CollectionUtil.isEmpty(childList)) {
+				childList.remove(i);		//移除
+				continue;
+			}
+			
+			parent.put("childGraphicTypeList", childList);
 		}
 	}
 	
+	/**
+	 * 获取转换后的数据,图类型数据转换
+	 * 
+	 * @param graphDefine
+	 * @return
+	 */
+	private JSONObject transfer(GraphDefine graphDefine) {
+		JSONObject top = new JSONObject();
+		top.put("sort", 1);
+		top.put("note", "");
+		top.put("statistics", Lists.newArrayList());
+		top.put("graphTypeName", graphDefine.getName());
+		top.put("graphTypeId", graphDefine.getId());
+		top.put("graphTypeCode", 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;
+	}
+	
+	/**
+	 * 获取转换后的数据,项目计算数据转换
+	 * 
+	 * @param relationProject
+	 * @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));
+		
+		String modifiedTime = relationProject.get("modifiedTime") == null ? null : relationProject.get("modifiedTime").asText();
+		modifiedTime = modifiedTime == null ? null : DateUtil.parse(modifiedTime, "yyyyMMddHHmmss").toString();
+		String creationTime = relationProject.get("creationTime") == null ? null : relationProject.get("creationTime").asText();
+		creationTime = creationTime == null ? null : DateUtil.parse(creationTime, "yyyyMMddHHmmss").toString();
+		
+		relationProject.put("lastUpdate", modifiedTime);
+		relationProject.put("createTime", creationTime);
+	}
+	
 }