Bläddra i källkod

水量同步服务修改

wangli 4 år sedan
förälder
incheckning
29879aaf0c

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

@@ -17,10 +17,12 @@ public class AmountSynRespDto implements Serializable {
 
     private static final long serialVersionUID = -4057222618378320320L;
 
-    @ApiModelProperty("本期抄表日期")
+    @ApiModelProperty("结算数据抄表日期")
     private  String currentPeriodDate;
     @ApiModelProperty("水表档案号")
     private  String fileNo;
     @ApiModelProperty("本期读数")
     private  String reading;
+    @ApiModelProperty("抄表时间")
+    private  String readTime;
 }

+ 3 - 0
smart-city-platform/src/main/java/com/bz/smart_city/quartz/service/AmountSynService.java

@@ -2,8 +2,11 @@ package com.bz.smart_city.quartz.service;
 
 import com.bz.smart_city.dto.pay.PayBaseConfigDto;
 
+import java.math.BigInteger;
+
 public interface AmountSynService {
 
     void saveQrtzTask(PayBaseConfigDto payBaseConfigDto);
+    void deleteQrtzTask(BigInteger id);
     void amountUpdate(Integer siteId, Integer customerId);
 }

+ 16 - 16
smart-city-platform/src/main/java/com/bz/smart_city/quartz/service/impl/AmountSynDayServiceImpl.java

@@ -29,11 +29,9 @@ import java.math.BigDecimal;
 import java.math.BigInteger;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
+import java.time.ZoneId;
 import java.time.format.DateTimeFormatter;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.function.Function;
 import java.util.stream.Collectors;
 
@@ -79,7 +77,7 @@ public class AmountSynDayServiceImpl implements AmountSynByDayService, Initializ
         // modify by pengdi ,判断定时任务是否存在,不存在才进行新增
 
         boolean exists = jobAndTriggerService.isExists(entity);
