|
@@ -1,16 +1,13 @@
|
|
|
package com.persagy.service.impl;
|
|
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
import com.persagy.entity.ExpireAlarmMessage;
|
|
|
-import com.persagy.job.AlarmContinueJob;
|
|
|
import com.persagy.job.AlarmExpireJob;
|
|
|
import com.persagy.job.ExpireAlarmQueue;
|
|
|
import com.persagy.service.AlarmQuartzService;
|
|
|
import com.persagy.utils.DateUtils;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.quartz.*;
|
|
|
-import org.quartz.impl.matchers.GroupMatcher;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -42,11 +39,6 @@ public class AlarmQuartzServiceImpl implements AlarmQuartzService {
|
|
|
} catch (InterruptedException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
- try {
|
|
|
- createSendAlarmLastMsgSchedule();
|
|
|
- } catch (SchedulerException e) {
|
|
|
- log.error("发送报警持续时间定时任务创建失败!");
|
|
|
- }
|
|
|
|
|
|
while (true) {
|
|
|
try {
|
|
@@ -100,50 +92,6 @@ public class AlarmQuartzServiceImpl implements AlarmQuartzService {
|
|
|
return "success";
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- * @description: 获取当前所有定时任务的信息,调试时使用,上线请勿用
|
|
|
- * @param:
|
|
|
- * @return: java.util.List<java.util.Map < java.lang.String, java.lang.Object>>
|
|
|
- * @exception:
|
|
|
- * @author: lixing
|
|
|
- * @company: Persagy Technology Co.,Ltd
|
|
|
- * @since: 2021/1/14 下午1:15
|
|
|
- * @version: V1.0
|
|
|
- */
|
|
|
- public List<Map<String, Object>> queryAllJob() {
|
|
|
- List<Map<String, Object>> jobList = null;
|
|
|
- try {
|
|
|
- GroupMatcher<JobKey> matcher = GroupMatcher.anyJobGroup();
|
|
|
- Set<JobKey> jobKeys = quartzScheduler.getJobKeys(matcher);
|
|
|
- jobList = new ArrayList<Map<String, Object>>();
|
|
|
- for (JobKey jobKey : jobKeys) {
|
|
|
- List<? extends Trigger> triggers = quartzScheduler.getTriggersOfJob(jobKey);
|
|
|
- for (Trigger trigger : triggers) {
|
|
|
- Map<String, Object> map = new HashMap<>();
|
|
|
- map.put("jobName", jobKey.getName());
|
|
|
- map.put("jobGroupName", jobKey.getGroup());
|
|
|
- map.put("description", "触发器:" + trigger.getKey());
|
|
|
- Trigger.TriggerState triggerState = quartzScheduler.getTriggerState(trigger.getKey());
|
|
|
- map.put("jobStatus", triggerState.name());
|
|
|
- if (trigger instanceof CronTrigger) {
|
|
|
- CronTrigger cronTrigger = (CronTrigger) trigger;
|
|
|
- String cronExpression = cronTrigger.getCronExpression();
|
|
|
- map.put("jobTime", cronExpression);
|
|
|
- } else if (trigger instanceof SimpleTrigger) {
|
|
|
- SimpleTrigger simpleTrigger = (SimpleTrigger) trigger;
|
|
|
- map.put("jobTime", simpleTrigger.getStartTime());
|
|
|
- }
|
|
|
-
|
|
|
- jobList.add(map);
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (SchedulerException e) {
|
|
|
- log.error("获取当前定时任务发生异常", e);
|
|
|
- }
|
|
|
- log.info("当前所有定时任务数量:[{}]", jobList.size());
|
|
|
- log.info("当前所有定时任务:[{}]", JSONObject.toJSONString(jobList));
|
|
|
- return jobList;
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
|
@@ -170,26 +118,6 @@ public class AlarmQuartzServiceImpl implements AlarmQuartzService {
|
|
|
return "success!";
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public void createSendAlarmLastMsgSchedule() throws SchedulerException {
|
|
|
- String jobName = "sendAlarmLastMsg";
|
|
|
- String jobGroupName = "sendMsg";
|
|
|
- log.info("创建发送报警消息定时任务");
|
|
|
- JobDetail jobDetail = JobBuilder.newJob(AlarmContinueJob.class)
|
|
|
- .withIdentity(jobName, jobGroupName)
|
|
|
- .requestRecovery()
|
|
|
- .build();
|
|
|
- Trigger trigger = TriggerBuilder.newTrigger()
|
|
|
- .withIdentity("trigger_" + jobName, jobGroupName)
|
|
|
- .startNow()
|
|
|
- .withSchedule(simpleSchedule().
|
|
|
- withIntervalInMilliseconds(10000).
|
|
|
- repeatForever())
|
|
|
- .build();
|
|
|
- Set<Trigger> triggerSet = new HashSet<>();
|
|
|
- triggerSet.add(trigger);
|
|
|
- quartzScheduler.scheduleJob(jobDetail, triggerSet, true);
|
|
|
- }
|
|
|
|
|
|
|
|
|
}
|