Browse Source

代码整理

zhangqiankun 3 years ago
parent
commit
f81f71b121

+ 5 - 0
src/main/java/com/persagy/transfer/constant/SwitchConstant.java

@@ -56,6 +56,11 @@ public interface SwitchConstant {
     String USER_ID_HEADER = "userId";
 
     /**
+     * 连接符 .
+     */
+    String POINT = ".";
+    
+    /**
      * 连接符 ?
      */
     String WHERE = "?";

+ 0 - 30
src/main/java/com/persagy/transfer/controller/RwdDefFuncidController.java

@@ -49,35 +49,5 @@ public class RwdDefFuncidController {
 		}
         return ResponseUtil.successResult(list, (long)list.size());
     }
-
-    /**
-     * 新增
-     */
-	@ApiOperation(value = "保存")
-	@RequestMapping(value = "createRwdDefFuncid")
-    public ResponseResult createRwdDefFuncid(@RequestBody RwdDefFuncid rwdDefFuncid) {
-        boolean result = this.rwdDefFuncidService.save(rwdDefFuncid);
-        return result ? ResponseUtil.successResult("保存成功") : ResponseUtil.errorResult("保存失败");
-    }
-    
-    /**
-     * 更新
-     */
-	@ApiOperation(value = "更新")
-	@RequestMapping(value = "updateRwdDefFuncid")
-    public ResponseResult updateRwdDefFuncid(@RequestBody RwdDefFuncid rwdDefFuncid) {
-        boolean result = this.rwdDefFuncidService.updateById(rwdDefFuncid);
-        return result ? ResponseUtil.successResult("更新成功") : ResponseUtil.errorResult("更新失败");
-    }
-
-    /**
-     * 物理删除
-     */
-    @ApiOperation(value = "删除")
-    @RequestMapping(value = "deleteRwdDefFuncid")
-    public ResponseResult deleteRwdDefFuncid(@RequestBody RwdDefFuncid rwdDefFuncid) {
-        boolean result = this.rwdDefFuncidService.removeById(rwdDefFuncid.getId());
-        return result ? ResponseUtil.successResult("删除成功") : ResponseUtil.errorResult("删除失败");
-    }
     
 }

+ 0 - 30
src/main/java/com/persagy/transfer/controller/RwdDefFuncidWdController.java

@@ -50,34 +50,4 @@ public class RwdDefFuncidWdController {
         return ResponseUtil.successResult(list, (long)list.size());
     }
 
-    /**
-     * 新增
-     */
-	@ApiOperation(value = "保存")
-	@RequestMapping(value = "createRwdDefFuncidWd")
-    public ResponseResult createRwdDefFuncidWd(@RequestBody RwdDefFuncidWd rwdDefFuncidWd) {
-        boolean result = this.rwdDefFuncidWdService.save(rwdDefFuncidWd);
-        return result ? ResponseUtil.successResult("保存成功") : ResponseUtil.errorResult("保存失败");
-    }
-    
-    /**
-     * 更新
-     */
-	@ApiOperation(value = "更新")
-	@RequestMapping(value = "updateRwdDefFuncidWd")
-    public ResponseResult updateRwdDefFuncidWd(@RequestBody RwdDefFuncidWd rwdDefFuncidWd) {
-        boolean result = this.rwdDefFuncidWdService.updateById(rwdDefFuncidWd);
-        return result ? ResponseUtil.successResult("更新成功") : ResponseUtil.errorResult("更新失败");
-    }
-
-    /**
-     * 物理删除
-     */
-    @ApiOperation(value = "删除")
-    @RequestMapping(value = "deleteRwdDefFuncidWd")
-    public ResponseResult deleteRwdDefFuncidWd(@RequestBody RwdDefFuncidWd rwdDefFuncidWd) {
-        boolean result = this.rwdDefFuncidWdService.removeById(rwdDefFuncidWd.getId());
-        return result ? ResponseUtil.successResult("删除成功") : ResponseUtil.errorResult("删除失败");
-    }
-    
 }

+ 11 - 8
src/main/java/com/persagy/transfer/controller/RwdObjectWdController.java

@@ -1,5 +1,8 @@
 package com.persagy.transfer.controller;
 
+import java.util.List;
+
+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.RequestMethod;
@@ -9,7 +12,9 @@ import com.google.common.collect.Lists;
 import com.persagy.common.utils.ResponseResult;
 import com.persagy.common.utils.ResponseUtil;
 import com.persagy.transfer.pojo.dto.RwdObjectWd;
+import com.persagy.transfer.service.IRwdObjectWdService;
 
+import cn.hutool.core.collection.CollectionUtil;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 
@@ -27,8 +32,8 @@ import io.swagger.annotations.ApiOperation;
 @RequestMapping(value = "/rwdObjectWd", method = RequestMethod.POST)
 public class RwdObjectWdController {
 	
-    //@Autowired
-    //private IRwdObjectWdService rwdObjectWdService;
+    @Autowired
+    private IRwdObjectWdService rwdObjectWdService;
     
     /**
      * 列表查询
@@ -36,13 +41,11 @@ public class RwdObjectWdController {
     @ApiOperation(value = "列表查询")
     @RequestMapping(value = "queryRwdObjectWdList")
     public ResponseResult queryRwdObjectWdList(@RequestBody RwdObjectWd rwdObjectWd) {
-    	/*LambdaQueryWrapper<RwdObjectWd> queryWrapper = new RwdObjectWd.BuilderQueryWrapper()
-    			.projectIdEq("Pj1101050001").builder();
-    	List<RwdObjectWd> list = this.rwdObjectWdService.list(queryWrapper);
+    	List<RwdObjectWd> list = this.rwdObjectWdService.listByProjectId(rwdObjectWd.getProjectId(), rwdObjectWd.getClassCode(), rwdObjectWd.getObjType());
     	if (CollectionUtil.isEmpty(list)) {
-			return ResponseUtil.successResult(Lists.newArrayList(), 0L);
-		}*/
-        return ResponseUtil.successResult(Lists.newArrayList(), 0L);
+    		return ResponseUtil.successResult(Lists.newArrayList(), 0L);
+		}
+        return ResponseUtil.successResult(list, (long)list.size());
     }
 
 }

