Browse Source

定时任务cron表达式验证

tags/v2.1
RuoYi 4 years ago
parent
commit
59b8df2e90
  1. 10
      ruoyi-common/ruoyi-common-log/src/main/java/com/ruoyi/common/log/aspect/LogAspect.java
  2. 12
      ruoyi-modules/ruoyi-job/src/main/java/com/ruoyi/job/controller/SysJobController.java

10
ruoyi-common/ruoyi-common-log/src/main/java/com/ruoyi/common/log/aspect/LogAspect.java

@ -198,8 +198,14 @@ public class LogAspect @@ -198,8 +198,14 @@ public class LogAspect
{
if (!isFilterObject(paramsArray[i]))
{
Object jsonObj = JSON.toJSON(paramsArray[i]);
params += jsonObj.toString() + " ";
try
{
Object jsonObj = JSON.toJSON(paramsArray[i]);
params += jsonObj.toString() + " ";
}
catch (Exception e)
{
}
}
}
}

12
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,8 +21,10 @@ import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.job.domain.SysJob;
import com.ruoyi.job.service.ISysJobService;
import com.ruoyi.job.util.CronUtils;
/**
* 调度任务信息操作处理
@ -79,6 +81,11 @@ public class SysJobController extends BaseController @@ -79,6 +81,11 @@ public class SysJobController extends BaseController
@PostMapping
public AjaxResult add(@RequestBody SysJob sysJob) throws SchedulerException, TaskException
{
if (!CronUtils.isValid(sysJob.getCronExpression()))
{
return AjaxResult.error("cron表达式不正确");
}
sysJob.setCreateBy(SecurityUtils.getUsername());
return toAjax(jobService.insertJob(sysJob));
}
@ -90,6 +97,11 @@ public class SysJobController extends BaseController @@ -90,6 +97,11 @@ public class SysJobController extends BaseController
@PutMapping
public AjaxResult edit(@RequestBody SysJob sysJob) throws SchedulerException, TaskException
{
if (!CronUtils.isValid(sysJob.getCronExpression()))
{
return AjaxResult.error("cron表达式不正确");
}
sysJob.setUpdateBy(SecurityUtils.getUsername());
return toAjax(jobService.updateJob(sysJob));
}

Loading…
Cancel
Save