Selaa lähdekoodia

月结水量同步

wangli 4 vuotta sitten
vanhempi
commit
203ac8f195
21 muutettua tiedostoa jossa 607 lisäystä ja 238 poistoa
  1. 2 0
      smart-city-platform/src/main/java/com/bz/smart_city/commom/security/WebSecurityConfig.java
  2. 3 3
      smart-city-platform/src/main/java/com/bz/smart_city/controller/pay/AmountWaterUsedAmountController.java
  3. 12 0
      smart-city-platform/src/main/java/com/bz/smart_city/controller/pay/PayBaseAccountController.java
  4. 3 0
      smart-city-platform/src/main/java/com/bz/smart_city/dao/SiteMapper.java
  5. 22 4
      smart-city-platform/src/main/java/com/bz/smart_city/dao/pay/AmountWaterUsedAmountMapper.java
  6. 3 0
      smart-city-platform/src/main/java/com/bz/smart_city/dao/pay/PayBaseAccountMapper.java
  7. 29 0
      smart-city-platform/src/main/java/com/bz/smart_city/dto/pay/AmountSynParamDto.java
  8. 26 0
      smart-city-platform/src/main/java/com/bz/smart_city/dto/pay/AmountSynRespDto.java
  9. 37 0
      smart-city-platform/src/main/java/com/bz/smart_city/dto/pay/BaseWatermeterDto.java
  10. 28 0
      smart-city-platform/src/main/java/com/bz/smart_city/dto/pay/SiteinfoDto.java
  11. 30 0
      smart-city-platform/src/main/java/com/bz/smart_city/dto/pay/SynAccountInfo.java
  12. 2 0
      smart-city-platform/src/main/java/com/bz/smart_city/entity/pay/DeviceReplaceRecord.java
  13. 184 158
      smart-city-platform/src/main/java/com/bz/smart_city/quartz/service/impl/AmountSynServiceImpl.java
  14. 22 6
      smart-city-platform/src/main/java/com/bz/smart_city/service/impl/pay/AmountWaterUsedAmountServiceImpl.java
  15. 4 1
      smart-city-platform/src/main/java/com/bz/smart_city/service/impl/pay/PayBaseAccountServiceImpl.java
  16. 2 2
      smart-city-platform/src/main/java/com/bz/smart_city/service/pay/PayBaseAccountService.java
  17. 1 2
      smart-city-platform/src/main/resources/application-dev.properties
  18. 1 1
      smart-city-platform/src/main/resources/mapper/CustomerMapper.xml
  19. 12 0
      smart-city-platform/src/main/resources/mapper/SiteMapper.xml
  20. 171 61
      smart-city-platform/src/main/resources/mapper/pay/AmountWaterUsedAmountMapper.xml
  21. 13 0
      smart-city-platform/src/main/resources/mapper/pay/PayBaseAccountMapper.xml

+ 2 - 0
smart-city-platform/src/main/java/com/bz/smart_city/commom/security/WebSecurityConfig.java

@@ -90,6 +90,8 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
                 .antMatchers("/watermeter/getMeterReadData","/watermeter/getDeviceCustomerInfo","/watermeter/getPeriodMeterReadData","/data/clearingData","/data/meterReadData")
                 .antMatchers("/apply/register","/apply/detail","/apply/approve")
                 .antMatchers("/payFee/payFee")
+                .antMatchers("/amount/synDeviceReplaceRecord")
+                .antMatchers("/pay/synAccountInfo")
                 .antMatchers("/printinvoice/InvoicePrintRequest")
                 .antMatchers("/waterMeter/getMeterByDeviceNo")
                 .antMatchers("/device/synArchies")

+ 3 - 3
smart-city-platform/src/main/java/com/bz/smart_city/controller/pay/AmountWaterUsedAmountController.java

