Browse Source

更改判断条件

hym 4 năm trước cách đây
mục cha
commit
a8383bcb2e
22 tập tin đã thay đổi với 1784 bổ sung39 xóa
  1. 136 0
      src/main/java/com/zoniot/ccrc/commom/Constants.java
  2. 9 0
      src/main/java/com/zoniot/ccrc/controller/GridManagementController.java
  3. 3 0
      src/main/java/com/zoniot/ccrc/dao/GridManagementMapper.java
  4. 53 0
      src/main/java/com/zoniot/ccrc/dao/MeterReadRecordMapper.java
  5. 112 0
      src/main/java/com/zoniot/ccrc/dao/MeterRecordMapper.java
  6. 2 0
      src/main/java/com/zoniot/ccrc/entity/Community.java
  7. 6 0
      src/main/java/com/zoniot/ccrc/entity/Device.java
  8. 33 0
      src/main/java/com/zoniot/ccrc/entity/MeasuringData.java
  9. 201 0
      src/main/java/com/zoniot/ccrc/entity/MeterReadRecord.java
  10. 34 0
      src/main/java/com/zoniot/ccrc/entity/MeterRecord.java
  11. 179 0
      src/main/java/com/zoniot/ccrc/entity/WaterMeter.java
  12. 339 0
      src/main/java/com/zoniot/ccrc/scheduled/SyncData.java
  13. 37 3
      src/main/java/com/zoniot/ccrc/scheduled/WarningMessageJob.java
  14. 1 1
      src/main/java/com/zoniot/ccrc/security/WebSecurityConfig.java
  15. 6 2
      src/main/java/com/zoniot/ccrc/service/impl/GridManagementServiceImpl.java
  16. 2 28
      src/main/java/com/zoniot/ccrc/service/impl/MongoMeterReadRecordServiceImpl.java
  17. 6 3
      src/main/java/com/zoniot/ccrc/service/impl/StatisticsServiceImpl.java
  18. 6 0
      src/main/resources/application-dev.properties
  19. 2 1
      src/main/resources/mapper/CommunityMapper.xml
  20. 8 1
      src/main/resources/mapper/GridManagementMapper.xml
  21. 433 0
      src/main/resources/mapper/MeterReadRecordMapper.xml
  22. 176 0
      src/main/resources/mapper/MeterRecordMapper.xml

+ 136 - 0
src/main/java/com/zoniot/ccrc/commom/Constants.java

@@ -0,0 +1,136 @@
+package com.zoniot.ccrc.commom;
+
+/**
+ * <p></p>
+ *
+ * @Author wilian.peng
+ * @Date 2020/12/22 21:14
+ * @Version 1.0
+ */
+public class Constants {
+
+    /**
+     * 系统标识符
+     */
+    public static final String SYS_FLAG = "system";
+
+    /**
+     * 设备标识符
+     */
+    public static final String DEVICE_FLAG = "deviceId";
+    /**
+     * 未抄状态
+     */
+    public static final String UN_READ = "1";
+
+    /**
+     * 已抄状态
+     */
+    public static final String READ = "2" ;
+
+    /**
+     * 水表最后数据缓存前缀
+     */
+    public static final String PREFIX_CACHE_FLAG = "LAST-METER-DATA:";
+
+    /**
+     * 测量点数值标记
+     */
+    public static final String TIME_FLAG = "TIME";
+
+    /**
+     * 批量提交批次
+     */
+    public static final Integer BATCH_SIZE = 1000 ;
+
+    /**
+     * 抄表日期参数
+     */
+    public static final String READ_DAY_PARAM_FLAG = "readDay";
+
+    /**
+     * 模式数据上报日期格式
+     */
+    public static final String DEFAULT_DATA_SEND_TIME_FORMAT = "yyyyMMddHHmmss";
+
+    /**
+     * 默认抄表日期格式
+     */
+    public static final String DEFAULT_METER_READ_DATE_FORMAT = "yyyyMMdd";
+
+    /**
+     * 远传表 表型
+     */
+    public static final Integer REMOTE_METER_TYPE = 1 ;
+
+    /**
+     * 智能表 表型
+     */
+    public static final Integer AI_METER_TYPE = 2 ;
+
+    /**
+     * 设备故障
+     */
+    public static final Integer DEVICE_ERROR = 2;
+
+    /**
+     * 设备报警
+     */
+    public static final Integer DEVICE_ALARM = 4;
+
+    /**
+     * 设备正常
+     */
+    public static final Integer DEVICE_NORMAL = 1 ;
+
+    /**
+     * 设备未启用
+     */
+    public static final Integer DEVICE_NOT_ENABLE = 5 ;
+
+    /**
+     * 设备注册状态,未注册
+     */
+    public static final Integer DEVICE_UN_REGIST = 0 ;
+
+    /**
+     * 设备注册状态,已注册
+     */
+    public static final Integer DEVICE_REGISTED = 1 ;
+
+    /**
+     * 文档编码
+     */
+    public static final String ENCODING_READ = "GBK";
+
+    /**
+     * 日志标识
+     */
+    public static final String LOG_TAG = ">>>>>>>>>>>>>>>>>";
+    /**
+     * 逗号标识
+     */
+    public static final String LOG_STR_COMMA = ",";
+
+    /**
+     * 返回值字符串resultStr
+     */
+    public static final String STR_RETURN_RESULT = "resultStr";
+    /**
+     * 返回值字符串exitStatus
+     */
+    public static final String STR_RETURN_EXITSTATUS = "exitStatus";
+
+    /**
+     * 处理失败 0 ,处理成功 1
+     */
+    public static final Integer PROCESS_STATE_FAILED = 0 ;
+
+    public static final Integer PROCESS_STATE_SUCCESS = 1 ;
+
+    public static final String FILE_PATH_TAG = "FilePath";
+
+    public static final String FILE_NAME_TAG = "FileName" ;
+
+    public static final String FILE_FULL_PATH_TAG = "FileFullPath" ;
+}

+ 9 - 0
src/main/java/com/zoniot/ccrc/controller/GridManagementController.java

@@ -10,6 +10,7 @@ import com.zoniot.ccrc.entity.Building;
 import com.zoniot.ccrc.entity.Community;
 import com.zoniot.ccrc.entity.Device;
 import com.zoniot.ccrc.entity.GridManagement;
+import com.zoniot.ccrc.scheduled.SyncData;
 import com.zoniot.ccrc.service.GridManagementService;
 import com.zoniot.ccrc.dto.GridUser;
 import io.swagger.annotations.Api;
@@ -38,6 +39,8 @@ public class GridManagementController {
      */
     @Autowired
     private GridManagementService gridManagementService;
+    @Autowired
+    private SyncData syncData;
 
 
 
@@ -171,5 +174,11 @@ public class GridManagementController {
 
         return new AjaxMessage<>(ResultStatus.OK);
     }
+    @RequestMapping(value = "test", method = RequestMethod.POST)
+    @ApiOperation(value = "test")
+    public void test(Integer id) {
+
+       syncData.synchronousData();
+    }
 
 }

+ 3 - 0
src/main/java/com/zoniot/ccrc/dao/GridManagementMapper.java

