Browse Source

1预计费阀控推送

Xiaojh 4 years ago
parent
commit
19096acc2a

+ 0 - 10
smart-city-platform/src/main/java/com/bz/smart_city/controller/pay/archives/PayBaseCustomerandmeterrelaController.java

@@ -11,7 +11,6 @@ import com.bz.smart_city.dto.pay.PayCustomerDto;
 import com.bz.smart_city.dto.pay.PaySaveCustomerDto;
 import com.bz.smart_city.entity.pay.archives.CustomerListInfo;
 import com.bz.smart_city.entity.pay.archives.PayAccountInfo;
-import com.bz.smart_city.quartz.service.EstimatedDayService;
 import com.bz.smart_city.service.impl.ImportServiceImpl;
 import com.bz.smart_city.service.pay.archives.PayBaseCustomerandmeterrelaService;
 import io.swagger.annotations.Api;
@@ -47,9 +46,6 @@ public class PayBaseCustomerandmeterrelaController {
     @Autowired
     private RedisUtil redisUtil;
 
-    @Autowired
-    private EstimatedDayService estimatedDayService;
-
     @ResponseBody
     @GetMapping("/pageOpenList")
     @ApiOperation(value = "计费系统-获取开户分页")
@@ -230,10 +226,4 @@ public class PayBaseCustomerandmeterrelaController {
 
         payBaseCustomerandmeterrelaService.getCustomerListExcel(condition,waterPropertyId,businessstate,calculateway,httpServletResponse);
     }
-
-    @GetMapping("/estimatedTest")
-    @ApiOperation(value = "计费系统-预计费测试")
-    public void estimatedTest(Integer siteId,Integer customerId){
-        estimatedDayService.start(siteId,customerId);
-    }
 }

+ 2 - 0
smart-city-platform/src/main/java/com/bz/smart_city/dao/pay/archives/PayBaseCustomerandmeterrelaMapper.java

@@ -106,4 +106,6 @@ public interface PayBaseCustomerandmeterrelaMapper {
     public List<PayControlRule> getRuleNames(@Param("siteId")Integer siteId,@Param("customerId")Integer customerId,@Param("list")List<String> list);
 
     void insertValve(@Param("deviceId")BigInteger deviceId,@Param("date")LocalDateTime date,@Param("controlState")int controlState);
+
+    PayBaseCustomerandmeterrela getAccountCustomer(@Param("id") BigInteger id);
 }

+ 36 - 0
smart-city-platform/src/main/java/com/bz/smart_city/quartz/job/EstimatedValveJob.java

@@ -0,0 +1,36 @@
+package com.bz.smart_city.quartz.job;
+
+import com.bz.smart_city.quartz.service.EstimatedValveService;
+import lombok.extern.slf4j.Slf4j;
+import org.quartz.*;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.io.Serializable;
+
+/**
+ * @author xjh
+ * @version 计费
+ * @date 2021/1/30 13:48
+ */
+@Slf4j
+@Component
+public class EstimatedValveJob implements Job, Serializable {
+
+    @Autowired
+    private EstimatedValveService estimatedValveService;
+    @Override
+    public void execute(JobExecutionContext context) throws JobExecutionException {
+
+        // 1,获取推送配置信息
+        JobDetail jobDetail = context.getJobDetail();
+        JobDataMap jobDataMap = jobDetail.getJobDataMap();
+        Integer siteId = Integer.valueOf(jobDataMap.get("siteId").toString());
+        Integer customerId = Integer.valueOf(jobDataMap.get("customerId").toString());
+
+        // 2,调用推送方法
+        log.info("invoke EstimatedValveJob , customerId = {}",customerId);
+        estimatedValveService.startValve(siteId,customerId);
+        log.info("invoked EstimatedValveJob , customerId = {}",customerId);
+    }
+}

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

@@ -0,0 +1,11 @@
+package com.bz.smart_city.quartz.service;
+
+/**
+ * @author xjh
+ * @version 计费
+ * @date 2021/1/30 13:50
+ */
+public interface EstimatedValveService {
+    void afterPropertiesSet();
+    void startValve(Integer siteId,Integer customerId);
+}

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

