瀏覽代碼

定时任务cron表达式验证

RuoYi 4 年之前
父節點
當前提交
f42b8c7a83
共有 2 個文件被更改,包括 10 次插入1 次删除
  1. 1 1
      ruoyi-admin/pom.xml
  2. 9 0
      ruoyi-quartz/src/main/java/com/ruoyi/quartz/controller/SysJobController.java

+ 1 - 1
ruoyi-admin/pom.xml

@@ -55,7 +55,7 @@
             <artifactId>springfox-swagger-ui</artifactId>
         </dependency>
 
-         <!-- Mysql驱动包 -->
+        <!-- Mysql驱动包 -->
         <dependency>
             <groupId>mysql</groupId>
             <artifactId>mysql-connector-java</artifactId>

+ 9 - 0
ruoyi-quartz/src/main/java/com/ruoyi/quartz/controller/SysJobController.java

@@ -21,6 +21,7 @@ import com.ruoyi.common.exception.job.TaskException;
 import com.ruoyi.common.utils.poi.ExcelUtil;
 import com.ruoyi.quartz.domain.SysJob;
 import com.ruoyi.quartz.service.ISysJobService;
+import com.ruoyi.quartz.util.CronUtils;
 
 /**
  * 调度任务信息操作处理
@@ -128,6 +129,10 @@ public class SysJobController extends BaseController
     @ResponseBody
     public AjaxResult addSave(@Validated SysJob job) throws SchedulerException, TaskException
     {
+        if (!CronUtils.isValid(job.getCronExpression()))
+        {
+            return AjaxResult.error("cron表达式不正确");
+        }
         return toAjax(jobService.insertJob(job));
     }
 
@@ -150,6 +155,10 @@ public class SysJobController extends BaseController
     @ResponseBody
     public AjaxResult editSave(@Validated SysJob job) throws SchedulerException, TaskException
     {
+        if (!CronUtils.isValid(job.getCronExpression()))
+        {
+            return AjaxResult.error("cron表达式不正确");
+        }
         return toAjax(jobService.updateJob(job));
     }