浏览代码

1018 设别类自定义/重命名 老adm同步优化

zhaoyk 3 年之前
父节点
当前提交
1560122e07

+ 5 - 0
src/main/java/com/persagy/bdtp/adm/entity/D2mMessage.java

@@ -1,5 +1,6 @@
 package com.persagy.bdtp.adm.entity;
 
+import cn.hutool.core.collection.CollUtil;
 import lombok.Data;
 
 import java.util.List;
@@ -15,4 +16,8 @@ public class D2mMessage {
 
 	private List<?> removeItems;
 
+	public boolean isNotEmpty(){
+		return CollUtil.isNotEmpty(addItems) || CollUtil.isNotEmpty(modifyItems) || CollUtil.isNotEmpty(removeItems);
+	}
+
 }

+ 4 - 0
src/main/java/com/persagy/bdtp/adm/entity/UploadRtn.java

@@ -25,4 +25,8 @@ public class UploadRtn {
 
 	private String timestamp;
 
+	private long timestampMillis;
+
+	private String buildingId;
+
 }

+ 6 - 0
src/main/java/com/persagy/bdtp/adm/service/IConfigService.java

@@ -1,5 +1,7 @@
 package com.persagy.bdtp.adm.service;
 
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
 import com.persagy.bdtp.adm.entity.*;
 
 import java.util.List;
@@ -18,4 +20,8 @@ public interface IConfigService {
 
 	List<AdmComponent> queryComponent(String projectId);
 
+	ArrayNode queryNewEquipTypes(String projectId);
+
+	ObjectNode queryRenameEquipTypes(String projectId);
+
 }

+ 26 - 0
src/main/java/com/persagy/bdtp/adm/service/impl/ConfigServiceImpl.java

@@ -1,5 +1,9 @@
 package com.persagy.bdtp.adm.service.impl;
 
+import cn.hutool.core.collection.CollUtil;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
 import com.persagy.bdtp.adm.dao.*;
 import com.persagy.bdtp.adm.entity.*;
 import com.persagy.bdtp.adm.service.IConfigService;
@@ -58,4 +62,26 @@ public class ConfigServiceImpl implements IConfigService {
 	public List<AdmComponent> queryComponent(String projectId) {
 		return componentMapper.selectList(null);
 	}
+
+	@Override
+	public ArrayNode queryNewEquipTypes(String projectId) {
+		List<AdmConfig> list = commonConfigMapper.selectList(new QueryWrapper<AdmConfig>().eq("code", "new_equip_types"));
+		if(CollUtil.isNotEmpty(list)){
+			AdmConfig cfg = list.get(0);
+			return (ArrayNode) cfg.getData();
+		}
+		return null;
+	}
+
+	@Override
+	public ObjectNode queryRenameEquipTypes(String projectId) {
+		List<AdmConfig> list = commonConfigMapper.selectList(new QueryWrapper<AdmConfig>().eq("code", "rename_equip_types"));
+		if(CollUtil.isNotEmpty(list)){
+			AdmConfig cfg = list.get(0);
+			return (ObjectNode) cfg.getData();
+		}
+		return null;
+	}
+
+
 }

+ 81 - 26
src/main/java/com/persagy/bdtp/adm/service/impl/SyncAppImpl.java

@@ -3,21 +3,21 @@ 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;
 import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
 import com.persagy.bdtp.adm.client.DicClient;
 import com.persagy.bdtp.adm.client.RwdClient;
 import com.persagy.bdtp.adm.common.AdmConst;
-import com.persagy.bdtp.adm.common.AdmMessageConst;
 import com.persagy.bdtp.adm.common.AdmResult;
 import com.persagy.bdtp.adm.dao.*;
 import com.persagy.bdtp.adm.entity.*;
 import com.persagy.bdtp.adm.entity.oldadm.OProject;
-import com.persagy.bdtp.adm.entity.oldadm.OldAdmResult;
 import com.persagy.bdtp.adm.service.*;
 import com.persagy.dmp.basic.model.QueryCriteria;
 import com.persagy.dmp.common.constant.ResponseCode;
@@ -27,8 +27,6 @@ import com.persagy.dmp.common.lang.PsDateTime;
 import com.persagy.dmp.common.model.response.CommonResult;
 import com.persagy.dmp.define.entity.RelationDefine;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.core.io.Resource;
