Commit c807de1ff816a93a1486ba72a8cd404780095ac9
1 parent
2f66829a
初始化 quartz 模块~
Showing
29 changed files
with
440 additions
and
855 deletions
pom.xml
| ... | ... | @@ -151,6 +151,12 @@ |
| 151 | 151 | <version>1.7.0</version> |
| 152 | 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 | 161 | <dependency> |
| 156 | 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 | 2 | |
| 3 | 3 | /** |
| 4 | 4 | * 任务调度通用常量 |
| 5 | - * | |
| 5 | + * | |
| 6 | 6 | * @author ruoyi |
| 7 | 7 | */ |
| 8 | -public class ScheduleConstants | |
| 9 | -{ | |
| 8 | +public class ScheduleConstants { | |
| 10 | 9 | public static final String TASK_CLASS_NAME = "TASK_CLASS_NAME"; |
| 11 | 10 | |
| 12 | - /** 执行目标key */ | |
| 11 | + /** | |
| 12 | + * 执行目标key | |
| 13 | + */ | |
| 13 | 14 | public static final String TASK_PROPERTIES = "TASK_PROPERTIES"; |
| 14 | 15 | |
| 15 | - /** 默认 */ | |
| 16 | + /** | |
| 17 | + * 默认 | |
| 18 | + */ | |
| 16 | 19 | public static final String MISFIRE_DEFAULT = "0"; |
| 17 | 20 | |
| 18 | - /** 立即触发执行 */ | |
| 21 | + /** | |
| 22 | + * 立即触发执行 | |
| 23 | + */ | |
| 19 | 24 | public static final String MISFIRE_IGNORE_MISFIRES = "1"; |
| 20 | 25 | |
| 21 | - /** 触发一次执行 */ | |
| 26 | + /** | |
| 27 | + * 触发一次执行 | |
| 28 | + */ | |
| 22 | 29 | public static final String MISFIRE_FIRE_AND_PROCEED = "2"; |
| 23 | 30 | |
| 24 | - /** 不触发立即执行 */ | |
| 31 | + /** | |
| 32 | + * 不触发立即执行 | |
| 33 | + */ | |
| 25 | 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 | 45 | |
| 38 | 46 | private String value; |
| 39 | 47 | |
| 40 | - private Status(String value) | |
| 41 | - { | |
| 48 | + private Status(String value) { | |
| 42 | 49 | this.value = value; |
| 43 | 50 | } |
| 44 | 51 | |
| 45 | - public String getValue() | |
| 46 | - { | |
| 52 | + public String getValue() { | |
| 47 | 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 | 3 | import org.springframework.context.annotation.Bean; |
| 4 | 4 | import org.springframework.context.annotation.Configuration; |
| 5 | 5 | import org.springframework.scheduling.quartz.SchedulerFactoryBean; |
| 6 | + | |
| 6 | 7 | import javax.sql.DataSource; |
| 7 | 8 | import java.util.Properties; |
| 8 | 9 | |
| 9 | 10 | /** |
| 10 | 11 | * 定时任务配置 |
| 11 | - * | |
| 12 | + * | |
| 12 | 13 | * @author ruoyi |
| 13 | 14 | */ |
| 14 | 15 | @Configuration |
| 15 | -public class ScheduleConfig | |
| 16 | -{ | |
| 16 | +public class ScheduleConfig { | |
| 17 | 17 | @Bean |
| 18 | - public SchedulerFactoryBean schedulerFactoryBean(DataSource dataSource) | |
| 19 | - { | |
| 18 | + public SchedulerFactoryBean schedulerFactoryBean(DataSource dataSource) { | |
| 20 | 19 | SchedulerFactoryBean factory = new SchedulerFactoryBean(); |
| 21 | 20 | factory.setDataSource(dataSource); |
| 22 | 21 | ... | ... |
ruoyi-quartz/src/main/java/com/ruoyi/quartz/controller/SysJobController.java
| 1 | 1 | package com.ruoyi.quartz.controller; |
| 2 | 2 | |
| 3 | 3 | import java.util.List; |
| 4 | + | |
| 4 | 5 | import org.quartz.SchedulerException; |
| 5 | 6 | import org.springframework.beans.factory.annotation.Autowired; |
| 6 | 7 | import org.springframework.security.access.prepost.PreAuthorize; |
| ... | ... | @@ -26,13 +27,12 @@ import com.ruoyi.quartz.util.CronUtils; |
| 26 | 27 | |
| 27 | 28 | /** |
| 28 | 29 | * 调度任务信息操作处理 |
| 29 | - * | |
| 30 | + * | |
| 30 | 31 | * @author ruoyi |
| 31 | 32 | */ |
| 32 | 33 | @RestController |
| 33 | 34 | @RequestMapping("/monitor/job") |
| 34 | -public class SysJobController extends BaseController | |
| 35 | -{ | |
| 35 | +public class SysJobController extends BaseController { | |
| 36 | 36 | @Autowired |
| 37 | 37 | private ISysJobService jobService; |
| 38 | 38 | |
| ... | ... | @@ -41,8 +41,7 @@ public class SysJobController extends BaseController |
| 41 | 41 | */ |
| 42 | 42 | @PreAuthorize("@ss.hasPermi('monitor:job:list')") |
| 43 | 43 | @GetMapping("/list") |
| 44 | - public TableDataInfo list(SysJob sysJob) | |
| 45 | - { | |
| 44 | + public TableDataInfo list(SysJob sysJob) { | |
| 46 | 45 | startPage(); |
| 47 | 46 | List<SysJob> list = jobService.selectJobList(sysJob); |
| 48 | 47 | return getDataTable(list); |
| ... | ... | @@ -54,8 +53,7 @@ public class SysJobController extends BaseController |
| 54 | 53 | @PreAuthorize("@ss.hasPermi('monitor:job:export')") |
| 55 | 54 | @Log(title = "定时任务", businessType = BusinessType.EXPORT) |
| 56 | 55 | @GetMapping("/export") |
| 57 | - public AjaxResult export(SysJob sysJob) | |
| 58 | - { | |
| 56 | + public AjaxResult export(SysJob sysJob) { | |
| 59 | 57 | List<SysJob> list = jobService.selectJobList(sysJob); |
| 60 | 58 | ExcelUtil<SysJob> util = new ExcelUtil<SysJob>(SysJob.class); |
| 61 | 59 | return util.exportExcel(list, "定时任务"); |
| ... | ... | @@ -66,8 +64,7 @@ public class SysJobController extends BaseController |
| 66 | 64 | */ |
| 67 | 65 | @PreAuthorize("@ss.hasPermi('monitor:job:query')") |
| 68 | 66 | @GetMapping(value = "/{jobId}") |
| 69 | - public AjaxResult getInfo(@PathVariable("jobId") Long jobId) | |
| 70 | - { | |
| 67 | + public AjaxResult getInfo(@PathVariable("jobId") Long jobId) { | |
| 71 | 68 | return AjaxResult.success(jobService.selectJobById(jobId)); |
| 72 | 69 | } |
| 73 | 70 | |
| ... | ... | @@ -77,10 +74,8 @@ public class SysJobController extends BaseController |
| 77 | 74 | @PreAuthorize("@ss.hasPermi('monitor:job:add')") |
| 78 | 75 | @Log(title = "定时任务", businessType = BusinessType.INSERT) |
| 79 | 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 | 79 | return AjaxResult.error("cron表达式不正确"); |
| 85 | 80 | } |
| 86 | 81 | sysJob.setCreateBy(SecurityUtils.getUsername()); |
| ... | ... | @@ -93,10 +88,8 @@ public class SysJobController extends BaseController |
| 93 | 88 | @PreAuthorize("@ss.hasPermi('monitor:job:edit')") |
| 94 | 89 | @Log(title = "定时任务", businessType = BusinessType.UPDATE) |
| 95 | 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 | 93 | return AjaxResult.error("cron表达式不正确"); |
| 101 | 94 | } |
| 102 | 95 | sysJob.setUpdateBy(SecurityUtils.getUsername()); |
| ... | ... | @@ -109,8 +102,7 @@ public class SysJobController extends BaseController |
| 109 | 102 | @PreAuthorize("@ss.hasPermi('monitor:job:changeStatus')") |
| 110 | 103 | @Log(title = "定时任务", businessType = BusinessType.UPDATE) |
| 111 | 104 | @PutMapping("/changeStatus") |
| 112 | - public AjaxResult changeStatus(@RequestBody SysJob job) throws SchedulerException | |
| 113 | - { | |
| 105 | + public AjaxResult changeStatus(@RequestBody SysJob job) throws SchedulerException { | |
| 114 | 106 | SysJob newJob = jobService.selectJobById(job.getJobId()); |
| 115 | 107 | newJob.setStatus(job.getStatus()); |
| 116 | 108 | return toAjax(jobService.changeStatus(newJob)); |
| ... | ... | @@ -122,8 +114,7 @@ public class SysJobController extends BaseController |
| 122 | 114 | @PreAuthorize("@ss.hasPermi('monitor:job:changeStatus')") |
| 123 | 115 | @Log(title = "定时任务", businessType = BusinessType.UPDATE) |
| 124 | 116 | @PutMapping("/run") |
| 125 | - public AjaxResult run(@RequestBody SysJob job) throws SchedulerException | |
| 126 | - { | |
| 117 | + public AjaxResult run(@RequestBody SysJob job) throws SchedulerException { | |
| 127 | 118 | jobService.run(job); |
| 128 | 119 | return AjaxResult.success(); |
| 129 | 120 | } |
| ... | ... | @@ -134,8 +125,7 @@ public class SysJobController extends BaseController |
| 134 | 125 | @PreAuthorize("@ss.hasPermi('monitor:job:remove')") |
| 135 | 126 | @Log(title = "定时任务", businessType = BusinessType.DELETE) |
| 136 | 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 | 129 | jobService.deleteJobByIds(jobIds); |
| 140 | 130 | return AjaxResult.success(); |
| 141 | 131 | } | ... | ... |
ruoyi-quartz/src/main/java/com/ruoyi/quartz/controller/SysJobLogController.java
| 1 | 1 | package com.ruoyi.quartz.controller; |
| 2 | 2 | |
| 3 | 3 | import java.util.List; |
| 4 | + | |
| 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; |
| 5 | 6 | import org.springframework.security.access.prepost.PreAuthorize; |
| 6 | 7 | import org.springframework.web.bind.annotation.DeleteMapping; |
| ... | ... | @@ -19,13 +20,12 @@ import com.ruoyi.quartz.service.ISysJobLogService; |
| 19 | 20 | |
| 20 | 21 | /** |
| 21 | 22 | * 调度日志操作处理 |
| 22 | - * | |
| 23 | + * | |
| 23 | 24 | * @author ruoyi |
| 24 | 25 | */ |
| 25 | 26 | @RestController |
| 26 | 27 | @RequestMapping("/monitor/jobLog") |
| 27 | -public class SysJobLogController extends BaseController | |
| 28 | -{ | |
| 28 | +public class SysJobLogController extends BaseController { | |
| 29 | 29 | @Autowired |
| 30 | 30 | private ISysJobLogService jobLogService; |
| 31 | 31 | |
| ... | ... | @@ -34,8 +34,7 @@ public class SysJobLogController extends BaseController |
| 34 | 34 | */ |
| 35 | 35 | @PreAuthorize("@ss.hasPermi('monitor:job:list')") |
| 36 | 36 | @GetMapping("/list") |
| 37 | - public TableDataInfo list(SysJobLog sysJobLog) | |
| 38 | - { | |
| 37 | + public TableDataInfo list(SysJobLog sysJobLog) { | |
| 39 | 38 | startPage(); |
| 40 | 39 | List<SysJobLog> list = jobLogService.selectJobLogList(sysJobLog); |
| 41 | 40 | return getDataTable(list); |
| ... | ... | @@ -47,20 +46,18 @@ public class SysJobLogController extends BaseController |
| 47 | 46 | @PreAuthorize("@ss.hasPermi('monitor:job:export')") |
| 48 | 47 | @Log(title = "任务调度日志", businessType = BusinessType.EXPORT) |
| 49 | 48 | @GetMapping("/export") |
| 50 | - public AjaxResult export(SysJobLog sysJobLog) | |
| 51 | - { | |
| 49 | + public AjaxResult export(SysJobLog sysJobLog) { | |
| 52 | 50 | List<SysJobLog> list = jobLogService.selectJobLogList(sysJobLog); |
| 53 | 51 | ExcelUtil<SysJobLog> util = new ExcelUtil<SysJobLog>(SysJobLog.class); |
| 54 | 52 | return util.exportExcel(list, "调度日志"); |
| 55 | 53 | } |
| 56 | - | |
| 54 | + | |
| 57 | 55 | /** |
| 58 | 56 | * 根据调度编号获取详细信息 |
| 59 | 57 | */ |
| 60 | 58 | @PreAuthorize("@ss.hasPermi('monitor:job:query')") |
| 61 | 59 | @GetMapping(value = "/{configId}") |
| 62 | - public AjaxResult getInfo(@PathVariable Long jobLogId) | |
| 63 | - { | |
| 60 | + public AjaxResult getInfo(@PathVariable Long jobLogId) { | |
| 64 | 61 | return AjaxResult.success(jobLogService.selectJobLogById(jobLogId)); |
| 65 | 62 | } |
| 66 | 63 | |
| ... | ... | @@ -71,8 +68,7 @@ public class SysJobLogController extends BaseController |
| 71 | 68 | @PreAuthorize("@ss.hasPermi('monitor:job:remove')") |
| 72 | 69 | @Log(title = "定时任务调度日志", businessType = BusinessType.DELETE) |
| 73 | 70 | @DeleteMapping("/{jobLogIds}") |
| 74 | - public AjaxResult remove(@PathVariable Long[] jobLogIds) | |
| 75 | - { | |
| 71 | + public AjaxResult remove(@PathVariable Long[] jobLogIds) { | |
| 76 | 72 | return toAjax(jobLogService.deleteJobLogByIds(jobLogIds)); |
| 77 | 73 | } |
| 78 | 74 | |
| ... | ... | @@ -82,8 +78,7 @@ public class SysJobLogController extends BaseController |
| 82 | 78 | @PreAuthorize("@ss.hasPermi('monitor:job:remove')") |
| 83 | 79 | @Log(title = "调度日志", businessType = BusinessType.CLEAN) |
| 84 | 80 | @DeleteMapping("/clean") |
| 85 | - public AjaxResult clean() | |
| 86 | - { | |
| 81 | + public AjaxResult clean() { | |
| 87 | 82 | jobLogService.cleanJobLog(); |
| 88 | 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 | 1 | package com.ruoyi.quartz.service; |
| 2 | 2 | |
| 3 | 3 | import java.util.List; |
| 4 | + | |
| 4 | 5 | import com.ruoyi.quartz.domain.SysJobLog; |
| 5 | 6 | |
| 6 | 7 | /** |
| 7 | 8 | * 定时任务调度日志信息信息 服务层 |
| 8 | - * | |
| 9 | + * | |
| 9 | 10 | * @author ruoyi |
| 10 | 11 | */ |
| 11 | -public interface ISysJobLogService | |
| 12 | -{ | |
| 12 | +public interface ISysJobLogService { | |
| 13 | 13 | /** |
| 14 | 14 | * 获取quartz调度器日志的计划任务 |
| 15 | - * | |
| 15 | + * | |
| 16 | 16 | * @param jobLog 调度日志信息 |
| 17 | 17 | * @return 调度任务日志集合 |
| 18 | 18 | */ |
| ... | ... | @@ -20,7 +20,7 @@ public interface ISysJobLogService |
| 20 | 20 | |
| 21 | 21 | /** |
| 22 | 22 | * 通过调度任务日志ID查询调度信息 |
| 23 | - * | |
| 23 | + * | |
| 24 | 24 | * @param jobLogId 调度任务日志ID |
| 25 | 25 | * @return 调度任务日志对象信息 |
| 26 | 26 | */ |
| ... | ... | @@ -28,14 +28,14 @@ public interface ISysJobLogService |
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * 新增任务日志 |
| 31 | - * | |
| 31 | + * | |
| 32 | 32 | * @param jobLog 调度日志信息 |
| 33 | 33 | */ |
| 34 | 34 | public void addJobLog(SysJobLog jobLog); |
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | 37 | * 批量删除调度日志信息 |
| 38 | - * | |
| 38 | + * | |
| 39 | 39 | * @param logIds 需要删除的日志ID |
| 40 | 40 | * @return 结果 |
| 41 | 41 | */ |
| ... | ... | @@ -43,7 +43,7 @@ public interface ISysJobLogService |
| 43 | 43 | |
| 44 | 44 | /** |
| 45 | 45 | * 删除任务日志 |
| 46 | - * | |
| 46 | + * | |
| 47 | 47 | * @param jobId 调度日志ID |
| 48 | 48 | * @return 结果 |
| 49 | 49 | */ | ... | ... |
ruoyi-quartz/src/main/java/com/ruoyi/quartz/service/ISysJobService.java
| 1 | 1 | package com.ruoyi.quartz.service; |
| 2 | 2 | |
| 3 | 3 | import java.util.List; |
| 4 | + | |
| 4 | 5 | import org.quartz.SchedulerException; |
| 5 | 6 | import com.ruoyi.common.exception.job.TaskException; |
| 6 | 7 | import com.ruoyi.quartz.domain.SysJob; |
| 7 | 8 | |
| 8 | 9 | /** |
| 9 | 10 | * 定时任务调度信息信息 服务层 |
| 10 | - * | |
| 11 | + * | |
| 11 | 12 | * @author ruoyi |
| 12 | 13 | */ |
| 13 | -public interface ISysJobService | |
| 14 | -{ | |
| 14 | +public interface ISysJobService { | |
| 15 | 15 | /** |
| 16 | 16 | * 获取quartz调度器的计划任务 |
| 17 | - * | |
| 17 | + * | |
| 18 | 18 | * @param job 调度信息 |
| 19 | 19 | * @return 调度任务集合 |
| 20 | 20 | */ |
| ... | ... | @@ -22,7 +22,7 @@ public interface ISysJobService |
| 22 | 22 | |
| 23 | 23 | /** |
| 24 | 24 | * 通过调度任务ID查询调度信息 |
| 25 | - * | |
| 25 | + * | |
| 26 | 26 | * @param jobId 调度任务ID |
| 27 | 27 | * @return 调度任务对象信息 |
| 28 | 28 | */ |
| ... | ... | @@ -30,7 +30,7 @@ public interface ISysJobService |
| 30 | 30 | |
| 31 | 31 | /** |
| 32 | 32 | * 暂停任务 |
| 33 | - * | |
| 33 | + * | |
| 34 | 34 | * @param job 调度信息 |
| 35 | 35 | * @return 结果 |
| 36 | 36 | */ |
| ... | ... | @@ -38,7 +38,7 @@ public interface ISysJobService |
| 38 | 38 | |
| 39 | 39 | /** |
| 40 | 40 | * 恢复任务 |
| 41 | - * | |
| 41 | + * | |
| 42 | 42 | * @param job 调度信息 |
| 43 | 43 | * @return 结果 |
| 44 | 44 | */ |
| ... | ... | @@ -46,7 +46,7 @@ public interface ISysJobService |
| 46 | 46 | |
| 47 | 47 | /** |
| 48 | 48 | * 删除任务后,所对应的trigger也将被删除 |
| 49 | - * | |
| 49 | + * | |
| 50 | 50 | * @param job 调度信息 |
| 51 | 51 | * @return 结果 |
| 52 | 52 | */ |
| ... | ... | @@ -54,7 +54,7 @@ public interface ISysJobService |
| 54 | 54 | |
| 55 | 55 | /** |
| 56 | 56 | * 批量删除调度信息 |
| 57 | - * | |
| 57 | + * | |
| 58 | 58 | * @param jobIds 需要删除的任务ID |
| 59 | 59 | * @return 结果 |
| 60 | 60 | */ |
| ... | ... | @@ -62,7 +62,7 @@ public interface ISysJobService |
| 62 | 62 | |
| 63 | 63 | /** |
| 64 | 64 | * 任务调度状态修改 |
| 65 | - * | |
| 65 | + * | |
| 66 | 66 | * @param job 调度信息 |
| 67 | 67 | * @return 结果 |
| 68 | 68 | */ |
| ... | ... | @@ -70,7 +70,7 @@ public interface ISysJobService |
| 70 | 70 | |
| 71 | 71 | /** |
| 72 | 72 | * 立即运行任务 |
| 73 | - * | |
| 73 | + * | |
| 74 | 74 | * @param job 调度信息 |
| 75 | 75 | * @return 结果 |
| 76 | 76 | */ |
| ... | ... | @@ -78,7 +78,7 @@ public interface ISysJobService |
| 78 | 78 | |
| 79 | 79 | /** |
| 80 | 80 | * 新增任务 |
| 81 | - * | |
| 81 | + * | |
| 82 | 82 | * @param job 调度信息 |
| 83 | 83 | * @return 结果 |
| 84 | 84 | */ |
| ... | ... | @@ -86,7 +86,7 @@ public interface ISysJobService |
| 86 | 86 | |
| 87 | 87 | /** |
| 88 | 88 | * 更新任务 |
| 89 | - * | |
| 89 | + * | |
| 90 | 90 | * @param job 调度信息 |
| 91 | 91 | * @return 结果 |
| 92 | 92 | */ |
| ... | ... | @@ -94,7 +94,7 @@ public interface ISysJobService |
| 94 | 94 | |
| 95 | 95 | /** |
| 96 | 96 | * 校验cron表达式是否有效 |
| 97 | - * | |
| 97 | + * | |
| 98 | 98 | * @param cronExpression 表达式 |
| 99 | 99 | * @return 结果 |
| 100 | 100 | */ | ... | ... |
ruoyi-quartz/src/main/java/com/ruoyi/quartz/service/impl/SysJobLogServiceImpl.java
| 1 | 1 | package com.ruoyi.quartz.service.impl; |
| 2 | 2 | |
| 3 | 3 | import java.util.List; |
| 4 | + | |
| 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; |
| 5 | 6 | import org.springframework.stereotype.Service; |
| 6 | 7 | import com.ruoyi.quartz.domain.SysJobLog; |
| ... | ... | @@ -9,70 +10,64 @@ import com.ruoyi.quartz.service.ISysJobLogService; |
| 9 | 10 | |
| 10 | 11 | /** |
| 11 | 12 | * 定时任务调度日志信息 服务层 |
| 12 | - * | |
| 13 | + * | |
| 13 | 14 | * @author ruoyi |
| 14 | 15 | */ |
| 15 | 16 | @Service |
| 16 | -public class SysJobLogServiceImpl implements ISysJobLogService | |
| 17 | -{ | |
| 17 | +public class SysJobLogServiceImpl implements ISysJobLogService { | |
| 18 | 18 | @Autowired |
| 19 | 19 | private SysJobLogMapper jobLogMapper; |
| 20 | 20 | |
| 21 | 21 | /** |
| 22 | 22 | * 获取quartz调度器日志的计划任务 |
| 23 | - * | |
| 23 | + * | |
| 24 | 24 | * @param jobLog 调度日志信息 |
| 25 | 25 | * @return 调度任务日志集合 |
| 26 | 26 | */ |
| 27 | 27 | @Override |
| 28 | - public List<SysJobLog> selectJobLogList(SysJobLog jobLog) | |
| 29 | - { | |
| 28 | + public List<SysJobLog> selectJobLogList(SysJobLog jobLog) { | |
| 30 | 29 | return jobLogMapper.selectJobLogList(jobLog); |
| 31 | 30 | } |
| 32 | 31 | |
| 33 | 32 | /** |
| 34 | 33 | * 通过调度任务日志ID查询调度信息 |
| 35 | - * | |
| 34 | + * | |
| 36 | 35 | * @param jobLogId 调度任务日志ID |
| 37 | 36 | * @return 调度任务日志对象信息 |
| 38 | 37 | */ |
| 39 | 38 | @Override |
| 40 | - public SysJobLog selectJobLogById(Long jobLogId) | |
| 41 | - { | |
| 39 | + public SysJobLog selectJobLogById(Long jobLogId) { | |
| 42 | 40 | return jobLogMapper.selectJobLogById(jobLogId); |
| 43 | 41 | } |
| 44 | 42 | |
| 45 | 43 | /** |
| 46 | 44 | * 新增任务日志 |
| 47 | - * | |
| 45 | + * | |
| 48 | 46 | * @param jobLog 调度日志信息 |
| 49 | 47 | */ |
| 50 | 48 | @Override |
| 51 | - public void addJobLog(SysJobLog jobLog) | |
| 52 | - { | |
| 49 | + public void addJobLog(SysJobLog jobLog) { | |
| 53 | 50 | jobLogMapper.insertJobLog(jobLog); |
| 54 | 51 | } |
| 55 | 52 | |
| 56 | 53 | /** |
| 57 | 54 | * 批量删除调度日志信息 |
| 58 | - * | |
| 55 | + * | |
| 59 | 56 | * @param logIds 需要删除的数据ID |
| 60 | 57 | * @return 结果 |
| 61 | 58 | */ |
| 62 | 59 | @Override |
| 63 | - public int deleteJobLogByIds(Long[] logIds) | |
| 64 | - { | |
| 60 | + public int deleteJobLogByIds(Long[] logIds) { | |
| 65 | 61 | return jobLogMapper.deleteJobLogByIds(logIds); |
| 66 | 62 | } |
| 67 | 63 | |
| 68 | 64 | /** |
| 69 | 65 | * 删除任务日志 |
| 70 | - * | |
| 66 | + * | |
| 71 | 67 | * @param jobId 调度日志ID |
| 72 | 68 | */ |
| 73 | 69 | @Override |
| 74 | - public int deleteJobLogById(Long jobId) | |
| 75 | - { | |
| 70 | + public int deleteJobLogById(Long jobId) { | |
| 76 | 71 | return jobLogMapper.deleteJobLogById(jobId); |
| 77 | 72 | } |
| 78 | 73 | |
| ... | ... | @@ -80,8 +75,7 @@ public class SysJobLogServiceImpl implements ISysJobLogService |
| 80 | 75 | * 清空任务日志 |
| 81 | 76 | */ |
| 82 | 77 | @Override |
| 83 | - public void cleanJobLog() | |
| 84 | - { | |
| 78 | + public void cleanJobLog() { | |
| 85 | 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 | 2 | |
| 3 | 3 | import java.util.List; |
| 4 | 4 | import javax.annotation.PostConstruct; |
| 5 | + | |
| 5 | 6 | import org.quartz.JobDataMap; |
| 6 | 7 | import org.quartz.JobKey; |
| 7 | 8 | import org.quartz.Scheduler; |
| ... | ... | @@ -19,12 +20,11 @@ import com.ruoyi.quartz.util.ScheduleUtils; |
| 19 | 20 | |
| 20 | 21 | /** |
| 21 | 22 | * 定时任务调度信息 服务层 |
| 22 | - * | |
| 23 | + * | |
| 23 | 24 | * @author ruoyi |
| 24 | 25 | */ |
| 25 | 26 | @Service |
| 26 | -public class SysJobServiceImpl implements ISysJobService | |
| 27 | -{ | |
| 27 | +public class SysJobServiceImpl implements ISysJobService { | |
| 28 | 28 | @Autowired |
| 29 | 29 | private Scheduler scheduler; |
| 30 | 30 | |
| ... | ... | @@ -35,55 +35,49 @@ public class SysJobServiceImpl implements ISysJobService |
| 35 | 35 | * 项目启动时,初始化定时器 主要是防止手动修改数据库导致未同步到定时任务处理(注:不能手动修改数据库ID和任务组名,否则会导致脏数据) |
| 36 | 36 | */ |
| 37 | 37 | @PostConstruct |
| 38 | - public void init() throws SchedulerException, TaskException | |
| 39 | - { | |
| 38 | + public void init() throws SchedulerException, TaskException { | |
| 40 | 39 | scheduler.clear(); |
| 41 | 40 | List<SysJob> jobList = jobMapper.selectJobAll(); |
| 42 | - for (SysJob job : jobList) | |
| 43 | - { | |
| 41 | + for (SysJob job : jobList) { | |
| 44 | 42 | ScheduleUtils.createScheduleJob(scheduler, job); |
| 45 | 43 | } |
| 46 | 44 | } |
| 47 | 45 | |
| 48 | 46 | /** |
| 49 | 47 | * 获取quartz调度器的计划任务列表 |
| 50 | - * | |
| 48 | + * | |
| 51 | 49 | * @param job 调度信息 |
| 52 | 50 | * @return |
| 53 | 51 | */ |
| 54 | 52 | @Override |
| 55 | - public List<SysJob> selectJobList(SysJob job) | |
| 56 | - { | |
| 53 | + public List<SysJob> selectJobList(SysJob job) { | |
| 57 | 54 | return jobMapper.selectJobList(job); |
| 58 | 55 | } |
| 59 | 56 | |
| 60 | 57 | /** |
| 61 | 58 | * 通过调度任务ID查询调度信息 |
| 62 | - * | |
| 59 | + * | |
| 63 | 60 | * @param jobId 调度任务ID |
| 64 | 61 | * @return 调度任务对象信息 |
| 65 | 62 | */ |
| 66 | 63 | @Override |
| 67 | - public SysJob selectJobById(Long jobId) | |
| 68 | - { | |
| 64 | + public SysJob selectJobById(Long jobId) { | |
| 69 | 65 | return jobMapper.selectJobById(jobId); |
| 70 | 66 | } |
| 71 | 67 | |
| 72 | 68 | /** |
| 73 | 69 | * 暂停任务 |
| 74 | - * | |
| 70 | + * | |
| 75 | 71 | * @param job 调度信息 |
| 76 | 72 | */ |
| 77 | 73 | @Override |
| 78 | 74 | @Transactional |
| 79 | - public int pauseJob(SysJob job) throws SchedulerException | |
| 80 | - { | |
| 75 | + public int pauseJob(SysJob job) throws SchedulerException { | |
| 81 | 76 | Long jobId = job.getJobId(); |
| 82 | 77 | String jobGroup = job.getJobGroup(); |
| 83 | 78 | job.setStatus(ScheduleConstants.Status.PAUSE.getValue()); |
| 84 | 79 | int rows = jobMapper.updateJob(job); |
| 85 | - if (rows > 0) | |
| 86 | - { | |
| 80 | + if (rows > 0) { | |
| 87 | 81 | scheduler.pauseJob(ScheduleUtils.getJobKey(jobId, jobGroup)); |
| 88 | 82 | } |
| 89 | 83 | return rows; |
| ... | ... | @@ -91,19 +85,17 @@ public class SysJobServiceImpl implements ISysJobService |
| 91 | 85 | |
| 92 | 86 | /** |
| 93 | 87 | * 恢复任务 |
| 94 | - * | |
| 88 | + * | |
| 95 | 89 | * @param job 调度信息 |
| 96 | 90 | */ |
| 97 | 91 | @Override |
| 98 | 92 | @Transactional |
| 99 | - public int resumeJob(SysJob job) throws SchedulerException | |
| 100 | - { | |
| 93 | + public int resumeJob(SysJob job) throws SchedulerException { | |
| 101 | 94 | Long jobId = job.getJobId(); |
| 102 | 95 | String jobGroup = job.getJobGroup(); |
| 103 | 96 | job.setStatus(ScheduleConstants.Status.NORMAL.getValue()); |
| 104 | 97 | int rows = jobMapper.updateJob(job); |
| 105 | - if (rows > 0) | |
| 106 | - { | |
| 98 | + if (rows > 0) { | |
| 107 | 99 | scheduler.resumeJob(ScheduleUtils.getJobKey(jobId, jobGroup)); |
| 108 | 100 | } |
| 109 | 101 | return rows; |
| ... | ... | @@ -111,18 +103,16 @@ public class SysJobServiceImpl implements ISysJobService |
| 111 | 103 | |
| 112 | 104 | /** |
| 113 | 105 | * 删除任务后,所对应的trigger也将被删除 |
| 114 | - * | |
| 106 | + * | |
| 115 | 107 | * @param job 调度信息 |
| 116 | 108 | */ |
| 117 | 109 | @Override |
| 118 | 110 | @Transactional |
| 119 | - public int deleteJob(SysJob job) throws SchedulerException | |
| 120 | - { | |
| 111 | + public int deleteJob(SysJob job) throws SchedulerException { | |
| 121 | 112 | Long jobId = job.getJobId(); |
| 122 | 113 | String jobGroup = job.getJobGroup(); |
| 123 | 114 | int rows = jobMapper.deleteJobById(jobId); |
| 124 | - if (rows > 0) | |
| 125 | - { | |
| 115 | + if (rows > 0) { | |
| 126 | 116 | scheduler.deleteJob(ScheduleUtils.getJobKey(jobId, jobGroup)); |
| 127 | 117 | } |
| 128 | 118 | return rows; |
| ... | ... | @@ -130,16 +120,14 @@ public class SysJobServiceImpl implements ISysJobService |
| 130 | 120 | |
| 131 | 121 | /** |
| 132 | 122 | * 批量删除调度信息 |
| 133 | - * | |
| 123 | + * | |
| 134 | 124 | * @param jobIds 需要删除的任务ID |
| 135 | 125 | * @return 结果 |
| 136 | 126 | */ |
| 137 | 127 | @Override |
| 138 | 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 | 131 | SysJob job = jobMapper.selectJobById(jobId); |
| 144 | 132 | deleteJob(job); |
| 145 | 133 | } |
| ... | ... | @@ -147,21 +135,17 @@ public class SysJobServiceImpl implements ISysJobService |
| 147 | 135 | |
| 148 | 136 | /** |
| 149 | 137 | * 任务调度状态修改 |
| 150 | - * | |
| 138 | + * | |
| 151 | 139 | * @param job 调度信息 |
| 152 | 140 | */ |
| 153 | 141 | @Override |
| 154 | 142 | @Transactional |
| 155 | - public int changeStatus(SysJob job) throws SchedulerException | |
| 156 | - { | |
| 143 | + public int changeStatus(SysJob job) throws SchedulerException { | |
| 157 | 144 | int rows = 0; |
| 158 | 145 | String status = job.getStatus(); |
| 159 | - if (ScheduleConstants.Status.NORMAL.getValue().equals(status)) | |
| 160 | - { | |
| 146 | + if (ScheduleConstants.Status.NORMAL.getValue().equals(status)) { | |
| 161 | 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 | 149 | rows = pauseJob(job); |
| 166 | 150 | } |
| 167 | 151 | return rows; |
| ... | ... | @@ -169,13 +153,12 @@ public class SysJobServiceImpl implements ISysJobService |
| 169 | 153 | |
| 170 | 154 | /** |
| 171 | 155 | * 立即运行任务 |
| 172 | - * | |
| 156 | + * | |
| 173 | 157 | * @param job 调度信息 |
| 174 | 158 | */ |
| 175 | 159 | @Override |
| 176 | 160 | @Transactional |
| 177 | - public void run(SysJob job) throws SchedulerException | |
| 178 | - { | |
| 161 | + public void run(SysJob job) throws SchedulerException { | |
| 179 | 162 | Long jobId = job.getJobId(); |
| 180 | 163 | String jobGroup = job.getJobGroup(); |
| 181 | 164 | SysJob properties = selectJobById(job.getJobId()); |
| ... | ... | @@ -187,17 +170,15 @@ public class SysJobServiceImpl implements ISysJobService |
| 187 | 170 | |
| 188 | 171 | /** |
| 189 | 172 | * 新增任务 |
| 190 | - * | |
| 173 | + * | |
| 191 | 174 | * @param job 调度信息 调度信息 |
| 192 | 175 | */ |
| 193 | 176 | @Override |
| 194 | 177 | @Transactional |
| 195 | - public int insertJob(SysJob job) throws SchedulerException, TaskException | |
| 196 | - { | |
| 178 | + public int insertJob(SysJob job) throws SchedulerException, TaskException { | |
| 197 | 179 | job.setStatus(ScheduleConstants.Status.PAUSE.getValue()); |
| 198 | 180 | int rows = jobMapper.insertJob(job); |
| 199 | - if (rows > 0) | |
| 200 | - { | |
| 181 | + if (rows > 0) { | |
| 201 | 182 | ScheduleUtils.createScheduleJob(scheduler, job); |
| 202 | 183 | } |
| 203 | 184 | return rows; |
| ... | ... | @@ -205,17 +186,15 @@ public class SysJobServiceImpl implements ISysJobService |
| 205 | 186 | |
| 206 | 187 | /** |
| 207 | 188 | * 更新任务的时间表达式 |
| 208 | - * | |
| 189 | + * | |
| 209 | 190 | * @param job 调度信息 |
| 210 | 191 | */ |
| 211 | 192 | @Override |
| 212 | 193 | @Transactional |
| 213 | - public int updateJob(SysJob job) throws SchedulerException, TaskException | |
| 214 | - { | |
| 194 | + public int updateJob(SysJob job) throws SchedulerException, TaskException { | |
| 215 | 195 | SysJob properties = selectJobById(job.getJobId()); |
| 216 | 196 | int rows = jobMapper.updateJob(job); |
| 217 | - if (rows > 0) | |
| 218 | - { | |
| 197 | + if (rows > 0) { | |
| 219 | 198 | updateSchedulerJob(job, properties.getJobGroup()); |
| 220 | 199 | } |
| 221 | 200 | return rows; |
| ... | ... | @@ -223,17 +202,15 @@ public class SysJobServiceImpl implements ISysJobService |
| 223 | 202 | |
| 224 | 203 | /** |
| 225 | 204 | * 更新任务 |
| 226 | - * | |
| 227 | - * @param job 任务对象 | |
| 205 | + * | |
| 206 | + * @param job 任务对象 | |
| 228 | 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 | 210 | Long jobId = job.getJobId(); |
| 233 | 211 | // 判断是否存在 |
| 234 | 212 | JobKey jobKey = ScheduleUtils.getJobKey(jobId, jobGroup); |
| 235 | - if (scheduler.checkExists(jobKey)) | |
| 236 | - { | |
| 213 | + if (scheduler.checkExists(jobKey)) { | |
| 237 | 214 | // 防止创建时存在数据问题 先移除,然后在执行创建操作 |
| 238 | 215 | scheduler.deleteJob(jobKey); |
| 239 | 216 | } |
| ... | ... | @@ -242,13 +219,12 @@ public class SysJobServiceImpl implements ISysJobService |
| 242 | 219 | |
| 243 | 220 | /** |
| 244 | 221 | * 校验cron表达式是否有效 |
| 245 | - * | |
| 222 | + * | |
| 246 | 223 | * @param cronExpression 表达式 |
| 247 | 224 | * @return 结果 |
| 248 | 225 | */ |
| 249 | 226 | @Override |
| 250 | - public boolean checkCronExpressionIsValid(String cronExpression) | |
| 251 | - { | |
| 227 | + public boolean checkCronExpressionIsValid(String cronExpression) { | |
| 252 | 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 | 5 | |
| 6 | 6 | /** |
| 7 | 7 | * 定时任务调度测试 |
| 8 | - * | |
| 8 | + * | |
| 9 | 9 | * @author ruoyi |
| 10 | 10 | */ |
| 11 | 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 | 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 | 18 | System.out.println("执行有参方法:" + params); |
| 22 | 19 | } |
| 23 | 20 | |
| 24 | - public void ryNoParams() | |
| 25 | - { | |
| 21 | + public void ryNoParams() { | |
| 26 | 22 | System.out.println("执行无参方法"); |
| 27 | 23 | } |
| 28 | 24 | } | ... | ... |
ruoyi-quartz/src/main/java/com/ruoyi/quartz/util/AbstractQuartzJob.java
| 1 | 1 | package com.ruoyi.quartz.util; |
| 2 | 2 | |
| 3 | 3 | import java.util.Date; |
| 4 | + | |
| 4 | 5 | import org.quartz.Job; |
| 5 | 6 | import org.quartz.JobExecutionContext; |
| 6 | 7 | import org.quartz.JobExecutionException; |
| ... | ... | @@ -21,8 +22,7 @@ import com.ruoyi.quartz.service.ISysJobLogService; |
| 21 | 22 | * |
| 22 | 23 | * @author ruoyi |
| 23 | 24 | */ |
| 24 | -public abstract class AbstractQuartzJob implements Job | |
| 25 | -{ | |
| 25 | +public abstract class AbstractQuartzJob implements Job { | |
| 26 | 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 | 31 | private static ThreadLocal<Date> threadLocal = new ThreadLocal<>(); |
| 32 | 32 | |
| 33 | 33 | @Override |
| 34 | - public void execute(JobExecutionContext context) throws JobExecutionException | |
| 35 | - { | |
| 34 | + public void execute(JobExecutionContext context) throws JobExecutionException { | |
| 36 | 35 | SysJob sysJob = new SysJob(); |
| 37 | 36 | BeanUtils.copyBeanProp(sysJob, context.getMergedJobDataMap().get(ScheduleConstants.TASK_PROPERTIES)); |
| 38 | - try | |
| 39 | - { | |
| 37 | + try { | |
| 40 | 38 | before(context, sysJob); |
| 41 | - if (sysJob != null) | |
| 42 | - { | |
| 39 | + if (sysJob != null) { | |
| 43 | 40 | doExecute(context, sysJob); |
| 44 | 41 | } |
| 45 | 42 | after(context, sysJob, null); |
| 46 | - } | |
| 47 | - catch (Exception e) | |
| 48 | - { | |
| 43 | + } catch (Exception e) { | |
| 49 | 44 | log.error("任务执行异常 - :", e); |
| 50 | 45 | after(context, sysJob, e); |
| 51 | 46 | } |
| ... | ... | @@ -55,10 +50,9 @@ public abstract class AbstractQuartzJob implements Job |
| 55 | 50 | * 执行前 |
| 56 | 51 | * |
| 57 | 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 | 56 | threadLocal.set(new Date()); |
| 63 | 57 | } |
| 64 | 58 | |
| ... | ... | @@ -66,10 +60,9 @@ public abstract class AbstractQuartzJob implements Job |
| 66 | 60 | * 执行后 |
| 67 | 61 | * |
| 68 | 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 | 66 | Date startTime = threadLocal.get(); |
| 74 | 67 | threadLocal.remove(); |
| 75 | 68 | |
| ... | ... | @@ -81,14 +74,11 @@ public abstract class AbstractQuartzJob implements Job |
| 81 | 74 | sysJobLog.setStopTime(new Date()); |
| 82 | 75 | long runMs = sysJobLog.getStopTime().getTime() - sysJobLog.getStartTime().getTime(); |
| 83 | 76 | sysJobLog.setJobMessage(sysJobLog.getJobName() + " 总共耗时:" + runMs + "毫秒"); |
| 84 | - if (e != null) | |
| 85 | - { | |
| 77 | + if (e != null) { | |
| 86 | 78 | sysJobLog.setStatus(Constants.FAIL); |
| 87 | 79 | String errorMsg = StringUtils.substring(ExceptionUtil.getExceptionMessage(e), 0, 2000); |
| 88 | 80 | sysJobLog.setExceptionInfo(errorMsg); |
| 89 | - } | |
| 90 | - else | |
| 91 | - { | |
| 81 | + } else { | |
| 92 | 82 | sysJobLog.setStatus(Constants.SUCCESS); |
| 93 | 83 | } |
| 94 | 84 | |
| ... | ... | @@ -100,7 +90,7 @@ public abstract class AbstractQuartzJob implements Job |
| 100 | 90 | * 执行方法,由子类重载 |
| 101 | 91 | * |
| 102 | 92 | * @param context 工作执行上下文对象 |
| 103 | - * @param sysJob 系统计划任务 | |
| 93 | + * @param sysJob 系统计划任务 | |
| 104 | 94 | * @throws Exception 执行过程中的异常 |
| 105 | 95 | */ |
| 106 | 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 | 2 | |
| 3 | 3 | import java.text.ParseException; |
| 4 | 4 | import java.util.Date; |
| 5 | + | |
| 5 | 6 | import org.quartz.CronExpression; |
| 6 | 7 | |
| 7 | 8 | /** |
| 8 | 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 | 15 | * 返回一个布尔值代表一个给定的Cron表达式的有效性 |
| 17 | 16 | * |
| 18 | 17 | * @param cronExpression Cron表达式 |
| 19 | 18 | * @return boolean 表达式是否有效 |
| 20 | 19 | */ |
| 21 | - public static boolean isValid(String cronExpression) | |
| 22 | - { | |
| 20 | + public static boolean isValid(String cronExpression) { | |
| 23 | 21 | return CronExpression.isValidExpression(cronExpression); |
| 24 | 22 | } |
| 25 | 23 | |
| ... | ... | @@ -29,15 +27,11 @@ public class CronUtils |
| 29 | 27 | * @param cronExpression Cron表达式 |
| 30 | 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 | 32 | new CronExpression(cronExpression); |
| 37 | 33 | return null; |
| 38 | - } | |
| 39 | - catch (ParseException pe) | |
| 40 | - { | |
| 34 | + } catch (ParseException pe) { | |
| 41 | 35 | return pe.getMessage(); |
| 42 | 36 | } |
| 43 | 37 | } |
| ... | ... | @@ -48,15 +42,11 @@ public class CronUtils |
| 48 | 42 | * @param cronExpression Cron表达式 |
| 49 | 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 | 47 | CronExpression cron = new CronExpression(cronExpression); |
| 56 | 48 | return cron.getNextValidTimeAfter(new Date(System.currentTimeMillis())); |
| 57 | - } | |
| 58 | - catch (ParseException e) | |
| 59 | - { | |
| 49 | + } catch (ParseException e) { | |
| 60 | 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 | 4 | import java.lang.reflect.Method; |
| 5 | 5 | import java.util.LinkedList; |
| 6 | 6 | import java.util.List; |
| 7 | + | |
| 7 | 8 | import com.ruoyi.common.utils.StringUtils; |
| 8 | 9 | import com.ruoyi.common.utils.spring.SpringUtils; |
| 9 | 10 | import com.ruoyi.quartz.domain.SysJob; |
| ... | ... | @@ -13,27 +14,22 @@ import com.ruoyi.quartz.domain.SysJob; |
| 13 | 14 | * |
| 14 | 15 | * @author ruoyi |
| 15 | 16 | */ |
| 16 | -public class JobInvokeUtil | |
| 17 | -{ | |
| 17 | +public class JobInvokeUtil { | |
| 18 | 18 | /** |
| 19 | 19 | * 执行方法 |
| 20 | 20 | * |
| 21 | 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 | 24 | String invokeTarget = sysJob.getInvokeTarget(); |
| 26 | 25 | String beanName = getBeanName(invokeTarget); |
| 27 | 26 | String methodName = getMethodName(invokeTarget); |
| 28 | 27 | List<Object[]> methodParams = getMethodParams(invokeTarget); |
| 29 | 28 | |
| 30 | - if (!isValidClassName(beanName)) | |
| 31 | - { | |
| 29 | + if (!isValidClassName(beanName)) { | |
| 32 | 30 | Object bean = SpringUtils.getBean(beanName); |
| 33 | 31 | invokeMethod(bean, methodName, methodParams); |
| 34 | - } | |
| 35 | - else | |
| 36 | - { | |
| 32 | + } else { | |
| 37 | 33 | Object bean = Class.forName(beanName).newInstance(); |
| 38 | 34 | invokeMethod(bean, methodName, methodParams); |
| 39 | 35 | } |
| ... | ... | @@ -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 | 43 | * @param methodParams 方法参数 |
| 48 | 44 | */ |
| 49 | 45 | private static void invokeMethod(Object bean, String methodName, List<Object[]> methodParams) |
| 50 | 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 | 49 | Method method = bean.getClass().getDeclaredMethod(methodName, getMethodParamsType(methodParams)); |
| 56 | 50 | method.invoke(bean, getMethodParamsValue(methodParams)); |
| 57 | - } | |
| 58 | - else | |
| 59 | - { | |
| 51 | + } else { | |
| 60 | 52 | Method method = bean.getClass().getDeclaredMethod(methodName); |
| 61 | 53 | method.invoke(bean); |
| 62 | 54 | } |
| ... | ... | @@ -64,81 +56,70 @@ public class JobInvokeUtil |
| 64 | 56 | |
| 65 | 57 | /** |
| 66 | 58 | * 校验是否为为class包名 |
| 67 | - * | |
| 59 | + * | |
| 68 | 60 | * @param str 名称 |
| 69 | 61 | * @return true是 false否 |
| 70 | 62 | */ |
| 71 | - public static boolean isValidClassName(String invokeTarget) | |
| 72 | - { | |
| 63 | + public static boolean isValidClassName(String invokeTarget) { | |
| 73 | 64 | return StringUtils.countMatches(invokeTarget, ".") > 1; |
| 74 | 65 | } |
| 75 | 66 | |
| 76 | 67 | /** |
| 77 | 68 | * 获取bean名称 |
| 78 | - * | |
| 69 | + * | |
| 79 | 70 | * @param invokeTarget 目标字符串 |
| 80 | 71 | * @return bean名称 |
| 81 | 72 | */ |
| 82 | - public static String getBeanName(String invokeTarget) | |
| 83 | - { | |
| 73 | + public static String getBeanName(String invokeTarget) { | |
| 84 | 74 | String beanName = StringUtils.substringBefore(invokeTarget, "("); |
| 85 | 75 | return StringUtils.substringBeforeLast(beanName, "."); |
| 86 | 76 | } |
| 87 | 77 | |
| 88 | 78 | /** |
| 89 | 79 | * 获取bean方法 |
| 90 | - * | |
| 80 | + * | |
| 91 | 81 | * @param invokeTarget 目标字符串 |
| 92 | 82 | * @return method方法 |
| 93 | 83 | */ |
| 94 | - public static String getMethodName(String invokeTarget) | |
| 95 | - { | |
| 84 | + public static String getMethodName(String invokeTarget) { | |
| 96 | 85 | String methodName = StringUtils.substringBefore(invokeTarget, "("); |
| 97 | 86 | return StringUtils.substringAfterLast(methodName, "."); |
| 98 | 87 | } |
| 99 | 88 | |
| 100 | 89 | /** |
| 101 | 90 | * 获取method方法参数相关列表 |
| 102 | - * | |
| 91 | + * | |
| 103 | 92 | * @param invokeTarget 目标字符串 |
| 104 | 93 | * @return method方法相关参数列表 |
| 105 | 94 | */ |
| 106 | - public static List<Object[]> getMethodParams(String invokeTarget) | |
| 107 | - { | |
| 95 | + public static List<Object[]> getMethodParams(String invokeTarget) { | |
| 108 | 96 | String methodStr = StringUtils.substringBetween(invokeTarget, "(", ")"); |
| 109 | - if (StringUtils.isEmpty(methodStr)) | |
| 110 | - { | |
| 97 | + if (StringUtils.isEmpty(methodStr)) { | |
| 111 | 98 | return null; |
| 112 | 99 | } |
| 113 | 100 | String[] methodParams = methodStr.split(","); |
| 114 | 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 | 103 | String str = StringUtils.trimToEmpty(methodParams[i]); |
| 118 | 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 | 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 | 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 | 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 | 125 | return classs; |
| ... | ... | @@ -146,16 +127,14 @@ public class JobInvokeUtil |
| 146 | 127 | |
| 147 | 128 | /** |
| 148 | 129 | * 获取参数类型 |
| 149 | - * | |
| 130 | + * | |
| 150 | 131 | * @param methodParams 参数相关列表 |
| 151 | 132 | * @return 参数类型列表 |
| 152 | 133 | */ |
| 153 | - public static Class<?>[] getMethodParamsType(List<Object[]> methodParams) | |
| 154 | - { | |
| 134 | + public static Class<?>[] getMethodParamsType(List<Object[]> methodParams) { | |
| 155 | 135 | Class<?>[] classs = new Class<?>[methodParams.size()]; |
| 156 | 136 | int index = 0; |
| 157 | - for (Object[] os : methodParams) | |
| 158 | - { | |
| 137 | + for (Object[] os : methodParams) { | |
| 159 | 138 | classs[index] = (Class<?>) os[1]; |
| 160 | 139 | index++; |
| 161 | 140 | } |
| ... | ... | @@ -164,16 +143,14 @@ public class JobInvokeUtil |
| 164 | 143 | |
| 165 | 144 | /** |
| 166 | 145 | * 获取参数值 |
| 167 | - * | |
| 146 | + * | |
| 168 | 147 | * @param methodParams 参数相关列表 |
| 169 | 148 | * @return 参数值列表 |
| 170 | 149 | */ |
| 171 | - public static Object[] getMethodParamsValue(List<Object[]> methodParams) | |
| 172 | - { | |
| 150 | + public static Object[] getMethodParamsValue(List<Object[]> methodParams) { | |
| 173 | 151 | Object[] classs = new Object[methodParams.size()]; |
| 174 | 152 | int index = 0; |
| 175 | - for (Object[] os : methodParams) | |
| 176 | - { | |
| 153 | + for (Object[] os : methodParams) { | |
| 177 | 154 | classs[index] = (Object) os[0]; |
| 178 | 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 | 6 | |
| 7 | 7 | /** |
| 8 | 8 | * 定时任务处理(禁止并发执行) |
| 9 | - * | |
| 10 | - * @author ruoyi | |
| 11 | 9 | * |
| 10 | + * @author ruoyi | |
| 12 | 11 | */ |
| 13 | 12 | @DisallowConcurrentExecution |
| 14 | -public class QuartzDisallowConcurrentExecution extends AbstractQuartzJob | |
| 15 | -{ | |
| 13 | +public class QuartzDisallowConcurrentExecution extends AbstractQuartzJob { | |
| 16 | 14 | @Override |
| 17 | - protected void doExecute(JobExecutionContext context, SysJob sysJob) throws Exception | |
| 18 | - { | |
| 15 | + protected void doExecute(JobExecutionContext context, SysJob sysJob) throws Exception { | |
| 19 | 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 | 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 | 12 | @Override |
| 15 | - protected void doExecute(JobExecutionContext context, SysJob sysJob) throws Exception | |
| 16 | - { | |
| 13 | + protected void doExecute(JobExecutionContext context, SysJob sysJob) throws Exception { | |
| 17 | 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 | 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 | 25 | * 得到quartz任务类 |
| 28 | 26 | * |
| 29 | 27 | * @param sysJob 执行计划 |
| 30 | 28 | * @return 具体执行任务类 |
| 31 | 29 | */ |
| 32 | - private static Class<? extends Job> getQuartzJobClass(SysJob sysJob) | |
| 33 | - { | |
| 30 | + private static Class<? extends Job> getQuartzJobClass(SysJob sysJob) { | |
| 34 | 31 | boolean isConcurrent = "0".equals(sysJob.getConcurrent()); |
| 35 | 32 | return isConcurrent ? QuartzJobExecution.class : QuartzDisallowConcurrentExecution.class; |
| 36 | 33 | } |
| ... | ... | @@ -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 | 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 | 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 | 53 | Class<? extends Job> jobClass = getQuartzJobClass(job); |
| 60 | 54 | // 构建job信息 |
| 61 | 55 | Long jobId = job.getJobId(); |
| ... | ... | @@ -74,8 +68,7 @@ public class ScheduleUtils |
| 74 | 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 | 73 | scheduler.deleteJob(getJobKey(jobId, jobGroup)); |
| 81 | 74 | } |
| ... | ... | @@ -83,8 +76,7 @@ public class ScheduleUtils |
| 83 | 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 | 80 | scheduler.pauseJob(ScheduleUtils.getJobKey(jobId, jobGroup)); |
| 89 | 81 | } |
| 90 | 82 | } |
| ... | ... | @@ -93,10 +85,8 @@ public class ScheduleUtils |
| 93 | 85 | * 设置定时任务策略 |
| 94 | 86 | */ |
| 95 | 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 | 90 | case ScheduleConstants.MISFIRE_DEFAULT: |
| 101 | 91 | return cb; |
| 102 | 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') >= 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') <= 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 | 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 | 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 | +} | ... | ... |