@@ -98,4 +98,7 @@ public interface GridManagementMapper {
     List<GridManagement> getByDeviceId(@Param("deviceId") Long deviceId);
 
     void deleteWarningRule(@Param("id") Integer id);
+
+    List<Device> getDeviceInfo(@Param("ids") List<Long> deviceIds);
+
 }

+ 53 - 0
src/main/java/com/zoniot/ccrc/dao/MeterReadRecordMapper.java

@@ -0,0 +1,53 @@
+package com.zoniot.ccrc.dao;
+
+
+import com.zoniot.ccrc.dto.UseWaterDto;
+import com.zoniot.ccrc.entity.MeterReadRecord;
+import com.zoniot.ccrc.repository.MongoMeterReadRecord;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/**
+ * <p></p>
+ * @Author wilian.peng
+ * @Date 2020/12/22 16:59
+ * @Version 1.0
+ */
+@Mapper
+public interface MeterReadRecordMapper {
+    int deleteByPrimaryKey(Long id);
+
+    int insert(MeterReadRecord record);
+
+    int insertSelective(MeterReadRecord record);
+
+    MeterReadRecord selectByPrimaryKey(Long id);
+
+    MeterReadRecord findRecordByReadDayAndDeviceId(@Param("deviceId") Long deviceId, @Param("readDate") Integer readDate);
+
+    int deleteRecordByReadDayAndDeviceId(@Param("deviceId") Long deviceId, @Param("readDate") Integer readDate);
+
+    int updateByPrimaryKeySelective(MeterReadRecord record);
+
+    int updateByPrimaryKey(MeterReadRecord record);
+
+    int batchInsert(@Param("list") List<MeterReadRecord> list);
+
+    List<UseWaterDto> getRealTimeUseWater(@Param("deviceId")Long deviceId,
+                                          @Param("startDate")Integer startDate,
+                                          @Param("endDate") Integer endDate);
+
+    List<UseWaterDto> getUseWaterByMonth(@Param("deviceId")Long deviceId,
+                                         @Param("startDate")Integer startDate,
+                                         @Param("endDate")Integer endDate);
+
+    Double getDeviceVolume(@Param("deviceId")Long deviceId,
+                           @Param("startDate")Integer startDate,
+                           @Param("endDate")Integer endDate);
+
+    List<MongoMeterReadRecord> getYesterReadData(
+            @Param("deviceId")Long deviceId,
+            @Param("date")Integer date);
+}

+ 112 - 0
src/main/java/com/zoniot/ccrc/dao/MeterRecordMapper.java

@@ -0,0 +1,112 @@
+package com.zoniot.ccrc.dao;
+
+
+import com.zoniot.ccrc.entity.Community;
+import com.zoniot.ccrc.entity.MeterReadRecord;
+import com.zoniot.ccrc.entity.MeterRecord;
+import com.zoniot.ccrc.entity.WaterMeter;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/**
+ * (MeterRecord)表数据库访问层
+ *
+ * @author hym
+ * @since 2021-05-21 15:08:37
+ */
+@Mapper
+public interface MeterRecordMapper {
+
+    /**
+     * 通过ID查询单条数据
+     *
+     * @param id 主键
+     * @return 实例对象
+     */
+    MeterRecord selectById(Integer id);
+
+
+    /**
+     * 查询全部
+     *
+     * @return 对象列表
+     */
+    List<MeterRecord> selectAll();
+
+    /**
+     * 通过实体作为筛选条件查询
+     *
+     * @param meterRecord 实例对象
+     * @return 对象列表
+     */
+    List<MeterRecord> selectList(MeterRecord meterRecord);
+
+    /**
+     * 新增数据
+     *
+     * @param meterRecord 实例对象
+     * @return 影响行数
+     */
+    int insert(MeterRecord meterRecord);
+
+    /**
+     * 批量新增
+     *
+     * @param meterRecords 实例对象的集合
+     * @return 影响行数
+     */
+    int batchInsert(@Param("meterRecords") List<MeterRecord> meterRecords);
+
+    /**
+     * 修改数据
+     *
+     * @param meterRecord 实例对象
+     * @return 影响行数
+     */
+    int update(MeterRecord meterRecord);
+
+    /**
+     * 通过主键删除数据
+     *
+     * @param id 主键
+     * @return 影响行数
+     */
+    int deleteById(Integer id);
+
+    /**
+     * 查询总数据数
+     *
+     * @return 数据总数
+     */
+    int count();
+
+
+
+    MeterRecord get(String registNo);
+
+    void syncDevice(@Param("siteId")String siteId, @Param("deviceId")long deviceId);
+
+    void deleteDevice();
+
+
+    void syncCell(@Param("siteId")String siteId,
+                  @Param("provinceId") String provinceId,
+                  @Param("cityId") String cityId,
+                  @Param("regionId")String regionId);
+
+    void deleteCell();
+
+    List<Community> getCommunityIds();
+
+    List<WaterMeter> findWaterMeterListWithPage(@Param("offset") int offset
+            ,@Param("size") int size);
+
+    void updateReadData(MeterReadRecord meterReadRecord);
+
+    void updateDeviceStatus();
+
+
+
+}

+ 2 - 0
src/main/java/com/zoniot/ccrc/entity/Community.java

@@ -66,4 +66,6 @@ public class Community implements Serializable {
     private String updateBy;
 
     private Integer orgId;
+    private Integer syncFlag;
+
 }

+ 6 - 0
src/main/java/com/zoniot/ccrc/entity/Device.java

@@ -76,4 +76,10 @@ public class Device {
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     @ApiModelProperty(value="更新时间")
     private Date dateUpdate;
+    @ApiModelProperty(value="客户编号")
+    private String clientUserNo;
+    @ApiModelProperty(value="客户名称")
+    private String clientUserName;
+    @ApiModelProperty(value="客户手机号")
+    private String clientUserMobile;
 }

+ 33 - 0
src/main/java/com/zoniot/ccrc/entity/MeasuringData.java

@@ -0,0 +1,33 @@
+package com.zoniot.ccrc.entity;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * <p></p>
+ *
+ * @Author wilian.peng
+ * @Date 2020/12/22 18:12
+ * @Version 1.0
+ */
+@Data
+public class MeasuringData implements Serializable {
+    /**
+     * 测点代码
+     */
+    String measuringCode ;
+    /**
+     * 测点值
+     */
+    String measuringVaule;
+    /**
+     * 测点名称
+     */
+    String measuringName ;
+    /**
+     * 测点单位
+     */
+    String measuringUnit ;
+
+}

+ 201 - 0
src/main/java/com/zoniot/ccrc/entity/MeterReadRecord.java

