zhaoyk 3 éve
szülő
commit
9b99a35ca3
42 módosított fájl, 1538 hozzáadás és 242 törlés
  1. 6 0
      src/main/java/com/persagy/bdtp/adm/common/AdmConst.java
  2. 5 12
      src/main/java/com/persagy/bdtp/adm/common/AdmMessageConst.java
  3. 7 0
      src/main/java/com/persagy/bdtp/adm/common/AdmRequest.java
  4. 0 24
      src/main/java/com/persagy/bdtp/adm/common/AdmResult.java
  5. 11 8
      src/main/java/com/persagy/bdtp/adm/controller/AppController.java
  6. 7 2
      src/main/java/com/persagy/bdtp/adm/controller/TestController.java
  7. 2 0
      src/main/java/com/persagy/bdtp/adm/dao/AdmComponentMapper.java
  8. 2 0
      src/main/java/com/persagy/bdtp/adm/dao/AdmInfosConfigMapper.java
  9. 2 0
      src/main/java/com/persagy/bdtp/adm/dao/AdmPipeConfigMapper.java
  10. 2 0
      src/main/java/com/persagy/bdtp/adm/dao/AdmRelsConfigMapper.java
  11. 13 1
      src/main/java/com/persagy/bdtp/adm/entity/AdmComponent.java
  12. 37 1
      src/main/java/com/persagy/bdtp/adm/entity/AdmConfig.java
  13. 1 21
      src/main/java/com/persagy/bdtp/adm/entity/AdmFile.java
  14. 39 3
      src/main/java/com/persagy/bdtp/adm/entity/AdmInfosConfig.java
  15. 35 20
      src/main/java/com/persagy/bdtp/adm/entity/AdmJobSpace.java
  16. 13 1
      src/main/java/com/persagy/bdtp/adm/entity/AdmM2dEquip.java
  17. 35 1
      src/main/java/com/persagy/bdtp/adm/entity/AdmObject.java
  18. 13 1
      src/main/java/com/persagy/bdtp/adm/entity/AdmPipeConfig.java
  19. 39 23
      src/main/java/com/persagy/bdtp/adm/entity/AdmProblemArch.java
  20. 1 18
      src/main/java/com/persagy/bdtp/adm/entity/AdmProblemEquip.java
  21. 33 21
      src/main/java/com/persagy/bdtp/adm/entity/AdmQrCode.java
  22. 11 1
      src/main/java/com/persagy/bdtp/adm/entity/AdmRelation.java
  23. 13 1
      src/main/java/com/persagy/bdtp/adm/entity/AdmRelsConfig.java
  24. 41 0
      src/main/java/com/persagy/bdtp/adm/entity/BaseAdmDataEntity.java
  25. 8 2
      src/main/java/com/persagy/bdtp/adm/entity/D2mMessage.java
  26. 55 0
      src/main/java/com/persagy/bdtp/adm/entity/IAdmBdtpEntity.java
  27. 17 0
      src/main/java/com/persagy/bdtp/adm/entity/IAdmEntity.java
  28. 28 0
      src/main/java/com/persagy/bdtp/adm/entity/SyncData.java
  29. 26 0
      src/main/java/com/persagy/bdtp/adm/entity/UploadRtn.java
  30. 15 7
      src/main/java/com/persagy/bdtp/adm/service/IAdmObjectService.java
  31. 8 1
      src/main/java/com/persagy/bdtp/adm/service/ISyncApp.java
  32. 2 7
      src/main/java/com/persagy/bdtp/adm/service/ISyncModel.java
  33. 5 12
      src/main/java/com/persagy/bdtp/adm/service/impl/AdmObjectServiceImpl.java
  34. 260 21
      src/main/java/com/persagy/bdtp/adm/service/impl/SyncAppImpl.java
  35. 2 7
      src/main/java/com/persagy/bdtp/adm/service/impl/SyncModelImpl.java
  36. 40 17
      src/main/java/com/persagy/bdtp/adm/service/impl/SyncOldAdmImpl.java
  37. 68 0
      src/main/java/com/persagy/bdtp/adm/util/IdGenerator.java
  38. 6 6
      src/main/resources/bootstrap.yml
  39. 147 3
      src/test/java/com/persagy/bdtp/adm/test/AdmApplicationTests.java
  40. 229 0
      src/test/java/com/persagy/bdtp/adm/test/data/InfosCfgs.java
  41. 95 0
      src/test/java/com/persagy/bdtp/adm/test/data/PipeCfgs.java
  42. 159 0
      src/test/java/com/persagy/bdtp/adm/test/data/RelCfgs.java

+ 6 - 0
src/main/java/com/persagy/bdtp/adm/common/AdmConst.java

@@ -36,4 +36,10 @@ public interface AdmConst {
 	/** 数据创建者,模型服务 */
 	String CREATOR_M2D = APP_ID + "_m2d";
 
+	int PIPE_DIRECTION_NONE = 0;
+
+	int PIPE_DIRECTION_FORWARD = 1;
+
+	int PIPE_DIRECTION_BACK = -1;
+
 }

+ 5 - 12
src/main/java/com/persagy/bdtp/adm/common/AdmMessageConst.java

@@ -16,17 +16,10 @@ public interface AdmMessageConst {
 
     String M2D_QUEUE = "bdtp.adm.m2d.queue";
 
-    /** 新增前 */
-    String OPERATE_BEFORE_INSERT = "BeforeInsert";
-    /** 修改前 */
-    String OPERATE_BEFORE_UPDATE = "BeforeUpdate";
-    /** 删除前 */
-    String OPERATE_BEFORE_DELETE = "BeforeDelete";
-    /** 新增后 */
-    String OPERATE_AFTER_INSERT = "AfterInsert";
-    /** 修改后 */
-    String OPERATE_AFTER_UPDATE = "AfterUpdate";
-    /** 删除后 */
-    String OPERATE_AFTER_DELETE = "AfterDelete";
+    String OPERATOR_ADD = "add";
+
+    String OPERATOR_MODIFY = "modify";
+
+    String OPERATOR_REMOVE = "remove";
 
 }

+ 7 - 0
src/main/java/com/persagy/bdtp/adm/common/AdmRequest.java

@@ -1,7 +1,10 @@
 package com.persagy.bdtp.adm.common;
 
+import com.persagy.bdtp.adm.entity.SyncData;
 import lombok.Data;
 
