Browse Source

数据库改造代码提交

pengdi@zoniot.com 4 years ago
parent
commit
165ecc9453
28 changed files with 2236 additions and 10 deletions
  1. 0 1
      iot-data-processor/src/main/java/com/zcxk/zoniot/data/processor/service/impl/CacheDataProcessor.java
  2. 28 0
      smart-city-data-migrate/src/main/java/com/zcxk/zoniot/data/migrate/SmartCityDataMigrateApplication.java
  3. 51 0
      smart-city-data-migrate/src/main/java/com/zcxk/zoniot/data/migrate/config/MongoDbConfig.java
  4. 32 0
      smart-city-data-migrate/src/main/java/com/zcxk/zoniot/data/migrate/dao/DataMigrateRecordMapper.java
  5. 25 0
      smart-city-data-migrate/src/main/java/com/zcxk/zoniot/data/migrate/dao/DeviceDataDimMapper.java
  6. 32 0
      smart-city-data-migrate/src/main/java/com/zcxk/zoniot/data/migrate/dao/DeviceMapper.java
  7. 31 0
      smart-city-data-migrate/src/main/java/com/zcxk/zoniot/data/migrate/dao/MeterReadRecordMapper.java
  8. 47 0
      smart-city-data-migrate/src/main/java/com/zcxk/zoniot/data/migrate/model/DataMigrateRecord.java
  9. 94 0
      smart-city-data-migrate/src/main/java/com/zcxk/zoniot/data/migrate/model/Device.java
  10. 88 0
      smart-city-data-migrate/src/main/java/com/zcxk/zoniot/data/migrate/model/DeviceDataDim.java
  11. 154 0
      smart-city-data-migrate/src/main/java/com/zcxk/zoniot/data/migrate/model/MeterReadRecord.java
  12. 13 0
      smart-city-data-migrate/src/main/java/com/zcxk/zoniot/data/migrate/service/DataMigrateService.java
  13. 18 0
      smart-city-data-migrate/src/main/java/com/zcxk/zoniot/data/migrate/service/DeviceService.java
  14. 349 0
      smart-city-data-migrate/src/main/java/com/zcxk/zoniot/data/migrate/service/impl/DataMigrateServiceImpl.java
  15. 39 0
      smart-city-data-migrate/src/main/java/com/zcxk/zoniot/data/migrate/service/impl/DeviceServiceImpl.java
  16. 13 0
      smart-city-data-migrate/src/main/java/com/zcxk/zoniot/data/migrate/utils/Constants.java
  17. 47 0
      smart-city-data-migrate/src/main/resources/application-dev.properties
  18. 3 0
      smart-city-data-migrate/src/main/resources/application.properties
  19. 136 0
      smart-city-data-migrate/src/main/resources/mapper/DataMigrateRecordMapper.xml
  20. 158 0
      smart-city-data-migrate/src/main/resources/mapper/DeviceDataDimMapper.xml
  21. 425 0
      smart-city-data-migrate/src/main/resources/mapper/DeviceMapper.xml
  22. 393 0
      smart-city-data-migrate/src/main/resources/mapper/MeterReadRecordMapper.xml
  23. 24 0
      smart-city-data-migrate/src/test/java/com/zcxk/zoniot/data/migrate/SmartCityDataMigrateApplicationTests.java
  24. 1 1
      smart-city-dispatcher/src/main/resources/application-dev.properties
  25. 2 1
      smart-city-intf/src/main/java/com/zcxk/smartcity/data/access/kafka/consumer/SingleDataReceiver.java
  26. 4 4
      smart-city-intf/src/main/java/com/zcxk/smartcity/data/access/util/HexUtil.java
  27. 22 0
      smart-city-platform/src/main/java/com/bz/smart_city/quartz/job/WaterMeterReadJobV2.java
  28. 7 3
      smart-city-platform/src/main/java/com/bz/smart_city/service/impl/MeterReadRecordServiceImpl.java

+ 0 - 1
iot-data-processor/src/main/java/com/zcxk/zoniot/data/processor/service/impl/CacheDataProcessor.java

@@ -6,7 +6,6 @@ import com.zcxk.zoniot.data.processor.service.DeviceDataProcessor;
 import com.zcxk.zoniot.data.processor.service.DeviceService;
 import com.zcxk.zoniot.data.processor.utils.Constants;
 import com.zcxk.zoniot.data.processor.utils.RedisUtil;
-import com.zcxk.zoniot.smartcity.common.dto.DeviceDataDTO;
 import com.zcxk.zoniot.smartcity.common.model.DeviceData;
 import com.zcxk.zoniot.smartcity.common.model.DeviceMeasuringData;
 import lombok.extern.slf4j.Slf4j;

+ 28 - 0
smart-city-data-migrate/src/main/java/com/zcxk/zoniot/data/migrate/SmartCityDataMigrateApplication.java

@@ -0,0 +1,28 @@
+package com.zcxk.zoniot.data.migrate;
+
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.boot.CommandLineRunner;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.cache.annotation.EnableCaching;
+import org.springframework.context.annotation.ComponentScan;
+
+/**
+ * @author wilian.peng
+ */
+@Slf4j
+@EnableCaching
+@SpringBootApplication
+@ComponentScan(basePackages={"com.zcxk"})
+public class SmartCityDataMigrateApplication implements CommandLineRunner {
+
+    public static void main(String[] args) {
+        SpringApplication.run(SmartCityDataMigrateApplication.class, args);
+    }
+
+
+    @Override
+    public void run(String... args) throws Exception {
+        log.info("IOT HUB Data Migrate Module Starting ... ");
+    }
+}

+ 51 - 0
smart-city-data-migrate/src/main/java/com/zcxk/zoniot/data/migrate/config/MongoDbConfig.java

@@ -0,0 +1,51 @@
+package com.zcxk.zoniot.data.migrate.config;
+
+import com.mongodb.MongoClientOptions;
+import org.springframework.beans.factory.BeanFactory;
+import org.springframework.beans.factory.NoSuchBeanDefinitionException;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.data.convert.CustomConversions;
+import org.springframework.data.mongodb.MongoDbFactory;
+import org.springframework.data.mongodb.core.convert.DbRefResolver;
+import org.springframework.data.mongodb.core.convert.DefaultDbRefResolver;
+import org.springframework.data.mongodb.core.convert.DefaultMongoTypeMapper;
+import org.springframework.data.mongodb.core.convert.MappingMongoConverter;
+import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
+
+/**
+ * @author pengdi
+ */
+@Configuration
+public class MongoDbConfig {
+    /**
+     * <p>解决 MongoSocketReadTimeoutException异常</p>
+     * @return
+     */
+    @Bean
+    public MongoClientOptions mongoOptions() {
+        return MongoClientOptions
+            .builder()
+            .maxConnectionIdleTime(60000)
+            .build();
+    }
+
+    /**
+     * <p>去除文档中的_class字段</p>
+     * @param factory
+     * @param context
+     * @param beanFactory
+     * @return
+     */
+    @Bean
+    public MappingMongoConverter mappingMongoConverter(MongoDbFactory factory, MongoMappingContext context, BeanFactory beanFactory) {
+        DbRefResolver dbRefResolver = new DefaultDbRefResolver(factory);
+        MappingMongoConverter mappingConverter = new MappingMongoConverter(dbRefResolver, context);
+        try {
+            mappingConverter.setCustomConversions(beanFactory.getBean(CustomConversions.class));
+        } catch (NoSuchBeanDefinitionException ignore) {
+        }
+        mappingConverter.setTypeMapper(new DefaultMongoTypeMapper(null));
+        return mappingConverter;
+    }
+}

+ 32 - 0
smart-city-data-migrate/src/main/java/com/zcxk/zoniot/data/migrate/dao/DataMigrateRecordMapper.java

@@ -0,0 +1,32 @@
+package com.zcxk.zoniot.data.migrate.dao;
+
+import com.zcxk.zoniot.data.migrate.model.DataMigrateRecord;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+/**
+ * <p></p>
+ * @Author wilian.peng
+ * @Date 2020/6/30 14:35
+ * @Version 1.0
+ */
+@Mapper
+public interface DataMigrateRecordMapper {
+    int deleteByPrimaryKey(@Param("migrateDate") Integer migrateDate, @Param("tableName") String tableName);
+
+    int insert(DataMigrateRecord record);
+
+    int insertSelective(DataMigrateRecord record);
+
+    DataMigrateRecord selectByPrimaryKey(@Param("migrateDate") Integer migrateDate, @Param("tableName") String tableName);
+
+    int updateByPrimaryKeySelective(DataMigrateRecord record);
+
+    int updateByPrimaryKey(DataMigrateRecord record);
+
+    DataMigrateRecord findMigrateRecord(@Param("migrateBeginDate") Integer beginDate ,
+                                        @Param("migrateEndDate") Integer endDate ,
+                                        @Param("deviceId") Long deviceId);
+
+    
+}

+ 25 - 0
smart-city-data-migrate/src/main/java/com/zcxk/zoniot/data/migrate/dao/DeviceDataDimMapper.java

@@ -0,0 +1,25 @@
+package com.zcxk.zoniot.data.migrate.dao;
+
+import com.zcxk.zoniot.data.migrate.model.DeviceDataDim;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/**
+ * <p></p>
+ * @Author wilian.peng
+ * @Date 2020/6/30 15:17
+ * @Version 1.0
+ */
+@Mapper
+public interface DeviceDataDimMapper {
+    int insert(DeviceDataDim record);
+
+    int insertSelective(DeviceDataDim record);
+
+    List<DeviceDataDim> findDataList(@Param("day") Integer day);
+
+    List<DeviceDataDim> findDeviceDataList(@Param("deviceId") Long deviceId , @Param("beginDay") Integer beginDay,
+                                           @Param("endDay") Integer endDay);
+}

+ 32 - 0
smart-city-data-migrate/src/main/java/com/zcxk/zoniot/data/migrate/dao/DeviceMapper.java

@@ -0,0 +1,32 @@
+package com.zcxk.zoniot.data.migrate.dao;
+
+import com.zcxk.zoniot.data.migrate.model.Device;
+import com.zcxk.zoniot.smartcity.common.dto.DeviceDTO;
+import org.apache.ibatis.annotations.Mapper;
+
+import java.util.List;
+
+/**
+ * <p></p>
+ * @Author wilian.peng
+ * @Date 2020/6/30 17:41
+ * @Version 1.0
+ */
+@Mapper
+public interface DeviceMapper {
+    int deleteByPrimaryKey(Long id);
+
+    int insert(Device record);
+
+    int insertSelective(Device record);
+
+    Device selectByPrimaryKey(Long id);
+
+    int updateByPrimaryKeySelective(Device record);
+
+    int updateByPrimaryKey(Device record);
+
+    DeviceDTO findByDeviceId(Long deviceId) ;
+
+    List<Long> getDeviceIdList();
+}

+ 31 - 0
smart-city-data-migrate/src/main/java/com/zcxk/zoniot/data/migrate/dao/MeterReadRecordMapper.java

@@ -0,0 +1,31 @@
+package com.zcxk.zoniot.data.migrate.dao;
+
+import com.zcxk.zoniot.data.migrate.model.MeterReadRecord;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/**
+ * <p></p>
+ * @Author wilian.peng
+ * @Date 2020/6/30 15:18
+ * @Version 1.0
+ */
+@Mapper
+public interface MeterReadRecordMapper {
+    int deleteByPrimaryKey(Long id);
+
+    int insert(MeterReadRecord record);
+
+    int insertSelective(MeterReadRecord record);
+
+    MeterReadRecord selectByPrimaryKey(Long id);
+
+    int updateByPrimaryKeySelective(MeterReadRecord record);
+
+    int updateByPrimaryKey(MeterReadRecord record);
+
+    Integer countRecordList(@Param("day") Integer day);
+    List<MeterReadRecord> findRecordList(@Param("day") Integer day ,@Param("offset") Integer offset, @Param("limit") Integer limit);
+}

