Browse Source

数据同步代码

yangwanyi 3 years ago
parent
commit
0b4095ddf1

+ 2 - 0
src/main/java/com/persagy/IbmsSwitchApplication.java

@@ -2,6 +2,7 @@ package com.persagy;
 
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.scheduling.annotation.EnableScheduling;
 import org.springframework.transaction.annotation.EnableTransactionManagement;
 
 import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure;
@@ -19,6 +20,7 @@ import com.persagy.common.annotation.EnableIdGenerator;
 @EnableIdGenerator
 @EnableControllerLog
 @EnableTransactionManagement
+@EnableScheduling // 开启定时任务功能
 @SpringBootApplication(exclude = {DruidDataSourceAutoConfigure.class})
 public class IbmsSwitchApplication {
 	

+ 156 - 0
src/main/java/com/persagy/transfer/constant/InfosKeyConstant.java

@@ -0,0 +1,156 @@
+package com.persagy.transfer.constant;
+
+/**
+ * @description: infos值中key常量类
+ * @author: YangWanYi
+ * @create: 2021-09-16 14:39
+ **/
+public class InfosKeyConstant {
+
+    /**
+     * 设备编码(工程信息化编码)
+     */
+    public static final String EQUIPMENT_CODE = "wD_gongchengxinxihua";
+
+    /**
+     * 设备名称(工程设备名称)
+     */
+    public static final String EQUIPMENT_NAME = "wD_shebeimingcheng";
+
+    /**
+     * 设备服务区域
+     */
+    public static final String EQUIPMENT_SERVICE_ZONE = "wD_equipfuwuquyu";
+
+    /**
+     * 设备型号
+     */
+    public static final String EQUIPMENT_MODEL = "Specification";
+
+    /**
+     * 设备分类
+     */
+    public static final String EQUIPMENT_SORT = "wD_shebeifenlei";
+
+    /**
+     * 设备状态
+     */
+    public static final String EQUIPMENT_STATUS = "EquipStatus";
+
+    /**
+     * 设备序号
+     */
+    public static final String EQUIPMENT_IDX = "wD_equipnumber";
+
+    /**
+     * 设备数量
+     */
+    public static final String EQUIPMENT_AMOUNT = "wD_equipquantity";
+
+    /**
+     * 计量单位
+     */
+    public static final String MEASURE_UNIT = "MeasureUnit";
+
+    /**
+     * 厂家设备序列号
+     */
+    public static final String SERIAL_NUM = "wD_serialnum";
+
+    /**
+     * 生产商
+     */
+    public static final String MANUFACTURER = "Manufacturer";
+
+    /**
+     * 供应商
+     */
+    public static final String SUPPLIER = "Supplier";
+
+    /**
+     * 服务商
+     */
+    public static final String MAINTAINER = "Maintainer";
+
+    /**
+     * 采购金额(元)
+     */
+    public static final String PURCHASE_PRICE = "PurchasePrice";
+
+    /**
+     * 折旧/使用年限
+     */
+    public static final String SERVICE_LIFE = "wD_servicelife";
+
+    /**
+     * 生产日期/出厂日期
+     */
+    public static final String PRODUCT_DATE = "wD_productdate";
+
+    /**
+     * 采购日期
+     */
+    public static final String PURCHASE_DATE = "PurchaseDate";
+
+    /**
+     * 安装日期
+     */
+    public static final String INSTALL_DATE = "InstallDate";
+
+    /**
+     * 启用日期
+     */
+    public static final String ENABLE_DATE = "wD_enabledate";
+
+    /**
+     * 质保开始日期
+     */
+    public static final String WARRANTY_START_DATE = "wD_warrantystartdate";
+
+    /**
+     * 质保结束日期
+     */
+    public static final String WARRANTY_END_DATE = "wD_warrantyenddate";
+
+    /**
+     * 中修周期
+     */
+    public static final String MEDIUM_REPAIR_CYCLE = "wD_mediumrepaircycle";
+
+    /**
+     * 大修周期
+     */
+    public static final String OVERHAUL_CYCLE = "wD_overhaulcycle";
+
+    /**
+     * 物业类型
+     */
+    public static final String PROPERTY_TYPE = "wD_propertytype";
+
+    /**
+     * 设备管理归属
+     */
+    public static final String EQUIPMENT_MANAGE_OWNERSHIP = "wD_equipmanageownership";
+
+    /**
+     * 慧云本地编码
+     */
+    public static final String WISDOM_CLOUD_LOCAL_CODE = "wD_huiyunbendibianma";
+
+    /**
+     * 是否慧云使用
+     */
+    public static final String WISDOM_CLOUD_USE = "wD_huiyunuse";
+
+    /**
+     * 是否是主力店
+     */
+    public static final String MAIN_STORE = "wD_mainstore";
+
+    /**
+     * 备注
+     */
+    public static final String REMARK = "wD_beizhu";
+
+
+}

+ 84 - 33
src/main/java/com/persagy/transfer/constant/SwitchConstant.java

@@ -2,56 +2,107 @@ package com.persagy.transfer.constant;
 
 /**
  * ADM 通用常量
+ *
  * @author Charlie Yu
  * @date 2021-08-16
  */
 public interface SwitchConstant {
-	
-	/** 数据源 1 */
-	String DS_MASTER_1 = "master_1";
-	
-	/** 数据源 2 */
-	String DS_MASTER_2 = "master_2";
-	
-	/** 项目根路径*/
-	String SERVER_ROOT_PATH = System.getProperty("user.dir");
-	
-	String EMPTY = "";
-	
-    /** appId */
+
+    /**
+     * 数据源 1
+     */
+    String DS_MASTER_1 = "master_1";
+
+    /**
+     * 数据源 2
+     */
+    String DS_MASTER_2 = "master_2";
+
+    /**
+     * 项目根路径
+     */
+    String SERVER_ROOT_PATH = System.getProperty("user.dir");
+
+    String EMPTY = "";
+
+    /**
+     * appId
+     */
     String APP_ID = "DMZ";
-    
-    /** 默认的userId */
+
+    /**
+     * 默认的userId
+     */
     String USER_ID = "systemId";
-    
-    /** 集团编码 header key*/
+
+    /**
+     * 集团编码 header key
+     */
     String GROUP_CODE_HEADER = "groupCode";
 
-    /** 项目ID header key*/
+    /**
+     * 项目ID header key
+     */
     String PROJECT_ID_HEADER = "projectId";
-    
-    /** appID header key*/
+
+    /**
+     * appID header key
+     */
     String APP_ID_HEADER = "appId";
-    
-    /** userID header key*/
+
+    /**
+     * userID header key
+     */
     String USER_ID_HEADER = "userId";
-    
-    /** 连接符 ? */
+
+    /**
+     * 连接符 ?
+     */
     String WHERE = "?";
 
-    /** 连接符 & */
+    /**
+     * 连接符 &
+     */
     String AND = "&";
-    
-    /** 连接符 _ */
+
+    /**
+     * 连接符 _
+     */
     String UNDERLINE = "_";
-    
-    /** 连接符 - */
+
+    /**
+     * 连接符 -
+     */
     String LINE_THROUGH = "-";
-    
-    /** 连接符 → */
+
+    /**
+     * 连接符 →
+     */
     String RIGHT_ARROW = "→";
-    
-    /** 有效标示*/
+
+    /**
+     * 有效标示
+     */
     String VALID = "valid";
 
+    /**
+     * 设备状态-运行中
+     */
+    String RUNNING = "运行中";
+
+    /**
+     * 设备状态-报废
+     */
+    String SCRAP = "报废";
+
+    /**
+     * 设备状态-update
+     */
+    String IS_UPDATE = "update";
+
+    /**
+     * 设备状态-delete
+     */
+    String IS_DELETE = "delete";
+
 }

+ 25 - 15
src/main/java/com/persagy/transfer/controller/DemoController.java

@@ -1,31 +1,41 @@
 package com.persagy.transfer.controller;
 
-import javax.servlet.http.HttpServletRequest;
-
+import com.persagy.transfer.service.impl.DemoService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
-import com.persagy.transfer.service.impl.DemoService;
+import javax.servlet.http.HttpServletRequest;
 
 /**
  * 多数据源测试
- * 
- * @version 1.0.0
- * @company persagy 
+ *
  * @author zhangqiankun
+ * @version 1.0.0
+ * @company persagy
  * @date 2021年9月15日 下午4:12:18
  */
 @RestController
 public class DemoController {
 
-	@Autowired
-	private DemoService demoService;
-	
-	@RequestMapping("/test")
-	public Object queryCount(HttpServletRequest request) {
-		String datasource = request.getHeader("datasource");
-		return "1".equals(datasource) ? this.demoService.getDataByMasterOne() : this.demoService.getDataByMasterTwo();
-	}
-	
+    @Autowired
+    private DemoService demoService;
+
+    @RequestMapping("/test")
+    public Object queryCount(HttpServletRequest request) {
+        String datasource = request.getHeader("datasource");
+        return "1".equals(datasource) ? this.demoService.getDataByMasterOne() : this.demoService.getDataByMasterTwo();
+    }
+
+    @RequestMapping("/syncNow")
+    public Object syncNow() {
+        try {
+            this.demoService.syncData2WD();
+            return true;
+        } catch (Exception e) {
+            e.printStackTrace();
+            return false;
+        }
+    }
+
 }

+ 17 - 3
src/main/java/com/persagy/transfer/mapper/RwdObjecWdMapper.java

@@ -1,16 +1,30 @@
 package com.persagy.transfer.mapper;
 
+import com.persagy.transfer.pojo.dto.RwdObjecWd;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
 
 /**
  * 对象实例表
- * 
- * @version 1.0.0
- * @company persagy 
+ *
  * @author zhangqiankun
+ * @version 1.0.0
+ * @company persagy
  * @date 2021-09-16 13:16:57
  */
 @Mapper
 public interface RwdObjecWdMapper {
 
+    /**
+     * @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<RwdObjecWd> listByProjectId(@Param("classCode") String classCode, @Param("objType") String objType, @Param("projectId") String projectId);
 }

+ 13 - 7
src/main/java/com/persagy/transfer/service/IDemoService.java

@@ -2,16 +2,22 @@ package com.persagy.transfer.service;
 
 /**
  * 多数据源测试
- * 
- * @version 1.0.0
- * @company persagy 
+ *
  * @author zhangqiankun
+ * @version 1.0.0
+ * @company persagy
  * @date 2021年9月15日 下午4:12:35
  */
 public interface IDemoService {
 
-	Object getDataByMasterOne();
-	
-	Object getDataByMasterTwo();
-	
+    Object getDataByMasterOne();
+
+    Object getDataByMasterTwo();
+
+    /**
+     * @author YangWanYi
+     * @describe 向万达数据库同步设备数据
+     * @date 2021/9/16 11:38
+     */
+    void syncData2WD();
 }

+ 286 - 25
src/main/java/com/persagy/transfer/service/impl/DemoService.java

@@ -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
+         */
+
+        // 1.获取表wdclass_rel_persagy去重class_code的数据
+        log.info("准备同步设备数据到万达数据库");
+        LambdaQueryWrapper<WdclassRelPersagy> queryWdclassRelWrapper = new WdclassRelPersagy.BuilderQueryWrapper().builder();
+        List<WdclassRelPersagy> funcList = this.wdclassRelPersagyMapper.selectList(queryWdclassRelWrapper);
+
+        // 2.获取表wdproj_rel_persagyproj所有数据
+        LambdaQueryWrapper<WdprojRelPersagyproj> queryProjRelWrapper = new WdprojRelPersagyproj.BuilderQueryWrapper().builder();
+        List<WdprojRelPersagyproj> projList = this.wdprojRelPersagyprojMapper.selectList(queryProjRelWrapper);
+
+        // 3.遍历获取rwd_object_wd_?的数据
+        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) {
+                // classCode和persagyProjectid去重
+                if (classCodeList.contains(wdclassRelPersagy.getClassCode()) || persagyProjectIdList.contains(wdprojRelPersagyproj.getPersagyProjectid())) {
+                    log.info("有已经处理过的BDTP类编码或者博锐尚格项目id,准备跳过此次处理");
+                    continue;
+                }
+                classCodeList.add(wdclassRelPersagy.getClassCode());
+                persagyProjectIdList.add(wdprojRelPersagyproj.getPersagyProjectid());
+                // 根据外循环对象的classCode、objType='equipment',内循环对象的persagyProjectId,查询wd_object_wd_?表
+                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) { // 循环万达项目ID与博锐尚格项目ID映射表数据时,wdfacility_rel_persagy只查询一次
+                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); // 广场id 关联设备信息 Pj4403070003
+            if (!infosObj.isEmpty()) {
+                hydomcAssetspec.setSbybm(String.valueOf(infosObj.get(InfosKeyConstant.EQUIPMENT_CODE))); // 设备编码 关联设备信息 wD_gongchengxinxihua
+                hydomcAssetspec.setClassstructureid(String.valueOf(infosObj.get(InfosKeyConstant.EQUIPMENT_SORT))); // 设备分类id 1507
+                // 根据Datatype判断设置设备参数数字值还是设备参数文本值 key为wdfacility_rel_persagy的code值从infos取
+                if (IS_NUMBER.equals(wdfacilityRelPersagy.getDatatype())) { // 是数字
+                    log.info("dataType是数字");
+                    hydomcAssetspec.setNumvalue(Double.valueOf(String.valueOf(infosObj.get(wdfacilityRelPersagy.getCode())))); // 设备参数数字值 (取自infos)
+                } else if (IS_LETTER.equals(wdfacilityRelPersagy.getDatatype())) { // 是字母
+                    log.info("dataType是字母");
+                    hydomcAssetspec.setAlnvalue(String.valueOf(infosObj.get(wdfacilityRelPersagy.getCode()))); // 设备参数文本值 (取自infos)
+                }
+                // key为wdfacility_rel_persagy的code值从infos取 有值update 无值(空、空字符串)就是delete
+                if (StringUtils.isBlank(String.valueOf(infosObj.get(wdfacilityRelPersagy.getCode())))) {
+                    // 无值 delete
+                    log.info("code没有值,数据状态设置为delete");
+                    hydomcAssetspec.setDatastatus(SwitchConstant.IS_DELETE); // 数据状态 update/delete
+                } else {
+                    // 有值 update
+                    log.info("code有值,数据状态设置为update");
+                    hydomcAssetspec.setDatastatus(SwitchConstant.IS_UPDATE); // 数据状态 update/delete
+                }
+            }
+            hydomcAssetspec.setClassqc(wdfacilityRelPersagy.getClassqc()); // 设备分类名称 电梯系统/扶梯/人行步道 (取自中间表wdfacility_rel_persagy)
+            hydomcAssetspec.setAssetattrid(wdfacilityRelPersagy.getAssetattrid()); // 主键 设备参数id 1106 (取自中间表wdfacility_rel_persagy)
+            hydomcAssetspec.setCsdesc(wdfacilityRelPersagy.getCsdesc()); // 设备参数名称 (取自中间表wdfacility_rel_persagy)
+            hydomcAssetspec.setDatatype(wdfacilityRelPersagy.getDatatype()); // 设备参数类型 (取自中间表wdfacility_rel_persagy)
+            hydomcAssetspec.setMeasureunitid(wdfacilityRelPersagy.getMeasureunitid()); // 设备参数单位编码 (取自中间表wdfacility_rel_persagy)
+            hydomcAssetspec.setCsjldw(wdfacilityRelPersagy.getCsjldw()); // 设备参数单位名称 (取自中间表wdfacility_rel_persagy)
+            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); // 万达设备分类表id
+        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.setWzqy(); // 详细设备安装位置,格式:楼体-楼层-区域 没有key 后续补充
+            hydomcAsset.setFwqy(String.valueOf(infosObj.get(InfosKeyConstant.EQUIPMENT_SERVICE_ZONE))); // 设备服务区域 设备/系统服务范围
+            hydomcAsset.setSbxh(String.valueOf(infosObj.get(InfosKeyConstant.EQUIPMENT_MODEL))); // 厂商设备型号
+            hydomcAsset.setClassstructureid(classstrucrureid); // 对接设备分类id,同步后不可更改
+            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))); // 生产商公司供方管理系统编码code
+            hydomcAsset.setVendor(String.valueOf(infosObj.get(InfosKeyConstant.SUPPLIER))); // 供应商公司供方管理系统编码code
+            hydomcAsset.setFws(String.valueOf(infosObj.get(InfosKeyConstant.MAINTAINER))); // 服务商公司供方管理系统编码code
+            hydomcAsset.setPurchaseprice(Double.valueOf(String.valueOf(infosObj.get(InfosKeyConstant.PURCHASE_PRICE)))); // 采购金额 填写人民币元
+            hydomcAsset.setZjsynx(Double.valueOf(String.valueOf(infosObj.get(InfosKeyConstant.SERVICE_LIFE)))); // 折旧/使用年限 按年填写 如3年半则填写 3.5
+            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))); // 备注 wD_beizhu
+        }
+        hydomcAsset.setSiteid(wdProjectId); // 项目唯一id,可采用租赁系统广场id,同步后不可更改
+        hydomcAsset.setDatastatus(valid == 0 ? SwitchConstant.IS_DELETE : SwitchConstant.IS_UPDATE); // 数据状态 update/delete 当数据状态为delete时,设备状态需改为报废
+        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);
+    }
+
 }