+import java.util.List;
+
 @Data
 public class AdmRequest {
 
@@ -11,10 +14,14 @@ public class AdmRequest {
 
 	private String groupCode;
 
+	private String buildingId;
+
 	private String floorId;
 
 	private String uploadFlag;
 
 	private String lastDownloadTime;
 
+	private SyncData uploadData;
+
 }

+ 0 - 24
src/main/java/com/persagy/bdtp/adm/common/AdmResult.java

@@ -29,30 +29,6 @@ public class AdmResult<T> {
 		this.data = commonResult.getData();
 	}
 
-	public String getCode() {
-		return code;
-	}
-
-	public void setCode(String code) {
-		this.code = code;
-	}
-
-	public String getMessage() {
-		return message;
-	}
-
-	public void setMessage(String message) {
-		this.message = message;
-	}
-
-	public T getData() {
-		return data;
-	}
-
-	public void setData(T data) {
-		this.data = data;
-	}
-
 	public static <T> AdmResult<T> success(T data){
 		return new AdmResult<>(ResponseCode.A00000.getCode(), null, data);
 	}

+ 11 - 8
src/main/java/com/persagy/bdtp/adm/controller/AppController.java

@@ -3,6 +3,8 @@ package com.persagy.bdtp.adm.controller;
 import com.persagy.bdtp.adm.client.OldAdmClient;
 import com.persagy.bdtp.adm.common.AdmRequest;
 import com.persagy.bdtp.adm.common.AdmResult;
+import com.persagy.bdtp.adm.entity.SyncData;
+import com.persagy.bdtp.adm.entity.UploadRtn;
 import com.persagy.bdtp.adm.service.ISyncApp;
 import feign.Response;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -70,8 +72,13 @@ public class AppController {
 	}
 
 	@RequestMapping("/download")
-	public AdmResult<Map<String, Object>> download(@RequestBody AdmRequest req){
-		return AdmResult.success(syncApp.downloadFloorData(req.getProjectId(), req.getFloorId()));
+	public AdmResult<SyncData> download(@RequestBody AdmRequest req){
+		return AdmResult.success(syncApp.downloadBuildingData(req.getProjectId(), req.getBuildingId(), req.getUploadFlag(), req.getLastDownloadTime()));
+	}
+
+	@RequestMapping("/downloadFl")
+	public AdmResult<Map<String, Object>> downloadFl(@RequestBody AdmRequest req){
+		return AdmResult.success(syncApp.downloadFloorData(req.getProjectId(), req.getFloorId(), req.getUploadFlag(), req.getLastDownloadTime()));
 	}
 
 	@RequestMapping("/downloadMap")
@@ -101,12 +108,8 @@ public class AppController {
 	}
 
 	@RequestMapping("/upload")
-	public AdmResult upload(){
-		//任务状态数据
-		//核查问题数据
-		//设备数据
-		//关系数据
-		return null;
+	public AdmResult<UploadRtn> upload(@RequestBody AdmRequest req){
+		return AdmResult.success(syncApp.uploadData(req.getUploadData(), req.getProjectId(), req.getUploadFlag()));
 	}
 
 	@PostMapping("/uploadFile")

+ 7 - 2
src/main/java/com/persagy/bdtp/adm/controller/TestController.java

@@ -1,17 +1,20 @@
 package com.persagy.bdtp.adm.controller;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.persagy.bdtp.adm.common.AdmMessageConst;
 import com.persagy.bdtp.adm.common.AdmRequest;
 import com.persagy.bdtp.adm.common.AdmResult;
 import com.persagy.bdtp.adm.dao.AdmObjectMapper;
 import com.persagy.bdtp.adm.entity.AdmObject;
-import com.persagy.bdtp.adm.entity.Pagination;
+import com.persagy.bdtp.adm.entity.D2mMessage;
 import com.persagy.bdtp.adm.service.ISyncModel;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.util.Arrays;
+
 @RestController
 @RequestMapping("/test")
 public class TestController {
@@ -26,7 +29,9 @@ public class TestController {
 	public AdmResult<Object> testMq(@RequestBody AdmRequest req){
 		AdmObject obj = admObjectMapper.selectOne(new QueryWrapper<AdmObject>().eq("id", "Eq00022200023a8d5a59a7fb49a89dfa6ae746518bc2"));
 		obj.getInfos().put("comp_type", "FFFAAL-声光报警器");
-		syncModel.sendMessageToModel(ISyncModel.OPERATOR_ADD, obj);
+		D2mMessage msg = new D2mMessage();
+		msg.setAddItems(Arrays.asList(obj));
+		syncModel.sendMessageToModel(msg);
 		return AdmResult.success(null);
 	}
 

+ 2 - 0
src/main/java/com/persagy/bdtp/adm/dao/AdmComponentMapper.java

@@ -2,7 +2,9 @@ package com.persagy.bdtp.adm.dao;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.persagy.bdtp.adm.entity.AdmComponent;
+import org.apache.ibatis.annotations.Mapper;
 
+@Mapper
 public interface AdmComponentMapper extends BaseMapper<AdmComponent> {
 
 }

+ 2 - 0
src/main/java/com/persagy/bdtp/adm/dao/AdmInfosConfigMapper.java

@@ -2,7 +2,9 @@ package com.persagy.bdtp.adm.dao;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.persagy.bdtp.adm.entity.AdmInfosConfig;
+import org.apache.ibatis.annotations.Mapper;
 
+@Mapper
 public interface AdmInfosConfigMapper extends BaseMapper<AdmInfosConfig> {
 
 }

+ 2 - 0
src/main/java/com/persagy/bdtp/adm/dao/AdmPipeConfigMapper.java

@@ -2,7 +2,9 @@ package com.persagy.bdtp.adm.dao;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.persagy.bdtp.adm.entity.AdmPipeConfig;
+import org.apache.ibatis.annotations.Mapper;
 
+@Mapper
 public interface AdmPipeConfigMapper extends BaseMapper<AdmPipeConfig> {
 
 }

+ 2 - 0
src/main/java/com/persagy/bdtp/adm/dao/AdmRelsConfigMapper.java

@@ -2,7 +2,9 @@ package com.persagy.bdtp.adm.dao;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.persagy.bdtp.adm.entity.AdmRelsConfig;
+import org.apache.ibatis.annotations.Mapper;
 
+@Mapper
 public interface AdmRelsConfigMapper extends BaseMapper<AdmRelsConfig> {
 
 }

+ 13 - 1
src/main/java/com/persagy/bdtp/adm/entity/AdmComponent.java

@@ -5,10 +5,12 @@ import lombok.Data;
 
 @Data
 @TableName(value = "adm_component",autoResultMap = true)
-public class AdmComponent {
+public class AdmComponent implements IAdmEntity {
 
 	private String id;
 
+	private String projectId;
+
 	private String compCode;
 
 	private String compName;
@@ -17,4 +19,14 @@ public class AdmComponent {
 
 	private String classCode;
 
+	@Override
+	public void serializeJsonProp() {
+
+	}
+
+	@Override
+	public void deserializeJsonProp() {
+
+	}
+
 }

+ 37 - 1
src/main/java/com/persagy/bdtp/adm/entity/AdmConfig.java

@@ -1,18 +1,26 @@
 package com.persagy.bdtp.adm.entity;
 
+import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
+import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.persagy.dmp.common.helper.SpringHelper;
 import lombok.Data;
 
+import java.io.IOException;
+
 @Data
 @TableName(value = "adm_config",autoResultMap = true)
-public class AdmConfig {
+public class AdmConfig implements IAdmEntity {
 
 	private String id;
 
+	private String projectId;
+
 	private String name;
 
 	private String code;
@@ -22,4 +30,32 @@ public class AdmConfig {
 	)
 	private JsonNode data;
 
+	private String strData;
+
+	@Override
+	public void serializeJsonProp() {
+		if(data != null) {
+			ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
+			try {
+				strData = objectMapper.writeValueAsString(data);
+			} catch (JsonProcessingException e) {
+
+			}
+			data = null;
+		}
+	}
+
+	@Override
+	public void deserializeJsonProp() {
+		if(StrUtil.isNotBlank(strData)) {
+			ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
+			try {
+				data = objectMapper.readValue(strData, JsonNode.class);
+			} catch (IOException e) {
+
+			}
+			strData = null;
+		}
+	}
+
 }

+ 1 - 21
src/main/java/com/persagy/bdtp/adm/entity/AdmFile.java

@@ -5,9 +5,7 @@ import lombok.Data;
 
 @Data
 @TableName(value = "adm_file",autoResultMap = true)
-public class AdmFile {
-
-    private String id;
+public class AdmFile extends BaseAdmDataEntity {
 
     private String fileType;
 
@@ -25,22 +23,4 @@ public class AdmFile {
 
     private Integer orderNum;
 
-    private String projectId;
-
-    private String floorId;
-
-    private String buildingId;
-
-    private String creator;
-
-    private String creationTime;
-
-    private String modifier;
-
-    private String modifiedTime;
-
-    private Integer valid;
-
-    private String uploadFlag;
-
 }

+ 39 - 3
src/main/java/com/persagy/bdtp/adm/entity/AdmInfosConfig.java

@@ -1,17 +1,25 @@
 package com.persagy.bdtp.adm.entity;
 
+import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
-import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.persagy.dmp.common.helper.SpringHelper;
 import lombok.Data;
 
+import java.io.IOException;
+import java.util.List;
+
 @Data
 @TableName(value = "adm_infos_config",autoResultMap = true)
-public class AdmInfosConfig {
+public class AdmInfosConfig implements IAdmEntity {
 
     private String id;
 
+    private String projectId;
+
     private String objType;
 
     private String name;
@@ -25,6 +33,34 @@ public class AdmInfosConfig {
     @TableField(
             typeHandler = JacksonTypeHandler.class
     )
-    private ObjectNode infos;
+    private List<Object> infos;
+
+    private String strInfos;
+
+    @Override
+    public void serializeJsonProp() {
+        if(infos != null) {
+            ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
+            try {
+                strInfos = objectMapper.writeValueAsString(infos);
+            } catch (JsonProcessingException e) {
+
+            }
+            infos = null;
+        }
+    }
+
+    @Override
+    public void deserializeJsonProp() {
+        if(StrUtil.isNotBlank(strInfos)) {
+            ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
+            try {
+                infos = objectMapper.readValue(strInfos, List.class);
+            } catch (IOException e) {
+
+            }
+            strInfos = null;
+        }
+    }
 
 }

+ 35 - 20
src/main/java/com/persagy/bdtp/adm/entity/AdmJobSpace.java

@@ -1,16 +1,21 @@
 package com.persagy.bdtp.adm.entity;
 
+import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.persagy.dmp.common.helper.SpringHelper;
 import lombok.Data;
 
+import java.io.IOException;
+import java.util.List;
+
 @Data
 @TableName(value = "adm_job_space",autoResultMap = true)
-public class AdmJobSpace {
-
-    private String id;
+public class AdmJobSpace extends BaseAdmDataEntity {
 
     private String workId;
 
@@ -24,27 +29,37 @@ public class AdmJobSpace {
 
     private Integer equipState;
 
-    private String projectId;
-
-    private String buildingId;
-
-    private String floorId;
-
-    private String creator;
-
-    private String creationTime;
-
-    private String modifier;
-
-    private String modifiedTime;
-
-    private Integer valid;
-
     @TableField(
             typeHandler = JacksonTypeHandler.class
     )
     private ArrayNode outline;
 
-    private String uploadFlag;
+    private String strOutline;
+
+    @Override
+    public void serializeJsonProp() {
+        if(outline != null) {
+            ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
+            try {
+                strOutline = objectMapper.writeValueAsString(outline);
+            } catch (JsonProcessingException e) {
+
+            }
+            outline = null;
+        }
+    }
+
+    @Override
+    public void deserializeJsonProp() {
+        if(StrUtil.isNotBlank(strOutline)) {
+            ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
+            try {
+                outline = objectMapper.readValue(strOutline, ArrayNode.class);
+            } catch (IOException e) {
+
+            }
+            strOutline = null;
+        }
+    }
 
 }

+ 13 - 1
src/main/java/com/persagy/bdtp/adm/entity/AdmM2dEquip.java

@@ -5,10 +5,12 @@ import lombok.Data;
 
 @Data
 @TableName(value = "adm_m2d_equip",autoResultMap = true)
-public class AdmM2dEquip {
+public class AdmM2dEquip implements IAdmEntity {
 
     private String id;
 
+    private String projectId;
+
     private String name;
 
     private String majorCode;
@@ -17,4 +19,14 @@ public class AdmM2dEquip {
 
     private String classCode;
 
+    @Override
+    public void serializeJsonProp() {
+
+    }
+
+    @Override
+    public void deserializeJsonProp() {
+
+    }
+
 }

+ 35 - 1
src/main/java/com/persagy/bdtp/adm/entity/AdmObject.java

@@ -1,14 +1,20 @@
 package com.persagy.bdtp.adm.entity;
 
+import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.annotation.TableName;
+import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.persagy.dmp.common.helper.SpringHelper;
 import com.persagy.dmp.digital.entity.ObjectDigital;
 import lombok.Data;
 
+import java.io.IOException;
+
 @Data
 @TableName(value = "adm_object",autoResultMap = true)
-public class AdmObject extends ObjectDigital {
+public class AdmObject extends ObjectDigital implements IAdmBdtpEntity {
 
 	/** 创建对象的本地设备(移动端) */
 	private String clientDevice;
@@ -29,6 +35,8 @@ public class AdmObject extends ObjectDigital {
 	/** app端上传数据标记 */
 	private String uploadFlag;
 
+	private String strInfos;
+
 	public JsonNode getInfo(String infoCode){
 		ObjectNode node = getInfos();
 		if(node != null)
@@ -36,4 +44,30 @@ public class AdmObject extends ObjectDigital {
 		return null;
 	}
 
+	@Override
+	public void serializeJsonProp() {
+		if(getInfos() != null) {
+			ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
+			try {
+				setStrInfos(objectMapper.writeValueAsString(getInfos()));
+			} catch (JsonProcessingException e) {
+
+			}
+			setInfos(null);
+		}
+	}
+
+	@Override
+	public void deserializeJsonProp() {
+		if(StrUtil.isNotBlank(strInfos)) {
+			ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
+			try {
+				setInfos(objectMapper.readValue(strInfos, ObjectNode.class));
+			} catch (IOException e) {
+
+			}
+			setStrInfos(null);
+		}
+	}
+
 }

+ 13 - 1
src/main/java/com/persagy/bdtp/adm/entity/AdmPipeConfig.java

@@ -5,10 +5,12 @@ import lombok.Data;
 
 @Data
 @TableName(value = "adm_pipe_config",autoResultMap = true)
-public class AdmPipeConfig {
+public class AdmPipeConfig implements IAdmEntity {
 
     private String id;
 
+    private String projectId;
+
     private String classCodeFrom;
 
     private String pipeType;
@@ -21,4 +23,14 @@ public class AdmPipeConfig {
 
     private String classCodeTo;
 
+    @Override
+    public void serializeJsonProp() {
+
+    }
+
+    @Override
+    public void deserializeJsonProp() {
+
+    }
+
 }

+ 39 - 23
src/main/java/com/persagy/bdtp/adm/entity/AdmProblemArch.java

@@ -1,48 +1,64 @@
 package com.persagy.bdtp.adm.entity;
 
+import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.persagy.dmp.common.helper.SpringHelper;
 import lombok.Data;
 
+import java.io.IOException;
 import java.util.List;
 
 @Data
 @TableName(value = "adm_problem_arch",autoResultMap = true)
-public class AdmProblemArch {
-
-    private String id;
+public class AdmProblemArch extends BaseAdmDataEntity {
 
     private String workId;
 
-    private String floorId;
-
-    private String projectId;
-
-    private String buildingId;
-
     private String geomType;
 
+    @TableField(
+            typeHandler = JacksonTypeHandler.class
+    )
+    private List<ObjectNode> geom;
+
     private String problemType;
 
     private String message;
 
     private Integer problemState;
 
-    private String creator;
-
-    private String creationTime;
-
-    private String modifier;
-
-    private String modifiedTime;
-
-    private String uploadFlag;
-
-    @TableField(
-            typeHandler = JacksonTypeHandler.class
-    )
-    private List<ObjectNode> geom;
+    private String strGeom;
+
+    @Override
+    public void serializeJsonProp() {
+        if(geom != null) {
+            ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
+            try {
+                strGeom = objectMapper.writeValueAsString(geom);
+            } catch (JsonProcessingException e) {
+
+            }
+            geom = null;
+        }
+    }
+
+    @Override
+    public void deserializeJsonProp() {
+        if(StrUtil.isNotBlank(strGeom)) {
+            ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
+            try {
+                geom = objectMapper.readValue(strGeom, new TypeReference<List<ObjectNode>>(){});
+            } catch (IOException e) {
+
+            }
+            strGeom = null;
+        }
+    }
 
 }

+ 1 - 18
src/main/java/com/persagy/bdtp/adm/entity/AdmProblemEquip.java

@@ -5,17 +5,10 @@ import lombok.Data;
 
 @Data
 @TableName(value = "adm_problem_equip",autoResultMap = true)
-public class AdmProblemEquip {
-    private String id;
+public class AdmProblemEquip extends BaseAdmDataEntity {
 
     private String workId;
 
-    private String floorId;
-
-    private String projectId;
-
-    private String buildingId;
-
     private String equipId;
 
     private String problemType;
@@ -24,14 +17,4 @@ public class AdmProblemEquip {
 
     private Integer problemState;
 
-    private String creator;
-
-    private String creationTime;
-
-    private String modifier;
-
-    private String modifiedTime;
-
-    private String uploadFlag;
-
 }

+ 33 - 21
src/main/java/com/persagy/bdtp/adm/entity/AdmQrCode.java

@@ -1,46 +1,58 @@
 package com.persagy.bdtp.adm.entity;
 
+import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.persagy.dmp.common.helper.SpringHelper;
 import lombok.Data;
 
-import java.util.List;
+import java.io.IOException;
 
 @Data
 @TableName(value = "adm_qr_code",autoResultMap = true)
-public class AdmQrCode {
-
-    private String id;
+public class AdmQrCode extends BaseAdmDataEntity {
 
     private String qrCode;
 
     private String objId;
 
-    private String floorId;
-
     @TableField(
             typeHandler = JacksonTypeHandler.class
     )
     private ObjectNode location;
 
-    private String remark;
-
-    private String projectId;
-
-    private String buildingId;
+    private String strLocation;
 
-    private String creator;
-
-    private String creationTime;
-
-    private String modifier;
-
-    private String modifiedTime;
-
-    private Integer valid;
+    private String remark;
 
-    private String uploadFlag;
+    @Override
+    public void serializeJsonProp() {
+        if(location != null) {
+            ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
+            try {
+                strLocation = objectMapper.writeValueAsString(location);
+            } catch (JsonProcessingException e) {
+
+            }
+            location = null;
+        }
+    }
+
+    @Override
+    public void deserializeJsonProp() {
+        if(StrUtil.isNotBlank(strLocation)) {
+            ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
+            try {
+                location = objectMapper.readValue(strLocation, ObjectNode.class);
+            } catch (IOException e) {
+
+            }
+            strLocation = null;
+        }
+    }
 
 }

+ 11 - 1
src/main/java/com/persagy/bdtp/adm/entity/AdmRelation.java

@@ -6,7 +6,7 @@ import lombok.Data;
 
 @Data
 @TableName(value = "adm_relation",autoResultMap = true)
-public class AdmRelation extends ObjectRelation {
+public class AdmRelation extends ObjectRelation implements IAdmBdtpEntity {
 
     private String clientDevice;
 
@@ -22,4 +22,14 @@ public class AdmRelation extends ObjectRelation {
 
     private String uploadFlag;
 
+    @Override
+    public void serializeJsonProp() {
+
+    }
+
+    @Override
+    public void deserializeJsonProp() {
+
+    }
+
 }

+ 13 - 1
src/main/java/com/persagy/bdtp/adm/entity/AdmRelsConfig.java

@@ -5,10 +5,12 @@ import lombok.Data;
 
 @Data
 @TableName(value = "adm_rels_config",autoResultMap = true)
-public class AdmRelsConfig {
+public class AdmRelsConfig implements IAdmEntity {
 
     private String id;
 
+    private String projectId;
+
     private String objTypeFrom;
 
     private String classCodeFrom;
@@ -21,4 +23,14 @@ public class AdmRelsConfig {
 
     private String classCodeTo;
 
+    @Override
+    public void serializeJsonProp() {
+
+    }
+
+    @Override
+    public void deserializeJsonProp() {
+
+    }
+
 }

+ 41 - 0
src/main/java/com/persagy/bdtp/adm/entity/BaseAdmDataEntity.java

@@ -0,0 +1,41 @@
+package com.persagy.bdtp.adm.entity;
+
+import lombok.Data;
+
+/**
+ * 数据实体基类
+ */
+@Data
+abstract public class BaseAdmDataEntity implements IAdmEntity {
+
+	protected String id;
+
+	protected String projectId;
+
+	protected String buildingId;
+
+	protected String floorId;
+
+	protected String creator;
+
+	protected String creationTime;
+
+	protected String modifier;
+
+	protected String modifiedTime;
+
+	protected Integer valid;
+
+	protected String uploadFlag;
+
+	@Override
+	public void serializeJsonProp() {
+
+	}
+
+	@Override
+	public void deserializeJsonProp() {
+
+	}
+
+}

+ 8 - 2
src/main/java/com/persagy/bdtp/adm/entity/D2mMessage.java

@@ -2,11 +2,17 @@ package com.persagy.bdtp.adm.entity;
 
 import lombok.Data;
 
+import java.util.List;
+
 @Data
 public class D2mMessage {
 
-	private String operation;
+	private String itemType; //object|relation|pipe
+
+	private List<?> addItems;
+
+	private List<?> modifyItems;
 
-	private Object objs;
+	private List<?> removeItems;
 
 }

+ 55 - 0
src/main/java/com/persagy/bdtp/adm/entity/IAdmBdtpEntity.java

@@ -0,0 +1,55 @@
+package com.persagy.bdtp.adm.entity;
+
+import com.persagy.dmp.common.lang.PsDateTime;
+
+public interface IAdmBdtpEntity extends IAdmEntity{
+
+	String getBuildingId();
+
+	void setBuildingId(String buildingId);
+
+	String getFloorId();
+
+	void setFloorId(String floorId);
+
+	String getCreator();
+
+	void setCreator(String creator);
+
+	PsDateTime getCreationTime();
+
+	void setCreationTime(PsDateTime creationTime);
+
+	String getModifier();
+
+	void setModifier(String modifier);
+
+	PsDateTime getModifiedTime();
+
+	void setModifiedTime(PsDateTime modifiedTime);
+
+	Integer getValid();
+
+	void setValid(Integer valid);
+
+	String getUploadFlag();
+
+	void setUploadFlag(String uploadFlag);
+
+	String getClientDevice();
+
+	void setClientDevice(String clientDevice);
+
+	String getClientId();
+
+	void setClientId(String clientId);
+
+	Integer getD2mState();
+
+	void setD2mState(Integer d2mState);
+
+	Integer getDeliveryState();
+
+	void setDeliveryState(Integer deliveryState);
+
+}

+ 17 - 0
src/main/java/com/persagy/bdtp/adm/entity/IAdmEntity.java

@@ -0,0 +1,17 @@
+package com.persagy.bdtp.adm.entity;
+
+public interface IAdmEntity {
+
+	String getId();
+
+	void setId(String id);
+
+	String getProjectId();
+
+	void setProjectId(String projectId);
+
+	void serializeJsonProp();
+
+	void deserializeJsonProp();
+
+}

+ 28 - 0
src/main/java/com/persagy/bdtp/adm/entity/SyncData.java

@@ -0,0 +1,28 @@
+package com.persagy.bdtp.adm.entity;
+
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+public class SyncData {
+
+	private String buildingId;
+
+	private List<AdmObject> objects;
+
+	private List<AdmRelation> relations;
+
+	private List<AdmJobSpace> jobSpace;
+
+	private List<AdmProblemArch> problemArch;
+
+	private List<AdmProblemEquip> problemEquip;
+
+	private List<AdmFile> file;
+
+	private List<AdmQrCode> qrCode;
+
+	private String timestamp;
+
+}

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

@@ -0,0 +1,26 @@
+package com.persagy.bdtp.adm.entity;
+
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+public class UploadRtn {
+
+	private List<String> expiredObjectIds;
+
+	private List<String> expiredRelationIds;
+
+	private List<String> expiredJobSpaceIds;
+
+	private List<String> expiredProblemArchIds;
+
+	private List<String> expiredProblemEquipIds;
+
+	private List<String> expiredFileIds;
+
+	private List<String> expiredQrCodeIds;
+
+	private String timestamp;
+
+}

+ 15 - 7
src/main/java/com/persagy/bdtp/adm/service/IAdmObjectService.java

@@ -26,13 +26,21 @@ public interface IAdmObjectService {
 	 */
 	List<AdmObject> queryBdAndFl(String... projectIds);
 
-	/**
-	 * 查询楼层下的数据(空间、设备)
-	 * @param projectId 项目id
-	 * @param floorId 楼层id
-	 * @return
-	 */
-	List<AdmObject> queryByFloor(String projectId, String floorId);
+//	/**
+//	 * 查询楼层下的数据(空间、设备)
+//	 * @param projectId 项目id
+//	 * @param floorId 楼层id
+//	 * @return
+//	 */
+//	List<AdmObject> queryByFloor(String projectId, String floorId);
+//
+//	/**
+//	 * 查询建筑下的数据(空间、设备)
+//	 * @param projectId 项目id
+//	 * @param buildingId 楼层id
+//	 * @return
+//	 */
+//	List<AdmObject> queryByBuilding(String projectId, String buildingId);
 
 	/**
 	 * 按类型查询正向交付的实体对象

+ 8 - 1
src/main/java/com/persagy/bdtp/adm/service/ISyncApp.java

@@ -1,5 +1,8 @@
 package com.persagy.bdtp.adm.service;
 
+import com.persagy.bdtp.adm.entity.SyncData;
+import com.persagy.bdtp.adm.entity.UploadRtn;
+
 import java.util.Map;
 
 /**
@@ -11,6 +14,10 @@ public interface ISyncApp {
 
 	Map<String, Object> downloadFrameData(String groupCode, String projectId, String userId);
 
-	Map<String, Object> downloadFloorData(String projectId, String floorId);
+	Map<String, Object> downloadFloorData(String projectId, String floorId, String uploadFlag, String lastDownloadTime);
+
+	SyncData downloadBuildingData(String projectId, String buildingId, String uploadFlag, String lastDownloadTime);
+
+	UploadRtn uploadData(SyncData uploadData, String projectId, String uploadFlag);
 
 }

+ 2 - 7
src/main/java/com/persagy/bdtp/adm/service/ISyncModel.java

@@ -1,5 +1,6 @@
 package com.persagy.bdtp.adm.service;
 
+import com.persagy.bdtp.adm.entity.D2mMessage;
 import org.springframework.amqp.core.Message;
 
 /**
@@ -7,13 +8,7 @@ import org.springframework.amqp.core.Message;
  */
 public interface ISyncModel {
 
-	String OPERATOR_ADD = "add";
-
-	String OPERATOR_MODIFY = "modify";
-
-	String OPERATOR_REMOVE = "remove";
-
-	void sendMessageToModel(String operation, Object entity);
+	void sendMessageToModel(D2mMessage message);
 
 	void handleModelMessage(String message, Message vo);
 

+ 5 - 12
src/main/java/com/persagy/bdtp/adm/service/impl/AdmObjectServiceImpl.java

@@ -18,7 +18,7 @@ import java.util.List;
 @RequiredArgsConstructor
 public class AdmObjectServiceImpl extends ServiceImpl<AdmObjectMapper, AdmObject> implements IAdmObjectService {
 
-	private final AdmObjectMapper objectMapper;
+	private final AdmObjectMapper admObjMapper;
 
 	@Override
 	public List<AdmObject> insert(List<AdmObject> voList) {
@@ -26,7 +26,7 @@ public class AdmObjectServiceImpl extends ServiceImpl<AdmObjectMapper, AdmObject
 			return null;
 
 		for(AdmObject obj : voList) {
-			objectMapper.insert(obj);
+			admObjMapper.insert(obj);
 			// 新增后消息
 			//messageSender.sendMessage(DigitalMessageConstant.OPERATE_AFTER_INSERT, null, vo, false);
 		}
@@ -40,7 +40,7 @@ public class AdmObjectServiceImpl extends ServiceImpl<AdmObjectMapper, AdmObject
 			return null;
 
 		for(AdmObject obj : voList) {
-			objectMapper.updateById(obj);
+			admObjMapper.updateById(obj);
 			// 更新后消息
 			//messageSender.sendMessage(DigitalMessageConstant.OPERATE_AFTER_INSERT, null, vo, false);
 		}
@@ -52,21 +52,14 @@ public class AdmObjectServiceImpl extends ServiceImpl<AdmObjectMapper, AdmObject
 	public List<AdmObject> queryBdAndFl(String... projectIds) {
 		QueryWrapper<AdmObject> queryWrapper = new QueryWrapper<>();
 		queryWrapper.in("project_id", projectIds).in("obj_type", AdmConst.OBJ_TYPE_BUILDING, AdmConst.OBJ_TYPE_FLOOR);
-		return objectMapper.selectList(queryWrapper);
-	}
-
-	@Override
-	public List<AdmObject> queryByFloor(String projectId, String floorId) {
-		QueryWrapper<AdmObject> queryWrapper = new QueryWrapper<>();
-		queryWrapper.eq("project_id", projectId).eq("floor_id", floorId);
-		return objectMapper.selectList(queryWrapper);
+		return admObjMapper.selectList(queryWrapper);
 	}
 
 	@Override
 	public List<AdmObject> queryM2dByObjType(String projectId, String objType) {
 		QueryWrapper<AdmObject> queryWrapper = new QueryWrapper<>();
 		queryWrapper.in("project_id", projectId).eq("obj_type", objType).isNull("client_id");
-		return objectMapper.selectList(queryWrapper);
+		return admObjMapper.selectList(queryWrapper);
 	}
 
 }

+ 260 - 21
src/main/java/com/persagy/bdtp/adm/service/impl/SyncAppImpl.java

@@ -1,11 +1,16 @@
 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.StrUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.fasterxml.jackson.databind.ObjectMapper;
 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.*;
@@ -13,10 +18,13 @@ import com.persagy.bdtp.adm.entity.oldadm.OProject;
 import com.persagy.bdtp.adm.service.*;
 import com.persagy.dmp.basic.model.QueryCriteria;
 import com.persagy.dmp.common.constant.ResponseCode;
+import com.persagy.dmp.common.constant.ValidEnum;
 import com.persagy.dmp.common.helper.SpringHelper;
+import com.persagy.dmp.common.lang.PsDateTime;
 import com.persagy.dmp.define.entity.RelationDefine;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.util.*;
 
@@ -38,6 +46,13 @@ public class SyncAppImpl implements ISyncApp {
 	@Autowired
 	private IConfigService configService;
 
+
+	@Autowired
+	private AdmObjectMapper admObjMapper;
+
+	@Autowired
+	private AdmRelationMapper relationMapper;
+
 	@Autowired
 	private AdmJobSpaceMapper jobSpaceMapper;
 
@@ -48,19 +63,19 @@ public class SyncAppImpl implements ISyncApp {
 	private AdmProblemEquipMapper problemEquipMapper;
 
 	@Autowired
-	private AdmRelationMapper relationMapper;
-
-	@Autowired
 	private AdmFileMapper fileMapper;
 
 	@Autowired
 	private AdmQrCodeMapper qrCodeMapper;
 
+	@Autowired
+	private ISyncModel syncModel;
+
 	@Override
 	public Map<String, Object> downloadDictAndConfig(String groupCode, String projectId, String userId) {
 		Map<String, Object> dict = queryDict(groupCode, projectId, userId);
 
-		//TODO 配置数据查询
+		//配置数据查询
 		List<AdmM2dEquip> m2dTypes = configService.queryM2dEquip(projectId);
 		List<AdmInfosConfig> infosConfig = configService.queryInfosConfig(projectId);
 		List<AdmRelsConfig> relConfig = configService.queryRelsConfig(projectId);
@@ -71,10 +86,10 @@ public class SyncAppImpl implements ISyncApp {
 		HashMap<String, Object> data = new HashMap<>();
 		data.put("dict", dict);
 		data.put("m2dTypes", m2dTypes);
-		data.put("infosConfig", infosConfig);
+		data.put("infosConfig", serializeJsonProp(infosConfig));
 		data.put("relConfig", relConfig);
 		data.put("pipeConfig", pipeConfig);
-		data.put("config", config);
+		data.put("config", serializeJsonProp(config));
 		data.put("component", component);
 
 		return data;
@@ -154,44 +169,268 @@ public class SyncAppImpl implements ISyncApp {
 
 		HashMap<String, Object> data = new HashMap<>();
 		data.put("projects", prjList);
-		data.put("buildingsAndFloors", bdAndFl);
+		data.put("buildingsAndFloors", serializeJsonProp(bdAndFl));
 		return data;
 	}
 
 	@Override
-	public Map<String, Object> downloadFloorData(String projectId, String floorId) {
-		List<AdmObject> floorData = objectService.queryByFloor(projectId, floorId);
-		List<AdmRelation> floorRel = relationMapper.selectList(buildQueryWrapperForFloor(new QueryWrapper<AdmRelation>(), projectId, floorId, true));
+	public Map<String, Object> downloadFloorData(String projectId, String floorId, String uploadFlag, String lastDownloadTime) {
+		List<AdmObject> floorData = admObjMapper.selectList(buildQueryWrapperForFloor(new QueryWrapper<AdmObject>(), projectId, floorId, true, uploadFlag, lastDownloadTime));
+		List<AdmRelation> floorRel = relationMapper.selectList(buildQueryWrapperForFloor(new QueryWrapper<AdmRelation>(), projectId, floorId, true, uploadFlag, lastDownloadTime));
 
-		//TODO 任务相关数据查询
-		List<AdmJobSpace> jobSpace = jobSpaceMapper.selectList(buildQueryWrapperForFloor(new QueryWrapper<AdmJobSpace>(), projectId, floorId, false));
-		List<AdmProblemArch> problemArch = problemArchMapper.selectList(buildQueryWrapperForFloor(new QueryWrapper<AdmProblemArch>(), projectId, floorId, false));
-		List<AdmProblemEquip> problemEquip = problemEquipMapper.selectList(buildQueryWrapperForFloor(new QueryWrapper<AdmProblemEquip>(), projectId, floorId, false));
-		List<AdmFile> file = fileMapper.selectList(buildQueryWrapperForFloor(new QueryWrapper<AdmFile>(), projectId, floorId, false));
-		List<AdmQrCode> qrCode = qrCodeMapper.selectList(buildQueryWrapperForFloor(new QueryWrapper<AdmQrCode>(), projectId, floorId, false));
+		//任务相关数据查询
+		List<AdmJobSpace> jobSpace = jobSpaceMapper.selectList(buildQueryWrapperForFloor(new QueryWrapper<AdmJobSpace>(), projectId, floorId, false, uploadFlag, lastDownloadTime));
+		List<AdmProblemArch> problemArch = problemArchMapper.selectList(buildQueryWrapperForFloor(new QueryWrapper<AdmProblemArch>(), projectId, floorId, false, uploadFlag, lastDownloadTime));
+		List<AdmProblemEquip> problemEquip = problemEquipMapper.selectList(buildQueryWrapperForFloor(new QueryWrapper<AdmProblemEquip>(), projectId, floorId, false, uploadFlag, lastDownloadTime));
+		List<AdmFile> file = fileMapper.selectList(buildQueryWrapperForFloor(new QueryWrapper<AdmFile>(), projectId, floorId, false, uploadFlag, lastDownloadTime));
+		List<AdmQrCode> qrCode = qrCodeMapper.selectList(buildQueryWrapperForFloor(new QueryWrapper<AdmQrCode>(), projectId, floorId, false, uploadFlag, lastDownloadTime));
 
 		HashMap<String, Object> data = new HashMap<>();
 		data.put("floorId", floorId);
 
-		data.put("objects", floorData);
+		data.put("objects", serializeJsonProp(floorData));
 		data.put("relations", floorRel);
 
-		data.put("jobSpace", jobSpace);
-		data.put("problemArch", problemArch);
+		data.put("jobSpace", serializeJsonProp(jobSpace));
+		data.put("problemArch", serializeJsonProp(problemArch));
 		data.put("problemEquip", problemEquip);
 		data.put("file", file);
-		data.put("qrCode", qrCode);
+		data.put("qrCode", serializeJsonProp(qrCode));
+		data.put("timestamp", DateUtil.format(new Date(), DatePattern.PURE_DATETIME_PATTERN));
 
 		return data;
 	}
 
-	private <T> QueryWrapper<T> buildQueryWrapperForFloor(QueryWrapper<T> wrapper, String projectId, String floorId, boolean floorIdNull){
+	private <T> QueryWrapper<T> buildQueryWrapperForFloor(QueryWrapper<T> wrapper, String projectId, String floorId, boolean floorIdNull, String uploadFlag, String lastDownloadTime){
 		wrapper.eq("project_id", projectId);
 		if(!floorIdNull)
 			wrapper.eq("floor_id", floorId);
 		else
 			wrapper.and(w -> w.eq("floor_id", floorId).or().isNull("floor_id"));
+		applyUploadFlag(wrapper, uploadFlag,lastDownloadTime);
 		return wrapper;
 	}
 
+	@Override
+	public SyncData downloadBuildingData(String projectId, String buildingId, String uploadFlag, String lastDownloadTime) {
+		List<AdmObject> bdData = admObjMapper.selectList(buildDownloadQueryWrapper(new QueryWrapper<AdmObject>(), projectId, buildingId, uploadFlag, lastDownloadTime));
+		List<AdmRelation> bdRel = relationMapper.selectList(buildDownloadQueryWrapper(new QueryWrapper<AdmRelation>(), projectId, buildingId, uploadFlag, lastDownloadTime));
+
+		//任务相关数据查询
+		List<AdmJobSpace> jobSpace = jobSpaceMapper.selectList(buildDownloadQueryWrapper(new QueryWrapper<AdmJobSpace>(), projectId, buildingId, uploadFlag, lastDownloadTime));
+		List<AdmProblemArch> problemArch = problemArchMapper.selectList(buildDownloadQueryWrapper(new QueryWrapper<AdmProblemArch>(), projectId, buildingId, uploadFlag, lastDownloadTime));
+		List<AdmProblemEquip> problemEquip = problemEquipMapper.selectList(buildDownloadQueryWrapper(new QueryWrapper<AdmProblemEquip>(), projectId, buildingId, uploadFlag, lastDownloadTime));
+		List<AdmFile> file = fileMapper.selectList(buildDownloadQueryWrapper(new QueryWrapper<AdmFile>(), projectId, buildingId, uploadFlag, lastDownloadTime));
+		List<AdmQrCode> qrCode = qrCodeMapper.selectList(buildDownloadQueryWrapper(new QueryWrapper<AdmQrCode>(), projectId, buildingId, uploadFlag, lastDownloadTime));
+
+		SyncData data = new SyncData();
+		data.setBuildingId(buildingId);
+
+		data.setObjects(serializeJsonProp(bdData));
+		data.setRelations(bdRel);
+
+		data.setJobSpace(serializeJsonProp(jobSpace));
+		data.setProblemArch(serializeJsonProp(problemArch));
+		data.setProblemEquip(problemEquip);
+		data.setFile(file);
+		data.setQrCode(serializeJsonProp(qrCode));
+		data.setTimestamp(DateUtil.format(new Date(), DatePattern.PURE_DATETIME_PATTERN));
+
+		return data;
+	}
+
+	private <T> QueryWrapper<T> buildDownloadQueryWrapper(QueryWrapper<T> wrapper, String projectId, String buildingId, String uploadFlag, String lastDownloadTime){
+		wrapper.eq("project_id", projectId).eq("building_id", buildingId);
+		applyUploadFlag(wrapper, uploadFlag,lastDownloadTime);
+		return wrapper;
+	}
+
+	private void applyUploadFlag(QueryWrapper<?> wrapper, String uploadFlag, String lastDownloadTime){
+		if(StrUtil.isNotBlank(uploadFlag))
+			wrapper.and(w -> w.isNull("upload_flag").or().ne("upload_flag", uploadFlag));
+		if (StrUtil.isNotBlank(lastDownloadTime)) {
+			wrapper.and(
+					w -> w.isNotNull("modified_time").gt("modified_time", lastDownloadTime)
+							.or()
+							.isNull("modified_time").gt("creation_time", lastDownloadTime)
+			);
+		}
+	}
+
+	@Override
+	@Transactional(rollbackFor = Exception.class)
+	public UploadRtn uploadData(SyncData uploadData, String projectId, String uploadFlag) {
+		UploadRtn rtn = new UploadRtn();
+		PsDateTime timestamp = new PsDateTime(System.currentTimeMillis());
+
+		if (CollUtil.isNotEmpty(uploadData.getObjects())) {
+			List<AdmObject> dbObjs = admObjMapper.selectList(new QueryWrapper<AdmObject>().eq("building_id", uploadData.getBuildingId()).eq("valid", ValidEnum.TRUE.getType()));
+			List<AdmObject> expired = uploadBdtpData(uploadData.getObjects(), dbObjs, uploadFlag, timestamp, admObjMapper, "object");
+			rtn.setExpiredObjectIds(buildExpiredIds(expired));
+		}
+		if (CollUtil.isNotEmpty(uploadData.getRelations())) {
+			List<AdmRelation> dbObjs = relationMapper.selectList(new QueryWrapper<AdmRelation>().eq("building_id", uploadData.getBuildingId()).eq("valid", ValidEnum.TRUE.getType()));
+			List<AdmRelation> expired = uploadBdtpData(uploadData.getRelations(), dbObjs, uploadFlag, timestamp, relationMapper, "relation");
+			rtn.setExpiredRelationIds(buildExpiredIds(expired));
+		}
+
+		String timestampStr = timestamp.toString();
+		if (CollUtil.isNotEmpty(uploadData.getJobSpace())) {
+			List<AdmJobSpace> dbObjs = jobSpaceMapper.selectList(new QueryWrapper<AdmJobSpace>().eq("building_id", uploadData.getBuildingId()).eq("valid", ValidEnum.TRUE.getType()));
+			List<AdmJobSpace> expired = uploadAdmData(uploadData.getJobSpace(), dbObjs, uploadFlag, timestampStr, jobSpaceMapper);
+			rtn.setExpiredJobSpaceIds(buildExpiredIds(expired));
+		}
+		if (CollUtil.isNotEmpty(uploadData.getProblemArch())) {
+			List<AdmProblemArch> dbObjs = problemArchMapper.selectList(new QueryWrapper<AdmProblemArch>().eq("building_id", uploadData.getBuildingId()).eq("valid", ValidEnum.TRUE.getType()));
+			List<AdmProblemArch> expired = uploadAdmData(uploadData.getProblemArch(), dbObjs, uploadFlag, timestampStr, problemArchMapper);
+			rtn.setExpiredProblemArchIds(buildExpiredIds(expired));
+		}
+		if (CollUtil.isNotEmpty(uploadData.getProblemEquip())) {
+			List<AdmProblemEquip> dbObjs = problemEquipMapper.selectList(new QueryWrapper<AdmProblemEquip>().eq("building_id", uploadData.getBuildingId()).eq("valid", ValidEnum.TRUE.getType()));
+			List<AdmProblemEquip> expired = uploadAdmData(uploadData.getProblemEquip(), dbObjs, uploadFlag, timestampStr, problemEquipMapper);
+			rtn.setExpiredProblemEquipIds(buildExpiredIds(expired));
+		}
+		if (CollUtil.isNotEmpty(uploadData.getFile())) {
+			List<AdmFile> dbObjs = fileMapper.selectList(new QueryWrapper<AdmFile>().eq("building_id", uploadData.getBuildingId()).eq("valid", ValidEnum.TRUE.getType()));
+			List<AdmFile> expired = uploadAdmData(uploadData.getFile(), dbObjs, uploadFlag, timestampStr, fileMapper);
+			rtn.setExpiredFileIds(buildExpiredIds(expired));
+		}
+		if (CollUtil.isNotEmpty(uploadData.getQrCode())) {
+			List<AdmQrCode> dbObjs = qrCodeMapper.selectList(new QueryWrapper<AdmQrCode>().eq("building_id", uploadData.getBuildingId()).eq("valid", ValidEnum.TRUE.getType()));
+			List<AdmQrCode> expired = uploadAdmData(uploadData.getQrCode(), dbObjs, uploadFlag, timestampStr, qrCodeMapper);
+			rtn.setExpiredQrCodeIds(buildExpiredIds(expired));
+		}
+
+		rtn.setTimestamp(timestampStr);
+		return rtn;
+	}
+
+	private <T extends IAdmBdtpEntity> List<T> uploadBdtpData(List<T> objs, List<T> dbObjs, String uploadFlag, PsDateTime timestamp, BaseMapper<T> mapper, String objectType){
+		List<T> expired = new ArrayList<>();
+		HashMap<String, T> map = new HashMap<>(dbObjs.size());
+		for(T dbObj : dbObjs) {
+			map.put(dbObj.getId(), dbObj);
+		}
+
+		List<T> msgAdd = new ArrayList<>();
+		List<T> msgModify = new ArrayList<>();
+		List<T> msgRemove = new ArrayList<>();
+		for (T obj : objs) {
+			T dbObj = map.get(obj.getId());
+			if (dbObj == null) {
+				if(obj.getValid().intValue() == ValidEnum.FALSE.getType())
+					continue;
+
+				obj.setCreationTime(timestamp);
+				obj.setCreator(AdmConst.CREATOR_APP);
+				setBdtpUploadProp(obj, dbObj, uploadFlag);
+
+				mapper.insert(obj);
+
+				msgAdd.add(obj);
+			} else {
+				long dbTs;
+				long ts;
+				if(dbObj.getModifiedTime() != null){
+					dbTs = dbObj.getModifiedTime().getMillis();
+					ts = obj.getModifiedTime().getMillis();
+				} else {
+					dbTs = dbObj.getCreationTime().getMillis();
+					ts = obj.getCreationTime().getMillis();
+				}
+				if (ts != dbTs) {
+					//TODO 时间戳不一致,离线数据无效,暂时跳过处理
+					expired.add(obj);
+				} else {
+					obj.setModifiedTime(timestamp);
+					obj.setModifier(AdmConst.CREATOR_APP);
+					setBdtpUploadProp(obj, dbObj, uploadFlag);
+
+					mapper.updateById(obj);
+
+					if(obj.getValid().intValue() == ValidEnum.FALSE.getType())
+						msgRemove.add(obj);
+					else
+						msgModify.add(obj);
+				}
+			}
+		}
+
+		D2mMessage message = new D2mMessage();
+		message.setItemType(objectType);
+		message.setAddItems(msgAdd);
+		message.setModifyItems(msgModify);
+		message.setRemoveItems(msgRemove);
+		syncModel.sendMessageToModel(message);
+
+		return expired;
+	}
+
+	private void setBdtpUploadProp(IAdmBdtpEntity obj, IAdmBdtpEntity dbObj, String uploadFlag){
+		obj.setUploadFlag(uploadFlag);
+		obj.setD2mState(ValidEnum.FALSE.getType());
+		obj.setDeliveryState(ValidEnum.FALSE.getType());
+		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){
+		List<T> expired = new ArrayList<>();
+		HashMap<String, T> dbMap = new HashMap<>(dbObjs.size());
+		for(T dbObj : dbObjs) {
+			dbMap.put(dbObj.getId(), dbObj);
+		}
+
+		for (T obj : objs) {
+			T dbObj = dbMap.get(obj.getId());
+			if (dbObj == null) {
+				if(obj.getValid().intValue() == ValidEnum.FALSE.getType())
+					continue;
+
+				obj.setCreationTime(timestamp);
+				obj.setCreator(AdmConst.CREATOR_APP);
+				obj.setUploadFlag(uploadFlag);
+				mapper.insert(obj);
+			} else {
+				String dbTs;
+				String ts;
+				if(dbObj.getModifiedTime() != null){
+					dbTs = dbObj.getModifiedTime();
+					ts = obj.getModifiedTime();
+				} else {
+					dbTs = dbObj.getCreationTime();
+					ts = obj.getCreationTime();
+				}
+				if (!ts.equals(dbTs)) {
+					//TODO 时间戳不一致,离线数据无效,暂时跳过处理
+					expired.add(obj);
+				} else {
+					obj.setModifiedTime(timestamp);
+					obj.setModifier(AdmConst.CREATOR_APP);
+					obj.setUploadFlag(uploadFlag);
+					mapper.updateById(obj);
+				}
+			}
+		}
+		return expired;
+	}
+
+	private List<String> buildExpiredIds(List<? extends IAdmEntity> expired){
+		if(expired.size() > 0) {
+			List<String> ids = new ArrayList<>();
+			for(IAdmEntity entity : expired) {
+				ids.add(entity.getId());
+			}
+			return ids;
+		}
+		return null;
+	}
+
+	private <T extends IAdmEntity> List<T> serializeJsonProp(List<T> list){
+		for(IAdmEntity entity : list) {
+			entity.serializeJsonProp();
+		}
+		return list;
+	}
+
 }

+ 2 - 7
src/main/java/com/persagy/bdtp/adm/service/impl/SyncModelImpl.java

@@ -8,8 +8,6 @@ import org.springframework.amqp.core.Message;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import java.util.Arrays;
-
 @Service
 public class SyncModelImpl implements ISyncModel {
 
@@ -17,16 +15,13 @@ public class SyncModelImpl implements ISyncModel {
 	private AdmMessageHelper messageHelper;
 
 	@Override
-	public void sendMessageToModel(String operation, Object entity) {
-		D2mMessage message = new D2mMessage();
-		message.setObjs(Arrays.asList(entity));
-		message.setOperation(operation);
+	public void sendMessageToModel(D2mMessage message) {
 		messageHelper.sendMessage(message, AdmMessageConst.ADM_D2M_ROUTING, false);
 	}
 
 	@Override
 	public void handleModelMessage(String message, Message vo) {
-
+		//TODO 处理模型计算返回结果:标注状态, 增加对象
 	}
 
 }

+ 40 - 17
src/main/java/com/persagy/bdtp/adm/service/impl/SyncOldAdmImpl.java

@@ -111,11 +111,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(dbItem.getId(), dbItem); //localId?
+			dbMap.put(getFixedIdForSync(dbItem), dbItem);
 		}
 
 		for(AdmObject obj : objs) {
-			AdmObject dbItem = dbMap.remove(obj.getId()); //localId?
+			AdmObject dbItem = dbMap.remove(getFixedIdForSync(obj));
 			if(dbItem == null)
 				operations[0].add(obj); //add
 			else {
@@ -128,23 +128,46 @@ public class SyncOldAdmImpl implements ISyncOldAdm {
 		if (dbMap.size() > 0) { //remove
 			for(AdmObject obj : dbMap.values()){
 				obj.setValid(ValidEnum.FALSE.getType());
-				//obj.setModifiedTime(new PsDateTime(System.currentTimeMillis()));
+				obj.setModifiedTime(new PsDateTime(System.currentTimeMillis()));
+				obj.setModifier(AdmConst.CREATOR_SYNC);
+				obj.setUploadFlag(null);
 				operations[1].add(obj);
 			}
 		}
 	}
 
+	/**
+	 * 同步数据时固定的id,优先取bimId,没有bimId取数据id
+	 */
+	private String getFixedIdForSync(AdmObject obj){
+		JsonNode node = obj.getInfo("bimId");
+		if(node == null)
+			return obj.getId();
+		return node.asText();
+	}
+
 	private AdmObject mergeObj(AdmObject obj, AdmObject dbItem, int objMark){
 		if(objNotChange(obj, dbItem))
 			return null;
 
-		//TODO 按交付规则,合并属性和信息点
-		if(objMark == 3) {//space
+		//合并属性和信息点
+//		if(objMark == 3) {//space
+//
+//		} else if(objMark == 4) {//equipment
+//
+//		}
+		if (obj.getInfos() != null) {
+			if (dbItem.getInfos() == null)
+				dbItem.setInfos(obj.getInfos());
+			else
+				dbItem.getInfos().setAll(obj.getInfos());
+		}
 
-		} else if(objMark == 4) {//equipment
+		dbItem.setModifiedTime(new PsDateTime(System.currentTimeMillis()));
+		dbItem.setModifier(AdmConst.CREATOR_SYNC);
+		dbItem.setUploadFlag(null);
 
-		}
-		return obj;
+		return dbItem;
 	}
 
 	private boolean objNotChange(AdmObject obj, AdmObject dbItem){
@@ -365,10 +388,9 @@ public class SyncOldAdmImpl implements ISyncOldAdm {
 				if(job != null) {
 					//id匹配,轮廓变化的空间,重置任务状态
 					if(!outlineMatch(job.getOutline(), spOutline)){
-						job.setArchState(AdmConst.JOB_STATE_TODO);
-						job.setEquipState(AdmConst.JOB_STATE_TODO);
-						job.setModifiedTime(time);
-						job.setModifier(AdmConst.APP_ID);
+						job.setArchState(AdmConst.JOB_STATE_PROCESSING);
+						job.setEquipState(AdmConst.JOB_STATE_PROCESSING);
+						job.setOutline(spOutline);
 						toModify.add(job);
 					} // else id和轮廓都匹配,不做处理
 				} else {
@@ -385,13 +407,13 @@ public class SyncOldAdmImpl implements ISyncOldAdm {
 					job.setId(IdUtil.fastUUID());
 					job.setSpaceId(sp.getId());
 					job.setOutline((ArrayNode) sp.getInfo("outline"));
-					job.setArchState(AdmConst.JOB_STATE_TODO);
-					job.setEquipState(AdmConst.JOB_STATE_TODO);
+					job.setArchState(AdmConst.JOB_STATE_PROCESSING);
+					job.setEquipState(AdmConst.JOB_STATE_PROCESSING);
 					job.setProjectId(projectId);
 					job.setBuildingId(sp.getBuildingId());
 					job.setFloorId(sp.getFloorId());
 					job.setCreationTime(time);
-					job.setCreator(AdmConst.APP_ID);
+					job.setCreator(AdmConst.CREATOR_SYNC);
 					job.setValid(ValidEnum.TRUE.getType());
 
 					toCreate.add(job);
@@ -401,7 +423,6 @@ public class SyncOldAdmImpl implements ISyncOldAdm {
 			//楼层中未找到匹配关系的任务空间
 			for(AdmJobSpace job : jobMap.values()){
 				job.setValid(ValidEnum.FALSE.getType());
-				job.setModifiedTime(time);
 				toModify.add(job);
 			}
 		}
@@ -409,7 +430,6 @@ public class SyncOldAdmImpl implements ISyncOldAdm {
 		//项目下未找到匹配关系的任务空间
 		for(AdmJobSpace job : jobSpaceList){
 			job.setValid(ValidEnum.FALSE.getType());
-			job.setModifiedTime(time);
 			toModify.add(job);
 		}
 
@@ -417,6 +437,9 @@ public class SyncOldAdmImpl implements ISyncOldAdm {
 			jobSpaceMapper.insert(job);
 		}
 		for(AdmJobSpace job : toModify) {
+			job.setModifiedTime(time);
+			job.setModifier(AdmConst.CREATOR_SYNC);
+			job.setUploadFlag(null);
 			jobSpaceMapper.updateById(job);
 		}
 	}

+ 68 - 0
src/main/java/com/persagy/bdtp/adm/util/IdGenerator.java

@@ -0,0 +1,68 @@
+package com.persagy.bdtp.adm.util;
+
+import cn.hutool.core.util.IdUtil;
+import cn.hutool.core.util.StrUtil;
+
+/**
+ * 实体对象id生成器
+ */
+public class IdGenerator {
+
+	public static final String PROJECT = "project"; //项目
+	public static final String BUILDING = "building"; //建筑
+	public static final String FLOOR = "floor"; //"楼层"),
+	public static final String SPACE = "space"; //空间
+	public static final String SYSTEM = "system"; //系统
+	public static final String EQUIPMENT = "equipment"; //设备
+	public static final String SHAFT = "shaft"; //竖井
+	public static final String COMPONENT = "component"; //部件
+	public static final String VIRTUAL = "virtual"; //虚拟对象
+	public static final String TOOL = "tool"; //工具
+	public static final String MATERIAL = "material"; //耗材
+
+	/**
+	 * 生成对象id
+	 * @param projectId 项目id
+	 * @param objType 对象类型
+	 * @return 两位prefix + 无前缀projectId + 无分隔符的32位uuid
+	 */
+	public static String getId(String projectId, String objType){
+		if (PROJECT.equals(objType))
+			return projectId;
+
+		String prefix = getPrefix(objType);
+		if(StrUtil.isBlank(prefix))
+			return IdUtil.simpleUUID();
+
+		return prefix + projectId.substring(2) + IdUtil.simpleUUID();
+	}
+
+	private static String getPrefix(String objType){
+		switch (objType) {
+			case PROJECT:
+				return "Pj";
+			case BUILDING:
+				return "Bd";
+			case FLOOR:
+				return "Fl";
+			case SPACE:
+				return "Sp";
+			case SYSTEM:
+				return "Sy";
+			case EQUIPMENT:
+				return "Eq";
+			case SHAFT:
+				return "Sh";
+			case COMPONENT:
+				return "Ec";
+			case VIRTUAL:
+				return "Vo";
+			case TOOL:
+				return "To";
+			case MATERIAL:
+				return "Ma";
+		}
+		return null;
+	}
+
+}

+ 6 - 6
src/main/resources/bootstrap.yml

@@ -13,12 +13,12 @@ spring:
           password: adm
           url: jdbc:mysql://192.168.0.11/adm?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT
 persagy:
-  common:
-    file:
-      storage: 0
-      url: http://192.168.25.129:9000/
-      accessKey: admin
-      secretKey: 12345678
+#  common:
+#    file:
+#      storage: 0
+#      url: http://192.168.25.129:9000/
+#      accessKey: admin
+#      secretKey: 12345678
   adm:
     oldPlatformUrl: http://39.102.40.239
 # typeHandler扫描

+ 147 - 3
src/test/java/com/persagy/bdtp/adm/test/AdmApplicationTests.java

@@ -1,16 +1,22 @@
 package com.persagy.bdtp.adm.test;
 
+import cn.hutool.core.util.IdUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.persagy.bdtp.adm.dao.AdmObjectMapper;
-import com.persagy.bdtp.adm.entity.AdmObject;
+import com.persagy.bdtp.adm.dao.*;
+import com.persagy.bdtp.adm.entity.*;
 import com.persagy.bdtp.adm.service.ISyncModel;
 import com.persagy.bdtp.adm.service.ISyncOldAdm;
+import com.persagy.bdtp.adm.test.data.InfosCfgs;
+import com.persagy.bdtp.adm.test.data.PipeCfgs;
+import com.persagy.bdtp.adm.test.data.RelCfgs;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.test.context.junit4.SpringRunner;
 
+import java.util.*;
+
 @RunWith(SpringRunner.class)
 @SpringBootTest
 public class AdmApplicationTests {
@@ -42,7 +48,145 @@ public class AdmApplicationTests {
 	public void testMq(){
 		AdmObject obj = admObjectMapper.selectOne(new QueryWrapper<AdmObject>().eq("id", "Eq00022200023a8d5a59a7fb49a89dfa6ae746518bc2"));
 		obj.getInfos().put("comp_type", "FFFAAL-声光报警器");
-		syncModel.sendMessageToModel(ISyncModel.OPERATOR_ADD, obj);
+		D2mMessage msg = new D2mMessage();
+		msg.setAddItems(Arrays.asList(obj));
+		syncModel.sendMessageToModel(msg);
+	}
+
+	@Autowired
+	private AdmInfosConfigMapper infosConfigMapper;
+	@Test
+	//@Transactional
+	public void testInfosCfg(){
+		String type = "se";
+		String major = type.toUpperCase();
+
+		List<AdmInfosConfig> dbList = infosConfigMapper.selectList(new QueryWrapper<AdmInfosConfig>().eq("major_code", major));
+		HashMap<String, AdmInfosConfig> dbMap = new HashMap<>();
+		dbList.stream().forEach(cfg -> dbMap.put(cfg.getClassCode(), cfg));
+		List<AdmInfosConfig> list = new InfosCfgs().read(type);
+		for(AdmInfosConfig item : list) {
+			AdmInfosConfig dbItem = dbMap.get(item.getClassCode());
+			if(dbItem == null)
+				infosConfigMapper.insert(item);
+			else {
+				item.setId(dbItem.getId());
+				infosConfigMapper.updateById(item);
+			}
+		}
+	}
+
+	@Autowired
+	private AdmRelsConfigMapper relsConfigMapper;
+	@Test
+	public void testRelsCfg(){
+		String type = "se";
+
+		List<AdmRelsConfig> dbList = relsConfigMapper.selectList(null);
+		HashMap<String, AdmRelsConfig> dbMap = new HashMap<>();
+		dbList.stream().forEach(cfg -> dbMap.put(cfg.getClassCodeFrom(), cfg));
+		List<AdmRelsConfig> list = new RelCfgs().read(type);
+		for(AdmRelsConfig item : list) {
+			AdmRelsConfig dbItem = dbMap.get(item.getClassCodeFrom());
+			if(dbItem == null)
+				relsConfigMapper.insert(item);
+			else {
+				item.setId(dbItem.getId());
+				relsConfigMapper.updateById(item);
+			}
+		}
+	}
+
+	@Autowired
+	private AdmComponentMapper componentMapper;
+	@Test
+	public void setCompToInfosCfg(){
+		List<AdmComponent> compList = componentMapper.selectList(null);
+		HashMap<String, List<AdmComponent>> compMap = new HashMap<>();
+		compList.stream().forEach(comp -> {
+			List<AdmComponent> list = compMap.get(comp.getClassCode());
+			if(list == null){
+				list = new ArrayList<>();
+				compMap.put(comp.getClassCode(), list);
+			}
+			list.add(comp);
+		});
+
+		List<AdmInfosConfig> cfgList = infosConfigMapper.selectList(null);
+		HashMap<String, AdmInfosConfig> cfgMap = new HashMap<>();
+		cfgList.stream().forEach(cfg -> cfgMap.put(cfg.getClassCode(), cfg));
+
+		for (Map.Entry<String, List<AdmComponent>> entry : compMap.entrySet()) {
+			String classCode = entry.getKey();
+			List<AdmComponent> comps = entry.getValue();
+			AdmInfosConfig cfg = cfgMap.get(classCode);
+			if(cfg != null){
+				List<Map> infos = (List)cfg.getInfos();
+				Map info = null;
+				for(Map m : infos) {
+					if("comp_type".equals(m.get("code"))){
+						info = m;
+						break;
+					}
+				}
+				setCompsToInfo(infos, info, comps);
+
+				infosConfigMapper.updateById(cfg);
+			} else {
+				cfg = new AdmInfosConfig();
+				cfg.setId(IdUtil.simpleUUID());
+				cfg.setObjType("equipment");
+				cfg.setClassCode(classCode);
+				AdmComponent comp0 = comps.get(0);
+				cfg.setSystemCode(comp0.getSystemCode());
+				cfg.setMajorCode(comp0.getSystemCode().substring(0, 2));
+				List infos = new ArrayList<>();
+				cfg.setInfos(infos);
+				setCompsToInfo(infos, null, comps);
+
+				infosConfigMapper.insert(cfg);
+			}
+		}
+	}
+
+	private void setCompsToInfo(List infos, Map info, List<AdmComponent> comps){
+		if(info == null){
+			info = new HashMap();
+			info.put("group", "几何信息");
+			info.put("code", "comp_type");
+			info.put("label", "构件类型");
+			info.put("dataType", "string");
+			infos.add(info);
+		}
+		List<Map> ops = new ArrayList<>();
+		for(AdmComponent comp : comps) {
+			Map<String, String> map = new HashMap<>();
+			ops.add(map);
+			map.put("val", comp.getCompCode());
+			map.put("txt", comp.getCompName());
+		}
+		info.put("options", ops);
+	}
+
+	@Autowired
+	private AdmPipeConfigMapper pipeConfigMapper;
+	@Test
+	public void testPipeCfg(){
+		String type = "ff";
+
+		List<AdmPipeConfig> dbList = pipeConfigMapper.selectList(null);
+		HashMap<String, AdmPipeConfig> dbMap = new HashMap<>();
+		dbList.stream().forEach(cfg -> dbMap.put(cfg.getClassCodeFrom(), cfg));
+		List<AdmPipeConfig> list = new PipeCfgs().read(type);
+		for(AdmPipeConfig item : list) {
+			AdmPipeConfig dbItem = dbMap.get(item.getClassCodeFrom());
+			if(dbItem == null)
+				pipeConfigMapper.insert(item);
+			else {
+				item.setId(dbItem.getId());
+				pipeConfigMapper.updateById(item);
+			}
+		}
 	}
 
 }

+ 229 - 0
src/test/java/com/persagy/bdtp/adm/test/data/InfosCfgs.java

@@ -0,0 +1,229 @@
+package com.persagy.bdtp.adm.test.data;
+
+import cn.hutool.core.util.IdUtil;
+import cn.hutool.core.util.StrUtil;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.persagy.bdtp.adm.entity.AdmInfosConfig;
+import lombok.Data;
+
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Pattern;
+
+public class InfosCfgs {
+
+    public static void main(String[] args) throws Exception {
+        new InfosCfgs().read("ff");
+    }
+
+    private ObjectMapper objectMapper = new ObjectMapper();;
+    private List<AdmInfosConfig> eqList = new ArrayList<>();
+    private AdmInfosConfig eq;
+    private String group;
+    private String major;
+
+    public List<AdmInfosConfig> read(String type){
+        major = type.toUpperCase();
+        try (BufferedReader r = new BufferedReader(new FileReader("D:\\work_area\\adm_1015\\" + type + ".txt"))){
+            String tmp;
+            while ((tmp = r.readLine()) != null){
+                readLine(tmp);
+            }
+
+            String json = objectMapper.writeValueAsString(eqList);
+            System.out.println(json);
+
+            return eqList;
+        }catch (Exception e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+    private void readLine(String line){
+        if(StrUtil.isBlank(line))
+            return;
+
+        int preS = preS(line);
+        String[] arr = line.trim().split("\\s", 9 - (preS == 0 ? 0 : preS - 1));
+
+        if(arr.length < 3)
+            return;
+
+        readLine(preS, arr);
+    }
+
+    private void readLine(int preS, String[] arr) {
+        if (preS <= 2) {
+            eq = new AdmInfosConfig();
+            eq.setId(IdUtil.simpleUUID());
+            eqList.add(eq);
+            eq.setName(arr[3 - preS]);
+            eq.setClassCode(major + arr[4 - preS]);
+            eq.setMajorCode(major);
+            eq.setSystemCode(eq.getClassCode().substring(0, 4));
+            eq.setObjType("equipment");
+            eq.setInfos(new ArrayList<>());
+        }
+        if(preS <= 5){
+            group = arr[5 - preS];
+        }
+        Info info = new Info();
+        eq.getInfos().add(info);
+
+        info.group = group;
+        info.label = arr[6 - preS];
+        info.code = arr[7 - preS];
+        if(isCode(info.label)){
+            String tmp = info.label;
+            info.label = info.code;
+            info.code = tmp;
+        }
+        info.dataType = getDataType(arr[8 - preS]);
+        String optionsStr = null;
+        if(arr.length > 9 - preS) {
+            String left = arr[9 - preS];
+            if(left.charAt(0) == '\t')
+                optionsStr = left.trim();
+            else {
+                String[] arr1 = left.split("\\s", 1);
+                info.dataType = getDataType(arr1[0]);
+                if(arr1.length > 1)
+                    optionsStr = arr1[1];
+            }
+        }
+        if(StrUtil.isNotBlank(optionsStr))
+          parseOptions(optionsStr, info);
+    }
+
+    private void parseOptions(String optionsStr, Info info) {
+        List<Op> ops = new ArrayList<>();
+        info.options = ops;
+
+        if(optionsStr.startsWith("{")) {
+            while(optionsStr.length() > 0){
+                int p1 = optionsStr.indexOf("{");
+                int p2 = optionsStr.indexOf("}");
+                if(p1 >= 0 && p2 > 0) {
+                    String item = optionsStr.substring(p1 + 1, p2);
+
+                    String[] arr = item.split(":");
+                    Op op = new Op();
+                    op.val = arr[0];
+                    op.txt = arr[1];
+                    ops.add(op);
+
+                    optionsStr = optionsStr.substring(p2 + 1);
+                } else
+                    break;
+            }
+        } else {
+            String multi = "(可多选)";
+            if(optionsStr.endsWith(multi)) {
+                optionsStr = optionsStr.substring(0, optionsStr.length() - multi.length());
+                info.inputType = "checkbox";
+            }
+
+            String[] arr = optionsStr.split("\\s+");
+            if(arr.length < 2 || arr.length % 2 != 0)
+                return;
+            for (int i = 0; i < arr.length; ) {
+                String id = arr[i];
+                if(id.endsWith("."))
+                    id = id.substring(0, id.length() - 1);
+
+                //debug
+                if(i + 1 >= arr.length)
+                    System.out.println(optionsStr);
+
+                String val = arr[i + 1];
+
+                Op op = new Op();
+                op.val = id;
+                op.txt = val;
+                ops.add(op);
+
+                i += 2;
+            }
+        }
+    }
+
+    private String getDataType(String dtName){
+        if(StrUtil.isBlank(dtName))
+            return null;
+
+        if("整数".equals(dtName))
+            return "int";
+        if("字符串".equals(dtName))
+            return "string";
+        if("浮点数".equals(dtName))
+            return "float";
+        if("枚举值".equals(dtName))
+            return "string";
+        if(dtName.indexOf("数组") >= 0)
+            return "arr";
+        return null;
+    }
+
+    private String getSeg(int segIdx, String line) {
+        int s = 0;
+        int idx = 0;
+        StringBuilder code = null;
+        while (idx < line.length()){
+            char c = line.charAt(idx++);
+            if(Character.isWhitespace(c)) {
+                s++;
+                if(s == segIdx)
+                    code = new StringBuilder();
+                else if(code != null)
+                    break;
+            } else if(code != null) {
+                code.append(c);
+            }
+        }
+        return code.toString();
+    }
+
+    private boolean isCode(String s){
+        String pattern = "^[A-Za-z0-9]+$";
+        return Pattern.matches(pattern, s);
+    }
+
+    private int preS(String line){
+        int s = 0;
+        while (s < line.length()){
+            if(!Character.isWhitespace(line.charAt(s)))
+                break;
+            s++;
+        }
+        return s;
+    }
+
+    @Data
+    class Info {
+
+        String group;
+
+        String code;
+
+        String label;
+
+        String dataType;
+
+        String inputType;
+
+        String unit;
+
+        List<Op> options;
+
+    }
+
+    @Data
+    class Op{
+        private String txt;
+        private Object val;
+    }
+
+}

+ 95 - 0
src/test/java/com/persagy/bdtp/adm/test/data/PipeCfgs.java

@@ -0,0 +1,95 @@
+package com.persagy.bdtp.adm.test.data;
+
+import cn.hutool.core.util.IdUtil;
+import cn.hutool.core.util.StrUtil;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.persagy.bdtp.adm.common.AdmConst;
+import com.persagy.bdtp.adm.entity.AdmPipeConfig;
+
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.util.ArrayList;
+import java.util.List;
+
+public class PipeCfgs {
+
+    public static void main(String[] args) throws Exception {
+        new PipeCfgs().read("ff");
+    }
+
+    private ObjectMapper objectMapper = new ObjectMapper();;
+    private List<AdmPipeConfig> list = new ArrayList<>();
+    private AdmPipeConfig cfg;
+    private String classCodeFrom;
+    private String major;
+
+
+    public List<AdmPipeConfig> read(String type){
+        major = type.toUpperCase();
+
+        try (BufferedReader r = new BufferedReader(new FileReader("D:\\work_area\\adm_1015\\" + type + "_pipe.txt"))){
+            String tmp;
+            while ((tmp = r.readLine()) != null){
+                readLine(tmp);
+            }
+
+            String json = objectMapper.writeValueAsString(list);
+            System.out.println(json);
+
+            return list;
+        }catch (Exception e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+    private void readLine(String line){
+        if(StrUtil.isBlank(line))
+            return;
+        int preS = preS(line);
+        String[] arr = line.trim().split("\\s+");
+        readLine(preS, arr);
+    }
+
+    private void readLine(int preS, String[] arr) {
+        if (preS <= 3)
+            classCodeFrom = arr[3 - preS];
+
+        cfg = new AdmPipeConfig();
+        cfg.setId(IdUtil.simpleUUID());
+        cfg.setClassCodeFrom(classCodeFrom);
+        cfg.setPipeType(getPipeClassCode(arr[4 - preS]));
+        cfg.setPipeSubType(arr[5 - preS]);
+        cfg.setClassCodeTo(arr[7 - preS]);
+        cfg.setPipeDirection(getDirection(arr[8 - preS]));
+
+        list.add(cfg);
+    }
+
+    private String getPipeClassCode(String name){
+        if("液体管道".equals(name))
+            return "LAPL";
+        if("气体管道".equals(name))
+            return "AAPL";
+        return name;
+    }
+
+    private int getDirection(String label) {
+        if("→".equals(label))
+            return AdmConst.PIPE_DIRECTION_FORWARD;
+        if("←".equals(label))
+            return AdmConst.PIPE_DIRECTION_BACK;
+        return AdmConst.PIPE_DIRECTION_NONE;
+    }
+
+    private int preS(String line){
+        int s = 0;
+        while (s < line.length()){
+            if(!Character.isWhitespace(line.charAt(s)))
+                break;
+            s++;
+        }
+        return s;
+    }
+
+}

+ 159 - 0
src/test/java/com/persagy/bdtp/adm/test/data/RelCfgs.java

@@ -0,0 +1,159 @@
+package com.persagy.bdtp.adm.test.data;
+
+import cn.hutool.core.util.IdUtil;
+import cn.hutool.core.util.StrUtil;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.persagy.bdtp.adm.entity.AdmRelsConfig;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+public class RelCfgs {
+
+    public static void main(String[] args) throws Exception {
+        new RelCfgs().read("se");
+    }
+
+    private ObjectMapper objectMapper = new ObjectMapper();;
+    private List<AdmRelsConfig> list = new ArrayList<>();
+    private AdmRelsConfig cfg;
+    private String classCodeFrom;
+    private String graphCode;
+    private String major;
+    private List<Map> graphDef;
+    private List<Map> relDef;
+    private List<Map> relsDef;
+
+    public List<AdmRelsConfig> read(String type){
+        major = type.toUpperCase();
+        try{
+            graphDef = objectMapper.readValue(new File("D:\\work_area\\adm_1015\\graph_def.json"), List.class);
+            relDef = objectMapper.readValue(new File("D:\\work_area\\adm_1015\\rel_def.json"), List.class);
+            List<Map> list = objectMapper.readValue(new File("D:\\work_area\\adm_1015\\rels_def.json"), List.class);
+            relsDef = new ArrayList<>();
+            for(Map m : list){
+                relsDef.addAll((List)m.get("children"));
+            }
+        }catch (Exception e){
+
+        }
+        try (BufferedReader r = new BufferedReader(new FileReader("D:\\work_area\\adm_1015\\" + type + "_rels.txt"))){
+            String tmp;
+            while ((tmp = r.readLine()) != null){
+                readLine(tmp);
+            }
+
+            String json = objectMapper.writeValueAsString(list);
+            System.out.println(json);
+
+            return list;
+        }catch (Exception e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+    private void readLine(String line){
+        if(StrUtil.isBlank(line))
+            return;
+        int preS = preS(line);
+        String[] arr = line.trim().split("\\s+");
+        readLine(preS, arr);
+    }
+
+    private void readLine(int preS, String[] arr) {
+        if (preS <= 3)
+            classCodeFrom = arr[3 - preS];
+        if (preS <= 4)
+            graphCode = findGraphCode(arr[4 - preS]);
+
+        cfg = new AdmRelsConfig();
+        cfg.setId(IdUtil.simpleUUID());
+        cfg.setObjTypeFrom("equipment");
+        cfg.setClassCodeFrom(classCodeFrom);
+        cfg.setGraphCode(graphCode);
+        cfg.setRelCode(findRelCode(arr[5 - preS], graphCode));
+        if(arr.length >= 8 - preS)
+            cfg.setClassCodeTo(arr[7 - preS]);
+        if(cfg.getClassCodeTo() != null){
+            switch (cfg.getClassCodeTo()){
+                case "CMZ":
+                    cfg.setClassCodeTo("GeneralZone");
+                    break;
+                case "ACZ":
+                    cfg.setClassCodeTo("AirConditioningZone");
+                    break;
+                //TODO
+            }
+            if(cfg.getClassCodeFrom().length() == 4){
+                if(cfg.getClassCodeTo().length() == 2)
+                    cfg.setObjTypeTo("system");
+                else if(cfg.getClassCodeTo().length() == 4)
+                    cfg.setObjTypeTo("equipment");
+            } else if(cfg.getClassCodeFrom().length() == 6){
+                if(cfg.getClassCodeTo().length() == 4)
+                    cfg.setObjTypeTo("system");
+                else if(cfg.getClassCodeTo().length() == 6)
+                    cfg.setObjTypeTo("equipment");
+            }
+            if(cfg.getObjTypeTo() == null) {
+                if(cfg.getRelCode().endsWith("2Fl"))
+                    cfg.setObjTypeTo("floor");
+                else if(cfg.getRelCode().endsWith("2Sh"))
+                    cfg.setObjTypeTo("shaft");
+                else if(cfg.getRelCode().endsWith("2Sp"))
+                    cfg.setObjTypeTo("space");
+                else {
+                    cfg.setObjTypeTo("unknown"); //TODO
+                }
+            }
+            list.add(cfg);
+        } else {
+            //TODO
+        }
+    }
+
+    private String findGraphCode(String graphName){
+        for(Map map : graphDef) {
+            if(graphName.equals(map.get("name")))
+                return (String) map.get("code");
+        }
+        for (Map map : relsDef) {
+            if(graphName.equals(map.get("name")))
+                return (String) map.get("code");
+        }
+        return graphName;
+    }
+
+    private String findRelCode(String relName, String graphCode){
+        for(Map map : relDef) {
+            if(relName.equals(map.get("name")))
+                return (String) map.get("code");
+        }
+        for (Map map : relsDef) {
+            if(graphCode.equals(map.get("code"))) {
+                List<Map> children = (List)map.get("children");
+                for(Map cm : children) {
+                    if(relName.equals(cm.get("code")))
+                        return (String) cm.get("name");
+                }
+            }
+        }
+        return relName;
+    }
+
+    private int preS(String line){
+        int s = 0;
+        while (s < line.length()){
+            if(!Character.isWhitespace(line.charAt(s)))
+                break;
+            s++;
+        }
+        return s;
+    }
+
+}