+ 47 - 0
smart-city-data-migrate/src/main/java/com/zcxk/zoniot/data/migrate/model/DataMigrateRecord.java

@@ -0,0 +1,47 @@
+package com.zcxk.zoniot.data.migrate.model;
+
+import java.util.Date;
+import lombok.Data;
+
+/**
+ * <p></p>
+ * @Author wilian.peng
+ * @Date 2020/6/30 14:35
+ * @Version 1.0
+ */
+@Data
+public class DataMigrateRecord {
+    /**
+    * 迁移日期
+    */
+    private Integer migrateDate;
+
+    /**
+    * 迁移表名称
+    */
+    private String tableName;
+
+    /**
+    * 应迁移总条数
+    */
+    private Integer total;
+
+    /**
+    * 实际迁移数
+    */
+    private Integer processCount;
+
+    /**
+    * 创建时间
+    */
+    private Date dateCreate;
+
+    /**
+    * 更新时间
+    */
+    private Date dateUpdate;
+
+    private Integer migrateEndDate;
+
+    private Long deviceId ;
+}

+ 94 - 0
smart-city-data-migrate/src/main/java/com/zcxk/zoniot/data/migrate/model/Device.java

@@ -0,0 +1,94 @@
+package com.zcxk.zoniot.data.migrate.model;
+
+import java.math.BigDecimal;
+import java.util.Date;
+import lombok.Data;
+
+/**
+ * <p></p>
+ * @Author wilian.peng
+ * @Date 2020/6/30 17:41
+ * @Version 1.0
+ */
+@Data
+public class Device {
+    private Long id;
+
+    private String deviceNo;
+
+    private Integer deviceType;
+
+    /**
+    * siteId
+    */
+    private Integer siteId;
+
+    private Integer sysId;
+
+    private Integer buildingId;
+
+    /**
+    * 建筑单元,存储格式, 数字+单元,例:1单元
+    */
+    private String buildingUnit;
+
+    private Integer floor;
+
+    private String locDesc;
+
+    /**
+    * 設備客戶,對應sc_customer表id
+    */
+    private Integer customerId;
+
+    private Long relatedDeviceNo;
+
+    /**
+    * 水表電子號
+    */
+    private String waterMeterNo;
+
+    /**
+    * 水表檔案號
+    */
+    private String waterMeterFileNo;
+
+    private Integer manufacturerId;
+
+    private String deviceStatus;
+
+    /**
+    * 设备最后上报时间
+    */
+    private Date lastReceiveTime;
+
+    private Boolean status;
+
+    private String isTag;
+
+    private BigDecimal xCoordinates;
+
+    private BigDecimal yCoordinates;
+
+    /**
+    * planId
+    */
+    private Integer planId;
+
+    /**
+    * udip平台id
+    */
+    private String udipId;
+
+    private String createBy;
+
+    private String updateBy;
+
+    private Date dateCreate;
+
+    private Date dateUpdate;
+
+    private String metercode;
+
+    private Long accountId;
+}

+ 88 - 0
smart-city-data-migrate/src/main/java/com/zcxk/zoniot/data/migrate/model/DeviceDataDim.java

@@ -0,0 +1,88 @@
+package com.zcxk.zoniot.data.migrate.model;
+
+import java.util.Date;
+import lombok.Data;
+
+/**
+ * <p></p>
+ * @Author wilian.peng
+ * @Date 2020/6/30 15:17
+ * @Version 1.0
+ */
+@Data
+public class DeviceDataDim {
+    /**
+    * 设备id,参考sc_device主键
+    */
+    private Long deviceId;
+
+    /**
+    * 设备编号,参考sc_device表device_no
+    */
+    private String deviceNo;
+
+    /**
+    * 站点,参考sc_site主键
+    */
+    private Integer siteId;
+
+    /**
+    * 场景,参考sc_channel主键
+    */
+    private Integer sysId;
+
+    /**
+    * 建筑,参考sc_building主键
+    */
+    private Integer buildingId;
+
+    /**
+    * 楼层
+    */
+    private Integer floor;
+
+    /**
+    * 安装信息
+    */
+    private String location;
+
+    /**
+    * 数据产生日期,yyyyMMdd
+    */
+    private Integer sendDate;
+
+    /**
+    * 测点id,参考
+    */
+    private Integer measuringId;
+
+    /**
+    * 测点编码
+    */
+    private String measuringCode;
+
+    /**
+    * 测点数据
+    */
+    private String measuringData;
+
+    /**
+    * 测点单位
+    */
+    private String measuringUnit;
+
+    /**
+    * 发送时间
+    */
+    private Date sendTime;
+
+    /**
+    * 创建人
+    */
+    private String createBy;
+
+    /**
+    * 创建时间
+    */
+    private Date dateCreate;
+}

+ 154 - 0
smart-city-data-migrate/src/main/java/com/zcxk/zoniot/data/migrate/model/MeterReadRecord.java

@@ -0,0 +1,154 @@
+package com.zcxk.zoniot.data.migrate.model;
+
+import java.math.BigDecimal;
+import java.util.Date;
+import lombok.Data;
+
+/**
+ * <p></p>
+ * @Author wilian.peng
+ * @Date 2020/6/30 15:18
+ * @Version 1.0
+ */
+@Data
+public class MeterReadRecord {
+    /**
+    * 主键
+    */
+    private Long id;
+
+    /**
+    * 读表日期
+    */
+    private Integer readDate;
+
+    /**
+    * 站点
+    */
+    private Integer siteId;
+
+    /**
+    * 场景
+    */
+    private Integer sysId;
+
+    /**
+    * 省
+    */
+    private Integer province;
+
+    /**
+    * 市
+    */
+    private Integer city;
+
+    /**
+    * 区
+    */
+    private Integer region;
+
+    /**
+    * 小区
+    */
+    private Integer community;
+
+    /**
+    * 客户
+    */
+    private Integer customerId;
+
+    /**
+    * 集中器
+    */
+    private Integer concentratorId;
+
+    /**
+    * 采集器
+    */
+    private Integer collectorId;
+
+    /**
+    * 建筑
+    */
+    private Integer buildingId;
+
+    /**
+    * 安装地址
+    */
+    private String location;
+
+    /**
+    * 设备类型
+    */
+    private Integer deviceTypeId;
+
+    /**
+    * 设备id
+    */
+    private Long deviceId;
+
+    /**
+    * 节点编号
+    */
+    private String deviceNo;
+
+    /**
+    * 电子号
+    */
+    private String meterNo;
+
+    /**
+    * 档案号
+    */
+    private String meterFileNo;
+
+    /**
+    * 读表时间
+    */
+    private Date readTime;
+
+    /**
+    * 读表状态
+    */
+    private Integer readStatus;
+
+    /**
+    * 读表数据
+    */
+    private String readData;
+
+    /**
+    * 最近有效数据
+    */
+    private String lastValid;
+
+    /**
+    * 距离上次的消耗
+    */
+    private Double lastCost;
+
+    /**
+    * 状态
+    */
+    private Integer status;
+
+    /**
+    * 创建时间
+    */
+    private Date dateCreate;
+
+    /**
+    * 更新时间
+    */
+    private Date dateUpdate;
+
+    /**
+    * 创建人
+    */
+    private String createBy;
+
+    /**
+    * 更新人
+    */
+    private String updateBy;
+}

+ 13 - 0
smart-city-data-migrate/src/main/java/com/zcxk/zoniot/data/migrate/service/DataMigrateService.java

@@ -0,0 +1,13 @@
+package com.zcxk.zoniot.data.migrate.service;
+
+/**
+ * <p></p>
+ *
+ * @Author wilian.peng
+ * @Date 2020/6/30 15:03
+ * @Version 1.0
+ */
+public interface DataMigrateService {
+    void migrate();
+    void migrate(Integer date , String tableName);
+}

+ 18 - 0
smart-city-data-migrate/src/main/java/com/zcxk/zoniot/data/migrate/service/DeviceService.java

@@ -0,0 +1,18 @@
+package com.zcxk.zoniot.data.migrate.service;
+
+import com.zcxk.zoniot.smartcity.common.dto.DeviceDTO;
+
+import java.util.List;
+
+/**
+ * <p></p>
+ *
+ * @Author wilian.peng
+ * @Date 2020/6/30 17:34
+ * @Version 1.0
+ */
+public interface DeviceService {
+    DeviceDTO findDeviceById(Long deviceId);
+
+    List<Long> getDeviceIdList();
+}

+ 349 - 0
smart-city-data-migrate/src/main/java/com/zcxk/zoniot/data/migrate/service/impl/DataMigrateServiceImpl.java

