春风项目四线(合箱线、总装线)
yyt
2024-06-29 c9745dfbbd9f64b1b84574446ab93f32a76896fe
提交 | 用户 | 时间
fd2207 1 package com.jcdm.quartz.controller;
2
3 import java.util.List;
4 import javax.servlet.http.HttpServletResponse;
5 import org.quartz.SchedulerException;
6 import org.springframework.beans.factory.annotation.Autowired;
7 import org.springframework.security.access.prepost.PreAuthorize;
8 import org.springframework.web.bind.annotation.DeleteMapping;
9 import org.springframework.web.bind.annotation.GetMapping;
10 import org.springframework.web.bind.annotation.PathVariable;
11 import org.springframework.web.bind.annotation.PostMapping;
12 import org.springframework.web.bind.annotation.PutMapping;
13 import org.springframework.web.bind.annotation.RequestBody;
14 import org.springframework.web.bind.annotation.RequestMapping;
15 import org.springframework.web.bind.annotation.RestController;
16 import com.jcdm.common.annotation.Log;
17 import com.jcdm.common.constant.Constants;
18 import com.jcdm.common.core.controller.BaseController;
19 import com.jcdm.common.core.domain.AjaxResult;
20 import com.jcdm.common.core.page.TableDataInfo;
21 import com.jcdm.common.enums.BusinessType;
22 import com.jcdm.common.exception.job.TaskException;
23 import com.jcdm.common.utils.StringUtils;
24 import com.jcdm.common.utils.poi.ExcelUtil;
25 import com.jcdm.quartz.domain.SysJob;
26 import com.jcdm.quartz.service.ISysJobService;
27 import com.jcdm.quartz.util.CronUtils;
28 import com.jcdm.quartz.util.ScheduleUtils;
29
30 /**
31  * 调度任务信息操作处理
32  * 
33  * @author jc
34  */
35 @RestController
36 @RequestMapping("/monitor/job")
37 public class SysJobController extends BaseController
38 {
39     @Autowired
40     private ISysJobService jobService;
41
42     /**
43      * 查询定时任务列表
44      */
45     @PreAuthorize("@ss.hasPermi('monitor:job:list')")
46     @GetMapping("/list")
47     public TableDataInfo list(SysJob sysJob)
48     {
49         startPage();
50         List<SysJob> list = jobService.selectJobList(sysJob);
51         return getDataTable(list);
52     }
53
54     /**
55      * 导出定时任务列表
56      */
57     @PreAuthorize("@ss.hasPermi('monitor:job:export')")
58     @Log(title = "定时任务", businessType = BusinessType.EXPORT)
59     @PostMapping("/export")
60     public void export(HttpServletResponse response, SysJob sysJob)
61     {
62         List<SysJob> list = jobService.selectJobList(sysJob);
63         ExcelUtil<SysJob> util = new ExcelUtil<SysJob>(SysJob.class);
64         util.exportExcel(response, list, "定时任务");
65     }
66
67     /**
68      * 获取定时任务详细信息
69      */
70     @PreAuthorize("@ss.hasPermi('monitor:job:query')")
71     @GetMapping(value = "/{jobId}")
72     public AjaxResult getInfo(@PathVariable("jobId") Long jobId)
73     {
74         return success(jobService.selectJobById(jobId));
75     }
76
77     /**
78      * 新增定时任务
79      */
80     @PreAuthorize("@ss.hasPermi('monitor:job:add')")
81     @Log(title = "定时任务", businessType = BusinessType.INSERT)
82     @PostMapping
83     public AjaxResult add(@RequestBody SysJob job) throws SchedulerException, TaskException
84     {
85         if (!CronUtils.isValid(job.getCronExpression()))
86         {
87             return error("新增任务'" + job.getJobName() + "'失败,Cron表达式不正确");
88         }
89         else if (StringUtils.containsIgnoreCase(job.getInvokeTarget(), Constants.LOOKUP_RMI))
90         {
91             return error("新增任务'" + job.getJobName() + "'失败,目标字符串不允许'rmi'调用");
92         }
93         else if (StringUtils.containsAnyIgnoreCase(job.getInvokeTarget(), new String[] { Constants.LOOKUP_LDAP, Constants.LOOKUP_LDAPS }))
94         {
95             return error("新增任务'" + job.getJobName() + "'失败,目标字符串不允许'ldap(s)'调用");
96         }
97         else if (StringUtils.containsAnyIgnoreCase(job.getInvokeTarget(), new String[] { Constants.HTTP, Constants.HTTPS }))
98         {
99             return error("新增任务'" + job.getJobName() + "'失败,目标字符串不允许'http(s)'调用");
100         }
101         else if (StringUtils.containsAnyIgnoreCase(job.getInvokeTarget(), Constants.JOB_ERROR_STR))
102         {
103             return error("新增任务'" + job.getJobName() + "'失败,目标字符串存在违规");
104         }
105         else if (!ScheduleUtils.whiteList(job.getInvokeTarget()))
106         {
107             return error("新增任务'" + job.getJobName() + "'失败,目标字符串不在白名单内");
108         }
109         job.setCreateBy(getUsername());
110         return toAjax(jobService.insertJob(job));
111     }
112
113     /**
114      * 修改定时任务
115      */
116     @PreAuthorize("@ss.hasPermi('monitor:job:edit')")
117     @Log(title = "定时任务", businessType = BusinessType.UPDATE)
118     @PutMapping
119     public AjaxResult edit(@RequestBody SysJob job) throws SchedulerException, TaskException
120     {
121         if (!CronUtils.isValid(job.getCronExpression()))
122         {
123             return error("修改任务'" + job.getJobName() + "'失败,Cron表达式不正确");
124         }
125         else if (StringUtils.containsIgnoreCase(job.getInvokeTarget(), Constants.LOOKUP_RMI))
126         {
127             return error("修改任务'" + job.getJobName() + "'失败,目标字符串不允许'rmi'调用");
128         }
129         else if (StringUtils.containsAnyIgnoreCase(job.getInvokeTarget(), new String[] { Constants.LOOKUP_LDAP, Constants.LOOKUP_LDAPS }))
130         {
131             return error("修改任务'" + job.getJobName() + "'失败,目标字符串不允许'ldap(s)'调用");
132         }
133         else if (StringUtils.containsAnyIgnoreCase(job.getInvokeTarget(), new String[] { Constants.HTTP, Constants.HTTPS }))
134         {
135             return error("修改任务'" + job.getJobName() + "'失败,目标字符串不允许'http(s)'调用");
136         }
137         else if (StringUtils.containsAnyIgnoreCase(job.getInvokeTarget(), Constants.JOB_ERROR_STR))
138         {
139             return error("修改任务'" + job.getJobName() + "'失败,目标字符串存在违规");
140         }
141         else if (!ScheduleUtils.whiteList(job.getInvokeTarget()))
142         {
143             return error("修改任务'" + job.getJobName() + "'失败,目标字符串不在白名单内");
144         }
145         job.setUpdateBy(getUsername());
146         return toAjax(jobService.updateJob(job));
147     }
148
149     /**
150      * 定时任务状态修改
151      */
152     @PreAuthorize("@ss.hasPermi('monitor:job:changeStatus')")
153     @Log(title = "定时任务", businessType = BusinessType.UPDATE)
154     @PutMapping("/changeStatus")
155     public AjaxResult changeStatus(@RequestBody SysJob job) throws SchedulerException
156     {
157         SysJob newJob = jobService.selectJobById(job.getJobId());
158         newJob.setStatus(job.getStatus());
159         return toAjax(jobService.changeStatus(newJob));
160     }
161
162     /**
163      * 定时任务立即执行一次
164      */
165     @PreAuthorize("@ss.hasPermi('monitor:job:changeStatus')")
166     @Log(title = "定时任务", businessType = BusinessType.UPDATE)
167     @PutMapping("/run")
168     public AjaxResult run(@RequestBody SysJob job) throws SchedulerException
169     {
170         boolean result = jobService.run(job);
171         return result ? success() : error("任务不存在或已过期!");
172     }
173
174     /**
175      * 删除定时任务
176      */
177     @PreAuthorize("@ss.hasPermi('monitor:job:remove')")
178     @Log(title = "定时任务", businessType = BusinessType.DELETE)
179     @DeleteMapping("/{jobIds}")
180     public AjaxResult remove(@PathVariable Long[] jobIds) throws SchedulerException, TaskException
181     {
182         jobService.deleteJobByIds(jobIds);
183         return success();
184     }
185 }