浏览代码

增加图类型、边类型定义查询方法

zhangqiankun 3 年之前
父节点
当前提交
5d1ea84826

+ 21 - 4
src/main/java/com/persagy/proxy/adm/controller/RelationReportController.java

@@ -30,6 +30,7 @@ import com.alibaba.excel.ExcelWriter;
 import com.alibaba.fastjson.JSONObject;
 import com.fasterxml.jackson.databind.node.ObjectNode;
 import com.google.common.collect.Lists;
+import com.persagy.dmp.define.client.DigitalGraphDefineFacade;
 import com.persagy.proxy.adm.constant.AdmCommonConstant;
 import com.persagy.proxy.adm.model.AdmRelationObject;
 import com.persagy.proxy.adm.request.AdmQueryCriteria;
@@ -37,6 +38,7 @@ import com.persagy.proxy.adm.request.AdmResponse;
 import com.persagy.proxy.adm.service.IRelationReportService;
 import com.persagy.proxy.adm.strategy.RelationObjectContext;
 
+import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.util.StrUtil;
 import lombok.extern.slf4j.Slf4j;
 
@@ -72,7 +74,6 @@ public class RelationReportController {
 	public AdmResponse queryCount(HttpServletRequest request) {
 		String groupCode = request.getHeader(AdmCommonConstant.GROUP_CODE_HEADER);
 		String projectId = request.getHeader(AdmCommonConstant.PROJECT_ID_HEADER);
-		// 获取所有的图类型
 		
 		JSONObject result = new JSONObject();
 		result.put("count", 0);
@@ -327,7 +328,7 @@ public class RelationReportController {
 		    // 获取识别码的属性
 		    String code = sheet.getRow(2).getCell(1).toString();
 		    int lastRowNum = sheet.getLastRowNum();
-		    for (int i = 4; i < lastRowNum; i++) {
+		    for (int i = 5; i <= lastRowNum; i++) {
 		    	XSSFRow xssfRow = sheet.getRow(i);
 		    	if (xssfRow == null) {
 					continue;
@@ -371,6 +372,18 @@ public class RelationReportController {
 					relationObjects.clear();
 				}
 			}
+		    // 最后一次遗留数据录入
+		    if (CollectionUtil.isNotEmpty(relationObjects)) {
+		    	boolean objects = this.relationObjectContext.saveRelationObjects(relationObjects, groupCode, projectId, relType);
+				if (objects) {
+					successNum += relationObjects.size();
+				} else {
+					failurNum += relationObjects.size();
+					for (int rowNum : rowNums) {
+						sheet.getRow(rowNum).createCell(16).setCellValue("调用中台,存储失败");
+					}
+				}
+			}
 		    
         	try {
         		// 调用中台存储完成之后,此文件存储至本地
@@ -453,9 +466,13 @@ public class RelationReportController {
 	 * @throws IOException 
 	 */
 	private File createTemplateFile(String uploadFile) throws IOException {
-		String path = AdmCommonConstant.SERVER_ROOT_PATH + "/template/" + uploadFile;
+		String path = AdmCommonConstant.SERVER_ROOT_PATH + "/template";
 		File file = new File(path);
-		if (file == null || !file.exists()) {
+		if (!file.exists()) {
+			file.mkdirs();
+		}
+		file = new File(path + "/" + uploadFile);
+		if (!file.exists()) {
 			file.createNewFile();
 		}
 		return file;

+ 13 - 1
src/main/java/com/persagy/proxy/adm/service/IRelationReportService.java

@@ -3,6 +3,8 @@ package com.persagy.proxy.adm.service;
 import java.util.List;
 
 import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.persagy.dmp.define.entity.GraphDefine;
+import com.persagy.dmp.define.entity.RelationDefine;
 import com.persagy.dmp.digital.entity.ObjectRelation;
 import com.persagy.proxy.adm.model.AdmRelationObject;
 
@@ -20,10 +22,20 @@ public interface IRelationReportService {
 	 * 根据条件查询对应的边类型数据
 	 * 
 	 * @param groupCode
+	 * @param projectId
+	 * @param graphCode
+	 */
+	List<GraphDefine> getGraphDefine(String groupCode, String projectId, String graphCode);
+	
+	/**
+	 * 根据条件查询对应的边类型数据
+	 * 
+	 * @param groupCode
+	 * @param projectId
 	 * @param graphCode
 	 * @param relCode
 	 */
-	void getGraphRelDefine(String groupCode, String graphCode, String relCode);
+	List<RelationDefine> getRelationDefine(String groupCode, String projectId, String graphCode, String relCode);
 	
 	/**
 	 * 获取项目计算关系

+ 31 - 5
src/main/java/com/persagy/proxy/adm/service/impl/RelationReportService.java

@@ -12,6 +12,10 @@ import com.google.common.collect.Lists;
 import com.persagy.dmp.basic.model.QueryCriteria;
 import com.persagy.dmp.common.helper.SpringHelper;
 import com.persagy.dmp.common.model.response.CommonResult;
+import com.persagy.dmp.define.client.DigitalGraphDefineFacade;
+import com.persagy.dmp.define.client.DigitalRelationDefineFacade;
+import com.persagy.dmp.define.entity.GraphDefine;
+import com.persagy.dmp.define.entity.RelationDefine;
 import com.persagy.dmp.digital.client.DigitalObjectFacade;
 import com.persagy.dmp.digital.client.DigitalRelationFacade;
 import com.persagy.dmp.digital.client.DigitalRelationProjectCalFacade;
@@ -27,6 +31,7 @@ import com.persagy.proxy.adm.strategy.relationdata.RelationObjectStrategy;
 import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.util.StrUtil;
 import lombok.extern.slf4j.Slf4j;
+import net.minidev.json.JSONObject;
 
 /**
  * 报表/模板下载
@@ -45,9 +50,22 @@ public class RelationReportService implements IRelationReportService {
 
 	@Autowired
 	private RelationObjectContext relationObjectContext;
+
+	@Override
+	public List<GraphDefine> getGraphDefine(String groupCode, String projectId, String graphCode) {
+		ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
+		QueryCriteria queryCriteria = new QueryCriteria();
+		ObjectNode criteria = objectMapper.createObjectNode();
+		if (StrUtil.isNotBlank(graphCode)) {
+			criteria.put("code", graphCode);
+		}
+		queryCriteria.setCriteria(criteria);
+		List<GraphDefine> graphDefines = DigitalGraphDefineFacade.query(groupCode, projectId, AdmCommonConstant.APP_ID, AdmCommonConstant.USER_ID, queryCriteria);
+		return graphDefines;
+	}
 	
 	@Override
-	public void getGraphRelDefine(String groupCode, String graphCode, String relCode) {
+	public List<RelationDefine> getRelationDefine(String groupCode, String projectId, String graphCode, String relCode) {
 		ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
 		QueryCriteria queryCriteria = new QueryCriteria();
 		ObjectNode criteria = objectMapper.createObjectNode();
@@ -55,9 +73,11 @@ public class RelationReportService implements IRelationReportService {
 			criteria.put("graphCode", graphCode);
 		}
 		if (StrUtil.isNotBlank(relCode)) {
-			criteria.put("relCode", relCode);
+			criteria.put("code", relCode);
 		}
 		queryCriteria.setCriteria(criteria);
+		List<RelationDefine> relationDefines = DigitalRelationDefineFacade.query(groupCode, projectId, AdmCommonConstant.APP_ID, AdmCommonConstant.USER_ID, queryCriteria);
+		return relationDefines;
 	}
 	
 	@Override
@@ -75,14 +95,20 @@ public class RelationReportService implements IRelationReportService {
 			objectNode.put("relationType", relType);
 			
 			// 获取此图类型和边类型对应的数据记录
+			List<RelationDefine> relationDefines = this.getRelationDefine(groupCode, projectId, relationTypeEnum.getGraphCode(), relationTypeEnum.getRelCode());
+			if (CollectionUtil.isNotEmpty(relationDefines)) {
+				RelationDefine relationDefine = relationDefines.get(0);
+				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);
+			}
 			
 			String prefix = ObjTypeMapping.getRelCodePrefix(relationTypeEnum.getRelCode());
 			String suffix = ObjTypeMapping.getRelCodeSuffix(relationTypeEnum.getRelCode());
 			objectNode.put("mainObject", ObjTypeMapping.PREFIX_NAME.get(prefix));
 			objectNode.put("fromObject", ObjTypeMapping.PREFIX_NAME.get(suffix));
-			objectNode.put("relationTypeCode", relationTypeEnum.getRelCode());
-			boolean automatic = objectNode.get("automaticFlag") == null ? false : objectNode.get("automaticFlag").asBoolean(false);
-			objectNode.put("automatic", automatic);
+			objectNode.putPOJO("statistics", new JSONObject());
 		}
 		
 		return objectNode;

+ 5 - 5
src/main/java/com/persagy/proxy/adm/strategy/RelationObjectContext.java

@@ -56,7 +56,7 @@ public class RelationObjectContext {
 		if (relationTypeEnum == null) {
 			return Lists.newArrayList();
 		}
-		String className = relationTypeEnum.getGraphCode() + AdmCommonConstant.UNDERLINE + relationTypeEnum.getRelationType();
+		String className = relationTypeEnum.getGraphCode() + AdmCommonConstant.UNDERLINE + relationTypeEnum.getRelCode();
 		RelationObjectStrategy strategy = this.relationObjectStrategyMap.get(className);
 		return strategy == null ? Lists.newArrayList() : strategy.findRelationObject(groupCode, projectId);
 	}
@@ -74,7 +74,7 @@ public class RelationObjectContext {
 		if (relationTypeEnum == null) {
 			return "未知类型";
 		}
-		String className = relationTypeEnum.getGraphCode() + AdmCommonConstant.UNDERLINE + relationTypeEnum.getRelationType();
+		String className = relationTypeEnum.getGraphCode() + AdmCommonConstant.UNDERLINE + relationTypeEnum.getRelCode();
 		RelationObjectStrategy strategy = this.relationObjectStrategyMap.get(className);
 		if (strategy == null) {
 			return "不存在此策略类";
@@ -97,7 +97,7 @@ public class RelationObjectContext {
 		if (relationTypeEnum == null) {
 			return false;
 		}
-		String className = relationTypeEnum.getGraphCode() + AdmCommonConstant.UNDERLINE + relationTypeEnum.getRelationType();
+		String className = relationTypeEnum.getGraphCode() + AdmCommonConstant.UNDERLINE + relationTypeEnum.getRelCode();
 		RelationObjectStrategy strategy = this.relationObjectStrategyMap.get(className);
 		if (strategy == null) {
 			return false;
@@ -119,7 +119,7 @@ public class RelationObjectContext {
 		if (relationTypeEnum == null) {
 			return 0;
 		}
-		String className = relationTypeEnum.getGraphCode() + AdmCommonConstant.UNDERLINE + relationTypeEnum.getRelationType();
+		String className = relationTypeEnum.getGraphCode() + AdmCommonConstant.UNDERLINE + relationTypeEnum.getRelCode();
 		RelationObjectStrategy strategy = this.relationObjectStrategyMap.get(className);
 		if (strategy == null) {
 			return 0;
@@ -143,7 +143,7 @@ public class RelationObjectContext {
 		if (relationTypeEnum == null) {
 			return masterObjs;
 		}
-		String className = relationTypeEnum.getGraphCode() + AdmCommonConstant.UNDERLINE + relationTypeEnum.getRelationType();
+		String className = relationTypeEnum.getGraphCode() + AdmCommonConstant.UNDERLINE + relationTypeEnum.getRelCode();
 		RelationObjectStrategy strategy = this.relationObjectStrategyMap.get(className);
 		if (strategy == null) {
 			return masterObjs;

+ 3 - 3
src/main/java/com/persagy/proxy/adm/strategy/relationdata/AbstractReportRelationObject.java

@@ -153,7 +153,7 @@ public abstract class AbstractReportRelationObject extends AbstractRelationObjec
 		if (StrUtil.isBlank(masterObjType)) {
 			return "边类型错误";
 		}
-		String slaveObjType = ObjTypeMapping.PREFIX_FULLNAME.get(ObjTypeMapping.getRelCodePrefix(relCode));
+		String slaveObjType = ObjTypeMapping.PREFIX_FULLNAME.get(ObjTypeMapping.getRelCodeSuffix(relCode));
 		if (StrUtil.isBlank(slaveObjType)) {
 			return "边类型错误";
 		}
@@ -190,8 +190,8 @@ public abstract class AbstractReportRelationObject extends AbstractRelationObjec
 			if ("Sp".equals(relCodePrefix)) {
 				objectNode.put("relValue", masterClassCode);
 			}
-			objectNode.put("objFrom", relationObject.getMasterId());
-			objectNode.put("objTo", relationObject.getSlaveId());
+			objectNode.put("objFrom", master.get("id").asText());
+			objectNode.put("objTo", slave.get("id").asText());
 			return objectNode;
 		}
 		

二进制
src/main/resources/template/relation-template.xlsx