@@ -0,0 +1,349 @@
+package com.zcxk.zoniot.data.migrate.service.impl;
+
+import com.alibaba.fastjson.JSON;
+import com.zcxk.zoniot.data.migrate.dao.DataMigrateRecordMapper;
+import com.zcxk.zoniot.data.migrate.dao.DeviceDataDimMapper;
+import com.zcxk.zoniot.data.migrate.dao.MeterReadRecordMapper;
+import com.zcxk.zoniot.data.migrate.model.DataMigrateRecord;
+import com.zcxk.zoniot.data.migrate.model.DeviceDataDim;
+import com.zcxk.zoniot.data.migrate.service.DataMigrateService;
+import com.zcxk.zoniot.data.migrate.service.DeviceService;
+import com.zcxk.zoniot.data.migrate.utils.Constants;
+import com.zcxk.zoniot.smartcity.common.dto.DeviceDTO;
+import com.zcxk.zoniot.smartcity.common.model.DeviceData;
+import com.zcxk.zoniot.smartcity.common.model.DeviceMeasuringData;
+import com.zcxk.zoniot.smartcity.common.model.MeterReadRecord;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.data.mongodb.core.MongoTemplate;
+import org.springframework.stereotype.Component;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.time.Instant;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.util.*;
+
+/**
+ * <p></p>
+ *
+ * @Author wilian.peng
+ * @Date 2020/6/30 15:03
+ * @Version 1.0
+ */
+@Slf4j
+@Component
+public class DataMigrateServiceImpl implements DataMigrateService {
+    private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
+
+    @Autowired
+    MongoTemplate mongoTemplate ;
+
+    @Autowired
+    DataMigrateRecordMapper  dataMigrateRecordMapper;
+
+    @Autowired
+    DeviceDataDimMapper  deviceDataDimMapper ;
+
+    @Autowired
+    MeterReadRecordMapper  meterReadRecordMapper ;
+
+    @Autowired
+    DeviceService deviceService;
+
+    @Value("${data.migrate.begin.date}")
+    String beginDateStr ;
+
+    @Value("${data.migrate.end.date}")
+    String endDateStr ;
+
+    @Override
+    public void migrate() {
+//        Date beginDate = parseDate(beginDateStr);
+//        Date endDate = parseDate(endDateStr);
+//        List<String> days = betweenDate(beginDate, endDate);
+//        for(String day : days){
+//            migrate(Integer.parseInt(day),Constants.RECORD_TABLE_NAME);
+//        }
+        migrateDeviceData(Integer.parseInt(beginDateStr),Integer.parseInt(endDateStr));
+    }
+
+    @Override
+    public void migrate(Integer date, String tableName) {
+        try{
+            // 1,查询是否已经迁移过
+            DataMigrateRecord record = dataMigrateRecordMapper.selectByPrimaryKey(date, tableName);
+            if (record != null){
+                log.warn("Data is migrated ! Date = {} ,Table = {}",date,tableName);
+                return ;
+            }
+            // 2,迁移实时数据
+            if(Constants.DATA_TABLE_NAME.equals(tableName)){
+                migrateDeviceData(date);
+            }
+            // 3,迁移抄表数据
+            else if(Constants.RECORD_TABLE_NAME.equals(tableName)){
+                migrateMeterReadRecord(date);
+            }
+        }catch (Exception e){
+            log.error("Migrate Data Failed !, Date = {} ,TableName = {}",date,tableName);
+        }
+    }
+
+
+    protected  void migrateMeterReadRecord(Integer day){
+        // 1,查询当日迁移数据
+        Integer total = meterReadRecordMapper.countRecordList(day);
+        // 2,转换成Mongo对象
+        if(total != 0){
+            int pageSize = 5000 ;
+            int batch =total / pageSize;
+            if(total % pageSize != 0){
+                batch++;
+            }
+            for(int j = 1 ;j <= batch ; j++){
+                int fromIndex = (j-1)*pageSize;
+                int endIndex = fromIndex + pageSize ;
+                if(endIndex > total){
+                    endIndex = total ;
+                }
+                List<com.zcxk.zoniot.data.migrate.model.MeterReadRecord> recordList = meterReadRecordMapper.findRecordList(day,fromIndex,pageSize);
+                List<MeterReadRecord> mongoRecordList = new ArrayList<>() ;
+                recordList.forEach(r->{
+                    mongoRecordList.add(buildMeterReadRecord(r));
+                });
+                mongoTemplate.insertAll(mongoRecordList);
+            }
+        }
+        // 3,保存迁移记录
+        DataMigrateRecord record = new DataMigrateRecord();
+        record.setDateCreate(new Date());
+        record.setMigrateDate(day);
+        record.setTableName(Constants.RECORD_TABLE_NAME);
+        record.setProcessCount(total);
+        record.setTotal(total);
+        dataMigrateRecordMapper.insert(record);
+    }
+
+    protected  void migrateDeviceData(Integer beginDay,Integer endDay){
+        // 1,查询所有设备
+        List<Long> deviceIdList = deviceService.getDeviceIdList();
+        // 2,按照设备进行数据迁移
+        for(Long deviceId : deviceIdList){
+            migrateDeviceData(deviceId,beginDay,endDay);
+        }
+    }
+    protected void migrateDeviceData(Long deviceId ,Integer beginDay ,Integer endDay){
+        // 1,判断时间段数据是否已经迁移
+        DataMigrateRecord migrateRecord = dataMigrateRecordMapper.findMigrateRecord(beginDay, endDay, deviceId);
+        if(migrateRecord != null){
+            log.warn("Data is migrated ! Date = {} ,EndDay = {} ,DeviceId = {}",beginDay,endDay,deviceId);
+            return ;
+        }
+        // 1,查询设备在时间段内的所有数据
+        List<DeviceDataDim> dataList = deviceDataDimMapper.findDeviceDataList(deviceId, beginDay, endDay);
+        // 2,将DataDimList转化为DataList
+        List<DeviceData> deviceDataList = deviceDataDimToDeviceData(dataList);
+        // 3,批量插入数据
+        mongoTemplate.insertAll(deviceDataList);
+        // 4,写入迁移日志
+        DataMigrateRecord record = new DataMigrateRecord();
+        record.setDateCreate(new Date());
+        record.setMigrateDate(beginDay);
+        record.setMigrateEndDate(endDay);
+        record.setDeviceId(deviceId);
+        record.setTableName(Constants.DATA_TABLE_NAME);
+        record.setProcessCount(deviceDataList.size());
+        record.setTotal(dataList.size());
+        dataMigrateRecordMapper.insertSelective(record);
+    }
+
+    protected List<DeviceData>  deviceDataDimToDeviceData(List<DeviceDataDim> dataList){
+        // 存储结构 设备ID-->各时间点设备测点数据
+        Map<Long,Map<Date,List<DeviceDataDim>>> dataMap = new HashMap<>();
+        for(DeviceDataDim data : dataList){
+            Long deviceId = data.getDeviceId();
+            Date sendTime = data.getSendTime();
+            Map<Date, List<DeviceDataDim>> dateMap = dataMap.get(deviceId);
+            if(dateMap == null){
+                Map<Date, List<DeviceDataDim>> tmpMap = new HashMap<>();
+                List<DeviceDataDim> tmpList = new ArrayList<>();
+                tmpList.add(data);
+                tmpMap.put(sendTime,tmpList);
+                dataMap.put(deviceId,tmpMap);
+            }
+            else{
+                List<DeviceDataDim> dimList = dateMap.get(sendTime);
+                if(dimList == null || dimList.size() == 0){
+                    List<DeviceDataDim> tmpList = new ArrayList<>();
+                    tmpList.add(data);
+                    dateMap.put(sendTime,tmpList);
+                }
+                else{
+                    dimList.add(data);
+                }
+            }
+
+        }
+        List<DeviceData>  deviceDataList = new ArrayList<>();
+        // 2,遍历设备进行实时数据存储
+        for(Map.Entry<Long,Map<Date,List<DeviceDataDim>>> entry : dataMap.entrySet()){
+            Long deviceId = entry.getKey();
+            DeviceDTO device = deviceService.findDeviceById(deviceId);
+            Map<Date,List<DeviceDataDim>>  dateMap = entry.getValue();
+            for(Map.Entry<Date,List<DeviceDataDim>> t : dateMap.entrySet()){
+                Date receiveTime = t.getKey();
+                List<DeviceDataDim> list = t.getValue();
+                DeviceData deviceData = buildDeviceData(device,receiveTime, list);
+                deviceDataList.add(deviceData);
+            }
+        }
+        return deviceDataList ;
+    }
+    /**
+     * <p>迁移设备数据,返回迁移条数</p>
+     * @param day
+     * @return
+     */
+    protected  void migrateDeviceData(Integer day){
+        // 1, 查询当日迁移条数
+        List<DeviceDataDim> dataList = deviceDataDimMapper.findDataList(day);
+        // 2,将DataDimList转化为DataList
+        // 存储结构 设备ID-->各时间点设备测点数据
+        List<DeviceData> deviceDataList = deviceDataDimToDeviceData(dataList);
+        // 3,批量插入数据
+        int total = deviceDataList.size() ;
+        if(total != 0){
+            int pageSize = 5000 ;
+            int batch =total / pageSize;
+            if(total % pageSize != 0){
+                batch++;
+            }
+            for(int j = 1 ;j <= batch ; j++){
+                int fromIndex = (j-1)*pageSize;
+                int endIndex = fromIndex + pageSize ;
+                if(endIndex > total){
+                    endIndex = total ;
+                }
+                List<DeviceData> subList = deviceDataList.subList(fromIndex, endIndex);
+                mongoTemplate.insertAll(subList);
+            }
+        }
+        // 4,记录迁移日志
+        DataMigrateRecord record = new DataMigrateRecord();
+        record.setDateCreate(new Date());
+        record.setMigrateDate(day);
+        record.setTableName(Constants.DATA_TABLE_NAME);
+        record.setProcessCount(total);
+        record.setTotal(dataList.size());
+        dataMigrateRecordMapper.insert(record);
+    }
+    protected MeterReadRecord  buildMeterReadRecord(com.zcxk.zoniot.data.migrate.model.MeterReadRecord  originalRecord){
+        MeterReadRecord record = new MeterReadRecord();
+        record.setLastCost(originalRecord.getLastCost());
+        record.setLastValid(originalRecord.getLastValid());
+        record.setReadData(originalRecord.getReadData());
+        record.setSiteId(originalRecord.getSiteId());
+        record.setReadStatus(originalRecord.getReadStatus());
+        record.setReadDate(originalRecord.getReadDate());
+        record.setReadTime(jdk8DateToLocalDateTime(originalRecord.getReadTime()));
+        record.setMeterFileNo(originalRecord.getMeterFileNo());
+        record.setMeterNo(originalRecord.getMeterNo());
+        record.setDeviceTypeId(originalRecord.getDeviceTypeId());
+        record.setDeviceNo(originalRecord.getDeviceNo());
+        record.setDeviceId(originalRecord.getDeviceId());
+        record.setDataCreate(jdk8DateToLocalDateTime(originalRecord.getDateCreate()));
+        record.setCustomerId(originalRecord.getCustomerId());
+        record.setCollectorId(originalRecord.getCollectorId());
+        record.setConcentratorId(originalRecord.getConcentratorId());
+        record.setRegionId(originalRecord.getRegion());
+        record.setCityId(originalRecord.getCity());
+        record.setCommunityId(originalRecord.getCustomerId());
+        record.setChannelId(originalRecord.getSysId());
+        record.setBuildingId(originalRecord.getBuildingId());
+        record.setProvinceId(originalRecord.getProvince());
+        record.setStatus(originalRecord.getStatus());
+        return record ;
+    }
+    protected DeviceData buildDeviceData(DeviceDTO device ,Date receiveDate ,List<DeviceDataDim> dataDimList){
+        DeviceData data = new DeviceData();
+        data.setCustomerId(device.getCustomerId());
+        data.setBuildingId(device.getBuildingId());
+        data.setBuildingName(device.getBuildingName());
+        data.setChannelId(device.getChannelId());
+        data.setCityId(device.getCityId());
+        data.setCityName(device.getCityName());
+        data.setCommunityId(device.getCommunityId());
+        data.setCommunityName(device.getCommunityName());
+        data.setDeviceId(device.getId());
+        data.setDeviceNo(device.getDeviceNo());
+        data.setDeviceTypeId(device.getDeviceTypeId());
+        data.setDeviceTypeName(device.getDeviceTypeName());
+        data.setLocation(device.getLocDesc());
+        data.setProvinceId(device.getProvinceId());
+        data.setProvinceName(device.getProvinceName());
+        data.setManufacturerId(device.getManufacturerId());
+        data.setManufacturerName(device.getManufacturerName());
+        data.setModel(device.getModel());
+        data.setSiteId(device.getSiteId());
+        data.setReceiveDate(Integer.parseInt(formatDate(receiveDate)));
+        data.setReceiveTime(receiveDate);
+        data.setStatus(1);
+        List<DeviceMeasuringData> measuringDataList = new ArrayList<>();
+        dataDimList.forEach(dataDim->{
+            DeviceMeasuringData measuringData = new DeviceMeasuringData();
+            measuringData.setMeasuringData(dataDim.getMeasuringData());
+            measuringData.setMeasuringUnit(dataDim.getMeasuringUnit());
+            measuringData.setMeasuringId(dataDim.getMeasuringId());
+            measuringData.setMeasuringCode(dataDim.getMeasuringCode());
+            measuringDataList.add(measuringData);
+        });
+        data.setData(measuringDataList);
+        return data ;
+    }
+    protected LocalDateTime jdk8DateToLocalDateTime(Date date){
+        if(date != null){
+            Instant instant = date.toInstant();
+            ZoneId zoneId = ZoneId.systemDefault();
+            LocalDateTime localDateTime = instant.atZone(zoneId).toLocalDateTime();
+            return localDateTime;
+        }
+        else{
+            return null ;
+        }
+    }
+    protected String formatDate(Date date) {
+        String  dateStr = null;
+        synchronized(sdf){
+            dateStr = sdf.format(date);
+        }
+        return dateStr;
+    }
+    protected  Date parseDate(String dateStr ) {
+        Date date = null ;
+        synchronized(sdf){
+            try {
+                date = sdf.parse(dateStr);
+            } catch (ParseException e) {
+                log.error("Date Parse Error !",e);
+            }
+        }
+        return date;
+    }
+    protected  List<String> betweenDate(Date startDate ,Date endDate){
+        List<String> dates = new ArrayList<String>();
+        Calendar cal=Calendar.getInstance();
+        cal.setTime(endDate);
+        while(endDate.after(startDate)) {
+            dates.add(formatDate(cal.getTime()));
+            cal.add(Calendar.DATE,-1);
+            cal.setTime(cal.getTime());
+            endDate = cal.getTime();
+        }
+        dates.add(formatDate(cal.getTime()));
+        return dates;
+    }
+
+}

+ 39 - 0
smart-city-data-migrate/src/main/java/com/zcxk/zoniot/data/migrate/service/impl/DeviceServiceImpl.java

