浏览代码

2021-1125
创建设备时,自动创建所在建筑和所在楼层关系

zhaoyk 3 年之前
父节点
当前提交
90ac46eea0
共有 1 个文件被更改,包括 41 次插入2 次删除
  1. 41 2
      src/main/java/com/persagy/bdtp/adm/service/impl/SyncAppImpl.java

+ 41 - 2
src/main/java/com/persagy/bdtp/adm/service/impl/SyncAppImpl.java

@@ -3,6 +3,7 @@ package com.persagy.bdtp.adm.service.impl;
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.date.DatePattern;
 import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.util.IdUtil;
 import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
@@ -383,15 +384,22 @@ public class SyncAppImpl implements ISyncApp {
 		//TODO 分布式事务管理
 		try {
 			//上传bdtp数据
+			List<ObjectNode> relations = new ArrayList<>();
+
 			if (CollUtil.isNotEmpty(uploadData.getObjects())) {
 				D2mMessage d2mMessage = new D2mMessage("object");
 				List<ObjectNode>[] objData = prepareBdtpData(uploadData.getObjects(), uploadParams, d2mMessage, logs);
 				uploadObjs(uploadParams, objData);
 
 				sendD2mMessage(d2mMessage, uploadParams);
+
+				autoRelations(objData[0], relations, uploadParams);
 			}
-			if (CollUtil.isNotEmpty(uploadData.getRelations())) {
-				List<ObjectNode>[] relData = prepareBdtpData(uploadData.getRelations(), uploadParams, null, logs);
+
+			if(uploadData.getRelations() != null)
+				relations.addAll(uploadData.getRelations());
+			if (relations.size() > 0) {
+				List<ObjectNode>[] relData = prepareBdtpData(relations, uploadParams, null, logs);
 				uploadRels(uploadParams, relData);
 			}
 
@@ -414,6 +422,37 @@ public class SyncAppImpl implements ISyncApp {
 		return new UploadRtn(AdmConst.UPLOAD_FINISHED);
 	}
 
+	private void autoRelations(List<ObjectNode> newObjs, List<ObjectNode> relations, UploadParams ps){
+		for(ObjectNode obj : newObjs) {
+			if (obj.get("objType") != null && AdmConst.OBJ_TYPE_EQUIPMENT.equals(obj.get("objType").asText())) {
+				String eqId = obj.get("id").asText();
+
+				if(obj.get("buildingId") != null) {
+					String bdId = obj.get("buildingId").asText();
+					relations.add(createRelation(eqId, bdId, "MechInArch", "Eq2Bd", ps.groupCode, ps.projectId));
+				}
+				if(obj.get("floorId") != null) {
+					String flId = obj.get("floorId").asText();
+					relations.add(createRelation(eqId, flId, "MechInArch", "Eq2Fl", ps.groupCode, ps.projectId));
+				}
+			}
+		}
+	}
+
+	private ObjectNode createRelation(String from, String to, String graphCode, String relCode, String groupCode, String projectId){
+		ObjectNode r = objectMapper.createObjectNode();
+		r.put("id", IdUtil.simpleUUID());
+		r.put("objFrom", from);
+		r.put("objTo", to);
+		r.put("graphCode", graphCode);
+		r.put("relCode", relCode);
+		r.put("groupCode", groupCode);
+		r.put("projectId", projectId);
+		r.put("valid", ValidEnum.TRUE.getType());
+		r.put("state", 0); //新增标识
+		return r;
+	}
+
 	private String checkUploadStatus(UploadParams uploadParams){
 		AdmUploadJob job = uploadJobMapper.selectOne(new QueryWrapper<AdmUploadJob>().eq("id", uploadParams.jobId));
 		if(job != null) {