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