+ 26 - 0
src/main/java/com/persagy/transfer/task/SycnEquDataToWdTask.java

@@ -0,0 +1,26 @@
+package com.persagy.transfer.task;
+
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+/**
+ * @description: 同步设备数据到万达数据库
+ * @author: YangWanYi
+ * @create: 2021-09-16 11:28
+ **/
+@Component
+@Slf4j
+public class SycnEquDataToWdTask {
+
+    private int times;
+
+    /**
+     * 数据同步逻辑
+     */
+    @Scheduled(cron = "*/15 * * * * ?")
+    public void execute() {
+        log.info("thread id:{},FixedPrintTask execute times:{}", Thread.currentThread().getId(), ++times);
+
+    }
+}

+ 10 - 4
src/main/resources/bootstrap.yml

@@ -11,9 +11,12 @@ spring:
       strict: true   #严格匹配数据源,默认false. true未匹配到指定数据源时抛异常,false使用默认数据源
       datasource:
         master_1:
-          url: jdbc:mysql://192.168.64.15:9934/dmp_rwd?serverTimezone=GMT&useUnicode=true&useSSL=false&characterEncoding=UTF-8&allowMultiQueries=true
+#          url: jdbc:mysql://192.168.64.15:9934/dmp_rwd?serverTimezone=GMT&useUnicode=true&useSSL=false&characterEncoding=UTF-8&allowMultiQueries=true
+#          url: jdbc:mysql://192.168.18.105:3306/dmp_rwd?serverTimezone=GMT&useUnicode=true&useSSL=false&characterEncoding=UTF-8&allowMultiQueries=true
+          url: jdbc:mysql://127.0.0.1:3306/dmp_rwd?serverTimezone=GMT&useUnicode=true&useSSL=false&characterEncoding=UTF-8&allowMultiQueries=true
           username: root
