Browse Source

定时同步水量优化(支持多次换表)、报表日期格式修改

zhoujiangyuan 4 years ago
parent
commit
8103543d45

+ 10 - 6
smart-city-platform/src/main/java/com/bz/smart_city/controller/pay/PayReportController.java

@@ -39,8 +39,8 @@ public class PayReportController {
             @ApiParam(value = "机构ID", required = false) @RequestParam(required = false) Integer officeId,
             @ApiParam(value = "支付方式ID,字典类:type=支付方式", required = false) @RequestParam(required = false) Integer payway,
             @ApiParam(value = "收费员ID",required = false)@RequestParam(required = false) Integer operateId,
-            @ApiParam(value = "开始时间yyyyMMddhhmmss", required = false) @RequestParam(required = false) String beginTime,
-            @ApiParam(value = "结束时间yyyyMMddhhmmss", required = false) @RequestParam(required = false) String endTime,
+            @ApiParam(value = "开始时间yyyyMMdd", required = false) @RequestParam(required = false) String beginTime,
+            @ApiParam(value = "结束时间yyyyMMdd", required = false) @RequestParam(required = false) String endTime,
             @ApiParam(value = "页数,非必传,默认第一页", required = false, defaultValue = "1") @RequestParam(required = false, defaultValue = "1") int pageNum,
             @ApiParam(value = "条数,非必传,默认10条", required = false, defaultValue = "10") @RequestParam(required = false, defaultValue = "10") int pageSize
     ){
@@ -53,9 +53,11 @@ public class PayReportController {
         inParams.setCreateBy(new BigInteger(String.valueOf(operateId)));
 
         if(StringUtils.isNotBlank(beginTime)){
+            beginTime = beginTime +"000000";
             inParams.setBeginTime( LocalDateTime.parse(beginTime,df));
         }
         if(StringUtils.isNotBlank(endTime)){
+            endTime = endTime + "235959";
             inParams.setEndTime(LocalDateTime.parse(endTime, df));
         }
 
@@ -66,12 +68,12 @@ public class PayReportController {
     @ApiOperation(value="收费员明细报表")
     @GetMapping("/getPayOperatordetailsReport")
     public AjaxMessage<Pagination<PayOperatordetailsReportDto>> getPayOperatordetailsReport(
-            @ApiParam(value = "小区ID", required = false) @RequestParam(required = false) String communityId,
+            @ApiParam(value = "小区code", required = false) @RequestParam(required = false) String communityId,
             @ApiParam(value = "收费员ID",required = false)@RequestParam(required = false) Integer operateId,
             @ApiParam(value = "小计值(与小计状态一起使用,如查询小计值大于100的)",required = false) @RequestParam(required = false) BigDecimal subtotal,
             @ApiParam(value = "小计状态,0等于,1小于,2大于",required = false) @RequestParam(required = false) Integer subtotalSt,
-            @ApiParam(value = "开始时间yyyyMMddhhmmss", required = false) @RequestParam(required = false) String beginTime,
-            @ApiParam(value = "结束时间yyyyMMddhhmmss", required = false) @RequestParam(required = false) String endTime,
+            @ApiParam(value = "开始时间yyyyMMdd", required = false) @RequestParam(required = false) String beginTime,
+            @ApiParam(value = "结束时间yyyyMMdd", required = false) @RequestParam(required = false) String endTime,
             @ApiParam(value = "页数,非必传,默认第一页", required = false, defaultValue = "1") @RequestParam(required = false, defaultValue = "1") int pageNum,
             @ApiParam(value = "条数,非必传,默认10条", required = false, defaultValue = "10") @RequestParam(required = false, defaultValue = "10") int pageSize
 
@@ -82,9 +84,11 @@ public class PayReportController {
         if(operateId != null)
             inParams.setCreateBy(new BigInteger(String.valueOf(operateId)));
         if(StringUtils.isNotBlank(beginTime)){
+            beginTime = beginTime +"000000";
             inParams.setBeginTime( LocalDateTime.parse(beginTime,df));
         }
         if(StringUtils.isNotBlank(endTime)){
+            endTime = endTime + "235959";
             inParams.setEndTime(LocalDateTime.parse(endTime, df));
         }
         if(subtotal != null)
@@ -101,7 +105,7 @@ public class PayReportController {
     @GetMapping("/getPayArrearagedetailsReport")
     public AjaxMessage<Pagination<PayArrearagedetailsReportDto>> getPayArrearagedetailsReport(
             @ApiParam(value = "机构ID", required = false) @RequestParam(required = false) Integer officeId,
-            @ApiParam(value = "小区ID", required = false) @RequestParam(required = false) String communityId,
+            @ApiParam(value = "小区code", required = false) @RequestParam(required = false) String communityId,
             @ApiParam(value = "用户编码(模糊查询)", required = false) @RequestParam(required = false) String accountNumber,
             @ApiParam(value = "页数,非必传,默认第一页", required = false, defaultValue = "1") @RequestParam(required = false, defaultValue = "1") int pageNum,
             @ApiParam(value = "条数,非必传,默认10条", required = false, defaultValue = "10") @RequestParam(required = false, defaultValue = "10") int pageSize

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

@@ -2,6 +2,7 @@ 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.entity.MeterReadRecord;
 import com.bz.smart_city.entity.ProgramItem;
@@ -13,6 +14,7 @@ import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 
 import java.math.BigInteger;
+import java.time.LocalDateTime;
 import java.util.HashMap;
 import java.util.List;
 
@@ -69,4 +71,11 @@ public interface AmountWaterUsedAmountMapper {
     @MapKey("deviceId")
     HashMap<BigInteger, ReplaceMeterDto> getRepalceRecord(@Param("list")List<BigInteger> list);
 
+    //换表明细
+    List<ReplaceMeterDto> getRepalceRecordDetail(@Param("stTime")LocalDateTime stTime,@Param("etTime")LocalDateTime etTime,@Param("list")List<BigInteger> list);
+
+    //换表统计
+    @MapKey("deviceId")
+    HashMap<BigInteger, ReplaceMeterCountDto> getRepalceRecordCount(@Param("stTime")LocalDateTime stTime, @Param("etTime")LocalDateTime etTime, @Param("list")List<BigInteger> list);
+
 }

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

@@ -0,0 +1,24 @@
+package com.bz.smart_city.dto.pay;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.math.BigInteger;
+import java.util.List;
+
+/**
+ * @Author: ZJY
+ * @DATE: 2020-08-03 17:13
+ */
+@Data
+public class ReplaceMeterCountDto {
+
+    @ApiModelProperty(value="设备ID")
+    private BigInteger deviceId;
+
+    private Integer number;
+
+    private List<ReplaceMeterDto> replaceMeterDtoList;
+
+}
+

+ 69 - 26
smart-city-platform/src/main/java/com/bz/smart_city/service/impl/pay/AmountSynByDayServiceImpl.java

@@ -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){

+ 46 - 1
smart-city-platform/src/main/resources/mapper/pay/AmountWaterUsedAmountMapper.xml

@@ -396,7 +396,6 @@ SELECT
 			a.watermeter_id
 		from pay_amount_waterusedamount_day a
 		<where>
-
 			a.read_date=DATE_FORMAT(DATE_SUB(now(),INTERVAL 1 day) ,'%Y%m%d')
 			<if test="customerId!= null" >and a.customer_id = #{customerId} </if>
 			<if test="siteId!= null" > and a.site_id = #{siteId} </if>
@@ -474,4 +473,50 @@ SELECT
 
 	</select>
 
+	<resultMap id="ReplaceMeterCountMap" type="com.bz.smart_city.dto.pay.ReplaceMeterCountDto">
+
+	</resultMap>
+	<select id="getRepalceRecordCount" resultMap="ReplaceMeterCountMap">
+		SELECT
+			COUNT(*) as number,
+			device_id AS deviceId
+		FROM sc_water_meter_replace_log
+		<where>
+			<if test="stTime != null"> and date_create >= #{stTime,jdbcType=TIMESTAMP}</if>
+			<if test="etTime != null"> and date_create &lt;= #{etTime,jdbcType=TIMESTAMP}</if>
+
+			and device_id IN
+			<foreach collection="list" item="listItem" open="(" close=")" separator=",">
+				<if test="listItem != null and listItem != ''">
+					#{listItem}
+				</if>
+			</foreach>
+
+
+		</where>
+			GROUP BY device_id
+	</select>
+
+	<select id ="getRepalceRecordDetail" resultType="com.bz.smart_city.dto.pay.ReplaceMeterDto">
+		SELECT
+		pc.device_id AS deviceId,
+		pc.date_create AS replaceTime,
+		pc.new_begin_wsv AS newBegin,
+		pc.old_end_wsv AS oldEnd
+		FROM
+		sc_water_meter_replace_log pc
+		<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>
+
+			and pc.device_id IN
+			<foreach collection="list" item="listItem" open="(" close=")" separator=",">
+				<if test="listItem != null and listItem != ''">
+					#{listItem}
+				</if>
+			</foreach>
+
+		</where>
+
+	</select>
 </mapper>