| | |
| | | package com.ruoyi.project.monitor.controller;
|
| | |
|
| | | import java.util.List;
|
| | | import javax.servlet.http.HttpServletResponse;
|
| | | import org.quartz.SchedulerException;
|
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | | import org.springframework.security.access.prepost.PreAuthorize;
|
| | |
| | | import org.springframework.web.bind.annotation.RestController;
|
| | | import com.ruoyi.common.constant.Constants;
|
| | | import com.ruoyi.common.exception.job.TaskException;
|
| | | import com.ruoyi.common.utils.SecurityUtils;
|
| | | import com.ruoyi.common.utils.StringUtils;
|
| | | import com.ruoyi.common.utils.job.CronUtils;
|
| | | import com.ruoyi.common.utils.job.ScheduleUtils;
|
| | | import com.ruoyi.common.utils.poi.ExcelUtil;
|
| | | import com.ruoyi.framework.aspectj.lang.annotation.Log;
|
| | | import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
|
| | |
| | | */
|
| | | @PreAuthorize("@ss.hasPermi('monitor:job:export')")
|
| | | @Log(title = "定时任务", businessType = BusinessType.EXPORT)
|
| | | @GetMapping("/export")
|
| | | public AjaxResult export(SysJob sysJob)
|
| | | @PostMapping("/export")
|
| | | public void export(HttpServletResponse response, SysJob sysJob)
|
| | | {
|
| | | List<SysJob> list = jobService.selectJobList(sysJob);
|
| | | ExcelUtil<SysJob> util = new ExcelUtil<SysJob>(SysJob.class);
|
| | | return util.exportExcel(list, "定时任务");
|
| | | util.exportExcel(response, list, "定时任务");
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | @GetMapping(value = "/{jobId}")
|
| | | public AjaxResult getInfo(@PathVariable("jobId") Long jobId)
|
| | | {
|
| | | return AjaxResult.success(jobService.selectJobById(jobId));
|
| | | return success(jobService.selectJobById(jobId));
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | }
|
| | | else if (StringUtils.containsIgnoreCase(job.getInvokeTarget(), Constants.LOOKUP_RMI))
|
| | | {
|
| | | return error("新增任务'" + job.getJobName() + "'失败,目标字符串不允许'rmi://'调用");
|
| | | return error("新增任务'" + job.getJobName() + "'失败,目标字符串不允许'rmi'调用");
|
| | | }
|
| | | else if (StringUtils.containsAnyIgnoreCase(job.getInvokeTarget(), new String[] { Constants.LOOKUP_LDAP, Constants.LOOKUP_LDAPS }))
|
| | | {
|
| | | return error("新增任务'" + job.getJobName() + "'失败,目标字符串不允许'ldap(s)'调用");
|
| | | }
|
| | | else if (StringUtils.containsAnyIgnoreCase(job.getInvokeTarget(), new String[] { Constants.HTTP, Constants.HTTPS }))
|
| | | {
|
| | | return error("新增任务'" + job.getJobName() + "'失败,目标字符串不允许'http(s)//'调用");
|
| | | return error("新增任务'" + job.getJobName() + "'失败,目标字符串不允许'http(s)'调用");
|
| | | }
|
| | | job.setCreateBy(SecurityUtils.getUsername());
|
| | | else if (StringUtils.containsAnyIgnoreCase(job.getInvokeTarget(), Constants.JOB_ERROR_STR))
|
| | | {
|
| | | return error("新增任务'" + job.getJobName() + "'失败,目标字符串存在违规");
|
| | | }
|
| | | else if (!ScheduleUtils.whiteList(job.getInvokeTarget()))
|
| | | {
|
| | | return error("新增任务'" + job.getJobName() + "'失败,目标字符串不在白名单内");
|
| | | }
|
| | | job.setCreateBy(getUsername());
|
| | | return toAjax(jobService.insertJob(job));
|
| | | }
|
| | |
|
| | |
| | | }
|
| | | else if (StringUtils.containsIgnoreCase(job.getInvokeTarget(), Constants.LOOKUP_RMI))
|
| | | {
|
| | | return error("修改任务'" + job.getJobName() + "'失败,目标字符串不允许'rmi://'调用");
|
| | | return error("修改任务'" + job.getJobName() + "'失败,目标字符串不允许'rmi'调用");
|
| | | }
|
| | | else if (StringUtils.containsAnyIgnoreCase(job.getInvokeTarget(), new String[] { Constants.LOOKUP_LDAP, Constants.LOOKUP_LDAPS }))
|
| | | {
|
| | | return error("修改任务'" + job.getJobName() + "'失败,目标字符串不允许'ldap(s)'调用");
|
| | | }
|
| | | else if (StringUtils.containsAnyIgnoreCase(job.getInvokeTarget(), new String[] { Constants.HTTP, Constants.HTTPS }))
|
| | | {
|
| | | return error("修改任务'" + job.getJobName() + "'失败,目标字符串不允许'http(s)//'调用");
|
| | | return error("修改任务'" + job.getJobName() + "'失败,目标字符串不允许'http(s)'调用");
|
| | | }
|
| | | job.setUpdateBy(SecurityUtils.getUsername());
|
| | | else if (StringUtils.containsAnyIgnoreCase(job.getInvokeTarget(), Constants.JOB_ERROR_STR))
|
| | | {
|
| | | return error("修改任务'" + job.getJobName() + "'失败,目标字符串存在违规");
|
| | | }
|
| | | else if (!ScheduleUtils.whiteList(job.getInvokeTarget()))
|
| | | {
|
| | | return error("修改任务'" + job.getJobName() + "'失败,目标字符串不在白名单内");
|
| | | }
|
| | | job.setUpdateBy(getUsername());
|
| | | return toAjax(jobService.updateJob(job));
|
| | | }
|
| | |
|
| | |
| | | @PutMapping("/run")
|
| | | public AjaxResult run(@RequestBody SysJob job) throws SchedulerException
|
| | | {
|
| | | jobService.run(job);
|
| | | return AjaxResult.success();
|
| | | boolean result = jobService.run(job);
|
| | | return result ? success() : error("任务不存在或已过期!");
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | public AjaxResult remove(@PathVariable Long[] jobIds) throws SchedulerException, TaskException
|
| | | {
|
| | | jobService.deleteJobByIds(jobIds);
|
| | | return AjaxResult.success();
|
| | | return success();
|
| | | }
|
| | | }
|