@@ -0,0 +1,39 @@
+package com.zcxk.zoniot.data.migrate.service.impl;
+
+import com.zcxk.zoniot.data.migrate.dao.DeviceMapper;
+import com.zcxk.zoniot.data.migrate.model.Device;
+import com.zcxk.zoniot.data.migrate.service.DeviceService;
+import com.zcxk.zoniot.smartcity.common.dto.DeviceDTO;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.cache.annotation.Cacheable;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+/**
+ * <p></p>
+ *
+ * @Author wilian.peng
+ * @Date 2020/6/30 17:35
+ * @Version 1.0
+ */
+@Slf4j
+@Service
+public class DeviceServiceImpl implements DeviceService {
+    @Autowired
+    DeviceMapper  deviceMapper;
+
+    @Cacheable(value = "DeviceIdCache",key = "#deviceId",unless = "#result == null")
+    @Override
+    public DeviceDTO findDeviceById(Long deviceId) {
+        DeviceDTO device = deviceMapper.findByDeviceId(deviceId);
+        return device;
+    }
+
+    @Override
+    public List<Long> getDeviceIdList() {
+        List<Long> deviceIdList = deviceMapper.getDeviceIdList();
+        return deviceIdList;
+    }
+}

+ 13 - 0
smart-city-data-migrate/src/main/java/com/zcxk/zoniot/data/migrate/utils/Constants.java

@@ -0,0 +1,13 @@
+package com.zcxk.zoniot.data.migrate.utils;
+
+/**
+ * <p></p>
+ *
+ * @Author wilian.peng
+ * @Date 2020/6/30 15:06
+ * @Version 1.0
+ */
+public class Constants {
+    public static final String DATA_TABLE_NAME= "sc_device_data_dim";
+    public static final String RECORD_TABLE_NAME = "sc_meter_read_record";
+}

+ 47 - 0
smart-city-data-migrate/src/main/resources/application-dev.properties