-          password: D56dLvRbSy5bMn
+#          password: D56dLvRbSy5bMn
+          password: 123456
           driver-class-name: com.mysql.cj.jdbc.Driver
           type: com.alibaba.druid.pool.DruidDataSource
           druid: 
@@ -33,9 +36,12 @@ spring:
             time-between-eviction-runs-millis: 50000
             max-pool-prepared-statement-per-connection-size: 20  
         master_2:
-          url: jdbc:mysql://192.168.64.15:9934/ibms-switch?serverTimezone=GMT&useUnicode=true&useSSL=false&characterEncoding=UTF-8&allowMultiQueries=true
+#          url: jdbc:mysql://192.168.64.15:9934/ibms-switch?serverTimezone=GMT&useUnicode=true&useSSL=false&characterEncoding=UTF-8&allowMultiQueries=true
+#          url: jdbc:mysql://192.168.18.105:3306/fakewd?serverTimezone=GMT&useUnicode=true&useSSL=false&characterEncoding=UTF-8&allowMultiQueries=true
+          url: jdbc:mysql://127.0.0.1:3306/fakewd?serverTimezone=GMT&useUnicode=true&useSSL=false&characterEncoding=UTF-8&allowMultiQueries=true
           username: root
-          password: D56dLvRbSy5bMn
+#          password: D56dLvRbSy5bMn
+          password: 123456
           driver-class-name: com.mysql.cj.jdbc.Driver
           type: com.alibaba.druid.pool.DruidDataSource
           druid: 