@@ -77,8 +77,8 @@ public class EstimateMsgSendServiceImpl implements EstimateMsgSendService, Initi
                 minute = sp[1];
                 //String cron = "0 */3 * * * ?";
                 //String cron ="0 40 14 * * ?";
-                //String cron = "0 "+Integer.valueOf(minute)+" "+Integer.valueOf(time)+" * * ?";
-                String cron = "0 2 15 * * ?";
+                String cron = "0 "+Integer.valueOf(minute)+" "+Integer.valueOf(time)+" * * ?";
+                //String cron = "0 2 15 * * ?";
                 log.info("预计费每天推送:" + cron);
                 log.info("预计费每天推送:" + "站点ID:"+siteId+"水司ID:"+customerId);
                 entity.setCronExpression(cron);

+ 103 - 0
smart-city-platform/src/main/java/com/bz/smart_city/quartz/service/impl/EstimatedValveServiceImpl.java

@@ -0,0 +1,103 @@
+package com.bz.smart_city.quartz.service.impl;
+
+import com.bz.smart_city.dao.pay.BaseClosingAccountInfoMapper;
+import com.bz.smart_city.dao.pay.PayMessagetemplateMapper;
+import com.bz.smart_city.dto.pay.BaseClosingAccountInfoDto;
+import com.bz.smart_city.dto.pay.PayMessageTemplateDto;
+import com.bz.smart_city.quartz.entity.QuartzEntity;
+import com.bz.smart_city.quartz.job.EstimatedValveJob;
+import com.bz.smart_city.quartz.service.EstimatedValveService;
+import com.bz.smart_city.quartz.service.JobAndTriggerService;
+import com.bz.smart_city.service.pay.AmountWaterUsedAmountService;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.InitializingBean;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+import java.math.BigInteger;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.HashMap;
+import java.util.List;
+
+/**
+ * @author xjh
+ * @version 计费
+ * @date 2021/1/30 13:52
+ */
+@Slf4j
+@Component
+public class EstimatedValveServiceImpl implements EstimatedValveService, InitializingBean {
+
+    @Autowired
+    private AmountWaterUsedAmountService amountWaterUsedAmountService;
+
+    @Resource
+    private JobAndTriggerService jobAndTriggerService;
+
+    @Resource
+    private BaseClosingAccountInfoMapper baseClosingAccountInfoMapper;
+
+    @Resource
+    private PayMessagetemplateMapper payMessagetemplateMapper;
+    @Override
+    public void afterPropertiesSet() {
+        List<BaseClosingAccountInfoDto> closingList = baseClosingAccountInfoMapper.getClosingSC();
+        if(closingList != null && closingList.size() >0){
+            for(BaseClosingAccountInfoDto list:closingList ){
+                PayMessageTemplateDto dto = payMessagetemplateMapper.get(list.getSiteId(),list.getCustomerId(),null,null);
+                saveQrtzTask(list.getSiteId(),list.getCustomerId(),dto != null && StringUtils.isNotBlank(dto.getSendTime()) ? dto.getSendTime() : "");
+            }
+        }
+    }
+
+    public void saveQrtzTask(BigInteger siteId, BigInteger customerId, String sendTime) {
+        // 1,查询需要批量推送的配置项目并构建定时任务
+        // 2,若对应定时任务不存在则创建
+        QuartzEntity entity = new QuartzEntity();
+        entity.setJobGroup("预计费推送阀控");
+        entity.setJobName("EstimatedValveJob"+siteId );
+        entity.setDescription("EstimatedValveJob"+customerId );
+        // modify by pengdi ,判断定时任务是否存在,不存在才进行新增
+
+        boolean exists = jobAndTriggerService.isExists(entity);
+        if(!exists) {
+            String time = "";
+            String minute = "";
+            String second = "";
+            if(StringUtils.isNotBlank(sendTime)){
+                if(sendTime.length() == 5)
+                    sendTime += ":00";
+                DateTimeFormatter dfYmd = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+                String currTime = LocalDateTime.now().format(dfYmd) + " " + sendTime;;
+                DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+                LocalDateTime localDateTime = LocalDateTime.parse(currTime,df);
+                LocalDateTime esTime = localDateTime.plusMinutes(30);
+                String cron = String.format("%s %s %s * * ?",esTime.getSecond(),esTime.getMinute(),esTime.getHour());
+                //String cron = "0 */2 * * * ?";
+                //String cron ="0 40 14 * * ?";
+                //String cron = "0 "+Integer.valueOf(minute)+" "+Integer.valueOf(time)+" * * ?";
+                //String cron = "0 22 15 * * ?";
+                log.info("预计费推送阀控:" + cron);
+                log.info("预计费推送阀控:" + "站点ID:"+siteId+"水司ID:"+customerId);
+                entity.setCronExpression(cron);
+                entity.setJobClassName(EstimatedValveJob.class.getName());
+                HashMap<String, Object> jobData = new HashMap<String, Object>();
+                jobData.put("siteId", siteId);
+                jobData.put("customerId", customerId);
+                entity.setJobData(jobData);
+                jobAndTriggerService.save(entity);
+            }else{
+                log.info("预计费推送阀控失败,失败:" + "站点ID:"+siteId+"水司ID:"+customerId+",失败原因:没有推送时间");
+                //throw new ServiceException(-999,"预计费每天推送失败,失败:"+"站点ID:"+siteId+"水司ID:"+customerId+",失败原因:没有推送时间");
+            }
+        }
+    }
+    public void startValve(Integer siteId,Integer customerId){
+        log.info("================================================>预计费阀控推送开始<=====================================");
+        amountWaterUsedAmountService.estimatedValveStart(siteId,customerId);
+        log.info("================================================>预计费阀控推送完成<=====================================");
+    }
+}