+ 0 - 30
src/main/java/com/persagy/transfer/controller/WdclassRelPersagyController.java

@@ -49,34 +49,4 @@ public class WdclassRelPersagyController {
         return ResponseUtil.successResult(list, (long)list.size());
     }
 
-    /**
-     * 新增
-     */
-	@ApiOperation(value = "保存")
-	@RequestMapping(value = "createWdclassRelPersagy")
-    public ResponseResult createWdclassRelPersagy(@RequestBody WdclassRelPersagy wdclassRelPersagy) {
-        boolean result = this.wdclassRelPersagyService.save(wdclassRelPersagy);
-        return result ? ResponseUtil.successResult("保存成功") : ResponseUtil.errorResult("保存失败");
-    }
-    
-    /**
-     * 更新
-     */
-	@ApiOperation(value = "更新")
-	@RequestMapping(value = "updateWdclassRelPersagy")
-    public ResponseResult updateWdclassRelPersagy(@RequestBody WdclassRelPersagy wdclassRelPersagy) {
-        boolean result = this.wdclassRelPersagyService.updateById(wdclassRelPersagy);
-        return result ? ResponseUtil.successResult("更新成功") : ResponseUtil.errorResult("更新失败");
-    }
-
-    /**
-     * 物理删除
-     */
-    @ApiOperation(value = "删除")
-    @RequestMapping(value = "deleteWdclassRelPersagy")
-    public ResponseResult deleteWdclassRelPersagy(@RequestBody WdclassRelPersagy wdclassRelPersagy) {
-        boolean result = this.wdclassRelPersagyService.removeById(wdclassRelPersagy.getId());
-        return result ? ResponseUtil.successResult("删除成功") : ResponseUtil.errorResult("删除失败");
-    }
-    
 }

+ 0 - 30
src/main/java/com/persagy/transfer/controller/WdfacilityRelPersagyController.java

@@ -49,34 +49,4 @@ public class WdfacilityRelPersagyController {
         return ResponseUtil.successResult(list, (long)list.size());
     }
 
-    /**
-     * 新增
-     */
-	@ApiOperation(value = "保存")
-	@RequestMapping(value = "createWdfacilityRelPersagy")
-    public ResponseResult createWdfacilityRelPersagy(@RequestBody WdfacilityRelPersagy wdfacilityRelPersagy) {
-        boolean result = this.wdfacilityRelPersagyService.save(wdfacilityRelPersagy);
-        return result ? ResponseUtil.successResult("保存成功") : ResponseUtil.errorResult("保存失败");
-    }
-    
-    /**
-     * 更新
-     */
-	@ApiOperation(value = "更新")
-	@RequestMapping(value = "updateWdfacilityRelPersagy")
-    public ResponseResult updateWdfacilityRelPersagy(@RequestBody WdfacilityRelPersagy wdfacilityRelPersagy) {
-        boolean result = this.wdfacilityRelPersagyService.updateById(wdfacilityRelPersagy);
-        return result ? ResponseUtil.successResult("更新成功") : ResponseUtil.errorResult("更新失败");
-    }
-
-    /**
-     * 物理删除
-     */
-    @ApiOperation(value = "删除")
-    @RequestMapping(value = "deleteWdfacilityRelPersagy")
-    public ResponseResult deleteWdfacilityRelPersagy(@RequestBody WdfacilityRelPersagy wdfacilityRelPersagy) {
-        boolean result = this.wdfacilityRelPersagyService.removeById(wdfacilityRelPersagy.getId());
-        return result ? ResponseUtil.successResult("删除成功") : ResponseUtil.errorResult("删除失败");
-    }
-    
 }

+ 1 - 19
src/main/java/com/persagy/transfer/controller/WdprojRelPersagyprojController.java

@@ -32,6 +32,7 @@ import io.swagger.annotations.ApiOperation;
 @RestController
 @RequestMapping(value = "/wdprojRelPersagyproj", method = RequestMethod.POST)
 public class WdprojRelPersagyprojController {
+	
     @Autowired
     private IWdprojRelPersagyprojService wdprojRelPersagyprojService;
     
@@ -49,24 +50,5 @@ public class WdprojRelPersagyprojController {
         return ResponseUtil.successResult(list, (long)list.size());
     }
 
-    /**
-     * 新增
-     */
-	@ApiOperation(value = "保存")
-	@RequestMapping(value = "createWdprojRelPersagyproj")
-    public ResponseResult createWdprojRelPersagyproj(@RequestBody WdprojRelPersagyproj wdprojRelPersagyproj) {
-        boolean result = this.wdprojRelPersagyprojService.save(wdprojRelPersagyproj);
-        return result ? ResponseUtil.successResult("保存成功") : ResponseUtil.errorResult("保存失败");
-    }
-    
-    /**
-     * 更新
-     */
-	@ApiOperation(value = "更新")
-	@RequestMapping(value = "updateWdprojRelPersagyproj")
-    public ResponseResult updateWdprojRelPersagyproj(@RequestBody WdprojRelPersagyproj wdprojRelPersagyproj) {
-        boolean result = this.wdprojRelPersagyprojService.updateById(wdprojRelPersagyproj);
-        return result ? ResponseUtil.successResult("更新成功") : ResponseUtil.errorResult("更新失败");
-    }
 
 }