@@ -125,10 +125,10 @@ public class AmountWaterUsedAmountController {
     //换表接口
 
     @ResponseBody
-    @GetMapping("/synDeviceReplaceRecord")
-    @ApiOperation(value = "获取全部审核条数")
+    @PostMapping("/synDeviceReplaceRecord")
+    @ApiOperation(value = "换表记录同步接口")
     public AjaxMessage synDeviceReplaceRecord(
-            @ApiParam(value = "h换表记录")@RequestBody(required = true) DeviceReplaceRecordDto deviceReplaceRecordDto
+            @ApiParam(value = "换表记录")@RequestBody(required = true) DeviceReplaceRecordDto deviceReplaceRecordDto
      ){
         amountWaterUsedAmountService.saveDeviceReplaceRecord(deviceReplaceRecordDto);
 

+ 12 - 0
smart-city-platform/src/main/java/com/bz/smart_city/controller/pay/PayBaseAccountController.java

@@ -134,5 +134,17 @@ public class PayBaseAccountController {
     }
 
 
+    @GetMapping("/synAccountInfo")
+    @ApiOperation(value = "客户信息同步接口")
+    public AjaxMessage synAccountInfo(
+            @ApiParam(value = "创建日期,格式yyyyMMdd",required = false) @RequestBody(required = false) String createDate)
+    {
+        List list = payBaseAccountService.getSynAccountInfo(createDate);
+        if(list.size()>0){
+            return new AjaxMessage(ResultStatus.OK,list);
+        }else{
+            return new AjaxMessage(1,"未查询到有效数据","");
+        }
+    }
 
 }

+ 3 - 0
smart-city-platform/src/main/java/com/bz/smart_city/dao/SiteMapper.java

@@ -1,6 +1,7 @@
 package com.bz.smart_city.dao;
 
 import com.bz.smart_city.dto.SiteDto;
+import com.bz.smart_city.dto.pay.SiteinfoDto;
 import com.bz.smart_city.entity.Site;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
@@ -26,4 +27,6 @@ public interface SiteMapper {
     Site findById(@Param("siteId") Integer siteId);
 
     int findByCustomerIdUnique(@Param("id") Integer id, @Param("customerId") Integer customerId);
+
+    SiteinfoDto getSiteAndCustomerByCustomerNo(@Param("customerNo") String customerNo);
 }

+ 22 - 4
smart-city-platform/src/main/java/com/bz/smart_city/dao/pay/AmountWaterUsedAmountMapper.java

@@ -1,14 +1,12 @@
 package com.bz.smart_city.dao.pay;
 
-import com.bz.smart_city.dto.pay.AmountWaterUsedAmountDto;
-import com.bz.smart_city.dto.pay.MeterReadRecordDto;
-import com.bz.smart_city.dto.pay.ReplaceMeterCountDto;
-import com.bz.smart_city.dto.pay.ReplaceMeterDto;
+import com.bz.smart_city.dto.pay.*;
 import com.bz.smart_city.entity.ProgramItem;
 import com.bz.smart_city.entity.pay.AmountWaterUsedAmount;
 import com.bz.smart_city.entity.pay.AmountWaterUsedAmountByDay;
 import com.bz.smart_city.entity.pay.DeviceReplaceRecord;
 import com.bz.smart_city.entity.pay.archives.PayBaseCustomerandmeterrela;
+import com.bz.smart_city.dto.pay.AmountSynParamDto;
 import org.apache.ibatis.annotations.MapKey;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
@@ -71,6 +69,26 @@ public interface AmountWaterUsedAmountMapper {
     //换表明细 list:设备ID
     List<ReplaceMeterDto> getRepalceRecordDetail(@Param("stTime")LocalDateTime stTime,@Param("etTime")LocalDateTime etTime,@Param("list")List<BigInteger> list,@Param("siteId")Integer siteId,@Param("customerId")Integer customerId);
 
+    AmountWaterUsedAmount getLastReadrecord(@Param("metercode") String metercode, @Param("siteId") Integer siteId,@Param("customerId")Integer customerId);
+
+    //插入换表信息
+    Integer insertReplaceRecord( @Param("deviceReplaceRecord") DeviceReplaceRecord deviceReplaceRecord);
+    //根据水表编码查询水表信息
+    BaseWatermeterDto getWatermeterInfoByMetercode(@Param("metercode") String metercode, @Param("siteId") Integer siteId, @Param("customerId") Integer customerId );
+
+    Integer updateWatermeterInfo(@Param("baseWatermeterDto") BaseWatermeterDto baseWatermeterDto);
+
+    //插入水量同步基础信息(同步计划)
+    Integer insertSelectAmountBaseInfo( @Param("year") Integer year,@Param("month") Integer month,@Param("siteId") Integer siteId,@Param("customerId") Integer customerId);
+
+    //获取需要同步水量的水表编码
+    List<String> getSynAmountMetercode( @Param("year") Integer year,@Param("month") Integer month,@Param("siteId") Integer siteId,@Param("customerId") Integer customerId);
+
+    AmountSynParamDto GetAmountSynMeterInfo(@Param("year") Integer year, @Param("month") Integer month, @Param("siteId") Integer siteId, @Param("customerId") Integer customerId);
+
+    //获取同步计划
+    List<String> GetAmountSynInfo(@Param("year") Integer year, @Param("month") Integer month, @Param("siteId") Integer siteId, @Param("customerId") Integer customerId);
+
     //换表统计 list:设备ID
     @MapKey("deviceId")
     HashMap<BigInteger, ReplaceMeterCountDto> getRepalceRecordCount(@Param("stTime")LocalDateTime stTime, @Param("etTime")LocalDateTime etTime, @Param("list")List<BigInteger> list,@Param("siteId")Integer siteId,@Param("customerId")Integer customerId);

+ 3 - 0
smart-city-platform/src/main/java/com/bz/smart_city/dao/pay/PayBaseAccountMapper.java

@@ -11,6 +11,7 @@ import org.apache.ibatis.annotations.Select;
 
 import java.math.BigDecimal;
 import java.math.BigInteger;
+import java.time.LocalDate;
 import java.util.List;
 
 @Mapper
@@ -54,4 +55,6 @@ public interface PayBaseAccountMapper {
     List<PayMeter>findMeterInfo(@Param("queryInfo") String queryInfo, @Param("state") String state, @Param("siteId") BigInteger siteId, @Param("customerId") BigInteger customerId,@Param("year") Integer year,@Param("month") Integer month,@Param("programItemList") List<ProgramItem> programItemList);
 
     void updateAccountName(@Param("type")Integer type,@Param("accountname")String accountname,@Param("accountId")BigInteger accountId);
+
+    List<SynAccountInfo> getSynAccountInfo( @Param("createDate")String createDate);
 }

+ 29 - 0
smart-city-platform/src/main/java/com/bz/smart_city/dto/pay/AmountSynParamDto.java

@@ -0,0 +1,29 @@
+package com.bz.smart_city.dto.pay;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * @description
+ * @auto wangli
+ * @data 2020-10-09 8:28
+ */
+@Data
+@Api("结算水量同步接口请求参数")
+public class AmountSynParamDto implements Serializable {
+
+    private static final long serialVersionUID = 3519394900406918279L;
+
+    @ApiModelProperty("账期,格式yyyymm")
+    private String yyyymm;
+
+    @ApiModelProperty("客户编号")
+    private String customerNo;
+
+    @ApiModelProperty("水表编码")
+    private List<String> fileNo;
+}

+ 26 - 0
smart-city-platform/src/main/java/com/bz/smart_city/dto/pay/AmountSynRespDto.java

@@ -0,0 +1,26 @@
+package com.bz.smart_city.dto.pay;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * @description
+ * @auto wangli
+ * @data 2020-10-09 9:55
+ */
+@Data
+@Api("结算水量同步接口结果")
+public class AmountSynRespDto implements Serializable {
+
+    private static final long serialVersionUID = -4057222618378320320L;
+
+    @ApiModelProperty("本期抄表日期")
+    private  String currentPeriodDate;
+    @ApiModelProperty("水表档案号")
+    private  String fileNo;
+    @ApiModelProperty("本期读数")
+    private  String reading;
+}

+ 37 - 0
smart-city-platform/src/main/java/com/bz/smart_city/dto/pay/BaseWatermeterDto.java

@@ -0,0 +1,37 @@
+package com.bz.smart_city.dto.pay;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.time.LocalDateTime;
+
+/**
+ * @description 水表信息
+ * @auto wangli
+ * @data 2020-09-28 10:53
+ */
+@Api("水表信息")
+@Data
+public class BaseWatermeterDto {
+
+    @ApiModelProperty("水表id")
+    private BigInteger id;
+    @ApiModelProperty("水表编码")
+    private String metercode;
+    @ApiModelProperty("水表表号")
+    private String eleno;
+    @ApiModelProperty("水表起度")
+    private BigDecimal stratcount;
+    @ApiModelProperty("创建者")
+    private BigInteger createBy;
+    @ApiModelProperty("创建时间")
+    private LocalDateTime createDate;
+    @ApiModelProperty("修改者")
+    private BigInteger updateBy;
+    @ApiModelProperty("修改时间")
+    private LocalDateTime updateDate;
+
+}

+ 28 - 0
smart-city-platform/src/main/java/com/bz/smart_city/dto/pay/SiteinfoDto.java

@@ -0,0 +1,28 @@
+package com.bz.smart_city.dto.pay;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.math.BigInteger;
+
+/**
+ * @description 站点信息
+ * @auto wangli
+ * @data 2020-09-28 16:05
+ */
+@Data
+@Api("站点信息")
+public class SiteinfoDto {
+
+    @ApiModelProperty("站点id")
+    private Integer id;
+    @ApiModelProperty("站点名称")
+    private String siteName;
+    @ApiModelProperty("客户id")
+    private Integer customerId;
+    @ApiModelProperty("客户编号")
+    private String customerNo;
+    @ApiModelProperty("客户名称")
+    private String customerName;
+}

+ 30 - 0
smart-city-platform/src/main/java/com/bz/smart_city/dto/pay/SynAccountInfo.java

@@ -0,0 +1,30 @@
+package com.bz.smart_city.dto.pay;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * @description
+ * @auto wangli
+ * @data 2020-09-27 16:06
+ */
+@ApiModel("水务系统查询新建用户信息")
+@Data
+public class SynAccountInfo implements Serializable {
+
+    private static final long serialVersionUID = -4697217705878774042L;
+
+    @ApiModelProperty("客户编码")
+    private String accountNumber;
+    @ApiModelProperty("客户名称")
+    private String accountName;//
+    @ApiModelProperty("电话号码")
+    private String accountPhone;//
+    @ApiModelProperty("水表编码")
+    private String fileNo;//
+    @ApiModelProperty("创建日期")
+    private String createDate;
+}

+ 2 - 0
smart-city-platform/src/main/java/com/bz/smart_city/entity/pay/DeviceReplaceRecord.java

@@ -18,6 +18,8 @@ public class DeviceReplaceRecord implements Serializable {
 
     @ApiModelProperty("主键id")
     private BigInteger id;
+    @ApiModelProperty("水表Id")
+    private BigInteger watermeterId;
     @ApiModelProperty("水表编码")
     private String metercode;
     @ApiModelProperty("旧表电子号")

+ 184 - 158
smart-city-platform/src/main/java/com/bz/smart_city/quartz/service/impl/AmountSynServiceImpl.java

@@ -1,13 +1,20 @@
 package com.bz.smart_city.quartz.service.impl;
 
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import com.bz.smart_city.commom.util.DateTimeUtil;
+import com.bz.smart_city.commom.util.HttpClientUtils;
+import com.bz.smart_city.dao.CustomerMapper;
 import com.bz.smart_city.dao.pay.AmountWaterUsedAmountMapper;
 import com.bz.smart_city.dao.pay.BaseClosingAccountInfoMapper;
 import com.bz.smart_city.dao.pay.PayBaseConfigMapper;
 import com.bz.smart_city.dto.pay.*;
+import com.bz.smart_city.entity.Customer;
 import com.bz.smart_city.quartz.service.AmountSynService;
 import com.bz.smart_city.quartz.service.JobAndTriggerService;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Component;
 
@@ -18,10 +25,9 @@ import java.time.Duration;
 import java.time.LocalDateTime;
 import java.time.ZoneId;
 import java.time.format.DateTimeFormatter;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
+import java.util.*;
+import java.util.function.Function;
+import java.util.stream.Collectors;
 
 /**
  * @description
@@ -35,11 +41,16 @@ public class AmountSynServiceImpl implements AmountSynService {
     @Value("1")
     private BigInteger createBy;
 
+    @Value("http://114.135.61.188:58080/api/syncData/clearingData")
+    private String amountSynUrl;
+
     @Resource
     private BaseClosingAccountInfoMapper baseClosingAccountInfoMapper;
     @Resource
     private AmountWaterUsedAmountMapper amountWaterUsedAmountMapper;
     @Resource
+    private CustomerMapper customerMapper;
+    @Resource
     private PayBaseConfigMapper payBaseConfigMapper;
     @Resource
     private JobAndTriggerService jobAndTriggerService;
@@ -50,180 +61,195 @@ public class AmountSynServiceImpl implements AmountSynService {
 
     @Override
     public void amountUpdate(Integer siteId, Integer customerId) {
-
-
-        //获取水表信息
-        //调取接口获取水量信息
-        //保存水量信息
-    }
-
- /*   public void amountUpdate(Integer siteId, Integer customerId){
-
         //获取最新账期
+        BaseClosingAccountInfoDto baseClosingAccountInfoDto = baseClosingAccountInfoMapper.getLastClosingAccount(siteId, customerId);
 
-        List<BaseClosingAccountInfoDto> baseClosingAccountInfoDtos = baseClosingAccountInfoMapper.getList(null,null, BigInteger.valueOf(siteId),BigInteger.valueOf(customerId),0);
-        if(baseClosingAccountInfoDtos.size()>0){
-            //customerId  accountPeriod 是否有结算计划
-            BaseClosingAccountInfoDto baseClosingAccountInfoDto =  baseClosingAccountInfoDtos.get(0);
-            Integer year = baseClosingAccountInfoDto.getYear();
-            Integer month = baseClosingAccountInfoDto.getMonth();
-
-            String accountPeriod = year + String.format("%02d",month);
-
-
-            ClearingRecord clearingRecord  = //clearingRecordMapper.findClearingRecordByAccoutPeriodAndCust(accountPeriod,Integer.valueOf(customerId));
-            if(clearingRecord!=null){
-                //产生水量基础计划
-                Integer totalNum = amountWaterUsedAmountMapper.getAllAmountCount(year,month,siteId,customerId);
-                Integer num = totalNum / 500 + (totalNum % 500 > 0 ? 1 : 0);
-                log.info("抄表计划生成开始:" + LocalDateTime.now() + ",计划条数" + totalNum);
-                for (int i = 0; i < num; i++)
-                {
-                    int a = amountWaterUsedAmountMapper.createdAmount(year,month,siteId,customerId);
-                    log.info("成功条数" + i + ":" + a);
+        if(baseClosingAccountInfoDto == null
+                || baseClosingAccountInfoDto .getYear() == null
+                || baseClosingAccountInfoDto.getMonth() == null){
+            log.info("同步水量失败:获取账期信息失败");
+            return ;
+        }
+        Integer year=baseClosingAccountInfoDto.getYear();
+        Integer month=baseClosingAccountInfoDto.getMonth();
+        //插入水量基础信息(同步计划)
+        Integer amountNumber = amountWaterUsedAmountMapper.insertSelectAmountBaseInfo(year,month,siteId,customerId);
+        if(amountNumber == 0){
+            log.info("同步水量失败:生成同步计划失败");
+            return;
+        }
+        //获取客户编号
+        List<Customer> customers = customerMapper.getListById(customerId);
+        if(customers .size() != 1){
+            log.info("同步水量失败:查询客户信息异常");
+            return;
+        }
+        String customerNo=customers.get(0).getCustomerNo();
+        //获取同步计划
+        List<AmountWaterUsedAmountDto> amountWaterUsedAmountDtos = amountWaterUsedAmountMapper.getAllAmountRecord(year, month,siteId, customerId);
+        if(amountWaterUsedAmountDtos.size() == 0){
+            log.info("同步水量失败:获取同步计划失败");
+            return;
+        }
+        List<String> metercodes = amountWaterUsedAmountDtos.stream().map(
+                AmountWaterUsedAmountDto -> AmountWaterUsedAmountDto.getMetercode()).collect(Collectors.toList());
+//        List<String> metercodes =amountWaterUsedAmountMapper.GetAmountSynInfo(year,month,siteId,customerId);
+
+        //批量更新水量信息
+        List<AmountWaterUsedAmountDto> updates = new ArrayList<>();
+
+        List<AmountSynRespDto> lists =new ArrayList<>();
+        for(int i=0;i<metercodes.size();i+=500){
+            AmountSynParamDto amountSynParamDto= new AmountSynParamDto();
+            amountSynParamDto.setYyyymm(year+""+month);
+            amountSynParamDto.setCustomerNo(customerNo);
+            //一次查询五百条
+            if(i+500 >= metercodes.size()){
+                amountSynParamDto.setFileNo(metercodes.subList(i,metercodes.size()));
+            }else{
+                amountSynParamDto.setFileNo(metercodes.subList(i,i+500));
+            }
+            String context=JSON.toJSON(amountSynParamDto).toString();
+            try {
+                String result= HttpClientUtils.doPostWithJson(amountSynUrl,context);
+                log.info("同步水量请求结果"+result);
+
+                JSONObject jsonObject= JSON.parseObject(result);
+                Integer status= jsonObject.getInteger("status");
+                if(status .equals(0)){   //返回正常
+                    JSONObject datas = jsonObject.getJSONObject("data");
+                    String total = datas.getString("total");
+                    if(StringUtils.isNotBlank(total) && Integer.valueOf(total) > 0){//有数据
+                        JSONArray jsonArray = datas.getJSONArray("list");
+                        List<AmountSynRespDto> list = jsonArray.toJavaList(AmountSynRespDto.class);
+                        lists.addAll(list);
+                    }
                 }
-                log.info("抄表计划生成完成:" + LocalDateTime.now());
-
-                //获取结算水量
-                log.info("水量同步开始:" + LocalDateTime.now());
-                HashMap<BigInteger, ClearingDataInfoDto> clearingDataHashMap = clearingRecordItemMapper.findClearingDataHashMap(clearingRecord.getId(),1);
-                if(clearingDataHashMap!=null&&clearingDataHashMap.size()>0) {
-                    //同步水量
-                    List<AmountWaterUsedAmountDto> amountWaterUsedAmountDtos = amountWaterUsedAmountMapper.getAllAmountRecord(year, month,siteId, customerId);
-                    //批量更新水量信息
-                    List<AmountWaterUsedAmountDto> updates = new ArrayList<>();
-
-                    //换表记录
-                    HashMap<BigInteger, ReplaceMeterCountDto> replaceMap = new HashMap<>();
-                    if(amountWaterUsedAmountDtos.size() > 0){
-                        LocalDateTime stTime = LocalDateTime.ofInstant(baseClosingAccountInfoDtos.get(0).getStartTime().toInstant(), ZoneId.systemDefault());
-                        HashMap<BigInteger, ReplaceMeterCountDto> childReplaceMap = amountWaterUsedAmountMapper.getRepalceRecordCount(stTime,null,null,null,customerId);
-                        if(childReplaceMap.size() >0){
-                            List<ReplaceMeterDto> replaceMeterDtoList = amountWaterUsedAmountMapper.getRepalceRecordDetail(stTime,null,null,null,customerId);
-                            if(replaceMeterDtoList.size() >0){
-                                for(int i=0;i<replaceMeterDtoList.size();i++){
-                                    if(childReplaceMap.containsKey(replaceMeterDtoList.get(i).getDeviceId())){
-                                        ReplaceMeterCountDto replaceMeterCountDto = childReplaceMap.get(replaceMeterDtoList.get(i).getDeviceId());
-                                        if(replaceMeterCountDto.getReplaceMeterDtoList() == null)
-                                        {
-                                            replaceMeterCountDto.setReplaceMeterDtoList(new ArrayList<>());
-                                        }
-                                        replaceMeterCountDto.getReplaceMeterDtoList().add(replaceMeterDtoList.get(i));
-                                    }
-                                }
-                            }
-                            replaceMap.putAll(childReplaceMap);
+
+            }catch (Exception e){
+                e.printStackTrace();
+            }
+        }
+        Map<String ,AmountSynRespDto> map = lists.stream().collect(Collectors.toMap(AmountSynRespDto::getFileNo, Function.identity(), (key1, key2) -> key2));
+        //换表记录
+        HashMap<BigInteger, ReplaceMeterCountDto> replaceMap = new HashMap<>();
+        LocalDateTime stTime = LocalDateTime.ofInstant(baseClosingAccountInfoDto.getStartTime().toInstant(), ZoneId.systemDefault());
+        HashMap<BigInteger, ReplaceMeterCountDto> childReplaceMap = amountWaterUsedAmountMapper.getRepalceRecordCount(stTime,null,null,null,customerId);
+        if(childReplaceMap.size() >0){
+            List<ReplaceMeterDto> replaceMeterDtoList = amountWaterUsedAmountMapper.getRepalceRecordDetail(stTime,null,null,null,customerId);
+            if(replaceMeterDtoList.size() >0){
+                for(int i=0;i<replaceMeterDtoList.size();i++){
+                    if(childReplaceMap.containsKey(replaceMeterDtoList.get(i).getDeviceId())){
+                        ReplaceMeterCountDto replaceMeterCountDto = childReplaceMap.get(replaceMeterDtoList.get(i).getDeviceId());
+                        if(replaceMeterCountDto.getReplaceMeterDtoList() == null)
+                        {
+                            replaceMeterCountDto.setReplaceMeterDtoList(new ArrayList<>());
                         }
+                        replaceMeterCountDto.getReplaceMeterDtoList().add(replaceMeterDtoList.get(i));
                     }
+                }
+            }
+            replaceMap.putAll(childReplaceMap);
+        }
 
-                    for (AmountWaterUsedAmountDto amountWaterUsedAmountDto : amountWaterUsedAmountDtos) {
-                        BigInteger watermeterId = amountWaterUsedAmountDto.getWatermeterId();
-                        if (watermeterId != null && clearingDataHashMap.containsKey(watermeterId)) {
-                            ClearingDataInfoDto clearingDataDTO = clearingDataHashMap.get(watermeterId);
-                            BigInteger amountId = amountWaterUsedAmountDto.getId();//水量id
-                            BigDecimal readingOld = amountWaterUsedAmountDto.getLastreading();//上期止度
-                            if (clearingDataDTO.getCurrentPeriodData() != null) {
-                                BigDecimal readingNew = new BigDecimal(clearingDataDTO.getCurrentPeriodData()).setScale(0, BigDecimal.ROUND_DOWN);//本期止度
-                                BigInteger meterid = amountWaterUsedAmountDto.getWatermeterId();//水表id
-                                BigDecimal payAmount = BigDecimal.ZERO;//结算水量
-                                Date lastAmountDate = amountWaterUsedAmountDto.getLastrecorddate();
-                                BigDecimal Amount = BigDecimal.ZERO;//实际用水量
-                                BigDecimal tempReading = BigDecimal.ZERO;
-                                tempReading = readingOld;//起度或上期的止度
-                                String readDate = clearingDataDTO.getMeterReadDate();
-                                Integer calculateway = amountWaterUsedAmountDto.getCalculateway();
-
-                                //换表记录计算
-                                boolean replace = false;
-                                ReplaceMeterCountDto replaceMeterCountDto=null;
-                                if(replaceMap.containsKey(watermeterId)){
-                                    replaceMeterCountDto = replaceMap.get(watermeterId);
-                                    //有换表记录且换表时间在两次同步之间 用水量=(换表中的旧表止度-上次抄表止度) + (本次止度-换表中的新表起度)
-                                    if(replaceMeterCountDto != null){
-                                        LocalDateTime currTime = LocalDateTime.parse(readDate, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.S"));//本次抄表时间
-                                        LocalDateTime previousTime = LocalDateTime.ofInstant(amountWaterUsedAmountDto.getLastrecorddate().toInstant(),ZoneId.systemDefault()); //上个帐期的结算抄表时间
-
-                                        ReplaceMeterDto oldReplaceMeterDto = null;
-                                        for(int i = 0;i<replaceMeterCountDto.getReplaceMeterDtoList().size();i++){
-                                            LocalDateTime replaceTime = replaceMeterCountDto.getReplaceMeterDtoList().get(i).getReplaceTime();   //换表时间
-
-                                            Duration duration1 = Duration.between(previousTime,replaceTime);
-                                            Duration duration2 = Duration.between(replaceTime,currTime);
-                                            if(duration1.toMillis() > 0  && duration2.toMinutes() > 0){
-                                                BigDecimal replaceEndData = new BigDecimal(replaceMeterCountDto.getReplaceMeterDtoList().get(i).getOldEnd()).setScale(2,BigDecimal.ROUND_DOWN);//换表中的旧表止度
-                                                BigDecimal replaceData = BigDecimal.ZERO;
-                                                if(oldReplaceMeterDto == null)
-                                                    replaceData = tempReading;
-                                                else
-                                                    replaceData = new BigDecimal(oldReplaceMeterDto.getNewBegin()).setScale(0,BigDecimal.ROUND_DOWN);//换表中的起度
-                                                BigDecimal oldMeterUse = replaceEndData.subtract(replaceData); //旧表用量
-
-                                                Amount = Amount.add(oldMeterUse);
-                                                replace = true;
-
-                                                oldReplaceMeterDto = replaceMeterCountDto.getReplaceMeterDtoList().get(i);
-                                            }
-                                            else {
-                                                break;
-                                            }
-
-                                        }
-
-                                        //新表用量
-                                        if(oldReplaceMeterDto != null){
-                                            BigDecimal replaceNewDate = new BigDecimal(oldReplaceMeterDto.getNewBegin()).setScale(0,BigDecimal.ROUND_DOWN);//换表中的新表起度
-                                            BigDecimal newMeterUse = readingNew.subtract(replaceNewDate);//新表用量
-                                            Amount = Amount.add(newMeterUse);
-                                        }
-
-                                    }
+        for (AmountWaterUsedAmountDto amountWaterUsedAmountDto : amountWaterUsedAmountDtos) {
+            BigInteger watermeterId = amountWaterUsedAmountDto.getWatermeterId();
+            if (watermeterId != null && map.containsKey(amountWaterUsedAmountDto.getMetercode())) {
+                AmountSynRespDto amountSynRespDto = map.get(amountWaterUsedAmountDto.getMetercode());
+                BigInteger amountId = amountWaterUsedAmountDto.getId();//水量id
+                BigDecimal readingOld = amountWaterUsedAmountDto.getLastreading();//上期止度
+                if (amountSynRespDto.getReading() != null) {
+                    BigDecimal readingNew = new BigDecimal(amountSynRespDto.getReading()).setScale(0, BigDecimal.ROUND_DOWN);//本期止度
+                    BigInteger meterid = amountWaterUsedAmountDto.getWatermeterId();//水表id
+                    BigDecimal payAmount = BigDecimal.ZERO;//结算水量
+                    Date lastAmountDate = amountWaterUsedAmountDto.getLastrecorddate();
+                    BigDecimal Amount = BigDecimal.ZERO;//实际用水量
+                    BigDecimal tempReading = BigDecimal.ZERO;
+                    tempReading = readingOld;//起度或上期的止度
+                    String readDate = amountSynRespDto.getCurrentPeriodDate();
+                    Integer calculateway = amountWaterUsedAmountDto.getCalculateway();
+
+                    //换表记录计算
+                    boolean replace = false;
+                    ReplaceMeterCountDto replaceMeterCountDto=null;
+                    if(replaceMap.containsKey(watermeterId)){
+                        replaceMeterCountDto = replaceMap.get(watermeterId);
+                        //有换表记录且换表时间在两次同步之间 用水量=(换表中的旧表止度-上次抄表止度) + (本次止度-换表中的新表起度)
+                        if(replaceMeterCountDto != null){
+                            LocalDateTime currTime = LocalDateTime.parse(readDate, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.S"));//本次抄表时间
+                            LocalDateTime previousTime = LocalDateTime.ofInstant(amountWaterUsedAmountDto.getLastrecorddate().toInstant(),ZoneId.systemDefault()); //上个帐期的结算抄表时间
+
+                            ReplaceMeterDto oldReplaceMeterDto = null;
+                            for(int i = 0;i<replaceMeterCountDto.getReplaceMeterDtoList().size();i++){
+                                LocalDateTime replaceTime = replaceMeterCountDto.getReplaceMeterDtoList().get(i).getReplaceTime();   //换表时间
+
+                                Duration duration1 = Duration.between(previousTime,replaceTime);
+                                Duration duration2 = Duration.between(replaceTime,currTime);
+                                if(duration1.toMillis() > 0  && duration2.toMinutes() > 0){
+                                    BigDecimal replaceEndData = new BigDecimal(replaceMeterCountDto.getReplaceMeterDtoList().get(i).getOldEnd()).setScale(2,BigDecimal.ROUND_DOWN);//换表中的旧表止度
+                                    BigDecimal replaceData = BigDecimal.ZERO;
+                                    if(oldReplaceMeterDto == null)
+                                        replaceData = tempReading;
+                                    else
+                                        replaceData = new BigDecimal(oldReplaceMeterDto.getNewBegin()).setScale(0,BigDecimal.ROUND_DOWN);//换表中的起度
+                                    BigDecimal oldMeterUse = replaceEndData.subtract(replaceData); //旧表用量
+
+                                    Amount = Amount.add(oldMeterUse);
+                                    replace = true;
+
+                                    oldReplaceMeterDto = replaceMeterCountDto.getReplaceMeterDtoList().get(i);
                                 }
-
-                                if(!replace){
-                                    if (readingNew.compareTo(tempReading) > 0)
-                                        Amount = Amount.add(readingNew.subtract(tempReading));
+                                else {
+                                    break;
                                 }
+                            }
 
+                            //新表用量
+                            if(oldReplaceMeterDto != null){
+                                BigDecimal replaceNewDate = new BigDecimal(oldReplaceMeterDto.getNewBegin()).setScale(0,BigDecimal.ROUND_DOWN);//换表中的新表起度
+                                BigDecimal newMeterUse = readingNew.subtract(replaceNewDate);//新表用量
+                                Amount = Amount.add(newMeterUse);
+                            }
+                        }
 
-                                //计量方式判断
-
-                                if (calculateway.equals(1))//按实际用量
-                                    payAmount = Amount;
-                                else if (calculateway.equals(2))//按固定量
-                                    payAmount = BigDecimal.valueOf(amountWaterUsedAmountDto.getFixedamount());
-                                else
-                                    payAmount = Amount;
+                        if(!replace){
+                            if (readingNew.compareTo(tempReading) > 0)
+                                Amount = Amount.add(readingNew.subtract(tempReading));
+                        }
 
-                                if (payAmount.compareTo(BigDecimal.ZERO) < 0) {
-                                    continue;
-                                }
+                        //计量方式判断
+                        if (calculateway.equals(1))//按实际用量
+                            payAmount = Amount;
+                        else if (calculateway.equals(2))//按固定量
+                            payAmount = BigDecimal.valueOf(amountWaterUsedAmountDto.getFixedamount());
+                        else
+                            payAmount = Amount;
 
-                                amountWaterUsedAmountDto.setReading(readingNew);
-                                amountWaterUsedAmountDto.setRecorddate(DateTimeUtil.parseDate(readDate, DateTimeUtil.DATE_TIME_FORMAT_SECOND));
-                                amountWaterUsedAmountDto.setAmount(Amount);
-                                amountWaterUsedAmountDto.setPayamount(payAmount);
+                        if (payAmount.compareTo(BigDecimal.ZERO) < 0) {
+                            continue;
+                        }
 
-                                updates.add(amountWaterUsedAmountDto);
+                        amountWaterUsedAmountDto.setReading(readingNew);
+                        amountWaterUsedAmountDto.setRecorddate(DateTimeUtil.parseDate(readDate, DateTimeUtil.DATE_TIME_FORMAT_SECOND));
+                        amountWaterUsedAmountDto.setAmount(Amount);
+                        amountWaterUsedAmountDto.setPayamount(payAmount);
 
-                            }
-                        }
+                        updates.add(amountWaterUsedAmountDto);
 
                     }
-                    if (updates.size() > 0) {
-                        //List<List<AmountWaterUsedAmountDto>> lists = Lists.partition(updates, 500);
-                        for (AmountWaterUsedAmountDto amountWaterUsedAmountDto : updates) {
-                            amountWaterUsedAmountMapper.batchUpdate(amountWaterUsedAmountDto);
-                        }
-                    }
                 }
 
-
-                log.info("水量同步结束:" + LocalDateTime.now());
-
             }
-
+            if (updates.size() > 0) {
+                //List<List<AmountWaterUsedAmountDto>> lists = Lists.partition(updates, 500);
+                for (AmountWaterUsedAmountDto amountWaterUsedAmount : updates) {
+                    amountWaterUsedAmountMapper.batchUpdate(amountWaterUsedAmount);
+                }
+            }
         }
 
 
-    }*/
+        log.info("水量同步结束:" + LocalDateTime.now());
+
+    }
 }

+ 22 - 6
smart-city-platform/src/main/java/com/bz/smart_city/service/impl/pay/AmountWaterUsedAmountServiceImpl.java

@@ -6,6 +6,7 @@ import com.bz.smart_city.commom.model.Pagination;
 import com.bz.smart_city.commom.model.ResultStatus;
 import com.bz.smart_city.commom.util.*;
 import com.bz.smart_city.dao.CustomerMapper;
+import com.bz.smart_city.dao.SiteMapper;
 import com.bz.smart_city.dao.pay.*;
 import com.bz.smart_city.dao.pay.archives.PayBaseCustomerandmeterrelaMapper;
 import com.bz.smart_city.dto.CustomerDto;
@@ -70,7 +71,7 @@ public class AmountWaterUsedAmountServiceImpl implements AmountWaterUsedAmountSe
     @Resource
     private PayFeeMapper payFeeMapper;
     @Resource
-    private CustomerMapper customerMapper;
+    private SiteMapper siteMapper;
 
     @Override
     public Pagination<AmountWaterUsedAmountDto> getList(String condition, String accountNumber, String accountName, String meterCode, String address, Integer year, Integer month, Integer state,
@@ -646,12 +647,12 @@ public class AmountWaterUsedAmountServiceImpl implements AmountWaterUsedAmountSe
         DeviceReplaceRecord deviceReplaceRecord=new DeviceReplaceRecord();
         //根据客户编号查询出客户id、站点id
         if(deviceReplaceRecordDto != null && StringUtils.isNotBlank(deviceReplaceRecordDto.getCustomerNo())){
-            CustomerDto customerDto = customerMapper.getCustomerByCustomerno(deviceReplaceRecordDto.getCustomerNo());
-            if(customerDto == null){
+            SiteinfoDto siteinfoDto = siteMapper.getSiteAndCustomerByCustomerNo(deviceReplaceRecordDto.getCustomerNo());
+            if(siteinfoDto == null){
                 throw  new ServiceException(ResultStatus.CLEARING_DATA_QUERY_NO_CUSTOMER);
             }
-            deviceReplaceRecord.setSiteId(customerDto.getSiteId());
-            deviceReplaceRecord.setCustomerId(customerDto.getId());
+            deviceReplaceRecord.setSiteId(siteinfoDto.getId());
+            deviceReplaceRecord.setCustomerId(siteinfoDto.getCustomerId());
         }else{
             throw  new ServiceException(ResultStatus.LACK_NECESSARY_PARAM);
         }
@@ -670,9 +671,16 @@ public class AmountWaterUsedAmountServiceImpl implements AmountWaterUsedAmountSe
         AmountWaterUsedAmount amountWaterUsedAmount = amountWaterUsedAmountMapper.getLastReadrecord(deviceReplaceRecordDto.getMetercode(),deviceReplaceRecord.getSiteId(),deviceReplaceRecord.getCustomerId());
         if(amountWaterUsedAmount == null || amountWaterUsedAmount.getAmount() == null){
             //无上次抄表数据则取水表起度
-
+            BaseWatermeterDto baseWatermeterDto = amountWaterUsedAmountMapper.getWatermeterInfoByMetercode(deviceReplaceRecordDto.getMetercode(),deviceReplaceRecord.getSiteId(),deviceReplaceRecord.getCustomerId());
+            if(baseWatermeterDto == null || baseWatermeterDto.getStratcount() == null){
+                throw  new ServiceException("未查询到设备信息");
+            }else{
+                deviceReplaceRecord.setOldLastreading(baseWatermeterDto.getStratcount());
+                deviceReplaceRecord.setWatermeterId(baseWatermeterDto.getId());
+            }
         }else{
             deviceReplaceRecord.setOldLastreading(amountWaterUsedAmount.getAmount());
+            deviceReplaceRecord.setWatermeterId(amountWaterUsedAmount.getWatermeterId());
         }
         //计算出旧表水量
         deviceReplaceRecord.setOldAmount(deviceReplaceRecordDto.getOldReading().subtract(deviceReplaceRecord.getOldLastreading()));
@@ -686,6 +694,14 @@ public class AmountWaterUsedAmountServiceImpl implements AmountWaterUsedAmountSe
         deviceReplaceRecord.setNewStartcount(deviceReplaceRecordDto.getNewStartcount());
         deviceReplaceRecord.setRemarks("换表同步");
         amountWaterUsedAmountMapper.insertReplaceRecord(deviceReplaceRecord);
+        //修改水表信息电子号和起度
+        BaseWatermeterDto watermeterDto = new BaseWatermeterDto();
+        watermeterDto.setId(deviceReplaceRecord.getWatermeterId());
+        watermeterDto.setEleno(deviceReplaceRecord.getNewEleno());
+        watermeterDto.setStratcount(deviceReplaceRecord.getNewStartcount());
+        watermeterDto.setUpdateBy(new BigInteger("1"));
+        watermeterDto.setUpdateDate(LocalDateTime.now());
+        amountWaterUsedAmountMapper.updateWatermeterInfo(watermeterDto);
 
     }
 

+ 4 - 1
smart-city-platform/src/main/java/com/bz/smart_city/service/impl/pay/PayBaseAccountServiceImpl.java

@@ -405,5 +405,8 @@ public class PayBaseAccountServiceImpl implements PayBaseAccountService {
         return accountNumber;
     }
 
-
+    @Override
+    public List<SynAccountInfo> getSynAccountInfo( String createDate){
+        return payBaseAccountMapper.getSynAccountInfo(createDate);
+    }
 }

+ 2 - 2
smart-city-platform/src/main/java/com/bz/smart_city/service/pay/PayBaseAccountService.java

@@ -6,7 +6,6 @@ import com.bz.smart_city.dto.pay.*;
 import com.bz.smart_city.entity.pay.PayBaseAccount;
 import com.bz.smart_city.entity.pay.PayMeter;
 
-import java.math.BigInteger;
 import java.util.List;
 
 
@@ -36,8 +35,9 @@ public interface PayBaseAccountService {
 
     Pagination<PayMeter>findMeter(String queryInfo, String state, Integer pageNum, Integer pageSize);
 
-    //鏍规嵁瀹夎�璁″垝ID鍒犻櫎鐢ㄦ埛淇℃伅
+    //根据安装计划ID删除用户信息
     int delByPlanId(BigInteger planId);
 
     int getMaxAccountNumber(String CommunityCode);
+    List<SynAccountInfo> getSynAccountInfo(String createDate);
 }

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

@@ -106,5 +106,4 @@ service.domain=http:/127.0.0.1
 invoice.print.url=http://nnfpbox.nuonuocs.cn/shop/buyer/allow/cxfKp/cxfServerKpOrderSync.action
 invoice.query.url=http://nnfpbox.nuonuocs.cn/shop/buyer/allow/ecOd/queryElectricKp.action
 
-#抄表数据同步接口
-Sync.Data.Url=http://114.135.61.188:58080
+

+ 1 - 1
smart-city-platform/src/main/resources/mapper/CustomerMapper.xml

@@ -244,7 +244,7 @@
         </if>
     </select>
     <select id="getListById" resultMap="BaseResultMap">
-        select id,customer_name from sc_customer where status = 1
+        select id,customer_name,customer_no from sc_customer where status = 1
         and id = #{customerId}
     </select>
     <select id="getCustomerTree" resultType="com.bz.smart_city.dto.CustomerDto">

+ 12 - 0
smart-city-platform/src/main/resources/mapper/SiteMapper.xml

@@ -192,5 +192,17 @@
         select count(1) from sc_site where status = 1 and customer_id = #{customerId}
         <if test="id != null"> and id != #{id}</if>
     </select>
+
+    <select id="getSiteAndCustomerByCustomerNo" resultType="com.bz.smart_city.dto.pay.SiteinfoDto">
+       select
+            s.id,
+            s.name as "siteName",
+            s.customer_id,
+            c.customer_no,
+            c.customer_name as "customerName"
+        from sc_site s
+        left join sc_customer c on s.customer_id=c.id
+        where c.customer_no=#{customerNo}
+    </select>
 </mapper>
 

+ 171 - 61
smart-city-platform/src/main/resources/mapper/pay/AmountWaterUsedAmountMapper.xml

@@ -216,6 +216,7 @@
 		select  amount.id,
 				amount.lastreading,
 				amount.ele_no eleNo,
+				amount.metercode metercode,
 				rela.calculateway,
 				rela.fixedamount,
 				amount.watermeter_id watermeterId,
@@ -480,67 +481,6 @@
 	group by c.customer_id, c.site_id
 	</select>
 
-	<resultMap id="ReplaceMeterMap" type="com.bz.smart_city.dto.pay.ReplaceMeterDto">
-
-	</resultMap>
-
-	<select id ="getRepalceRecord" resultMap="ReplaceMeterMap">
-		SELECT
-			pc.device_id AS deviceId,
-			pc.date_create AS replaceTime,
-			pc.new_begin_wsv AS newBegin,
-			pc.old_end_wsv AS oldEnd
-		FROM
-		(
-			SELECT
-				pc2.id,
-				MAX( pc2.date_create ) AS dateCreate
-			FROM
-				sc_water_meter_replace_log pc2
-				<where>
-					<if test="list != null and list.size() != 0">
-						pc2.device_id IN
-						<foreach collection="list" item="listItem" open="(" close=")" separator=",">
-							<if test="listItem != null and listItem != ''">
-								#{listItem}
-							</if>
-						</foreach>
-					</if>
-				</where>
-
-			GROUP BY
-			pc2.id
-		) a
-		LEFT JOIN sc_water_meter_replace_log pc ON a.id = pc.id
-
-	</select>
-
-	<resultMap id="ReplaceMeterCountMap" type="com.bz.smart_city.dto.pay.ReplaceMeterCountDto">
-
-	</resultMap>
-	<select id="getRepalceRecordCount" resultMap="ReplaceMeterCountMap">
-		SELECT
-			COUNT(*) as number,
-			pc.device_id AS deviceId
-		FROM sc_water_meter_replace_log pc LEFT JOIN sc_device scd on pc.device_id = scd.id
-		<where>
-			<if test="stTime != null"> and pc.date_create >= #{stTime,jdbcType=TIMESTAMP}</if>
-			<if test="etTime != null"> and pc.date_create &lt;= #{etTime,jdbcType=TIMESTAMP}</if>
-			<if test="siteId != null"> and scd.site_id = #{siteId}</if>
-			<if test="customerId != null"> and scd.customer_id = #{customerId}</if>
-			<if test="list != null and list.size() != 0">
-				and pc.device_id IN
-				<foreach collection="list" item="listItem" open="(" close=")" separator=",">
-					<if test="listItem != null and listItem != ''">
-						#{listItem}
-					</if>
-				</foreach>
-			</if>
-
-		</where>
-			GROUP BY pc.device_id
-	</select>
-
 	<select id ="getRepalceRecordDetail" resultType="com.bz.smart_city.dto.pay.ReplaceMeterDto">
 		SELECT
 		pc.device_id AS deviceId,
@@ -578,11 +518,45 @@
 		order by a.approvetime desc
 		limit 1
 	</select>
+	<select id="getWatermeterInfoByMetercode" resultType="com.bz.smart_city.dto.pay.BaseWatermeterDto">
+		select
+			id
+			,metercode
+			,water_meter_no as "eleno"
+			,new_meter_start  as "stratcount"
+		from sc_device
+		where site_id=#{siteId}
+		and customer_id=#{customerId}
+		and metercode=#{metercode}
+	</select>
+
+	<update id="updateWatermeterInfo">
+		update sc_device set
+		<set>
+			<if test="metercode != null and metercode != ''">
+				metercode=#{metercode},
+			</if>
+			<if test="eleno != null and eleno != ''">
+				water_meter_no = #{eleno},
+			</if>
+			<if test="stratcount != null ">
+				new_meter_start = #{stratcount},
+			</if>
+			<if test="updateBy != null ">
+				update_by = #{updateBy},
+			</if>
+			<if test="updateDate != null ">
+				date_update = #{updateDate},
+			</if>
+		</set>
+		where id=#{id}
+	</update>
 
 	<insert id="insertReplaceRecord">
 
 		insert into pay_device_replace_record
 		(
+			watermeter_id,
 			metercode,
 			old_eleno,
 			new_eleno,
@@ -597,6 +571,7 @@
 			year,
 			month)
 		value(
+			#{watermeterId},
 			#{metercode},
 			#{oldEleno},
 			#{newEleno},
@@ -612,4 +587,139 @@
 			#{month})
 	</insert>
 
+	<insert id="insertSelectAmountBaseInfo">
+	insert into pay_amount_waterusedamount (
+		customerandmeterrela_id
+		,office_id
+		,lastreading
+		,lastrecorddate
+		,metercode
+		,watermeter_id
+		,month
+		,state
+		,waterproperty_id
+		,year
+		,account_id
+		,accountname
+		,accountnumber
+		,watertype
+		,isprint
+		,ele_no
+		,create_by
+		,create_date
+		,update_by
+		,update_date
+		,remarks
+		,del_flag
+		,site_id
+		,customer_id
+		)
+		select
+		c.id as customerandmeterrela_id
+		,c.office_id
+		,ifnull(amount.reading,d.new_meter_start) as lastreading
+		,ifnull(amount.recorddate,d.date_create) as lastrecorddate
+		,c.metercode
+		,c.watermeter_id
+		,#{month}
+		,1
+		,p.id as waterproperty_id
+		,#{year}
+		,c.account_id
+		,c.accountname
+		,c.accountnumber
+		,c.watertype
+		,0
+		,d.water_meter_no as ele_no
+		,'1'
+		,now()
+		,'1'
+		,now()
+		,'抄表计划'
+		,'0'
+		,#{siteId}
+		,#{customerId}
+		from pay_base_customerandmeterrela c
+		left join pay_base_waterproperty p on c.waterproperty_id=p.id
+		left join sc_device d on c.watermeter_id=d.id
+		left join (
+			select
+			a.watermeter_id,
+			a.reading,
+			a.recorddate
+			from (
+				select
+					ele_no
+					,max(create_date) create_date
+				from pay_amount_waterusedamount
+				where state =2
+				group by ele_no
+			)	aLast
+			left join pay_amount_waterusedamount a on a.ele_no=aLast.ele_no and a.create_date=aLast.create_date
+		) amount on amount.watermeter_id=c.watermeter_id
+		where c.businessstate= 1 and c.site_id=#{siteId} and c.customer_id=#{customerId}
+	</insert>
+
+	<select id="getSynAmountMetercode" resultType="java.lang.String">
+		select metercode from pay_amount_waterusedamount
+ 		where year = #{year} and month = #{month} and  site_id = #{siteId} and customer_id=#{customerId}
+	</select>
+
+	<resultMap id="AmountSynParam" type="com.bz.smart_city.dto.pay.AmountSynParamDto">
+		<result  column="yyyymm" property="yyyymm" jdbcType="VARCHAR"/>
+		<result  column="customerNo" property="customerNo"  jdbcType="VARCHAR" />
+		<collection property="fileNo" resultMap="metercodes" />
+	</resultMap>
+
+	<resultMap id="metercodes" type="java.lang.String">
+		<result column="metercode"/>
+	</resultMap>
+
+	<select id="GetAmountSynMeterInfo" resultMap="AmountSynParam">
+		select
+			concat(year,month) as "yyyymm"
+			,c.customer_no as "customerNo"
+			,a.metercode as "metercode"
+		from pay_amount_waterusedamount a
+		left join sc_customer c on a.customer_id=c.id
+		where a.customer_id=#{customerId} and a.site_id=#{siteId}
+		and a.`year`=#{year} and a.`month`=#{month}
+	</select>
+
+	<select id="GetAmountSynInfo" resultType="java.lang.String">
+		select
+			a.metercode as "metercode"
+		from pay_amount_waterusedamount a
+		left join sc_customer c on a.customer_id=c.id
+		where a.customer_id=#{customerId} and a.site_id=#{siteId}
+		and a.`year`=#{year} and a.`month`=#{month}
+	</select>
+
+	<resultMap id="ReplaceMeterCountMap" type="com.bz.smart_city.dto.pay.ReplaceMeterCountDto">
+
+	</resultMap>
+	<select id="getRepalceRecordCount" resultMap="ReplaceMeterCountMap">
+		SELECT
+		COUNT(*) as number,
+		pc.device_id AS deviceId
+		FROM sc_water_meter_replace_log pc LEFT JOIN sc_device scd on pc.device_id = scd.id
+		<where>
+			<if test="stTime != null"> and pc.date_create >= #{stTime,jdbcType=TIMESTAMP}</if>
+			<if test="etTime != null"> and pc.date_create &lt;= #{etTime,jdbcType=TIMESTAMP}</if>
+			<if test="siteId != null"> and scd.site_id = #{siteId}</if>
+			<if test="customerId != null"> and scd.customer_id = #{customerId}</if>
+			<if test="list != null and list.size() != 0">
+				and pc.device_id IN
+				<foreach collection="list" item="listItem" open="(" close=")" separator=",">
+					<if test="listItem != null and listItem != ''">
+						#{listItem}
+					</if>
+				</foreach>
+			</if>
+
+		</where>
+		GROUP BY pc.device_id
+	</select>
+
+
 </mapper>

+ 13 - 0
smart-city-platform/src/main/resources/mapper/pay/PayBaseAccountMapper.xml

@@ -530,4 +530,17 @@
             update pay_pay_messagesendrecord set accountname =#{accountname} where account_id =#{accountId}
         </if>
     </update>
+    <select id="getSynAccountInfo" resultType="com.bz.smart_city.dto.pay.SynAccountInfo">
+        select
+            a.accountnumber as "accountNumber"
+            ,a.name as "accountName"
+            ,a.mobilephone as "accountPhone"
+            ,c.metercode as "fileNo"
+            ,c.create_date as "createDate"
+        from pay_base_customerandmeterrela c
+        left join pay_base_account a on c.account_id=a.id
+        <if test="createDate != null and createDate != ''">
+            where DATE_FORMAT( c.create_date, "%Y%m%d" ) = #{createDate}
+        </if>
+    </select>
 </mapper>