+ 27 - 0
smart-city-platform/src/main/java/com/bz/smart_city/service/impl/pay/AmountWaterUsedAmountServiceImpl.java

@@ -5,6 +5,7 @@ import com.bz.smart_city.commom.model.AjaxMessage;
 import com.bz.smart_city.commom.model.Pagination;
 import com.bz.smart_city.commom.model.ResultStatus;
 import com.bz.smart_city.commom.util.*;
+import com.bz.smart_city.dao.CustomerMapper;
 import com.bz.smart_city.dao.SiteMapper;
 import com.bz.smart_city.dao.pay.*;
 import com.bz.smart_city.dao.pay.archives.PayBaseCustomerandmeterrelaMapper;
@@ -12,9 +13,11 @@ import com.bz.smart_city.dto.LoginUser;
 import com.bz.smart_city.dto.pay.*;
 import com.bz.smart_city.dto.pay.DeviceReplaceRecordDto;
 import com.bz.smart_city.dto.pay.payfee.PayValveStateInfo;
+import com.bz.smart_city.entity.Customer;
 import com.bz.smart_city.entity.ProgramItem;
 import com.bz.smart_city.entity.pay.*;
 import com.bz.smart_city.entity.pay.archives.PayBaseCustomerandmeterrela;
+import com.bz.smart_city.quartz.service.impl.ControlDayServiceImpl;
 import com.bz.smart_city.service.pay.AmountWaterUsedAmountService;
 import com.bz.smart_city.service.pay.PayFeeService;
 import com.github.pagehelper.PageHelper;
@@ -80,6 +83,12 @@ public class AmountWaterUsedAmountServiceImpl implements AmountWaterUsedAmountSe
     @Resource
     private PayMessagesendrecordServiceImp payMessagesendrecordServiceImp;
 
+    @Resource
+    private ControlDayServiceImpl controlDayServiceImpl;
+
+    @Resource
+    CustomerMapper customerMapper;
+
     @Override
     public Pagination<AmountWaterUsedAmountDto> getList(String condition, String accountNumber, String accountName, String meterCode, String address, Integer year, Integer month, Integer state,
                                                         Integer amountMin, Integer amountMax, Integer pageNum, Integer pageSize) {
@@ -961,4 +970,22 @@ public class AmountWaterUsedAmountServiceImpl implements AmountWaterUsedAmountSe
         System.out.println("==============================>预计费短信推送成功<============================");
     }
 