-        if(!exists){
+        if(!exists) {
             String cron = "0 */1 * * * ?";
             log.info("水量每天同步:" + cron);
             entity.setCronExpression(cron);
@@ -121,10 +119,7 @@ public class AmountSynDayServiceImpl implements AmountSynByDayService, Initializ
         Integer month=baseClosingAccountInfoDto.getMonth();
         //插入水量基础信息(同步计划)
         Integer amountNumber = amountWaterUsedAmountMapper.createdAmountByDay(siteId,customerId);
-        if(amountNumber == 0){
-            log.info("每天同步水量失败:生成同步计划失败");
-            return;
-        }
+
         //获取客户编号
         List<Customer> customers = customerMapper.getListById(customerId);
         if(customers .size() != 1){
@@ -153,16 +148,16 @@ public class AmountSynDayServiceImpl implements AmountSynByDayService, Initializ
         //抄表数据结果
         List<AmountSynRespDto> lists =new ArrayList<>();
 
-        for(int i=0;i<metercodes.size();i+=500){
+        for(int i=0;i<metercodes.size();i+=30){
             AmountDaySynParamDto amountDaySynParamDto= new AmountDaySynParamDto();
             amountDaySynParamDto.setReadTime(DateTimeFormatter.ofPattern("yyyyMMdd").format(LocalDate.now().plusDays(-1)));
             amountDaySynParamDto.setCustomerNo(customerNo);
-            //一次查询五百
+            //一次查询30
             List<String> selectList ;
-            if(i+500 >= metercodes.size()){
+            if(i+30 >= metercodes.size()){
                 selectList=metercodes.subList(i,metercodes.size());
             }else{
-                selectList=metercodes.subList(i,i+500);
+                selectList=metercodes.subList(i,i+30);
             }
             amountDaySynParamDto.setFileNo(selectList);
 
@@ -197,7 +192,7 @@ public class AmountSynDayServiceImpl implements AmountSynByDayService, Initializ
                 AmountSynRespDto amountSynRespDto = map.get(amountWaterUsedAmountByDay.getMetercode());
                 BigDecimal readingOld = amountWaterUsedAmountByDay.getLastreading();//上期止度
 
-                if (amountSynRespDto.getReading() != null) {
+                if (StringUtils.isNotBlank(amountSynRespDto.getReading())) {
                     BigDecimal readingNew = new BigDecimal(amountSynRespDto.getReading()).setScale(0, BigDecimal.ROUND_DOWN);//本期止度
 
                     BigDecimal payAmount ;//结算水量
@@ -206,7 +201,7 @@ public class AmountSynDayServiceImpl implements AmountSynByDayService, Initializ
 
                     BigDecimal replaceAmount = BigDecimal.ZERO;//旧表用水量
 
-                    String readDate = amountSynRespDto.getCurrentPeriodDate();
+                    String readDate = amountSynRespDto.getReadTime();
 
                     Integer calculateway = amountWaterUsedAmountByDay.getCalculateway();
 
@@ -230,7 +225,11 @@ public class AmountSynDayServiceImpl implements AmountSynByDayService, Initializ
                             continue;
                         }
                     amountWaterUsedAmountByDay.setReading(readingNew);
-                    amountWaterUsedAmountByDay.setRecorddate(DateTimeUtil.parseDate(readDate, DateTimeUtil.DATE_TIME_FORMAT_SECOND));
+                    if(StringUtils.isNotBlank(readDate)){
+                         amountWaterUsedAmountByDay.setRecorddate(
+                                 Date.from(LocalDateTime.parse(readDate,DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ")).atZone(ZoneId.systemDefault()).toInstant()));
+                    }
+
                     amountWaterUsedAmountByDay.setAmount(Amount);
                     amountWaterUsedAmountByDay.setPayamount(payAmount);
                     updates.add(amountWaterUsedAmountByDay);
@@ -245,4 +244,5 @@ public class AmountSynDayServiceImpl implements AmountSynByDayService, Initializ
             }
         log.info("每天水量同步结束:" + LocalDateTime.now());
         }
+
 }

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

@@ -84,10 +84,11 @@ public class AmountSynServiceImpl implements AmountSynService , InitializingBean
         entity.setJobName("AmountSyncJob"+payBaseConfigDto.getCustomerId());
         entity.setDescription("AmountSyncJob"+payBaseConfigDto.getCustomerId());
         boolean exists = jobAndTriggerService.isExists(entity);
-        if(!exists){
+        if(!exists) {
             String[] values = value.split("_");
-            String cron = "0 */"+values[2]+" * "+values[0]+"-"+values[1]+" * ?";
-            log.info("水量同步cron:"+cron);
+            String cron = "0 */" + values[2] + " * " + values[0] + "-" + values[1] + " * ?";
+//                    String cron = "0 */3 * 1-31 * ?";
+            log.info("水量同步cron:" + cron);
             entity.setCronExpression(cron);
             entity.setJobClassName(AmountSyncJob.class.getName());
             HashMap<String, Object> jobData = new HashMap<String, Object>();
@@ -111,6 +112,9 @@ public class AmountSynServiceImpl implements AmountSynService , InitializingBean
 
     @Override
     public void amountUpdate(Integer siteId, Integer customerId) {
+        if(customerId == 47){
+            log.info("didi");
+        }
         //获取最新账期
         BaseClosingAccountInfoDto baseClosingAccountInfoDto = baseClosingAccountInfoMapper.getLastClosingAccount(siteId, customerId);
 
@@ -124,10 +128,10 @@ public class AmountSynServiceImpl implements AmountSynService , InitializingBean
         Integer month=baseClosingAccountInfoDto.getMonth();
         //插入水量基础信息(同步计划)
         Integer amountNumber = amountWaterUsedAmountMapper.insertSelectAmountBaseInfo(year,month,siteId,customerId);
-        if(amountNumber == 0){
-            log.info("同步水量失败:生成同步计划失败");
-            return;
-        }
+//        if(amountNumber == 0){
+//            log.info("同步水量失败:生成同步计划失败");
+//            return;
+//        }
         //获取客户编号
         List<Customer> customers = customerMapper.getListById(customerId);
         if(customers .size() != 1){
@@ -154,16 +158,16 @@ public class AmountSynServiceImpl implements AmountSynService , InitializingBean
         //抄表数据结果
         List<AmountSynRespDto> lists =new ArrayList<>();
 
-        for(int i=0;i<metercodes.size();i+=500){
+        for(int i=0;i<metercodes.size();i+=29){
             AmountSynParamDto amountSynParamDto= new AmountSynParamDto();
             amountSynParamDto.setYyyymm(year+""+month);
             amountSynParamDto.setCustomerNo(customerNo);
-            //一次查询五百条
+            //一次最多查询30个
             List<String> selectList ;
-            if(i+500 >= metercodes.size()){
+            if(i+29 >= metercodes.size()){
                 selectList=metercodes.subList(i,metercodes.size());
             }else{
-                selectList=metercodes.subList(i,i+500);
+                selectList=metercodes.subList(i,i+29);
             }
             amountSynParamDto.setFileNo(selectList);
 

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

@@ -7,6 +7,8 @@ import com.bz.smart_city.dao.pay.PayBaseConfigMapper;
 import com.bz.smart_city.dto.LoginUser;
 import com.bz.smart_city.dto.pay.PayBaseConfigDto;
 import com.bz.smart_city.entity.pay.PayBaseConfig;
+import com.bz.smart_city.quartz.service.AmountSynService;
+import com.bz.smart_city.quartz.service.impl.AmountSynServiceImpl;
 import com.bz.smart_city.service.pay.PayBaseConfigService;
 import com.github.pagehelper.PageHelper;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -29,7 +31,8 @@ public class PayBaseConfigServiceImpl implements PayBaseConfigService {
     private PayBaseConfigMapper payBaseConfigMapper;
     @Autowired
     private ResetLadderServiceImpl resetLadderServiceImpl;
-
+    @Autowired
+    private AmountSynService amountSynService;
     @Override
     public int add(PayBaseConfigDto payBaseConfigDto) {
         LoginUser loginUser = UserUtil.getCurrentUser();
@@ -99,8 +102,8 @@ public class PayBaseConfigServiceImpl implements PayBaseConfigService {
             payBaseConfigDto.setCustomerId(customerId);
             payBaseConfigDto.setSiteId(siteId);
             if(payBaseConfigDto.getName().equals("AUTO_SYNUAMOUNT_TIME")) {
-//                amountSynServiceImpl.deleteQrtzTask(payBaseConfigDto.getCustomerId());
-//                amountSynServiceImpl.saveQrtzTask(payBaseConfigDto);
+                amountSynService.deleteQrtzTask(payBaseConfigDto.getCustomerId());
+                amountSynService.saveQrtzTask(payBaseConfigDto);
             }else if(payBaseConfigDto.getName().equals("LADDER_WATER_RESET_DATE")){
                 resetLadderServiceImpl.deleteQrtzTask(payBaseConfigDto.getCustomerId());
                 resetLadderServiceImpl.saveQrtzTask(payBaseConfigDto);

+ 7 - 8
smart-city-platform/src/main/resources/mapper/pay/AmountWaterUsedAmountMapper.xml

@@ -382,7 +382,6 @@
 		AND amount.id IS NULL
 		<if test="customerId!= null" >AND c.customer_id = #{customerId}</if>
 		<if test="siteId!= null" > and c.site_id = #{siteId} </if>
-		limit 500
 	</insert>
 
 
@@ -416,7 +415,7 @@
 	</select>
 
 
-	<select id="getAllAmountRecordByDay"  resultType="com.bz.smart_city.entity.pay.AmountWaterUsedAmountByDay">
+	 <select id="getAllAmountRecordByDay"  resultType="com.bz.smart_city.entity.pay.AmountWaterUsedAmountByDay">
 		select  amount.id,
 		amount.lastreading,
 		amount.lastrecorddate,
@@ -566,8 +565,8 @@
 		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
+		,ifnull(ifnull(amount.reading,d.new_meter_start),null) as lastreading
+		,ifnull(ifnull(amount.recorddate,d.date_create),null) as lastrecorddate
 		,c.metercode
 		,c.watermeter_id
 		,#{month}
@@ -590,9 +589,9 @@
 		,#{customerId}
 		from pay_base_customerandmeterrela c
 		left join pay_base_waterproperty p on c.waterproperty_id=p.id
-		LEFT JOIN pay_amount_waterusedamount amount ON amount.watermeter_id = c.watermeter_id
-		AND amount.YEAR = #{year}
-		AND amount.MONTH = #{month}
+		LEFT JOIN pay_amount_waterusedamount amounts ON amounts.watermeter_id = c.watermeter_id
+		AND amounts.YEAR = #{year}
+		AND amounts.MONTH = #{month}
 		left join sc_device d on c.watermeter_id=d.id
 		left join (
 			select
@@ -609,7 +608,7 @@
 			)	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 amount.id is null and c.site_id=#{siteId} and c.customer_id=#{customerId}
+		where c.businessstate= 1 and amounts.id is null and c.site_id=#{siteId} and c.customer_id=#{customerId}
 	</insert>
 
 	<select id="getSynAmountMetercode" resultType="java.lang.String">