|
@@ -1,9 +1,9 @@
|
|
|
package com.persagy.proxy.adm.strategy.relationdata;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Set;
|
|
|
+import java.util.*;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
|
|
import com.persagy.dmp.digital.entity.ObjectDigital;
|
|
|
import com.persagy.proxy.adm.constant.AdmCommonConstant;
|
|
@@ -14,6 +14,7 @@ import com.persagy.proxy.report.service.IRelationReportService;
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
+import org.json.JSONObject;
|
|
|
|
|
|
/**
|
|
|
* 报表数据抽象类
|
|
@@ -208,10 +209,135 @@ public abstract class AbstractReportRelationObject extends AbstractRelationObjec
|
|
|
objectNode.put("objTo", slave.get("id").asText());
|
|
|
return objectNode;
|
|
|
}
|
|
|
-
|
|
|
return result;
|
|
|
- }
|
|
|
-
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 检查关系对象数据的正确性,并完成额外字段的赋值功能
|
|
|
+ *
|
|
|
+ * @param relationTypeEnum AdmRelationTypeEnum枚举类
|
|
|
+ * @param code
|
|
|
+ * @return String - 校验失败的原因, ObjectNode -- BDTP接口的参数,不会返回null,请用instanceOf 判断返回值
|
|
|
+ */
|
|
|
+ protected Map<String,Object> beforeSaveRelationObjects(List<AdmRelationObject> relationObjects, AdmRelationTypeEnum relationTypeEnum,
|
|
|
+ String groupCode, String projectId, String code) {
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ if (CollUtil.isEmpty(relationObjects)){
|
|
|
+ return CollUtil.newHashMap(0);
|
|
|
+ }
|
|
|
+ // 收集master的识别编码
|
|
|
+ Set<String> masterCodes = new HashSet<>();
|
|
|
+ Set<String> masterObjTypes = new HashSet<>();
|
|
|
+ // 收集slave的识别编码
|
|
|
+ Set<String> slaveCodes = new HashSet<>();
|
|
|
+ Set<String> slaveObjTypes = new HashSet<>();
|
|
|
+ for (AdmRelationObject relationObject : relationObjects) {
|
|
|
+ if (!StrUtil.isAllNotBlank(relationObject.getMasterCode(), relationObject.getSlaveCode())) {
|
|
|
+ result.put(StrUtil.toString(relationObject.getMasterCode())+StrUtil.UNDERLINE
|
|
|
+ +StrUtil.toString(relationObject.getSlaveCode()),"主对象或从对象的识别编码为空");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ // 获取备用的类型
|
|
|
+ String relationType = relationTypeEnum.getRelationType();
|
|
|
+ int indexOf = relationType.indexOf("_");
|
|
|
+ String relCodeBak = indexOf > 0 ? relationType.substring(0, indexOf) : relationType;
|
|
|
+ String relCode = relationTypeEnum.getRelCode();
|
|
|
+ String relCodePrefix = ObjTypeMapping.getRelCodePrefix(relCode);
|
|
|
+ String masterObjType = ObjTypeMapping.PREFIX_FULLNAME.get(relCodePrefix);
|
|
|
+ if (StrUtil.isBlank(masterObjType)) {
|
|
|
+ relCodePrefix = ObjTypeMapping.getRelCodePrefix(relCodeBak);
|
|
|
+ relCodePrefix = StrUtil.upperFirst(relCodePrefix);
|
|
|
+ masterObjType = ObjTypeMapping.PREFIX_FULLNAME.get(relCodePrefix);
|
|
|
+ if (StrUtil.isBlank(masterObjType)) {
|
|
|
+ result.put(relationObject.getMasterCode()+StrUtil.UNDERLINE +relationObject.getSlaveCode(),"边类型错误");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String slaveObjType = ObjTypeMapping.PREFIX_FULLNAME.get(ObjTypeMapping.getRelCodeSuffix(relCode));
|
|
|
+ if (StrUtil.isBlank(slaveObjType)) {
|
|
|
+ String relCodeSuffix = StrUtil.upperFirst(ObjTypeMapping.getRelCodeSuffix(relCodeBak));
|
|
|
+ slaveObjType = ObjTypeMapping.PREFIX_FULLNAME.get(relCodeSuffix);
|
|
|
+ if (StrUtil.isBlank(slaveObjType)) {
|
|
|
+ result.put(relationObject.getMasterCode()+StrUtil.UNDERLINE +relationObject.getSlaveCode(),"边类型错误");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (StrUtil.isBlank(code)
|
|
|
+ || !RelationObjectStrategy.OBJNAME_2_TYPE.containsKey(code)
|
|
|
+ || StrUtil.isBlank(RelationObjectStrategy.OBJNAME_2_TYPE.get(code))) {
|
|
|
+ result.put(relationObject.getMasterCode()+StrUtil.UNDERLINE +relationObject.getSlaveCode(),"未找到主对象");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ masterCodes.add(relationObject.getMasterCode());
|
|
|
+ slaveCodes.add(relationObject.getSlaveCode());
|
|
|
+ masterObjTypes.add(masterObjType);
|
|
|
+ slaveObjTypes.add(slaveObjType);
|
|
|
+ }
|
|
|
+ if (StrUtil.isBlank(code)
|
|
|
+ || !RelationObjectStrategy.OBJNAME_2_TYPE.containsKey(code)
|
|
|
+ || StrUtil.isBlank(RelationObjectStrategy.OBJNAME_2_TYPE.get(code))
|
|
|
+ || CollUtil.isEmpty(masterCodes)
|
|
|
+ || CollUtil.isEmpty(slaveCodes)
|
|
|
+ || CollUtil.isEmpty(masterObjTypes)
|
|
|
+ || CollUtil.isEmpty(slaveObjTypes)) {
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ // 查询出对象信息
|
|
|
+ Map<String,List<ObjectNode>> masterMap = this.relationReportService.findObjectNodesByPage(groupCode, projectId,
|
|
|
+ masterObjTypes, RelationObjectStrategy.OBJNAME_2_TYPE.get(code), masterCodes);
|
|
|
+ Map<String,List<ObjectNode>> slaveMap = this.relationReportService.findObjectNodesByPage(groupCode, projectId,
|
|
|
+ slaveObjTypes, RelationObjectStrategy.OBJNAME_2_TYPE.get(code), slaveCodes);
|
|
|
+ String relationType = relationTypeEnum.getRelationType();
|
|
|
+ int indexOf = relationType.indexOf("_");
|
|
|
+ String relCodeSuffix = StrUtil.upperFirst(ObjTypeMapping
|
|
|
+ .getRelCodeSuffix(indexOf > 0 ? relationType.substring(0, indexOf) : relationType));
|
|
|
+ for (AdmRelationObject relationObject : relationObjects) {
|
|
|
+ String key = StrUtil.toString(relationObject.getMasterCode())+StrUtil.UNDERLINE
|
|
|
+ +StrUtil.toString(relationObject.getSlaveCode());
|
|
|
+ if (result.containsKey(key)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ List<ObjectNode> masterNodes = masterMap.get(relationObject.getMasterCode());
|
|
|
+ if (CollectionUtil.isEmpty(masterNodes)) {
|
|
|
+ result.put(relationObject.getMasterCode()+StrUtil.UNDERLINE +relationObject.getSlaveCode(),"未找到主对象");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (masterNodes.size() > 1) {
|
|
|
+ result.put(relationObject.getMasterCode()+StrUtil.UNDERLINE +relationObject.getSlaveCode(),"匹配到多个主对象");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ List<ObjectNode> slaveNodes = slaveMap.get(relationObject.getSlaveCode());
|
|
|
+ if (CollectionUtil.isEmpty(slaveNodes)) {
|
|
|
+ result.put(relationObject.getMasterCode()+StrUtil.UNDERLINE +relationObject.getSlaveCode(),"未找到从对象");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (slaveNodes.size() > 1) {
|
|
|
+ result.put(relationObject.getMasterCode()+StrUtil.UNDERLINE +relationObject.getSlaveCode(),"匹配到多个从对象");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ // 添加关系数据
|
|
|
+ ObjectNode master = masterNodes.get(0);
|
|
|
+ ObjectNode slave = slaveNodes.get(0);
|
|
|
+ String masterClassCode = master.get("classCode") == null ? AdmCommonConstant.EMPTY : master.get("classCode").asText();
|
|
|
+ String slaveClassCode = slave.get("classCode") == null ? AdmCommonConstant.EMPTY : slave.get("classCode").asText();
|
|
|
+ String subResult = this.checkRelationObject(master, masterClassCode, slave, slaveClassCode);
|
|
|
+ if (StrUtil.isBlank(subResult)) {
|
|
|
+ ObjectNode objectNode = OBJECT_MAPPER.createObjectNode();
|
|
|
+ String graphCode = relationTypeEnum.getGraphCode();
|
|
|
+ objectNode.put("graphId", "Gt" + graphCode + "001");
|
|
|
+ objectNode.put("graphCode", graphCode);
|
|
|
+ objectNode.put("relCode", relationTypeEnum.getRelCode());
|
|
|
+ if ("Sp".equals(relCodeSuffix)) {
|
|
|
+ objectNode.put("relValue", masterClassCode);
|
|
|
+ }
|
|
|
+ objectNode.put("objFrom", master.get("id").asText());
|
|
|
+ objectNode.put("objTo", slave.get("id").asText());
|
|
|
+ result.put(relationObject.getMasterCode()+StrUtil.UNDERLINE +relationObject.getSlaveCode(),objectNode);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 检查关系对象数据的正确性,并可完成额外字段的赋值功能
|
|
|
* 默认不实现,由子类实现
|