Browse Source

1019 数据同步修改

zhaoyk 3 years ago
parent
commit
11a626685e

+ 10 - 0
src/main/java/com/persagy/bdtp/adm/dao/AdmUploadLogMapper.java

@@ -0,0 +1,10 @@
+package com.persagy.bdtp.adm.dao;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.persagy.bdtp.adm.entity.AdmUploadLog;
+import org.apache.ibatis.annotations.Mapper;
+
+@Mapper
+public interface AdmUploadLogMapper extends BaseMapper<AdmUploadLog> {
+
+}

+ 32 - 0
src/main/java/com/persagy/bdtp/adm/entity/AdmUploadLog.java

@@ -0,0 +1,32 @@
+package com.persagy.bdtp.adm.entity;
+
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
+import lombok.Data;
+
+@Data
+@TableName(value = "adm_upload_log",autoResultMap = true)
+public class AdmUploadLog {
+
+	private String uploadFlag;
+
+	private String entityType;
+
+	private String uploadTime;
+
+	private String operation;
+
+	@TableField(
+			typeHandler = JacksonTypeHandler.class
+	)
+	private Object data;
+
+	public AdmUploadLog(String uploadFlag, String entityType, String uploadTime, Object data) {
+		this.uploadFlag = uploadFlag;
+		this.entityType = entityType;
+		this.uploadTime = uploadTime;
+		this.data = data;
+	}
+
+}

+ 13 - 0
src/main/java/com/persagy/bdtp/adm/service/IAdmLogService.java

@@ -0,0 +1,13 @@
+package com.persagy.bdtp.adm.service;
+
+import com.persagy.bdtp.adm.entity.AdmUploadLog;
+
+import java.util.List;
+
+public interface IAdmLogService {
+
+	void saveUploadLog(List<AdmUploadLog> logs);
+
+	void saveUploadLog(AdmUploadLog log);
+
+}

+ 36 - 0
src/main/java/com/persagy/bdtp/adm/service/impl/AdmLogServiceImpl.java

@@ -0,0 +1,36 @@
+package com.persagy.bdtp.adm.service.impl;
+
+import cn.hutool.core.collection.CollUtil;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.persagy.bdtp.adm.common.AdmConst;
+import com.persagy.bdtp.adm.dao.AdmObjectMapper;
+import com.persagy.bdtp.adm.dao.AdmUploadLogMapper;
+import com.persagy.bdtp.adm.entity.AdmObject;
+import com.persagy.bdtp.adm.entity.AdmUploadLog;
+import com.persagy.bdtp.adm.service.IAdmLogService;
+import com.persagy.bdtp.adm.service.IAdmObjectService;
+import lombok.RequiredArgsConstructor;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.List;
+
+@Service
+@Transactional(rollbackFor = Exception.class)
+@RequiredArgsConstructor
+public class AdmLogServiceImpl extends ServiceImpl<AdmUploadLogMapper, AdmUploadLog> implements IAdmLogService {
+
+	private final AdmUploadLogMapper uploadLogMapper;
+
+	@Override
+	public void saveUploadLog(List<AdmUploadLog> logs) {
+		saveBatch(logs);
+	}
+
+	@Override
+	public void saveUploadLog(AdmUploadLog log) {
+		save(log);
+	}
+
+}

+ 16 - 0
src/main/java/com/persagy/bdtp/adm/service/impl/SyncAppImpl.java

@@ -82,6 +82,9 @@ public class SyncAppImpl implements ISyncApp {
 	@Autowired
 	private ObjectMapper objectMapper;
 
+	@Autowired
+	private IAdmLogService logService;
+
 //	@Autowired
 //	ResourceLoader resourceLoader;
 
@@ -380,7 +383,12 @@ public class SyncAppImpl implements ISyncApp {
 		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())
@@ -441,6 +449,12 @@ public class SyncAppImpl implements ISyncApp {
 		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());
@@ -463,6 +477,8 @@ 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(d2mType != null) {
 				if(obj instanceof AdmPipe) {
 					((AdmPipe) obj).setD2mState(ValidEnum.FALSE.getType());

+ 19 - 5
src/main/java/com/persagy/bdtp/adm/service/impl/SyncOldAdmImpl.java

@@ -79,6 +79,7 @@ public class SyncOldAdmImpl implements ISyncOldAdm {
 			transEntities(spObjs, spList, (spObj, oSp) -> setSpData(spObj, (OSpace) oSp));
 			transEntities(eqObjs, eqList, (eqObj, oEq) -> setEqData(eqObj, (OEquip) oEq));
 
+			Map<String, String> floorIdMap = new HashMap<>();
 			List<AdmObject> dbBds = objectService.queryM2dByObjType(projectId, AdmConst.OBJ_TYPE_BUILDING);
 			List<AdmObject> dbFls = objectService.queryM2dByObjType(projectId, AdmConst.OBJ_TYPE_FLOOR);
 			List<AdmObject> dbSps = objectService.queryM2dByObjType(projectId, AdmConst.OBJ_TYPE_SPACE);
@@ -86,10 +87,10 @@ public class SyncOldAdmImpl implements ISyncOldAdm {
 
 			List<AdmObject>[] operations = new List[]{new ArrayList<>(), new ArrayList<>()};
 
-			syncObjs(bdObjs, dbBds, operations, 1);
-			syncObjs(flObjs, dbFls, operations, 2);
-			syncObjs(spObjs, dbSps, operations, 3);
-			syncObjs(eqObjs, dbEqs, operations, 4);
+			syncObjs(bdObjs, dbBds, operations, 1, floorIdMap);
+			syncObjs(flObjs, dbFls, operations, 2, floorIdMap);
+			syncObjs(spObjs, dbSps, operations, 3, floorIdMap);
+			syncObjs(eqObjs, dbEqs, operations, 4, floorIdMap);
 
 			objectService.insert(operations[0]);
 			objectService.update(operations[1]);
@@ -107,7 +108,7 @@ public class SyncOldAdmImpl implements ISyncOldAdm {
 	}
 
 	//TODO 设备同步时,按正逆向规则过滤
-	private void syncObjs(List<AdmObject> objs, List<AdmObject> dbItems, List<AdmObject>[] operations, int objMark){
+	private void syncObjs(List<AdmObject> objs, List<AdmObject> dbItems, List<AdmObject>[] operations, int objMark, Map<String, String> floorIdMap){
 		HashMap<String, AdmObject> dbMap = new HashMap<>();
 		for (AdmObject dbItem : dbItems){
 			dbMap.put(getFixedIdForSync(dbItem, objMark), dbItem);
@@ -118,11 +119,24 @@ public class SyncOldAdmImpl implements ISyncOldAdm {
 			if(dbItem == null) {
 				obj.setD2mState(ValidEnum.TRUE.getType());
 				obj.setDeliveryState(ValidEnum.FALSE.getType());
+
+				if(objMark == 3 || objMark == 4) { //新增空间|设备
+					if(floorIdMap.size() > 0){
+						String fixedFloorId = floorIdMap.get(obj.getFloorId());
+						if(fixedFloorId != null)
+							obj.setFloorId(fixedFloorId);
+					}
+				}
+
 				operations[0].add(obj); //add
 			} else {
 				AdmObject updateItem = mergeObj(obj, dbItem, objMark);
 				if(updateItem != null)
 					operations[1].add(updateItem); //modify
+
+				if(objMark == 2 && !obj.getId().equals(dbItem.getId())) {
+					floorIdMap.put(obj.getId(), dbItem.getId());
+				}
 			}
 		}