+ 196 - 0
src/main/java/com/persagy/transfer/handle/WDRwdObjectTransferHandler.java

@@ -0,0 +1,196 @@
+package com.persagy.transfer.handle;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+import org.springframework.transaction.annotation.Transactional;
+
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.google.common.collect.Lists;
+import com.persagy.common.utils.StringUtil;
+import com.persagy.transfer.cache.LocalCache;
+import com.persagy.transfer.constant.InfosKeyConstant;
+import com.persagy.transfer.constant.ObjectTypeMapping;
+import com.persagy.transfer.constant.SwitchConstant;
+import com.persagy.transfer.pojo.dto.RwdObjectWd;
+import com.persagy.transfer.pojo.dto.WdclassRelPersagy;
+import com.persagy.transfer.pojo.dto.WdfacilityRelPersagy;
+import com.persagy.transfer.service.IHydomcAssetService;
+import com.persagy.transfer.service.IHydomcAssetspecService;
+import com.persagy.transfer.service.IRwdObjectWdService;
+import com.persagy.transfer.service.IWdfacilityRelPersagyService;
+import com.persagy.transfer.utils.StringTool;
+
+import cn.hutool.core.collection.CollectionUtil;
+import lombok.extern.slf4j.Slf4j;
+
+/**
+ * 
+ * 同步物理世界的对象至万达数据库中
+ * 
+ * @version 1.0.0
+ * @company persagy 
+ * @author YangWanYi
+ * @date 2021年9月17日 上午10:25:53
+ */
+@Slf4j
+@Component
+public class WDRwdObjectTransferHandler {
+	
+    @Autowired
+    private IRwdObjectWdService rwdObjectWdService;
+    
+    @Autowired
+    private IHydomcAssetService hydomcAssetService;
+    
+    @Autowired
+    private IHydomcAssetspecService hydomcAssetspecService;
+
+    @Autowired
+    private IWdfacilityRelPersagyService wdfacilityRelPersagyService;
+	
+    /**
+     * 开始同步设备数据到万达数据库
+     * 
+     * @company persagy 
+     * @author YangWanYi
+     * @date 2021年9月17日 下午6:10:07
+     */
+	public void syncRwdObject2WD() {
+		log.info("开始同步设备数据到万达数据库");
+		
+    	Set<String> classCodes = LocalCache.BDTP_CLASS_CODE_BY_WD;
+    	Map<String, String> projectMaps = LocalCache.PROJECT_MAPPING_BY_WD;
+    	Set<String> projectIds = projectMaps.keySet();
+    	
+    	List<RwdObjectWd> objectLists = null;
+    	// 物理世界对象数据获取
+    	for (String classCode : classCodes) {
+    		for (String projectId : projectIds) {
+    			// 以 classCode、projectId 以及 objType=equipment 为条件,获取所有的对象信息
+    			objectLists = this.rwdObjectWdService.listByProjectId(projectId, classCode, ObjectTypeMapping.EQUIPMENT);
+    			// 处理中台数据 -> 万达数据库
+    			this.handleObjectLists(objectLists, projectId, classCode);
+    		}
+		}
+	}
+	
+	/**
+	 * 
+	 * 处理中台的对象数据,并进行同步
+	 * 
+     * @param rwdObjecWdList       博锐尚格的项目对象
+     * @param projectId 博锐项目ID
+     * @param classCode 博锐类型编码
+     * @author YangWanYi
+     * @describe 同步万达设备数据的新增与更新
+     * @date 2021/9/16 14:19
+     */
+    private void handleObjectLists(List<RwdObjectWd> rwdObjecWdList, String projectId, String classCode) {
+    	// 获取万达项目ID
+        String wdProjectId = LocalCache.PROJECT_MAPPING_BY_WD.get(projectId);
+        
+        
+        List<WdfacilityRelPersagy> wdfacilityRelList = null;
+        for (RwdObjectWd rwdObjectWd : rwdObjecWdList) {
+        	// 验证此对象是否需要进行同步
+        	String localId = rwdObjectWd.getLocalId();
+        	if (StringUtil.isBlank(localId)) {
+				log.warn("项目ID为:{} 的对象本地编码为空,对象ID:{}", projectId, rwdObjectWd.getId());
+				continue;
+			}
+        	localId = localId.substring(0, localId.lastIndexOf(SwitchConstant.POINT));
+        	WdclassRelPersagy calassPersagy = LocalCache.CLASS_CODE_MAPPING_BY_WD.get(LocalCache.getWDCacheKey(classCode, localId));
+        	if (calassPersagy == null) {
+        		log.warn("项目ID为:{} 的对象本地编码不匹配,对象ID:{},本地编码:{}", projectId, rwdObjectWd.getId(), localId);
+        		continue;
+			}
+        	
+        	// 需要进行同步的对象,开始同步
+        	if (StringUtil.isBlank(rwdObjectWd.getInfos())) {
+        		continue;
+    		}
+        	
+        	try {
+        		// 防止一个对象数据不正确,影响到所有对象的同步
+        		JSONObject infos = JSONObject.parseObject(rwdObjectWd.getInfos());
+        		// 获取设备信息主键编码
+            	String sbybm = StringTool.object2String(infos.get(InfosKeyConstant.EQUIPMENT_CODE));
+            	if (StringUtil.isBlank(sbybm)) {
+        			log.warn("设备信息编码为空,不进行同步");
+        			continue;
+        		}
+            	// 查询出18类设备单独的信息点
+                if (CollectionUtil.isEmpty(wdfacilityRelList)) {
+                	// 循环万达项目ID与博锐尚格项目ID映射表数据时,wdfacility_rel_persagy只查询一次
+                    wdfacilityRelList = this.listWdfacilityRelPersagy(calassPersagy.getWdClassCode(), calassPersagy.getClassstructureid());
+                }
+                
+                // 数据开始同步
+                this.saveHydomcAssetAndAssetspec(wdfacilityRelList, rwdObjectWd, infos, wdProjectId, calassPersagy.getClassstructureid(), sbybm);
+			} catch (Exception e) {
+				log.error("对象数据同步失败,失败对象ID:" + rwdObjectWd.getId(), e);
+			}
+        }
+    }
+    
+    /**
+     * 保存 设备参数信息  主从表数据
+     * 
+     * @param wdfacilityRelList 筛选后的万达设备参数信息表与博锐尚格信息点的映射表数据
+     * @param rwdObjectWd       物理世界对象数据
+     * @param infos             博锐尚格项目表的debugs字段值
+     * @param wdProjectId		万达项目ID
+     * @param classstructureid  设备分类ID
+     * @param sbybm 			设备编码 主表的ID
+     * @author YangWanYi
+     * @describe 同步万达设备参数对象数据
+     * @date 2021/9/16 18:56
+     */
+    @Transactional
+    public void saveHydomcAssetAndAssetspec(List<WdfacilityRelPersagy> wdfacilityRelList, RwdObjectWd rwdObjectWd, JSONObject infos, String wdProjectId, String classstructureid, String sbybm) {
+    	// 优先同步主表数据 万达设备信息表
+        boolean result = this.hydomcAssetService.saveHydomcAsset(rwdObjectWd, infos, wdProjectId, classstructureid, sbybm);
+        if (!result) {
+			log.error("万达设备信息主表数据同步失败,本方对象ID:{}, 项目ID:{}", rwdObjectWd.getId(), rwdObjectWd.getProjectId());
+        	return;
+		}
+        
+        // 从表数据开始同步	万达设备参数信息表
+    	for (WdfacilityRelPersagy wdfacilityRelPersagy : wdfacilityRelList) {
+			try {
+				// 保证一个信息点的异常,不影响其余信息点的录入
+				result = this.hydomcAssetspecService.saveHydomcAssetspec(wdfacilityRelPersagy, rwdObjectWd, infos, wdProjectId, classstructureid, sbybm);
+				if (!result) {
+					log.error("万达设备参数信息从表数据同步失败,本方对象ID:{}, 项目ID:{}, 信息点编码:{}", rwdObjectWd.getId(), rwdObjectWd.getProjectId(), wdfacilityRelPersagy.getCode());
+		        	return;
+				}
+			} catch (Exception e) {
+				log.error("万达设备参数信息从表数据同步失败,本方对象ID:{}, 项目ID:{}, 信息点编码:{}", rwdObjectWd.getId(), rwdObjectWd.getProjectId(), wdfacilityRelPersagy.getCode());
+			}
+		}
+    }
+    
+    
+    /**
+     * 根据万达的类编码 和 设备分类ID,获取需要映射的信息点数据
+     * 
+     * @param wdClassCode      万达设备类编码 (从wdclass_rel_persagy获取)
+     * @param classStructureId 万达设备分类表id (从wdclass_rel_persagy获取)
+     * @return java.util.List<com.persagy.transfer.pojo.dto.WdfacilityRelPersagy> 非空集合
+     * @author YangWanYi
+     * @describe 根据万达设备类编码和万达设备分类表id查询表wdfacility_rel_persagy数据
+     * @date 2021/9/16 17:49
+     */
+    private List<WdfacilityRelPersagy> listWdfacilityRelPersagy(String wdClassCode, String classStructureId) {
+    	LambdaQueryWrapper<WdfacilityRelPersagy> queryWrapper = new WdfacilityRelPersagy.BuilderQueryWrapper()
+    			.wdClassCodeEq(wdClassCode).classstructureidEq(classStructureId).builder();
+    	List<WdfacilityRelPersagy> list = this.wdfacilityRelPersagyService.list(queryWrapper);
+        return CollectionUtil.isEmpty(list) ? Lists.newArrayList() : list;
+    }
+	
+}

