| | |
| | | import jakarta.servlet.http.HttpServletResponse;
|
| | | import lombok.AllArgsConstructor;
|
| | | import org.quartz.SchedulerException;
|
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | | import org.springframework.security.access.prepost.PreAuthorize;
|
| | | import org.springframework.web.bind.annotation.DeleteMapping;
|
| | | import org.springframework.web.bind.annotation.GetMapping;
|
| | |
| | | import com.ruoyi.framework.aspectj.lang.annotation.Log;
|
| | | import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
|
| | | import com.ruoyi.framework.web.controller.BaseController;
|
| | | import com.ruoyi.framework.web.domain.AjaxResult;
|
| | | import com.ruoyi.framework.web.domain.R; |
| | | import com.ruoyi.framework.web.page.TableDataInfo;
|
| | | import com.ruoyi.project.monitor.domain.SysJob;
|
| | | import com.ruoyi.project.monitor.service.ISysJobService;
|
| | |
| | | */
|
| | | @PreAuthorize("@ss.hasPermi('monitor:job:query')")
|
| | | @GetMapping(value = "/{jobId}")
|
| | | public AjaxResult getInfo(@PathVariable("jobId") Long jobId)
|
| | | public R<?> getInfo(@PathVariable("jobId") Long jobId) |
| | | {
|
| | | return success(jobService.selectJobById(jobId));
|
| | | return R.ok(jobService.selectJobById(jobId)); |
| | | }
|
| | |
|
| | | /**
|
| | |
| | | @PreAuthorize("@ss.hasPermi('monitor:job:add')")
|
| | | @Log(title = "定时任务", businessType = BusinessType.INSERT)
|
| | | @PostMapping
|
| | | public AjaxResult add(@RequestBody SysJob job) throws SchedulerException, TaskException
|
| | | public R<?> add(@RequestBody SysJob job) throws SchedulerException, TaskException |
| | | {
|
| | | if (!CronUtils.isValid(job.getCronExpression()))
|
| | | {
|
| | | return error("新增任务'" + job.getJobName() + "'失败,Cron表达式不正确");
|
| | | return R.fail("新增任务'" + job.getJobName() + "'失败,Cron表达式不正确"); |
| | | }
|
| | | else if (StringUtils.containsIgnoreCase(job.getInvokeTarget(), Constants.LOOKUP_RMI))
|
| | | {
|
| | | return error("新增任务'" + job.getJobName() + "'失败,目标字符串不允许'rmi'调用");
|
| | | return R.fail("新增任务'" + job.getJobName() + "'失败,目标字符串不允许'rmi'调用"); |
| | | }
|
| | | else if (StringUtils.containsAnyIgnoreCase(job.getInvokeTarget(), new String[] { Constants.LOOKUP_LDAP, Constants.LOOKUP_LDAPS }))
|
| | | {
|
| | | return error("新增任务'" + job.getJobName() + "'失败,目标字符串不允许'ldap(s)'调用");
|
| | | return R.fail("新增任务'" + job.getJobName() + "'失败,目标字符串不允许'ldap(s)'调用"); |
| | | }
|
| | | else if (StringUtils.containsAnyIgnoreCase(job.getInvokeTarget(), new String[] { Constants.HTTP, Constants.HTTPS }))
|
| | | {
|
| | | return error("新增任务'" + job.getJobName() + "'失败,目标字符串不允许'http(s)'调用");
|
| | | return R.fail("新增任务'" + job.getJobName() + "'失败,目标字符串不允许'http(s)'调用"); |
| | | }
|
| | | else if (StringUtils.containsAnyIgnoreCase(job.getInvokeTarget(), Constants.JOB_ERROR_STR))
|
| | | {
|
| | | return error("新增任务'" + job.getJobName() + "'失败,目标字符串存在违规");
|
| | | return R.fail("新增任务'" + job.getJobName() + "'失败,目标字符串存在违规"); |
| | | }
|
| | | else if (!ScheduleUtils.whiteList(job.getInvokeTarget()))
|
| | | {
|
| | | return error("新增任务'" + job.getJobName() + "'失败,目标字符串不在白名单内");
|
| | | return R.fail("新增任务'" + job.getJobName() + "'失败,目标字符串不在白名单内"); |
| | | }
|
| | | job.setCreateBy(getUsername());
|
| | | return toAjax(jobService.insertJob(job));
|
| | | jobService.insertJob(job); |
| | | return R.ok(); |
| | | }
|
| | |
|
| | | /**
|
| | |
| | | @PreAuthorize("@ss.hasPermi('monitor:job:edit')")
|
| | | @Log(title = "定时任务", businessType = BusinessType.UPDATE)
|
| | | @PutMapping
|
| | | public AjaxResult edit(@RequestBody SysJob job) throws SchedulerException, TaskException
|
| | | public R<?> edit(@RequestBody SysJob job) throws SchedulerException, TaskException |
| | | {
|
| | | if (!CronUtils.isValid(job.getCronExpression()))
|
| | | {
|
| | | return error("修改任务'" + job.getJobName() + "'失败,Cron表达式不正确");
|
| | | return R.fail("修改任务'" + job.getJobName() + "'失败,Cron表达式不正确"); |
| | | }
|
| | | else if (StringUtils.containsIgnoreCase(job.getInvokeTarget(), Constants.LOOKUP_RMI))
|
| | | {
|
| | | return error("修改任务'" + job.getJobName() + "'失败,目标字符串不允许'rmi'调用");
|
| | | return R.fail("修改任务'" + job.getJobName() + "'失败,目标字符串不允许'rmi'调用"); |
| | | }
|
| | | else if (StringUtils.containsAnyIgnoreCase(job.getInvokeTarget(), new String[] { Constants.LOOKUP_LDAP, Constants.LOOKUP_LDAPS }))
|
| | | {
|
| | | return error("修改任务'" + job.getJobName() + "'失败,目标字符串不允许'ldap(s)'调用");
|
| | | return R.fail("修改任务'" + job.getJobName() + "'失败,目标字符串不允许'ldap(s)'调用"); |
| | | }
|
| | | else if (StringUtils.containsAnyIgnoreCase(job.getInvokeTarget(), new String[] { Constants.HTTP, Constants.HTTPS }))
|
| | | {
|
| | | return error("修改任务'" + job.getJobName() + "'失败,目标字符串不允许'http(s)'调用");
|
| | | return R.fail("修改任务'" + job.getJobName() + "'失败,目标字符串不允许'http(s)'调用"); |
| | | }
|
| | | else if (StringUtils.containsAnyIgnoreCase(job.getInvokeTarget(), Constants.JOB_ERROR_STR))
|
| | | {
|
| | | return error("修改任务'" + job.getJobName() + "'失败,目标字符串存在违规");
|
| | | return R.fail("修改任务'" + job.getJobName() + "'失败,目标字符串存在违规"); |
| | | }
|
| | | else if (!ScheduleUtils.whiteList(job.getInvokeTarget()))
|
| | | {
|
| | | return error("修改任务'" + job.getJobName() + "'失败,目标字符串不在白名单内");
|
| | | return R.fail("修改任务'" + job.getJobName() + "'失败,目标字符串不在白名单内"); |
| | | }
|
| | | job.setUpdateBy(getUsername());
|
| | | return toAjax(jobService.updateJob(job));
|
| | | jobService.updateJob(job); |
| | | return R.ok(); |
| | | }
|
| | |
|
| | | /**
|
| | |
| | | @PreAuthorize("@ss.hasPermi('monitor:job:changeStatus')")
|
| | | @Log(title = "定时任务", businessType = BusinessType.UPDATE)
|
| | | @PutMapping("/changeStatus")
|
| | | public AjaxResult changeStatus(@RequestBody SysJob job) throws SchedulerException
|
| | | public R<?> changeStatus(@RequestBody SysJob job) throws SchedulerException |
| | | {
|
| | | SysJob newJob = jobService.selectJobById(job.getJobId());
|
| | | newJob.setStatus(job.getStatus());
|
| | | return toAjax(jobService.changeStatus(newJob));
|
| | | jobService.changeStatus(newJob); |
| | | return R.ok(); |
| | | }
|
| | |
|
| | | /**
|
| | |
| | | @PreAuthorize("@ss.hasPermi('monitor:job:changeStatus')")
|
| | | @Log(title = "定时任务", businessType = BusinessType.UPDATE)
|
| | | @PutMapping("/run")
|
| | | public AjaxResult run(@RequestBody SysJob job) throws SchedulerException
|
| | | public R<?> run(@RequestBody SysJob job) throws SchedulerException |
| | | {
|
| | | boolean result = jobService.run(job);
|
| | | return result ? success() : error("任务不存在或已过期!");
|
| | | return result ? R.ok() : R.fail("任务不存在或已过期!"); |
| | | }
|
| | |
|
| | | /**
|
| | |
| | | @PreAuthorize("@ss.hasPermi('monitor:job:remove')")
|
| | | @Log(title = "定时任务", businessType = BusinessType.DELETE)
|
| | | @DeleteMapping("/{jobIds}")
|
| | | public AjaxResult remove(@PathVariable Long[] jobIds) throws SchedulerException
|
| | | public R<?> remove(@PathVariable Long[] jobIds) throws SchedulerException |
| | | {
|
| | | jobService.deleteJobByIds(jobIds);
|
| | | return success();
|
| | | return R.ok(); |
| | | }
|
| | | }
|