浏览代码

项目关系计算数据插入

zhangqiankun 3 年之前
父节点
当前提交
3641c844fa

+ 2 - 0
src/main/java/com/persagy/proxy/adm/constant/AdmCommonConstant.java

@@ -10,6 +10,8 @@ import java.util.Map;
 public interface AdmCommonConstant {
 	/** ADM 边类型 -> 枚举类 */
 	static Map<String, AdmRelationTypeEnum> RELATION_TYPE_MAP = AdmRelationTypeEnum.getRelationTypeMap();
+	/** BDTP 图类型_边类型 -> 枚举类 */
+	static Map<String, AdmRelationTypeEnum> GRAPH_RELATION_TYPE_MAP = AdmRelationTypeEnum.getGraphRelTypeMap();
 	
 	/** 项目根路径*/
 	String SERVER_ROOT_PATH = System.getProperty("user.dir");

+ 14 - 1
src/main/java/com/persagy/proxy/adm/constant/AdmRelationTypeEnum.java

@@ -384,6 +384,19 @@ public enum AdmRelationTypeEnum {
         List<AdmRelationTypeEnum> enumList = EnumUtils.getEnumList(AdmRelationTypeEnum.class);
         return enumList.stream().collect(Collectors.toMap(AdmRelationTypeEnum::getRelationType,admRelationTypeEnum -> admRelationTypeEnum));
     }
-
+    
+    /***
+     * Description: 获取枚举类的映射
+     * key: 图类型_边类型, value: enum
+     * @return : java.util.Map<java.lang.String,com.persagy.proxy.enumeration.AdmRelationTypeEnum>
+     * @author : lijie
+     * date :2021/9/2 17:22
+     * Update By lijie 2021/9/2 17:22
+     */
+    public static Map<String,AdmRelationTypeEnum> getGraphRelTypeMap(){
+        List<AdmRelationTypeEnum> enumList = EnumUtils.getEnumList(AdmRelationTypeEnum.class);
+        return enumList.stream().collect(Collectors.toMap(k -> k.getGraphCode() + AdmCommonConstant.UNDERLINE + k.getRelationType(),
+        		admRelationTypeEnum -> admRelationTypeEnum));
+    }
 
 }

+ 22 - 2
src/main/java/com/persagy/proxy/adm/controller/RelationReportController.java

