|
@@ -1,41 +1,302 @@
|
|
|
package com.persagy.transfer.service.impl;
|
|
|
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.dynamic.datasource.annotation.DS;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.persagy.transfer.constant.InfosKeyConstant;
|
|
|
import com.persagy.transfer.constant.SwitchConstant;
|
|
|
-import com.persagy.transfer.mapper.MasterOneMapper;
|
|
|
-import com.persagy.transfer.mapper.MasterTwoMapper;
|
|
|
+import com.persagy.transfer.mapper.*;
|
|
|
+import com.persagy.transfer.pojo.dto.*;
|
|
|
import com.persagy.transfer.service.IDemoService;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.sql.Date;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
|
|
|
|
|
|
* 多数据源测试
|
|
|
- *
|
|
|
- * @version 1.0.0
|
|
|
- * @company persagy
|
|
|
+ *
|
|
|
* @author zhangqiankun
|
|
|
+ * @version 1.0.0
|
|
|
+ * @company persagy
|
|
|
* @date 2021年9月15日 下午4:13:29
|
|
|
*/
|
|
|
@Service
|
|
|
@DS(value = SwitchConstant.DS_MASTER_1)
|
|
|
+@Slf4j
|
|
|
public class DemoService implements IDemoService {
|
|
|
|
|
|
- @Autowired
|
|
|
- private MasterOneMapper masterOneMapper;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private MasterTwoMapper masterTwoMapper;
|
|
|
-
|
|
|
- @Override
|
|
|
- public Object getDataByMasterOne() {
|
|
|
- return this.masterOneMapper.queryOne();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- @DS(value = SwitchConstant.DS_MASTER_2)
|
|
|
- public Object getDataByMasterTwo() {
|
|
|
- return this.masterTwoMapper.queryTwo();
|
|
|
- }
|
|
|
-
|
|
|
+ @Autowired
|
|
|
+ private MasterOneMapper masterOneMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MasterTwoMapper masterTwoMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private WdclassRelPersagyMapper wdclassRelPersagyMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private WdprojRelPersagyprojMapper wdprojRelPersagyprojMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RwdObjecWdMapper rwdObjecWdMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private WdfacilityRelPersagyMapper wdfacilityRelPersagyMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private HydomcAssetMapper hydomcAssetMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private HydomcAssetspecMapper hydomcAssetspecMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Object getDataByMasterOne() {
|
|
|
+ return this.masterOneMapper.queryOne();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @DS(value = SwitchConstant.DS_MASTER_2)
|
|
|
+ public Object getDataByMasterTwo() {
|
|
|
+ return this.masterTwoMapper.queryTwo();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * @author YangWanYi
|
|
|
+ * @describe 向万达数据库同步设备数据
|
|
|
+ * @date 2021/9/16 11:38
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void syncData2WD() {
|
|
|
+
|
|
|
+ 处理逻辑
|
|
|
+ 1、获取表wdclass_rel_persagy去重class_code的数据
|
|
|
+ 2、获取表wdproj_rel_persagyproj去重博锐尚格项目ID的数据
|
|
|
+ 3、根据1的class_code,2的persagy_project_id、obj_type='equipment',获取表rwd_object_wd_*的数据
|
|
|
+ 4、对应数据进行insert或者update或者delete
|
|
|
+ */
|
|
|
+
|
|
|
+
|
|
|
+ log.info("准备同步设备数据到万达数据库");
|
|
|
+ LambdaQueryWrapper<WdclassRelPersagy> queryWdclassRelWrapper = new WdclassRelPersagy.BuilderQueryWrapper().builder();
|
|
|
+ List<WdclassRelPersagy> funcList = this.wdclassRelPersagyMapper.selectList(queryWdclassRelWrapper);
|
|
|
+
|
|
|
+
|
|
|
+ LambdaQueryWrapper<WdprojRelPersagyproj> queryProjRelWrapper = new WdprojRelPersagyproj.BuilderQueryWrapper().builder();
|
|
|
+ List<WdprojRelPersagyproj> projList = this.wdprojRelPersagyprojMapper.selectList(queryProjRelWrapper);
|
|
|
+
|
|
|
+
|
|
|
+ List<RwdObjecWd> rwdObjecWdList;
|
|
|
+ final String OBJ_TYPE = "equipment";
|
|
|
+ List<String> classCodeList = new ArrayList<>();
|
|
|
+ List<String> persagyProjectIdList = new ArrayList<>();
|
|
|
+ for (WdclassRelPersagy wdclassRelPersagy : funcList) {
|
|
|
+ for (WdprojRelPersagyproj wdprojRelPersagyproj : projList) {
|
|
|
+
|
|
|
+ if (classCodeList.contains(wdclassRelPersagy.getClassCode()) || persagyProjectIdList.contains(wdprojRelPersagyproj.getPersagyProjectid())) {
|
|
|
+ log.info("有已经处理过的BDTP类编码或者博锐尚格项目id,准备跳过此次处理");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ classCodeList.add(wdclassRelPersagy.getClassCode());
|
|
|
+ persagyProjectIdList.add(wdprojRelPersagyproj.getPersagyProjectid());
|
|
|
+
|
|
|
+ rwdObjecWdList = this.rwdObjecWdMapper.listByProjectId(wdclassRelPersagy.getClassCode(), OBJ_TYPE, wdprojRelPersagyproj.getPersagyProjectid());
|
|
|
+ if (rwdObjecWdList != null && !rwdObjecWdList.isEmpty()) {
|
|
|
+ this.handleFieldMapping(rwdObjecWdList, wdprojRelPersagyproj, wdclassRelPersagy);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * @param rwdObjecWdList 博锐尚格的项目对象
|
|
|
+ * @param wdprojRelPersagyproj 万达项目ID与博锐尚格项目ID映射表实体
|
|
|
+ * @author YangWanYi
|
|
|
+ * @describe 同步万达设备数据的新增与更新
|
|
|
+ * @date 2021/9/16 14:19
|
|
|
+ */
|
|
|
+ private void handleFieldMapping(List<RwdObjecWd> rwdObjecWdList, WdprojRelPersagyproj wdprojRelPersagyproj, WdclassRelPersagy wdclassRelPersagy) {
|
|
|
+ JSONObject infosObj;
|
|
|
+ HydomcAsset hydomcAsset = null;
|
|
|
+ List<WdfacilityRelPersagy> wdfacilityRelList = null;
|
|
|
+ for (RwdObjecWd rwdObjecWd : rwdObjecWdList) {
|
|
|
+ infosObj = rwdObjecWd.getInfos();
|
|
|
+
|
|
|
+ this.sycnHydomcAsset(infosObj, wdprojRelPersagyproj.getWdProjectid(), hydomcAsset, rwdObjecWd.getValid(), rwdObjecWd.getUpdateTime(), wdclassRelPersagy.getClassstrucrureid());
|
|
|
+
|
|
|
+ if (wdfacilityRelList == null) {
|
|
|
+ wdfacilityRelList = this.listWdfacilityRelPersagy(wdclassRelPersagy.getWdClassCode(), wdclassRelPersagy.getClassstrucrureid());
|
|
|
+ }
|
|
|
+ this.sycnHydomcAssetspec(wdfacilityRelList, wdprojRelPersagyproj.getWdProjectid(), infosObj, rwdObjecWd.getUpdateTime());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * @param wdfacilityRelList 筛选后的万达设备参数信息表与博锐尚格信息点的映射表数据
|
|
|
+ * @param wdProjectid 万达项目ID(广场ID)
|
|
|
+ * @param infosObj 博锐尚格项目表的infos字段值
|
|
|
+ * @param updateTime 项目最后更新时间
|
|
|
+ * @author YangWanYi
|
|
|
+ * @describe 同步万达设备参数对象数据
|
|
|
+ * @date 2021/9/16 18:56
|
|
|
+ */
|
|
|
+ @DS(value = SwitchConstant.DS_MASTER_2)
|
|
|
+ private void sycnHydomcAssetspec(List<WdfacilityRelPersagy> wdfacilityRelList, String wdProjectid, JSONObject infosObj, java.util.Date updateTime) {
|
|
|
+ log.info("准备同步万达设备参数对象数据");
|
|
|
+ boolean isInsert = false;
|
|
|
+ HydomcAssetspec hydomcAssetspec;
|
|
|
+ final String IS_NUMBER = "数字";
|
|
|
+ final String IS_LETTER = "字母";
|
|
|
+ for (WdfacilityRelPersagy wdfacilityRelPersagy : wdfacilityRelList) {
|
|
|
+
|
|
|
+ hydomcAssetspec = this.getHydomcAssetspecByPKey(wdfacilityRelPersagy.getAssetattrid());
|
|
|
+ if (hydomcAssetspec == null) {
|
|
|
+ hydomcAssetspec = new HydomcAssetspec();
|
|
|
+ isInsert = true;
|
|
|
+ }
|
|
|
+ hydomcAssetspec.setSiteid(wdProjectid);
|
|
|
+ if (!infosObj.isEmpty()) {
|
|
|
+ hydomcAssetspec.setSbybm(String.valueOf(infosObj.get(InfosKeyConstant.EQUIPMENT_CODE)));
|
|
|
+ hydomcAssetspec.setClassstructureid(String.valueOf(infosObj.get(InfosKeyConstant.EQUIPMENT_SORT)));
|
|
|
+
|
|
|
+ if (IS_NUMBER.equals(wdfacilityRelPersagy.getDatatype())) {
|
|
|
+ log.info("dataType是数字");
|
|
|
+ hydomcAssetspec.setNumvalue(Double.valueOf(String.valueOf(infosObj.get(wdfacilityRelPersagy.getCode()))));
|
|
|
+ } else if (IS_LETTER.equals(wdfacilityRelPersagy.getDatatype())) {
|
|
|
+ log.info("dataType是字母");
|
|
|
+ hydomcAssetspec.setAlnvalue(String.valueOf(infosObj.get(wdfacilityRelPersagy.getCode())));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isBlank(String.valueOf(infosObj.get(wdfacilityRelPersagy.getCode())))) {
|
|
|
+
|
|
|
+ log.info("code没有值,数据状态设置为delete");
|
|
|
+ hydomcAssetspec.setDatastatus(SwitchConstant.IS_DELETE);
|
|
|
+ } else {
|
|
|
+
|
|
|
+ log.info("code有值,数据状态设置为update");
|
|
|
+ hydomcAssetspec.setDatastatus(SwitchConstant.IS_UPDATE);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ hydomcAssetspec.setClassqc(wdfacilityRelPersagy.getClassqc());
|
|
|
+ hydomcAssetspec.setAssetattrid(wdfacilityRelPersagy.getAssetattrid());
|
|
|
+ hydomcAssetspec.setCsdesc(wdfacilityRelPersagy.getCsdesc());
|
|
|
+ hydomcAssetspec.setDatatype(wdfacilityRelPersagy.getDatatype());
|
|
|
+ hydomcAssetspec.setMeasureunitid(wdfacilityRelPersagy.getMeasureunitid());
|
|
|
+ hydomcAssetspec.setCsjldw(wdfacilityRelPersagy.getCsjldw());
|
|
|
+ hydomcAssetspec.setChangedate(updateTime);
|
|
|
+ if (isInsert) {
|
|
|
+ this.hydomcAssetspecMapper.insert(hydomcAssetspec);
|
|
|
+ } else {
|
|
|
+ this.hydomcAssetspecMapper.updateById(hydomcAssetspec);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ * @param primaryKey 万达设备参数信息表主键
|
|
|
+ * @return com.persagy.transfer.pojo.dto.HydomcAssetspec
|
|
|
+ * @author YangWanYi
|
|
|
+ * @describe 根据主键查询设备参数信息
|
|
|
+ * @date 2021/9/16 18:17
|
|
|
+ */
|
|
|
+ @DS(value = SwitchConstant.DS_MASTER_2)
|
|
|
+ private HydomcAssetspec getHydomcAssetspecByPKey(String primaryKey) {
|
|
|
+ return this.hydomcAssetspecMapper.selectById(primaryKey);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * @param wdClassCode 万达设备类编码 (从wdclass_rel_persagy获取)
|
|
|
+ * @param classStrucrureId 万达设备分类表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 classStrucrureId) {
|
|
|
+ HashMap<String, Object> columnMap = new HashMap<>();
|
|
|
+ columnMap.put("wdClassCode", wdClassCode);
|
|
|
+ columnMap.put("classstrucrureid", classStrucrureId);
|
|
|
+ return this.wdfacilityRelPersagyMapper.selectByMap(columnMap);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * @param infosObj 博锐尚格项目表的infos字段值
|
|
|
+ * @param wdProjectId 博锐尚格项目ID映射的万达项目ID
|
|
|
+ * @param hydomcAsset 万达设备信息对象
|
|
|
+ * @param valid 项目数据对象状态:1有效,0无效
|
|
|
+ * @param updateTime 项目最后更新时间
|
|
|
+ * @param classstrucrureid 万达设备分类ID
|
|
|
+ * @return int
|
|
|
+ * @author YangWanYi
|
|
|
+ * @describe 万达设备信息对象数据同步
|
|
|
+ * @date 2021/9/16 16:00
|
|
|
+ */
|
|
|
+ @DS(value = SwitchConstant.DS_MASTER_2)
|
|
|
+ private int sycnHydomcAsset(JSONObject infosObj, String wdProjectId, HydomcAsset hydomcAsset, Integer valid, java.util.Date updateTime, String classstrucrureid) {
|
|
|
+ log.info("准备同步万达设备信息对象数据");
|
|
|
+ boolean isInsert = false;
|
|
|
+ if (!infosObj.isEmpty()) {
|
|
|
+
|
|
|
+ hydomcAsset = this.getHydomcAssetByPKey(String.valueOf(infosObj.get(InfosKeyConstant.EQUIPMENT_CODE)));
|
|
|
+ if (hydomcAsset == null) {
|
|
|
+ hydomcAsset = new HydomcAsset();
|
|
|
+ isInsert = true;
|
|
|
+ }
|
|
|
+ hydomcAsset.setSbybm(String.valueOf(infosObj.get(InfosKeyConstant.EQUIPMENT_CODE)));
|
|
|
+ hydomcAsset.setDescription(String.valueOf(infosObj.get(InfosKeyConstant.EQUIPMENT_NAME)));
|
|
|
+
|
|
|
+ hydomcAsset.setFwqy(String.valueOf(infosObj.get(InfosKeyConstant.EQUIPMENT_SERVICE_ZONE)));
|
|
|
+ hydomcAsset.setSbxh(String.valueOf(infosObj.get(InfosKeyConstant.EQUIPMENT_MODEL)));
|
|
|
+ hydomcAsset.setClassstructureid(classstrucrureid);
|
|
|
+ hydomcAsset.setStatus(valid == 0 ? SwitchConstant.SCRAP : SwitchConstant.RUNNING);
|
|
|
+ hydomcAsset.setSbxhh(String.valueOf(infosObj.get(InfosKeyConstant.EQUIPMENT_IDX)));
|
|
|
+ hydomcAsset.setCjsbxh(String.valueOf(infosObj.get(InfosKeyConstant.SERIAL_NUM)));
|
|
|
+ hydomcAsset.setManufacturer(String.valueOf(infosObj.get(InfosKeyConstant.MANUFACTURER)));
|
|
|
+ hydomcAsset.setVendor(String.valueOf(infosObj.get(InfosKeyConstant.SUPPLIER)));
|
|
|
+ hydomcAsset.setFws(String.valueOf(infosObj.get(InfosKeyConstant.MAINTAINER)));
|
|
|
+ hydomcAsset.setPurchaseprice(Double.valueOf(String.valueOf(infosObj.get(InfosKeyConstant.PURCHASE_PRICE))));
|
|
|
+ hydomcAsset.setZjsynx(Double.valueOf(String.valueOf(infosObj.get(InfosKeyConstant.SERVICE_LIFE))));
|
|
|
+ hydomcAsset.setScrq(Date.valueOf(String.valueOf(infosObj.get(InfosKeyConstant.PRODUCT_DATE))));
|
|
|
+ hydomcAsset.setCgrq(Date.valueOf(String.valueOf(infosObj.get(InfosKeyConstant.PURCHASE_DATE))));
|
|
|
+ hydomcAsset.setAzdate(Date.valueOf(String.valueOf(infosObj.get(InfosKeyConstant.INSTALL_DATE))));
|
|
|
+ hydomcAsset.setInstalldate(Date.valueOf(String.valueOf(infosObj.get(InfosKeyConstant.ENABLE_DATE))));
|
|
|
+ hydomcAsset.setZbksrq(Date.valueOf(String.valueOf(infosObj.get(InfosKeyConstant.WARRANTY_START_DATE))));
|
|
|
+ hydomcAsset.setZbjsrq(Date.valueOf(String.valueOf(infosObj.get(InfosKeyConstant.WARRANTY_END_DATE))));
|
|
|
+ hydomcAsset.setZxzq(Integer.valueOf(String.valueOf(infosObj.get(InfosKeyConstant.MEDIUM_REPAIR_CYCLE))));
|
|
|
+ hydomcAsset.setDxzq(Integer.valueOf(String.valueOf(infosObj.get(InfosKeyConstant.OVERHAUL_CYCLE))));
|
|
|
+ hydomcAsset.setWylx(String.valueOf(infosObj.get(InfosKeyConstant.PROPERTY_TYPE)));
|
|
|
+ hydomcAsset.setSbglgs(String.valueOf(infosObj.get(InfosKeyConstant.EQUIPMENT_MANAGE_OWNERSHIP)));
|
|
|
+ hydomcAsset.setHysbbm(String.valueOf(infosObj.get(InfosKeyConstant.WISDOM_CLOUD_LOCAL_CODE)));
|
|
|
+ hydomcAsset.setSfhysy(String.valueOf(infosObj.get(InfosKeyConstant.WISDOM_CLOUD_USE)));
|
|
|
+ hydomcAsset.setSfzld(String.valueOf(infosObj.get(InfosKeyConstant.MAIN_STORE)));
|
|
|
+ hydomcAsset.setMark(String.valueOf(infosObj.get(InfosKeyConstant.REMARK)));
|
|
|
+ }
|
|
|
+ hydomcAsset.setSiteid(wdProjectId);
|
|
|
+ hydomcAsset.setDatastatus(valid == 0 ? SwitchConstant.IS_DELETE : SwitchConstant.IS_UPDATE);
|
|
|
+ hydomcAsset.setChangedate(updateTime);
|
|
|
+ if (isInsert) {
|
|
|
+ return this.hydomcAssetMapper.insert(hydomcAsset);
|
|
|
+ } else {
|
|
|
+ return this.hydomcAssetMapper.updateById(hydomcAsset);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * @param primaryKey 万达设备信息主表主键
|
|
|
+ * @return com.persagy.transfer.pojo.dto.HydomcAsset
|
|
|
+ * @author YangWanYi
|
|
|
+ * @describe 根据主键获取万达设备信息
|
|
|
+ * @date 2021/9/16 15:31
|
|
|
+ */
|
|
|
+ @DS(value = SwitchConstant.DS_MASTER_2)
|
|
|
+ private HydomcAsset getHydomcAssetByPKey(String primaryKey) {
|
|
|
+ return this.hydomcAssetMapper.selectById(primaryKey);
|
|
|
+ }
|
|
|
+
|
|
|
}
|