提交 | 用户 | 时间
|
516ef4
|
1 |
package com.iailab.module.shasteel.job.init; |
L |
2 |
|
|
3 |
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
4 |
import com.iailab.module.shasteel.job.dao.ScheduleJobDao; |
|
5 |
import com.iailab.module.shasteel.job.entity.ScheduleJobEntity; |
|
6 |
import com.iailab.module.shasteel.job.utils.ScheduleUtils; |
|
7 |
import org.quartz.CronTrigger; |
|
8 |
import org.quartz.Scheduler; |
|
9 |
import org.springframework.boot.CommandLineRunner; |
|
10 |
import org.springframework.stereotype.Component; |
|
11 |
|
|
12 |
import javax.annotation.Resource; |
|
13 |
import java.util.List; |
|
14 |
|
|
15 |
/** |
|
16 |
* 初始化定时任务数据 |
|
17 |
*/ |
|
18 |
@Component |
|
19 |
public class JobCommandLineRunner implements CommandLineRunner { |
|
20 |
@Resource |
|
21 |
private Scheduler scheduler; |
|
22 |
@Resource |
|
23 |
private ScheduleJobDao scheduleJobDao; |
|
24 |
|
|
25 |
@Override |
|
26 |
public void run(String... args) { |
|
27 |
List<ScheduleJobEntity> scheduleJobList = scheduleJobDao.selectList(new QueryWrapper<>()); |
|
28 |
for(ScheduleJobEntity scheduleJob : scheduleJobList){ |
|
29 |
CronTrigger cronTrigger = ScheduleUtils.getCronTrigger(scheduler, scheduleJob.getId()); |
|
30 |
//如果不存在,则创建 |
|
31 |
if(cronTrigger == null) { |
|
32 |
ScheduleUtils.createScheduleJob(scheduler, scheduleJob); |
|
33 |
}else { |
|
34 |
ScheduleUtils.updateScheduleJob(scheduler, scheduleJob); |
|
35 |
} |
|
36 |
} |
|
37 |
} |
|
38 |
} |