@@ -0,0 +1,201 @@
+package com.zoniot.ccrc.entity;
+
+import lombok.Data;
+import org.springframework.data.mongodb.core.mapping.Document;
+
+import java.io.Serializable;
+import java.util.Date;
+import java.util.Map;
+
+/**
+ * <p>抄表记录</p>
+ * sh.enableSharding("meter-reading-database");
+ * sh.shardCollection("meter-reading-database.sc_meter_read_record",{"readDate":1,"deviceId":1});
+ * db.sc_meter_read_record.createIndex({readDate:1,customerId:1,buildingId:1,siteId:1,sysId:1,readStatus:1,concentratorId:1},{background: true,name:'idx_1'})
+ * @Author wilian.peng
+ * @Date 2020/12/22 16:59
+ * @Version 1.0
+ */
+@Data
+@Document(collection = "sc_meter_read_record")
+public class MeterReadRecord implements Serializable {
+    /**
+    * 主键
+    */
+    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 String readStatus;
+
+    /**
+    * 读表数据
+    */
+    private String readData;
+
+    /**
+     * 阀门状态
+     * 0:关 1:开 2:无阀 3:异常
+     */
+    private Integer valveState ;
+
+    /**
+    * 最近有效数据
+    */
+    private String lastValid;
+
+    /**
+    * 距离上次的消耗
+    */
+    private Double lastCost;
+
+    /**
+    * 状态
+    */
+    private Integer status;
+
+    /**
+    * 创建时间
+    */
+    private Date dateCreate;
+
+    /**
+    * 更新时间
+    */
+    private Date dateUpdate;
+
+    /**
+    * 创建人
+    */
+    private String createBy;
+
+    /**
+    * 更新人
+    */
+    private String updateBy;
+
+    /***********************************以下字段将存入MongoDB中**************************************/
+    private String communityName;
+
+    private String buildingName ;
+
+    private String customerName ;
+
+    private String provinceName ;
+
+    private String cityName ;
+
+    private String regionName ;
+
+    private String deviceTypeName ;
+
+    private String concentratorNo ;
+
+    private String collectorNo ;
+
+    private Integer manufacturerId ;
+
+    private String manufacturerName ;
+
+    private Integer channelNumberId;
+
+    private String channelName ;
+    private String meterStatusInfo;
+
+    /**
+     * 最后上送数据,格式如下:
+     * {"数据ID":11111,data:{"WSV":"1","VOL":"2.5"}}
+     */
+    private Map<String, String> lastSendData ;
+}

+ 34 - 0
src/main/java/com/zoniot/ccrc/entity/MeterRecord.java

@@ -0,0 +1,34 @@
+package com.zoniot.ccrc.entity;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * (MeterRecord)实体类
+ *
+ * @author hym
+ * @since 2021-05-21 15:08:37
+ */
+@Data
+@ApiModel
+public class MeterRecord implements Serializable {
+    private static final long serialVersionUID = 212007639963190616L;
+    @ApiModelProperty(value = "")
+    private Integer id;
+    @ApiModelProperty(value = "")
+    private String registNo;
+    @ApiModelProperty(value = "")
+    private Double meterReading;
+    @ApiModelProperty(value = "")
+    private Date readingTime;
+    @ApiModelProperty(value = "")
+    private Integer valveStatus;
+    @ApiModelProperty(value = "")
+    private Integer meterStatus;
+    @ApiModelProperty(value = "")
+    private String meterStatusInfo;
+}

+ 179 - 0
src/main/java/com/zoniot/ccrc/entity/WaterMeter.java

@@ -0,0 +1,179 @@
+package com.zoniot.ccrc.entity;
+
+import lombok.Data;
+
+import java.util.Date;
+
+/**
+ * <p>水表</p>
+ *
+ * @Author wilian.peng
+ * @Date 2020/12/22 17:06
+ * @Version 1.0
+ */
+@Data
+public class WaterMeter {
+
+    /**
+     * 设备id
+     */
+    private Long deviceId;
+
+    /**
+     * 水表类型,1:物联网表,2:远传表
+     */
+    private Integer waterMeterType ;
+
+    /**
+     * 站点
+     */
+    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;
+
+    /**
+     * 是否支持阀控,0:不支持,1:支持
+     */
+    private Integer isValve;
+
+    /**
+     * 阀门测点
+     */
+    private String valveMeasuringCode;
+
+
+    /**
+     * 止度测点
+     */
+    private String readingMeasuringCode;
+
+    /**
+     * 节点编号
+     */
+    private String deviceNo;
+
+    /**
+     * 电子号
+     */
+    private String meterNo;
+
+    /**
+     * 档案号
+     */
+    private String meterFileNo;
+
+    /**
+     * 状态
+     */
+    private Integer status;
+
+    /**
+     * 创建时间
+     */
+    private Date dateCreate;
+
+    /**
+     * 更新时间
+     */
+    private Date dateUpdate;
+
+    /**
+     * 创建人
+     */
+    private String createBy;
+
+    /**
+     * 更新人
+     */
+    private String updateBy;
+
+    /**
+     * 设备状态
+     */
+    private Integer deviceStatus ;
+
+    /**
+     * 注册状态
+     */
+    private Integer registerStatus ;
+    /***********************************以下字段将存入MongoDB中**************************************/
+    private String communityName;
+
+    private String buildingName ;
+
+    private String customerName ;
+
+    private String provinceName ;
+
+    private String cityName ;
+
+    private String regionName ;
+
+    private String deviceTypeName ;
+
+    private String concentratorNo ;
+
+    private String collectorNo ;
+
+    private Integer manufacturerId ;
+
+    private String manufacturerName ;
+
+    private Integer channelNumberId;
+
+    private String channelName ;
+    private String registNo;
+}

+ 339 - 0
src/main/java/com/zoniot/ccrc/scheduled/SyncData.java

