|
@@ -7,10 +7,7 @@ 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.ClearingDataDTO;
|
|
|
-import com.bz.smart_city.dto.pay.AmountWaterUsedAmountDto;
|
|
|
-import com.bz.smart_city.dto.pay.BaseClosingAccountInfoDto;
|
|
|
-import com.bz.smart_city.dto.pay.MeterReadRecordDto;
|
|
|
-import com.bz.smart_city.dto.pay.PayBaseConfigDto;
|
|
|
+import com.bz.smart_city.dto.pay.*;
|
|
|
import com.bz.smart_city.entity.ClearingRecord;
|
|
|
import com.bz.smart_city.entity.MeterReadRecord;
|
|
|
import com.bz.smart_city.entity.pay.AmountWaterUsedAmountByDay;
|
|
@@ -22,6 +19,7 @@ import com.bz.smart_city.quartz.service.JobAndTriggerService;
|
|
|
import com.bz.smart_city.service.pay.AmountSynByDayService;
|
|
|
import com.bz.smart_city.service.pay.AmountSynService;
|
|
|
import com.google.common.collect.Lists;
|
|
|
+import com.sun.org.apache.xpath.internal.operations.Bool;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.InitializingBean;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
@@ -30,8 +28,10 @@ import org.springframework.stereotype.Component;
|
|
|
import javax.annotation.Resource;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.BigInteger;
|
|
|
+import java.time.Duration;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.*;
|
|
|
+import java.time.ZoneId;
|
|
|
|
|
|
/**
|
|
|
* @author Administrator
|
|
@@ -125,12 +125,17 @@ public class AmountSynByDayServiceImpl implements AmountSynByDayService, Initial
|
|
|
if (idList != null && idList.size() > 0) {
|
|
|
//获取同步数据
|
|
|
HashMap<BigInteger, MeterReadRecordDto> meterReadRecordHashMap = new HashMap<>();
|
|
|
+ HashMap<BigInteger, ReplaceMeterDto> replaceMap = new HashMap<>();
|
|
|
|
|
|
List<List<BigInteger>> lists = Lists.partition(idList, 500);
|
|
|
for (List<BigInteger> bigIntegers :
|
|
|
lists) {
|
|
|
- HashMap<BigInteger, MeterReadRecordDto> childMap = amountWaterUsedAmountMapper.getMeterReadRecord(idList);
|
|
|
+ HashMap<BigInteger, MeterReadRecordDto> childMap = amountWaterUsedAmountMapper.getMeterReadRecord(bigIntegers);
|
|
|
meterReadRecordHashMap.putAll(childMap);
|
|
|
+
|
|
|
+ //查询换表信息(取最近一次换表)
|
|
|
+ HashMap<BigInteger, ReplaceMeterDto> childReplaceMap =amountWaterUsedAmountMapper.getRepalceRecord(bigIntegers);
|
|
|
+ replaceMap.putAll(childReplaceMap);
|
|
|
}
|
|
|
if(meterReadRecordHashMap.size()>0) {
|
|
|
//批量更新水量信息
|
|
@@ -138,7 +143,6 @@ public class AmountSynByDayServiceImpl implements AmountSynByDayService, Initial
|
|
|
//更新数据
|
|
|
List<AmountWaterUsedAmountByDay> amountWaterUsedAmountDtos = amountWaterUsedAmountMapper.getAllAmountRecordByDay(siteId, customerId);
|
|
|
|
|
|
-
|
|
|
for (AmountWaterUsedAmountByDay amountWaterUsedAmountDto : amountWaterUsedAmountDtos) {
|
|
|
BigInteger watermeterId = amountWaterUsedAmountDto.getWatermeterId();
|
|
|
if (watermeterId != null && meterReadRecordHashMap.containsKey(watermeterId)) {
|
|
@@ -153,8 +157,38 @@ public class AmountSynByDayServiceImpl implements AmountSynByDayService, Initial
|
|
|
Date readDate = meterReadRecord.getReadTime() != null ? meterReadRecord.getReadTime() : new Date();
|
|
|
Integer calculateway = amountWaterUsedAmountDto.getCalculateway();
|
|
|
|
|
|
- if (readingNew.compareTo(tempReading) > 0)
|
|
|
- Amount = Amount.add(readingNew.subtract(tempReading));
|
|
|
+ //取换表记录
|
|
|
+ ReplaceMeterDto replaceMeterDto = null;
|
|
|
+ if(replaceMap.containsKey(watermeterId)){
|
|
|
+ replaceMeterDto = 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(!replace.booleanValue()){
|
|
|
+ if (readingNew.compareTo(tempReading) > 0){
|
|
|
+ Amount = Amount.add(readingNew.subtract(tempReading));
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
//计量方式判断
|
|
|
|