|
@@ -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;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|