+ 4 - 2
src/main/java/com/persagy/transfer/mapper/RwdObjectWdMapper.java

@@ -19,14 +19,16 @@ import com.persagy.transfer.pojo.dto.RwdObjectWd;
 public interface RwdObjectWdMapper {
 
     /**
+     * 查询出物理世界对象数据
+     * 
+     * @param projectId 博锐尚格项目id
      * @param classCode 对象类型编码
      * @param objType 对象分类
-     * @param projectId 博锐尚格项目id
      * @return java.util.List<com.persagy.transfer.pojo.dto.RwdObjecWd>
      * @author YangWanYi
      * @describe
      * @date 2021/9/16 14:06
      */
-    List<RwdObjectWd> listByProjectId(@Param("classCode") String classCode, @Param("objType") String objType, @Param("projectId") String projectId);
+    List<RwdObjectWd> listByProjectId(@Param("projectId") String projectId, @Param("classCode") String classCode, @Param("objType") String objType);
 	
 }

+ 36 - 0
src/main/java/com/persagy/transfer/service/IHydomcAssetService.java

@@ -1,7 +1,11 @@
 package com.persagy.transfer.service;
 
+import java.util.Date;
+
+import com.alibaba.fastjson.JSONObject;
 import com.persagy.common.service.ISuperService;
 import com.persagy.transfer.pojo.dto.HydomcAsset;
