Commit c807de1ff816a93a1486ba72a8cd404780095ac9

Authored by YunaiV
1 parent 2f66829a

初始化 quartz 模块~

Showing 29 changed files with 440 additions and 855 deletions
@@ -151,6 +151,12 @@ @@ -151,6 +151,12 @@
151 <version>1.7.0</version> 151 <version>1.7.0</version>
152 </dependency> 152 </dependency>
153 153
  154 + <!-- Job 定时任务相关 -->
  155 + <dependency>
  156 + <groupId>org.springframework.boot</groupId>
  157 + <artifactId>spring-boot-starter-quartz</artifactId>
  158 + </dependency>
  159 +
154 <!-- 监控相关 --> 160 <!-- 监控相关 -->
155 <dependency> 161 <dependency>
156 <groupId>org.apache.skywalking</groupId> 162 <groupId>org.apache.skywalking</groupId>
ruoyi-common/src/main/java/com/ruoyi/common/constant/GenConstants.java deleted
1 -package com.ruoyi.common.constant;  
2 -  
3 -/**  
4 - * 代码生成通用常量  
5 - *  
6 - * @author ruoyi  
7 - */  
8 -public class GenConstants {  
9 -  
10 - /**  
11 - * 树编码字段  
12 - */  
13 - public static final String TREE_CODE = "treeCode";  
14 -  
15 - /**  
16 - * 树父编码字段  
17 - */  
18 - public static final String TREE_PARENT_CODE = "treeParentCode";  
19 -  
20 - /**  
21 - * 树名称字段  
22 - */  
23 - public static final String TREE_NAME = "treeName";  
24 -  
25 - /**  
26 - * 上级菜单ID字段  
27 - */  
28 - public static final String PARENT_MENU_ID = "parentMenuId";  
29 -  
30 - /**  
31 - * 上级菜单名称字段  
32 - */  
33 - public static final String PARENT_MENU_NAME = "parentMenuName";  
34 -  
35 - /**  
36 - * Tree基类字段  
37 - */  
38 - public static final String[] TREE_ENTITY = {"parentName", "parentId", "orderNum", "ancestors", "children"};  
39 -  
40 -}  
ruoyi-common/src/main/java/com/ruoyi/common/constant/ScheduleConstants.java
@@ -2,30 +2,38 @@ package com.ruoyi.common.constant; @@ -2,30 +2,38 @@ package com.ruoyi.common.constant;
2 2
3 /** 3 /**
4 * 任务调度通用常量 4 * 任务调度通用常量
5 - * 5 + *
6 * @author ruoyi 6 * @author ruoyi
7 */ 7 */
8 -public class ScheduleConstants  
9 -{ 8 +public class ScheduleConstants {
10 public static final String TASK_CLASS_NAME = "TASK_CLASS_NAME"; 9 public static final String TASK_CLASS_NAME = "TASK_CLASS_NAME";
11 10
12 - /** 执行目标key */ 11 + /**
  12 + * 执行目标key
  13 + */
13 public static final String TASK_PROPERTIES = "TASK_PROPERTIES"; 14 public static final String TASK_PROPERTIES = "TASK_PROPERTIES";
14 15
15 - /** 默认 */ 16 + /**
  17 + * 默认
  18 + */
16 public static final String MISFIRE_DEFAULT = "0"; 19 public static final String MISFIRE_DEFAULT = "0";
17 20
18 - /** 立即触发执行 */ 21 + /**
  22 + * 立即触发执行
  23 + */
19 public static final String MISFIRE_IGNORE_MISFIRES = "1"; 24 public static final String MISFIRE_IGNORE_MISFIRES = "1";
20 25
21 - /** 触发一次执行 */ 26 + /**
  27 + * 触发一次执行
  28 + */
22 public static final String MISFIRE_FIRE_AND_PROCEED = "2"; 29 public static final String MISFIRE_FIRE_AND_PROCEED = "2";
23 30
24 - /** 不触发立即执行 */ 31 + /**
  32 + * 不触发立即执行
  33 + */
25 public static final String MISFIRE_DO_NOTHING = "3"; 34 public static final String MISFIRE_DO_NOTHING = "3";
26 35
27 - public enum Status  
28 - { 36 + public enum Status {
29 /** 37 /**
30 * 正常 38 * 正常
31 */ 39 */
@@ -37,13 +45,11 @@ public class ScheduleConstants @@ -37,13 +45,11 @@ public class ScheduleConstants
37 45
38 private String value; 46 private String value;
39 47
40 - private Status(String value)  
41 - { 48 + private Status(String value) {
42 this.value = value; 49 this.value = value;
43 } 50 }
44 51
45 - public String getValue()  
46 - { 52 + public String getValue() {
47 return value; 53 return value;
48 } 54 }
49 } 55 }
ruoyi-quartz/pom.xml deleted
1 -<?xml version="1.0" encoding="UTF-8"?>  
2 -<project xmlns="http://maven.apache.org/POM/4.0.0"  
3 - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
4 - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">  
5 - <parent>  
6 - <artifactId>ruoyi</artifactId>  
7 - <groupId>com.ruoyi</groupId>  
8 - <version>3.3.0</version>  
9 - </parent>  
10 - <modelVersion>4.0.0</modelVersion>  
11 -  
12 - <artifactId>ruoyi-quartz</artifactId>  
13 -  
14 - <description>  
15 - quartz定时任务  
16 - </description>  
17 -  
18 - <dependencies>  
19 -  
20 - <!-- 定时任务 -->  
21 - <dependency>  
22 - <groupId>org.quartz-scheduler</groupId>  
23 - <artifactId>quartz</artifactId>  
24 - <exclusions>  
25 - <exclusion>  
26 - <groupId>com.mchange</groupId>  
27 - <artifactId>c3p0</artifactId>  
28 - </exclusion>  
29 - </exclusions>  
30 - </dependency>  
31 - </dependencies>  
32 -  
33 -</project>  
ruoyi-quartz/src/main/java/com/ruoyi/quartz/config/ScheduleConfig.java
@@ -3,20 +3,19 @@ package com.ruoyi.quartz.config; @@ -3,20 +3,19 @@ package com.ruoyi.quartz.config;
3 import org.springframework.context.annotation.Bean; 3 import org.springframework.context.annotation.Bean;
4 import org.springframework.context.annotation.Configuration; 4 import org.springframework.context.annotation.Configuration;
5 import org.springframework.scheduling.quartz.SchedulerFactoryBean; 5 import org.springframework.scheduling.quartz.SchedulerFactoryBean;
  6 +
6 import javax.sql.DataSource; 7 import javax.sql.DataSource;
7 import java.util.Properties; 8 import java.util.Properties;
8 9
9 /** 10 /**
10 * 定时任务配置 11 * 定时任务配置
11 - * 12 + *
12 * @author ruoyi 13 * @author ruoyi
13 */ 14 */
14 @Configuration 15 @Configuration
15 -public class ScheduleConfig  
16 -{ 16 +public class ScheduleConfig {
17 @Bean 17 @Bean
18 - public SchedulerFactoryBean schedulerFactoryBean(DataSource dataSource)  
19 - { 18 + public SchedulerFactoryBean schedulerFactoryBean(DataSource dataSource) {
20 SchedulerFactoryBean factory = new SchedulerFactoryBean(); 19 SchedulerFactoryBean factory = new SchedulerFactoryBean();
21 factory.setDataSource(dataSource); 20 factory.setDataSource(dataSource);
22 21
ruoyi-quartz/src/main/java/com/ruoyi/quartz/controller/SysJobController.java
1 package com.ruoyi.quartz.controller; 1 package com.ruoyi.quartz.controller;
2 2
3 import java.util.List; 3 import java.util.List;
  4 +
4 import org.quartz.SchedulerException; 5 import org.quartz.SchedulerException;
5 import org.springframework.beans.factory.annotation.Autowired; 6 import org.springframework.beans.factory.annotation.Autowired;
6 import org.springframework.security.access.prepost.PreAuthorize; 7 import org.springframework.security.access.prepost.PreAuthorize;
@@ -26,13 +27,12 @@ import com.ruoyi.quartz.util.CronUtils; @@ -26,13 +27,12 @@ import com.ruoyi.quartz.util.CronUtils;
26 27
27 /** 28 /**
28 * 调度任务信息操作处理 29 * 调度任务信息操作处理
29 - * 30 + *
30 * @author ruoyi 31 * @author ruoyi
31 */ 32 */
32 @RestController 33 @RestController
33 @RequestMapping("/monitor/job") 34 @RequestMapping("/monitor/job")
34 -public class SysJobController extends BaseController  
35 -{ 35 +public class SysJobController extends BaseController {
36 @Autowired 36 @Autowired
37 private ISysJobService jobService; 37 private ISysJobService jobService;
38 38
@@ -41,8 +41,7 @@ public class SysJobController extends BaseController @@ -41,8 +41,7 @@ public class SysJobController extends BaseController
41 */ 41 */
42 @PreAuthorize("@ss.hasPermi('monitor:job:list')") 42 @PreAuthorize("@ss.hasPermi('monitor:job:list')")
43 @GetMapping("/list") 43 @GetMapping("/list")
44 - public TableDataInfo list(SysJob sysJob)  
45 - { 44 + public TableDataInfo list(SysJob sysJob) {
46 startPage(); 45 startPage();
47 List<SysJob> list = jobService.selectJobList(sysJob); 46 List<SysJob> list = jobService.selectJobList(sysJob);
48 return getDataTable(list); 47 return getDataTable(list);
@@ -54,8 +53,7 @@ public class SysJobController extends BaseController @@ -54,8 +53,7 @@ public class SysJobController extends BaseController
54 @PreAuthorize("@ss.hasPermi('monitor:job:export')") 53 @PreAuthorize("@ss.hasPermi('monitor:job:export')")
55 @Log(title = "定时任务", businessType = BusinessType.EXPORT) 54 @Log(title = "定时任务", businessType = BusinessType.EXPORT)
56 @GetMapping("/export") 55 @GetMapping("/export")
57 - public AjaxResult export(SysJob sysJob)  
58 - { 56 + public AjaxResult export(SysJob sysJob) {
59 List<SysJob> list = jobService.selectJobList(sysJob); 57 List<SysJob> list = jobService.selectJobList(sysJob);
60 ExcelUtil<SysJob> util = new ExcelUtil<SysJob>(SysJob.class); 58 ExcelUtil<SysJob> util = new ExcelUtil<SysJob>(SysJob.class);
61 return util.exportExcel(list, "定时任务"); 59 return util.exportExcel(list, "定时任务");
@@ -66,8 +64,7 @@ public class SysJobController extends BaseController @@ -66,8 +64,7 @@ public class SysJobController extends BaseController
66 */ 64 */
67 @PreAuthorize("@ss.hasPermi('monitor:job:query')") 65 @PreAuthorize("@ss.hasPermi('monitor:job:query')")
68 @GetMapping(value = "/{jobId}") 66 @GetMapping(value = "/{jobId}")
69 - public AjaxResult getInfo(@PathVariable("jobId") Long jobId)  
70 - { 67 + public AjaxResult getInfo(@PathVariable("jobId") Long jobId) {
71 return AjaxResult.success(jobService.selectJobById(jobId)); 68 return AjaxResult.success(jobService.selectJobById(jobId));
72 } 69 }
73 70
@@ -77,10 +74,8 @@ public class SysJobController extends BaseController @@ -77,10 +74,8 @@ public class SysJobController extends BaseController
77 @PreAuthorize("@ss.hasPermi('monitor:job:add')") 74 @PreAuthorize("@ss.hasPermi('monitor:job:add')")
78 @Log(title = "定时任务", businessType = BusinessType.INSERT) 75 @Log(title = "定时任务", businessType = BusinessType.INSERT)
79 @PostMapping 76 @PostMapping
80 - public AjaxResult add(@RequestBody SysJob sysJob) throws SchedulerException, TaskException  
81 - {  
82 - if (!CronUtils.isValid(sysJob.getCronExpression()))  
83 - { 77 + public AjaxResult add(@RequestBody SysJob sysJob) throws SchedulerException, TaskException {
  78 + if (!CronUtils.isValid(sysJob.getCronExpression())) {
84 return AjaxResult.error("cron表达式不正确"); 79 return AjaxResult.error("cron表达式不正确");
85 } 80 }
86 sysJob.setCreateBy(SecurityUtils.getUsername()); 81 sysJob.setCreateBy(SecurityUtils.getUsername());
@@ -93,10 +88,8 @@ public class SysJobController extends BaseController @@ -93,10 +88,8 @@ public class SysJobController extends BaseController
93 @PreAuthorize("@ss.hasPermi('monitor:job:edit')") 88 @PreAuthorize("@ss.hasPermi('monitor:job:edit')")
94 @Log(title = "定时任务", businessType = BusinessType.UPDATE) 89 @Log(title = "定时任务", businessType = BusinessType.UPDATE)
95 @PutMapping 90 @PutMapping
96 - public AjaxResult edit(@RequestBody SysJob sysJob) throws SchedulerException, TaskException  
97 - {  
98 - if (!CronUtils.isValid(sysJob.getCronExpression()))  
99 - { 91 + public AjaxResult edit(@RequestBody SysJob sysJob) throws SchedulerException, TaskException {
  92 + if (!CronUtils.isValid(sysJob.getCronExpression())) {
100 return AjaxResult.error("cron表达式不正确"); 93 return AjaxResult.error("cron表达式不正确");
101 } 94 }
102 sysJob.setUpdateBy(SecurityUtils.getUsername()); 95 sysJob.setUpdateBy(SecurityUtils.getUsername());
@@ -109,8 +102,7 @@ public class SysJobController extends BaseController @@ -109,8 +102,7 @@ public class SysJobController extends BaseController
109 @PreAuthorize("@ss.hasPermi('monitor:job:changeStatus')") 102 @PreAuthorize("@ss.hasPermi('monitor:job:changeStatus')")
110 @Log(title = "定时任务", businessType = BusinessType.UPDATE) 103 @Log(title = "定时任务", businessType = BusinessType.UPDATE)
111 @PutMapping("/changeStatus") 104 @PutMapping("/changeStatus")
112 - public AjaxResult changeStatus(@RequestBody SysJob job) throws SchedulerException  
113 - { 105 + public AjaxResult changeStatus(@RequestBody SysJob job) throws SchedulerException {
114 SysJob newJob = jobService.selectJobById(job.getJobId()); 106 SysJob newJob = jobService.selectJobById(job.getJobId());
115 newJob.setStatus(job.getStatus()); 107 newJob.setStatus(job.getStatus());
116 return toAjax(jobService.changeStatus(newJob)); 108 return toAjax(jobService.changeStatus(newJob));
@@ -122,8 +114,7 @@ public class SysJobController extends BaseController @@ -122,8 +114,7 @@ public class SysJobController extends BaseController
122 @PreAuthorize("@ss.hasPermi('monitor:job:changeStatus')") 114 @PreAuthorize("@ss.hasPermi('monitor:job:changeStatus')")
123 @Log(title = "定时任务", businessType = BusinessType.UPDATE) 115 @Log(title = "定时任务", businessType = BusinessType.UPDATE)
124 @PutMapping("/run") 116 @PutMapping("/run")
125 - public AjaxResult run(@RequestBody SysJob job) throws SchedulerException  
126 - { 117 + public AjaxResult run(@RequestBody SysJob job) throws SchedulerException {
127 jobService.run(job); 118 jobService.run(job);
128 return AjaxResult.success(); 119 return AjaxResult.success();
129 } 120 }
@@ -134,8 +125,7 @@ public class SysJobController extends BaseController @@ -134,8 +125,7 @@ public class SysJobController extends BaseController
134 @PreAuthorize("@ss.hasPermi('monitor:job:remove')") 125 @PreAuthorize("@ss.hasPermi('monitor:job:remove')")
135 @Log(title = "定时任务", businessType = BusinessType.DELETE) 126 @Log(title = "定时任务", businessType = BusinessType.DELETE)
136 @DeleteMapping("/{jobIds}") 127 @DeleteMapping("/{jobIds}")
137 - public AjaxResult remove(@PathVariable Long[] jobIds) throws SchedulerException, TaskException  
138 - { 128 + public AjaxResult remove(@PathVariable Long[] jobIds) throws SchedulerException, TaskException {
139 jobService.deleteJobByIds(jobIds); 129 jobService.deleteJobByIds(jobIds);
140 return AjaxResult.success(); 130 return AjaxResult.success();
141 } 131 }
ruoyi-quartz/src/main/java/com/ruoyi/quartz/controller/SysJobLogController.java
1 package com.ruoyi.quartz.controller; 1 package com.ruoyi.quartz.controller;
2 2
3 import java.util.List; 3 import java.util.List;
  4 +
4 import org.springframework.beans.factory.annotation.Autowired; 5 import org.springframework.beans.factory.annotation.Autowired;
5 import org.springframework.security.access.prepost.PreAuthorize; 6 import org.springframework.security.access.prepost.PreAuthorize;
6 import org.springframework.web.bind.annotation.DeleteMapping; 7 import org.springframework.web.bind.annotation.DeleteMapping;
@@ -19,13 +20,12 @@ import com.ruoyi.quartz.service.ISysJobLogService; @@ -19,13 +20,12 @@ import com.ruoyi.quartz.service.ISysJobLogService;
19 20
20 /** 21 /**
21 * 调度日志操作处理 22 * 调度日志操作处理
22 - * 23 + *
23 * @author ruoyi 24 * @author ruoyi
24 */ 25 */
25 @RestController 26 @RestController
26 @RequestMapping("/monitor/jobLog") 27 @RequestMapping("/monitor/jobLog")
27 -public class SysJobLogController extends BaseController  
28 -{ 28 +public class SysJobLogController extends BaseController {
29 @Autowired 29 @Autowired
30 private ISysJobLogService jobLogService; 30 private ISysJobLogService jobLogService;
31 31
@@ -34,8 +34,7 @@ public class SysJobLogController extends BaseController @@ -34,8 +34,7 @@ public class SysJobLogController extends BaseController
34 */ 34 */
35 @PreAuthorize("@ss.hasPermi('monitor:job:list')") 35 @PreAuthorize("@ss.hasPermi('monitor:job:list')")
36 @GetMapping("/list") 36 @GetMapping("/list")
37 - public TableDataInfo list(SysJobLog sysJobLog)  
38 - { 37 + public TableDataInfo list(SysJobLog sysJobLog) {
39 startPage(); 38 startPage();
40 List<SysJobLog> list = jobLogService.selectJobLogList(sysJobLog); 39 List<SysJobLog> list = jobLogService.selectJobLogList(sysJobLog);
41 return getDataTable(list); 40 return getDataTable(list);
@@ -47,20 +46,18 @@ public class SysJobLogController extends BaseController @@ -47,20 +46,18 @@ public class SysJobLogController extends BaseController
47 @PreAuthorize("@ss.hasPermi('monitor:job:export')") 46 @PreAuthorize("@ss.hasPermi('monitor:job:export')")
48 @Log(title = "任务调度日志", businessType = BusinessType.EXPORT) 47 @Log(title = "任务调度日志", businessType = BusinessType.EXPORT)
49 @GetMapping("/export") 48 @GetMapping("/export")
50 - public AjaxResult export(SysJobLog sysJobLog)  
51 - { 49 + public AjaxResult export(SysJobLog sysJobLog) {
52 List<SysJobLog> list = jobLogService.selectJobLogList(sysJobLog); 50 List<SysJobLog> list = jobLogService.selectJobLogList(sysJobLog);
53 ExcelUtil<SysJobLog> util = new ExcelUtil<SysJobLog>(SysJobLog.class); 51 ExcelUtil<SysJobLog> util = new ExcelUtil<SysJobLog>(SysJobLog.class);
54 return util.exportExcel(list, "调度日志"); 52 return util.exportExcel(list, "调度日志");
55 } 53 }
56 - 54 +
57 /** 55 /**
58 * 根据调度编号获取详细信息 56 * 根据调度编号获取详细信息
59 */ 57 */
60 @PreAuthorize("@ss.hasPermi('monitor:job:query')") 58 @PreAuthorize("@ss.hasPermi('monitor:job:query')")
61 @GetMapping(value = "/{configId}") 59 @GetMapping(value = "/{configId}")
62 - public AjaxResult getInfo(@PathVariable Long jobLogId)  
63 - { 60 + public AjaxResult getInfo(@PathVariable Long jobLogId) {
64 return AjaxResult.success(jobLogService.selectJobLogById(jobLogId)); 61 return AjaxResult.success(jobLogService.selectJobLogById(jobLogId));
65 } 62 }
66 63
@@ -71,8 +68,7 @@ public class SysJobLogController extends BaseController @@ -71,8 +68,7 @@ public class SysJobLogController extends BaseController
71 @PreAuthorize("@ss.hasPermi('monitor:job:remove')") 68 @PreAuthorize("@ss.hasPermi('monitor:job:remove')")
72 @Log(title = "定时任务调度日志", businessType = BusinessType.DELETE) 69 @Log(title = "定时任务调度日志", businessType = BusinessType.DELETE)
73 @DeleteMapping("/{jobLogIds}") 70 @DeleteMapping("/{jobLogIds}")
74 - public AjaxResult remove(@PathVariable Long[] jobLogIds)  
75 - { 71 + public AjaxResult remove(@PathVariable Long[] jobLogIds) {
76 return toAjax(jobLogService.deleteJobLogByIds(jobLogIds)); 72 return toAjax(jobLogService.deleteJobLogByIds(jobLogIds));
77 } 73 }
78 74
@@ -82,8 +78,7 @@ public class SysJobLogController extends BaseController @@ -82,8 +78,7 @@ public class SysJobLogController extends BaseController
82 @PreAuthorize("@ss.hasPermi('monitor:job:remove')") 78 @PreAuthorize("@ss.hasPermi('monitor:job:remove')")
83 @Log(title = "调度日志", businessType = BusinessType.CLEAN) 79 @Log(title = "调度日志", businessType = BusinessType.CLEAN)
84 @DeleteMapping("/clean") 80 @DeleteMapping("/clean")
85 - public AjaxResult clean()  
86 - { 81 + public AjaxResult clean() {
87 jobLogService.cleanJobLog(); 82 jobLogService.cleanJobLog();
88 return AjaxResult.success(); 83 return AjaxResult.success();
89 } 84 }
ruoyi-quartz/src/main/java/com/ruoyi/quartz/domain/SysJob.java deleted
1 -package com.ruoyi.quartz.domain;  
2 -  
3 -import java.io.Serializable;  
4 -import java.util.Date;  
5 -import javax.validation.constraints.NotBlank;  
6 -import javax.validation.constraints.Size;  
7 -import org.apache.commons.lang3.builder.ToStringBuilder;  
8 -import org.apache.commons.lang3.builder.ToStringStyle;  
9 -import com.fasterxml.jackson.annotation.JsonFormat;  
10 -import com.ruoyi.common.annotation.Excel;  
11 -import com.ruoyi.common.annotation.Excel.ColumnType;  
12 -import com.ruoyi.common.constant.ScheduleConstants;  
13 -import com.ruoyi.common.core.domain.BaseEntity;  
14 -import com.ruoyi.common.utils.StringUtils;  
15 -import com.ruoyi.quartz.util.CronUtils;  
16 -  
17 -/**  
18 - * 定时任务调度表 sys_job  
19 - *  
20 - * @author ruoyi  
21 - */  
22 -public class SysJob extends BaseEntity implements Serializable  
23 -{  
24 - private static final long serialVersionUID = 1L;  
25 -  
26 - /** 任务ID */  
27 - @Excel(name = "任务序号", cellType = ColumnType.NUMERIC)  
28 - private Long jobId;  
29 -  
30 - /** 任务名称 */  
31 - @Excel(name = "任务名称")  
32 - private String jobName;  
33 -  
34 - /** 任务组名 */  
35 - @Excel(name = "任务组名")  
36 - private String jobGroup;  
37 -  
38 - /** 调用目标字符串 */  
39 - @Excel(name = "调用目标字符串")  
40 - private String invokeTarget;  
41 -  
42 - /** cron执行表达式 */  
43 - @Excel(name = "执行表达式 ")  
44 - private String cronExpression;  
45 -  
46 - /** cron计划策略 */  
47 - @Excel(name = "计划策略 ", readConverterExp = "0=默认,1=立即触发执行,2=触发一次执行,3=不触发立即执行")  
48 - private String misfirePolicy = ScheduleConstants.MISFIRE_DEFAULT;  
49 -  
50 - /** 是否并发执行(0允许 1禁止) */  
51 - @Excel(name = "并发执行", readConverterExp = "0=允许,1=禁止")  
52 - private String concurrent;  
53 -  
54 - /** 任务状态(0正常 1暂停) */  
55 - @Excel(name = "任务状态", readConverterExp = "0=正常,1=暂停")  
56 - private String status;  
57 -  
58 - @NotBlank(message = "任务名称不能为空")  
59 - @Size(min = 0, max = 64, message = "任务名称不能超过64个字符")  
60 - public String getJobName()  
61 - {  
62 - return jobName;  
63 - }  
64 -  
65 - @NotBlank(message = "调用目标字符串不能为空")  
66 - @Size(min = 0, max = 500, message = "调用目标字符串长度不能超过500个字符")  
67 - public String getInvokeTarget()  
68 - {  
69 - return invokeTarget;  
70 - }  
71 -  
72 - @NotBlank(message = "Cron执行表达式不能为空")  
73 - @Size(min = 0, max = 255, message = "Cron执行表达式不能超过255个字符")  
74 - public String getCronExpression()  
75 - {  
76 - return cronExpression;  
77 - }  
78 -  
79 - @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")  
80 - public Date getNextValidTime()  
81 - {  
82 - if (StringUtils.isNotEmpty(cronExpression))  
83 - {  
84 - return CronUtils.getNextExecution(cronExpression);  
85 - }  
86 - return null;  
87 - }  
88 -  
89 -}  
ruoyi-quartz/src/main/java/com/ruoyi/quartz/domain/SysJobLog.java deleted
1 -package com.ruoyi.quartz.domain;  
2 -  
3 -import java.util.Date;  
4 -import org.apache.commons.lang3.builder.ToStringBuilder;  
5 -import org.apache.commons.lang3.builder.ToStringStyle;  
6 -import com.ruoyi.common.annotation.Excel;  
7 -import com.ruoyi.common.core.domain.BaseEntity;  
8 -  
9 -/**  
10 - * 定时任务调度日志表 sys_job_log  
11 - *  
12 - * @author ruoyi  
13 - */  
14 -public class SysJobLog extends BaseEntity  
15 -{  
16 - private static final long serialVersionUID = 1L;  
17 -  
18 - /** ID */  
19 - @Excel(name = "日志序号")  
20 - private Long jobLogId;  
21 -  
22 - /** 任务名称 */  
23 - @Excel(name = "任务名称")  
24 - private String jobName;  
25 -  
26 - /** 任务组名 */  
27 - @Excel(name = "任务组名")  
28 - private String jobGroup;  
29 -  
30 - /** 调用目标字符串 */  
31 - @Excel(name = "调用目标字符串")  
32 - private String invokeTarget;  
33 -  
34 - /** 日志信息 */  
35 - @Excel(name = "日志信息")  
36 - private String jobMessage;  
37 -  
38 - /** 执行状态(0正常 1失败) */  
39 - @Excel(name = "执行状态", readConverterExp = "0=正常,1=失败")  
40 - private String status;  
41 -  
42 - /** 异常信息 */  
43 - @Excel(name = "异常信息")  
44 - private String exceptionInfo;  
45 -  
46 - /** 开始时间 */  
47 - private Date startTime;  
48 -  
49 - /** 停止时间 */  
50 - private Date stopTime;  
51 -  
52 -}  
ruoyi-quartz/src/main/java/com/ruoyi/quartz/mapper/SysJobLogMapper.java deleted
1 -package com.ruoyi.quartz.mapper;  
2 -  
3 -import java.util.List;  
4 -import com.ruoyi.quartz.domain.SysJobLog;  
5 -  
6 -/**  
7 - * 调度任务日志信息 数据层  
8 - *  
9 - * @author ruoyi  
10 - */  
11 -public interface SysJobLogMapper  
12 -{  
13 - /**  
14 - * 获取quartz调度器日志的计划任务  
15 - *  
16 - * @param jobLog 调度日志信息  
17 - * @return 调度任务日志集合  
18 - */  
19 - public List<SysJobLog> selectJobLogList(SysJobLog jobLog);  
20 -  
21 - /**  
22 - * 查询所有调度任务日志  
23 - *  
24 - * @return 调度任务日志列表  
25 - */  
26 - public List<SysJobLog> selectJobLogAll();  
27 -  
28 - /**  
29 - * 通过调度任务日志ID查询调度信息  
30 - *  
31 - * @param jobLogId 调度任务日志ID  
32 - * @return 调度任务日志对象信息  
33 - */  
34 - public SysJobLog selectJobLogById(Long jobLogId);  
35 -  
36 - /**  
37 - * 新增任务日志  
38 - *  
39 - * @param jobLog 调度日志信息  
40 - * @return 结果  
41 - */  
42 - public int insertJobLog(SysJobLog jobLog);  
43 -  
44 - /**  
45 - * 批量删除调度日志信息  
46 - *  
47 - * @param logIds 需要删除的数据ID  
48 - * @return 结果  
49 - */  
50 - public int deleteJobLogByIds(Long[] logIds);  
51 -  
52 - /**  
53 - * 删除任务日志  
54 - *  
55 - * @param jobId 调度日志ID  
56 - * @return 结果  
57 - */  
58 - public int deleteJobLogById(Long jobId);  
59 -  
60 - /**  
61 - * 清空任务日志  
62 - */  
63 - public void cleanJobLog();  
64 -}  
ruoyi-quartz/src/main/java/com/ruoyi/quartz/mapper/SysJobMapper.java deleted
1 -package com.ruoyi.quartz.mapper;  
2 -  
3 -import java.util.List;  
4 -import com.ruoyi.quartz.domain.SysJob;  
5 -  
6 -/**  
7 - * 调度任务信息 数据层  
8 - *  
9 - * @author ruoyi  
10 - */  
11 -public interface SysJobMapper  
12 -{  
13 - /**  
14 - * 查询调度任务日志集合  
15 - *  
16 - * @param job 调度信息  
17 - * @return 操作日志集合  
18 - */  
19 - public List<SysJob> selectJobList(SysJob job);  
20 -  
21 - /**  
22 - * 查询所有调度任务  
23 - *  
24 - * @return 调度任务列表  
25 - */  
26 - public List<SysJob> selectJobAll();  
27 -  
28 - /**  
29 - * 通过调度ID查询调度任务信息  
30 - *  
31 - * @param jobId 调度ID  
32 - * @return 角色对象信息  
33 - */  
34 - public SysJob selectJobById(Long jobId);  
35 -  
36 - /**  
37 - * 通过调度ID删除调度任务信息  
38 - *  
39 - * @param jobId 调度ID  
40 - * @return 结果  
41 - */  
42 - public int deleteJobById(Long jobId);  
43 -  
44 - /**  
45 - * 批量删除调度任务信息  
46 - *  
47 - * @param ids 需要删除的数据ID  
48 - * @return 结果  
49 - */  
50 - public int deleteJobByIds(Long[] ids);  
51 -  
52 - /**  
53 - * 修改调度任务信息  
54 - *  
55 - * @param job 调度任务信息  
56 - * @return 结果  
57 - */  
58 - public int updateJob(SysJob job);  
59 -  
60 - /**  
61 - * 新增调度任务信息  
62 - *  
63 - * @param job 调度任务信息  
64 - * @return 结果  
65 - */  
66 - public int insertJob(SysJob job);  
67 -}  
ruoyi-quartz/src/main/java/com/ruoyi/quartz/service/ISysJobLogService.java
1 package com.ruoyi.quartz.service; 1 package com.ruoyi.quartz.service;
2 2
3 import java.util.List; 3 import java.util.List;
  4 +
4 import com.ruoyi.quartz.domain.SysJobLog; 5 import com.ruoyi.quartz.domain.SysJobLog;
5 6
6 /** 7 /**
7 * 定时任务调度日志信息信息 服务层 8 * 定时任务调度日志信息信息 服务层
8 - * 9 + *
9 * @author ruoyi 10 * @author ruoyi
10 */ 11 */
11 -public interface ISysJobLogService  
12 -{ 12 +public interface ISysJobLogService {
13 /** 13 /**
14 * 获取quartz调度器日志的计划任务 14 * 获取quartz调度器日志的计划任务
15 - * 15 + *
16 * @param jobLog 调度日志信息 16 * @param jobLog 调度日志信息
17 * @return 调度任务日志集合 17 * @return 调度任务日志集合
18 */ 18 */
@@ -20,7 +20,7 @@ public interface ISysJobLogService @@ -20,7 +20,7 @@ public interface ISysJobLogService
20 20
21 /** 21 /**
22 * 通过调度任务日志ID查询调度信息 22 * 通过调度任务日志ID查询调度信息
23 - * 23 + *
24 * @param jobLogId 调度任务日志ID 24 * @param jobLogId 调度任务日志ID
25 * @return 调度任务日志对象信息 25 * @return 调度任务日志对象信息
26 */ 26 */
@@ -28,14 +28,14 @@ public interface ISysJobLogService @@ -28,14 +28,14 @@ public interface ISysJobLogService
28 28
29 /** 29 /**
30 * 新增任务日志 30 * 新增任务日志
31 - * 31 + *
32 * @param jobLog 调度日志信息 32 * @param jobLog 调度日志信息
33 */ 33 */
34 public void addJobLog(SysJobLog jobLog); 34 public void addJobLog(SysJobLog jobLog);
35 35
36 /** 36 /**
37 * 批量删除调度日志信息 37 * 批量删除调度日志信息
38 - * 38 + *
39 * @param logIds 需要删除的日志ID 39 * @param logIds 需要删除的日志ID
40 * @return 结果 40 * @return 结果
41 */ 41 */
@@ -43,7 +43,7 @@ public interface ISysJobLogService @@ -43,7 +43,7 @@ public interface ISysJobLogService
43 43
44 /** 44 /**
45 * 删除任务日志 45 * 删除任务日志
46 - * 46 + *
47 * @param jobId 调度日志ID 47 * @param jobId 调度日志ID
48 * @return 结果 48 * @return 结果
49 */ 49 */
ruoyi-quartz/src/main/java/com/ruoyi/quartz/service/ISysJobService.java
1 package com.ruoyi.quartz.service; 1 package com.ruoyi.quartz.service;
2 2
3 import java.util.List; 3 import java.util.List;
  4 +
4 import org.quartz.SchedulerException; 5 import org.quartz.SchedulerException;
5 import com.ruoyi.common.exception.job.TaskException; 6 import com.ruoyi.common.exception.job.TaskException;
6 import com.ruoyi.quartz.domain.SysJob; 7 import com.ruoyi.quartz.domain.SysJob;
7 8
8 /** 9 /**
9 * 定时任务调度信息信息 服务层 10 * 定时任务调度信息信息 服务层
10 - * 11 + *
11 * @author ruoyi 12 * @author ruoyi
12 */ 13 */
13 -public interface ISysJobService  
14 -{ 14 +public interface ISysJobService {
15 /** 15 /**
16 * 获取quartz调度器的计划任务 16 * 获取quartz调度器的计划任务
17 - * 17 + *
18 * @param job 调度信息 18 * @param job 调度信息
19 * @return 调度任务集合 19 * @return 调度任务集合
20 */ 20 */
@@ -22,7 +22,7 @@ public interface ISysJobService @@ -22,7 +22,7 @@ public interface ISysJobService
22 22
23 /** 23 /**
24 * 通过调度任务ID查询调度信息 24 * 通过调度任务ID查询调度信息
25 - * 25 + *
26 * @param jobId 调度任务ID 26 * @param jobId 调度任务ID
27 * @return 调度任务对象信息 27 * @return 调度任务对象信息
28 */ 28 */
@@ -30,7 +30,7 @@ public interface ISysJobService @@ -30,7 +30,7 @@ public interface ISysJobService
30 30
31 /** 31 /**
32 * 暂停任务 32 * 暂停任务
33 - * 33 + *
34 * @param job 调度信息 34 * @param job 调度信息
35 * @return 结果 35 * @return 结果
36 */ 36 */
@@ -38,7 +38,7 @@ public interface ISysJobService @@ -38,7 +38,7 @@ public interface ISysJobService
38 38
39 /** 39 /**
40 * 恢复任务 40 * 恢复任务
41 - * 41 + *
42 * @param job 调度信息 42 * @param job 调度信息
43 * @return 结果 43 * @return 结果
44 */ 44 */
@@ -46,7 +46,7 @@ public interface ISysJobService @@ -46,7 +46,7 @@ public interface ISysJobService
46 46
47 /** 47 /**
48 * 删除任务后,所对应的trigger也将被删除 48 * 删除任务后,所对应的trigger也将被删除
49 - * 49 + *
50 * @param job 调度信息 50 * @param job 调度信息
51 * @return 结果 51 * @return 结果
52 */ 52 */
@@ -54,7 +54,7 @@ public interface ISysJobService @@ -54,7 +54,7 @@ public interface ISysJobService
54 54
55 /** 55 /**
56 * 批量删除调度信息 56 * 批量删除调度信息
57 - * 57 + *
58 * @param jobIds 需要删除的任务ID 58 * @param jobIds 需要删除的任务ID
59 * @return 结果 59 * @return 结果
60 */ 60 */
@@ -62,7 +62,7 @@ public interface ISysJobService @@ -62,7 +62,7 @@ public interface ISysJobService
62 62
63 /** 63 /**
64 * 任务调度状态修改 64 * 任务调度状态修改
65 - * 65 + *
66 * @param job 调度信息 66 * @param job 调度信息
67 * @return 结果 67 * @return 结果
68 */ 68 */
@@ -70,7 +70,7 @@ public interface ISysJobService @@ -70,7 +70,7 @@ public interface ISysJobService
70 70
71 /** 71 /**
72 * 立即运行任务 72 * 立即运行任务
73 - * 73 + *
74 * @param job 调度信息 74 * @param job 调度信息
75 * @return 结果 75 * @return 结果
76 */ 76 */
@@ -78,7 +78,7 @@ public interface ISysJobService @@ -78,7 +78,7 @@ public interface ISysJobService
78 78
79 /** 79 /**
80 * 新增任务 80 * 新增任务
81 - * 81 + *
82 * @param job 调度信息 82 * @param job 调度信息
83 * @return 结果 83 * @return 结果
84 */ 84 */
@@ -86,7 +86,7 @@ public interface ISysJobService @@ -86,7 +86,7 @@ public interface ISysJobService
86 86
87 /** 87 /**
88 * 更新任务 88 * 更新任务
89 - * 89 + *
90 * @param job 调度信息 90 * @param job 调度信息
91 * @return 结果 91 * @return 结果
92 */ 92 */
@@ -94,7 +94,7 @@ public interface ISysJobService @@ -94,7 +94,7 @@ public interface ISysJobService
94 94
95 /** 95 /**
96 * 校验cron表达式是否有效 96 * 校验cron表达式是否有效
97 - * 97 + *
98 * @param cronExpression 表达式 98 * @param cronExpression 表达式
99 * @return 结果 99 * @return 结果
100 */ 100 */
ruoyi-quartz/src/main/java/com/ruoyi/quartz/service/impl/SysJobLogServiceImpl.java
1 package com.ruoyi.quartz.service.impl; 1 package com.ruoyi.quartz.service.impl;
2 2
3 import java.util.List; 3 import java.util.List;
  4 +
4 import org.springframework.beans.factory.annotation.Autowired; 5 import org.springframework.beans.factory.annotation.Autowired;
5 import org.springframework.stereotype.Service; 6 import org.springframework.stereotype.Service;
6 import com.ruoyi.quartz.domain.SysJobLog; 7 import com.ruoyi.quartz.domain.SysJobLog;
@@ -9,70 +10,64 @@ import com.ruoyi.quartz.service.ISysJobLogService; @@ -9,70 +10,64 @@ import com.ruoyi.quartz.service.ISysJobLogService;
9 10
10 /** 11 /**
11 * 定时任务调度日志信息 服务层 12 * 定时任务调度日志信息 服务层
12 - * 13 + *
13 * @author ruoyi 14 * @author ruoyi
14 */ 15 */
15 @Service 16 @Service
16 -public class SysJobLogServiceImpl implements ISysJobLogService  
17 -{ 17 +public class SysJobLogServiceImpl implements ISysJobLogService {
18 @Autowired 18 @Autowired
19 private SysJobLogMapper jobLogMapper; 19 private SysJobLogMapper jobLogMapper;
20 20
21 /** 21 /**
22 * 获取quartz调度器日志的计划任务 22 * 获取quartz调度器日志的计划任务
23 - * 23 + *
24 * @param jobLog 调度日志信息 24 * @param jobLog 调度日志信息
25 * @return 调度任务日志集合 25 * @return 调度任务日志集合
26 */ 26 */
27 @Override 27 @Override
28 - public List<SysJobLog> selectJobLogList(SysJobLog jobLog)  
29 - { 28 + public List<SysJobLog> selectJobLogList(SysJobLog jobLog) {
30 return jobLogMapper.selectJobLogList(jobLog); 29 return jobLogMapper.selectJobLogList(jobLog);
31 } 30 }
32 31
33 /** 32 /**
34 * 通过调度任务日志ID查询调度信息 33 * 通过调度任务日志ID查询调度信息
35 - * 34 + *
36 * @param jobLogId 调度任务日志ID 35 * @param jobLogId 调度任务日志ID
37 * @return 调度任务日志对象信息 36 * @return 调度任务日志对象信息
38 */ 37 */
39 @Override 38 @Override
40 - public SysJobLog selectJobLogById(Long jobLogId)  
41 - { 39 + public SysJobLog selectJobLogById(Long jobLogId) {
42 return jobLogMapper.selectJobLogById(jobLogId); 40 return jobLogMapper.selectJobLogById(jobLogId);
43 } 41 }
44 42
45 /** 43 /**
46 * 新增任务日志 44 * 新增任务日志
47 - * 45 + *
48 * @param jobLog 调度日志信息 46 * @param jobLog 调度日志信息
49 */ 47 */
50 @Override 48 @Override
51 - public void addJobLog(SysJobLog jobLog)  
52 - { 49 + public void addJobLog(SysJobLog jobLog) {
53 jobLogMapper.insertJobLog(jobLog); 50 jobLogMapper.insertJobLog(jobLog);
54 } 51 }
55 52
56 /** 53 /**
57 * 批量删除调度日志信息 54 * 批量删除调度日志信息
58 - * 55 + *
59 * @param logIds 需要删除的数据ID 56 * @param logIds 需要删除的数据ID
60 * @return 结果 57 * @return 结果
61 */ 58 */
62 @Override 59 @Override
63 - public int deleteJobLogByIds(Long[] logIds)  
64 - { 60 + public int deleteJobLogByIds(Long[] logIds) {
65 return jobLogMapper.deleteJobLogByIds(logIds); 61 return jobLogMapper.deleteJobLogByIds(logIds);
66 } 62 }
67 63
68 /** 64 /**
69 * 删除任务日志 65 * 删除任务日志
70 - * 66 + *
71 * @param jobId 调度日志ID 67 * @param jobId 调度日志ID
72 */ 68 */
73 @Override 69 @Override
74 - public int deleteJobLogById(Long jobId)  
75 - { 70 + public int deleteJobLogById(Long jobId) {
76 return jobLogMapper.deleteJobLogById(jobId); 71 return jobLogMapper.deleteJobLogById(jobId);
77 } 72 }
78 73
@@ -80,8 +75,7 @@ public class SysJobLogServiceImpl implements ISysJobLogService @@ -80,8 +75,7 @@ public class SysJobLogServiceImpl implements ISysJobLogService
80 * 清空任务日志 75 * 清空任务日志
81 */ 76 */
82 @Override 77 @Override
83 - public void cleanJobLog()  
84 - { 78 + public void cleanJobLog() {
85 jobLogMapper.cleanJobLog(); 79 jobLogMapper.cleanJobLog();
86 } 80 }
87 } 81 }
ruoyi-quartz/src/main/java/com/ruoyi/quartz/service/impl/SysJobServiceImpl.java
@@ -2,6 +2,7 @@ package com.ruoyi.quartz.service.impl; @@ -2,6 +2,7 @@ package com.ruoyi.quartz.service.impl;
2 2
3 import java.util.List; 3 import java.util.List;
4 import javax.annotation.PostConstruct; 4 import javax.annotation.PostConstruct;
  5 +
5 import org.quartz.JobDataMap; 6 import org.quartz.JobDataMap;
6 import org.quartz.JobKey; 7 import org.quartz.JobKey;
7 import org.quartz.Scheduler; 8 import org.quartz.Scheduler;
@@ -19,12 +20,11 @@ import com.ruoyi.quartz.util.ScheduleUtils; @@ -19,12 +20,11 @@ import com.ruoyi.quartz.util.ScheduleUtils;
19 20
20 /** 21 /**
21 * 定时任务调度信息 服务层 22 * 定时任务调度信息 服务层
22 - * 23 + *
23 * @author ruoyi 24 * @author ruoyi
24 */ 25 */
25 @Service 26 @Service
26 -public class SysJobServiceImpl implements ISysJobService  
27 -{ 27 +public class SysJobServiceImpl implements ISysJobService {
28 @Autowired 28 @Autowired
29 private Scheduler scheduler; 29 private Scheduler scheduler;
30 30
@@ -35,55 +35,49 @@ public class SysJobServiceImpl implements ISysJobService @@ -35,55 +35,49 @@ public class SysJobServiceImpl implements ISysJobService
35 * 项目启动时,初始化定时器 主要是防止手动修改数据库导致未同步到定时任务处理(注:不能手动修改数据库ID和任务组名,否则会导致脏数据) 35 * 项目启动时,初始化定时器 主要是防止手动修改数据库导致未同步到定时任务处理(注:不能手动修改数据库ID和任务组名,否则会导致脏数据)
36 */ 36 */
37 @PostConstruct 37 @PostConstruct
38 - public void init() throws SchedulerException, TaskException  
39 - { 38 + public void init() throws SchedulerException, TaskException {
40 scheduler.clear(); 39 scheduler.clear();
41 List<SysJob> jobList = jobMapper.selectJobAll(); 40 List<SysJob> jobList = jobMapper.selectJobAll();
42 - for (SysJob job : jobList)  
43 - { 41 + for (SysJob job : jobList) {
44 ScheduleUtils.createScheduleJob(scheduler, job); 42 ScheduleUtils.createScheduleJob(scheduler, job);
45 } 43 }
46 } 44 }
47 45
48 /** 46 /**
49 * 获取quartz调度器的计划任务列表 47 * 获取quartz调度器的计划任务列表
50 - * 48 + *
51 * @param job 调度信息 49 * @param job 调度信息
52 * @return 50 * @return
53 */ 51 */
54 @Override 52 @Override
55 - public List<SysJob> selectJobList(SysJob job)  
56 - { 53 + public List<SysJob> selectJobList(SysJob job) {
57 return jobMapper.selectJobList(job); 54 return jobMapper.selectJobList(job);
58 } 55 }
59 56
60 /** 57 /**
61 * 通过调度任务ID查询调度信息 58 * 通过调度任务ID查询调度信息
62 - * 59 + *
63 * @param jobId 调度任务ID 60 * @param jobId 调度任务ID
64 * @return 调度任务对象信息 61 * @return 调度任务对象信息
65 */ 62 */
66 @Override 63 @Override
67 - public SysJob selectJobById(Long jobId)  
68 - { 64 + public SysJob selectJobById(Long jobId) {
69 return jobMapper.selectJobById(jobId); 65 return jobMapper.selectJobById(jobId);
70 } 66 }
71 67
72 /** 68 /**
73 * 暂停任务 69 * 暂停任务
74 - * 70 + *
75 * @param job 调度信息 71 * @param job 调度信息
76 */ 72 */
77 @Override 73 @Override
78 @Transactional 74 @Transactional
79 - public int pauseJob(SysJob job) throws SchedulerException  
80 - { 75 + public int pauseJob(SysJob job) throws SchedulerException {
81 Long jobId = job.getJobId(); 76 Long jobId = job.getJobId();
82 String jobGroup = job.getJobGroup(); 77 String jobGroup = job.getJobGroup();
83 job.setStatus(ScheduleConstants.Status.PAUSE.getValue()); 78 job.setStatus(ScheduleConstants.Status.PAUSE.getValue());
84 int rows = jobMapper.updateJob(job); 79 int rows = jobMapper.updateJob(job);
85 - if (rows > 0)  
86 - { 80 + if (rows > 0) {
87 scheduler.pauseJob(ScheduleUtils.getJobKey(jobId, jobGroup)); 81 scheduler.pauseJob(ScheduleUtils.getJobKey(jobId, jobGroup));
88 } 82 }
89 return rows; 83 return rows;
@@ -91,19 +85,17 @@ public class SysJobServiceImpl implements ISysJobService @@ -91,19 +85,17 @@ public class SysJobServiceImpl implements ISysJobService
91 85
92 /** 86 /**
93 * 恢复任务 87 * 恢复任务
94 - * 88 + *
95 * @param job 调度信息 89 * @param job 调度信息
96 */ 90 */
97 @Override 91 @Override
98 @Transactional 92 @Transactional
99 - public int resumeJob(SysJob job) throws SchedulerException  
100 - { 93 + public int resumeJob(SysJob job) throws SchedulerException {
101 Long jobId = job.getJobId(); 94 Long jobId = job.getJobId();
102 String jobGroup = job.getJobGroup(); 95 String jobGroup = job.getJobGroup();
103 job.setStatus(ScheduleConstants.Status.NORMAL.getValue()); 96 job.setStatus(ScheduleConstants.Status.NORMAL.getValue());
104 int rows = jobMapper.updateJob(job); 97 int rows = jobMapper.updateJob(job);
105 - if (rows > 0)  
106 - { 98 + if (rows > 0) {
107 scheduler.resumeJob(ScheduleUtils.getJobKey(jobId, jobGroup)); 99 scheduler.resumeJob(ScheduleUtils.getJobKey(jobId, jobGroup));
108 } 100 }
109 return rows; 101 return rows;
@@ -111,18 +103,16 @@ public class SysJobServiceImpl implements ISysJobService @@ -111,18 +103,16 @@ public class SysJobServiceImpl implements ISysJobService
111 103
112 /** 104 /**
113 * 删除任务后,所对应的trigger也将被删除 105 * 删除任务后,所对应的trigger也将被删除
114 - * 106 + *
115 * @param job 调度信息 107 * @param job 调度信息
116 */ 108 */
117 @Override 109 @Override
118 @Transactional 110 @Transactional
119 - public int deleteJob(SysJob job) throws SchedulerException  
120 - { 111 + public int deleteJob(SysJob job) throws SchedulerException {
121 Long jobId = job.getJobId(); 112 Long jobId = job.getJobId();
122 String jobGroup = job.getJobGroup(); 113 String jobGroup = job.getJobGroup();
123 int rows = jobMapper.deleteJobById(jobId); 114 int rows = jobMapper.deleteJobById(jobId);
124 - if (rows > 0)  
125 - { 115 + if (rows > 0) {
126 scheduler.deleteJob(ScheduleUtils.getJobKey(jobId, jobGroup)); 116 scheduler.deleteJob(ScheduleUtils.getJobKey(jobId, jobGroup));
127 } 117 }
128 return rows; 118 return rows;
@@ -130,16 +120,14 @@ public class SysJobServiceImpl implements ISysJobService @@ -130,16 +120,14 @@ public class SysJobServiceImpl implements ISysJobService
130 120
131 /** 121 /**
132 * 批量删除调度信息 122 * 批量删除调度信息
133 - * 123 + *
134 * @param jobIds 需要删除的任务ID 124 * @param jobIds 需要删除的任务ID
135 * @return 结果 125 * @return 结果
136 */ 126 */
137 @Override 127 @Override
138 @Transactional 128 @Transactional
139 - public void deleteJobByIds(Long[] jobIds) throws SchedulerException  
140 - {  
141 - for (Long jobId : jobIds)  
142 - { 129 + public void deleteJobByIds(Long[] jobIds) throws SchedulerException {
  130 + for (Long jobId : jobIds) {
143 SysJob job = jobMapper.selectJobById(jobId); 131 SysJob job = jobMapper.selectJobById(jobId);
144 deleteJob(job); 132 deleteJob(job);
145 } 133 }
@@ -147,21 +135,17 @@ public class SysJobServiceImpl implements ISysJobService @@ -147,21 +135,17 @@ public class SysJobServiceImpl implements ISysJobService
147 135
148 /** 136 /**
149 * 任务调度状态修改 137 * 任务调度状态修改
150 - * 138 + *
151 * @param job 调度信息 139 * @param job 调度信息
152 */ 140 */
153 @Override 141 @Override
154 @Transactional 142 @Transactional
155 - public int changeStatus(SysJob job) throws SchedulerException  
156 - { 143 + public int changeStatus(SysJob job) throws SchedulerException {
157 int rows = 0; 144 int rows = 0;
158 String status = job.getStatus(); 145 String status = job.getStatus();
159 - if (ScheduleConstants.Status.NORMAL.getValue().equals(status))  
160 - { 146 + if (ScheduleConstants.Status.NORMAL.getValue().equals(status)) {
161 rows = resumeJob(job); 147 rows = resumeJob(job);
162 - }  
163 - else if (ScheduleConstants.Status.PAUSE.getValue().equals(status))  
164 - { 148 + } else if (ScheduleConstants.Status.PAUSE.getValue().equals(status)) {
165 rows = pauseJob(job); 149 rows = pauseJob(job);
166 } 150 }
167 return rows; 151 return rows;
@@ -169,13 +153,12 @@ public class SysJobServiceImpl implements ISysJobService @@ -169,13 +153,12 @@ public class SysJobServiceImpl implements ISysJobService
169 153
170 /** 154 /**
171 * 立即运行任务 155 * 立即运行任务
172 - * 156 + *
173 * @param job 调度信息 157 * @param job 调度信息
174 */ 158 */
175 @Override 159 @Override
176 @Transactional 160 @Transactional
177 - public void run(SysJob job) throws SchedulerException  
178 - { 161 + public void run(SysJob job) throws SchedulerException {
179 Long jobId = job.getJobId(); 162 Long jobId = job.getJobId();
180 String jobGroup = job.getJobGroup(); 163 String jobGroup = job.getJobGroup();
181 SysJob properties = selectJobById(job.getJobId()); 164 SysJob properties = selectJobById(job.getJobId());
@@ -187,17 +170,15 @@ public class SysJobServiceImpl implements ISysJobService @@ -187,17 +170,15 @@ public class SysJobServiceImpl implements ISysJobService
187 170
188 /** 171 /**
189 * 新增任务 172 * 新增任务
190 - * 173 + *
191 * @param job 调度信息 调度信息 174 * @param job 调度信息 调度信息
192 */ 175 */
193 @Override 176 @Override
194 @Transactional 177 @Transactional
195 - public int insertJob(SysJob job) throws SchedulerException, TaskException  
196 - { 178 + public int insertJob(SysJob job) throws SchedulerException, TaskException {
197 job.setStatus(ScheduleConstants.Status.PAUSE.getValue()); 179 job.setStatus(ScheduleConstants.Status.PAUSE.getValue());
198 int rows = jobMapper.insertJob(job); 180 int rows = jobMapper.insertJob(job);
199 - if (rows > 0)  
200 - { 181 + if (rows > 0) {
201 ScheduleUtils.createScheduleJob(scheduler, job); 182 ScheduleUtils.createScheduleJob(scheduler, job);
202 } 183 }
203 return rows; 184 return rows;
@@ -205,17 +186,15 @@ public class SysJobServiceImpl implements ISysJobService @@ -205,17 +186,15 @@ public class SysJobServiceImpl implements ISysJobService
205 186
206 /** 187 /**
207 * 更新任务的时间表达式 188 * 更新任务的时间表达式
208 - * 189 + *
209 * @param job 调度信息 190 * @param job 调度信息
210 */ 191 */
211 @Override 192 @Override
212 @Transactional 193 @Transactional
213 - public int updateJob(SysJob job) throws SchedulerException, TaskException  
214 - { 194 + public int updateJob(SysJob job) throws SchedulerException, TaskException {
215 SysJob properties = selectJobById(job.getJobId()); 195 SysJob properties = selectJobById(job.getJobId());
216 int rows = jobMapper.updateJob(job); 196 int rows = jobMapper.updateJob(job);
217 - if (rows > 0)  
218 - { 197 + if (rows > 0) {
219 updateSchedulerJob(job, properties.getJobGroup()); 198 updateSchedulerJob(job, properties.getJobGroup());
220 } 199 }
221 return rows; 200 return rows;
@@ -223,17 +202,15 @@ public class SysJobServiceImpl implements ISysJobService @@ -223,17 +202,15 @@ public class SysJobServiceImpl implements ISysJobService
223 202
224 /** 203 /**
225 * 更新任务 204 * 更新任务
226 - *  
227 - * @param job 任务对象 205 + *
  206 + * @param job 任务对象
228 * @param jobGroup 任务组名 207 * @param jobGroup 任务组名
229 */ 208 */
230 - public void updateSchedulerJob(SysJob job, String jobGroup) throws SchedulerException, TaskException  
231 - { 209 + public void updateSchedulerJob(SysJob job, String jobGroup) throws SchedulerException, TaskException {
232 Long jobId = job.getJobId(); 210 Long jobId = job.getJobId();
233 // 判断是否存在 211 // 判断是否存在
234 JobKey jobKey = ScheduleUtils.getJobKey(jobId, jobGroup); 212 JobKey jobKey = ScheduleUtils.getJobKey(jobId, jobGroup);
235 - if (scheduler.checkExists(jobKey))  
236 - { 213 + if (scheduler.checkExists(jobKey)) {
237 // 防止创建时存在数据问题 先移除,然后在执行创建操作 214 // 防止创建时存在数据问题 先移除,然后在执行创建操作
238 scheduler.deleteJob(jobKey); 215 scheduler.deleteJob(jobKey);
239 } 216 }
@@ -242,13 +219,12 @@ public class SysJobServiceImpl implements ISysJobService @@ -242,13 +219,12 @@ public class SysJobServiceImpl implements ISysJobService
242 219
243 /** 220 /**
244 * 校验cron表达式是否有效 221 * 校验cron表达式是否有效
245 - * 222 + *
246 * @param cronExpression 表达式 223 * @param cronExpression 表达式
247 * @return 结果 224 * @return 结果
248 */ 225 */
249 @Override 226 @Override
250 - public boolean checkCronExpressionIsValid(String cronExpression)  
251 - { 227 + public boolean checkCronExpressionIsValid(String cronExpression) {
252 return CronUtils.isValid(cronExpression); 228 return CronUtils.isValid(cronExpression);
253 } 229 }
254 } 230 }
ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/RyTask.java
@@ -5,24 +5,20 @@ import com.ruoyi.common.utils.StringUtils; @@ -5,24 +5,20 @@ import com.ruoyi.common.utils.StringUtils;
5 5
6 /** 6 /**
7 * 定时任务调度测试 7 * 定时任务调度测试
8 - * 8 + *
9 * @author ruoyi 9 * @author ruoyi
10 */ 10 */
11 @Component("ryTask") 11 @Component("ryTask")
12 -public class RyTask  
13 -{  
14 - public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i)  
15 - { 12 +public class RyTask {
  13 + public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i) {
16 System.out.println(StringUtils.format("执行多参方法: 字符串类型{},布尔类型{},长整型{},浮点型{},整形{}", s, b, l, d, i)); 14 System.out.println(StringUtils.format("执行多参方法: 字符串类型{},布尔类型{},长整型{},浮点型{},整形{}", s, b, l, d, i));
17 } 15 }
18 16
19 - public void ryParams(String params)  
20 - { 17 + public void ryParams(String params) {
21 System.out.println("执行有参方法:" + params); 18 System.out.println("执行有参方法:" + params);
22 } 19 }
23 20
24 - public void ryNoParams()  
25 - { 21 + public void ryNoParams() {
26 System.out.println("执行无参方法"); 22 System.out.println("执行无参方法");
27 } 23 }
28 } 24 }
ruoyi-quartz/src/main/java/com/ruoyi/quartz/util/AbstractQuartzJob.java
1 package com.ruoyi.quartz.util; 1 package com.ruoyi.quartz.util;
2 2
3 import java.util.Date; 3 import java.util.Date;
  4 +
4 import org.quartz.Job; 5 import org.quartz.Job;
5 import org.quartz.JobExecutionContext; 6 import org.quartz.JobExecutionContext;
6 import org.quartz.JobExecutionException; 7 import org.quartz.JobExecutionException;
@@ -21,8 +22,7 @@ import com.ruoyi.quartz.service.ISysJobLogService; @@ -21,8 +22,7 @@ import com.ruoyi.quartz.service.ISysJobLogService;
21 * 22 *
22 * @author ruoyi 23 * @author ruoyi
23 */ 24 */
24 -public abstract class AbstractQuartzJob implements Job  
25 -{ 25 +public abstract class AbstractQuartzJob implements Job {
26 private static final Logger log = LoggerFactory.getLogger(AbstractQuartzJob.class); 26 private static final Logger log = LoggerFactory.getLogger(AbstractQuartzJob.class);
27 27
28 /** 28 /**
@@ -31,21 +31,16 @@ public abstract class AbstractQuartzJob implements Job @@ -31,21 +31,16 @@ public abstract class AbstractQuartzJob implements Job
31 private static ThreadLocal<Date> threadLocal = new ThreadLocal<>(); 31 private static ThreadLocal<Date> threadLocal = new ThreadLocal<>();
32 32
33 @Override 33 @Override
34 - public void execute(JobExecutionContext context) throws JobExecutionException  
35 - { 34 + public void execute(JobExecutionContext context) throws JobExecutionException {
36 SysJob sysJob = new SysJob(); 35 SysJob sysJob = new SysJob();
37 BeanUtils.copyBeanProp(sysJob, context.getMergedJobDataMap().get(ScheduleConstants.TASK_PROPERTIES)); 36 BeanUtils.copyBeanProp(sysJob, context.getMergedJobDataMap().get(ScheduleConstants.TASK_PROPERTIES));
38 - try  
39 - { 37 + try {
40 before(context, sysJob); 38 before(context, sysJob);
41 - if (sysJob != null)  
42 - { 39 + if (sysJob != null) {
43 doExecute(context, sysJob); 40 doExecute(context, sysJob);
44 } 41 }
45 after(context, sysJob, null); 42 after(context, sysJob, null);
46 - }  
47 - catch (Exception e)  
48 - { 43 + } catch (Exception e) {
49 log.error("任务执行异常 - :", e); 44 log.error("任务执行异常 - :", e);
50 after(context, sysJob, e); 45 after(context, sysJob, e);
51 } 46 }
@@ -55,10 +50,9 @@ public abstract class AbstractQuartzJob implements Job @@ -55,10 +50,9 @@ public abstract class AbstractQuartzJob implements Job
55 * 执行前 50 * 执行前
56 * 51 *
57 * @param context 工作执行上下文对象 52 * @param context 工作执行上下文对象
58 - * @param sysJob 系统计划任务 53 + * @param sysJob 系统计划任务
59 */ 54 */
60 - protected void before(JobExecutionContext context, SysJob sysJob)  
61 - { 55 + protected void before(JobExecutionContext context, SysJob sysJob) {
62 threadLocal.set(new Date()); 56 threadLocal.set(new Date());
63 } 57 }
64 58
@@ -66,10 +60,9 @@ public abstract class AbstractQuartzJob implements Job @@ -66,10 +60,9 @@ public abstract class AbstractQuartzJob implements Job
66 * 执行后 60 * 执行后
67 * 61 *
68 * @param context 工作执行上下文对象 62 * @param context 工作执行上下文对象
69 - * @param sysJob 系统计划任务 63 + * @param sysJob 系统计划任务
70 */ 64 */
71 - protected void after(JobExecutionContext context, SysJob sysJob, Exception e)  
72 - { 65 + protected void after(JobExecutionContext context, SysJob sysJob, Exception e) {
73 Date startTime = threadLocal.get(); 66 Date startTime = threadLocal.get();
74 threadLocal.remove(); 67 threadLocal.remove();
75 68
@@ -81,14 +74,11 @@ public abstract class AbstractQuartzJob implements Job @@ -81,14 +74,11 @@ public abstract class AbstractQuartzJob implements Job
81 sysJobLog.setStopTime(new Date()); 74 sysJobLog.setStopTime(new Date());
82 long runMs = sysJobLog.getStopTime().getTime() - sysJobLog.getStartTime().getTime(); 75 long runMs = sysJobLog.getStopTime().getTime() - sysJobLog.getStartTime().getTime();
83 sysJobLog.setJobMessage(sysJobLog.getJobName() + " 总共耗时:" + runMs + "毫秒"); 76 sysJobLog.setJobMessage(sysJobLog.getJobName() + " 总共耗时:" + runMs + "毫秒");
84 - if (e != null)  
85 - { 77 + if (e != null) {
86 sysJobLog.setStatus(Constants.FAIL); 78 sysJobLog.setStatus(Constants.FAIL);
87 String errorMsg = StringUtils.substring(ExceptionUtil.getExceptionMessage(e), 0, 2000); 79 String errorMsg = StringUtils.substring(ExceptionUtil.getExceptionMessage(e), 0, 2000);
88 sysJobLog.setExceptionInfo(errorMsg); 80 sysJobLog.setExceptionInfo(errorMsg);
89 - }  
90 - else  
91 - { 81 + } else {
92 sysJobLog.setStatus(Constants.SUCCESS); 82 sysJobLog.setStatus(Constants.SUCCESS);
93 } 83 }
94 84
@@ -100,7 +90,7 @@ public abstract class AbstractQuartzJob implements Job @@ -100,7 +90,7 @@ public abstract class AbstractQuartzJob implements Job
100 * 执行方法,由子类重载 90 * 执行方法,由子类重载
101 * 91 *
102 * @param context 工作执行上下文对象 92 * @param context 工作执行上下文对象
103 - * @param sysJob 系统计划任务 93 + * @param sysJob 系统计划任务
104 * @throws Exception 执行过程中的异常 94 * @throws Exception 执行过程中的异常
105 */ 95 */
106 protected abstract void doExecute(JobExecutionContext context, SysJob sysJob) throws Exception; 96 protected abstract void doExecute(JobExecutionContext context, SysJob sysJob) throws Exception;
ruoyi-quartz/src/main/java/com/ruoyi/quartz/util/CronUtils.java
@@ -2,24 +2,22 @@ package com.ruoyi.quartz.util; @@ -2,24 +2,22 @@ package com.ruoyi.quartz.util;
2 2
3 import java.text.ParseException; 3 import java.text.ParseException;
4 import java.util.Date; 4 import java.util.Date;
  5 +
5 import org.quartz.CronExpression; 6 import org.quartz.CronExpression;
6 7
7 /** 8 /**
8 * cron表达式工具类 9 * cron表达式工具类
9 - *  
10 - * @author ruoyi  
11 * 10 *
  11 + * @author ruoyi
12 */ 12 */
13 -public class CronUtils  
14 -{ 13 +public class CronUtils {
15 /** 14 /**
16 * 返回一个布尔值代表一个给定的Cron表达式的有效性 15 * 返回一个布尔值代表一个给定的Cron表达式的有效性
17 * 16 *
18 * @param cronExpression Cron表达式 17 * @param cronExpression Cron表达式
19 * @return boolean 表达式是否有效 18 * @return boolean 表达式是否有效
20 */ 19 */
21 - public static boolean isValid(String cronExpression)  
22 - { 20 + public static boolean isValid(String cronExpression) {
23 return CronExpression.isValidExpression(cronExpression); 21 return CronExpression.isValidExpression(cronExpression);
24 } 22 }
25 23
@@ -29,15 +27,11 @@ public class CronUtils @@ -29,15 +27,11 @@ public class CronUtils
29 * @param cronExpression Cron表达式 27 * @param cronExpression Cron表达式
30 * @return String 无效时返回表达式错误描述,如果有效返回null 28 * @return String 无效时返回表达式错误描述,如果有效返回null
31 */ 29 */
32 - public static String getInvalidMessage(String cronExpression)  
33 - {  
34 - try  
35 - { 30 + public static String getInvalidMessage(String cronExpression) {
  31 + try {
36 new CronExpression(cronExpression); 32 new CronExpression(cronExpression);
37 return null; 33 return null;
38 - }  
39 - catch (ParseException pe)  
40 - { 34 + } catch (ParseException pe) {
41 return pe.getMessage(); 35 return pe.getMessage();
42 } 36 }
43 } 37 }
@@ -48,15 +42,11 @@ public class CronUtils @@ -48,15 +42,11 @@ public class CronUtils
48 * @param cronExpression Cron表达式 42 * @param cronExpression Cron表达式
49 * @return Date 下次Cron表达式执行时间 43 * @return Date 下次Cron表达式执行时间
50 */ 44 */
51 - public static Date getNextExecution(String cronExpression)  
52 - {  
53 - try  
54 - { 45 + public static Date getNextExecution(String cronExpression) {
  46 + try {
55 CronExpression cron = new CronExpression(cronExpression); 47 CronExpression cron = new CronExpression(cronExpression);
56 return cron.getNextValidTimeAfter(new Date(System.currentTimeMillis())); 48 return cron.getNextValidTimeAfter(new Date(System.currentTimeMillis()));
57 - }  
58 - catch (ParseException e)  
59 - { 49 + } catch (ParseException e) {
60 throw new IllegalArgumentException(e.getMessage()); 50 throw new IllegalArgumentException(e.getMessage());
61 } 51 }
62 } 52 }
ruoyi-quartz/src/main/java/com/ruoyi/quartz/util/JobInvokeUtil.java
@@ -4,6 +4,7 @@ import java.lang.reflect.InvocationTargetException; @@ -4,6 +4,7 @@ import java.lang.reflect.InvocationTargetException;
4 import java.lang.reflect.Method; 4 import java.lang.reflect.Method;
5 import java.util.LinkedList; 5 import java.util.LinkedList;
6 import java.util.List; 6 import java.util.List;
  7 +
7 import com.ruoyi.common.utils.StringUtils; 8 import com.ruoyi.common.utils.StringUtils;
8 import com.ruoyi.common.utils.spring.SpringUtils; 9 import com.ruoyi.common.utils.spring.SpringUtils;
9 import com.ruoyi.quartz.domain.SysJob; 10 import com.ruoyi.quartz.domain.SysJob;
@@ -13,27 +14,22 @@ import com.ruoyi.quartz.domain.SysJob; @@ -13,27 +14,22 @@ import com.ruoyi.quartz.domain.SysJob;
13 * 14 *
14 * @author ruoyi 15 * @author ruoyi
15 */ 16 */
16 -public class JobInvokeUtil  
17 -{ 17 +public class JobInvokeUtil {
18 /** 18 /**
19 * 执行方法 19 * 执行方法
20 * 20 *
21 * @param sysJob 系统任务 21 * @param sysJob 系统任务
22 */ 22 */
23 - public static void invokeMethod(SysJob sysJob) throws Exception  
24 - { 23 + public static void invokeMethod(SysJob sysJob) throws Exception {
25 String invokeTarget = sysJob.getInvokeTarget(); 24 String invokeTarget = sysJob.getInvokeTarget();
26 String beanName = getBeanName(invokeTarget); 25 String beanName = getBeanName(invokeTarget);
27 String methodName = getMethodName(invokeTarget); 26 String methodName = getMethodName(invokeTarget);
28 List<Object[]> methodParams = getMethodParams(invokeTarget); 27 List<Object[]> methodParams = getMethodParams(invokeTarget);
29 28
30 - if (!isValidClassName(beanName))  
31 - { 29 + if (!isValidClassName(beanName)) {
32 Object bean = SpringUtils.getBean(beanName); 30 Object bean = SpringUtils.getBean(beanName);
33 invokeMethod(bean, methodName, methodParams); 31 invokeMethod(bean, methodName, methodParams);
34 - }  
35 - else  
36 - { 32 + } else {
37 Object bean = Class.forName(beanName).newInstance(); 33 Object bean = Class.forName(beanName).newInstance();
38 invokeMethod(bean, methodName, methodParams); 34 invokeMethod(bean, methodName, methodParams);
39 } 35 }
@@ -42,21 +38,17 @@ public class JobInvokeUtil @@ -42,21 +38,17 @@ public class JobInvokeUtil
42 /** 38 /**
43 * 调用任务方法 39 * 调用任务方法
44 * 40 *
45 - * @param bean 目标对象  
46 - * @param methodName 方法名称 41 + * @param bean 目标对象
  42 + * @param methodName 方法名称
47 * @param methodParams 方法参数 43 * @param methodParams 方法参数
48 */ 44 */
49 private static void invokeMethod(Object bean, String methodName, List<Object[]> methodParams) 45 private static void invokeMethod(Object bean, String methodName, List<Object[]> methodParams)
50 throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, 46 throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException,
51 - InvocationTargetException  
52 - {  
53 - if (StringUtils.isNotNull(methodParams) && methodParams.size() > 0)  
54 - { 47 + InvocationTargetException {
  48 + if (StringUtils.isNotNull(methodParams) && methodParams.size() > 0) {
55 Method method = bean.getClass().getDeclaredMethod(methodName, getMethodParamsType(methodParams)); 49 Method method = bean.getClass().getDeclaredMethod(methodName, getMethodParamsType(methodParams));
56 method.invoke(bean, getMethodParamsValue(methodParams)); 50 method.invoke(bean, getMethodParamsValue(methodParams));
57 - }  
58 - else  
59 - { 51 + } else {
60 Method method = bean.getClass().getDeclaredMethod(methodName); 52 Method method = bean.getClass().getDeclaredMethod(methodName);
61 method.invoke(bean); 53 method.invoke(bean);
62 } 54 }
@@ -64,81 +56,70 @@ public class JobInvokeUtil @@ -64,81 +56,70 @@ public class JobInvokeUtil
64 56
65 /** 57 /**
66 * 校验是否为为class包名 58 * 校验是否为为class包名
67 - * 59 + *
68 * @param str 名称 60 * @param str 名称
69 * @return true是 false否 61 * @return true是 false否
70 */ 62 */
71 - public static boolean isValidClassName(String invokeTarget)  
72 - { 63 + public static boolean isValidClassName(String invokeTarget) {
73 return StringUtils.countMatches(invokeTarget, ".") > 1; 64 return StringUtils.countMatches(invokeTarget, ".") > 1;
74 } 65 }
75 66
76 /** 67 /**
77 * 获取bean名称 68 * 获取bean名称
78 - * 69 + *
79 * @param invokeTarget 目标字符串 70 * @param invokeTarget 目标字符串
80 * @return bean名称 71 * @return bean名称
81 */ 72 */
82 - public static String getBeanName(String invokeTarget)  
83 - { 73 + public static String getBeanName(String invokeTarget) {
84 String beanName = StringUtils.substringBefore(invokeTarget, "("); 74 String beanName = StringUtils.substringBefore(invokeTarget, "(");
85 return StringUtils.substringBeforeLast(beanName, "."); 75 return StringUtils.substringBeforeLast(beanName, ".");
86 } 76 }
87 77
88 /** 78 /**
89 * 获取bean方法 79 * 获取bean方法
90 - * 80 + *
91 * @param invokeTarget 目标字符串 81 * @param invokeTarget 目标字符串
92 * @return method方法 82 * @return method方法
93 */ 83 */
94 - public static String getMethodName(String invokeTarget)  
95 - { 84 + public static String getMethodName(String invokeTarget) {
96 String methodName = StringUtils.substringBefore(invokeTarget, "("); 85 String methodName = StringUtils.substringBefore(invokeTarget, "(");
97 return StringUtils.substringAfterLast(methodName, "."); 86 return StringUtils.substringAfterLast(methodName, ".");
98 } 87 }
99 88
100 /** 89 /**
101 * 获取method方法参数相关列表 90 * 获取method方法参数相关列表
102 - * 91 + *
103 * @param invokeTarget 目标字符串 92 * @param invokeTarget 目标字符串
104 * @return method方法相关参数列表 93 * @return method方法相关参数列表
105 */ 94 */
106 - public static List<Object[]> getMethodParams(String invokeTarget)  
107 - { 95 + public static List<Object[]> getMethodParams(String invokeTarget) {
108 String methodStr = StringUtils.substringBetween(invokeTarget, "(", ")"); 96 String methodStr = StringUtils.substringBetween(invokeTarget, "(", ")");
109 - if (StringUtils.isEmpty(methodStr))  
110 - { 97 + if (StringUtils.isEmpty(methodStr)) {
111 return null; 98 return null;
112 } 99 }
113 String[] methodParams = methodStr.split(","); 100 String[] methodParams = methodStr.split(",");
114 List<Object[]> classs = new LinkedList<>(); 101 List<Object[]> classs = new LinkedList<>();
115 - for (int i = 0; i < methodParams.length; i++)  
116 - { 102 + for (int i = 0; i < methodParams.length; i++) {
117 String str = StringUtils.trimToEmpty(methodParams[i]); 103 String str = StringUtils.trimToEmpty(methodParams[i]);
118 // String字符串类型,包含' 104 // String字符串类型,包含'
119 - if (StringUtils.contains(str, "'"))  
120 - {  
121 - classs.add(new Object[] { StringUtils.replace(str, "'", ""), String.class }); 105 + if (StringUtils.contains(str, "'")) {
  106 + classs.add(new Object[]{StringUtils.replace(str, "'", ""), String.class});
122 } 107 }
123 // boolean布尔类型,等于true或者false 108 // boolean布尔类型,等于true或者false
124 - else if (StringUtils.equals(str, "true") || StringUtils.equalsIgnoreCase(str, "false"))  
125 - {  
126 - classs.add(new Object[] { Boolean.valueOf(str), Boolean.class }); 109 + else if (StringUtils.equals(str, "true") || StringUtils.equalsIgnoreCase(str, "false")) {
  110 + classs.add(new Object[]{Boolean.valueOf(str), Boolean.class});
127 } 111 }
128 // long长整形,包含L 112 // long长整形,包含L
129 - else if (StringUtils.containsIgnoreCase(str, "L"))  
130 - {  
131 - classs.add(new Object[] { Long.valueOf(StringUtils.replaceIgnoreCase(str, "L", "")), Long.class }); 113 + else if (StringUtils.containsIgnoreCase(str, "L")) {
  114 + classs.add(new Object[]{Long.valueOf(StringUtils.replaceIgnoreCase(str, "L", "")), Long.class});
132 } 115 }
133 // double浮点类型,包含D 116 // double浮点类型,包含D
134 - else if (StringUtils.containsIgnoreCase(str, "D"))  
135 - {  
136 - classs.add(new Object[] { Double.valueOf(StringUtils.replaceIgnoreCase(str, "D", "")), Double.class }); 117 + else if (StringUtils.containsIgnoreCase(str, "D")) {
  118 + classs.add(new Object[]{Double.valueOf(StringUtils.replaceIgnoreCase(str, "D", "")), Double.class});
137 } 119 }
138 // 其他类型归类为整形 120 // 其他类型归类为整形
139 - else  
140 - {  
141 - classs.add(new Object[] { Integer.valueOf(str), Integer.class }); 121 + else {
  122 + classs.add(new Object[]{Integer.valueOf(str), Integer.class});
142 } 123 }
143 } 124 }
144 return classs; 125 return classs;
@@ -146,16 +127,14 @@ public class JobInvokeUtil @@ -146,16 +127,14 @@ public class JobInvokeUtil
146 127
147 /** 128 /**
148 * 获取参数类型 129 * 获取参数类型
149 - * 130 + *
150 * @param methodParams 参数相关列表 131 * @param methodParams 参数相关列表
151 * @return 参数类型列表 132 * @return 参数类型列表
152 */ 133 */
153 - public static Class<?>[] getMethodParamsType(List<Object[]> methodParams)  
154 - { 134 + public static Class<?>[] getMethodParamsType(List<Object[]> methodParams) {
155 Class<?>[] classs = new Class<?>[methodParams.size()]; 135 Class<?>[] classs = new Class<?>[methodParams.size()];
156 int index = 0; 136 int index = 0;
157 - for (Object[] os : methodParams)  
158 - { 137 + for (Object[] os : methodParams) {
159 classs[index] = (Class<?>) os[1]; 138 classs[index] = (Class<?>) os[1];
160 index++; 139 index++;
161 } 140 }
@@ -164,16 +143,14 @@ public class JobInvokeUtil @@ -164,16 +143,14 @@ public class JobInvokeUtil
164 143
165 /** 144 /**
166 * 获取参数值 145 * 获取参数值
167 - * 146 + *
168 * @param methodParams 参数相关列表 147 * @param methodParams 参数相关列表
169 * @return 参数值列表 148 * @return 参数值列表
170 */ 149 */
171 - public static Object[] getMethodParamsValue(List<Object[]> methodParams)  
172 - { 150 + public static Object[] getMethodParamsValue(List<Object[]> methodParams) {
173 Object[] classs = new Object[methodParams.size()]; 151 Object[] classs = new Object[methodParams.size()];
174 int index = 0; 152 int index = 0;
175 - for (Object[] os : methodParams)  
176 - { 153 + for (Object[] os : methodParams) {
177 classs[index] = (Object) os[0]; 154 classs[index] = (Object) os[0];
178 index++; 155 index++;
179 } 156 }
ruoyi-quartz/src/main/java/com/ruoyi/quartz/util/QuartzDisallowConcurrentExecution.java
@@ -6,16 +6,13 @@ import com.ruoyi.quartz.domain.SysJob; @@ -6,16 +6,13 @@ import com.ruoyi.quartz.domain.SysJob;
6 6
7 /** 7 /**
8 * 定时任务处理(禁止并发执行) 8 * 定时任务处理(禁止并发执行)
9 - *  
10 - * @author ruoyi  
11 * 9 *
  10 + * @author ruoyi
12 */ 11 */
13 @DisallowConcurrentExecution 12 @DisallowConcurrentExecution
14 -public class QuartzDisallowConcurrentExecution extends AbstractQuartzJob  
15 -{ 13 +public class QuartzDisallowConcurrentExecution extends AbstractQuartzJob {
16 @Override 14 @Override
17 - protected void doExecute(JobExecutionContext context, SysJob sysJob) throws Exception  
18 - { 15 + protected void doExecute(JobExecutionContext context, SysJob sysJob) throws Exception {
19 JobInvokeUtil.invokeMethod(sysJob); 16 JobInvokeUtil.invokeMethod(sysJob);
20 } 17 }
21 } 18 }
ruoyi-quartz/src/main/java/com/ruoyi/quartz/util/QuartzJobExecution.java
@@ -5,15 +5,12 @@ import com.ruoyi.quartz.domain.SysJob; @@ -5,15 +5,12 @@ import com.ruoyi.quartz.domain.SysJob;
5 5
6 /** 6 /**
7 * 定时任务处理(允许并发执行) 7 * 定时任务处理(允许并发执行)
8 - *  
9 - * @author ruoyi  
10 * 8 *
  9 + * @author ruoyi
11 */ 10 */
12 -public class QuartzJobExecution extends AbstractQuartzJob  
13 -{ 11 +public class QuartzJobExecution extends AbstractQuartzJob {
14 @Override 12 @Override
15 - protected void doExecute(JobExecutionContext context, SysJob sysJob) throws Exception  
16 - { 13 + protected void doExecute(JobExecutionContext context, SysJob sysJob) throws Exception {
17 JobInvokeUtil.invokeMethod(sysJob); 14 JobInvokeUtil.invokeMethod(sysJob);
18 } 15 }
19 } 16 }
ruoyi-quartz/src/main/java/com/ruoyi/quartz/util/ScheduleUtils.java
@@ -17,20 +17,17 @@ import com.ruoyi.quartz.domain.SysJob; @@ -17,20 +17,17 @@ import com.ruoyi.quartz.domain.SysJob;
17 17
18 /** 18 /**
19 * 定时任务工具类 19 * 定时任务工具类
20 - *  
21 - * @author ruoyi  
22 * 20 *
  21 + * @author ruoyi
23 */ 22 */
24 -public class ScheduleUtils  
25 -{ 23 +public class ScheduleUtils {
26 /** 24 /**
27 * 得到quartz任务类 25 * 得到quartz任务类
28 * 26 *
29 * @param sysJob 执行计划 27 * @param sysJob 执行计划
30 * @return 具体执行任务类 28 * @return 具体执行任务类
31 */ 29 */
32 - private static Class<? extends Job> getQuartzJobClass(SysJob sysJob)  
33 - { 30 + private static Class<? extends Job> getQuartzJobClass(SysJob sysJob) {
34 boolean isConcurrent = "0".equals(sysJob.getConcurrent()); 31 boolean isConcurrent = "0".equals(sysJob.getConcurrent());
35 return isConcurrent ? QuartzJobExecution.class : QuartzDisallowConcurrentExecution.class; 32 return isConcurrent ? QuartzJobExecution.class : QuartzDisallowConcurrentExecution.class;
36 } 33 }
@@ -38,24 +35,21 @@ public class ScheduleUtils @@ -38,24 +35,21 @@ public class ScheduleUtils
38 /** 35 /**
39 * 构建任务触发对象 36 * 构建任务触发对象
40 */ 37 */
41 - public static TriggerKey getTriggerKey(Long jobId, String jobGroup)  
42 - { 38 + public static TriggerKey getTriggerKey(Long jobId, String jobGroup) {
43 return TriggerKey.triggerKey(ScheduleConstants.TASK_CLASS_NAME + jobId, jobGroup); 39 return TriggerKey.triggerKey(ScheduleConstants.TASK_CLASS_NAME + jobId, jobGroup);
44 } 40 }
45 41
46 /** 42 /**
47 * 构建任务键对象 43 * 构建任务键对象
48 */ 44 */
49 - public static JobKey getJobKey(Long jobId, String jobGroup)  
50 - { 45 + public static JobKey getJobKey(Long jobId, String jobGroup) {
51 return JobKey.jobKey(ScheduleConstants.TASK_CLASS_NAME + jobId, jobGroup); 46 return JobKey.jobKey(ScheduleConstants.TASK_CLASS_NAME + jobId, jobGroup);
52 } 47 }
53 48
54 /** 49 /**
55 * 创建定时任务 50 * 创建定时任务
56 */ 51 */
57 - public static void createScheduleJob(Scheduler scheduler, SysJob job) throws SchedulerException, TaskException  
58 - { 52 + public static void createScheduleJob(Scheduler scheduler, SysJob job) throws SchedulerException, TaskException {
59 Class<? extends Job> jobClass = getQuartzJobClass(job); 53 Class<? extends Job> jobClass = getQuartzJobClass(job);
60 // 构建job信息 54 // 构建job信息
61 Long jobId = job.getJobId(); 55 Long jobId = job.getJobId();
@@ -74,8 +68,7 @@ public class ScheduleUtils @@ -74,8 +68,7 @@ public class ScheduleUtils
74 jobDetail.getJobDataMap().put(ScheduleConstants.TASK_PROPERTIES, job); 68 jobDetail.getJobDataMap().put(ScheduleConstants.TASK_PROPERTIES, job);
75 69
76 // 判断是否存在 70 // 判断是否存在
77 - if (scheduler.checkExists(getJobKey(jobId, jobGroup)))  
78 - { 71 + if (scheduler.checkExists(getJobKey(jobId, jobGroup))) {
79 // 防止创建时存在数据问题 先移除,然后在执行创建操作 72 // 防止创建时存在数据问题 先移除,然后在执行创建操作
80 scheduler.deleteJob(getJobKey(jobId, jobGroup)); 73 scheduler.deleteJob(getJobKey(jobId, jobGroup));
81 } 74 }
@@ -83,8 +76,7 @@ public class ScheduleUtils @@ -83,8 +76,7 @@ public class ScheduleUtils
83 scheduler.scheduleJob(jobDetail, trigger); 76 scheduler.scheduleJob(jobDetail, trigger);
84 77
85 // 暂停任务 78 // 暂停任务
86 - if (job.getStatus().equals(ScheduleConstants.Status.PAUSE.getValue()))  
87 - { 79 + if (job.getStatus().equals(ScheduleConstants.Status.PAUSE.getValue())) {
88 scheduler.pauseJob(ScheduleUtils.getJobKey(jobId, jobGroup)); 80 scheduler.pauseJob(ScheduleUtils.getJobKey(jobId, jobGroup));
89 } 81 }
90 } 82 }
@@ -93,10 +85,8 @@ public class ScheduleUtils @@ -93,10 +85,8 @@ public class ScheduleUtils
93 * 设置定时任务策略 85 * 设置定时任务策略
94 */ 86 */
95 public static CronScheduleBuilder handleCronScheduleMisfirePolicy(SysJob job, CronScheduleBuilder cb) 87 public static CronScheduleBuilder handleCronScheduleMisfirePolicy(SysJob job, CronScheduleBuilder cb)
96 - throws TaskException  
97 - {  
98 - switch (job.getMisfirePolicy())  
99 - { 88 + throws TaskException {
  89 + switch (job.getMisfirePolicy()) {
100 case ScheduleConstants.MISFIRE_DEFAULT: 90 case ScheduleConstants.MISFIRE_DEFAULT:
101 return cb; 91 return cb;
102 case ScheduleConstants.MISFIRE_IGNORE_MISFIRES: 92 case ScheduleConstants.MISFIRE_IGNORE_MISFIRES:
ruoyi-quartz/src/main/resources/mapper/quartz/SysJobLogMapper.xml deleted
1 -<?xml version="1.0" encoding="UTF-8" ?>  
2 -<!DOCTYPE mapper  
3 -PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"  
4 -"http://mybatis.org/dtd/mybatis-3-mapper.dtd">  
5 -<mapper namespace="com.ruoyi.quartz.mapper.SysJobLogMapper">  
6 -  
7 - <resultMap type="SysJobLog" id="SysJobLogResult">  
8 - <id property="jobLogId" column="job_log_id" />  
9 - <result property="jobName" column="job_name" />  
10 - <result property="jobGroup" column="job_group" />  
11 - <result property="invokeTarget" column="invoke_target" />  
12 - <result property="jobMessage" column="job_message" />  
13 - <result property="status" column="status" />  
14 - <result property="exceptionInfo" column="exception_info" />  
15 - <result property="createTime" column="create_time" />  
16 - </resultMap>  
17 -  
18 - <sql id="selectJobLogVo">  
19 - select job_log_id, job_name, job_group, invoke_target, job_message, status, exception_info, create_time  
20 - from sys_job_log  
21 - </sql>  
22 -  
23 - <select id="selectJobLogList" parameterType="SysJobLog" resultMap="SysJobLogResult">  
24 - <include refid="selectJobLogVo"/>  
25 - <where>  
26 - <if test="jobName != null and jobName != ''">  
27 - AND job_name like concat('%', #{jobName}, '%')  
28 - </if>  
29 - <if test="jobGroup != null and jobGroup != ''">  
30 - AND job_group = #{jobGroup}  
31 - </if>  
32 - <if test="status != null and status != ''">  
33 - AND status = #{status}  
34 - </if>  
35 - <if test="invokeTarget != null and invokeTarget != ''">  
36 - AND invoke_target like concat('%', #{invokeTarget}, '%')  
37 - </if>  
38 - <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->  
39 - and date_format(create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')  
40 - </if>  
41 - <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->  
42 - and date_format(create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')  
43 - </if>  
44 - </where>  
45 - </select>  
46 -  
47 - <select id="selectJobLogAll" resultMap="SysJobLogResult">  
48 - <include refid="selectJobLogVo"/>  
49 - </select>  
50 -  
51 - <select id="selectJobLogById" parameterType="Long" resultMap="SysJobLogResult">  
52 - <include refid="selectJobLogVo"/>  
53 - where job_log_id = #{jobLogId}  
54 - </select>  
55 -  
56 - <delete id="deleteJobLogById" parameterType="Long">  
57 - delete from sys_job_log where job_log_id = #{jobLogId}  
58 - </delete>  
59 -  
60 - <delete id="deleteJobLogByIds" parameterType="Long">  
61 - delete from sys_job_log where job_log_id in  
62 - <foreach collection="array" item="jobLogId" open="(" separator="," close=")">  
63 - #{jobLogId}  
64 - </foreach>  
65 - </delete>  
66 -  
67 - <update id="cleanJobLog">  
68 - truncate table sys_job_log  
69 - </update>  
70 -  
71 - <insert id="insertJobLog" parameterType="SysJobLog">  
72 - insert into sys_job_log(  
73 - <if test="jobLogId != null and jobLogId != 0">job_log_id,</if>  
74 - <if test="jobName != null and jobName != ''">job_name,</if>  
75 - <if test="jobGroup != null and jobGroup != ''">job_group,</if>  
76 - <if test="invokeTarget != null and invokeTarget != ''">invoke_target,</if>  
77 - <if test="jobMessage != null and jobMessage != ''">job_message,</if>  
78 - <if test="status != null and status != ''">status,</if>  
79 - <if test="exceptionInfo != null and exceptionInfo != ''">exception_info,</if>  
80 - create_time  
81 - )values(  
82 - <if test="jobLogId != null and jobLogId != 0">#{jobLogId},</if>  
83 - <if test="jobName != null and jobName != ''">#{jobName},</if>  
84 - <if test="jobGroup != null and jobGroup != ''">#{jobGroup},</if>  
85 - <if test="invokeTarget != null and invokeTarget != ''">#{invokeTarget},</if>  
86 - <if test="jobMessage != null and jobMessage != ''">#{jobMessage},</if>  
87 - <if test="status != null and status != ''">#{status},</if>  
88 - <if test="exceptionInfo != null and exceptionInfo != ''">#{exceptionInfo},</if>  
89 - sysdate()  
90 - )  
91 - </insert>  
92 -  
93 -</mapper>  
94 \ No newline at end of file 0 \ No newline at end of file
ruoyi-quartz/src/main/resources/mapper/quartz/SysJobMapper.xml deleted
1 -<?xml version="1.0" encoding="UTF-8" ?>  
2 -<!DOCTYPE mapper  
3 -PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"  
4 -"http://mybatis.org/dtd/mybatis-3-mapper.dtd">  
5 -<mapper namespace="com.ruoyi.quartz.mapper.SysJobMapper">  
6 -  
7 - <resultMap type="SysJob" id="SysJobResult">  
8 - <id property="jobId" column="job_id" />  
9 - <result property="jobName" column="job_name" />  
10 - <result property="jobGroup" column="job_group" />  
11 - <result property="invokeTarget" column="invoke_target" />  
12 - <result property="cronExpression" column="cron_expression" />  
13 - <result property="misfirePolicy" column="misfire_policy" />  
14 - <result property="concurrent" column="concurrent" />  
15 - <result property="status" column="status" />  
16 - <result property="createBy" column="create_by" />  
17 - <result property="createTime" column="create_time" />  
18 - <result property="updateBy" column="update_by" />  
19 - <result property="updateTime" column="update_time" />  
20 - <result property="remark" column="remark" />  
21 - </resultMap>  
22 -  
23 - <sql id="selectJobVo">  
24 - select job_id, job_name, job_group, invoke_target, cron_expression, misfire_policy, concurrent, status, create_by, create_time, remark  
25 - from sys_job  
26 - </sql>  
27 -  
28 - <select id="selectJobList" parameterType="SysJob" resultMap="SysJobResult">  
29 - <include refid="selectJobVo"/>  
30 - <where>  
31 - <if test="jobName != null and jobName != ''">  
32 - AND job_name like concat('%', #{jobName}, '%')  
33 - </if>  
34 - <if test="jobGroup != null and jobGroup != ''">  
35 - AND job_group = #{jobGroup}  
36 - </if>  
37 - <if test="status != null and status != ''">  
38 - AND status = #{status}  
39 - </if>  
40 - <if test="invokeTarget != null and invokeTarget != ''">  
41 - AND invoke_target like concat('%', #{invokeTarget}, '%')  
42 - </if>  
43 - </where>  
44 - </select>  
45 -  
46 - <select id="selectJobAll" resultMap="SysJobResult">  
47 - <include refid="selectJobVo"/>  
48 - </select>  
49 -  
50 - <select id="selectJobById" parameterType="Long" resultMap="SysJobResult">  
51 - <include refid="selectJobVo"/>  
52 - where job_id = #{jobId}  
53 - </select>  
54 -  
55 - <delete id="deleteJobById" parameterType="Long">  
56 - delete from sys_job where job_id = #{jobId}  
57 - </delete>  
58 -  
59 - <delete id="deleteJobByIds" parameterType="Long">  
60 - delete from sys_job where job_id in  
61 - <foreach collection="array" item="jobId" open="(" separator="," close=")">  
62 - #{jobId}  
63 - </foreach>  
64 - </delete>  
65 -  
66 - <update id="updateJob" parameterType="SysJob">  
67 - update sys_job  
68 - <set>  
69 - <if test="jobName != null and jobName != ''">job_name = #{jobName},</if>  
70 - <if test="jobGroup != null and jobGroup != ''">job_group = #{jobGroup},</if>  
71 - <if test="invokeTarget != null and invokeTarget != ''">invoke_target = #{invokeTarget},</if>  
72 - <if test="cronExpression != null and cronExpression != ''">cron_expression = #{cronExpression},</if>  
73 - <if test="misfirePolicy != null and misfirePolicy != ''">misfire_policy = #{misfirePolicy},</if>  
74 - <if test="concurrent != null and concurrent != ''">concurrent = #{concurrent},</if>  
75 - <if test="status !=null">status = #{status},</if>  
76 - <if test="remark != null and remark != ''">remark = #{remark},</if>  
77 - <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>  
78 - update_time = sysdate()  
79 - </set>  
80 - where job_id = #{jobId}  
81 - </update>  
82 -  
83 - <insert id="insertJob" parameterType="SysJob" useGeneratedKeys="true" keyProperty="jobId">  
84 - insert into sys_job(  
85 - <if test="jobId != null and jobId != 0">job_id,</if>  
86 - <if test="jobName != null and jobName != ''">job_name,</if>  
87 - <if test="jobGroup != null and jobGroup != ''">job_group,</if>  
88 - <if test="invokeTarget != null and invokeTarget != ''">invoke_target,</if>  
89 - <if test="cronExpression != null and cronExpression != ''">cron_expression,</if>  
90 - <if test="misfirePolicy != null and misfirePolicy != ''">misfire_policy,</if>  
91 - <if test="concurrent != null and concurrent != ''">concurrent,</if>  
92 - <if test="status != null and status != ''">status,</if>  
93 - <if test="remark != null and remark != ''">remark,</if>  
94 - <if test="createBy != null and createBy != ''">create_by,</if>  
95 - create_time  
96 - )values(  
97 - <if test="jobId != null and jobId != 0">#{jobId},</if>  
98 - <if test="jobName != null and jobName != ''">#{jobName},</if>  
99 - <if test="jobGroup != null and jobGroup != ''">#{jobGroup},</if>  
100 - <if test="invokeTarget != null and invokeTarget != ''">#{invokeTarget},</if>  
101 - <if test="cronExpression != null and cronExpression != ''">#{cronExpression},</if>  
102 - <if test="misfirePolicy != null and misfirePolicy != ''">#{misfirePolicy},</if>  
103 - <if test="concurrent != null and concurrent != ''">#{concurrent},</if>  
104 - <if test="status != null and status != ''">#{status},</if>  
105 - <if test="remark != null and remark != ''">#{remark},</if>  
106 - <if test="createBy != null and createBy != ''">#{createBy},</if>  
107 - sysdate()  
108 - )  
109 - </insert>  
110 -  
111 -</mapper>  
112 \ No newline at end of file 0 \ No newline at end of file
src/main/java/cn/iocoder/dashboard/modules/infra/controller/package-info.java deleted
1 -package cn.iocoder.dashboard.modules.infra.controller;  
src/main/java/cn/iocoder/dashboard/modules/infra/dal/dataobject/job/InfJob.java 0 → 100644
  1 +package cn.iocoder.dashboard.modules.infra.dal.dataobject.job;
  2 +
  3 +import cn.iocoder.dashboard.framework.mybatis.core.dataobject.BaseDO;
  4 +import cn.iocoder.dashboard.modules.infra.enums.job.InfJobStatusEnum;
  5 +import com.baomidou.mybatisplus.annotation.TableField;
  6 +import com.baomidou.mybatisplus.annotation.TableId;
  7 +import com.baomidou.mybatisplus.annotation.TableName;
  8 +import lombok.Data;
  9 +import lombok.EqualsAndHashCode;
  10 +import lombok.ToString;
  11 +
  12 +import java.util.Date;
  13 +
  14 +/**
  15 + * 定时任务表
  16 + *
  17 + * @author 芋道源码
  18 + */
  19 +@TableName("inf_job")
  20 +@Data
  21 +@EqualsAndHashCode(callSuper = true)
  22 +@ToString(callSuper = true)
  23 +public class InfJob extends BaseDO {
  24 +
  25 + /**
  26 + * 任务编号
  27 + */
  28 + @TableId
  29 + private Long id;
  30 + /**
  31 + * 任务名称
  32 + */
  33 + private String name;
  34 + /**
  35 + * 任务分组
  36 + */
  37 + @TableField("`group`")
  38 + private String group;
  39 + /**
  40 + * 任务状态
  41 + *
  42 + * 枚举 {@link InfJobStatusEnum}
  43 + */
  44 + private Integer status;
  45 + /**
  46 + * 处理器的名字
  47 + */
  48 + private String handlerName;
  49 + /**
  50 + * 处理器的参数
  51 + */
  52 + private String handlerParam;
  53 +
  54 + // ========== 时间相关字段 ==========
  55 +
  56 + /**
  57 + * CRON 表达式
  58 + */
  59 + private String cronExpression;
  60 + /**
  61 + * 最后一次执行的开始时间
  62 + *
  63 + * 该字段在任务执行结束后,进行记录
  64 + */
  65 + private Date executeBeginTime;
  66 + /**
  67 + * 最后一次执行的结束时间
  68 + *
  69 + * 该字段在任务执行结束后,进行记录
  70 + */
  71 + private Date executeEndTime;
  72 + /**
  73 + * 上一次触发时间,来自 Quartz SCHE_TRIGGERS 表
  74 + */
  75 + private Date firePrevTime;
  76 + /**
  77 + * 下一次触发时间,来自 Quartz SCHE_TRIGGERS 表
  78 + *
  79 + * 在触发器状态从 `ACQUIRED` 变成 `BLOCKED` 时,就会更新 PREV_FIRE_TIME、NEXT_FIRE_TIME,然后定时任务才正式开始执行
  80 + */
  81 + private Date fireNextTime;
  82 +
  83 + // ========== 监控相关字段 ==========
  84 + /**
  85 + * 监控开关
  86 + */
  87 + private Boolean monitorSwitch;
  88 + /**
  89 + * 监控超时时间,单位:毫秒
  90 + */
  91 + private Integer monitorTimeout;
  92 +
  93 + // TODO misfirePolicy
  94 + // TODO concurrent
  95 + // TODO 失败重试
  96 +
  97 +}
src/main/java/cn/iocoder/dashboard/modules/infra/dal/dataobject/job/InfJobLog.java 0 → 100644
  1 +package cn.iocoder.dashboard.modules.infra.dal.dataobject.job;
  2 +
  3 +import cn.iocoder.dashboard.common.pojo.CommonResult;
  4 +import cn.iocoder.dashboard.framework.mybatis.core.dataobject.BaseDO;
  5 +import com.baomidou.mybatisplus.annotation.TableName;
  6 +import lombok.Data;
  7 +import lombok.EqualsAndHashCode;
  8 +import lombok.ToString;
  9 +
  10 +import java.util.Date;
  11 +
  12 +/**
  13 + * 定时任务的执行日志 sys_job_log
  14 + *
  15 + * @author 芋道源码
  16 + */
  17 +@TableName("inf_job_log")
  18 +@Data
  19 +@EqualsAndHashCode(callSuper = true)
  20 +@ToString(callSuper = true)
  21 +public class InfJobLog extends BaseDO {
  22 +
  23 + /**
  24 + * 日志编号
  25 + */
  26 + private Long id;
  27 + /**
  28 + * 任务编号
  29 + *
  30 + * 关联 {@link InfJob#getId()}
  31 + */
  32 + private Long jobId;
  33 + /**
  34 + * 任务名称
  35 + *
  36 + * 冗余字段 {@link InfJob#getName()}
  37 + */
  38 + private String jobName;
  39 + /**
  40 + * 任务分组
  41 + *
  42 + * 冗余字段 {@link InfJob#getGroup()}
  43 + */
  44 + private String jobGroup;
  45 + /**
  46 + * 处理器的名字
  47 + *
  48 + * 冗余字段 {@link InfJob#getHandlerName()}
  49 + */
  50 + private String handlerName;
  51 + /**
  52 + * 处理器的参数
  53 + *
  54 + * 冗余字段 {@link InfJob#getHandlerParam()}
  55 + */
  56 + private String handlerParam;
  57 +
  58 + /**
  59 + * 开始执行时间
  60 + */
  61 + private Date startTime;
  62 + /**
  63 + * 结束执行时间
  64 + */
  65 + private Date endTime;
  66 + /**
  67 + * 执行时长,单位:毫秒
  68 + */
  69 + private Integer duration;
  70 + /**
  71 + * 结果码
  72 + *
  73 + * 目前使用的 {@link CommonResult#getCode()} 属性
  74 + */
  75 + private Integer resultCode;
  76 + /**
  77 + * 结果提示
  78 + *
  79 + * 目前使用的 {@link CommonResult#getMsg()} 属性
  80 + */
  81 + private String resultMsg;
  82 + /**
  83 + * 结果数据
  84 + *
  85 + * 如果是对象,则使用 JSON 格式化
  86 + */
  87 + private String resultData;
  88 +
  89 +}
src/main/java/cn/iocoder/dashboard/modules/infra/dal/dataobject/package-info.java deleted
1 -package cn.iocoder.dashboard.modules.infra.dal.dataobject;  
src/main/java/cn/iocoder/dashboard/modules/infra/enums/job/InfJobStatusEnum.java 0 → 100644
  1 +package cn.iocoder.dashboard.modules.infra.enums.job;
  2 +
  3 +import com.google.common.collect.Sets;
  4 +import lombok.AllArgsConstructor;
  5 +import lombok.Getter;
  6 +
  7 +import java.util.Collections;
  8 +import java.util.Set;
  9 +
  10 +import static org.quartz.impl.jdbcjobstore.Constants.*;
  11 +
  12 +/**
  13 + * 任务状态的枚举
  14 + *
  15 + * @author 芋道源码
  16 + */
  17 +@Getter
  18 +@AllArgsConstructor
  19 +public enum InfJobStatusEnum {
  20 +
  21 + /**
  22 + * 初始化中
  23 + */
  24 + INIT(0, Collections.emptySet()),
  25 + /**
  26 + * 开启运行
  27 + */
  28 + NORMAL(1, Sets.newHashSet(STATE_WAITING, STATE_ACQUIRED, STATE_BLOCKED)),
  29 + /**
  30 + * 异常运行
  31 + */
  32 + EXCEPTION(2, Sets.newHashSet(STATE_COMPLETE)),
  33 + /**
  34 + * 暂停运行
  35 + */
  36 + STOP(3, Sets.newHashSet(STATE_PAUSED, STATE_PAUSED_BLOCKED));
  37 +
  38 + /**
  39 + * 状态
  40 + */
  41 + private final Integer status;
  42 + /**
  43 + * 对应的 Quartz 触发器的状态集合
  44 + */
  45 + private final Set<String> quartzStates;
  46 +
  47 +}