Browse Source

1021 实体修改

zhaoyk 3 years ago
parent
commit
adf4bb6fd6
23 changed files with 189 additions and 410 deletions
  1. 4 4
      src/main/java/com/persagy/bdtp/adm/controller/AppController.java
  2. 1 15
      src/main/java/com/persagy/bdtp/adm/entity/AdmComponent.java
  3. 1 5
      src/main/java/com/persagy/bdtp/adm/entity/AdmConfig.java
  4. 1 5
      src/main/java/com/persagy/bdtp/adm/entity/AdmInfosConfig.java
  5. 1 15
      src/main/java/com/persagy/bdtp/adm/entity/AdmM2dEquip.java
  6. 32 20
      src/main/java/com/persagy/bdtp/adm/entity/AdmObject.java
  7. 5 11
      src/main/java/com/persagy/bdtp/adm/entity/AdmPipe.java
  8. 1 15
      src/main/java/com/persagy/bdtp/adm/entity/AdmPipeConfig.java
  9. 10 17
      src/main/java/com/persagy/bdtp/adm/entity/AdmRelation.java
  10. 1 15
      src/main/java/com/persagy/bdtp/adm/entity/AdmRelsConfig.java
  11. 8 2
      src/main/java/com/persagy/bdtp/adm/entity/AdmUploadLog.java
  12. 1 15
      src/main/java/com/persagy/bdtp/adm/entity/BaseAdmDataEntity.java
  13. 23 0
      src/main/java/com/persagy/bdtp/adm/entity/BaseAdmEntity.java
  14. 23 0
      src/main/java/com/persagy/bdtp/adm/entity/BaseDeliveryEntity.java
  15. 0 55
      src/main/java/com/persagy/bdtp/adm/entity/IAdmBdtpEntity.java
  16. 0 17
      src/main/java/com/persagy/bdtp/adm/entity/IAdmEntity.java
  17. 0 2
      src/main/java/com/persagy/bdtp/adm/entity/UploadRtn.java
  18. 1 1
      src/main/java/com/persagy/bdtp/adm/service/ISyncApp.java
  19. 64 185
      src/main/java/com/persagy/bdtp/adm/service/impl/SyncAppImpl.java
  20. 10 9
      src/main/java/com/persagy/bdtp/adm/service/impl/SyncOldAdmImpl.java
  21. 0 0
      src/main/resources/mapper/AdmObjectMapper.xml.bak
  22. 1 1
      src/test/java/com/persagy/bdtp/adm/test/data/PipeCfgs.java
  23. 1 1
      src/test/java/com/persagy/bdtp/adm/test/data/RelCfgs.java

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