+import com.persagy.transfer.pojo.dto.RwdObjectWd;
 
 /**
  * 设备信息主表
@@ -13,5 +17,37 @@ import com.persagy.transfer.pojo.dto.HydomcAsset;
  */
 public interface IHydomcAssetService extends ISuperService<HydomcAsset> {
 
+	/**
+	 * 根据主键获取设备信息
+	 * 
+	 * @param sbybm
+	 * @return 
+	 */
+	HydomcAsset getHydomcAssetByPKey(String sbybm);
+	
+	/**
+	 * 保存设备信息
+	 * 
+	 * @param rwdObjectWd BDTP中台对象数据
+	 * @param infos 对象数据信息点集合,来源于 rwdObjectWd
+	 * @param wdProjectId 万达项目ID
+	 * @param classstructureid 设备分类ID
+	 * @param sbybm 设备编码 主键
+	 * @return true-成功
+	 */
+	boolean saveHydomcAsset(RwdObjectWd rwdObjectWd, JSONObject infos, String wdProjectId, String classstructureid, String sbybm);
+	
+	/**
+	 * 构建 设备信息 主表数据
+	 * 
+	 * @param infos BDTP中台信息点集合
+	 * @param wdProjectId 万达项目ID
+	 * @param classstructureid 设备分类ID
+	 * @param valid 有效性 0-无效,1-有效
+	 * @param updateTime 更新时间
+	 * @return 
+	 */
+	HydomcAsset buildHydomcAsset(JSONObject infos, String wdProjectId, String classstructureid, int valid, Date updateTime);
+	
 }
 

+ 46 - 0
src/main/java/com/persagy/transfer/service/IHydomcAssetspecService.java

@@ -1,7 +1,12 @@
 package com.persagy.transfer.service;
 
+import java.util.Date;
+
+import com.alibaba.fastjson.JSONObject;
 import com.persagy.common.service.ISuperService;
 import com.persagy.transfer.pojo.dto.HydomcAssetspec;
+import com.persagy.transfer.pojo.dto.RwdObjectWd;
+import com.persagy.transfer.pojo.dto.WdfacilityRelPersagy;
 
 /**
  * 设备参数信息
@@ -13,5 +18,46 @@ import com.persagy.transfer.pojo.dto.HydomcAssetspec;
  */
 public interface IHydomcAssetspecService extends ISuperService<HydomcAssetspec> {
 
+	/**
+	 * @param sbybm 设备编码 -> 主表
+	 * @param siteId 万达项目ID -> 主表
+	 * @param assetAttrId 设备参数ID
+	 * @return
+	 * @author YangWanYi
+	 * @describe 处理设备参数信息对象字段映射
+	 * @date 2021/9/17 10:55
+	 */
+	HydomcAssetspec getHydomcAssetspec(String sbybm, String siteId, String assetAttrId);
+	
+	/**
+	 * 
+	 * @param wdfacilityRelPersagy 万达设备参数信息表与博锐尚格信息点的映射表
+	 * @param rwdObjectWd			物理世界对象数据
+	 * @param infos                博锐尚格项目表debugs字段数据
+	 * @param wdProjectid          广场ID(万达项目ID)
+	 * @param classstructureid     设备分类ID
+	 * @param sbybm           	设备编码 -> 主表
+	 * @return true - 成功
+	 * @author YangWanYi
+	 * @describe 保存设备参数信息
+	 * @date 2021/9/17 10:55
+	 */
+	boolean saveHydomcAssetspec(WdfacilityRelPersagy wdfacilityRelPersagy, RwdObjectWd rwdObjectWd, JSONObject infos, String wdProjectid, String classstructureid, String sbybm);
+	
+	/**
+	 * 
+	 * @param infos                博锐尚格项目表debugs字段数据
+	 * @param wdfacilityRelPersagy 万达设备参数信息表与博锐尚格信息点的映射表
+	 * @param assetspecid			主键ID
+	 * @param wdProjectid          广场ID(万达项目ID)
+	 * @param classstructureid     设备分类ID
+	 * @param changedate           数据更新时间
+	 * @return com.persagy.transfer.pojo.dto.HydomcAssetspec
+	 * @author YangWanYi
+	 * @describe 处理设备参数信息对象字段映射
+	 * @date 2021/9/17 10:55
+	 */
+	HydomcAssetspec buildHydomcAssetspec(JSONObject infos, WdfacilityRelPersagy wdfacilityRelPersagy, String assetspecid, String wdProjectid, String classstructureid, Date changedate);
+	
 }
 

+ 14 - 0
src/main/java/com/persagy/transfer/service/IRwdObjectWdService.java

@@ -1,5 +1,9 @@
 package com.persagy.transfer.service;
 
+import java.util.List;
+
+import com.persagy.transfer.pojo.dto.RwdObjectWd;
+
 /**
  * 对象实例表
  * 
@@ -10,5 +14,15 @@ package com.persagy.transfer.service;
  */
 public interface IRwdObjectWdService {
 
+	/**
+	 * 获取物理世界对象数据
+	 * 
+	 * @param projectId 项目ID
+	 * @param classCode 类编码
+	 * @param objType 对象类型
+	 * @return 非空集合
+	 */
+	List<RwdObjectWd> listByProjectId(String projectId, String classCode, String objType);
+
 }
 

+ 122 - 0
src/main/java/com/persagy/transfer/service/impl/HydomcAssetServiceImpl.java

@@ -1,13 +1,27 @@
 package com.persagy.transfer.service.impl;
 
+import java.util.Date;
+
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.dynamic.datasource.annotation.DS;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
+import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
 import com.persagy.common.service.impl.SuperServiceImpl;
+import com.persagy.common.utils.DateUtil;
+import com.persagy.common.utils.StringUtil;
+import com.persagy.transfer.constant.InfosKeyConstant;
 import com.persagy.transfer.constant.SwitchConstant;
 import com.persagy.transfer.mapper.HydomcAssetMapper;
 import com.persagy.transfer.pojo.dto.HydomcAsset;
+import com.persagy.transfer.pojo.dto.RwdObjectWd;
 import com.persagy.transfer.service.IHydomcAssetService;