-import org.springframework.core.io.ResourceLoader;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -82,7 +80,10 @@ public class SyncAppImpl implements ISyncApp {
 	private ISyncModel syncModel;
 
 	@Autowired
-	ResourceLoader resourceLoader;
+	private ObjectMapper objectMapper;
+
+//	@Autowired
+//	ResourceLoader resourceLoader;
 
 	@Override
 	public Map<String, Object> downloadDictAndConfig(String groupCode, String projectId, String userId) {
@@ -124,22 +125,40 @@ public class SyncAppImpl implements ISyncApp {
 		//查询关系定义
 		List<RelationDefine> relList = ServiceUtil.call(() -> rwdClient.queryRelDef(groupCode, projectId, AdmConst.APP_ID, userId, new QueryCriteria()));
 
+		//查询重命名设备类型
+		ObjectNode renameNode = configService.queryRenameEquipTypes(projectId);
+
 		LinkedList<TypeDef> sysList = new LinkedList<>();
 		LinkedList<TypeDef> equipList = new LinkedList<>();
 		for(TypeDef def : typeList){
 			if(def.getObjType().equals("system"))
 				sysList.add(def);
-			else if(def.getObjType().equals("equipment"))
+			else if(def.getObjType().equals("equipment")) {
+				if (renameNode != null) { //设备类型重命名
+					JsonNode n = renameNode.get(def.getCode());
+					if(n != null)
+						def.setName(n.asText());
+				}
 				equipList.add(def);
+			}
 		}
 
 		//加载新增的自定义设备类
-		try{
-			Resource resource = resourceLoader.getResource("classpath:equip.json");
-			List<TypeDef> types = objectMapper.readValue(resource.getInputStream(), new TypeReference<List<TypeDef>>(){});
-			equipList.addAll(types);
-		}catch (Exception e) {
+//		try{
+//			Resource resource = resourceLoader.getResource("classpath:equip.json");
+//			List<TypeDef> types = objectMapper.readValue(resource.getInputStream(), new TypeReference<List<TypeDef>>(){});
+//			equipList.addAll(types);
+//		}catch (Exception e) {
+//
+//		}
+		ArrayNode arr = configService.queryNewEquipTypes(projectId);
+		if(arr != null) {
+			try{
+				List<TypeDef> types = objectMapper.readValue(objectMapper.writeValueAsString(arr), new TypeReference<List<TypeDef>>(){});
+				equipList.addAll(types);
+			}catch (Exception e) {
 
+			}
 		}
 
 		//组织树形结构
@@ -346,6 +365,8 @@ public class SyncAppImpl implements ISyncApp {
 		}
 
 		rtn.setTimestamp(timestampStr);
+		rtn.setTimestampMillis(timestamp.getMillis());
+		rtn.setBuildingId(uploadData.getBuildingId());
 		return rtn;
 	}
 
@@ -366,8 +387,9 @@ public class SyncAppImpl implements ISyncApp {
 					continue;
 
 				obj.setCreationTime(timestamp);
+				obj.setModifiedTime(timestamp); //新增时设置modifiedTime,方便后续处理
 				obj.setCreator(AdmConst.CREATOR_APP);
-				setBdtpUploadProp(obj, dbObj, uploadFlag);
+				setBdtpUploadProp(obj, null, uploadFlag);
 
 				mapper.insert(obj);
 
@@ -382,12 +404,26 @@ public class SyncAppImpl implements ISyncApp {
 					dbTs = dbObj.getCreationTime().getMillis();
 					ts = obj.getCreationTime().getMillis();
 				}
-				if (ts != dbTs) {
-					//TODO 时间戳不一致,离线数据无效,暂时跳过处理
-					expired.add(obj);
-				} else {
+//				if (ts != dbTs) {
+//					//TODO 时间戳不一致,离线数据无效,暂时跳过处理
+//					expired.add(obj);
+//				} else {
 					obj.setModifiedTime(timestamp);
 					obj.setModifier(AdmConst.CREATOR_APP);
+
+					//合并对象信息点
+					if(dbObj instanceof AdmObject) {
+						AdmObject vo = (AdmObject) obj;
+						AdmObject dbo = (AdmObject)dbObj;
+						if(dbo.getInfos() != null) {
+							ObjectNode infos = objectMapper.createObjectNode();
+							infos.setAll(dbo.getInfos());
+							if(vo.getInfos() != null)
+								infos.setAll(vo.getInfos());
+							vo.setInfos(infos);
+						}
+					}
+
 					setBdtpUploadProp(obj, dbObj, uploadFlag);
 
 					mapper.updateById(obj);
@@ -397,7 +433,7 @@ public class SyncAppImpl implements ISyncApp {
 					else
 						msgModify.add(obj);
 				}
-			}
+//			}
 		}
 
 		sendD2mMessage(objectType, msgAdd, msgModify, msgRemove);
@@ -409,8 +445,11 @@ public class SyncAppImpl implements ISyncApp {
 		obj.setUploadFlag(uploadFlag);
 		obj.setD2mState(ValidEnum.FALSE.getType());
 		obj.setDeliveryState(ValidEnum.FALSE.getType());
-		obj.setClientId(dbObj.getClientId());
-		obj.setClientDevice(dbObj.getClientDevice());
+
+		if(dbObj != null) {
+			obj.setClientId(dbObj.getClientId());
+			obj.setClientDevice(dbObj.getClientDevice());
+		}
 	}
 
 	private <T extends BaseAdmDataEntity> List<T> uploadAdmData(List<T> objs, List<T> dbObjs, String uploadFlag, String timestamp, BaseMapper<T> mapper, String d2mType){
@@ -437,6 +476,7 @@ public class SyncAppImpl implements ISyncApp {
 					continue;
 
 				obj.setCreationTime(timestamp);
+				obj.setModifiedTime(timestamp); //新增时设置modifiedTime,方便后续处理
 				obj.setCreator(AdmConst.CREATOR_APP);
 				obj.setUploadFlag(uploadFlag);
 
@@ -454,14 +494,27 @@ public class SyncAppImpl implements ISyncApp {
 					dbTs = dbObj.getCreationTime();
 					ts = obj.getCreationTime();
 				}
-				if (!ts.equals(dbTs)) {
-					//TODO 时间戳不一致,离线数据无效,暂时跳过处理
-					expired.add(obj);
-				} else {
+//				if (!ts.equals(dbTs)) {
+//					//TODO 时间戳不一致,离线数据无效,暂时跳过处理
+//					expired.add(obj);
+//				} else {
 					obj.setModifiedTime(timestamp);
 					obj.setModifier(AdmConst.CREATOR_APP);
 					obj.setUploadFlag(uploadFlag);
 
+					//合并对象信息点
+					if(dbObj instanceof AdmPipe) {
+						AdmPipe vo = (AdmPipe) obj;
+						AdmPipe dbo = (AdmPipe) dbObj;
+						if(dbo.getInfos() != null) {
+							ObjectNode infos = objectMapper.createObjectNode();
+							infos.setAll(dbo.getInfos());
+							if(vo.getInfos() != null)
+								infos.setAll(vo.getInfos());
+							vo.setInfos(infos);
+						}
+					}
+
 					mapper.updateById(obj);
 
 					if(d2mType != null) {
@@ -471,7 +524,7 @@ public class SyncAppImpl implements ISyncApp {
 							msgModify.add(obj);
 					}
 				}
-			}
+//			}
 		}
 
 		if(d2mType != null)
@@ -486,7 +539,9 @@ public class SyncAppImpl implements ISyncApp {
 		message.setAddItems(msgAdd);
 		message.setModifyItems(msgModify);
 		message.setRemoveItems(msgRemove);
-		syncModel.sendMessageToModel(message);
+
+		if(message.isNotEmpty())
+			syncModel.sendMessageToModel(message);
 	}
 
 	private List<String> buildExpiredIds(List<? extends IAdmEntity> expired){

+ 16 - 10
src/main/java/com/persagy/bdtp/adm/service/impl/SyncOldAdmImpl.java

@@ -28,9 +28,6 @@ import com.persagy.dmp.common.constant.ValidEnum;
 import com.persagy.dmp.common.exception.BusinessException;
 import com.persagy.dmp.common.helper.SpringHelper;
 import com.persagy.dmp.common.lang.PsDateTime;
-import org.locationtech.jts.geom.Coordinate;
-import org.locationtech.jts.geom.GeometryFactory;
-import org.locationtech.jts.geom.LinearRing;
 import org.locationtech.jts.geom.Polygon;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -39,7 +36,6 @@ import org.springframework.transaction.annotation.Transactional;
 import java.io.IOException;
 import java.lang.reflect.Field;
 import java.util.*;
-import java.util.List;
 import java.util.stream.Collectors;
 
 @Service
@@ -114,11 +110,11 @@ public class SyncOldAdmImpl implements ISyncOldAdm {
 	private void syncObjs(List<AdmObject> objs, List<AdmObject> dbItems, List<AdmObject>[] operations, int objMark){
 		HashMap<String, AdmObject> dbMap = new HashMap<>();
 		for (AdmObject dbItem : dbItems){
-			dbMap.put(getFixedIdForSync(dbItem), dbItem);
+			dbMap.put(getFixedIdForSync(dbItem, objMark), dbItem);
 		}
 
 		for(AdmObject obj : objs) {
-			AdmObject dbItem = dbMap.remove(getFixedIdForSync(obj));
+			AdmObject dbItem = dbMap.remove(getFixedIdForSync(obj, objMark));
 			if(dbItem == null) {
 				obj.setD2mState(ValidEnum.TRUE.getType());
 				obj.setDeliveryState(ValidEnum.FALSE.getType());
@@ -144,11 +140,21 @@ public class SyncOldAdmImpl implements ISyncOldAdm {
 	/**
 	 * 同步数据时固定的id,优先取bimId,没有bimId取数据id
 	 */
-	private String getFixedIdForSync(AdmObject obj){
+	private String getFixedIdForSync(AdmObject obj, int objMark){
+		String bimId = null;
 		JsonNode node = obj.getInfo("bimId");
-		if(node == null)
-			return obj.getId();
-		return node.asText();
+		if(node != null)
+			bimId = node.asText();
+
+		if(StrUtil.isNotBlank(bimId))
+			return bimId;
+
+		if(objMark == 1) //建筑
+			return obj.getLocalId();
+		else if(objMark == 2) //楼层
+			return obj.getBuildingId() + ":" + obj.getLocalId();
+
+		return obj.getId();
 	}
 
 	private AdmObject mergeObj(AdmObject obj, AdmObject dbItem, int objMark){

+ 72 - 0
src/main/resources/equip.json

@@ -29,6 +29,24 @@
   {
     "id": "",
     "valid": 1,
+    "code": "FFFASL",
+    "name": "消防强电线路",
+    "objType": "equipment",
+    "majorCode": "FF",
+    "systemCode": "FFFA"
+  },
+  {
+    "id": "",
+    "valid": 1,
+    "code": "FFFAWL",
+    "name": "消防弱电线路",
+    "objType": "equipment",
+    "majorCode": "FF",
+    "systemCode": "FFFA"
+  },
+  {
+    "id": "",
+    "valid": 1,
     "code": "FFFS01",
     "name": "消防关断阀",
     "objType": "equipment",
@@ -88,5 +106,59 @@
     "objType": "equipment",
     "majorCode": "FF",
     "systemCode": "FFFS"
+  },
+  {
+    "id": "",
+    "valid": 1,
+    "code": "FFFS08",
+    "name": "消防止回阀",
+    "objType": "equipment",
+    "majorCode": "FF",
+    "systemCode": "FFFS"
+  },
+  {
+    "id": "",
+    "valid": 1,
+    "code": "FFFS09",
+    "name": "消防减压阀",
+    "objType": "equipment",
+    "majorCode": "FF",
+    "systemCode": "FFFS"
+  },
+  {
+    "id": "",
+    "valid": 1,
+    "code": "FFFS10",
+    "name": "消防电接点压力表",
+    "objType": "equipment",
+    "majorCode": "FF",
+    "systemCode": "FFFS"
+  },
+  {
+    "id": "",
+    "valid": 1,
+    "code": "FFFS11",
+    "name": "雨淋式报警阀组",
+    "objType": "equipment",
+    "majorCode": "FF",
+    "systemCode": "FFFS"
+  },
+  {
+    "id": "",
+    "valid": 1,
+    "code": "FFFSWP",
+    "name": "消防水管",
+    "objType": "equipment",
+    "majorCode": "FF",
+    "systemCode": "FFFS"
+  },
+  {
+    "id": "",
+    "valid": 1,
+    "code": "FFFSGP",
+    "name": "消防气管",
+    "objType": "equipment",
+    "majorCode": "FF",
+    "systemCode": "FFFS"
   }
 ]

+ 9 - 0
src/main/resources/equip_rename.json

@@ -0,0 +1,9 @@
+{
+  "FFFACU": "火灾报警控制器",
+  "FFFALP": "消防联动控制器",
+  "FFFATL": "消防电话主机",
+  "FFFADS": "CRT图形显示装置",
+  "FFFSHT": "消防水炮主机",
+  "FFFSPT": "消防稳压罐",
+  "FFFSCP": "消防水炮现场控制箱"
+}

+ 9 - 0
src/test/java/com/persagy/bdtp/adm/test/AdmApplicationTests.java

@@ -204,4 +204,13 @@ public class AdmApplicationTests {
 		}
 	}
 
+	@Test
+	public void testAdmObject(){
+		try{
+			admObjectMapper.selectList(new QueryWrapper<AdmObject>());
+		}catch (Exception e) {
+
+		}
+	}
+
 }