@@ -76,10 +76,10 @@ public class AppController {
 		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("/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")
 	public void downloadMap(HttpServletRequest request, HttpServletResponse response, @RequestParam String key){

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

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

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

@@ -15,11 +15,7 @@ import java.io.IOException;
 
 @Data
 @TableName(value = "adm_config",autoResultMap = true)
-public class AdmConfig implements IAdmEntity {
-
-	private String id;
-
-	private String projectId;
+public class AdmConfig extends BaseAdmEntity {
 
 	private String name;
 

+ 1 - 5
src/main/java/com/persagy/bdtp/adm/entity/AdmInfosConfig.java

@@ -14,11 +14,7 @@ import java.util.List;
 
 @Data
 @TableName(value = "adm_infos_config",autoResultMap = true)
-public class AdmInfosConfig implements IAdmEntity {
-
-    private String id;
-
-    private String projectId;
+public class AdmInfosConfig extends BaseAdmEntity {
 
     private String objType;
 

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

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

+ 32 - 20
src/main/java/com/persagy/bdtp/adm/entity/AdmObject.java

@@ -1,44 +1,56 @@
 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 com.persagy.dmp.digital.entity.ObjectDigital;
 import lombok.Data;
 
 import java.io.IOException;
+import java.util.List;
 
 @Data
 @TableName(value = "adm_object",autoResultMap = true)
-public class AdmObject extends ObjectDigital implements IAdmBdtpEntity {
+public class AdmObject extends BaseDeliveryEntity {
 
-	/** 创建对象的本地设备(移动端) */
-	private String clientDevice;
+	private String name;
 
-	/** 由本地设备生成的对象id */
-	private String clientId;
+	private String localId;
 
-	/**  数模同步状态:0未同步, 1已同步 */
-	private Integer d2mState;
+	private String localName;
 
-	/** 交付BDTP状态:1已交付,0待交付 */
-	private Integer deliveryState;
+	private String objType;
 
-	private String buildingId;
+	private String classCode;
 
-	private String floorId;
+	private String groupCode;
 
-	/** app端上传数据标记 */
-	private String uploadFlag;
+	@TableField("`grouping`")
+	private Integer grouping;
+
+	@TableField(
+			typeHandler = JacksonTypeHandler.class
+	)
+	private List<String> virtualCodes;
+
+	private String createApp;
+
+	private String updateApp;
+
+	@TableField(
+			typeHandler = JacksonTypeHandler.class
+	)
+	private ObjectNode infos;
 
 	private String strInfos;
 
 	public JsonNode getInfo(String infoCode){
-		ObjectNode node = getInfos();
+		ObjectNode node = infos;
 		if(node != null)
 			return node.get(infoCode);
 		return null;
@@ -46,14 +58,14 @@ public class AdmObject extends ObjectDigital implements IAdmBdtpEntity {
 
 	@Override
 	public void serializeJsonProp() {
-		if(getInfos() != null) {
+		if(infos != null) {
 			ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
 			try {
-				setStrInfos(objectMapper.writeValueAsString(getInfos()));
+				strInfos = objectMapper.writeValueAsString(infos);
 			} catch (JsonProcessingException e) {
 
 			}
-			setInfos(null);
+			infos = null;
 		}
 	}
 
@@ -62,11 +74,11 @@ public class AdmObject extends ObjectDigital implements IAdmBdtpEntity {
 		if(StrUtil.isNotBlank(strInfos)) {
 			ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
 			try {
-				setInfos(objectMapper.readValue(strInfos, ObjectNode.class));
+				infos = objectMapper.readValue(strInfos, ObjectNode.class);
 			} catch (IOException e) {
 
 			}
-			setStrInfos(null);
+			strInfos = null;
 		}
 	}
 

+ 5 - 11
src/main/java/com/persagy/bdtp/adm/entity/AdmPipe.java

@@ -15,7 +15,7 @@ import java.util.List;
 
 @Data
 @TableName(value = "adm_pipe",autoResultMap = true)
-public class AdmPipe extends BaseAdmDataEntity {
+public class AdmPipe extends BaseDeliveryEntity {
 
     private String objFrom;
 
@@ -41,12 +41,6 @@ public class AdmPipe extends BaseAdmDataEntity {
     )
     private ObjectNode infos;
 
-    /**  数模同步状态:0未同步, 1已同步 */
-    private Integer d2mState;
-
-    /** 交付BDTP状态:1已交付,0待交付 */
-    private Integer deliveryState;
-
     private String strRoute;
 
     private String strInfos;
@@ -65,11 +59,11 @@ public class AdmPipe extends BaseAdmDataEntity {
         if(infos != null) {
             ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
             try {
-                setStrInfos(objectMapper.writeValueAsString(infos));
+                strInfos = objectMapper.writeValueAsString(infos);
             } catch (JsonProcessingException e) {
 
             }
-            setInfos(null);
+            infos = null;
         }
     }
 
@@ -87,11 +81,11 @@ public class AdmPipe extends BaseAdmDataEntity {
         if(StrUtil.isNotBlank(strInfos)) {
             ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
             try {
-                setInfos(objectMapper.readValue(strInfos, ObjectNode.class));
+                infos = objectMapper.readValue(strInfos, ObjectNode.class);
             } catch (IOException e) {
 
             }
-            setStrInfos(null);
+            strInfos = null;
         }
     }
 

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

@@ -5,11 +5,7 @@ import lombok.Data;
 
 @Data
 @TableName(value = "adm_pipe_config",autoResultMap = true)
-public class AdmPipeConfig implements IAdmEntity {
-
-    private String id;
-
-    private String projectId;
+public class AdmPipeConfig extends BaseAdmEntity {
 
     private String classCodeFrom;
 
@@ -25,14 +21,4 @@ public class AdmPipeConfig implements IAdmEntity {
 
     private String flag;
 
-    @Override
-    public void serializeJsonProp() {
-
-    }
-
-    @Override
-    public void deserializeJsonProp() {
-
-    }
-
 }

+ 10 - 17
src/main/java/com/persagy/bdtp/adm/entity/AdmRelation.java

@@ -1,35 +1,28 @@
 package com.persagy.bdtp.adm.entity;
 
 import com.baomidou.mybatisplus.annotation.TableName;
-import com.persagy.dmp.digital.entity.ObjectRelation;
 import lombok.Data;
 
 @Data
 @TableName(value = "adm_relation",autoResultMap = true)
-public class AdmRelation extends ObjectRelation implements IAdmBdtpEntity {
+public class AdmRelation extends BaseDeliveryEntity {
 
-    private String clientDevice;
+    private String groupCode;
 
-    private String clientId;
+    private String graphId;
 
-    private Integer d2mState;
+    private String graphCode;
 
-    private Integer deliveryState;
+    private String relCode;
 
-    private String buildingId;
+    private String relValue;
 
-    private String floorId;
+    private String objFrom;
 
-    private String uploadFlag;
+    private String objTo;
 
-    @Override
-    public void serializeJsonProp() {
+    private String createApp;
 
-    }
-
-    @Override
-    public void deserializeJsonProp() {
-
-    }
+    private String updateApp;
 
 }

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

@@ -5,11 +5,7 @@ import lombok.Data;
 
 @Data
 @TableName(value = "adm_rels_config",autoResultMap = true)
-public class AdmRelsConfig implements IAdmEntity {
-
-    private String id;
-
-    private String projectId;
+public class AdmRelsConfig extends BaseAdmEntity {
 
     private String objTypeFrom;
 
@@ -29,14 +25,4 @@ public class AdmRelsConfig implements IAdmEntity {
 
     private String flag;
 
-    @Override
-    public void serializeJsonProp() {
-
-    }
-
-    @Override
-    public void deserializeJsonProp() {
-
-    }
-
 }

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

@@ -22,11 +22,17 @@ public class AdmUploadLog {
 	)
 	private Object data;
 
-	public AdmUploadLog(String uploadFlag, String entityType, String uploadTime, Object data) {
+	public AdmUploadLog(String uploadFlag, String uploadTime, Object data) {
 		this.uploadFlag = uploadFlag;
-		this.entityType = entityType;
+		this.entityType = getLogEntityType(data);
 		this.uploadTime = uploadTime;
 		this.data = data;
 	}
 
+	private String getLogEntityType(Object o){
+		if(o instanceof AdmObject)
+			return ((AdmObject) o).getObjType();
+		return o.getClass().getSimpleName();
+	}
+
 }

+ 1 - 15
src/main/java/com/persagy/bdtp/adm/entity/BaseAdmDataEntity.java

@@ -6,11 +6,7 @@ import lombok.Data;
  * 数据实体基类
  */
 @Data
-abstract public class BaseAdmDataEntity implements IAdmEntity {
-
-	protected String id;
-
-	protected String projectId;
+abstract public class BaseAdmDataEntity extends BaseAdmEntity {
 
 	protected String buildingId;
 
@@ -28,14 +24,4 @@ abstract public class BaseAdmDataEntity implements IAdmEntity {
 
 	protected String uploadFlag;
 
-	@Override
-	public void serializeJsonProp() {
-
-	}
-
-	@Override
-	public void deserializeJsonProp() {
-
-	}
-
 }

+ 23 - 0
src/main/java/com/persagy/bdtp/adm/entity/BaseAdmEntity.java

@@ -0,0 +1,23 @@
+package com.persagy.bdtp.adm.entity;
+
+import lombok.Data;
+
+/**
+ * 实体基类
+ */
+@Data
+abstract public class BaseAdmEntity {
+
+	protected String id;
+
+	protected String projectId;
+
+	public void serializeJsonProp() {
+
+	}
+
+	public void deserializeJsonProp() {
+
+	}
+
+}

+ 23 - 0
src/main/java/com/persagy/bdtp/adm/entity/BaseDeliveryEntity.java

@@ -0,0 +1,23 @@
+package com.persagy.bdtp.adm.entity;
+
+import lombok.Data;
+
+/**
+ * 需要交付给BDTP的实体基类
+ */
+@Data
+abstract public class BaseDeliveryEntity extends BaseAdmDataEntity {
+
+	/** 创建对象的本地设备(移动端) */
+	protected String clientDevice;
+
+	/** 由本地设备生成的对象id */
+	protected String clientId;
+
+	/**  数模同步状态:0未同步, 1已同步 */
+	protected Integer d2mState;
+
+	/** 交付BDTP状态:1已交付,0待交付 */
+	protected Integer deliveryState;
+
+}

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

@@ -1,55 +0,0 @@
-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);
-
-}

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

@@ -1,17 +0,0 @@
-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();
-
-}

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

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

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

@@ -14,7 +14,7 @@ public interface ISyncApp {
 
 	Map<String, Object> downloadFrameData(String groupCode, String projectId, String userId);
 
-	Map<String, Object> downloadFloorData(String projectId, String floorId, String uploadFlag, String lastDownloadTime);
+	/*Map<String, Object> downloadFloorData(String projectId, String floorId, String uploadFlag, String lastDownloadTime);*/
 
 	SyncData downloadBuildingData(String projectId, String buildingId, String uploadFlag, String lastDownloadTime);
 

+ 64 - 185
src/main/java/com/persagy/bdtp/adm/service/impl/SyncAppImpl.java

@@ -23,7 +23,6 @@ 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.common.model.response.CommonResult;
 import com.persagy.dmp.define.entity.RelationDefine;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -232,44 +231,6 @@ public class SyncAppImpl implements ISyncApp {
 	}
 
 	@Override
-	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));
-
-		//任务相关数据查询
-		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", serializeJsonProp(floorData));
-		data.put("relations", floorRel);
-
-		data.put("jobSpace", serializeJsonProp(jobSpace));
-		data.put("problemArch", serializeJsonProp(problemArch));
-		data.put("problemEquip", problemEquip);
-		data.put("file", file);
-		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, 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));
@@ -306,9 +267,10 @@ public class SyncAppImpl implements ISyncApp {
 	}
 
 	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)) {
+		if (StrUtil.isNotBlank(lastDownloadTime)) { //非初始化下载
+			if (StrUtil.isNotBlank(uploadFlag))
+				wrapper.and(w -> w.isNull("upload_flag").or().ne("upload_flag", uploadFlag));
+
 			wrapper.and(
 					w -> w.isNotNull("modified_time").gt("modified_time", lastDownloadTime)
 							.or()
@@ -321,151 +283,56 @@ public class SyncAppImpl implements ISyncApp {
 	@Transactional(rollbackFor = Exception.class)
 	public UploadRtn uploadData(SyncData uploadData, String projectId, String uploadFlag) {
 		UploadRtn rtn = new UploadRtn();
-		PsDateTime timestamp = new PsDateTime(System.currentTimeMillis());
+		String timestamp = DateUtil.format(new Date(), DatePattern.PURE_DATETIME_PATTERN);
 
 		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(deserializeJsonProp(uploadData.getObjects()), dbObjs, uploadFlag, timestamp, admObjMapper, "object");
+			List<AdmObject> expired = uploadAdmData(deserializeJsonProp(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");
+			List<AdmRelation> expired = uploadAdmData(uploadData.getRelations(), dbObjs, uploadFlag, timestamp, relationMapper, "relation");
 			rtn.setExpiredRelationIds(buildExpiredIds(expired));
 		}
 
-		String timestampStr = timestamp.toString();
 		if (CollUtil.isNotEmpty(uploadData.getPipes())) {
 			List<AdmPipe> dbObjs = pipeMapper.selectList(new QueryWrapper<AdmPipe>().eq("building_id", uploadData.getBuildingId()).eq("valid", ValidEnum.TRUE.getType()));
-			List<AdmPipe> expired = uploadAdmData(deserializeJsonProp(uploadData.getPipes()), dbObjs, uploadFlag, timestampStr, pipeMapper, "pipe");
+			List<AdmPipe> expired = uploadAdmData(deserializeJsonProp(uploadData.getPipes()), dbObjs, uploadFlag, timestamp, pipeMapper, "pipe");
 			rtn.setExpiredPipeIds(buildExpiredIds(expired));
 		}
 
 		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(deserializeJsonProp(uploadData.getJobSpace()), dbObjs, uploadFlag, timestampStr, jobSpaceMapper, null);
+			List<AdmJobSpace> expired = uploadAdmData(deserializeJsonProp(uploadData.getJobSpace()), dbObjs, uploadFlag, timestamp, jobSpaceMapper, null);
 			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(deserializeJsonProp(uploadData.getProblemArch()), dbObjs, uploadFlag, timestampStr, problemArchMapper, null);
+			List<AdmProblemArch> expired = uploadAdmData(deserializeJsonProp(uploadData.getProblemArch()), dbObjs, uploadFlag, timestamp, problemArchMapper, null);
 			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, null);
+			List<AdmProblemEquip> expired = uploadAdmData(uploadData.getProblemEquip(), dbObjs, uploadFlag, timestamp, problemEquipMapper, null);
 			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, null);
+			List<AdmFile> expired = uploadAdmData(uploadData.getFile(), dbObjs, uploadFlag, timestamp, fileMapper, null);
 			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(deserializeJsonProp(uploadData.getQrCode()), dbObjs, uploadFlag, timestampStr, qrCodeMapper, null);
+			List<AdmQrCode> expired = uploadAdmData(deserializeJsonProp(uploadData.getQrCode()), dbObjs, uploadFlag, timestamp, qrCodeMapper, null);
 			rtn.setExpiredQrCodeIds(buildExpiredIds(expired));
 		}
 
-		rtn.setTimestamp(timestampStr);
-		rtn.setTimestampMillis(timestamp.getMillis());
+		rtn.setTimestamp(timestamp);
 		rtn.setBuildingId(uploadData.getBuildingId());
 		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<>();
-
-		String timestampStr = timestamp.toString();
-
-		for (T obj : objs) {
-			logService.saveUploadLog(new AdmUploadLog(uploadFlag, getLogEntityType(obj), timestampStr, obj));
-
-			T dbObj = map.get(obj.getId());
-			if (dbObj == null) {
-				if(obj.getValid().intValue() == ValidEnum.FALSE.getType())
-					continue;
-
-				obj.setCreationTime(timestamp);
-				obj.setModifiedTime(timestamp); //新增时设置modifiedTime,方便后续处理
-				obj.setCreator(AdmConst.CREATOR_APP);
-				setBdtpUploadProp(obj, null, 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);
-
-					//合并对象信息点
-					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);
-
-					if(obj.getValid().intValue() == ValidEnum.FALSE.getType())
-						msgRemove.add(obj);
-					else
-						msgModify.add(obj);
-				}
-//			}
-		}
-
-		sendD2mMessage(objectType, msgAdd, msgModify, msgRemove);
-
-		return expired;
-	}
-
-	private String getLogEntityType(Object o){
-		if(o instanceof AdmObject)
-			return ((AdmObject) o).getObjType();
-		return o.getClass().getSimpleName();
-	}
-
-	private void setBdtpUploadProp(IAdmBdtpEntity obj, IAdmBdtpEntity dbObj, String uploadFlag){
-		obj.setUploadFlag(uploadFlag);
-		obj.setD2mState(ValidEnum.FALSE.getType());
-		obj.setDeliveryState(ValidEnum.FALSE.getType());
-
-		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){
 		List<T> expired = new ArrayList<>();
 		HashMap<String, T> dbMap = new HashMap<>(dbObjs.size());
@@ -477,14 +344,10 @@ public class SyncAppImpl implements ISyncApp {
 		List<T> msgModify = new ArrayList<>();
 		List<T> msgRemove = new ArrayList<>();
 		for (T obj : objs) {
-			logService.saveUploadLog(new AdmUploadLog(uploadFlag, getLogEntityType(obj), timestamp, obj));
+			if(obj == null)
+				continue;
 
-			if(d2mType != null) {
-				if(obj instanceof AdmPipe) {
-					((AdmPipe) obj).setD2mState(ValidEnum.FALSE.getType());
-					((AdmPipe) obj).setDeliveryState(ValidEnum.FALSE.getType());
-				}
-			}
+			logService.saveUploadLog(new AdmUploadLog(uploadFlag, timestamp, obj));
 
 			T dbObj = dbMap.get(obj.getId());
 			if (dbObj == null) {
@@ -492,25 +355,27 @@ public class SyncAppImpl implements ISyncApp {
 					continue;
 
 				obj.setCreationTime(timestamp);
-				obj.setModifiedTime(timestamp); //新增时设置modifiedTime,方便后续处理
 				obj.setCreator(AdmConst.CREATOR_APP);
 				obj.setUploadFlag(uploadFlag);
 
+				if(d2mType != null)
+					setDeliveryDataProps((BaseDeliveryEntity) obj, null);
+
 				mapper.insert(obj);
 
 				if(d2mType != null)
 					msgAdd.add(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)) {
+//				String dbTs;
+//				String ts;
+//				if(dbObj.getModifiedTime() != null){
+//					dbTs = dbObj.getModifiedTime();
+//					ts = obj.getModifiedTime();
+//				} else {
+//					dbTs = dbObj.getCreationTime();
+//					ts = obj.getCreationTime();
+//				}
+//				if (!dbTs.equals(ts)) {
 //					//TODO 时间戳不一致,离线数据无效,暂时跳过处理
 //					expired.add(obj);
 //				} else {
@@ -518,18 +383,14 @@ public class SyncAppImpl implements ISyncApp {
 					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);
-						}
-					}
+					if(d2mType != null)
+						setDeliveryDataProps((BaseDeliveryEntity) obj, null);
+
+					//合并信息点
+					if(dbObj instanceof AdmObject && obj instanceof AdmObject)
+						((AdmObject) obj).setInfos(mergeInfos(((AdmObject) obj).getInfos(), ((AdmObject) dbObj).getInfos()));
+					else if(dbObj instanceof AdmPipe && obj instanceof AdmPipe)
+						((AdmPipe) obj).setInfos(mergeInfos(((AdmPipe) obj).getInfos(), ((AdmPipe) dbObj).getInfos()));
 
 					mapper.updateById(obj);
 
@@ -539,8 +400,8 @@ public class SyncAppImpl implements ISyncApp {
 						else
 							msgModify.add(obj);
 					}
-				}
-//			}
+//				}
+			}
 		}
 
 		if(d2mType != null)
@@ -549,6 +410,24 @@ public class SyncAppImpl implements ISyncApp {
 		return expired;
 	}
 
+	private void setDeliveryDataProps(BaseDeliveryEntity obj, BaseDeliveryEntity dbObj){
+		obj.setD2mState(ValidEnum.FALSE.getType());
+		obj.setDeliveryState(ValidEnum.FALSE.getType());
+
+		if(dbObj != null) {
+			obj.setClientId(dbObj.getClientId());
+			obj.setClientDevice(dbObj.getClientDevice());
+		}
+	}
+
+	private ObjectNode mergeInfos(ObjectNode infos, ObjectNode dbInfos){
+		if(dbInfos != null) {
+			if(infos != null)
+				dbInfos.setAll(infos);
+		}
+		return dbInfos;
+	}
+
 	private void sendD2mMessage(String objectType, List<?> msgAdd, List<?> msgModify, List<?> msgRemove){
 		D2mMessage message = new D2mMessage();
 		message.setItemType(objectType);
@@ -560,10 +439,10 @@ public class SyncAppImpl implements ISyncApp {
 			syncModel.sendMessageToModel(message);
 	}
 
-	private List<String> buildExpiredIds(List<? extends IAdmEntity> expired){
+	private List<String> buildExpiredIds(List<? extends BaseAdmDataEntity> expired){
 		if(expired.size() > 0) {
 			List<String> ids = new ArrayList<>();
-			for(IAdmEntity entity : expired) {
+			for(BaseAdmDataEntity entity : expired) {
 				ids.add(entity.getId());
 			}
 			return ids;
@@ -571,15 +450,15 @@ public class SyncAppImpl implements ISyncApp {
 		return null;
 	}
 
-	private <T extends IAdmEntity> List<T> serializeJsonProp(List<T> list){
-		for(IAdmEntity entity : list) {
+	private <T extends BaseAdmEntity> List<T> serializeJsonProp(List<T> list){
+		for(BaseAdmEntity entity : list) {
 			entity.serializeJsonProp();
 		}
 		return list;
 	}
 
-	private <T extends IAdmEntity> List<T> deserializeJsonProp(List<T> list){
-		for(IAdmEntity entity : list) {
+	private <T extends BaseAdmEntity> List<T> deserializeJsonProp(List<T> list){
+		for(BaseAdmEntity entity : list) {
 			entity.deserializeJsonProp();
 		}
 		return list;

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

@@ -27,7 +27,6 @@ import com.persagy.dmp.common.constant.ResponseCode;
 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.Polygon;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -114,9 +113,13 @@ public class SyncOldAdmImpl implements ISyncOldAdm {
 			dbMap.put(getFixedIdForSync(dbItem, objMark), dbItem);
 		}
 
+		String timestamp =  DateUtil.format(new Date(), DatePattern.PURE_DATETIME_PATTERN);
+
 		for(AdmObject obj : objs) {
 			AdmObject dbItem = dbMap.remove(getFixedIdForSync(obj, objMark));
 			if(dbItem == null) {
+				obj.setCreator(AdmConst.CREATOR_SYNC);
+				obj.setModifiedTime(timestamp); //保留从老adm同步过来的createTime,设置updateTime
 				obj.setD2mState(ValidEnum.TRUE.getType());
 				obj.setDeliveryState(ValidEnum.FALSE.getType());
 
@@ -130,7 +133,7 @@ public class SyncOldAdmImpl implements ISyncOldAdm {
 
 				operations[0].add(obj); //add
 			} else {
-				AdmObject updateItem = mergeObj(obj, dbItem, objMark);
+				AdmObject updateItem = mergeObj(obj, dbItem, timestamp, objMark);
 				if(updateItem != null)
 					operations[1].add(updateItem); //modify
 
@@ -143,7 +146,7 @@ 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(timestamp);
 				obj.setModifier(AdmConst.CREATOR_SYNC);
 				obj.setUploadFlag(null);
 				operations[1].add(obj);
@@ -171,7 +174,7 @@ public class SyncOldAdmImpl implements ISyncOldAdm {
 		return obj.getId();
 	}
 
-	private AdmObject mergeObj(AdmObject obj, AdmObject dbItem, int objMark){
+	private AdmObject mergeObj(AdmObject obj, AdmObject dbItem, String timestamp, int objMark){
 		if(objNotChange(obj, dbItem))
 			return null;
 
@@ -188,7 +191,7 @@ public class SyncOldAdmImpl implements ISyncOldAdm {
 				dbItem.getInfos().setAll(obj.getInfos());
 		}
 
-		dbItem.setModifiedTime(new PsDateTime(System.currentTimeMillis()));
+		dbItem.setModifiedTime(timestamp);
 		dbItem.setModifier(AdmConst.CREATOR_SYNC);
 		dbItem.setUploadFlag(null);
 		dbItem.setD2mState(ValidEnum.TRUE.getType());
@@ -244,10 +247,8 @@ public class SyncOldAdmImpl implements ISyncOldAdm {
 		if (base.getInfos() != null)
 			obj.setInfos(mapToNode(base.getInfos()));
 
-		if(base.getCreateTime() != null)
-			obj.setCreationTime(new PsDateTime(DateUtil.parse(base.getCreateTime(), "yyyy-MM-dd HH:mm:ss")));
-		if(base.getLastUpdate() != null)
-			obj.setModifiedTime(new PsDateTime(DateUtil.parse(base.getLastUpdate(), "yyyy-MM-dd HH:mm:ss")));
+		if(base.getCreateTime() != null) //同步数据中没有createTime时,设置为当前时间
+			obj.setCreationTime(DateUtil.format(new Date(), DatePattern.PURE_DATETIME_PATTERN));
 
 		obj.setValid(ValidEnum.TRUE.getType());
 

src/main/resources/mapper/AdmObjectMapper.xml → src/main/resources/mapper/AdmObjectMapper.xml.bak


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

@@ -14,7 +14,7 @@ import java.util.List;
 public class PipeCfgs {
 
     public static void main(String[] args) throws Exception {
-        new PipeCfgs().read("ac");
+        new PipeCfgs().read("ff");
     }
 
     private ObjectMapper objectMapper = new ObjectMapper();;

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

@@ -15,7 +15,7 @@ import java.util.Map;
 public class RelCfgs {
 
     public static void main(String[] args) throws Exception {
-        new RelCfgs().read("ac");
+        new RelCfgs().read("ff");
     }
 
     private ObjectMapper objectMapper = new ObjectMapper();;