Преглед на файлове

同步全部水表每日读数

oppadmin преди 4 години
родител
ревизия
a9872eaf0e

+ 1 - 1
smart-city-platform/src/main/java/com/bz/smart_city/controller/pay/PayControlRuleController.java

@@ -40,7 +40,7 @@ public class PayControlRuleController {
                     throw new Exception("阀控规则判断条件不能为空");
                 if(payControlRule.getOperator() == null)
                     throw new Exception("阀控规则运算符不能为空");
-                if(StringUtils.isNotBlank(payControlRule.getValue()))
+                if(StringUtils.isBlank(payControlRule.getValue()))
                     throw new Exception("阀控规则条件值不能为空");
                 if(payControlRule.getAction() == null)
                     throw new Exception("阀控规则执行操作不能为空");

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

@@ -63,6 +63,8 @@ public interface AmountWaterUsedAmountMapper {
 
     List<PayBaseCustomerandmeterrela> getCustIdAndSiteId();
 
+    List<PayBaseCustomerandmeterrela> getCustIdAndSiteIdByAccount();
+
     AmountWaterUsedAmount getLastReadrecord(@Param("metercode") String metercode, @Param("siteId") Integer siteId,@Param("customerId")Integer customerId);
 
     //插入换表信息
@@ -94,4 +96,6 @@ public interface AmountWaterUsedAmountMapper {
     List<EstimatedDayDto> getEstimatedDay(@Param("readdate")String readdate,@Param("year")Integer year,@Param("month")Integer month,
                                           @Param("siteId")Integer siteId,@Param("customerId")Integer customerId);
 
+    //创建水量信息(全部)
+    Integer createdAllAmountByDay(@Param("siteId") Integer siteId, @Param("customerId")Integer customerId);
 }

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

@@ -95,7 +95,7 @@ public class AmountSynDayServiceImpl implements AmountSynByDayService, Initializ
     }
 
     public void start(){
-        List<PayBaseCustomerandmeterrela> payBaseCustomerandmeterrelas = amountWaterUsedAmountMapper.getCustIdAndSiteId();
+        List<PayBaseCustomerandmeterrela> payBaseCustomerandmeterrelas = amountWaterUsedAmountMapper.getCustIdAndSiteIdByAccount();
         for (PayBaseCustomerandmeterrela payBaseCustomerandmeterrela: payBaseCustomerandmeterrelas){
             this.amountUpdateByDay(payBaseCustomerandmeterrela.getSiteId().intValue(),payBaseCustomerandmeterrela.getCustomerId().intValue());
         }
@@ -115,7 +115,8 @@ public class AmountSynDayServiceImpl implements AmountSynByDayService, Initializ
         Integer year=baseClosingAccountInfoDto.getYear();
         Integer month=baseClosingAccountInfoDto.getMonth();
         //插入水量基础信息(同步计划)
-        Integer amountNumber = amountWaterUsedAmountMapper.createdAmountByDay(siteId,customerId);
+        //Integer amountNumber = amountWaterUsedAmountMapper.createdAmountByDay(siteId,customerId);
+        Integer amountNumber = amountWaterUsedAmountMapper.createdAllAmountByDay(siteId,customerId);
 
         //获取客户编号
         List<Customer> customers = customerMapper.getListById(customerId);
@@ -187,7 +188,17 @@ public class AmountSynDayServiceImpl implements AmountSynByDayService, Initializ
             BigInteger watermeterId = amountWaterUsedAmountByDay.getWatermeterId();
             if (watermeterId != null && map.containsKey(amountWaterUsedAmountByDay.getMetercode())) {
                 AmountSynRespDto amountSynRespDto = map.get(amountWaterUsedAmountByDay.getMetercode());
-                BigDecimal readingOld = amountWaterUsedAmountByDay.getLastreading();//上期止度
+
+                if(amountWaterUsedAmountByDay.getCustomerandmeterrelaId() == null){//未开户用户
+                    amountWaterUsedAmountByDay.setReading(
+                            StringUtils.isNotBlank(amountSynRespDto.getReading()) ? new BigDecimal(amountSynRespDto.getReading()).setScale(2, BigDecimal.ROUND_DOWN) : null);
+                    amountWaterUsedAmountByDay.setRecorddate(
+                            StringUtils.isNotBlank(amountSynRespDto.getReadTime()) ? Date.from(LocalDateTime.parse(amountSynRespDto.getReadTime(),DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ")).atZone(ZoneId.systemDefault()).toInstant()) : null);
+                    updates.add(amountWaterUsedAmountByDay);
+                    continue;
+                }
+                //上期止度
+                BigDecimal readingOld = amountWaterUsedAmountByDay.getLastreading() == null ? new BigDecimal(0) : amountWaterUsedAmountByDay.getLastreading();
 
                 if (StringUtils.isNotBlank(amountSynRespDto.getReading())) {
                     BigDecimal readingNew = new BigDecimal(amountSynRespDto.getReading()).setScale(2, BigDecimal.ROUND_DOWN);//本期止度

+ 71 - 4
smart-city-platform/src/main/resources/mapper/pay/AmountWaterUsedAmountMapper.xml

@@ -390,6 +390,64 @@
 		<if test="siteId!= null" > and c.site_id = #{siteId} </if>
 	</insert>
 
+	<insert id ="createdAllAmountByDay" useGeneratedKeys="false">
+		INSERT INTO pay_amount_waterusedamount_day (
+		customerandmeterrela_id,
+		office_id,
+		lastreading,
+		lastrecorddate,
+		metercode,
+		watermeter_id,
+		payamount,
+		reading,
+		recorddate,
+		amount,
+		waterproperty_id,
+		account_id,
+		create_by,
+		create_date,
+		update_by,
+		update_date,
+		remarks,
+		del_flag,
+		site_id,
+		customer_id,
+		read_date,
+		debt
+		) SELECT
+		c.id,
+		c.office_id,
+		NULL,
+		NULL,
+		device.metercode,
+		device.id,
+		NULL,
+		NULL,
+		NULL,
+		NULL,
+		c.waterproperty_id,
+		pba.id,
+		1,
+		NOW(),
+		1,
+		now(),
+		'每天抄表计划',
+		0,
+		pba.site_id,
+		pba.customer_id,
+		DATE_FORMAT( DATE_SUB( now(), INTERVAL 1 DAY ), '%Y%m%d' ),
+		NULL
+		FROM
+		pay_base_account pba
+		LEFT JOIN sc_device device ON device.account_id = pba.id
+		LEFT JOIN pay_amount_waterusedamount_day amount ON amount.watermeter_id = device.id
+		AND amount.read_date = DATE_FORMAT( DATE_SUB( now(), INTERVAL 1 DAY ), '%Y%m%d' )
+		LEFT JOIN pay_base_customerandmeterrela c ON device.id = c.watermeter_id
+		WHERE
+		device.curr_status > 0 and amount.id IS NULL
+		<if test="customerId!= null" >AND pba.customer_id = #{customerId}</if>
+		<if test="siteId!= null" > and pba.site_id = #{siteId} </if>
+	</insert>
 
 	<update id="updateByDate">
 
@@ -434,11 +492,11 @@
 		amount.waterproperty_id waterpropertyId,
 		rela.account_id as accountId
 		from  pay_amount_waterusedamount_day amount
-		inner join pay_base_customerandmeterrela rela on rela.id= amount.customerandmeterrela_id
+		left join pay_base_customerandmeterrela rela on rela.id= amount.customerandmeterrela_id
 		where amount.read_date =DATE_FORMAT(DATE_SUB(now(),INTERVAL 1 day) ,'%Y%m%d')
-		and amount.reading is null
-		<if test="customerId!= null" > and rela.customer_id =#{customerId}</if>
-		<if test="siteId!= null" > and rela.site_id = #{siteId} </if>
+		and amount.reading is null and amount.metercode is not null
+		<if test="customerId!= null" > and amount.customer_id =#{customerId}</if>
+		<if test="siteId!= null" > and amount.site_id = #{siteId} </if>
 	</select>
 
 	<select id="getWaterMeterIdByDay" resultType="java.math.BigInteger">
@@ -461,6 +519,15 @@
 	group by c.customer_id, c.site_id
 	</select>
 
+	<select id="getCustIdAndSiteIdByAccount" resultType="com.bz.smart_city.entity.pay.archives.PayBaseCustomerandmeterrela">
+	select
+	c.customer_id customerId,
+	c.site_id siteId
+	from pay_base_account c
+	where
+	c.customer_id is not null  and c.site_id is not null
+	group by c.customer_id, c.site_id
+	</select>
 
 	<select id="getLastReadrecord" resultType="com.bz.smart_city.dto.pay.AmountWaterUsedAmountDto">
 		SELECT