|
@@ -0,0 +1,64 @@
|
|
|
+package com.bz.smart_city.quartz.service.impl;
|
|
|
+
|
|
|
+import com.bz.smart_city.quartz.entity.QuartzEntity;
|
|
|
+import com.bz.smart_city.quartz.job.EstimatedDayJob;
|
|
|
+import com.bz.smart_city.quartz.service.EstimatedDayService;
|
|
|
+import com.bz.smart_city.quartz.service.JobAndTriggerService;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.InitializingBean;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @description
|
|
|
+ * @auto xjh
|
|
|
+ * @data 2021-01-12 15:32
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Component
|
|
|
+public class EstimatedDayServiceImpl implements EstimatedDayService, InitializingBean {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private JobAndTriggerService jobAndTriggerService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void afterPropertiesSet() {
|
|
|
+ saveQrtzTask();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public void saveQrtzTask() {
|
|
|
+ // 1,查询需要批量推送的配置项目并构建定时任务
|
|
|
+ // 2,若对应定时任务不存在则创建
|
|
|
+ QuartzEntity entity = new QuartzEntity();
|
|
|
+ entity.setJobGroup("预计费每天统计");
|
|
|
+ entity.setJobName("EstimatedDayJob" );
|
|
|
+ entity.setDescription("EstimatedDayJob" );
|
|
|
+ // modify by pengdi ,判断定时任务是否存在,不存在才进行新增
|
|
|
+
|
|
|
+ boolean exists = jobAndTriggerService.isExists(entity);
|
|
|
+ if(!exists) {
|
|
|
+ String cron = "0 */1 * * * ?";
|
|
|
+ log.info("预计费每天统计:" + cron);
|
|
|
+ entity.setCronExpression(cron);
|
|
|
+ entity.setJobClassName(EstimatedDayJob.class.getName());
|
|
|
+ jobAndTriggerService.save(entity);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public void deleteQrtzTask() {
|
|
|
+ // 1,查询需要批量推送的配置项目并构建定时任务
|
|
|
+ QuartzEntity entity = new QuartzEntity();
|
|
|
+ entity.setJobGroup("预计费每天统计");
|
|
|
+ entity.setJobName("EstimatedDayJob");
|
|
|
+ if (jobAndTriggerService.isExists(entity)) {
|
|
|
+ jobAndTriggerService.deleteJob(entity);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void start(){
|
|
|
+ log.info("================================================>预计费每天统计<=====================================");
|
|
|
+ }
|
|
|
+}
|