|
@@ -75,7 +75,7 @@ public class AmountSynByDayServiceImpl implements AmountSynByDayService, Initial
|
|
|
|
|
|
boolean exists = jobAndTriggerService.isExists(entity);
|
|
|
if(!exists){
|
|
|
- String cron = "0 */5 * * * ?";
|
|
|
+ String cron = "0 */1 * * * ?";
|
|
|
log.info("水量每天同步:" + cron);
|
|
|
entity.setCronExpression(cron);
|
|
|
entity.setJobClassName(AmountSyncByDayJob.class.getName());
|
|
@@ -117,7 +117,6 @@ public class AmountSynByDayServiceImpl implements AmountSynByDayService, Initial
|
|
|
}
|
|
|
log.info("抄表计划生成完成:" + LocalDateTime.now());
|
|
|
|
|
|
-
|
|
|
log.info("每天水量同步开始:" + LocalDateTime.now());
|
|
|
|
|
|
//获取设备id
|
|
@@ -125,18 +124,42 @@ public class AmountSynByDayServiceImpl implements AmountSynByDayService, Initial
|
|
|
if (idList != null && idList.size() > 0) {
|
|
|
//获取同步数据
|
|
|
HashMap<BigInteger, MeterReadRecordDto> meterReadRecordHashMap = new HashMap<>();
|
|
|
- HashMap<BigInteger, ReplaceMeterDto> replaceMap = new HashMap<>();
|
|
|
+ HashMap<BigInteger, ReplaceMeterCountDto> replaceMap = new HashMap<>();
|
|
|
+
|
|
|
+ LocalDateTime stTime = null;
|
|
|
+ //获取上一帐期结算时间,用于查询换表
|
|
|
+ List<BaseClosingAccountInfoDto> baseClosingAccountInfoDtos = baseClosingAccountInfoMapper.getList(null,null,BigInteger.valueOf(siteId),BigInteger.valueOf(customerId),0);
|
|
|
+ if(baseClosingAccountInfoDtos.size() > 0){
|
|
|
+ stTime = LocalDateTime.ofInstant(baseClosingAccountInfoDtos.get(0).getStartTime().toInstant(),ZoneId.systemDefault());
|
|
|
+ }
|
|
|
|
|
|
List<List<BigInteger>> lists = Lists.partition(idList, 500);
|
|
|
- for (List<BigInteger> bigIntegers :
|
|
|
- lists) {
|
|
|
+ for (List<BigInteger> bigIntegers : lists) {
|
|
|
HashMap<BigInteger, MeterReadRecordDto> childMap = amountWaterUsedAmountMapper.getMeterReadRecord(bigIntegers);
|
|
|
meterReadRecordHashMap.putAll(childMap);
|
|
|
|
|
|
- //查询换表信息(取最近一次换表)
|
|
|
- HashMap<BigInteger, ReplaceMeterDto> childReplaceMap =amountWaterUsedAmountMapper.getRepalceRecord(bigIntegers);
|
|
|
- replaceMap.putAll(childReplaceMap);
|
|
|
+ //查询换表信息(上一帐期结束时间至当前时间所有换表)
|
|
|
+ //HashMap<BigInteger, ReplaceMeterDto> childReplaceMap =amountWaterUsedAmountMapper.getRepalceRecord(bigIntegers);
|
|
|
+ //replaceMap.putAll(childReplaceMap);
|
|
|
+ HashMap<BigInteger, ReplaceMeterCountDto> childReplaceMap = amountWaterUsedAmountMapper.getRepalceRecordCount(stTime,null,bigIntegers);
|
|
|
+ if(childReplaceMap.size() >0){
|
|
|
+ List<ReplaceMeterDto> replaceMeterDtoList = amountWaterUsedAmountMapper.getRepalceRecordDetail(stTime,null,bigIntegers);
|
|
|
+ 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);
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
if(meterReadRecordHashMap.size()>0) {
|
|
|
//批量更新水量信息
|
|
|
List<AmountWaterUsedAmountByDay> updates = new ArrayList<>();
|
|
@@ -158,30 +181,50 @@ public class AmountSynByDayServiceImpl implements AmountSynByDayService, Initial
|
|
|
Integer calculateway = amountWaterUsedAmountDto.getCalculateway();
|
|
|
|
|
|
//取换表记录
|
|
|
- ReplaceMeterDto replaceMeterDto = null;
|
|
|
+ ReplaceMeterCountDto replaceMeterCountDto=null;
|
|
|
if(replaceMap.containsKey(watermeterId)){
|
|
|
- replaceMeterDto = replaceMap.get(watermeterId);
|
|
|
+ replaceMeterCountDto = replaceMap.get(watermeterId);
|
|
|
}
|
|
|
|
|
|
//有换表记录且换表时间在两次同步之间 用水量=(换表中的旧表止度-上次抄表止度) + (本次止度-换表中的新表起度)
|
|
|
boolean replace = false;
|
|
|
- if(replaceMeterDto != null){
|
|
|
-
|
|
|
- LocalDateTime currTime = LocalDateTime.ofInstant(meterReadRecord.getReadTime().toInstant(),ZoneId.systemDefault()); //本次抄表时间
|
|
|
- LocalDateTime previousTime = LocalDateTime.ofInstant(amountWaterUsedAmountDto.getLastrecorddate().toInstant(),ZoneId.systemDefault()); //上次抄表时间
|
|
|
- LocalDateTime replaceTime = replaceMeterDto.getReplaceTime(); //换表时间
|
|
|
- Duration duration1 = Duration.between(previousTime,replaceTime);
|
|
|
- Duration duration2 = Duration.between(replaceTime,currTime);
|
|
|
- if(duration1.toMillis() > 0 && duration2.toMinutes() > 0){
|
|
|
- BigDecimal replaceEndData = new BigDecimal(replaceMeterDto.getOldEnd()).setScale(0,BigDecimal.ROUND_DOWN);//换表中的旧表止度
|
|
|
- BigDecimal repllaceNewbegin = new BigDecimal(replaceMeterDto.getNewBegin()).setScale(0,BigDecimal.ROUND_DOWN);//换表中的新表起度
|
|
|
-
|
|
|
- BigDecimal oldMeterUse = replaceEndData.subtract(tempReading); //旧表用量
|
|
|
- BigDecimal newMeterUse = readingNew.subtract(repllaceNewbegin);//新表用量
|
|
|
- Amount = oldMeterUse.add(newMeterUse);
|
|
|
-
|
|
|
- replace = true;
|
|
|
+ if(replaceMeterCountDto != null){
|
|
|
+ LocalDateTime currTime = LocalDateTime.ofInstant(readDate.toInstant(),ZoneId.systemDefault()); //本次抄表时间
|
|
|
+ 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(0,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);
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
if(!replace){
|