Browse Source

1预计费发送短信

Xiaojh 4 years ago
parent
commit
6f8e4fb7e2

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

@@ -0,0 +1,37 @@
+package com.bz.smart_city.quartz.job;
+
+import com.bz.smart_city.quartz.service.EstimateMsgSendService;
+import lombok.extern.slf4j.Slf4j;
+import org.quartz.*;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+import java.io.Serializable;
+
+/**
+ * @description
+ * @auto xjh
+ * @data 2021-01-12 15:32
+ */
+@Slf4j
+@Component
+public class EstimateMsgSendJob implements Job, Serializable {
+
+    @Autowired
+    private EstimateMsgSendService estimateMsgSendService;
+    @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 EstimateMsgSendJob , customerId = {}",customerId);
+        estimateMsgSendService.send(siteId,customerId);
+        log.info("invoked EstimateMsgSendJob , customerId = {}",customerId);
+    }
+}

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

@@ -0,0 +1,18 @@
+package com.bz.smart_city.quartz.service;
+
+import java.math.BigInteger;
+
+/**
+ * @description
+ * @auto xjh
+ * @data 2021-01-12 15:32
+ */
+public interface EstimateMsgSendService {
+    void afterPropertiesSet();
+
+    void saveQrtzTask(BigInteger siteId, BigInteger customerId, String sendTime);
+
+    void deleteQrtzTask();
+
+    void send(Integer siteId, Integer customerId);
+}

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

@@ -0,0 +1,113 @@
+package com.bz.smart_city.quartz.service.impl;
+
+import com.bz.smart_city.commom.exception.ServiceException;
+import com.bz.smart_city.commom.model.ResultStatus;
+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.EstimateMsgSendJob;
+import com.bz.smart_city.quartz.job.EstimatedDayJob;
+import com.bz.smart_city.quartz.service.EstimateMsgSendService;
+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.util.HashMap;
+import java.util.List;
+
+/**
+ * @author xjh
+ * @version 计费
+ * @date 2021/1/13 20:34
+ */
+@Slf4j
+@Component
+public class EstimateMsgSendServiceImpl implements EstimateMsgSendService, InitializingBean {
+
+    //void afterPropertiesSet();
+
+    @Resource
+    private JobAndTriggerService jobAndTriggerService;
+
+    @Autowired
+    private AmountWaterUsedAmountService amountWaterUsedAmountService;
+
+    @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("EstimateMsgSendJob"+siteId );
+        entity.setDescription("EstimateMsgSendJob"+customerId );
+        // modify by pengdi ,判断定时任务是否存在,不存在才进行新增
+
+        boolean exists = jobAndTriggerService.isExists(entity);
+        if(!exists) {
+            String time = "";
+            String minute = "";
+            String second = "";
+            if(StringUtils.isNotBlank(sendTime)){
+                String[] sp = sendTime.split(":");
+                time = sp[0];
+                minute = sp[1];
+                //String cron = "0 */3 * * * ?";
+                //String cron ="0 40 14 * * ?";
+                //String cron = "0 "+Integer.valueOf(minute)+" "+Integer.valueOf(time)+" * * ? ";
+                String cron = "0 0 19 * * ? ";
+                log.info("预计费每天推送:" + cron);
+                log.info("预计费每天推送:" + "站点ID:"+siteId+"水司ID:"+customerId);
+                entity.setCronExpression(cron);
+                entity.setJobClassName(EstimateMsgSendJob.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 deleteQrtzTask() {
+        // 1,查询需要批量推送的配置项目并构建定时任务
+        QuartzEntity entity = new QuartzEntity();
+        entity.setJobGroup("预计费每天推送");
+        entity.setJobName("EstimateMsgSendJob");
+        if (jobAndTriggerService.isExists(entity)) {
+            jobAndTriggerService.deleteJob(entity);
+        }
+    }
+
+    public void send(Integer siteId,Integer customerId){
+        log.info("================================================>预计费每天统推送始<=====================================");
+        amountWaterUsedAmountService.estimateMsgSend(siteId,customerId);
+        log.info("================================================>预计费每天推送完成<=====================================");
+    }
+}