+import com.persagy.transfer.utils.StringTool;
+
+import lombok.extern.slf4j.Slf4j;
 
 /**
  * 设备信息主表
@@ -17,8 +31,116 @@ import com.persagy.transfer.service.IHydomcAssetService;
  * @author zhangqiankun
  * @date 2021-09-16 10:45:41
  */
+@Slf4j
 @Service
 @DS(value = SwitchConstant.DS_MASTER_2)
 public class HydomcAssetServiceImpl extends SuperServiceImpl<HydomcAssetMapper, HydomcAsset> implements IHydomcAssetService {
 
+	@Override
+	public HydomcAsset getHydomcAssetByPKey(String sbybm) {
+		LambdaQueryWrapper<HydomcAsset> queryHydomcAssetWrapper = new HydomcAsset.BuilderQueryWrapper().sbybmEq(sbybm).builder();
+        return this.baseMapper.selectOne(queryHydomcAssetWrapper);
+	}
+	
+	@Override
+	@Transactional
+    public boolean saveHydomcAsset(RwdObjectWd rwdObjectWd, JSONObject infos, String wdProjectId, String classstructureid, String sbybm) {
+    	int valid = rwdObjectWd.getValid() == null ? 0 : rwdObjectWd.getValid();
+		Date updateTime = rwdObjectWd.getUpdateTime() == null ? DateUtil.date().toJdkDate() : rwdObjectWd.getUpdateTime();
+		
+    	log.info("设备数据同步至万达数据库,本方对象ID:{},设备状态:{},万达项目ID:{}, 设备分类ID:{}", rwdObjectWd.getId(), valid, wdProjectId, classstructureid);
+    	
+    	Integer result = null;
+        HydomcAsset hydomcAsset = this.getHydomcAssetByPKey(sbybm);
+        if (hydomcAsset == null) {
+        	hydomcAsset = this.buildHydomcAsset(infos, wdProjectId, classstructureid, valid, updateTime);
+        	result = this.baseMapper.insert(hydomcAsset);
+        	return SqlHelper.retBool(result);
+        }
+        
+        LambdaUpdateWrapper<HydomcAsset> updateWrapper = new HydomcAsset.BuilderUpdateWrapper().sbybmEq(sbybm).builder();
+        // 数据更新时间 增量字段
+        if (valid == 0) {
+            updateWrapper.set(HydomcAsset::getStatus, SwitchConstant.SCRAP); 		// 设备状态 运行中/报废    默认都为运行中
+            updateWrapper.set(HydomcAsset::getStatus, SwitchConstant.IS_DELETE); 	// 数据状态 update/delete 当数据状态为delete时,设备状态需改为报废
+            updateWrapper.set(HydomcAsset::getChangedate, updateTime); 				// 数据更新时间 增量字段
+        } else {
+        	hydomcAsset = this.buildHydomcAsset(infos, wdProjectId, classstructureid, valid, updateTime);
+        }
+        result = this.baseMapper.update(hydomcAsset, updateWrapper);
+        return SqlHelper.retBool(result);
+    }
+
+    
+    @Override
+    public HydomcAsset buildHydomcAsset(JSONObject infos, String wdProjectId, String classstructureid, int valid, Date updateTime) {
+    	String sfhysy = StringTool.object2String(infos.get(InfosKeyConstant.WISDOM_CLOUD_USE));
+    	sfhysy = StringUtil.isBlank(sfhysy) ? "是" : sfhysy;
+    	
+    	HydomcAsset hydomcAsset = HydomcAsset.builder()
+    			// 主键  无其他主键可采用设备编码为主键,但要确保唯一(工程信息化设备原码)
+    			.sbybm(StringTool.object2String(infos.get(InfosKeyConstant.EQUIPMENT_CODE)))
+    			// 详细设备安装位置,格式:楼体-楼层-区域 没有key 后续补充
+    			.wzqy(StringTool.object2String(infos.get(InfosKeyConstant.EQUIPMENT_INSTALL_AREA)))
+    			// 设备服务区域 设备/系统服务范围
+    			.fwqy(StringTool.object2String(infos.get(InfosKeyConstant.EQUIPMENT_SERVICE_ZONE)))
+    			// 设备名称
+    			.description(StringTool.object2String(infos.get(InfosKeyConstant.EQUIPMENT_NAME)))
+    	 		// 厂商设备型号
+    			.sbxh(StringTool.object2String(infos.get(InfosKeyConstant.EQUIPMENT_MODEL)))
+    			.classstructureid(classstructureid)
+    			// 设备状态 运行中/报废    默认都为运行中
+    			.status(valid == 0 ? SwitchConstant.SCRAP : SwitchConstant.RUNNING)
+    			// 设备序号 同类设备的序号,即第几台设备:第几台电梯
+    			.sbxhh(StringTool.object2String(infos.get(InfosKeyConstant.EQUIPMENT_IDX)))
+    			// 厂家设备序列号
+    			.cjsbxh(StringTool.object2String(infos.get(InfosKeyConstant.SERIAL_NUM)))
+    			// 生产商公司供方管理系统编码code
+    			.manufacturer(StringTool.object2String(infos.get(InfosKeyConstant.MANUFACTURER)))
+    			// 供应商公司供方管理系统编码code
+    			.vendor(StringTool.object2String(infos.get(InfosKeyConstant.SUPPLIER)))
+    			// 服务商公司供方管理系统编码code
+    			.fws(StringTool.object2String(infos.get(InfosKeyConstant.MAINTAINER)))
+    			// 采购金额 填写人民币元
+    			.purchaseprice(Double.valueOf(StringTool.object2String(infos.get(InfosKeyConstant.PURCHASE_PRICE))))
+    			// 折旧/使用年限 按年填写 如3年半则填写 3.5
+    			.zjsynx(StringTool.object2Double(infos.get(InfosKeyConstant.SERVICE_LIFE)))
+    			// 生产日期/出厂日期 年/月/日
+    			.scrq(StringTool.object2DateTime(infos.get(InfosKeyConstant.PRODUCT_DATE)))
+    			// 采购日期
+    			.cgrq(StringTool.object2DateTime(infos.get(InfosKeyConstant.PURCHASE_DATE)))
+    			// 安装日期
+		    	.azdate(StringTool.object2DateTime(infos.get(InfosKeyConstant.INSTALL_DATE))) 
+		    	// 启用日期
+		    	.installdate(StringTool.object2DateTime(infos.get(InfosKeyConstant.ENABLE_DATE))) 
+		    	// 质保开始日期
+		    	.zbksrq(StringTool.object2DateTime(infos.get(InfosKeyConstant.WARRANTY_START_DATE))) 
+		    	// 质保结束日期
+		    	.zbjsrq(StringTool.object2DateTime(infos.get(InfosKeyConstant.WARRANTY_END_DATE)))
+		    	// 中修周期 单位为月
+		    	.zxzq(StringTool.object2Integer(infos.get(InfosKeyConstant.MEDIUM_REPAIR_CYCLE)))
+		    	// 大修周期 单位为月
+		    	.dxzq(StringTool.object2Integer(infos.get(InfosKeyConstant.OVERHAUL_CYCLE))) 
+		    	// 物业类型 自持/销售/合作方
+		    	.wylx(StringTool.object2String(infos.get(InfosKeyConstant.PROPERTY_TYPE))) 
+		    	// 设备管理归属 商管/百货/大歌星/超市/影院/大酒楼/其他
+		    	.sbglgs(StringTool.object2String(infos.get(InfosKeyConstant.EQUIPMENT_MANAGE_OWNERSHIP))) 
+		    	// 慧云设备编码
+		    	.hysbbm(StringTool.object2String(infos.get(InfosKeyConstant.WISDOM_CLOUD_LOCAL_CODE))) 
+		    	// 是否慧云使用 是/否   缺省为 是
+		    	.sfhysy(sfhysy) 
+		    	// 是否是主力店 缺省为 否
+		    	.sfzld(StringTool.object2String(infos.get(InfosKeyConstant.MAIN_STORE))) 
+		    	// 备注 wD_beizhu
+		    	.mark(StringTool.object2String(infos.get(InfosKeyConstant.REMARK))) 
+		    	// 项目唯一id,可采用租赁系统广场id,同步后不可更改
+		    	.siteid(wdProjectId) 
+		    	// 数据状态 update/delete 当数据状态为delete时,设备状态需改为报废
+		    	.datastatus(valid == 0 ? SwitchConstant.IS_DELETE : SwitchConstant.IS_UPDATE) 
+		    	// 数据更新时间 增量字段
+		    	.changedate(updateTime) 
+    			.build();
+    	return hydomcAsset;
+    }
+    
 }