+ 33 - 24
src/main/resources/mapper/RwdObjecWdMapper.xml

@@ -2,28 +2,37 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 
 <mapper namespace="com.persagy.transfer.mapper.RwdObjecWdMapper">
-    
-	<resultMap id="BaseResultMap" type="com.persagy.transfer.pojo.dto.RwdObjecWd">
-		<result column="id" property="id" jdbcType="VARCHAR" />
-		<result column="name" property="name" jdbcType="VARCHAR" />
-		<result column="local_id" property="localId" jdbcType="VARCHAR" />
-		<result column="local_name" property="localName" jdbcType="VARCHAR" />
-		<result column="group_code" property="groupCode" jdbcType="VARCHAR" />
-		<result column="project_id" property="projectId" jdbcType="VARCHAR" />
-		<result column="obj_type" property="objType" jdbcType="VARCHAR" />
-		<result column="class_code" property="classCode" jdbcType="VARCHAR" />
-		<result column="grouping" property="grouping" jdbcType="INTEGER" />
-		<result column="valid" property="valid" jdbcType="INTEGER" />
-		<result column="infos" property="infos"
-			typeHandler="com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler"/>
-		<result column="virtual_info_codes" property="virtualInfoCodes" 
-			typeHandler="com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler"/>
-		<result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
-		<result column="update_time" property="updateTime" jdbcType="TIMESTAMP" />
-		<result column="create_user" property="createUser" jdbcType="VARCHAR" />
-		<result column="update_user" property="updateUser" jdbcType="VARCHAR" />
-		<result column="create_app" property="createApp" jdbcType="VARCHAR" />
-		<result column="update_app" property="updateApp" jdbcType="VARCHAR" />
-	</resultMap>
-	
+
+    <resultMap id="BaseResultMap" type="com.persagy.transfer.pojo.dto.RwdObjecWd">
+        <result column="id" property="id" jdbcType="VARCHAR"/>
+        <result column="name" property="name" jdbcType="VARCHAR"/>
+        <result column="local_id" property="localId" jdbcType="VARCHAR"/>
+        <result column="local_name" property="localName" jdbcType="VARCHAR"/>
+        <result column="group_code" property="groupCode" jdbcType="VARCHAR"/>
+        <result column="project_id" property="projectId" jdbcType="VARCHAR"/>
+        <result column="obj_type" property="objType" jdbcType="VARCHAR"/>
+        <result column="class_code" property="classCode" jdbcType="VARCHAR"/>
+        <result column="grouping" property="grouping" jdbcType="INTEGER"/>
+        <result column="valid" property="valid" jdbcType="INTEGER"/>
+        <result column="infos" property="infos"
+                typeHandler="com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler"/>
+        <result column="virtual_info_codes" property="virtualInfoCodes"
+                typeHandler="com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler"/>
+        <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
+        <result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
+        <result column="create_user" property="createUser" jdbcType="VARCHAR"/>
+        <result column="update_user" property="updateUser" jdbcType="VARCHAR"/>
+        <result column="create_app" property="createApp" jdbcType="VARCHAR"/>
+        <result column="update_app" property="updateApp" jdbcType="VARCHAR"/>
+    </resultMap>
+    <select id="listByProjectId" resultType="com.persagy.transfer.pojo.dto.RwdObjecWd">
+        select * from wd_object_wd_${projectId} where 1=1
+        <if test="objType != null and objType.trim() != ''">
+            and obj_type = #{objType}
+        </if>
+        <if test="classCode != null and classCode.trim() != ''">
+            and class_code = #{classCode}
+        </if>
+    </select>
+
 </mapper>