diff --git a/pom.xml b/pom.xml
index d93101c89..e68c5bfe5 100644
--- a/pom.xml
+++ b/pom.xml
@@ -151,6 +151,12 @@
1.7.0
+
+
+ org.springframework.boot
+ spring-boot-starter-quartz
+
+
org.apache.skywalking
diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/constant/GenConstants.java b/ruoyi-common/src/main/java/com/ruoyi/common/constant/GenConstants.java
deleted file mode 100644
index 54c82967c..000000000
--- a/ruoyi-common/src/main/java/com/ruoyi/common/constant/GenConstants.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package com.ruoyi.common.constant;
-
-/**
- * 代码生成通用常量
- *
- * @author ruoyi
- */
-public class GenConstants {
-
- /**
- * 树编码字段
- */
- public static final String TREE_CODE = "treeCode";
-
- /**
- * 树父编码字段
- */
- public static final String TREE_PARENT_CODE = "treeParentCode";
-
- /**
- * 树名称字段
- */
- public static final String TREE_NAME = "treeName";
-
- /**
- * 上级菜单ID字段
- */
- public static final String PARENT_MENU_ID = "parentMenuId";
-
- /**
- * 上级菜单名称字段
- */
- public static final String PARENT_MENU_NAME = "parentMenuName";
-
- /**
- * Tree基类字段
- */
- public static final String[] TREE_ENTITY = {"parentName", "parentId", "orderNum", "ancestors", "children"};
-
-}
diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/constant/ScheduleConstants.java b/ruoyi-common/src/main/java/com/ruoyi/common/constant/ScheduleConstants.java
index 8318b8f5f..cb984558c 100644
--- a/ruoyi-common/src/main/java/com/ruoyi/common/constant/ScheduleConstants.java
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/constant/ScheduleConstants.java
@@ -2,30 +2,38 @@ package com.ruoyi.common.constant;
/**
* 任务调度通用常量
- *
+ *
* @author ruoyi
*/
-public class ScheduleConstants
-{
+public class ScheduleConstants {
public static final String TASK_CLASS_NAME = "TASK_CLASS_NAME";
- /** 执行目标key */
+ /**
+ * 执行目标key
+ */
public static final String TASK_PROPERTIES = "TASK_PROPERTIES";
- /** 默认 */
+ /**
+ * 默认
+ */
public static final String MISFIRE_DEFAULT = "0";
- /** 立即触发执行 */
+ /**
+ * 立即触发执行
+ */
public static final String MISFIRE_IGNORE_MISFIRES = "1";
- /** 触发一次执行 */
+ /**
+ * 触发一次执行
+ */
public static final String MISFIRE_FIRE_AND_PROCEED = "2";
- /** 不触发立即执行 */
+ /**
+ * 不触发立即执行
+ */
public static final String MISFIRE_DO_NOTHING = "3";
- public enum Status
- {
+ public enum Status {
/**
* 正常
*/
@@ -37,13 +45,11 @@ public class ScheduleConstants
private String value;
- private Status(String value)
- {
+ private Status(String value) {
this.value = value;
}
- public String getValue()
- {
+ public String getValue() {
return value;
}
}
diff --git a/ruoyi-quartz/pom.xml b/ruoyi-quartz/pom.xml
deleted file mode 100644
index b91b68cff..000000000
--- a/ruoyi-quartz/pom.xml
+++ /dev/null
@@ -1,33 +0,0 @@
-
-
-
- ruoyi
- com.ruoyi
- 3.3.0
-
- 4.0.0
-
- ruoyi-quartz
-
-
- quartz定时任务
-
-
-
-
-
-
- org.quartz-scheduler
- quartz
-
-
- com.mchange
- c3p0
-
-
-
-
-
-
diff --git a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/config/ScheduleConfig.java b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/config/ScheduleConfig.java
index e466ed057..e3c08fb88 100644
--- a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/config/ScheduleConfig.java
+++ b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/config/ScheduleConfig.java
@@ -3,20 +3,19 @@ package com.ruoyi.quartz.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
+
import javax.sql.DataSource;
import java.util.Properties;
/**
* 定时任务配置
- *
+ *
* @author ruoyi
*/
@Configuration
-public class ScheduleConfig
-{
+public class ScheduleConfig {
@Bean
- public SchedulerFactoryBean schedulerFactoryBean(DataSource dataSource)
- {
+ public SchedulerFactoryBean schedulerFactoryBean(DataSource dataSource) {
SchedulerFactoryBean factory = new SchedulerFactoryBean();
factory.setDataSource(dataSource);
diff --git a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/controller/SysJobController.java b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/controller/SysJobController.java
index f770a7d8f..289e8b283 100644
--- a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/controller/SysJobController.java
+++ b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/controller/SysJobController.java
@@ -1,6 +1,7 @@
package com.ruoyi.quartz.controller;
import java.util.List;
+
import org.quartz.SchedulerException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
@@ -26,13 +27,12 @@ import com.ruoyi.quartz.util.CronUtils;
/**
* 调度任务信息操作处理
- *
+ *
* @author ruoyi
*/
@RestController
@RequestMapping("/monitor/job")
-public class SysJobController extends BaseController
-{
+public class SysJobController extends BaseController {
@Autowired
private ISysJobService jobService;
@@ -41,8 +41,7 @@ public class SysJobController extends BaseController
*/
@PreAuthorize("@ss.hasPermi('monitor:job:list')")
@GetMapping("/list")
- public TableDataInfo list(SysJob sysJob)
- {
+ public TableDataInfo list(SysJob sysJob) {
startPage();
List list = jobService.selectJobList(sysJob);
return getDataTable(list);
@@ -54,8 +53,7 @@ public class SysJobController extends BaseController
@PreAuthorize("@ss.hasPermi('monitor:job:export')")
@Log(title = "定时任务", businessType = BusinessType.EXPORT)
@GetMapping("/export")
- public AjaxResult export(SysJob sysJob)
- {
+ public AjaxResult export(SysJob sysJob) {
List list = jobService.selectJobList(sysJob);
ExcelUtil util = new ExcelUtil(SysJob.class);
return util.exportExcel(list, "定时任务");
@@ -66,8 +64,7 @@ public class SysJobController extends BaseController
*/
@PreAuthorize("@ss.hasPermi('monitor:job:query')")
@GetMapping(value = "/{jobId}")
- public AjaxResult getInfo(@PathVariable("jobId") Long jobId)
- {
+ public AjaxResult getInfo(@PathVariable("jobId") Long jobId) {
return AjaxResult.success(jobService.selectJobById(jobId));
}
@@ -77,10 +74,8 @@ public class SysJobController extends BaseController
@PreAuthorize("@ss.hasPermi('monitor:job:add')")
@Log(title = "定时任务", businessType = BusinessType.INSERT)
@PostMapping
- public AjaxResult add(@RequestBody SysJob sysJob) throws SchedulerException, TaskException
- {
- if (!CronUtils.isValid(sysJob.getCronExpression()))
- {
+ public AjaxResult add(@RequestBody SysJob sysJob) throws SchedulerException, TaskException {
+ if (!CronUtils.isValid(sysJob.getCronExpression())) {
return AjaxResult.error("cron表达式不正确");
}
sysJob.setCreateBy(SecurityUtils.getUsername());
@@ -93,10 +88,8 @@ public class SysJobController extends BaseController
@PreAuthorize("@ss.hasPermi('monitor:job:edit')")
@Log(title = "定时任务", businessType = BusinessType.UPDATE)
@PutMapping
- public AjaxResult edit(@RequestBody SysJob sysJob) throws SchedulerException, TaskException
- {
- if (!CronUtils.isValid(sysJob.getCronExpression()))
- {
+ public AjaxResult edit(@RequestBody SysJob sysJob) throws SchedulerException, TaskException {
+ if (!CronUtils.isValid(sysJob.getCronExpression())) {
return AjaxResult.error("cron表达式不正确");
}
sysJob.setUpdateBy(SecurityUtils.getUsername());
@@ -109,8 +102,7 @@ public class SysJobController extends BaseController
@PreAuthorize("@ss.hasPermi('monitor:job:changeStatus')")
@Log(title = "定时任务", businessType = BusinessType.UPDATE)
@PutMapping("/changeStatus")
- public AjaxResult changeStatus(@RequestBody SysJob job) throws SchedulerException
- {
+ public AjaxResult changeStatus(@RequestBody SysJob job) throws SchedulerException {
SysJob newJob = jobService.selectJobById(job.getJobId());
newJob.setStatus(job.getStatus());
return toAjax(jobService.changeStatus(newJob));
@@ -122,8 +114,7 @@ public class SysJobController extends BaseController
@PreAuthorize("@ss.hasPermi('monitor:job:changeStatus')")
@Log(title = "定时任务", businessType = BusinessType.UPDATE)
@PutMapping("/run")
- public AjaxResult run(@RequestBody SysJob job) throws SchedulerException
- {
+ public AjaxResult run(@RequestBody SysJob job) throws SchedulerException {
jobService.run(job);
return AjaxResult.success();
}
@@ -134,8 +125,7 @@ public class SysJobController extends BaseController
@PreAuthorize("@ss.hasPermi('monitor:job:remove')")
@Log(title = "定时任务", businessType = BusinessType.DELETE)
@DeleteMapping("/{jobIds}")
- public AjaxResult remove(@PathVariable Long[] jobIds) throws SchedulerException, TaskException
- {
+ public AjaxResult remove(@PathVariable Long[] jobIds) throws SchedulerException, TaskException {
jobService.deleteJobByIds(jobIds);
return AjaxResult.success();
}
diff --git a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/controller/SysJobLogController.java b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/controller/SysJobLogController.java
index 10a842b6d..f1b4e9564 100644
--- a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/controller/SysJobLogController.java
+++ b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/controller/SysJobLogController.java
@@ -1,6 +1,7 @@
package com.ruoyi.quartz.controller;
import java.util.List;
+
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
@@ -19,13 +20,12 @@ import com.ruoyi.quartz.service.ISysJobLogService;
/**
* 调度日志操作处理
- *
+ *
* @author ruoyi
*/
@RestController
@RequestMapping("/monitor/jobLog")
-public class SysJobLogController extends BaseController
-{
+public class SysJobLogController extends BaseController {
@Autowired
private ISysJobLogService jobLogService;
@@ -34,8 +34,7 @@ public class SysJobLogController extends BaseController
*/
@PreAuthorize("@ss.hasPermi('monitor:job:list')")
@GetMapping("/list")
- public TableDataInfo list(SysJobLog sysJobLog)
- {
+ public TableDataInfo list(SysJobLog sysJobLog) {
startPage();
List list = jobLogService.selectJobLogList(sysJobLog);
return getDataTable(list);
@@ -47,20 +46,18 @@ public class SysJobLogController extends BaseController
@PreAuthorize("@ss.hasPermi('monitor:job:export')")
@Log(title = "任务调度日志", businessType = BusinessType.EXPORT)
@GetMapping("/export")
- public AjaxResult export(SysJobLog sysJobLog)
- {
+ public AjaxResult export(SysJobLog sysJobLog) {
List list = jobLogService.selectJobLogList(sysJobLog);
ExcelUtil util = new ExcelUtil(SysJobLog.class);
return util.exportExcel(list, "调度日志");
}
-
+
/**
* 根据调度编号获取详细信息
*/
@PreAuthorize("@ss.hasPermi('monitor:job:query')")
@GetMapping(value = "/{configId}")
- public AjaxResult getInfo(@PathVariable Long jobLogId)
- {
+ public AjaxResult getInfo(@PathVariable Long jobLogId) {
return AjaxResult.success(jobLogService.selectJobLogById(jobLogId));
}
@@ -71,8 +68,7 @@ public class SysJobLogController extends BaseController
@PreAuthorize("@ss.hasPermi('monitor:job:remove')")
@Log(title = "定时任务调度日志", businessType = BusinessType.DELETE)
@DeleteMapping("/{jobLogIds}")
- public AjaxResult remove(@PathVariable Long[] jobLogIds)
- {
+ public AjaxResult remove(@PathVariable Long[] jobLogIds) {
return toAjax(jobLogService.deleteJobLogByIds(jobLogIds));
}
@@ -82,8 +78,7 @@ public class SysJobLogController extends BaseController
@PreAuthorize("@ss.hasPermi('monitor:job:remove')")
@Log(title = "调度日志", businessType = BusinessType.CLEAN)
@DeleteMapping("/clean")
- public AjaxResult clean()
- {
+ public AjaxResult clean() {
jobLogService.cleanJobLog();
return AjaxResult.success();
}
diff --git a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/domain/SysJob.java b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/domain/SysJob.java
deleted file mode 100644
index f8df5b54d..000000000
--- a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/domain/SysJob.java
+++ /dev/null
@@ -1,89 +0,0 @@
-package com.ruoyi.quartz.domain;
-
-import java.io.Serializable;
-import java.util.Date;
-import javax.validation.constraints.NotBlank;
-import javax.validation.constraints.Size;
-import org.apache.commons.lang3.builder.ToStringBuilder;
-import org.apache.commons.lang3.builder.ToStringStyle;
-import com.fasterxml.jackson.annotation.JsonFormat;
-import com.ruoyi.common.annotation.Excel;
-import com.ruoyi.common.annotation.Excel.ColumnType;
-import com.ruoyi.common.constant.ScheduleConstants;
-import com.ruoyi.common.core.domain.BaseEntity;
-import com.ruoyi.common.utils.StringUtils;
-import com.ruoyi.quartz.util.CronUtils;
-
-/**
- * 定时任务调度表 sys_job
- *
- * @author ruoyi
- */
-public class SysJob extends BaseEntity implements Serializable
-{
- private static final long serialVersionUID = 1L;
-
- /** 任务ID */
- @Excel(name = "任务序号", cellType = ColumnType.NUMERIC)
- private Long jobId;
-
- /** 任务名称 */
- @Excel(name = "任务名称")
- private String jobName;
-
- /** 任务组名 */
- @Excel(name = "任务组名")
- private String jobGroup;
-
- /** 调用目标字符串 */
- @Excel(name = "调用目标字符串")
- private String invokeTarget;
-
- /** cron执行表达式 */
- @Excel(name = "执行表达式 ")
- private String cronExpression;
-
- /** cron计划策略 */
- @Excel(name = "计划策略 ", readConverterExp = "0=默认,1=立即触发执行,2=触发一次执行,3=不触发立即执行")
- private String misfirePolicy = ScheduleConstants.MISFIRE_DEFAULT;
-
- /** 是否并发执行(0允许 1禁止) */
- @Excel(name = "并发执行", readConverterExp = "0=允许,1=禁止")
- private String concurrent;
-
- /** 任务状态(0正常 1暂停) */
- @Excel(name = "任务状态", readConverterExp = "0=正常,1=暂停")
- private String status;
-
- @NotBlank(message = "任务名称不能为空")
- @Size(min = 0, max = 64, message = "任务名称不能超过64个字符")
- public String getJobName()
- {
- return jobName;
- }
-
- @NotBlank(message = "调用目标字符串不能为空")
- @Size(min = 0, max = 500, message = "调用目标字符串长度不能超过500个字符")
- public String getInvokeTarget()
- {
- return invokeTarget;
- }
-
- @NotBlank(message = "Cron执行表达式不能为空")
- @Size(min = 0, max = 255, message = "Cron执行表达式不能超过255个字符")
- public String getCronExpression()
- {
- return cronExpression;
- }
-
- @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
- public Date getNextValidTime()
- {
- if (StringUtils.isNotEmpty(cronExpression))
- {
- return CronUtils.getNextExecution(cronExpression);
- }
- return null;
- }
-
-}
diff --git a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/domain/SysJobLog.java b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/domain/SysJobLog.java
deleted file mode 100644
index 14875f4bf..000000000
--- a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/domain/SysJobLog.java
+++ /dev/null
@@ -1,52 +0,0 @@
-package com.ruoyi.quartz.domain;
-
-import java.util.Date;
-import org.apache.commons.lang3.builder.ToStringBuilder;
-import org.apache.commons.lang3.builder.ToStringStyle;
-import com.ruoyi.common.annotation.Excel;
-import com.ruoyi.common.core.domain.BaseEntity;
-
-/**
- * 定时任务调度日志表 sys_job_log
- *
- * @author ruoyi
- */
-public class SysJobLog extends BaseEntity
-{
- private static final long serialVersionUID = 1L;
-
- /** ID */
- @Excel(name = "日志序号")
- private Long jobLogId;
-
- /** 任务名称 */
- @Excel(name = "任务名称")
- private String jobName;
-
- /** 任务组名 */
- @Excel(name = "任务组名")
- private String jobGroup;
-
- /** 调用目标字符串 */
- @Excel(name = "调用目标字符串")
- private String invokeTarget;
-
- /** 日志信息 */
- @Excel(name = "日志信息")
- private String jobMessage;
-
- /** 执行状态(0正常 1失败) */
- @Excel(name = "执行状态", readConverterExp = "0=正常,1=失败")
- private String status;
-
- /** 异常信息 */
- @Excel(name = "异常信息")
- private String exceptionInfo;
-
- /** 开始时间 */
- private Date startTime;
-
- /** 停止时间 */
- private Date stopTime;
-
-}
diff --git a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/mapper/SysJobLogMapper.java b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/mapper/SysJobLogMapper.java
deleted file mode 100644
index ed01ef72e..000000000
--- a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/mapper/SysJobLogMapper.java
+++ /dev/null
@@ -1,64 +0,0 @@
-package com.ruoyi.quartz.mapper;
-
-import java.util.List;
-import com.ruoyi.quartz.domain.SysJobLog;
-
-/**
- * 调度任务日志信息 数据层
- *
- * @author ruoyi
- */
-public interface SysJobLogMapper
-{
- /**
- * 获取quartz调度器日志的计划任务
- *
- * @param jobLog 调度日志信息
- * @return 调度任务日志集合
- */
- public List selectJobLogList(SysJobLog jobLog);
-
- /**
- * 查询所有调度任务日志
- *
- * @return 调度任务日志列表
- */
- public List selectJobLogAll();
-
- /**
- * 通过调度任务日志ID查询调度信息
- *
- * @param jobLogId 调度任务日志ID
- * @return 调度任务日志对象信息
- */
- public SysJobLog selectJobLogById(Long jobLogId);
-
- /**
- * 新增任务日志
- *
- * @param jobLog 调度日志信息
- * @return 结果
- */
- public int insertJobLog(SysJobLog jobLog);
-
- /**
- * 批量删除调度日志信息
- *
- * @param logIds 需要删除的数据ID
- * @return 结果
- */
- public int deleteJobLogByIds(Long[] logIds);
-
- /**
- * 删除任务日志
- *
- * @param jobId 调度日志ID
- * @return 结果
- */
- public int deleteJobLogById(Long jobId);
-
- /**
- * 清空任务日志
- */
- public void cleanJobLog();
-}
diff --git a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/mapper/SysJobMapper.java b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/mapper/SysJobMapper.java
deleted file mode 100644
index f481ea12e..000000000
--- a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/mapper/SysJobMapper.java
+++ /dev/null
@@ -1,67 +0,0 @@
-package com.ruoyi.quartz.mapper;
-
-import java.util.List;
-import com.ruoyi.quartz.domain.SysJob;
-
-/**
- * 调度任务信息 数据层
- *
- * @author ruoyi
- */
-public interface SysJobMapper
-{
- /**
- * 查询调度任务日志集合
- *
- * @param job 调度信息
- * @return 操作日志集合
- */
- public List selectJobList(SysJob job);
-
- /**
- * 查询所有调度任务
- *
- * @return 调度任务列表
- */
- public List selectJobAll();
-
- /**
- * 通过调度ID查询调度任务信息
- *
- * @param jobId 调度ID
- * @return 角色对象信息
- */
- public SysJob selectJobById(Long jobId);
-
- /**
- * 通过调度ID删除调度任务信息
- *
- * @param jobId 调度ID
- * @return 结果
- */
- public int deleteJobById(Long jobId);
-
- /**
- * 批量删除调度任务信息
- *
- * @param ids 需要删除的数据ID
- * @return 结果
- */
- public int deleteJobByIds(Long[] ids);
-
- /**
- * 修改调度任务信息
- *
- * @param job 调度任务信息
- * @return 结果
- */
- public int updateJob(SysJob job);
-
- /**
- * 新增调度任务信息
- *
- * @param job 调度任务信息
- * @return 结果
- */
- public int insertJob(SysJob job);
-}
diff --git a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/service/ISysJobLogService.java b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/service/ISysJobLogService.java
index 5291a63ac..07d36b959 100644
--- a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/service/ISysJobLogService.java
+++ b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/service/ISysJobLogService.java
@@ -1,18 +1,18 @@
package com.ruoyi.quartz.service;
import java.util.List;
+
import com.ruoyi.quartz.domain.SysJobLog;
/**
* 定时任务调度日志信息信息 服务层
- *
+ *
* @author ruoyi
*/
-public interface ISysJobLogService
-{
+public interface ISysJobLogService {
/**
* 获取quartz调度器日志的计划任务
- *
+ *
* @param jobLog 调度日志信息
* @return 调度任务日志集合
*/
@@ -20,7 +20,7 @@ public interface ISysJobLogService
/**
* 通过调度任务日志ID查询调度信息
- *
+ *
* @param jobLogId 调度任务日志ID
* @return 调度任务日志对象信息
*/
@@ -28,14 +28,14 @@ public interface ISysJobLogService
/**
* 新增任务日志
- *
+ *
* @param jobLog 调度日志信息
*/
public void addJobLog(SysJobLog jobLog);
/**
* 批量删除调度日志信息
- *
+ *
* @param logIds 需要删除的日志ID
* @return 结果
*/
@@ -43,7 +43,7 @@ public interface ISysJobLogService
/**
* 删除任务日志
- *
+ *
* @param jobId 调度日志ID
* @return 结果
*/
diff --git a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/service/ISysJobService.java b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/service/ISysJobService.java
index 53f098956..ec68c085a 100644
--- a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/service/ISysJobService.java
+++ b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/service/ISysJobService.java
@@ -1,20 +1,20 @@
package com.ruoyi.quartz.service;
import java.util.List;
+
import org.quartz.SchedulerException;
import com.ruoyi.common.exception.job.TaskException;
import com.ruoyi.quartz.domain.SysJob;
/**
* 定时任务调度信息信息 服务层
- *
+ *
* @author ruoyi
*/
-public interface ISysJobService
-{
+public interface ISysJobService {
/**
* 获取quartz调度器的计划任务
- *
+ *
* @param job 调度信息
* @return 调度任务集合
*/
@@ -22,7 +22,7 @@ public interface ISysJobService
/**
* 通过调度任务ID查询调度信息
- *
+ *
* @param jobId 调度任务ID
* @return 调度任务对象信息
*/
@@ -30,7 +30,7 @@ public interface ISysJobService
/**
* 暂停任务
- *
+ *
* @param job 调度信息
* @return 结果
*/
@@ -38,7 +38,7 @@ public interface ISysJobService
/**
* 恢复任务
- *
+ *
* @param job 调度信息
* @return 结果
*/
@@ -46,7 +46,7 @@ public interface ISysJobService
/**
* 删除任务后,所对应的trigger也将被删除
- *
+ *
* @param job 调度信息
* @return 结果
*/
@@ -54,7 +54,7 @@ public interface ISysJobService
/**
* 批量删除调度信息
- *
+ *
* @param jobIds 需要删除的任务ID
* @return 结果
*/
@@ -62,7 +62,7 @@ public interface ISysJobService
/**
* 任务调度状态修改
- *
+ *
* @param job 调度信息
* @return 结果
*/
@@ -70,7 +70,7 @@ public interface ISysJobService
/**
* 立即运行任务
- *
+ *
* @param job 调度信息
* @return 结果
*/
@@ -78,7 +78,7 @@ public interface ISysJobService
/**
* 新增任务
- *
+ *
* @param job 调度信息
* @return 结果
*/
@@ -86,7 +86,7 @@ public interface ISysJobService
/**
* 更新任务
- *
+ *
* @param job 调度信息
* @return 结果
*/
@@ -94,7 +94,7 @@ public interface ISysJobService
/**
* 校验cron表达式是否有效
- *
+ *
* @param cronExpression 表达式
* @return 结果
*/
diff --git a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/service/impl/SysJobLogServiceImpl.java b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/service/impl/SysJobLogServiceImpl.java
index f68a5482b..9ce6d8230 100644
--- a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/service/impl/SysJobLogServiceImpl.java
+++ b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/service/impl/SysJobLogServiceImpl.java
@@ -1,6 +1,7 @@
package com.ruoyi.quartz.service.impl;
import java.util.List;
+
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.quartz.domain.SysJobLog;
@@ -9,70 +10,64 @@ import com.ruoyi.quartz.service.ISysJobLogService;
/**
* 定时任务调度日志信息 服务层
- *
+ *
* @author ruoyi
*/
@Service
-public class SysJobLogServiceImpl implements ISysJobLogService
-{
+public class SysJobLogServiceImpl implements ISysJobLogService {
@Autowired
private SysJobLogMapper jobLogMapper;
/**
* 获取quartz调度器日志的计划任务
- *
+ *
* @param jobLog 调度日志信息
* @return 调度任务日志集合
*/
@Override
- public List selectJobLogList(SysJobLog jobLog)
- {
+ public List selectJobLogList(SysJobLog jobLog) {
return jobLogMapper.selectJobLogList(jobLog);
}
/**
* 通过调度任务日志ID查询调度信息
- *
+ *
* @param jobLogId 调度任务日志ID
* @return 调度任务日志对象信息
*/
@Override
- public SysJobLog selectJobLogById(Long jobLogId)
- {
+ public SysJobLog selectJobLogById(Long jobLogId) {
return jobLogMapper.selectJobLogById(jobLogId);
}
/**
* 新增任务日志
- *
+ *
* @param jobLog 调度日志信息
*/
@Override
- public void addJobLog(SysJobLog jobLog)
- {
+ public void addJobLog(SysJobLog jobLog) {
jobLogMapper.insertJobLog(jobLog);
}
/**
* 批量删除调度日志信息
- *
+ *
* @param logIds 需要删除的数据ID
* @return 结果
*/
@Override
- public int deleteJobLogByIds(Long[] logIds)
- {
+ public int deleteJobLogByIds(Long[] logIds) {
return jobLogMapper.deleteJobLogByIds(logIds);
}
/**
* 删除任务日志
- *
+ *
* @param jobId 调度日志ID
*/
@Override
- public int deleteJobLogById(Long jobId)
- {
+ public int deleteJobLogById(Long jobId) {
return jobLogMapper.deleteJobLogById(jobId);
}
@@ -80,8 +75,7 @@ public class SysJobLogServiceImpl implements ISysJobLogService
* 清空任务日志
*/
@Override
- public void cleanJobLog()
- {
+ public void cleanJobLog() {
jobLogMapper.cleanJobLog();
}
}
diff --git a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/service/impl/SysJobServiceImpl.java b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/service/impl/SysJobServiceImpl.java
index d7bc6c984..b5ce72c5d 100644
--- a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/service/impl/SysJobServiceImpl.java
+++ b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/service/impl/SysJobServiceImpl.java
@@ -2,6 +2,7 @@ package com.ruoyi.quartz.service.impl;
import java.util.List;
import javax.annotation.PostConstruct;
+
import org.quartz.JobDataMap;
import org.quartz.JobKey;
import org.quartz.Scheduler;
@@ -19,12 +20,11 @@ import com.ruoyi.quartz.util.ScheduleUtils;
/**
* 定时任务调度信息 服务层
- *
+ *
* @author ruoyi
*/
@Service
-public class SysJobServiceImpl implements ISysJobService
-{
+public class SysJobServiceImpl implements ISysJobService {
@Autowired
private Scheduler scheduler;
@@ -35,55 +35,49 @@ public class SysJobServiceImpl implements ISysJobService
* 项目启动时,初始化定时器 主要是防止手动修改数据库导致未同步到定时任务处理(注:不能手动修改数据库ID和任务组名,否则会导致脏数据)
*/
@PostConstruct
- public void init() throws SchedulerException, TaskException
- {
+ public void init() throws SchedulerException, TaskException {
scheduler.clear();
List jobList = jobMapper.selectJobAll();
- for (SysJob job : jobList)
- {
+ for (SysJob job : jobList) {
ScheduleUtils.createScheduleJob(scheduler, job);
}
}
/**
* 获取quartz调度器的计划任务列表
- *
+ *
* @param job 调度信息
* @return
*/
@Override
- public List selectJobList(SysJob job)
- {
+ public List selectJobList(SysJob job) {
return jobMapper.selectJobList(job);
}
/**
* 通过调度任务ID查询调度信息
- *
+ *
* @param jobId 调度任务ID
* @return 调度任务对象信息
*/
@Override
- public SysJob selectJobById(Long jobId)
- {
+ public SysJob selectJobById(Long jobId) {
return jobMapper.selectJobById(jobId);
}
/**
* 暂停任务
- *
+ *
* @param job 调度信息
*/
@Override
@Transactional
- public int pauseJob(SysJob job) throws SchedulerException
- {
+ public int pauseJob(SysJob job) throws SchedulerException {
Long jobId = job.getJobId();
String jobGroup = job.getJobGroup();
job.setStatus(ScheduleConstants.Status.PAUSE.getValue());
int rows = jobMapper.updateJob(job);
- if (rows > 0)
- {
+ if (rows > 0) {
scheduler.pauseJob(ScheduleUtils.getJobKey(jobId, jobGroup));
}
return rows;
@@ -91,19 +85,17 @@ public class SysJobServiceImpl implements ISysJobService
/**
* 恢复任务
- *
+ *
* @param job 调度信息
*/
@Override
@Transactional
- public int resumeJob(SysJob job) throws SchedulerException
- {
+ public int resumeJob(SysJob job) throws SchedulerException {
Long jobId = job.getJobId();
String jobGroup = job.getJobGroup();
job.setStatus(ScheduleConstants.Status.NORMAL.getValue());
int rows = jobMapper.updateJob(job);
- if (rows > 0)
- {
+ if (rows > 0) {
scheduler.resumeJob(ScheduleUtils.getJobKey(jobId, jobGroup));
}
return rows;
@@ -111,18 +103,16 @@ public class SysJobServiceImpl implements ISysJobService
/**
* 删除任务后,所对应的trigger也将被删除
- *
+ *
* @param job 调度信息
*/
@Override
@Transactional
- public int deleteJob(SysJob job) throws SchedulerException
- {
+ public int deleteJob(SysJob job) throws SchedulerException {
Long jobId = job.getJobId();
String jobGroup = job.getJobGroup();
int rows = jobMapper.deleteJobById(jobId);
- if (rows > 0)
- {
+ if (rows > 0) {
scheduler.deleteJob(ScheduleUtils.getJobKey(jobId, jobGroup));
}
return rows;
@@ -130,16 +120,14 @@ public class SysJobServiceImpl implements ISysJobService
/**
* 批量删除调度信息
- *
+ *
* @param jobIds 需要删除的任务ID
* @return 结果
*/
@Override
@Transactional
- public void deleteJobByIds(Long[] jobIds) throws SchedulerException
- {
- for (Long jobId : jobIds)
- {
+ public void deleteJobByIds(Long[] jobIds) throws SchedulerException {
+ for (Long jobId : jobIds) {
SysJob job = jobMapper.selectJobById(jobId);
deleteJob(job);
}
@@ -147,21 +135,17 @@ public class SysJobServiceImpl implements ISysJobService
/**
* 任务调度状态修改
- *
+ *
* @param job 调度信息
*/
@Override
@Transactional
- public int changeStatus(SysJob job) throws SchedulerException
- {
+ public int changeStatus(SysJob job) throws SchedulerException {
int rows = 0;
String status = job.getStatus();
- if (ScheduleConstants.Status.NORMAL.getValue().equals(status))
- {
+ if (ScheduleConstants.Status.NORMAL.getValue().equals(status)) {
rows = resumeJob(job);
- }
- else if (ScheduleConstants.Status.PAUSE.getValue().equals(status))
- {
+ } else if (ScheduleConstants.Status.PAUSE.getValue().equals(status)) {
rows = pauseJob(job);
}
return rows;
@@ -169,13 +153,12 @@ public class SysJobServiceImpl implements ISysJobService
/**
* 立即运行任务
- *
+ *
* @param job 调度信息
*/
@Override
@Transactional
- public void run(SysJob job) throws SchedulerException
- {
+ public void run(SysJob job) throws SchedulerException {
Long jobId = job.getJobId();
String jobGroup = job.getJobGroup();
SysJob properties = selectJobById(job.getJobId());
@@ -187,17 +170,15 @@ public class SysJobServiceImpl implements ISysJobService
/**
* 新增任务
- *
+ *
* @param job 调度信息 调度信息
*/
@Override
@Transactional
- public int insertJob(SysJob job) throws SchedulerException, TaskException
- {
+ public int insertJob(SysJob job) throws SchedulerException, TaskException {
job.setStatus(ScheduleConstants.Status.PAUSE.getValue());
int rows = jobMapper.insertJob(job);
- if (rows > 0)
- {
+ if (rows > 0) {
ScheduleUtils.createScheduleJob(scheduler, job);
}
return rows;
@@ -205,17 +186,15 @@ public class SysJobServiceImpl implements ISysJobService
/**
* 更新任务的时间表达式
- *
+ *
* @param job 调度信息
*/
@Override
@Transactional
- public int updateJob(SysJob job) throws SchedulerException, TaskException
- {
+ public int updateJob(SysJob job) throws SchedulerException, TaskException {
SysJob properties = selectJobById(job.getJobId());
int rows = jobMapper.updateJob(job);
- if (rows > 0)
- {
+ if (rows > 0) {
updateSchedulerJob(job, properties.getJobGroup());
}
return rows;
@@ -223,17 +202,15 @@ public class SysJobServiceImpl implements ISysJobService
/**
* 更新任务
- *
- * @param job 任务对象
+ *
+ * @param job 任务对象
* @param jobGroup 任务组名
*/
- public void updateSchedulerJob(SysJob job, String jobGroup) throws SchedulerException, TaskException
- {
+ public void updateSchedulerJob(SysJob job, String jobGroup) throws SchedulerException, TaskException {
Long jobId = job.getJobId();
// 判断是否存在
JobKey jobKey = ScheduleUtils.getJobKey(jobId, jobGroup);
- if (scheduler.checkExists(jobKey))
- {
+ if (scheduler.checkExists(jobKey)) {
// 防止创建时存在数据问题 先移除,然后在执行创建操作
scheduler.deleteJob(jobKey);
}
@@ -242,13 +219,12 @@ public class SysJobServiceImpl implements ISysJobService
/**
* 校验cron表达式是否有效
- *
+ *
* @param cronExpression 表达式
* @return 结果
*/
@Override
- public boolean checkCronExpressionIsValid(String cronExpression)
- {
+ public boolean checkCronExpressionIsValid(String cronExpression) {
return CronUtils.isValid(cronExpression);
}
}
diff --git a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/RyTask.java b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/RyTask.java
index 25d1ddd02..6a6e1fdf1 100644
--- a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/RyTask.java
+++ b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/RyTask.java
@@ -5,24 +5,20 @@ import com.ruoyi.common.utils.StringUtils;
/**
* 定时任务调度测试
- *
+ *
* @author ruoyi
*/
@Component("ryTask")
-public class RyTask
-{
- public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i)
- {
+public class RyTask {
+ public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i) {
System.out.println(StringUtils.format("执行多参方法: 字符串类型{},布尔类型{},长整型{},浮点型{},整形{}", s, b, l, d, i));
}
- public void ryParams(String params)
- {
+ public void ryParams(String params) {
System.out.println("执行有参方法:" + params);
}
- public void ryNoParams()
- {
+ public void ryNoParams() {
System.out.println("执行无参方法");
}
}
diff --git a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/util/AbstractQuartzJob.java b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/util/AbstractQuartzJob.java
index fd652d677..0b2fe9d28 100644
--- a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/util/AbstractQuartzJob.java
+++ b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/util/AbstractQuartzJob.java
@@ -1,6 +1,7 @@
package com.ruoyi.quartz.util;
import java.util.Date;
+
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
@@ -21,8 +22,7 @@ import com.ruoyi.quartz.service.ISysJobLogService;
*
* @author ruoyi
*/
-public abstract class AbstractQuartzJob implements Job
-{
+public abstract class AbstractQuartzJob implements Job {
private static final Logger log = LoggerFactory.getLogger(AbstractQuartzJob.class);
/**
@@ -31,21 +31,16 @@ public abstract class AbstractQuartzJob implements Job
private static ThreadLocal threadLocal = new ThreadLocal<>();
@Override
- public void execute(JobExecutionContext context) throws JobExecutionException
- {
+ public void execute(JobExecutionContext context) throws JobExecutionException {
SysJob sysJob = new SysJob();
BeanUtils.copyBeanProp(sysJob, context.getMergedJobDataMap().get(ScheduleConstants.TASK_PROPERTIES));
- try
- {
+ try {
before(context, sysJob);
- if (sysJob != null)
- {
+ if (sysJob != null) {
doExecute(context, sysJob);
}
after(context, sysJob, null);
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
log.error("任务执行异常 - :", e);
after(context, sysJob, e);
}
@@ -55,10 +50,9 @@ public abstract class AbstractQuartzJob implements Job
* 执行前
*
* @param context 工作执行上下文对象
- * @param sysJob 系统计划任务
+ * @param sysJob 系统计划任务
*/
- protected void before(JobExecutionContext context, SysJob sysJob)
- {
+ protected void before(JobExecutionContext context, SysJob sysJob) {
threadLocal.set(new Date());
}
@@ -66,10 +60,9 @@ public abstract class AbstractQuartzJob implements Job
* 执行后
*
* @param context 工作执行上下文对象
- * @param sysJob 系统计划任务
+ * @param sysJob 系统计划任务
*/
- protected void after(JobExecutionContext context, SysJob sysJob, Exception e)
- {
+ protected void after(JobExecutionContext context, SysJob sysJob, Exception e) {
Date startTime = threadLocal.get();
threadLocal.remove();
@@ -81,14 +74,11 @@ public abstract class AbstractQuartzJob implements Job
sysJobLog.setStopTime(new Date());
long runMs = sysJobLog.getStopTime().getTime() - sysJobLog.getStartTime().getTime();
sysJobLog.setJobMessage(sysJobLog.getJobName() + " 总共耗时:" + runMs + "毫秒");
- if (e != null)
- {
+ if (e != null) {
sysJobLog.setStatus(Constants.FAIL);
String errorMsg = StringUtils.substring(ExceptionUtil.getExceptionMessage(e), 0, 2000);
sysJobLog.setExceptionInfo(errorMsg);
- }
- else
- {
+ } else {
sysJobLog.setStatus(Constants.SUCCESS);
}
@@ -100,7 +90,7 @@ public abstract class AbstractQuartzJob implements Job
* 执行方法,由子类重载
*
* @param context 工作执行上下文对象
- * @param sysJob 系统计划任务
+ * @param sysJob 系统计划任务
* @throws Exception 执行过程中的异常
*/
protected abstract void doExecute(JobExecutionContext context, SysJob sysJob) throws Exception;
diff --git a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/util/CronUtils.java b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/util/CronUtils.java
index 6826787a6..31c4e819b 100644
--- a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/util/CronUtils.java
+++ b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/util/CronUtils.java
@@ -2,24 +2,22 @@ package com.ruoyi.quartz.util;
import java.text.ParseException;
import java.util.Date;
+
import org.quartz.CronExpression;
/**
* cron表达式工具类
- *
- * @author ruoyi
*
+ * @author ruoyi
*/
-public class CronUtils
-{
+public class CronUtils {
/**
* 返回一个布尔值代表一个给定的Cron表达式的有效性
*
* @param cronExpression Cron表达式
* @return boolean 表达式是否有效
*/
- public static boolean isValid(String cronExpression)
- {
+ public static boolean isValid(String cronExpression) {
return CronExpression.isValidExpression(cronExpression);
}
@@ -29,15 +27,11 @@ public class CronUtils
* @param cronExpression Cron表达式
* @return String 无效时返回表达式错误描述,如果有效返回null
*/
- public static String getInvalidMessage(String cronExpression)
- {
- try
- {
+ public static String getInvalidMessage(String cronExpression) {
+ try {
new CronExpression(cronExpression);
return null;
- }
- catch (ParseException pe)
- {
+ } catch (ParseException pe) {
return pe.getMessage();
}
}
@@ -48,15 +42,11 @@ public class CronUtils
* @param cronExpression Cron表达式
* @return Date 下次Cron表达式执行时间
*/
- public static Date getNextExecution(String cronExpression)
- {
- try
- {
+ public static Date getNextExecution(String cronExpression) {
+ try {
CronExpression cron = new CronExpression(cronExpression);
return cron.getNextValidTimeAfter(new Date(System.currentTimeMillis()));
- }
- catch (ParseException e)
- {
+ } catch (ParseException e) {
throw new IllegalArgumentException(e.getMessage());
}
}
diff --git a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/util/JobInvokeUtil.java b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/util/JobInvokeUtil.java
index 5519c672f..ade0f8624 100644
--- a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/util/JobInvokeUtil.java
+++ b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/util/JobInvokeUtil.java
@@ -4,6 +4,7 @@ import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.LinkedList;
import java.util.List;
+
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.quartz.domain.SysJob;
@@ -13,27 +14,22 @@ import com.ruoyi.quartz.domain.SysJob;
*
* @author ruoyi
*/
-public class JobInvokeUtil
-{
+public class JobInvokeUtil {
/**
* 执行方法
*
* @param sysJob 系统任务
*/
- public static void invokeMethod(SysJob sysJob) throws Exception
- {
+ public static void invokeMethod(SysJob sysJob) throws Exception {
String invokeTarget = sysJob.getInvokeTarget();
String beanName = getBeanName(invokeTarget);
String methodName = getMethodName(invokeTarget);
List