Commit 4088463adf5a33a43b7fddf3f66d65c220acf93d
1 parent
dd7a9850
定时任务cron表达式验证
Showing
1 changed file
with
12 additions
and
0 deletions
ruoyi/src/main/java/com/ruoyi/project/monitor/controller/SysJobController.java
| @@ -13,6 +13,8 @@ import org.springframework.web.bind.annotation.RequestBody; | @@ -13,6 +13,8 @@ import org.springframework.web.bind.annotation.RequestBody; | ||
| 13 | import org.springframework.web.bind.annotation.RequestMapping; | 13 | import org.springframework.web.bind.annotation.RequestMapping; |
| 14 | import org.springframework.web.bind.annotation.RestController; | 14 | import org.springframework.web.bind.annotation.RestController; |
| 15 | import com.ruoyi.common.exception.job.TaskException; | 15 | import com.ruoyi.common.exception.job.TaskException; |
| 16 | +import com.ruoyi.common.utils.SecurityUtils; | ||
| 17 | +import com.ruoyi.common.utils.job.CronUtils; | ||
| 16 | import com.ruoyi.common.utils.poi.ExcelUtil; | 18 | import com.ruoyi.common.utils.poi.ExcelUtil; |
| 17 | import com.ruoyi.framework.aspectj.lang.annotation.Log; | 19 | import com.ruoyi.framework.aspectj.lang.annotation.Log; |
| 18 | import com.ruoyi.framework.aspectj.lang.enums.BusinessType; | 20 | import com.ruoyi.framework.aspectj.lang.enums.BusinessType; |
| @@ -77,6 +79,11 @@ public class SysJobController extends BaseController | @@ -77,6 +79,11 @@ public class SysJobController extends BaseController | ||
| 77 | @PostMapping | 79 | @PostMapping |
| 78 | public AjaxResult add(@RequestBody SysJob sysJob) throws SchedulerException, TaskException | 80 | public AjaxResult add(@RequestBody SysJob sysJob) throws SchedulerException, TaskException |
| 79 | { | 81 | { |
| 82 | + if (!CronUtils.isValid(sysJob.getCronExpression())) | ||
| 83 | + { | ||
| 84 | + return AjaxResult.error("cron表达式不正确"); | ||
| 85 | + } | ||
| 86 | + sysJob.setCreateBy(SecurityUtils.getUsername()); | ||
| 80 | return toAjax(jobService.insertJob(sysJob)); | 87 | return toAjax(jobService.insertJob(sysJob)); |
| 81 | } | 88 | } |
| 82 | 89 | ||
| @@ -88,6 +95,11 @@ public class SysJobController extends BaseController | @@ -88,6 +95,11 @@ public class SysJobController extends BaseController | ||
| 88 | @PutMapping | 95 | @PutMapping |
| 89 | public AjaxResult edit(@RequestBody SysJob sysJob) throws SchedulerException, TaskException | 96 | public AjaxResult edit(@RequestBody SysJob sysJob) throws SchedulerException, TaskException |
| 90 | { | 97 | { |
| 98 | + if (!CronUtils.isValid(sysJob.getCronExpression())) | ||
| 99 | + { | ||
| 100 | + return AjaxResult.error("cron表达式不正确"); | ||
| 101 | + } | ||
| 102 | + sysJob.setUpdateBy(SecurityUtils.getUsername()); | ||
| 91 | return toAjax(jobService.updateJob(sysJob)); | 103 | return toAjax(jobService.updateJob(sysJob)); |
| 92 | } | 104 | } |
| 93 | 105 |