+ 93 - 1
src/main/java/com/persagy/transfer/service/impl/HydomcAssetspecServiceImpl.java

@@ -1,19 +1,32 @@
 package com.persagy.transfer.service.impl;
 
+import java.util.Date;
+
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.dynamic.datasource.annotation.DS;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
 import com.persagy.common.service.impl.SuperServiceImpl;
+import com.persagy.common.utils.DateUtil;
+import com.persagy.common.utils.StringUtil;
+import com.persagy.transfer.constant.InfosKeyConstant;
 import com.persagy.transfer.constant.SwitchConstant;
 import com.persagy.transfer.mapper.HydomcAssetspecMapper;
 import com.persagy.transfer.pojo.dto.HydomcAssetspec;
+import com.persagy.transfer.pojo.dto.RwdObjectWd;
+import com.persagy.transfer.pojo.dto.WdfacilityRelPersagy;
 import com.persagy.transfer.service.IHydomcAssetspecService;
+import com.persagy.transfer.utils.StringTool;
 
 /**
  * 设备参数信息
  * 
  * @version 1.0.0
- * @company persagy 
+ * @company persagy
  * @author zhangqiankun
  * @date 2021-09-16 10:45:41
  */
@@ -21,4 +34,83 @@ import com.persagy.transfer.service.IHydomcAssetspecService;
 @DS(value = SwitchConstant.DS_MASTER_2)
 public class HydomcAssetspecServiceImpl extends SuperServiceImpl<HydomcAssetspecMapper, HydomcAssetspec> implements IHydomcAssetspecService {
 
+	public static final String IS_NUMBER = "数字";
+	public static final String IS_LETTER = "字母数字";
+
+	@Override
+	public HydomcAssetspec getHydomcAssetspec(String sbybm, String siteId, String assetAttrId) {
+		LambdaQueryWrapper<HydomcAssetspec> queryWrapper = new HydomcAssetspec.BuilderQueryWrapper().sbybmEq(sbybm)
+				.siteidEq(siteId).assetattridEq(assetAttrId).builder();
+		return this.baseMapper.selectOne(queryWrapper);
+	}
+
+	@Override
+	@Transactional
+	public boolean saveHydomcAssetspec(WdfacilityRelPersagy wdfacilityRelPersagy, RwdObjectWd rwdObjectWd, JSONObject infos, String wdProjectid, String classstructureid, String sbybm) {
+		Date updateTime = rwdObjectWd.getUpdateTime() == null ? DateUtil.date().toJdkDate() : rwdObjectWd.getUpdateTime();
+
+		Integer result = null;
+		// 根据万达设备信息表的SITEID、SBYBM、ASSETATTRID查询数据是否存在
+		HydomcAssetspec hydomcAssetspec = this.getHydomcAssetspec(sbybm, wdProjectid, wdfacilityRelPersagy.getAssetattrid());
+		if (hydomcAssetspec == null) {
+			hydomcAssetspec = this.buildHydomcAssetspec(infos, wdfacilityRelPersagy, null, wdProjectid, classstructureid, updateTime);
+			result = this.baseMapper.insert(hydomcAssetspec);
+			return SqlHelper.retBool(result);
+		}
+		
+		// key为wdfacility_rel_persagy的code值从debugs取 有值update 无值(空、空字符串)就是delete
+		if (StringUtils.isBlank(StringTool.object2String(infos.get(wdfacilityRelPersagy.getCode())))) {
+			hydomcAssetspec.setDatastatus(SwitchConstant.IS_DELETE); // 数据状态 update/delete
+			hydomcAssetspec.setChangedate(updateTime); // 数据更新时间 增量字段
+		} else {
+			hydomcAssetspec = this.buildHydomcAssetspec(infos, wdfacilityRelPersagy, hydomcAssetspec.getAssetspecid(), wdProjectid, classstructureid, updateTime);
+		}
+		result = this.baseMapper.updateById(hydomcAssetspec);
+		return SqlHelper.retBool(result);
+	}
+
+	@Override
+	public HydomcAssetspec buildHydomcAssetspec(JSONObject infos, WdfacilityRelPersagy wdfacilityRelPersagy, String assetspecid,
+			String wdProjectid, String classstructureid, Date changedate) {
+		HydomcAssetspec hydomcAssetspec = HydomcAssetspec.builder().siteid(wdProjectid) // 广场id 关联设备信息 Pj4403070003
+				// 设备编码 关联设备信息 wD_gongchengxinxihua
+				.sbybm(StringTool.object2String(infos.get(InfosKeyConstant.EQUIPMENT_CODE)))
+				// 设备分类id 1507
+				.classstructureid(classstructureid)
+				// 设备分类名称 电梯系统/扶梯/人行步道 (取自中间表wdfacility_rel_persagy)
+				.classqc(wdfacilityRelPersagy.getClassqc())
+				// 设备参数id 1106 (取自中间表wdfacility_rel_persagy)
+				.assetattrid(wdfacilityRelPersagy.getAssetattrid())
+				// 设备参数名称 (取自中间表wdfacility_rel_persagy)
+				.csdesc(wdfacilityRelPersagy.getCsdesc())
+				// 设备参数类型 (取自中间表wdfacility_rel_persagy)
+				.datatype(wdfacilityRelPersagy.getDatatype())
+				// 设备参数单位编码 (取自中间表wdfacility_rel_persagy)
+				.measureunitid(wdfacilityRelPersagy.getMeasureunitid())
+				// 设备参数单位名称 (取自中间表wdfacility_rel_persagy)
+				.csjldw(wdfacilityRelPersagy.getCsjldw())
+				// 数据更新时间 增量字段
+				.changedate(changedate).build();
+
+		// 根据Datatype判断设置设备参数数字值还是设备参数文本值 key为wdfacility_rel_persagy的code值从debugs取
+		if (IS_NUMBER.equals(wdfacilityRelPersagy.getDatatype())) { // 是数字
+			hydomcAssetspec.setNumvalue(StringTool.object2Double(infos.get(wdfacilityRelPersagy.getCode()))); // 设备参数数字值
+		} else {
+			// 默认字符串
+			hydomcAssetspec.setAlnvalue(StringTool.object2String(infos.get(wdfacilityRelPersagy.getCode()))); // 设备参数文本值
+		}
+		// key为wdfacility_rel_persagy的code值从debugs取 有值update 无值(空、空字符串)就是delete
+		if (StringUtils.isBlank(StringTool.object2String(infos.get(wdfacilityRelPersagy.getCode())))) {
+			hydomcAssetspec.setDatastatus(SwitchConstant.IS_DELETE); // 数据状态 update/delete
+		} else {
+			hydomcAssetspec.setDatastatus(SwitchConstant.IS_UPDATE); // 数据状态 update/delete
+		}
+
+		// 主键ID 赋值
+		if (StringUtil.isNotBlank(assetspecid)) {
+			hydomcAssetspec.setAssetspecid(assetspecid);
+		}
+		return hydomcAssetspec;
+	}
+
 }