@@ -0,0 +1,339 @@
+package com.zoniot.ccrc.scheduled;
+
+import cn.hutool.core.date.DateField;
+import cn.hutool.core.date.DateTime;
+import cn.hutool.core.date.DateUtil;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.alibaba.fastjson.TypeReference;
+import com.zoniot.ccrc.commom.Constants;
+import com.zoniot.ccrc.commom.utils.HttpRequest;
+import com.zoniot.ccrc.commom.utils.RedisUtil;
+import com.zoniot.ccrc.commom.utils.SnowflakeIdWorker;
+import com.zoniot.ccrc.dao.CommunityMapper;
+import com.zoniot.ccrc.dao.MeterReadRecordMapper;
+import com.zoniot.ccrc.dao.MeterRecordMapper;
+import com.zoniot.ccrc.dto.CommunityDto;
+import com.zoniot.ccrc.entity.*;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.text.SimpleDateFormat;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+@Slf4j
+@Service
+public class SyncData {
+    @Resource
+    SnowflakeIdWorker snowflakeIdWorker ;
+    @Resource
+    MeterReadRecordMapper meterReadRecordMapper;
+    @Resource
+    MeterRecordMapper meterRecordMapper;
+    @Autowired
+    RedisUtil redisUtil;
+    @Value("${site_id}")
+    private String siteId;
+    @Value("${province_id}")
+    private String provinceId;
+    @Value("${city_id}")
+    private String cityId;
+    @Value("${region_id}")
+    private String regionId;
+    @Value("${geomap.apikey}")
+    private String apikey;
+
+    @Value("${geomap.api.url}")
+    private String apiUrl;
+    @Resource
+    private CommunityMapper communityMapper;
+
+    public void synchronousData(){
+       syncCell();
+        log.info("同步小区完毕");
+        syncDevice();
+        log.info("同步设备完毕");
+        syncReading();
+        log.info("同步设备读数完毕");
+       // synchronizeLatitudeAndLongitude();
+        log.info("小区地理反编码完毕");
+    }
+    private void syncDevice(){
+
+        meterRecordMapper.syncDevice(siteId,snowflakeIdWorker.nextId());
+        //meterRecordMapper.deleteDevice();
+    }
+    private void syncCell(){
+        meterRecordMapper.syncCell(siteId,provinceId,cityId,regionId);
+    }
+    private void syncReading(){
+        int size=1000;
+        int offset=0;
+        SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyyMMdd");
+        int readDay=Integer.parseInt(simpleDateFormat.format(new Date()));
+        while(true){
+            List<WaterMeter> waterMeterList =meterRecordMapper.
+                    findWaterMeterListWithPage(offset, size);
+            if(waterMeterList.isEmpty()){
+                break;
+            }
+            offset=offset+size;
+            generateReadingRecords(waterMeterList,readDay);
+        }
+        meterRecordMapper.updateDeviceStatus();
+
+
+    }
+    private String[] getInfoFromGaode(String name,String city){
+        String request = apiUrl+"?key="+apikey+"&address="+name+"&city="+city;
+        String[] tts=null;;
+        try {
+            String  jsonContent = HttpRequest.doGet(request);
+            JSONObject parse = (JSONObject)JSON.parse(jsonContent);
+            Integer count = Integer.parseInt((String)parse.get("count"));
+            if(count != 0) {
+                JSONObject geocodes=parse.getJSONArray("geocodes").getJSONObject(0);
+                String rtnContent =geocodes.get("location").toString();
+                if(StringUtils.isNotBlank(rtnContent)) {
+                     tts=new String[3];
+                     String []latitudeAndLongitude= rtnContent.split(",");
+                     tts[0] =latitudeAndLongitude[0];
+                     tts[1] =latitudeAndLongitude[1];
+                     tts[2] =geocodes.getString("formatted_address");
+
+                }
+            }
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+      return tts;
+    }
+    private void synchronizeLatitudeAndLongitude(){
+      //  meterRecordMapper.deleteCell();
+        List<Community>communitys=meterRecordMapper.getCommunityIds();
+        communitys.forEach(community -> {
+            String[] infoFromGaode = getInfoFromGaode(community.getName(),community.getAddress());
+            Community updateCommunity=new Community();
+            updateCommunity.setId(community.getId());
+            if(infoFromGaode!=null){
+
+                updateCommunity.setAddress(infoFromGaode[2]);
+                updateCommunity.setLongitude(Double.parseDouble(infoFromGaode[0]));
+                updateCommunity.setLatitude(Double.parseDouble(infoFromGaode[1]));
+
+            }
+            updateCommunity.setSyncFlag(1);
+            communityMapper.updateByPrimaryKeySelective(updateCommunity);
+        });
+
+
+    }
+    public void generateReadingRecords(List<WaterMeter> waterMeterList,
+                                                  Integer readDay){
+        log.info("begin batch create meter record , data size = {},readDay={}",waterMeterList.size(),readDay);
+        int i = 0 ;
+        if(compareMeterReadDay(readDay) < 0 ){
+            log.warn("Not Support Passed ReadDay = {}",readDay);
+        }
+        else{
+            List<MeterReadRecord> meterReadRecordList = new ArrayList<>();
+
+            for (WaterMeter waterMeter : waterMeterList){
+                MeterReadRecord meterReadRecord = buildUnReadRecord(waterMeter, readDay);
+                if(meterReadRecord != null){
+                    meterReadRecordList.add(meterReadRecord);
+                    updateReadData(waterMeter);
+
+                }
+                if (meterReadRecordList.size() == Constants.BATCH_SIZE){
+                    // 按批次提交
+                    int insert = meterReadRecordMapper.batchInsert(meterReadRecordList);
+                    i = i+insert ;
+                    meterReadRecordList.clear();
+                }
+            }
+            if(meterReadRecordList.size() != 0){
+                int insert = meterReadRecordMapper.batchInsert(meterReadRecordList);
+                i = i+insert ;
+                meterReadRecordList.clear();
+            }
+
+        }
+        log.info("end batch create meter record , readDay={} ,result size = {}",readDay,i);
+
+    }
+    public void updateReadData(WaterMeter waterMeter){
+        if(waterMeter.getDeviceTypeId()==1){
+            MeterReadRecord meterReadRecord=new MeterReadRecord();
+            setMeterRead(waterMeter.getRegistNo(),meterReadRecord);
+            DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyyMMdd");
+            LocalDateTime endDateTime = LocalDateTime.now().plusDays(-1);
+            Integer readDay = Integer.valueOf(endDateTime.format(df));
+            meterReadRecord.setReadDate(readDay);
+            meterRecordMapper.updateReadData(meterReadRecord);
+
+        }
+    }
+    /**
+     * 将抄表日期与当期日期进行比较
+     * 若抄表日期大于当前日期返回值>0
+     * 若抄表日期等于当前日期返回值=0
+     * 若抄表日期早于当前日期返回值<0
+     * @param readDay
+     * @return
+     */
+    protected int compareMeterReadDay(int readDay){
+        Integer today = Integer.parseInt(DateUtil.format(DateUtil.date(), Constants.DEFAULT_METER_READ_DATE_FORMAT));
+        return readDay-today;
+    }
+    /**
+     * 构造未抄记录
+     * @param waterMeter
+     * @param readDay
+     * @return
+     */
+    protected MeterReadRecord buildUnReadRecord(WaterMeter waterMeter , Integer readDay){
+
+        MeterReadRecord meterReadRecord = new MeterReadRecord() ;
+        Integer type=waterMeter.getDeviceTypeId();
+        meterReadRecord.setSiteId(waterMeter.getSiteId());
+        meterReadRecord.setSysId(waterMeter.getSysId());
+        meterReadRecord.setCommunity(waterMeter.getCommunity());
+        meterReadRecord.setMeterFileNo(waterMeter.getMeterFileNo());
+        meterReadRecord.setMeterNo(waterMeter.getMeterNo());
+        meterReadRecord.setDateCreate(new Date());
+        meterReadRecord.setDeviceId(waterMeter.getDeviceId());
+        meterReadRecord.setDeviceNo(waterMeter.getDeviceNo());
+        meterReadRecord.setDeviceTypeId(waterMeter.getDeviceTypeId());
+        meterReadRecord.setId(snowflakeIdWorker.nextId());
+        meterReadRecord.setLastCost(new Double(0));
+        meterReadRecord.setLocation(waterMeter.getLocation());
+        meterReadRecord.setCreateBy(Constants.SYS_FLAG);
+        meterReadRecord.setStatus(1);
+        meterReadRecord.setReadDate(readDay);
+        meterReadRecord.setCity(Integer.parseInt(cityId));
+        meterReadRecord.setReadStatus(Constants.UN_READ);
+        meterReadRecord.setRegion(Integer.parseInt(regionId));
+        meterReadRecord.setProvince(Integer.parseInt(provinceId));
+        meterReadRecord.setLastValid(getMeterLastValid(waterMeter,readDay));
+        if(type==2){
+            setMeterRead(waterMeter.getRegistNo(),meterReadRecord);
+            meterReadRecord.setReadStatus(Constants.READ);
+        }
+
+        return meterReadRecord ;
+    }
+    private void setMeterRead(String registNo,MeterReadRecord meterReadRecord){
+        MeterRecord meterRecord = meterRecordMapper.get(registNo);
+        if(meterRecord!=null){
+            String reading=meterRecord.getMeterReading()+"";
+            meterReadRecord.setLastValid(reading);
+            meterReadRecord.setReadTime(meterRecord.getReadingTime());
+            meterReadRecord.setReadData(reading);
+            Double todayCost = new BigDecimal(calculateTodayCost(reading,
+                    new Double(meterReadRecord.getLastValid()),
+                    meterReadRecord)).setScale(3,BigDecimal.ROUND_HALF_UP).doubleValue();
+            meterReadRecord.setLastCost(todayCost);
+            meterReadRecord.setValveState(meterRecord.getValveStatus());
+            meterReadRecord.setMeterStatusInfo(meterRecord.getMeterStatusInfo());
+            meterReadRecord.setReadStatus(meterRecord.getMeterStatus()+"");
+            setMeterLastDataToCache(meterReadRecord.getDeviceId(),reading);
+        }
+
+    }
+    protected  Double calculateTodayCost(String currentReading,Double lastValid,MeterReadRecord record){
+
+
+        Double currentValid = new Double(currentReading);
+        Double  cost = currentValid-lastValid;
+        return cost ;
+    }
+    /**
+     * 获取水表最后止度,先从缓存中获取止度,缓存无数据则从数据库中获取
+     * @param waterMeter
+     * @param readDate
+     * @return
+     */
+    protected String getMeterLastValid(WaterMeter waterMeter,Integer readDate){
+        String lastValid = "0" ;
+        String lastValidFromCache = getMeterLastValidFromCache(waterMeter);
+        if(StringUtils.isBlank(lastValidFromCache)){
+            String lastValidFromDB = getMeterLastValidFromDB(waterMeter, readDate);
+            if(StringUtils.isNotBlank(lastValidFromDB)){
+                lastValid = lastValidFromDB;
+            }
+        }
+        else{
+            lastValid = lastValidFromCache ;
+        }
+        return lastValid;
+    }
+    /**
+     * 从数据库中获取最后止度,默认为前一天的抄表最后止度
+     * @param waterMeter
+     * @param readDate
+     * @return
+     */
+    protected String getMeterLastValidFromDB(WaterMeter waterMeter,Integer readDate){
+        // 默认水表止度
+        String lastValid = "" ;
+        // 计算输入日期的前一日
+        DateTime inputDate = DateUtil.parse(String.valueOf(readDate), Constants.DEFAULT_METER_READ_DATE_FORMAT);
+        DateTime previousDate = DateUtil.offset(inputDate, DateField.DAY_OF_MONTH, -1);
+        int previousDay = Integer.parseInt(DateUtil.format(previousDate.toJdkDate(), Constants.DEFAULT_METER_READ_DATE_FORMAT));
+        // 查询前一日抄表记录
+        MeterReadRecord  previousRecord= findRecordByMeterIdAndReadDate(waterMeter, previousDay);
+        if(previousRecord != null){
+            lastValid = previousRecord.getLastValid();
+        }
+        return lastValid ;
+    }
+    /**
+     * 从缓存中获取水表的最后止度
+     * @param waterMeter
+     * @return
+     */
+    protected String getMeterLastValidFromCache(WaterMeter waterMeter){
+        // 默认水表止度
+        String lastValid = "" ;
+        String meterLastData = getMeterLastDataFromCache(waterMeter.getDeviceId());
+        if(StringUtils.isNotBlank(meterLastData)){
+           lastValid=meterLastData;
+        }
+        return lastValid ;
+    }
+    /**
+     * 从缓存中获取水表最后上报数据
+     * @param deviceId
+     * @return
+     */
+    protected String getMeterLastDataFromCache(Long deviceId){
+        Map<String, MeasuringData> data = null;
+        return redisUtil.get(Constants.PREFIX_CACHE_FLAG+deviceId);
+
+
+    }
+
+    public MeterReadRecord findRecordByMeterIdAndReadDate(WaterMeter waterMeter, Integer readDate) {
+        MeterReadRecord record = meterReadRecordMapper.findRecordByReadDayAndDeviceId(waterMeter.getDeviceId(), readDate);
+        return record;
+    }
+    protected  void setMeterLastDataToCache(Long deviceId ,String measuringData){
+        redisUtil.set(Constants.PREFIX_CACHE_FLAG+deviceId,measuringData);
+    }
+
+
+
+}

+ 37 - 3
src/main/java/com/zoniot/ccrc/scheduled/WarningMessageJob.java

@@ -5,17 +5,22 @@ package com.zoniot.ccrc.scheduled;
 import com.zoniot.ccrc.commom.utils.SendWechatPush;
 import com.zoniot.ccrc.dao.*;
 import com.zoniot.ccrc.entity.*;
+import com.zoniot.ccrc.repository.MongoMeterReadRecord;
 import com.zoniot.ccrc.service.AccessTokenService;
 import com.zoniot.ccrc.service.MongoMeterReadRecordService;
+import io.jsonwebtoken.lang.Collections;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.annotation.Configuration;
+import org.springframework.data.mongodb.core.query.Criteria;
+import org.springframework.data.mongodb.core.query.Query;
 import org.springframework.scheduling.annotation.EnableScheduling;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 
 import javax.annotation.Resource;
+import java.math.BigDecimal;
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
 import java.util.Date;
@@ -34,8 +39,6 @@ public class WarningMessageJob {
     private WarningLogMapper warningLogMapper;
     @Resource
     private WarningMessageMapper warningMessageMapper;
-    @Autowired
-    private MongoMeterReadRecordService mongoMeterReadRecordService;
     @Resource
     private DeviceMapper deviceMapper;
     @Resource
@@ -50,6 +53,8 @@ public class WarningMessageJob {
 
     @Value("${wechat.mp.appid}")
     private String mpAppid;
+    @Resource
+    private MeterReadRecordMapper meterReadRecordMapper;
 
 
     /**
@@ -61,7 +66,7 @@ public class WarningMessageJob {
         List<WarningRule> list = warningRuleMapper.getList(null);
         if (list != null && list.size() > 0) {
             for (WarningRule warningRule : list) {
-                    Boolean flag =  mongoMeterReadRecordService.complyWithWarningRules(warningRule.getDeviceId(),warningRule.getWarningType());
+                    Boolean flag =  complyWithWarningRules(warningRule.getDeviceId(),warningRule.getWarningType());
                     if ( flag) {
                         String content ="";
                         if(warningRule.getWarningType()==4){
@@ -79,6 +84,35 @@ public class WarningMessageJob {
         }
         log.info("end warningMessage job");
     }
+
+    public boolean complyWithWarningRules(Long deviceId, Integer type) {
+        boolean flag=false;
+
+        Integer date = Integer.valueOf(LocalDateTime.now().plusDays(-1).format(DateTimeFormatter.ofPattern("yyyyMMdd")));
+
+        List<MongoMeterReadRecord> list =  meterReadRecordMapper.getYesterReadData(deviceId,date);
+        if(!Collections.isEmpty(list)){
+            MongoMeterReadRecord mongoMeterReadRecord=list.get(0);
+            BigDecimal lastCost = mongoMeterReadRecord.getLastCost();
+                 /*小于: == -1
+                    等于: == 0
+                    大于: == 1
+                    大于等于: > -1
+                    小于等于: < 1 */
+            if(type==4){
+                BigDecimal bigDecimal=new BigDecimal("2");
+                if(lastCost.compareTo(bigDecimal)>0){
+                    flag=true;
+                }
+            }else if(type==3){
+                BigDecimal smallDecimal=new BigDecimal("0.01");
+                if(lastCost.compareTo(smallDecimal)<0){
+                    flag=true;
+                }
+            }
+        }
+        return flag;
+    }
     private void addMessageInfo(WarningRule warningRule,String content){
         WarningLog warningLogNew = new WarningLog();
 

+ 1 - 1
src/main/java/com/zoniot/ccrc/security/WebSecurityConfig.java

@@ -98,7 +98,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
                 .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
                 .and().authorizeRequests()
                 .antMatchers(HttpMethod.OPTIONS, "/**").permitAll()
-                .anyRequest().authenticated()
+               // .anyRequest().authenticated()
                 .and()
                 .formLogin()
                 .successHandler(authenticationSuccessHandler)//登陆成功处理

+ 6 - 2
src/main/java/com/zoniot/ccrc/service/impl/GridManagementServiceImpl.java

@@ -77,14 +77,18 @@ public class GridManagementServiceImpl implements GridManagementService {
     public int insert(GridInfo gridInfo) {
         Integer userId = gridInfo.getUserId();
         List<Long> deviceIds = gridInfo.getDeviceIds();
+        List<Device>devices=gridManagementMapper.getDeviceInfo(deviceIds);
         List<GridManagement> gridManagements=new ArrayList<>();
         LoginUser currentUser = UserUtil.getCurrentUser();
-        deviceIds.forEach(deviceId->{
+        devices.forEach(device->{
             GridManagement gridManagement=new GridManagement();
             gridManagement.setCreateBy(currentUser.getUsername());
             gridManagement.setCreateTime(new Date());
             gridManagement.setUserId(userId);
-            gridManagement.setDeviceId(deviceId);
+            gridManagement.setDeviceId(device.getId());
+            gridManagement.setCustomerName(device.getClientUserName());
+            gridManagement.setCustomerNo(device.getClientUserNo());
+            gridManagement.setCustomerPhone(device.getClientUserMobile());
             gridManagement.setStatus(1);
             gridManagement.setIsDefault(0);
             gridManagements.add(gridManagement);

+ 2 - 28
src/main/java/com/zoniot/ccrc/service/impl/MongoMeterReadRecordServiceImpl.java

@@ -125,33 +125,7 @@ public class MongoMeterReadRecordServiceImpl implements MongoMeterReadRecordServ
 
     @Override
     public boolean complyWithWarningRules(Long deviceId, Integer type) {
-        boolean flag=false;
-
-            Integer date = Integer.valueOf(LocalDateTime.now().plusDays(-1).format(DateTimeFormatter.ofPattern("yyyyMMdd")));
-            Query query = new Query();
-            query.addCriteria(Criteria.where("deviceId").is(deviceId));
-            query.addCriteria(Criteria.where("readDate").is(date));
-            List<MongoMeterReadRecord> list =  this.findMongoMeterReadRecordList(query);
-            if(!Collections.isEmpty(list)){
-                MongoMeterReadRecord mongoMeterReadRecord=list.get(0);
-                BigDecimal lastCost = mongoMeterReadRecord.getLastCost();
-                 /*小于: == -1
-                    等于: == 0
-                    大于: == 1
-                    大于等于: > -1
-                    小于等于: < 1 */
-                if(type==4){
-                BigDecimal bigDecimal=new BigDecimal("2");
-                   if(lastCost.compareTo(bigDecimal)>0){
-                        flag=true;
-                    }
-                 }else if(type==3){
-                    BigDecimal smallDecimal=new BigDecimal("0.01");
-                    if(lastCost.compareTo(smallDecimal)<0){
-                        flag=true;
-                    }
-                }
-            }
-        return flag;
+
+        return true;
     }
 }

+ 6 - 3
src/main/java/com/zoniot/ccrc/service/impl/StatisticsServiceImpl.java

@@ -2,6 +2,7 @@ package com.zoniot.ccrc.service.impl;
 
 import com.zoniot.ccrc.commom.utils.UserUtil;
 import com.zoniot.ccrc.dao.DeviceMapper;
+import com.zoniot.ccrc.dao.MeterReadRecordMapper;
 import com.zoniot.ccrc.dto.*;
 import com.zoniot.ccrc.service.MongoMeterReadRecordService;
 import com.zoniot.ccrc.service.StatisticsService;
@@ -23,6 +24,8 @@ public class StatisticsServiceImpl implements StatisticsService {
     private DeviceMapper deviceMapper;
     @Autowired
     private MongoMeterReadRecordService mongoMeterReadRecordService;
+    @Resource
+    private MeterReadRecordMapper meterReadRecordMapper;
 
     @Override
     public List<UseWaterDto> getRealTimeUseWater(Integer period) {
@@ -32,7 +35,7 @@ public class StatisticsServiceImpl implements StatisticsService {
         Integer startDate = Integer.valueOf(startDateTime.format(df));
         Integer endDate = Integer.valueOf(endDateTime.format(df));
         Long deviceId=getDeviceId();
-        List<UseWaterDto> list =mongoMeterReadRecordService.getRealTimeUseWater(deviceId,startDate,endDate);
+        List<UseWaterDto> list =  meterReadRecordMapper.getRealTimeUseWater(deviceId, startDate, endDate);
 
         //填充缺失月份数据
         fillDataForCertainMonths(period,list,startDateTime,df,0);
@@ -106,7 +109,7 @@ public class StatisticsServiceImpl implements StatisticsService {
         LocalDateTime endDateTime = LocalDateTime.now().plusMonths(-1).with(TemporalAdjusters.lastDayOfMonth());
         Integer startDate = Integer.valueOf(startDateTime.format(df));
         Integer endDate = Integer.valueOf(endDateTime.format(df));
-        List<UseWaterDto> list =mongoMeterReadRecordService.getUseWaterByMonth(deviceId,startDate,endDate);
+        List<UseWaterDto> list =meterReadRecordMapper.getUseWaterByMonth(deviceId, startDate, endDate);
         //填充缺失月份数据
         fillDataForCertainMonths(12,list,startDateTime,dateTimeFormatter,1);
         useWaterAnalyze.setList(list);
@@ -119,7 +122,7 @@ public class StatisticsServiceImpl implements StatisticsService {
     @Override
     public Double getDeviceVolume(Integer startDate, Integer endDate) {
         Long deviceId=getDeviceId();
-        return mongoMeterReadRecordService.getDeviceVolume(deviceId, startDate, endDate);
+        return meterReadRecordMapper.getDeviceVolume(deviceId, startDate, endDate);
     }
     @Override
     public Long getDeviceId(){

+ 6 - 0
src/main/resources/application-dev.properties

@@ -100,6 +100,12 @@ wechat.oa.appid=wx6b2ce547cd593413
 #小程序水查查服务
 wechat.mp.appid=wx27f831675081e293
 wechat.mp.app-secret=a01d7f75f15e1a6b7fa28a317f97ef1b
+site_id=1
+province_id=1
+city_id=1
+region_id=1
+geomap.apikey=bb218fd3700b37dd1e02872365cab4d5
+geomap.api.url=https://restapi.amap.com/v3/geocode/geo
 
 
 

+ 2 - 1
src/main/resources/mapper/CommunityMapper.xml

@@ -302,7 +302,8 @@
             <if test="community.dateCreate != null"> date_create= #{community.dateCreate,jdbcType=TIMESTAMP},</if>
             <if test="community.dateUpdate != null"> date_update= #{community.dateUpdate,jdbcType=TIMESTAMP},</if>
             <if test="community.createBy != null"> create_by= #{community.createBy,jdbcType=VARCHAR},</if>
-            <if test="community.updateBy != null"> update_by= #{community.updateBy,jdbcType=VARCHAR}</if>
+            <if test="community.syncFlag != null"> sync_flag= #{community.syncFlag,jdbcType=INTEGER},</if>
+
         </set>
         WHERE id = #{community.id,jdbcType=INTEGER}
     </update>

+ 8 - 1
src/main/resources/mapper/GridManagementMapper.xml

@@ -232,7 +232,7 @@
         select * from sc_building where community_id=#{commutityId} and status=1
     </select>
     <select id="getDevices" resultType="com.zoniot.ccrc.entity.Device">
-        select * from sc_device where building_id=#{buildingId} and
+        select * from sc_device where community_id=#{buildingId} and
          id not in (select distinct device_id from sc_grid_management where status=1) and status=1
         <if test="address != null  ">
             and loc_desc LIKE concat('%',#{address},'%')
@@ -242,4 +242,11 @@
     <select id="getByDeviceId" resultMap="GridManagementMap">
         select * from sc_grid_management where status = 1 and device_id = #{deviceId}
     </select>
+    <select id="getDeviceInfo" resultType="com.zoniot.ccrc.entity.Device">
+        select id,client_user_no,client_user_name,client_user_mobile from sc_device
+        where id in
+        <foreach collection="ids" item="id" open="(" separator="," close=")">
+            #{id}
+        </foreach>
+    </select>
 </mapper>

+ 433 - 0
src/main/resources/mapper/MeterReadRecordMapper.xml

@@ -0,0 +1,433 @@
+<?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.zoniot.ccrc.dao.MeterReadRecordMapper">
+  <resultMap id="BaseResultMap" type="com.zoniot.ccrc.entity.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.zoniot.ccrc.entity.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.zoniot.ccrc.entity.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.zoniot.ccrc.entity.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.zoniot.ccrc.entity.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>
+  <insert id="batchInsert" parameterType="map">
+    <!--@mbg.generated-->
+    replace 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,valve_status,meter_status_info)
+    values
+    <foreach collection="list" item="item" separator=",">
+      (#{item.id,jdbcType=BIGINT}, #{item.readDate,jdbcType=INTEGER}, #{item.siteId,jdbcType=INTEGER}, 
+        #{item.sysId,jdbcType=INTEGER}, #{item.province,jdbcType=INTEGER}, #{item.city,jdbcType=INTEGER}, 
+        #{item.region,jdbcType=INTEGER}, #{item.community,jdbcType=INTEGER}, #{item.customerId,jdbcType=INTEGER}, 
+        #{item.concentratorId,jdbcType=INTEGER}, #{item.collectorId,jdbcType=INTEGER}, 
+        #{item.buildingId,jdbcType=INTEGER}, #{item.location,jdbcType=VARCHAR}, #{item.deviceTypeId,jdbcType=INTEGER}, 
+        #{item.deviceId,jdbcType=BIGINT}, #{item.deviceNo,jdbcType=VARCHAR}, #{item.meterNo,jdbcType=VARCHAR}, 
+        #{item.meterFileNo,jdbcType=VARCHAR}, #{item.readTime,jdbcType=TIMESTAMP}, #{item.readStatus,jdbcType=VARCHAR}, 
+        #{item.readData,jdbcType=VARCHAR}, #{item.lastValid,jdbcType=VARCHAR}, #{item.lastCost,jdbcType=DECIMAL}, 
+        #{item.status,jdbcType=INTEGER}, #{item.dateCreate,jdbcType=TIMESTAMP}, #{item.dateUpdate,jdbcType=TIMESTAMP}, 
+        #{item.createBy,jdbcType=VARCHAR}, #{item.updateBy,jdbcType=VARCHAR},
+       #{item.valveState,jdbcType=INTEGER}, #{item.meterStatusInfo,jdbcType=VARCHAR})
+    </foreach>
+  </insert>
+  <select id="findRecordByReadDayAndDeviceId" resultMap="BaseResultMap">
+    select
+        <include refid="Base_Column_List" />
+    from
+      sc_meter_read_record
+    where
+        status = 1
+    and read_date = #{readDate,jdbcType=INTEGER}
+    and device_id = #{deviceId,jdbcType=BIGINT}
+  </select>
+  <select id="getDeviceVolume" resultType="java.lang.Double">
+    select ifnull(sum(last_cost),0) from sc_meter_read_record
+    where status = 1 and device_id = #{deviceId} and
+      read_date <![CDATA[ >= ]]> #{startDate} and read_date <![CDATA[ <= ]]> #{endDate}
+  </select>
+  <select id="getRealTimeUseWater" resultType="com.zoniot.ccrc.dto.UseWaterDto">
+    select read_date as date,last_cost as use_volume from sc_meter_read_record
+    where status = 1 and device_id = #{deviceId} and
+      read_date <![CDATA[ >= ]]> #{startDate} and read_date <![CDATA[ <= ]]> #{endDate}
+    order by read_data asc
+  </select>
+  <select id="getUseWaterByMonth" resultType="com.zoniot.ccrc.dto.UseWaterDto">
+    SELECT DATE_FORMAT(read_date,'%Y%m') as date,sum(last_cost) as useVolume FROM sc_meter_read_record
+    where status = 1 and device_id = #{deviceId}
+      and read_date <![CDATA[ >= ]]> #{startDate} and read_date <![CDATA[ <= ]]> #{endDate}
+    GROUP BY  date
+  </select>
+  <select id="getYesterReadData" resultType="com.zoniot.ccrc.repository.MongoMeterReadRecord">
+    select last_cost from sc_meter_read_record where status = 1 and device_id = #{deviceId}
+    and read_date=#{date}
+  </select>
+  <update id="deleteRecordByReadDayAndDeviceId">
+    update sc_meter_read_record set status = 0
+    where
+     read_date = #{readDate,jdbcType=INTEGER}
+    and device_id = #{deviceId,jdbcType=BIGINT}
+  </update>
+</mapper>

+ 176 - 0
src/main/resources/mapper/MeterRecordMapper.xml

@@ -0,0 +1,176 @@
+<?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.zoniot.ccrc.dao.MeterRecordMapper">
+    <!-- 结果集 -->
+    <resultMap type="com.zoniot.ccrc.entity.MeterRecord" id="MeterRecordMap">
+        <result property="id" column="id" jdbcType="INTEGER"/>
+        <result property="registNo" column="regist_no" jdbcType="VARCHAR"/>
+        <result property="meterReading" column="meter_reading" jdbcType="NUMERIC"/>
+        <result property="readingTime" column="reading_time" jdbcType="TIMESTAMP"/>
+        <result property="valveStatus" column="valve_status" jdbcType="INTEGER"/>
+        <result property="meterStatus" column="meter_status" jdbcType="INTEGER"/>
+        <result property="meterStatusInfo" column="meter_status_info" jdbcType="VARCHAR"/>
+    </resultMap>
+
+    <!-- 基本字段 -->
+    <sql id="Base_Column_List">
+        id, regist_no, meter_reading, reading_time, valve_status, meter_status, meter_status_info    </sql>
+
+    <!-- 查询单个 -->
+    <select id="selectById" resultMap="MeterRecordMap">
+        select
+        <include refid="Base_Column_List"/>
+        from crcc_mid_meter_record
+        where id = #{id}
+    </select>
+
+
+    <!-- 查询全部 -->
+    <select id="selectAll" resultMap="MeterRecordMap">
+        select
+        <include refid="Base_Column_List"/>
+        from crcc_mid_meter_record
+    </select>
+
+    <!--通过实体作为筛选条件查询-->
+    <select id="selectList" resultMap="MeterRecordMap">
+        select
+        <include refid="Base_Column_List"/>
+        from crcc_mid_meter_record
+        <where>
+            <if test="id != null">
+                and id = #{id}
+            </if>
+            <if test="registNo != null and registNo != ''">
+                and regist_no = #{registNo}
+            </if>
+            <if test="meterReading != null">
+                and meter_reading = #{meterReading}
+            </if>
+            <if test="readingTime != null">
+                and reading_time = #{readingTime}
+            </if>
+            <if test="valveStatus != null">
+                and valve_status = #{valveStatus}
+            </if>
+            <if test="meterStatus != null">
+                and meter_status = #{meterStatus}
+            </if>
+            <if test="meterStatusInfo != null and meterStatusInfo != ''">
+                and meter_status_info = #{meterStatusInfo}
+            </if>
+        </where>
+    </select>
+
+    <!-- 新增所有列 -->
+    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
+        insert into crcc_mid_meter_record(id, regist_no, meter_reading, reading_time, valve_status, meter_status,
+                                          meter_status_info)
+        values (#{id}, #{registNo}, #{meterReading}, #{readingTime}, #{valveStatus}, #{meterStatus}, #{meterStatusInfo})
+    </insert>
+
+    <!-- 批量新增 -->
+    <insert id="batchInsert">
+        insert into crcc_mid_meter_record(id, regist_no, meter_reading, reading_time, valve_status, meter_status,
+        meter_status_info)
+        values
+        <foreach collection="meterRecords" item="item" index="index" separator=",">
+            (
+            #{item.id}, #{item.registNo}, #{item.meterReading}, #{item.readingTime}, #{item.valveStatus},
+            #{item.meterStatus}, #{item.meterStatusInfo} )
+        </foreach>
+    </insert>
+
+    <!-- 通过主键修改数据 -->
+    <update id="update">
+        update crcc_mid_meter_record
+        <set>
+            <if test="registNo != null and registNo != ''">
+                regist_no = #{registNo},
+            </if>
+            <if test="meterReading != null">
+                meter_reading = #{meterReading},
+            </if>
+            <if test="readingTime != null">
+                reading_time = #{readingTime},
+            </if>
+            <if test="valveStatus != null">
+                valve_status = #{valveStatus},
+            </if>
+            <if test="meterStatus != null">
+                meter_status = #{meterStatus},
+            </if>
+            <if test="meterStatusInfo != null and meterStatusInfo != ''">
+                meter_status_info = #{meterStatusInfo},
+            </if>
+        </set>
+        where id = #{id}
+    </update>
+
+    <!--通过主键删除-->
+    <delete id="deleteById">
+        delete
+        from crcc_mid_meter_record
+        where id = #{id}
+    </delete>
+    <delete id="deleteDevice">
+        update sc_device set status=0 where regist_no not in (select regist_no from crcc_mid_meter)
+    </delete>
+    <update id="deleteCell">
+        update sc_community set status=0 where uniq_id not in (select code from crcc_mid_community)
+    </update>
+    <update id="updateReadData">
+       update sc_meter_read_record set read_data=#{readData},last_valid=#{readData},
+       read_time=#{readTime},last_cost=#{lastCost},valve_status=#{valveState}
+       ,meter_status_info=#{meterStatusInfo}
+       where device_id=#{deviceId} and read_date=#{readDate}
+    </update>
+
+
+    <!-- 总数 -->
+    <select id="count" resultType="int">
+        select count(*)
+        from crcc_mid_meter_record
+    </select>
+
+    <select id="get" resultType="com.zoniot.ccrc.entity.MeterRecord">
+        select * from crcc_mid_meter_record where regist_no=#{registNo}
+    </select>
+    <select id="syncCell">
+        insert into sc_community(site_id,name,province,city,region,uniq_id,status,date_create)
+        select #{siteId},name,#{provinceId},#{cityId},#{regionId},code,1,now() from crcc_mid_community
+        ON DUPLICATE KEY UPDATE name=VALUES(name),date_update=now()
+    </select>
+    <select id="getCommunityIds" resultType="com.zoniot.ccrc.entity.Community">
+        select a.id,a.name,b.name addrees from sc_community a join sc_area b on a.city=b.id
+        where longitude is null and sync_flag =0
+    </select>
+    <select id="findWaterMeterListWithPage" resultType="com.zoniot.ccrc.entity.WaterMeter">
+        select id device_id,device_no,community_id community,loc_desc location,
+               device_type_id,site_id,sys_id,meter_no,file_no meterFileNo,regist_no
+        from sc_device where status=1 and regist_no is not null limit #{offset},#{size}
+    </select>
+    <update id="updateDeviceStatus">
+        update sc_device a,crcc_mid_meter_record b set a.valve_status =b.valve_status
+                       ,a.device_status=b.meter_status,a.last_receive_time=b.reading_time,
+            a.meter_reading=b.meter_reading,a.meter_status_info=b.meter_status_info
+          where a.regist_no=b.regist_no
+    </update>
+    <insert id="syncDevice">
+        INSERT INTO sc_device (id,regist_no,device_no,file_no,site_id,sys_id
+                              ,device_type_id,manufacturer_id,community_id,loc_desc,status,
+                               date_create,date_update,client_user_mobile,client_user_name,client_user_no)
+        select #{deviceId},regist_no,meter_no,regist_no,#{siteId}, CASE meter_type WHEN 1 THEN  40 ELSE
+            58 END sysId,meter_type,1,b.id,concat(a.address,a.location),1,now(),now(),client_user_mobile,
+               client_user_name,client_user_no
+
+        from crcc_mid_meter a join sc_community b
+                                   on a.community_code=b.uniq_id
+        ON DUPLICATE KEY UPDATE device_no=VALUES(meter_no),
+                                file_no=VALUES(regist_no),community_id=b.id,
+                                loc_desc=concat(a.address,a.location),date_update=now(),
+                                client_user_mobile=VALUES(client_user_mobile),
+                                client_user_name=VALUES(client_user_name),
+                                client_user_no=VALUES(client_user_no)
+    </insert>
+</mapper>