Преглед на файлове

Merge remote-tracking branch 'origin/develop' into develop

lijie преди 3 години
родител
ревизия
9b2983ffdc

+ 16 - 22
src/main/java/com/persagy/proxy/relation/controller/RelationShContainSpBaseController.java

@@ -1,24 +1,14 @@
 package com.persagy.proxy.relation.controller;
 
-import java.util.*;
-import java.util.stream.Collectors;
-
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.comparator.CompareUtil;
+import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.core.util.StrUtil;
 import cn.hutool.extra.spring.SpringUtil;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.persagy.dmp.digital.client.DigitalRelationFacade;
-import com.persagy.proxy.adm.constant.AdmRelationTypeEnum;
-import org.checkerframework.checker.units.qual.C;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
-
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.node.JsonNodeFactory;
 import com.fasterxml.jackson.databind.node.ObjectNode;
 import com.google.common.collect.Sets;
@@ -27,11 +17,13 @@ import com.persagy.dmp.basic.model.QueryCriteria;
 import com.persagy.dmp.common.context.AppContext;
 import com.persagy.dmp.define.entity.ObjectTypeDefine;
 import com.persagy.dmp.digital.client.DigitalObjectFacade;
+import com.persagy.dmp.digital.client.DigitalRelationFacade;
 import com.persagy.dmp.digital.entity.ObjectDigital;
 import com.persagy.dmp.digital.entity.ObjectRelation;
 import com.persagy.proxy.adm.constant.AdmCommonConstant;
 import com.persagy.proxy.adm.constant.AdmDictCategoryEnum;
 import com.persagy.proxy.adm.constant.AdmObjectType;
+import com.persagy.proxy.adm.constant.AdmRelationTypeEnum;
 import com.persagy.proxy.adm.request.AdmResponse;
 import com.persagy.proxy.adm.service.IAdmRelationService;
 import com.persagy.proxy.adm.utils.AdmContextUtil;
@@ -39,11 +31,13 @@ import com.persagy.proxy.common.client.DmpRwdClient;
 import com.persagy.proxy.common.entity.InstanceUrlParam;
 import com.persagy.proxy.common.entity.RelationDTO;
 import com.persagy.proxy.report.service.IRelationReportService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
 
-import cn.hutool.core.collection.CollUtil;
-import cn.hutool.core.collection.CollectionUtil;
-import cn.hutool.core.util.ObjectUtil;
-import cn.hutool.core.util.StrUtil;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
 
 /**
  * @description:023、关系-竖井下的业务空间
@@ -102,7 +96,7 @@ public class RelationShContainSpBaseController {
      */
     @PostMapping("/unlink")
     public AdmResponse delete(@RequestParam(value = "type", required = false) String type,
-                              @RequestBody JSONObject param) throws Exception {
+                              @RequestBody List<JSONObject> param) throws Exception {
         if(CollUtil.isEmpty(param)) {
             return AdmResponse.success();
         }
@@ -110,8 +104,8 @@ public class RelationShContainSpBaseController {
         InstanceUrlParam context = AdmContextUtil.toDmpContext();
         // 组装条件
         QueryCriteria criteria = new QueryCriteria();
-        String shaftId = param.getString("shaftId");
-        String spaceId = param.getString("spaceId");
+        String shaftId = param.get(0).getString("shaftId");
+        String spaceId = param.get(0).getString("spaceId");
         if(!StrUtil.isAllNotEmpty(shaftId,spaceId)) {
             return AdmResponse.failure("必填项:ShaftID(竖井id)、SpaceID(业务空间id)");
         }

+ 54 - 51
src/main/java/com/persagy/proxy/report/service/impl/RelationReportService.java

@@ -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));