@@ -21,6 +21,7 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.util.ResourceUtils;
+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;
@@ -76,6 +77,7 @@ public class RelationReportController {
 	@RequestMapping("/graphic/query-count")
 	public AdmResponse queryCount(HttpServletRequest request) {
 		String groupCode = request.getHeader(AdmCommonConstant.GROUP_CODE_HEADER);
+		groupCode = StrUtil.isBlank(groupCode) ? defaultCode : groupCode;
 		String projectId = request.getHeader(AdmCommonConstant.PROJECT_ID_HEADER);
 		
 		JSONObject result = new JSONObject();
@@ -97,6 +99,24 @@ public class RelationReportController {
 	}
 	
 	/**
+	 * 查询关系总览(空表,先插入)
+	 * 
+	 * @param queryCriteria
+	 * @param request
+	 * @return
+	 */
+	@RequestMapping("/graphic/overview")
+	public AdmResponse overview(@RequestParam String content, HttpServletRequest request) {
+		String groupCode = request.getHeader(AdmCommonConstant.GROUP_CODE_HEADER);
+		String projectId = request.getHeader(AdmCommonConstant.PROJECT_ID_HEADER);
+		this.relationReportService.overview(groupCode, projectId, content);
+		
+		JSONObject result = new JSONObject();
+		result.put("count", 0);
+		return AdmResponse.success(Lists.newArrayList(result));
+	}
+	
+	/**
 	 * 项目关系类型查询
 	 * 
 	 * @param queryCriteria
@@ -104,15 +124,15 @@ public class RelationReportController {
 	 * @return
 	 */
 	@RequestMapping("/graphic/relation_type_project")
-	public AdmResponse queryRelationObjects(@RequestParam AdmQueryCriteria queryCriteria, HttpServletRequest request) {
+	public AdmResponse queryRelationObjects(@RequestBody AdmQueryCriteria queryCriteria, HttpServletRequest request) {
 		String groupCode = request.getHeader(AdmCommonConstant.GROUP_CODE_HEADER);
+		groupCode = StrUtil.isBlank(groupCode) ? defaultCode : groupCode;
 		String projectId = request.getHeader(AdmCommonConstant.PROJECT_ID_HEADER);
 		JSONObject result = new JSONObject();
 		result.put("count", 0);
 		return AdmResponse.success(Lists.newArrayList(result));
 	}
 	
-	
 	/**
 	 * 下载报告-设备静态信息维护模板
 	 * 

+ 19 - 0
src/main/java/com/persagy/proxy/adm/service/IRelationReportService.java

@@ -139,6 +139,25 @@ public interface IRelationReportService {
 	 * @return
 	 */
 	List<ObjectRelation> findObjectRelationList(String groupCode, String projectId, String graphCode, String relCode);
+
+	/**
+	 * 查询关系总览(空表,先插入)
+	 * 
+	 * @param groupCode
+	 * @param projectId
+	 * @param content
+	 */
+	void overview(String groupCode, String projectId, String content);
+	
+	/**
+	 * 初始化项目关系计算数据
+	 * 
+	 * @param groupCode
+	 * @param projectId
+	 * @param content
+	 * @return
+	 */
+	boolean createRelationProjectCal(String groupCode, String projectId);
 	
 	/**
 	 * 查询出所有的关系信息

+ 67 - 0
src/main/java/com/persagy/proxy/adm/service/impl/RelationReportService.java

@@ -1,5 +1,7 @@
 package com.persagy.proxy.adm.service.impl;
 
+import java.util.ArrayList;
+import java.util.Date;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -22,6 +24,7 @@ import com.persagy.dmp.digital.client.DigitalObjectFacade;
 import com.persagy.dmp.digital.client.DigitalRelationFacade;
 import com.persagy.dmp.digital.client.DigitalRelationProjectCalFacade;
 import com.persagy.dmp.digital.entity.ObjectRelation;
+import com.persagy.dmp.digital.entity.ObjectRelationProjectCal;
 import com.persagy.dmp.simple.client.DigitalObjectSimpleFacade;
 import com.persagy.proxy.adm.constant.AdmCommonConstant;
 import com.persagy.proxy.adm.constant.AdmRelationTypeEnum;
@@ -30,6 +33,8 @@ import com.persagy.proxy.adm.service.IRelationReportService;
 import com.persagy.proxy.adm.strategy.relationdata.RelationObjectStrategy;
 
 import cn.hutool.core.collection.CollectionUtil;
+import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.util.IdUtil;
 import cn.hutool.core.util.StrUtil;
 import net.minidev.json.JSONObject;
 
@@ -258,5 +263,67 @@ 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;
 	}
+
+	@Override
+	public boolean createRelationProjectCal(String groupCode, String projectId) {
+		groupCode = StrUtil.isBlank(groupCode) ? defaultCode : groupCode;
+		
+		// 验证是否已经添加过
+		QueryCriteria queryCriteria = new QueryCriteria();
+		queryCriteria.setOnlyCount(true);
+		CommonResult<List<ObjectNode>> prototype = DigitalRelationProjectCalFacade.queryPrototype(groupCode, null, AdmCommonConstant.APP_ID, AdmCommonConstant.USER_ID, queryCriteria);
+		if (prototype != null && prototype.getCount() != 0) {
+			return true;
+		}
+		
+		// 获取所有的边类型
+		QueryCriteria criteria = new QueryCriteria();
+		List<RelationDefine> list = DigitalRelationDefineFacade.query(groupCode, null, AdmCommonConstant.APP_ID, AdmCommonConstant.USER_ID, criteria);
+		if (CollectionUtil.isEmpty(list)) {
+			return true;
+		}
+		
+		// 组装关系计算数据
+		String now = DateUtil.format(new Date(), "yyyyMMddHHmmss");
+		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("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", relationDefine.getGraphCode());	// 手动计算关系类型
+			//objectNode.put("computeVersion", relationDefine.getGraphCode());	// 计算版本
+			objectNode.put("creator", AdmCommonConstant.USER_ID);	// 创建人
+			objectNode.put("creationTime", now);	// 创建时间
+			objectNode.put("modifier", AdmCommonConstant.USER_ID);	// 最后修改人
+			objectNode.put("modifiedTime", now);	// 最后修改时间
+			//objectNode.put("valid", relationDefine.getGraphCode());	// 合法标识
+		}
+		
+		List<ObjectRelationProjectCal> result = DigitalRelationProjectCalFacade.create(groupCode, projectId, AdmCommonConstant.APP_ID, AdmCommonConstant.USER_ID, nodes);
+		return CollectionUtil.isNotEmpty(result);
+	}
+
+	@Override
+	public void overview(String groupCode, String projectId, String content) {
+		if (StrUtil.isBlank(content)) {
+			this.createRelationProjectCal(groupCode, projectId);
+			
+			// 获取所有的一级图类型定义
+		}
+	}
 	
 }