@@ -0,0 +1,47 @@
+############################################日志配置###############################################
+logging.level.root=info
+logging.file.path=c:/tmp/iot/migrate/logs
+###########################################数据库配置##############################################
+spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
+spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
+spring.datasource.url=jdbc:mysql://114.135.61.188:33306/smart_city_sit_6_10?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&zeroDateTimeBehavior=convertToNull
+spring.datasource.name=smart_city
+spring.datasource.username=root
+spring.datasource.password=100Zone@123
+spring.datasource.druid.initial-size=20
+spring.datasource.druid.min-idle=5
+spring.datasource.druid.max-active=50
+spring.datasource.druid.max-wait=60000
+spring.datasource.druid.time-between-eviction-runs-millis=60000
+spring.datasource.druid.min-evictable-idle-time-millis=300000
+spring.datasource.druid.validation-query=SELECT 1
+spring.datasource.druid.test-while-idle=true
+spring.datasource.druid.test-on-borrow=true
+spring.datasource.druid.test-on-return=false
+spring.datasource.druid.pool-prepared-statements=true
+spring.datasource.druid.max-pool-prepared-statement-per-connection-size=20
+spring.datasource.druid.filters=stat,wall
+spring.datasource.druid.connection-properties=druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
+###########################################MyBatis配置##############################################
+mybatis.mapper-locations=classpath*:mapper/*.xml
+mybatis.type-aliases-package=com.zcxk.zoniot.data.migrate.model
+mybatis.configuration.map-underscore-to-camel-case=true
+mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
+mybatis.configuration.use-column-label=true
+###########################################MongoDB配置##############################################
+spring.data.mongodb.uri=mongodb://114.135.61.188:17017/water-iot-database
+logging.level.org.springframework.data.mongodb.core=DEBUG
+#############################################Redis配置##############################################
+spring.redis.host=114.135.61.188
+spring.redis.port=26379
+spring.redis.password=zoniot
+spring.redis.database=1
+spring.redis.timeout=36000
+spring.redis.lettuce.pool.max-active=8
+spring.redis.lettuce.pool.max-wait=300
+spring.redis.lettuce.pool.max-idle=8
+spring.redis.lettuce.pool.min-idle=1
+spring.redis.lettuce.shutdown-timeout=300
+#############################################迁移配置##############################################
+data.migrate.begin.date=20200701
+data.migrate.end.date=20200701

+ 3 - 0
smart-city-data-migrate/src/main/resources/application.properties

@@ -0,0 +1,3 @@
+#开发环境:dev  测试环境:sit  线上环境:prd
+spring.profiles.active=dev
+

+ 136 - 0
smart-city-data-migrate/src/main/resources/mapper/DataMigrateRecordMapper.xml

@@ -0,0 +1,136 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.zcxk.zoniot.data.migrate.dao.DataMigrateRecordMapper">
+  <resultMap id="BaseResultMap" type="com.zcxk.zoniot.data.migrate.model.DataMigrateRecord">
+    <!--@mbg.generated-->
+    <!--@Table sc_data_migrate_record-->
+    <id column="migrate_date" jdbcType="INTEGER" property="migrateDate" />
+    <id column="table_name" jdbcType="VARCHAR" property="tableName" />
+    <result column="total" jdbcType="INTEGER" property="total" />
+    <result column="process_count" jdbcType="INTEGER" property="processCount" />
+    <result column="date_create" jdbcType="TIMESTAMP" property="dateCreate" />
+    <result column="date_update" jdbcType="TIMESTAMP" property="dateUpdate" />
+  </resultMap>
+  <sql id="Base_Column_List">
+    <!--@mbg.generated-->
+    migrate_date, `table_name`, total, process_count, date_create, date_update
+  </sql>
+  <select id="selectByPrimaryKey" parameterType="map" resultMap="BaseResultMap">
+    <!--@mbg.generated-->
+    select 
+    <include refid="Base_Column_List" />
+    from sc_data_migrate_record
+    where migrate_date = #{migrateDate,jdbcType=INTEGER}
+      and `table_name` = #{tableName,jdbcType=VARCHAR}
+  </select>
+  <delete id="deleteByPrimaryKey" parameterType="map">
+    <!--@mbg.generated-->
+    delete from sc_data_migrate_record
+    where migrate_date = #{migrateDate,jdbcType=INTEGER}
+      and `table_name` = #{tableName,jdbcType=VARCHAR}
+  </delete>
+  <insert id="insert" parameterType="com.zcxk.zoniot.data.migrate.model.DataMigrateRecord">
+    <!--@mbg.generated-->
+    insert into sc_data_migrate_record (migrate_date, `table_name`, total, 
+      process_count, date_create, date_update
+      )
+    values (#{migrateDate,jdbcType=INTEGER}, #{tableName,jdbcType=VARCHAR}, #{total,jdbcType=INTEGER}, 
+      #{processCount,jdbcType=INTEGER}, #{dateCreate,jdbcType=TIMESTAMP}, #{dateUpdate,jdbcType=TIMESTAMP}
+      )
+  </insert>
+  <insert id="insertSelective" parameterType="com.zcxk.zoniot.data.migrate.model.DataMigrateRecord">
+    <!--@mbg.generated-->
+    insert into sc_data_migrate_record
+    <trim prefix="(" suffix=")" suffixOverrides=",">
+      <if test="migrateDate != null">
+        migrate_date,
+      </if>
+      <if test="tableName != null">
+        `table_name`,
+      </if>
+      <if test="total != null">
+        total,
+      </if>
+      <if test="processCount != null">
+        process_count,
+      </if>
+      <if test="dateCreate != null">
+        date_create,
+      </if>
+      <if test="dateUpdate != null">
+        date_update,
+      </if>
+      <if test="migrateEndDate != null">
+        migrate_end_date,
+      </if>
+      <if test="deviceId != null" >
+        device_id,
+      </if>
+    </trim>
+    <trim prefix="values (" suffix=")" suffixOverrides=",">
+      <if test="migrateDate != null">
+        #{migrateDate,jdbcType=INTEGER},
+      </if>
+      <if test="tableName != null">
+        #{tableName,jdbcType=VARCHAR},
+      </if>
+      <if test="total != null">
+        #{total,jdbcType=INTEGER},
+      </if>
+      <if test="processCount != null">
+        #{processCount,jdbcType=INTEGER},
+      </if>
+      <if test="dateCreate != null">
+        #{dateCreate,jdbcType=TIMESTAMP},
+      </if>
+      <if test="dateUpdate != null">
+        #{dateUpdate,jdbcType=TIMESTAMP},
+      </if>
+      <if test="migrateEndDate != null">
+        #{migrateEndDate,jdbcType=INTEGER},
+      </if>
+      <if test="deviceId != null">
+        #{deviceId,jdbcType=BIGINT}
+      </if>
+    </trim>
+  </insert>
+  <update id="updateByPrimaryKeySelective" parameterType="com.zcxk.zoniot.data.migrate.model.DataMigrateRecord">
+    <!--@mbg.generated-->
+    update sc_data_migrate_record
+    <set>
+      <if test="total != null">
+        total = #{total,jdbcType=INTEGER},
+      </if>
+      <if test="processCount != null">
+        process_count = #{processCount,jdbcType=INTEGER},
+      </if>
+      <if test="dateCreate != null">
+        date_create = #{dateCreate,jdbcType=TIMESTAMP},
+      </if>
+      <if test="dateUpdate != null">
+        date_update = #{dateUpdate,jdbcType=TIMESTAMP},
+      </if>
+    </set>
+    where migrate_date = #{migrateDate,jdbcType=INTEGER}
+      and `table_name` = #{tableName,jdbcType=VARCHAR}
+  </update>
+  <update id="updateByPrimaryKey" parameterType="com.zcxk.zoniot.data.migrate.model.DataMigrateRecord">
+    <!--@mbg.generated-->
+    update sc_data_migrate_record
+    set total = #{total,jdbcType=INTEGER},
+      process_count = #{processCount,jdbcType=INTEGER},
+      date_create = #{dateCreate,jdbcType=TIMESTAMP},
+      date_update = #{dateUpdate,jdbcType=TIMESTAMP}
+    where migrate_date = #{migrateDate,jdbcType=INTEGER}
+      and `table_name` = #{tableName,jdbcType=VARCHAR}
+  </update>
+  <select id="findMigrateRecord" resultMap="BaseResultMap">
+    select
+        <include refid="Base_Column_List" />
+    from
+        sc_data_migrate_record
+    where migrate_date = #{migrateBeginDate,jdbcType=INTEGER}
+    and migrate_end_date = #{migrateEndDate,jdbcType=INTEGER}
+    and device_id = #{deviceId,jdbcType=BIGINT}
+  </select>
+</mapper>

+ 158 - 0
smart-city-data-migrate/src/main/resources/mapper/DeviceDataDimMapper.xml

@@ -0,0 +1,158 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.zcxk.zoniot.data.migrate.dao.DeviceDataDimMapper">
+  <resultMap id="BaseResultMap" type="com.zcxk.zoniot.data.migrate.model.DeviceDataDim">
+    <!--@mbg.generated-->
+    <!--@Table sc_device_data_dim-->
+    <result column="device_id" jdbcType="BIGINT" property="deviceId" />
+    <result column="device_no" jdbcType="VARCHAR" property="deviceNo" />
+    <result column="site_id" jdbcType="INTEGER" property="siteId" />
+    <result column="sys_id" jdbcType="INTEGER" property="sysId" />
+    <result column="building_id" jdbcType="INTEGER" property="buildingId" />
+    <result column="floor" jdbcType="INTEGER" property="floor" />
+    <result column="location" jdbcType="VARCHAR" property="location" />
+    <result column="send_date" jdbcType="INTEGER" property="sendDate" />
+    <result column="measuring_id" jdbcType="INTEGER" property="measuringId" />
+    <result column="measuring_code" jdbcType="VARCHAR" property="measuringCode" />
+    <result column="measuring_data" jdbcType="VARCHAR" property="measuringData" />
+    <result column="measuring_unit" jdbcType="VARCHAR" property="measuringUnit" />
+    <result column="send_time" jdbcType="TIMESTAMP" property="sendTime" />
+    <result column="create_by" jdbcType="VARCHAR" property="createBy" />
+    <result column="date_create" jdbcType="TIMESTAMP" property="dateCreate" />
+  </resultMap>
+  <sql id="Base_SQL_Field">
+    device_id,device_no,site_id,sys_id,building_id,floor,location,send_date,measuring_id,measuring_code,measuring_data,measuring_unit,
+    send_time,create_by,date_create
+  </sql>
+  <insert id="insert" parameterType="com.zcxk.zoniot.data.migrate.model.DeviceDataDim">
+    <!--@mbg.generated-->
+    insert into sc_device_data_dim (device_id, device_no, site_id, 
+      sys_id, building_id, `floor`, 
+      `location`, send_date, measuring_id, 
+      measuring_code, measuring_data, measuring_unit, 
+      send_time, create_by, date_create
+      )
+    values (#{deviceId,jdbcType=BIGINT}, #{deviceNo,jdbcType=VARCHAR}, #{siteId,jdbcType=INTEGER}, 
+      #{sysId,jdbcType=INTEGER}, #{buildingId,jdbcType=INTEGER}, #{floor,jdbcType=INTEGER}, 
+      #{location,jdbcType=VARCHAR}, #{sendDate,jdbcType=INTEGER}, #{measuringId,jdbcType=INTEGER}, 
+      #{measuringCode,jdbcType=VARCHAR}, #{measuringData,jdbcType=VARCHAR}, #{measuringUnit,jdbcType=VARCHAR}, 
+      #{sendTime,jdbcType=TIMESTAMP}, #{createBy,jdbcType=VARCHAR}, #{dateCreate,jdbcType=TIMESTAMP}
+      )
+  </insert>
+  <insert id="insertSelective" parameterType="com.zcxk.zoniot.data.migrate.model.DeviceDataDim">
+    <!--@mbg.generated-->
+    insert into sc_device_data_dim
+    <trim prefix="(" suffix=")" suffixOverrides=",">
+      <if test="deviceId != null">
+        device_id,
+      </if>
+      <if test="deviceNo != null">
+        device_no,
+      </if>
+      <if test="siteId != null">
+        site_id,
+      </if>
+      <if test="sysId != null">
+        sys_id,
+      </if>
+      <if test="buildingId != null">
+        building_id,
+      </if>
+      <if test="floor != null">
+        `floor`,
+      </if>
+      <if test="location != null">
+        `location`,
+      </if>
+      <if test="sendDate != null">
+        send_date,
+      </if>
+      <if test="measuringId != null">
+        measuring_id,
+      </if>
+      <if test="measuringCode != null">
+        measuring_code,
+      </if>
+      <if test="measuringData != null">
+        measuring_data,
+      </if>
+      <if test="measuringUnit != null">
+        measuring_unit,
+      </if>
+      <if test="sendTime != null">
+        send_time,
+      </if>
+      <if test="createBy != null">
+        create_by,
+      </if>
+      <if test="dateCreate != null">
+        date_create,
+      </if>
+    </trim>
+    <trim prefix="values (" suffix=")" suffixOverrides=",">
+      <if test="deviceId != null">
+        #{deviceId,jdbcType=BIGINT},
+      </if>
+      <if test="deviceNo != null">
+        #{deviceNo,jdbcType=VARCHAR},
+      </if>
+      <if test="siteId != null">
+        #{siteId,jdbcType=INTEGER},
+      </if>
+      <if test="sysId != null">
+        #{sysId,jdbcType=INTEGER},
+      </if>
+      <if test="buildingId != null">
+        #{buildingId,jdbcType=INTEGER},
+      </if>
+      <if test="floor != null">
+        #{floor,jdbcType=INTEGER},
+      </if>
+      <if test="location != null">
+        #{location,jdbcType=VARCHAR},
+      </if>
+      <if test="sendDate != null">
+        #{sendDate,jdbcType=INTEGER},
+      </if>
+      <if test="measuringId != null">
+        #{measuringId,jdbcType=INTEGER},
+      </if>
+      <if test="measuringCode != null">
+        #{measuringCode,jdbcType=VARCHAR},
+      </if>
+      <if test="measuringData != null">
+        #{measuringData,jdbcType=VARCHAR},
+      </if>
+      <if test="measuringUnit != null">
+        #{measuringUnit,jdbcType=VARCHAR},
+      </if>
+      <if test="sendTime != null">
+        #{sendTime,jdbcType=TIMESTAMP},
+      </if>
+      <if test="createBy != null">
+        #{createBy,jdbcType=VARCHAR},
+      </if>
+      <if test="dateCreate != null">
+        #{dateCreate,jdbcType=TIMESTAMP},
+      </if>
+    </trim>
+  </insert>
+  <select id="findDataList" resultMap="BaseResultMap">
+    select
+        <include refid="Base_SQL_Field" />
+    from
+        sc_device_data_dim
+    where
+        send_date = #{day,jdbcType=INTEGER}
+    and sys_id != 55
+  </select>
+  <select id="findDeviceDataList" resultMap="BaseResultMap">
+    select
+        <include refid="Base_SQL_Field" />
+    from
+        sc_device_data_dim
+    where device_id = #{deviceId,jdbcType=BIGINT}
+    and send_date >= #{beginDay,jdbcType=INTEGER}
+    and send_date <![CDATA[ <= ]]> #{endDay,jdbcType=INTEGER}
+  </select>
+</mapper>

+ 425 - 0
smart-city-data-migrate/src/main/resources/mapper/DeviceMapper.xml

@@ -0,0 +1,425 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.zcxk.zoniot.data.migrate.dao.DeviceMapper">
+  <resultMap id="BaseResultMap" type="com.zcxk.zoniot.data.migrate.model.Device">
+    <!--@mbg.generated-->
+    <!--@Table sc_device-->
+    <id column="id" jdbcType="BIGINT" property="id" />
+    <result column="device_no" jdbcType="VARCHAR" property="deviceNo" />
+    <result column="device_type" jdbcType="INTEGER" property="deviceType" />
+    <result column="site_id" jdbcType="INTEGER" property="siteId" />
+    <result column="sys_id" jdbcType="INTEGER" property="sysId" />
+    <result column="building_id" jdbcType="INTEGER" property="buildingId" />
+    <result column="building_unit" jdbcType="VARCHAR" property="buildingUnit" />
+    <result column="floor" jdbcType="INTEGER" property="floor" />
+    <result column="loc_desc" jdbcType="VARCHAR" property="locDesc" />
+    <result column="customer_id" jdbcType="INTEGER" property="customerId" />
+    <result column="related_device_no" jdbcType="BIGINT" property="relatedDeviceNo" />
+    <result column="water_meter_no" jdbcType="VARCHAR" property="waterMeterNo" />
+    <result column="water_meter_file_no" jdbcType="VARCHAR" property="waterMeterFileNo" />
+    <result column="manufacturer_id" jdbcType="INTEGER" property="manufacturerId" />
+    <result column="device_status" jdbcType="CHAR" property="deviceStatus" />
+    <result column="last_receive_time" jdbcType="TIMESTAMP" property="lastReceiveTime" />
+    <result column="status" jdbcType="BOOLEAN" property="status" />
+    <result column="is_tag" jdbcType="CHAR" property="isTag" />
+    <result column="x_coordinates" jdbcType="DECIMAL" property="xCoordinates" />
+    <result column="y_coordinates" jdbcType="DECIMAL" property="yCoordinates" />
+    <result column="plan_id" jdbcType="INTEGER" property="planId" />
+    <result column="udip_id" jdbcType="VARCHAR" property="udipId" />
+    <result column="create_by" jdbcType="VARCHAR" property="createBy" />
+    <result column="update_by" jdbcType="VARCHAR" property="updateBy" />
+    <result column="date_create" jdbcType="TIMESTAMP" property="dateCreate" />
+    <result column="date_update" jdbcType="TIMESTAMP" property="dateUpdate" />
+    <result column="metercode" jdbcType="VARCHAR" property="metercode" />
+    <result column="account_id" jdbcType="BIGINT" property="accountId" />
+  </resultMap>
+  <sql id="Base_Column_List">
+    <!--@mbg.generated-->
+    id, device_no, device_type, site_id, sys_id, building_id, building_unit, `floor`, 
+    loc_desc, customer_id, related_device_no, water_meter_no, water_meter_file_no, manufacturer_id, 
+    device_status, last_receive_time, `status`, is_tag, x_coordinates, y_coordinates, 
+    plan_id, udip_id, create_by, update_by, date_create, date_update, metercode, account_id
+  </sql>
+  <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
+    <!--@mbg.generated-->
+    select 
+    <include refid="Base_Column_List" />
+    from sc_device
+    where id = #{id,jdbcType=BIGINT}
+  </select>
+  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
+    <!--@mbg.generated-->
+    delete from sc_device
+    where id = #{id,jdbcType=BIGINT}
+  </delete>
+  <insert id="insert" parameterType="com.zcxk.zoniot.data.migrate.model.Device">
+    <!--@mbg.generated-->
+    insert into sc_device (id, device_no, device_type, 
+      site_id, sys_id, building_id, 
+      building_unit, `floor`, loc_desc, 
+      customer_id, related_device_no, water_meter_no, 
+      water_meter_file_no, manufacturer_id, device_status, 
+      last_receive_time, `status`, is_tag, 
+      x_coordinates, y_coordinates, plan_id, 
+      udip_id, create_by, update_by, 
+      date_create, date_update, metercode, 
+      account_id)
+    values (#{id,jdbcType=BIGINT}, #{deviceNo,jdbcType=VARCHAR}, #{deviceType,jdbcType=INTEGER}, 
+      #{siteId,jdbcType=INTEGER}, #{sysId,jdbcType=INTEGER}, #{buildingId,jdbcType=INTEGER}, 
+      #{buildingUnit,jdbcType=VARCHAR}, #{floor,jdbcType=INTEGER}, #{locDesc,jdbcType=VARCHAR}, 
+      #{customerId,jdbcType=INTEGER}, #{relatedDeviceNo,jdbcType=BIGINT}, #{waterMeterNo,jdbcType=VARCHAR}, 
+      #{waterMeterFileNo,jdbcType=VARCHAR}, #{manufacturerId,jdbcType=INTEGER}, #{deviceStatus,jdbcType=CHAR}, 
+      #{lastReceiveTime,jdbcType=TIMESTAMP}, #{status,jdbcType=BOOLEAN}, #{isTag,jdbcType=CHAR}, 
+      #{xCoordinates,jdbcType=DECIMAL}, #{yCoordinates,jdbcType=DECIMAL}, #{planId,jdbcType=INTEGER}, 
+      #{udipId,jdbcType=VARCHAR}, #{createBy,jdbcType=VARCHAR}, #{updateBy,jdbcType=VARCHAR}, 
+      #{dateCreate,jdbcType=TIMESTAMP}, #{dateUpdate,jdbcType=TIMESTAMP}, #{metercode,jdbcType=VARCHAR}, 
+      #{accountId,jdbcType=BIGINT})
+  </insert>
+  <insert id="insertSelective" parameterType="com.zcxk.zoniot.data.migrate.model.Device">
+    <!--@mbg.generated-->
+    insert into sc_device
+    <trim prefix="(" suffix=")" suffixOverrides=",">
+      <if test="id != null">
+        id,
+      </if>
+      <if test="deviceNo != null">
+        device_no,
+      </if>
+      <if test="deviceType != null">
+        device_type,
+      </if>
+      <if test="siteId != null">
+        site_id,
+      </if>
+      <if test="sysId != null">
+        sys_id,
+      </if>
+      <if test="buildingId != null">
+        building_id,
+      </if>
+      <if test="buildingUnit != null">
+        building_unit,
+      </if>
+      <if test="floor != null">
+        `floor`,
+      </if>
+      <if test="locDesc != null">
+        loc_desc,
+      </if>
+      <if test="customerId != null">
+        customer_id,
+      </if>
+      <if test="relatedDeviceNo != null">
+        related_device_no,
+      </if>
+      <if test="waterMeterNo != null">
+        water_meter_no,
+      </if>
+      <if test="waterMeterFileNo != null">
+        water_meter_file_no,
+      </if>
+      <if test="manufacturerId != null">
+        manufacturer_id,
+      </if>
+      <if test="deviceStatus != null">
+        device_status,
+      </if>
+      <if test="lastReceiveTime != null">
+        last_receive_time,
+      </if>
+      <if test="status != null">
+        `status`,
+      </if>
+      <if test="isTag != null">
+        is_tag,
+      </if>
+      <if test="xCoordinates != null">
+        x_coordinates,
+      </if>
+      <if test="yCoordinates != null">
+        y_coordinates,
+      </if>
+      <if test="planId != null">
+        plan_id,
+      </if>
+      <if test="udipId != null">
+        udip_id,
+      </if>
+      <if test="createBy != null">
+        create_by,
+      </if>
+      <if test="updateBy != null">
+        update_by,
+      </if>
+      <if test="dateCreate != null">
+        date_create,
+      </if>
+      <if test="dateUpdate != null">
+        date_update,
+      </if>
+      <if test="metercode != null">
+        metercode,
+      </if>
+      <if test="accountId != null">
+        account_id,
+      </if>
+    </trim>
+    <trim prefix="values (" suffix=")" suffixOverrides=",">
+      <if test="id != null">
+        #{id,jdbcType=BIGINT},
+      </if>
+      <if test="deviceNo != null">
+        #{deviceNo,jdbcType=VARCHAR},
+      </if>
+      <if test="deviceType != null">
+        #{deviceType,jdbcType=INTEGER},
+      </if>
+      <if test="siteId != null">
+        #{siteId,jdbcType=INTEGER},
+      </if>
+      <if test="sysId != null">
+        #{sysId,jdbcType=INTEGER},
+      </if>
+      <if test="buildingId != null">
+        #{buildingId,jdbcType=INTEGER},
+      </if>
+      <if test="buildingUnit != null">
+        #{buildingUnit,jdbcType=VARCHAR},
+      </if>
+      <if test="floor != null">
+        #{floor,jdbcType=INTEGER},
+      </if>
+      <if test="locDesc != null">
+        #{locDesc,jdbcType=VARCHAR},
+      </if>
+      <if test="customerId != null">
+        #{customerId,jdbcType=INTEGER},
+      </if>
+      <if test="relatedDeviceNo != null">
+        #{relatedDeviceNo,jdbcType=BIGINT},
+      </if>
+      <if test="waterMeterNo != null">
+        #{waterMeterNo,jdbcType=VARCHAR},
+      </if>
+      <if test="waterMeterFileNo != null">
+        #{waterMeterFileNo,jdbcType=VARCHAR},
+      </if>
+      <if test="manufacturerId != null">
+        #{manufacturerId,jdbcType=INTEGER},
+      </if>
+      <if test="deviceStatus != null">
+        #{deviceStatus,jdbcType=CHAR},
+      </if>
+      <if test="lastReceiveTime != null">
+        #{lastReceiveTime,jdbcType=TIMESTAMP},
+      </if>
+      <if test="status != null">
+        #{status,jdbcType=BOOLEAN},
+      </if>
+      <if test="isTag != null">
+        #{isTag,jdbcType=CHAR},
+      </if>
+      <if test="xCoordinates != null">
+        #{xCoordinates,jdbcType=DECIMAL},
+      </if>
+      <if test="yCoordinates != null">
+        #{yCoordinates,jdbcType=DECIMAL},
+      </if>
+      <if test="planId != null">
+        #{planId,jdbcType=INTEGER},
+      </if>
+      <if test="udipId != null">
+        #{udipId,jdbcType=VARCHAR},
+      </if>
+      <if test="createBy != null">
+        #{createBy,jdbcType=VARCHAR},
+      </if>
+      <if test="updateBy != null">
+        #{updateBy,jdbcType=VARCHAR},
+      </if>
+      <if test="dateCreate != null">
+        #{dateCreate,jdbcType=TIMESTAMP},
+      </if>
+      <if test="dateUpdate != null">
+        #{dateUpdate,jdbcType=TIMESTAMP},
+      </if>
+      <if test="metercode != null">
+        #{metercode,jdbcType=VARCHAR},
+      </if>
+      <if test="accountId != null">
+        #{accountId,jdbcType=BIGINT},
+      </if>
+    </trim>
+  </insert>
+  <update id="updateByPrimaryKeySelective" parameterType="com.zcxk.zoniot.data.migrate.model.Device">
+    <!--@mbg.generated-->
+    update sc_device
+    <set>
+      <if test="deviceNo != null">
+        device_no = #{deviceNo,jdbcType=VARCHAR},
+      </if>
+      <if test="deviceType != null">
+        device_type = #{deviceType,jdbcType=INTEGER},
+      </if>
+      <if test="siteId != null">
+        site_id = #{siteId,jdbcType=INTEGER},
+      </if>
+      <if test="sysId != null">
+        sys_id = #{sysId,jdbcType=INTEGER},
+      </if>
+      <if test="buildingId != null">
+        building_id = #{buildingId,jdbcType=INTEGER},
+      </if>
+      <if test="buildingUnit != null">
+        building_unit = #{buildingUnit,jdbcType=VARCHAR},
+      </if>
+      <if test="floor != null">
+        `floor` = #{floor,jdbcType=INTEGER},
+      </if>
+      <if test="locDesc != null">
+        loc_desc = #{locDesc,jdbcType=VARCHAR},
+      </if>
+      <if test="customerId != null">
+        customer_id = #{customerId,jdbcType=INTEGER},
+      </if>
+      <if test="relatedDeviceNo != null">
+        related_device_no = #{relatedDeviceNo,jdbcType=BIGINT},
+      </if>
+      <if test="waterMeterNo != null">
+        water_meter_no = #{waterMeterNo,jdbcType=VARCHAR},
+      </if>
+      <if test="waterMeterFileNo != null">
+        water_meter_file_no = #{waterMeterFileNo,jdbcType=VARCHAR},
+      </if>
+      <if test="manufacturerId != null">
+        manufacturer_id = #{manufacturerId,jdbcType=INTEGER},
+      </if>
+      <if test="deviceStatus != null">
+        device_status = #{deviceStatus,jdbcType=CHAR},
+      </if>
+      <if test="lastReceiveTime != null">
+        last_receive_time = #{lastReceiveTime,jdbcType=TIMESTAMP},
+      </if>
+      <if test="status != null">
+        `status` = #{status,jdbcType=BOOLEAN},
+      </if>
+      <if test="isTag != null">
+        is_tag = #{isTag,jdbcType=CHAR},
+      </if>
+      <if test="xCoordinates != null">
+        x_coordinates = #{xCoordinates,jdbcType=DECIMAL},
+      </if>
+      <if test="yCoordinates != null">
+        y_coordinates = #{yCoordinates,jdbcType=DECIMAL},
+      </if>
+      <if test="planId != null">
+        plan_id = #{planId,jdbcType=INTEGER},
+      </if>
+      <if test="udipId != null">
+        udip_id = #{udipId,jdbcType=VARCHAR},
+      </if>
+      <if test="createBy != null">
+        create_by = #{createBy,jdbcType=VARCHAR},
+      </if>
+      <if test="updateBy != null">
+        update_by = #{updateBy,jdbcType=VARCHAR},
+      </if>
+      <if test="dateCreate != null">
+        date_create = #{dateCreate,jdbcType=TIMESTAMP},
+      </if>
+      <if test="dateUpdate != null">
+        date_update = #{dateUpdate,jdbcType=TIMESTAMP},
+      </if>
+      <if test="metercode != null">
+        metercode = #{metercode,jdbcType=VARCHAR},
+      </if>
+      <if test="accountId != null">
+        account_id = #{accountId,jdbcType=BIGINT},
+      </if>
+    </set>
+    where id = #{id,jdbcType=BIGINT}
+  </update>
+  <update id="updateByPrimaryKey" parameterType="com.zcxk.zoniot.data.migrate.model.Device">
+    <!--@mbg.generated-->
+    update sc_device
+    set device_no = #{deviceNo,jdbcType=VARCHAR},
+      device_type = #{deviceType,jdbcType=INTEGER},
+      site_id = #{siteId,jdbcType=INTEGER},
+      sys_id = #{sysId,jdbcType=INTEGER},
+      building_id = #{buildingId,jdbcType=INTEGER},
+      building_unit = #{buildingUnit,jdbcType=VARCHAR},
+      `floor` = #{floor,jdbcType=INTEGER},
+      loc_desc = #{locDesc,jdbcType=VARCHAR},
+      customer_id = #{customerId,jdbcType=INTEGER},
+      related_device_no = #{relatedDeviceNo,jdbcType=BIGINT},
+      water_meter_no = #{waterMeterNo,jdbcType=VARCHAR},
+      water_meter_file_no = #{waterMeterFileNo,jdbcType=VARCHAR},
+      manufacturer_id = #{manufacturerId,jdbcType=INTEGER},
+      device_status = #{deviceStatus,jdbcType=CHAR},
+      last_receive_time = #{lastReceiveTime,jdbcType=TIMESTAMP},
+      `status` = #{status,jdbcType=BOOLEAN},
+      is_tag = #{isTag,jdbcType=CHAR},
+      x_coordinates = #{xCoordinates,jdbcType=DECIMAL},
+      y_coordinates = #{yCoordinates,jdbcType=DECIMAL},
+      plan_id = #{planId,jdbcType=INTEGER},
+      udip_id = #{udipId,jdbcType=VARCHAR},
+      create_by = #{createBy,jdbcType=VARCHAR},
+      update_by = #{updateBy,jdbcType=VARCHAR},
+      date_create = #{dateCreate,jdbcType=TIMESTAMP},
+      date_update = #{dateUpdate,jdbcType=TIMESTAMP},
+      metercode = #{metercode,jdbcType=VARCHAR},
+      account_id = #{accountId,jdbcType=BIGINT}
+    where id = #{id,jdbcType=BIGINT}
+  </update>
+  <select id="findByDeviceId" resultType="com.zcxk.zoniot.smartcity.common.dto.DeviceDTO">
+    SELECT
+      d.id,
+      d.sys_id as channel_id,
+      d.device_no ,
+      d.device_type as device_type_id,
+      d.site_id ,
+      d.`status`,
+      d.device_status,
+      d.building_id ,
+      b.`name` as building_name,
+      d.customer_id,
+      d.loc_desc,
+      d.x_coordinates,
+      d.y_coordinates,
+      t.manufacturer_id,
+      m.`name` as manufacturer_name,
+      t.equipment_type as device_type_name,
+      t.model as model,
+      c.id as community_id,
+      c.`name` as community_name,
+      pa.id as province_id,
+      pa.`name` as province_name,
+      ca.id as city_id ,
+      ca.`name` as city_name,
+      ra.id as region_id,
+      ra.`name` as region_name,
+      d.date_update,
+      d.date_create
+    FROM
+        sc_device d
+    left join sc_building b on (b.id = d.building_id)
+    left join sc_community c on (c.id = b.community)
+    left join sc_device_type t on (t.id = d.device_type)
+    left join sc_device_manufacturer m on (t.manufacturer_id = m.id)
+    left join sc_area pa on (pa.id = b.province)
+    left join sc_area ca on (ca.id = b.city)
+    left join sc_area ra on (ra.id = b.region)
+    WHERE d.id = #{deviceId,jdbcType=BIGINT}
+    limit 1
+  </select>
+  <select id="getDeviceIdList" resultType="java.lang.Long">
+    select
+        id
+    from
+        sc_device
+    where
+        status = 1
+    and device_type != 19
+    <!-- 光电直读表不在迁移范围内 -->
+  </select>
+</mapper>

+ 393 - 0
smart-city-data-migrate/src/main/resources/mapper/MeterReadRecordMapper.xml

@@ -0,0 +1,393 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.zcxk.zoniot.data.migrate.dao.MeterReadRecordMapper">
+  <resultMap id="BaseResultMap" type="com.zcxk.zoniot.data.migrate.model.MeterReadRecord">
+    <!--@mbg.generated-->
+    <!--@Table sc_meter_read_record-->
+    <id column="id" jdbcType="BIGINT" property="id" />
+    <result column="read_date" jdbcType="INTEGER" property="readDate" />
+    <result column="site_id" jdbcType="INTEGER" property="siteId" />
+    <result column="sys_id" jdbcType="INTEGER" property="sysId" />
+    <result column="province" jdbcType="INTEGER" property="province" />
+    <result column="city" jdbcType="INTEGER" property="city" />
+    <result column="region" jdbcType="INTEGER" property="region" />
+    <result column="community" jdbcType="INTEGER" property="community" />
+    <result column="customer_id" jdbcType="INTEGER" property="customerId" />
+    <result column="concentrator_id" jdbcType="INTEGER" property="concentratorId" />
+    <result column="collector_id" jdbcType="INTEGER" property="collectorId" />
+    <result column="building_id" jdbcType="INTEGER" property="buildingId" />
+    <result column="location" jdbcType="VARCHAR" property="location" />
+    <result column="device_type_id" jdbcType="INTEGER" property="deviceTypeId" />
+    <result column="device_id" jdbcType="BIGINT" property="deviceId" />
+    <result column="device_no" jdbcType="VARCHAR" property="deviceNo" />
+    <result column="meter_no" jdbcType="VARCHAR" property="meterNo" />
+    <result column="meter_file_no" jdbcType="VARCHAR" property="meterFileNo" />
+    <result column="read_time" jdbcType="TIMESTAMP" property="readTime" />
+    <result column="read_status" jdbcType="VARCHAR" property="readStatus" />
+    <result column="read_data" jdbcType="VARCHAR" property="readData" />
+    <result column="last_valid" jdbcType="VARCHAR" property="lastValid" />
+    <result column="last_cost" jdbcType="DECIMAL" property="lastCost" />
+    <result column="status" jdbcType="INTEGER" property="status" />
+    <result column="date_create" jdbcType="TIMESTAMP" property="dateCreate" />
+    <result column="date_update" jdbcType="TIMESTAMP" property="dateUpdate" />
+    <result column="create_by" jdbcType="VARCHAR" property="createBy" />
+    <result column="update_by" jdbcType="VARCHAR" property="updateBy" />
+  </resultMap>
+  <sql id="Base_Column_List">
+    <!--@mbg.generated-->
+    id, read_date, site_id, sys_id, province, city, region, community, customer_id, concentrator_id, 
+    collector_id, building_id, `location`, device_type_id, device_id, device_no, meter_no, 
+    meter_file_no, read_time, read_status, read_data, last_valid, last_cost, `status`, 
+    date_create, date_update, create_by, update_by
+  </sql>
+  <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
+    <!--@mbg.generated-->
+    select 
+    <include refid="Base_Column_List" />
+    from sc_meter_read_record
+    where id = #{id,jdbcType=BIGINT}
+  </select>
+  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
+    <!--@mbg.generated-->
+    delete from sc_meter_read_record
+    where id = #{id,jdbcType=BIGINT}
+  </delete>
+  <insert id="insert" parameterType="com.zcxk.zoniot.data.migrate.model.MeterReadRecord">
+    <!--@mbg.generated-->
+    insert into sc_meter_read_record (id, read_date, site_id, 
+      sys_id, province, city, 
+      region, community, customer_id, 
+      concentrator_id, collector_id, building_id, 
+      `location`, device_type_id, device_id, 
+      device_no, meter_no, meter_file_no, 
+      read_time, read_status, read_data, 
+      last_valid, last_cost, `status`, 
+      date_create, date_update, create_by, 
+      update_by)
+    values (#{id,jdbcType=BIGINT}, #{readDate,jdbcType=INTEGER}, #{siteId,jdbcType=INTEGER}, 
+      #{sysId,jdbcType=INTEGER}, #{province,jdbcType=INTEGER}, #{city,jdbcType=INTEGER}, 
+      #{region,jdbcType=INTEGER}, #{community,jdbcType=INTEGER}, #{customerId,jdbcType=INTEGER}, 
+      #{concentratorId,jdbcType=INTEGER}, #{collectorId,jdbcType=INTEGER}, #{buildingId,jdbcType=INTEGER}, 
+      #{location,jdbcType=VARCHAR}, #{deviceTypeId,jdbcType=INTEGER}, #{deviceId,jdbcType=BIGINT}, 
+      #{deviceNo,jdbcType=VARCHAR}, #{meterNo,jdbcType=VARCHAR}, #{meterFileNo,jdbcType=VARCHAR}, 
+      #{readTime,jdbcType=TIMESTAMP}, #{readStatus,jdbcType=VARCHAR}, #{readData,jdbcType=VARCHAR}, 
+      #{lastValid,jdbcType=VARCHAR}, #{lastCost,jdbcType=DECIMAL}, #{status,jdbcType=INTEGER}, 
+      #{dateCreate,jdbcType=TIMESTAMP}, #{dateUpdate,jdbcType=TIMESTAMP}, #{createBy,jdbcType=VARCHAR}, 
+      #{updateBy,jdbcType=VARCHAR})
+  </insert>
+  <insert id="insertSelective" parameterType="com.zcxk.zoniot.data.migrate.model.MeterReadRecord">
+    <!--@mbg.generated-->
+    insert into sc_meter_read_record
+    <trim prefix="(" suffix=")" suffixOverrides=",">
+      <if test="id != null">
+        id,
+      </if>
+      <if test="readDate != null">
+        read_date,
+      </if>
+      <if test="siteId != null">
+        site_id,
+      </if>
+      <if test="sysId != null">
+        sys_id,
+      </if>
+      <if test="province != null">
+        province,
+      </if>
+      <if test="city != null">
+        city,
+      </if>
+      <if test="region != null">
+        region,
+      </if>
+      <if test="community != null">
+        community,
+      </if>
+      <if test="customerId != null">
+        customer_id,
+      </if>
+      <if test="concentratorId != null">
+        concentrator_id,
+      </if>
+      <if test="collectorId != null">
+        collector_id,
+      </if>
+      <if test="buildingId != null">
+        building_id,
+      </if>
+      <if test="location != null">
+        `location`,
+      </if>
+      <if test="deviceTypeId != null">
+        device_type_id,
+      </if>
+      <if test="deviceId != null">
+        device_id,
+      </if>
+      <if test="deviceNo != null">
+        device_no,
+      </if>
+      <if test="meterNo != null">
+        meter_no,
+      </if>
+      <if test="meterFileNo != null">
+        meter_file_no,
+      </if>
+      <if test="readTime != null">
+        read_time,
+      </if>
+      <if test="readStatus != null">
+        read_status,
+      </if>
+      <if test="readData != null">
+        read_data,
+      </if>
+      <if test="lastValid != null">
+        last_valid,
+      </if>
+      <if test="lastCost != null">
+        last_cost,
+      </if>
+      <if test="status != null">
+        `status`,
+      </if>
+      <if test="dateCreate != null">
+        date_create,
+      </if>
+      <if test="dateUpdate != null">
+        date_update,
+      </if>
+      <if test="createBy != null">
+        create_by,
+      </if>
+      <if test="updateBy != null">
+        update_by,
+      </if>
+    </trim>
+    <trim prefix="values (" suffix=")" suffixOverrides=",">
+      <if test="id != null">
+        #{id,jdbcType=BIGINT},
+      </if>
+      <if test="readDate != null">
+        #{readDate,jdbcType=INTEGER},
+      </if>
+      <if test="siteId != null">
+        #{siteId,jdbcType=INTEGER},
+      </if>
+      <if test="sysId != null">
+        #{sysId,jdbcType=INTEGER},
+      </if>
+      <if test="province != null">
+        #{province,jdbcType=INTEGER},
+      </if>
+      <if test="city != null">
+        #{city,jdbcType=INTEGER},
+      </if>
+      <if test="region != null">
+        #{region,jdbcType=INTEGER},
+      </if>
+      <if test="community != null">
+        #{community,jdbcType=INTEGER},
+      </if>
+      <if test="customerId != null">
+        #{customerId,jdbcType=INTEGER},
+      </if>
+      <if test="concentratorId != null">
+        #{concentratorId,jdbcType=INTEGER},
+      </if>
+      <if test="collectorId != null">
+        #{collectorId,jdbcType=INTEGER},
+      </if>
+      <if test="buildingId != null">
+        #{buildingId,jdbcType=INTEGER},
+      </if>
+      <if test="location != null">
+        #{location,jdbcType=VARCHAR},
+      </if>
+      <if test="deviceTypeId != null">
+        #{deviceTypeId,jdbcType=INTEGER},
+      </if>
+      <if test="deviceId != null">
+        #{deviceId,jdbcType=BIGINT},
+      </if>
+      <if test="deviceNo != null">
+        #{deviceNo,jdbcType=VARCHAR},
+      </if>
+      <if test="meterNo != null">
+        #{meterNo,jdbcType=VARCHAR},
+      </if>
+      <if test="meterFileNo != null">
+        #{meterFileNo,jdbcType=VARCHAR},
+      </if>
+      <if test="readTime != null">
+        #{readTime,jdbcType=TIMESTAMP},
+      </if>
+      <if test="readStatus != null">
+        #{readStatus,jdbcType=VARCHAR},
+      </if>
+      <if test="readData != null">
+        #{readData,jdbcType=VARCHAR},
+      </if>
+      <if test="lastValid != null">
+        #{lastValid,jdbcType=VARCHAR},
+      </if>
+      <if test="lastCost != null">
+        #{lastCost,jdbcType=DECIMAL},
+      </if>
+      <if test="status != null">
+        #{status,jdbcType=INTEGER},
+      </if>
+      <if test="dateCreate != null">
+        #{dateCreate,jdbcType=TIMESTAMP},
+      </if>
+      <if test="dateUpdate != null">
+        #{dateUpdate,jdbcType=TIMESTAMP},
+      </if>
+      <if test="createBy != null">
+        #{createBy,jdbcType=VARCHAR},
+      </if>
+      <if test="updateBy != null">
+        #{updateBy,jdbcType=VARCHAR},
+      </if>
+    </trim>
+  </insert>
+  <update id="updateByPrimaryKeySelective" parameterType="com.zcxk.zoniot.data.migrate.model.MeterReadRecord">
+    <!--@mbg.generated-->
+    update sc_meter_read_record
+    <set>
+      <if test="readDate != null">
+        read_date = #{readDate,jdbcType=INTEGER},
+      </if>
+      <if test="siteId != null">
+        site_id = #{siteId,jdbcType=INTEGER},
+      </if>
+      <if test="sysId != null">
+        sys_id = #{sysId,jdbcType=INTEGER},
+      </if>
+      <if test="province != null">
+        province = #{province,jdbcType=INTEGER},
+      </if>
+      <if test="city != null">
+        city = #{city,jdbcType=INTEGER},
+      </if>
+      <if test="region != null">
+        region = #{region,jdbcType=INTEGER},
+      </if>
+      <if test="community != null">
+        community = #{community,jdbcType=INTEGER},
+      </if>
+      <if test="customerId != null">
+        customer_id = #{customerId,jdbcType=INTEGER},
+      </if>
+      <if test="concentratorId != null">
+        concentrator_id = #{concentratorId,jdbcType=INTEGER},
+      </if>
+      <if test="collectorId != null">
+        collector_id = #{collectorId,jdbcType=INTEGER},
+      </if>
+      <if test="buildingId != null">
+        building_id = #{buildingId,jdbcType=INTEGER},
+      </if>
+      <if test="location != null">
+        `location` = #{location,jdbcType=VARCHAR},
+      </if>
+      <if test="deviceTypeId != null">
+        device_type_id = #{deviceTypeId,jdbcType=INTEGER},
+      </if>
+      <if test="deviceId != null">
+        device_id = #{deviceId,jdbcType=BIGINT},
+      </if>
+      <if test="deviceNo != null">
+        device_no = #{deviceNo,jdbcType=VARCHAR},
+      </if>
+      <if test="meterNo != null">
+        meter_no = #{meterNo,jdbcType=VARCHAR},
+      </if>
+      <if test="meterFileNo != null">
+        meter_file_no = #{meterFileNo,jdbcType=VARCHAR},
+      </if>
+      <if test="readTime != null">
+        read_time = #{readTime,jdbcType=TIMESTAMP},
+      </if>
+      <if test="readStatus != null">
+        read_status = #{readStatus,jdbcType=VARCHAR},
+      </if>
+      <if test="readData != null">
+        read_data = #{readData,jdbcType=VARCHAR},
+      </if>
+      <if test="lastValid != null">
+        last_valid = #{lastValid,jdbcType=VARCHAR},
+      </if>
+      <if test="lastCost != null">
+        last_cost = #{lastCost,jdbcType=DECIMAL},
+      </if>
+      <if test="status != null">
+        `status` = #{status,jdbcType=INTEGER},
+      </if>
+      <if test="dateCreate != null">
+        date_create = #{dateCreate,jdbcType=TIMESTAMP},
+      </if>
+      <if test="dateUpdate != null">
+        date_update = #{dateUpdate,jdbcType=TIMESTAMP},
+      </if>
+      <if test="createBy != null">
+        create_by = #{createBy,jdbcType=VARCHAR},
+      </if>
+      <if test="updateBy != null">
+        update_by = #{updateBy,jdbcType=VARCHAR},
+      </if>
+    </set>
+    where id = #{id,jdbcType=BIGINT}
+  </update>
+  <update id="updateByPrimaryKey" parameterType="com.zcxk.zoniot.data.migrate.model.MeterReadRecord">
+    <!--@mbg.generated-->
+    update sc_meter_read_record
+    set read_date = #{readDate,jdbcType=INTEGER},
+      site_id = #{siteId,jdbcType=INTEGER},
+      sys_id = #{sysId,jdbcType=INTEGER},
+      province = #{province,jdbcType=INTEGER},
+      city = #{city,jdbcType=INTEGER},
+      region = #{region,jdbcType=INTEGER},
+      community = #{community,jdbcType=INTEGER},
+      customer_id = #{customerId,jdbcType=INTEGER},
+      concentrator_id = #{concentratorId,jdbcType=INTEGER},
+      collector_id = #{collectorId,jdbcType=INTEGER},
+      building_id = #{buildingId,jdbcType=INTEGER},
+      `location` = #{location,jdbcType=VARCHAR},
+      device_type_id = #{deviceTypeId,jdbcType=INTEGER},
+      device_id = #{deviceId,jdbcType=BIGINT},
+      device_no = #{deviceNo,jdbcType=VARCHAR},
+      meter_no = #{meterNo,jdbcType=VARCHAR},
+      meter_file_no = #{meterFileNo,jdbcType=VARCHAR},
+      read_time = #{readTime,jdbcType=TIMESTAMP},
+      read_status = #{readStatus,jdbcType=VARCHAR},
+      read_data = #{readData,jdbcType=VARCHAR},
+      last_valid = #{lastValid,jdbcType=VARCHAR},
+      last_cost = #{lastCost,jdbcType=DECIMAL},
+      `status` = #{status,jdbcType=INTEGER},
+      date_create = #{dateCreate,jdbcType=TIMESTAMP},
+      date_update = #{dateUpdate,jdbcType=TIMESTAMP},
+      create_by = #{createBy,jdbcType=VARCHAR},
+      update_by = #{updateBy,jdbcType=VARCHAR}
+    where id = #{id,jdbcType=BIGINT}
+  </update>
+  <select id="countRecordList" resultType="java.lang.Integer">
+    select
+        count(1)
+    from sc_meter_read_record
+    where
+    read_date = #{day,jdbcType=INTEGER}
+    and status = 1
+    and sys_id != 55
+  </select>
+  <select id="findRecordList" resultMap="BaseResultMap">
+    select
+        <include refid="Base_Column_List" />
+    from sc_meter_read_record
+    where
+     read_date = #{day,jdbcType=INTEGER}
+    and status = 1
+    and sys_id != 55
+    limit #{offset}, #{limit}
+  </select>
+</mapper>

+ 24 - 0
smart-city-data-migrate/src/test/java/com/zcxk/zoniot/data/migrate/SmartCityDataMigrateApplicationTests.java

@@ -0,0 +1,24 @@
+package com.zcxk.zoniot.data.migrate;
+
+import com.zcxk.zoniot.data.migrate.service.DataMigrateService;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes = SmartCityDataMigrateApplication.class)
+public class SmartCityDataMigrateApplicationTests {
+    @Autowired
+    DataMigrateService  dataMigrateService ;
+    @Test
+    public void contextLoads() {
+    }
+
+    @Test
+    public void migrateTest(){
+        dataMigrateService.migrate();
+    }
+
+}

+ 1 - 1
smart-city-dispatcher/src/main/resources/application-dev.properties

@@ -4,7 +4,7 @@ server.port=8071
 logging.level.root=info
 logging.path=c:/tmp
 #kafka配置
-spring.kafka.bootstrap-servers=193.112.139.7:9092
+spring.kafka.bootstrap-servers=114.135.61.188:36377
 #kafka生产者配置
 spring.kafka.producer.retries=0
 spring.kafka.producer.batch-size=4096

+ 2 - 1
smart-city-intf/src/main/java/com/zcxk/smartcity/data/access/kafka/consumer/SingleDataReceiver.java

@@ -1,6 +1,7 @@
 package com.zcxk.smartcity.data.access.kafka.consumer;
 
 import com.alibaba.fastjson.JSON;
+import com.mysql.cj.x.protobuf.MysqlxDatatypes;
 import com.zcxk.smartcity.data.access.common.http.HTTPException;
 import com.zcxk.smartcity.data.access.common.http.HTTPResponse;
 import com.zcxk.smartcity.data.access.dao.DeviceDataPushConfigMapper;
@@ -73,7 +74,7 @@ public class SingleDataReceiver {
 	DeviceDataService deviceDataService;
 
 	@Autowired
-	KafkaTemplate<String, Object> kafkaTemplate;
+	KafkaTemplate<MysqlxDatatypes.Scalar.String, Object> kafkaTemplate;
 
 	@Autowired
 	CustomerService customerService;

+ 4 - 4
smart-city-intf/src/main/java/com/zcxk/smartcity/data/access/util/HexUtil.java

@@ -6,8 +6,6 @@ import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
 
-import org.apache.commons.lang3.StringUtils;
-
 /**
  * 16进制工具类
  *
@@ -79,8 +77,9 @@ public class HexUtil {
      * @return
      */
     public static String hexString2binaryString(String hexString) {
-        if (hexString == null || hexString.length() % 2 != 0)
+        if (hexString == null || hexString.length() % 2 != 0){
             return null;
+        }
         String bString = "", tmp;
         for (int i = 0; i < hexString.length(); i++) {
             tmp = "0000" + Integer.toBinaryString(Integer.parseInt(hexString.substring(i, i + 1), 16));
@@ -96,8 +95,9 @@ public class HexUtil {
      * @return
      */
     public static String binaryString2hexString(String bString) {
-        if (bString == null || bString.equals("") || bString.length() % 8 != 0)
+        if (bString == null || bString.equals("") || bString.length() % 8 != 0){
             return null;
+        }
         StringBuffer tmp = new StringBuffer();
         int iTmp = 0;
         for (int i = 0; i < bString.length(); i += 4) {

+ 22 - 0
smart-city-platform/src/main/java/com/bz/smart_city/quartz/job/WaterMeterReadJobV2.java

@@ -17,6 +17,28 @@ import java.util.Date;
 /**
  * <p>新抄表定时任务</p>
  * 按表型进行抄表,不通表型抄表时间与测点字段均不相同,需要从任务的传参中获取
+ * {
+ *   "cronExpression": "0 0 2 * * ?",
+ *   "description": "NB188表抄表定时任务,每天2点执行",
+ *   "endDate": "2030-07-04 13:31:53",
+ *   "jobClassName": "com.bz.smart_city.quartz.job.WaterMeterReadJobV2",
+ *   "jobData": {"MeterTypeCode":"188NBWM","MeterWSVCode":"currentQuantity"},
+ *   "jobGroup": "system",
+ *   "jobName": "NB188表抄表定时任务",
+ *   "startDate": "2020-07-04 13:31:53"
+ * }
+ *
+ *
+ * {
+ *   "cronExpression": "0 0 2 * * ?",
+ *   "description": "NB天津v2协议表抄表定时任务,每天2点执行",
+ *   "endDate": "2030-07-04 13:31:53",
+ *   "jobClassName": "com.bz.smart_city.quartz.job.WaterMeterReadJobV2",
+ *   "jobData": {"MeterTypeCode":"TJv2NBWM","MeterWSVCode":"currentQuantity"},
+ *   "jobGroup": "system",
+ *   "jobName": "NB天津v2协议表定时任务",
+ *   "startDate": "2020-07-04 13:31:53"
+ * }
  * @Author wilian.peng
  * @Date 2020/6/1 20:33
  * @Version 1.0

+ 7 - 3
smart-city-platform/src/main/java/com/bz/smart_city/service/impl/MeterReadRecordServiceImpl.java

@@ -427,6 +427,7 @@ public class MeterReadRecordServiceImpl implements MeterReadRecordService{
 		statusList.add(4); // 预警
 		statusList.add(5); // 未启用
 		param.setDeviceStatusList(statusList);
+		param.setDeviceType(type.getDeviceTypeId());
 		int total = deviceMapper.countDevice(param);
 		
 		// 2,分页获取设备并生成抄表记录
@@ -959,6 +960,7 @@ public class MeterReadRecordServiceImpl implements MeterReadRecordService{
 		statusList.add(4); // 预警
 		statusList.add(5); // 未启用
 		param.setDeviceStatusList(statusList);
+		param.setDeviceType(type.getDeviceTypeId());
 		return param;
 	}
 	protected  void calcWsvIncrement(Date current , DeviceDto device , MeterReadRecord  record){
@@ -1018,10 +1020,11 @@ public class MeterReadRecordServiceImpl implements MeterReadRecordService{
 	 * 从缓存数据中生成抄表记录
 	 */
 	protected MeterReadRecord genrateMeterRecordFromCache(DeviceDto device, Integer startDate,Integer endDate , String wsvCode){
+		log.info("Generate Meter Record From Cache ,Device No = {}",device.getDeviceNo());
 		MeterReadRecord readRecord = null;
 		readRecord = buildRecordBaseInfo(device,startDate);
 		String deviceDataJSONStr = redisUtil.get(String.valueOf(device.getId()));
-
+		log.info(" Device {} Cache Data Log ,Data = {} ",device.getDeviceNo(),deviceDataJSONStr);
 		JSONObject dataObj = (JSONObject)JSON.parse(deviceDataJSONStr);
 		// 分别获取用水测点与上报时间测点
 		JSONObject timeData = (JSONObject)dataObj.get("TIME");
@@ -1045,6 +1048,7 @@ public class MeterReadRecordServiceImpl implements MeterReadRecordService{
 	 * 从数据库记录中生成抄表记录
 	 */
 	protected MeterReadRecord genrateMeterRecordFromDB(DeviceDto device,Integer startDate,Integer endDate,String wsvCode){
+		log.info("Generate Meter Record From DB ,Device No = {}",device.getDeviceNo());
 		MeterReadRecord readRecord = null;
 		readRecord = buildRecordBaseInfo(device,startDate);
 
@@ -1057,12 +1061,12 @@ public class MeterReadRecordServiceImpl implements MeterReadRecordService{
 		List<DeviceDataDim> data = deviceDataDimMapper.queryDeviceDataDim(p,1);
 
 		if(data.size() > 0) {
-			readRecord.setReadData("2"); // 已抄
+			readRecord.setReadStatus("2"); // 已抄
 			readRecord.setReadTime(data.get(0).getSendTime()); // 抄表时间
 			readRecord.setReadData(data.get(0).getMeasuringData());
 		}
 		else{
-			readRecord.setReadData("1"); // 未抄
+			readRecord.setReadStatus("1"); // 未抄
 		}
 		return readRecord ;
 	}