+    public void estimatedValveStart(Integer siteId,Integer customerId){
+        //查找欠费用户
+        //获取最新账期
+        BaseClosingAccountInfoDto baseClosingAccountInfoDto=baseClosingAccountInfoMapper.getLastClosingAccount(siteId,customerId);
+        if(baseClosingAccountInfoDto == null){
+            throw new ServiceException(ResultStatus.ClOSING_ACCCOUNT_NOT_EXIT);
+        }
+        //根据站点跟客户ID查找出用水余额小于0用户
+        List<PayRechargeaccountDto> rechList = payRechargeaccountMapper.getEstimateBalance(siteId,customerId);
+        Customer customerNo = customerMapper.findById(customerId);
+        List<Integer> filterId = new ArrayList<>();
+        filterId.add(4);
+        for(PayRechargeaccountDto dto:rechList){
+            PayBaseCustomerandmeterrela customer = payBaseCustomerandmeterrelaMapper.getAccountCustomer(dto.getAccountId());
+            controlDayServiceImpl.sendValve(customerNo.getCustomerNo(),2,filterId,customer);
+        }
+    }
+
 }

+ 2 - 0
smart-city-platform/src/main/java/com/bz/smart_city/service/pay/AmountWaterUsedAmountService.java

@@ -36,4 +36,6 @@ public interface AmountWaterUsedAmountService {
     void estimatedDay(Integer siteId,Integer customerId);
 
     void estimateMsgSend(Integer siteId,Integer customerId);
+
+    void estimatedValveStart(Integer siteId,Integer customerId);
 }

+ 39 - 0
smart-city-platform/src/main/resources/mapper/PayBaseCustomerandmeterrelaMapper.xml

@@ -729,4 +729,43 @@
             #{controlState}
         )
     </insert>
+
+    <select id="getAccountCustomer" resultType="com.bz.smart_city.entity.pay.archives.PayBaseCustomerandmeterrela">
+        select
+        a.id,
+        a.account_id AS "accountId",
+        a.watermeter_id AS "watermeterId",
+        a.accountname,
+        a.accountnumber,
+        a.metercode,
+        a.businessstate,
+        a.office_id AS "officeId",
+        a.housetype,
+        a.calculateway,
+        a.customercategory,
+        a.customergroup,
+        a.fixedamount,
+        a.vatno,
+        a.bankaccount,
+        a.invoicetitle,
+        a.address,
+        a.opendate,
+        a.waterproperty_id AS "waterpropertyId",
+        a.watertype,
+        a.canceldate,
+        a.create_by AS "createBy",
+        a.create_date AS "createDate",
+        a.update_by AS "updateBy",
+        a.update_date AS "updateDate",
+        a.remarks AS "remarks",
+        a.del_flag AS "delFlag",
+        a.site_id as "siteId",
+        a.customer_id as "customerId",
+        a.valve_rule_id,
+        a.valve_rule_name
+        from pay_base_customerandmeterrela a
+        <where>
+            a.account_id =#{id}
+        </where>
+    </select>
 </mapper>

+ 1 - 3
smart-city-platform/src/main/resources/mapper/pay/PayPenaltyrecordMapper.xml

@@ -8,9 +8,7 @@
             rece.accountname as "accountname",
             rece.debt as "debt",
             rece.create_date as "createDate",
-            "" as "reductionDebt",
-        <!--(rech.remaining - rece.debt) as "balanceDebt"-->
-            rech.remaining as balanceDebt
+            rech.balance as "balanceDebt"
         from pay_pay_receivable rece
         left join pay_pay_rechargeaccount rech on rech.account_id = rece.account_id
         <where>

+ 1 - 0
smart-city-platform/src/main/resources/mapper/pay/baseClosingAccountInfoMapper.xml

@@ -222,6 +222,7 @@
 			site_id as "siteId",
 			customer_id as "customerId"
 		from pay_base_closingaccountinfo
+		where site_id = 51 and customer_id = 120
 		GROUP BY site_id,customer_id
 	</select>