+ 17 - 0
src/main/java/com/persagy/transfer/service/impl/RwdObjectWdServiceImpl.java

@@ -1,11 +1,19 @@
 package com.persagy.transfer.service.impl;
 
+import java.util.List;
+
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import com.baomidou.dynamic.datasource.annotation.DS;
+import com.google.common.collect.Lists;
 import com.persagy.transfer.constant.SwitchConstant;
+import com.persagy.transfer.mapper.RwdObjectWdMapper;
+import com.persagy.transfer.pojo.dto.RwdObjectWd;
 import com.persagy.transfer.service.IRwdObjectWdService;
 
+import cn.hutool.core.collection.CollectionUtil;
+
 /**
  * 对象实例表
  * 
@@ -17,5 +25,14 @@ import com.persagy.transfer.service.IRwdObjectWdService;
 @Service
 @DS(value = SwitchConstant.DS_MASTER_1)
 public class RwdObjectWdServiceImpl implements IRwdObjectWdService {
+	
+	@Autowired
+	private RwdObjectWdMapper rwdObjectWdMapper;
+	
+	@Override
+	public List<RwdObjectWd> listByProjectId(String projectId, String classCode, String objType) {
+		List<RwdObjectWd> list = rwdObjectWdMapper.listByProjectId(classCode, objType, projectId);
+		return CollectionUtil.isEmpty(list) ? Lists.newArrayList() : list;
+	}
 
 }