Просмотр исходного кода

定时任务cron表达式验证

RuoYi лет назад: 5
Родитель
Сommit
59b8df2e90

+ 8 - 2
ruoyi-common/ruoyi-common-log/src/main/java/com/ruoyi/common/log/aspect/LogAspect.java

@@ -198,8 +198,14 @@ public class LogAspect
198 198
             {
199 199
                 if (!isFilterObject(paramsArray[i]))
200 200
                 {
201
-                    Object jsonObj = JSON.toJSON(paramsArray[i]);
202
-                    params += jsonObj.toString() + " ";
201
+                    try
202
+                    {
203
+                        Object jsonObj = JSON.toJSON(paramsArray[i]);
204
+                        params += jsonObj.toString() + " ";
205
+                    }
206
+                    catch (Exception e)
207
+                    {
208
+                    }
203 209
                 }
204 210
             }
205 211
         }

+ 12 - 0
ruoyi-modules/ruoyi-job/src/main/java/com/ruoyi/job/controller/SysJobController.java

@@ -21,8 +21,10 @@ import com.ruoyi.common.core.web.domain.AjaxResult;
21 21
 import com.ruoyi.common.core.web.page.TableDataInfo;
22 22
 import com.ruoyi.common.log.annotation.Log;
23 23
 import com.ruoyi.common.log.enums.BusinessType;
24
+import com.ruoyi.common.security.utils.SecurityUtils;
24 25
 import com.ruoyi.job.domain.SysJob;
25 26
 import com.ruoyi.job.service.ISysJobService;
27
+import com.ruoyi.job.util.CronUtils;
26 28
 
27 29
 /**
28 30
  * 调度任务信息操作处理
@@ -79,6 +81,11 @@ public class SysJobController extends BaseController
79 81
     @PostMapping
80 82
     public AjaxResult add(@RequestBody SysJob sysJob) throws SchedulerException, TaskException
81 83
     {
84
+        if (!CronUtils.isValid(sysJob.getCronExpression()))
85
+        {
86
+            return AjaxResult.error("cron表达式不正确");
87
+        }
88
+        sysJob.setCreateBy(SecurityUtils.getUsername());
82 89
         return toAjax(jobService.insertJob(sysJob));
83 90
     }
84 91
 
@@ -90,6 +97,11 @@ public class SysJobController extends BaseController
90 97
     @PutMapping
91 98
     public AjaxResult edit(@RequestBody SysJob sysJob) throws SchedulerException, TaskException
92 99
     {
100
+        if (!CronUtils.isValid(sysJob.getCronExpression()))
101
+        {
102
+            return AjaxResult.error("cron表达式不正确");
103
+        }
104
+        sysJob.setUpdateBy(SecurityUtils.getUsername());
93 105
         return toAjax(jobService.updateJob(sysJob));
94 106
     }
95 107