JobServiceImpl.java
3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package com.bootdo.common.service.impl;
import com.bootdo.common.config.Constant;
import com.bootdo.common.dao.TaskDao;
import com.bootdo.common.domain.ScheduleJob;
import com.bootdo.common.domain.TaskDO;
import com.bootdo.common.quartz.utils.QuartzManager;
import com.bootdo.common.service.JobService;
import com.bootdo.common.utils.ScheduleJobUtils;
import org.quartz.SchedulerException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class JobServiceImpl implements JobService {
@Autowired
private TaskDao taskScheduleJobMapper;
@Autowired
QuartzManager quartzManager;
@Override
public TaskDO get(Long id) {
return taskScheduleJobMapper.get(id);
}
@Override
public List<TaskDO> list(Map<String, Object> map) {
return taskScheduleJobMapper.list(map);
}
@Override
public int count(Map<String, Object> map) {
return taskScheduleJobMapper.count(map);
}
@Override
public int save(TaskDO taskScheduleJob) {
return taskScheduleJobMapper.save(taskScheduleJob);
}
@Override
public int update(TaskDO taskScheduleJob) {
return taskScheduleJobMapper.update(taskScheduleJob);
}
@Override
public int remove(Long id) {
try {
TaskDO scheduleJob = get(id);
quartzManager.deleteJob(ScheduleJobUtils.entityToData(scheduleJob));
return taskScheduleJobMapper.remove(id);
} catch (SchedulerException e) {
e.printStackTrace();
return 0;
}
}
@Override
public int batchRemove(Long[] ids) {
for (Long id : ids) {
try {
TaskDO scheduleJob = get(id);
quartzManager.deleteJob(ScheduleJobUtils.entityToData(scheduleJob));
} catch (SchedulerException e) {
e.printStackTrace();
return 0;
}
}
return taskScheduleJobMapper.batchRemove(ids);
}
@Override
public void initSchedule() throws SchedulerException {
// 这里获取任务信息数据
List<TaskDO> jobList = taskScheduleJobMapper.list(new HashMap<String, Object>(16));
for (TaskDO scheduleJob : jobList) {
if ("1".equals(scheduleJob.getJobStatus())) {
ScheduleJob job = ScheduleJobUtils.entityToData(scheduleJob);
quartzManager.addJob(job);
}
}
}
@Override
public void changeStatus(Long jobId, String cmd) throws SchedulerException {
TaskDO scheduleJob = get(jobId);
if (scheduleJob == null) {
return;
}
if (Constant.STATUS_RUNNING_STOP.equals(cmd)) {
quartzManager.deleteJob(ScheduleJobUtils.entityToData(scheduleJob));
scheduleJob.setJobStatus(ScheduleJob.STATUS_NOT_RUNNING);
} else {
if (!Constant.STATUS_RUNNING_START.equals(cmd)) {
} else {
scheduleJob.setJobStatus(ScheduleJob.STATUS_RUNNING);
quartzManager.addJob(ScheduleJobUtils.entityToData(scheduleJob));
}
}
update(scheduleJob);
}
@Override
public void updateCron(Long jobId) throws SchedulerException {
TaskDO scheduleJob = get(jobId);
if (scheduleJob == null) {
return;
}
if (ScheduleJob.STATUS_RUNNING.equals(scheduleJob.getJobStatus())) {
quartzManager.updateJobCron(ScheduleJobUtils.entityToData(scheduleJob));
}
update(scheduleJob);
}
}