|
@@ -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("================================================>预计费阀控推送完成<=====================================");
|
|
|
+ }
|
|
|
+}
|