diff --git a/ruoyi-admin/src/main/resources/static/ruoyi/js/ry-ui.js b/ruoyi-admin/src/main/resources/static/ruoyi/js/ry-ui.js
index 2b030c32d..59c705f6a 100644
--- a/ruoyi-admin/src/main/resources/static/ruoyi/js/ry-ui.js
+++ b/ruoyi-admin/src/main/resources/static/ruoyi/js/ry-ui.js
@@ -196,7 +196,7 @@
var pageNumber = table.pageNumber;
return pageSize * (pageNumber - 1) + index + 1;
},
- // 列超出指定长度浮动提示(单击文本复制列)
+ // 列超出指定长度浮动提示(单击文本复制)
tooltip: function (value, length) {
var _length = $.common.isEmpty(length) ? 20 : length;
var _text = "";
@@ -386,7 +386,7 @@
var actions = [];
$.each(datas, function(index, dict) {
if (dict.dictValue == ('' + value)) {
- var listClass = $.common.equals("default", dict.listClass) ? "" : "badge badge-" + dict.listClass;
+ var listClass = $.common.equals("default", dict.listClass) || $.common.isEmpty(dict.listClass) ? "" : "badge badge-" + dict.listClass;
actions.push($.common.sprintf("%s", listClass, dict.dictLabel));
return false;
}
diff --git a/ruoyi-admin/src/main/resources/templates/system/user/add.html b/ruoyi-admin/src/main/resources/templates/system/user/add.html
index f5d1e2ebe..6d270cf3c 100644
--- a/ruoyi-admin/src/main/resources/templates/system/user/add.html
+++ b/ruoyi-admin/src/main/resources/templates/system/user/add.html
@@ -71,11 +71,9 @@
diff --git a/ruoyi-admin/src/main/resources/templates/system/user/edit.html b/ruoyi-admin/src/main/resources/templates/system/user/edit.html
index acef2c50f..e10e45a75 100644
--- a/ruoyi-admin/src/main/resources/templates/system/user/edit.html
+++ b/ruoyi-admin/src/main/resources/templates/system/user/edit.html
@@ -85,11 +85,9 @@
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 8c8141e97..461cbb250 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
@@ -127,7 +127,7 @@ public class SysJobController extends BaseController
@ResponseBody
public AjaxResult addSave(SysJob job) throws SchedulerException, TaskException
{
- return toAjax(jobService.insertJobCron(job));
+ return toAjax(jobService.insertJob(job));
}
/**
@@ -149,7 +149,7 @@ public class SysJobController extends BaseController
@ResponseBody
public AjaxResult editSave(SysJob job) throws SchedulerException, TaskException
{
- return toAjax(jobService.updateJobCron(job));
+ return toAjax(jobService.updateJob(job));
}
/**
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
index de10afd82..84c11151f 100644
--- a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/domain/SysJob.java
+++ b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/domain/SysJob.java
@@ -31,24 +31,20 @@ public class SysJob extends BaseEntity implements Serializable
@Excel(name = "任务组名")
private String jobGroup;
- /** 任务方法 */
- @Excel(name = "任务方法")
- private String methodName;
-
- /** 方法参数 */
- @Excel(name = "方法参数")
- private String methodParams;
+ /** 调用目标字符串 */
+ @Excel(name = "调用目标字符串")
+ private String invokeTarget;
/** cron执行表达式 */
@Excel(name = "执行表达式 ")
private String cronExpression;
/** cron计划策略 */
- @Excel(name = "计划策略 ")
+ @Excel(name = "计划策略 ", readConverterExp = "0=默认,1=立即触发执行,2=触发一次执行,3=不触发立即执行")
private String misfirePolicy = ScheduleConstants.MISFIRE_DEFAULT;
/** 是否并发执行(0允许 1禁止) */
- @Excel(name = "并发执行", readConverterExp = "0=允许,1=禁止")
+ @Excel(name = "并发执行", readConverterExp = "0=允许,1=禁止")
private String concurrent;
/** 任务状态(0正常 1暂停) */
@@ -85,24 +81,14 @@ public class SysJob extends BaseEntity implements Serializable
this.jobGroup = jobGroup;
}
- public String getMethodName()
+ public String getInvokeTarget()
{
- return methodName;
+ return invokeTarget;
}
- public void setMethodName(String methodName)
+ public void setInvokeTarget(String invokeTarget)
{
- this.methodName = methodName;
- }
-
- public String getMethodParams()
- {
- return methodParams;
- }
-
- public void setMethodParams(String methodParams)
- {
- this.methodParams = methodParams;
+ this.invokeTarget = invokeTarget;
}
public String getCronExpression()
@@ -153,15 +139,13 @@ public class SysJob extends BaseEntity implements Serializable
{
this.status = status;
}
-
+
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("jobId", getJobId())
.append("jobName", getJobName())
.append("jobGroup", getJobGroup())
- .append("methodName", getMethodName())
- .append("methodParams", getMethodParams())
.append("cronExpression", getCronExpression())
.append("nextValidTime", getNextValidTime())
.append("misfirePolicy", getMisfirePolicy())
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
index 9356629c4..f044aea7f 100644
--- a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/domain/SysJobLog.java
+++ b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/domain/SysJobLog.java
@@ -27,13 +27,9 @@ public class SysJobLog extends BaseEntity
@Excel(name = "任务组名")
private String jobGroup;
- /** 任务方法 */
- @Excel(name = "任务方法")
- private String methodName;
-
- /** 方法参数 */
- @Excel(name = "方法参数")
- private String methodParams;
+ /** 调用目标字符串 */
+ @Excel(name = "调用目标字符串")
+ private String invokeTarget;
/** 日志信息 */
@Excel(name = "日志信息")
@@ -83,24 +79,14 @@ public class SysJobLog extends BaseEntity
this.jobGroup = jobGroup;
}
- public String getMethodName()
+ public String getInvokeTarget()
{
- return methodName;
+ return invokeTarget;
}
- public void setMethodName(String methodName)
+ public void setInvokeTarget(String invokeTarget)
{
- this.methodName = methodName;
- }
-
- public String getMethodParams()
- {
- return methodParams;
- }
-
- public void setMethodParams(String methodParams)
- {
- this.methodParams = methodParams;
+ this.invokeTarget = invokeTarget;
}
public String getJobMessage()
@@ -132,7 +118,7 @@ public class SysJobLog extends BaseEntity
{
this.exceptionInfo = exceptionInfo;
}
-
+
public Date getStartTime()
{
return startTime;
@@ -159,8 +145,6 @@ public class SysJobLog extends BaseEntity
.append("jobLogId", getJobLogId())
.append("jobName", getJobName())
.append("jobGroup", getJobGroup())
- .append("methodName", getMethodName())
- .append("methodParams", getMethodParams())
.append("jobMessage", getJobMessage())
.append("status", getStatus())
.append("exceptionInfo", getExceptionInfo())
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 1e94f5ec6..ce4953290 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
@@ -77,20 +77,20 @@ public interface ISysJobService
public void run(SysJob job) throws SchedulerException;
/**
- * 新增任务表达式
+ * 新增任务
*
* @param job 调度信息
* @return 结果
*/
- public int insertJobCron(SysJob job) throws SchedulerException, TaskException;
+ public int insertJob(SysJob job) throws SchedulerException, TaskException;
/**
- * 更新任务的时间表达式
+ * 更新任务
*
* @param job 调度信息
* @return 结果
*/
- public int updateJobCron(SysJob job) throws SchedulerException, TaskException;
+ public int updateJob(SysJob job) throws SchedulerException, TaskException;
/**
* 校验cron表达式是否有效
@@ -99,4 +99,4 @@ public interface ISysJobService
* @return 结果
*/
public boolean checkCronExpressionIsValid(String cronExpression);
-}
+}
\ No newline at end of file
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 da28feefd..29a9eb540 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,8 @@ 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;
import org.quartz.SchedulerException;
import org.springframework.beans.factory.annotation.Autowired;
@@ -31,7 +33,8 @@ public class SysJobServiceImpl implements ISysJobService
private SysJobMapper jobMapper;
/**
- * 项目启动时,初始化定时器
+ * 项目启动时,初始化定时器
+ * 主要是防止手动修改数据库导致未同步到定时任务处理(注:不能手动修改数据库ID和任务组名,否则会导致脏数据)
*/
@PostConstruct
public void init() throws SchedulerException, TaskException
@@ -39,7 +42,7 @@ public class SysJobServiceImpl implements ISysJobService
List jobList = jobMapper.selectJobAll();
for (SysJob job : jobList)
{
- ScheduleUtils.updateScheduleJob(scheduler, job);
+ updateSchedulerJob(job, job.getJobGroup());
}
}
@@ -76,11 +79,13 @@ public class SysJobServiceImpl implements ISysJobService
@Transactional
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)
{
- ScheduleUtils.pauseJob(scheduler, job.getJobId());
+ scheduler.pauseJob(ScheduleUtils.getJobKey(jobId, jobGroup));
}
return rows;
}
@@ -94,11 +99,13 @@ public class SysJobServiceImpl implements ISysJobService
@Transactional
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)
{
- ScheduleUtils.resumeJob(scheduler, job.getJobId());
+ scheduler.resumeJob(ScheduleUtils.getJobKey(jobId, jobGroup));
}
return rows;
}
@@ -112,10 +119,12 @@ public class SysJobServiceImpl implements ISysJobService
@Transactional
public int deleteJob(SysJob job) throws SchedulerException
{
- int rows = jobMapper.deleteJobById(job.getJobId());
+ Long jobId = job.getJobId();
+ String jobGroup = job.getJobGroup();
+ int rows = jobMapper.deleteJobById(jobId);
if (rows > 0)
{
- ScheduleUtils.deleteScheduleJob(scheduler, job.getJobId());
+ scheduler.deleteJob(ScheduleUtils.getJobKey(jobId, jobGroup));
}
return rows;
}
@@ -169,7 +178,13 @@ public class SysJobServiceImpl implements ISysJobService
@Transactional
public void run(SysJob job) throws SchedulerException
{
- ScheduleUtils.run(scheduler, selectJobById(job.getJobId()));
+ Long jobId = job.getJobId();
+ String jobGroup = job.getJobGroup();
+ SysJob properties = selectJobById(job.getJobId());
+ // 参数
+ JobDataMap dataMap = new JobDataMap();
+ dataMap.put(ScheduleConstants.TASK_PROPERTIES, properties);
+ scheduler.triggerJob(ScheduleUtils.getJobKey(jobId, jobGroup), dataMap);
}
/**
@@ -179,7 +194,7 @@ public class SysJobServiceImpl implements ISysJobService
*/
@Override
@Transactional
- public int insertJobCron(SysJob job) throws SchedulerException, TaskException
+ public int insertJob(SysJob job) throws SchedulerException, TaskException
{
job.setStatus(ScheduleConstants.Status.PAUSE.getValue());
int rows = jobMapper.insertJob(job);
@@ -197,16 +212,36 @@ public class SysJobServiceImpl implements ISysJobService
*/
@Override
@Transactional
- public int updateJobCron(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)
{
- ScheduleUtils.updateScheduleJob(scheduler, job);
+ updateSchedulerJob(job, properties.getJobGroup());
}
return rows;
}
+ /**
+ * 更新任务
+ *
+ * @param job 任务对象
+ * @param jobGroup 任务组名
+ */
+ public void updateSchedulerJob(SysJob job, String jobGroup) throws SchedulerException, TaskException
+ {
+ Long jobId = job.getJobId();
+ // 判断是否存在
+ JobKey jobKey = ScheduleUtils.getJobKey(jobId, jobGroup);
+ if (scheduler.checkExists(jobKey))
+ {
+ // 防止创建时存在数据问题 先移除,然后在执行创建操作
+ scheduler.deleteJob(jobKey);
+ }
+ ScheduleUtils.createScheduleJob(scheduler, job);
+ }
+
/**
* 校验cron表达式是否有效
*
@@ -218,4 +253,4 @@ public class SysJobServiceImpl implements ISysJobService
{
return CronUtils.isValid(cronExpression);
}
-}
+}
\ No newline at end of file
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 a8dc9e114..25d1ddd02 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
@@ -1,6 +1,7 @@
package com.ruoyi.quartz.task;
import org.springframework.stereotype.Component;
+import com.ruoyi.common.utils.StringUtils;
/**
* 定时任务调度测试
@@ -10,6 +11,11 @@ import org.springframework.stereotype.Component;
@Component("ryTask")
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)
{
System.out.println("执行有参方法:" + params);
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 7cd0893e7..a6f3dc4ee 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
@@ -76,8 +76,7 @@ public abstract class AbstractQuartzJob implements Job
final SysJobLog sysJobLog = new SysJobLog();
sysJobLog.setJobName(sysJob.getJobName());
sysJobLog.setJobGroup(sysJob.getJobGroup());
- sysJobLog.setMethodName(sysJob.getMethodName());
- sysJobLog.setMethodParams(sysJob.getMethodParams());
+ sysJobLog.setInvokeTarget(sysJob.getInvokeTarget());
sysJobLog.setStartTime(startTime);
sysJobLog.setEndTime(new Date());
long runMs = sysJobLog.getEndTime().getTime() - sysJobLog.getStartTime().getTime();
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 c126951da..5519c672f 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
@@ -2,6 +2,8 @@ package com.ruoyi.quartz.util;
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;
@@ -20,11 +22,21 @@ public class JobInvokeUtil
*/
public static void invokeMethod(SysJob sysJob) throws Exception
{
- Object bean = SpringUtils.getBean(sysJob.getJobName());
- String methodName = sysJob.getMethodName();
- String methodParams = sysJob.getMethodParams();
+ String invokeTarget = sysJob.getInvokeTarget();
+ String beanName = getBeanName(invokeTarget);
+ String methodName = getMethodName(invokeTarget);
+ List