潘志宝
2024-08-20 92d87eda945d68346475e6766673a3cdccf3d41c
提交 | 用户 | 时间
a6de49 1 package com.iailab.module.job.controller;
H 2
3 import com.iailab.framework.common.page.PageData;
4 import com.iailab.common.utils.Constant;
5 import com.iailab.framework.common.pojo.CommonResult;
6 import com.iailab.framework.common.util.validation.ValidationUtils;
7 import com.iailab.framework.common.validation.group.AddGroup;
8 import com.iailab.framework.common.validation.group.DefaultGroup;
9 import com.iailab.framework.common.validation.group.UpdateGroup;
10 import com.iailab.module.job.dto.ScheduleJobDTO;
11 import com.iailab.module.job.service.ScheduleJobService;
12 import io.swagger.v3.oas.annotations.tags.Tag;
13 import io.swagger.v3.oas.annotations.Operation;
14 import io.swagger.v3.oas.annotations.Parameter;
15 import io.swagger.v3.oas.annotations.Parameters;
16 import javax.annotation.Resource;
17 import org.springframework.security.access.prepost.PreAuthorize;
18 import org.springframework.web.bind.annotation.*;
19
20
21 import java.util.Map;
22
23 /**
24  * 定时任务
25  *
26  * @author Mark sunlightcs@gmail.com
27  */
28 @RestController
29 @RequestMapping("mcs/schedule")
30 @Tag(name = "定时任务")
31 public class ScheduleJobController {
32     @Resource
33     private ScheduleJobService scheduleJobService;
34
35     @GetMapping("page")
36     @Operation(summary = "分页")
37     @Parameters({
38         @Parameter(name = Constant.PAGE, description = "当前页码,从1开始", required = true) ,
39         @Parameter(name = Constant.LIMIT, description = "每页显示记录数", required = true) ,
40         @Parameter(name = Constant.ORDER_FIELD, description = "排序字段") ,
41         @Parameter(name = Constant.ORDER, description = "排序方式,可选值(asc、desc)") ,
42         @Parameter(name = "beanName", description = "beanName")
43     })
44     public CommonResult<PageData<ScheduleJobDTO>> page(@RequestParam Map<String, Object> params){
45         PageData<ScheduleJobDTO> page = scheduleJobService.page(params);
46
47         return new CommonResult<PageData<ScheduleJobDTO>>().setData(page);
48     }
49
50     @GetMapping("{id}")
51     @Operation(summary = "信息")
52     public CommonResult<ScheduleJobDTO> info(@PathVariable("id") Long id){
53         ScheduleJobDTO schedule = scheduleJobService.get(id);
54         
55         return new CommonResult<ScheduleJobDTO>().setData(schedule);
56     }
57
58     @PostMapping
59     @Operation(summary = "保存")
60     @PreAuthorize("@ss.hasPermission('mcs:schedule:save')")
61     public CommonResult save(@RequestBody ScheduleJobDTO dto){
62         ValidationUtils.validate(dto, AddGroup.class, DefaultGroup.class);
63         
64         scheduleJobService.save(dto);
65         
66         return new CommonResult();
67     }
68
69     @PutMapping
70     @Operation(summary = "修改")
71     @PreAuthorize("@ss.hasPermission('mcs:schedule:update')")
72     public CommonResult update(@RequestBody ScheduleJobDTO dto){
73         ValidationUtils.validate(dto, UpdateGroup.class, DefaultGroup.class);
74                 
75         scheduleJobService.update(dto);
76         
77         return new CommonResult();
78     }
79
80     @DeleteMapping
81     @Operation(summary = "删除")
82     @PreAuthorize("@ss.hasPermission('mcs:schedule:delete')")
83     public CommonResult delete(@RequestBody Long[] ids){
84         scheduleJobService.deleteBatch(ids);
85         
86         return new CommonResult();
87     }
88
89     @PutMapping("/run")
90     @Operation(summary = "立即执行")
91     @PreAuthorize("@ss.hasPermission('mcs:schedule:run')")
92     public CommonResult run(@RequestBody Long[] ids){
93         scheduleJobService.run(ids);
94         
95         return new CommonResult();
96     }
97
98     @PutMapping("/pause")
99     @Operation(summary = "暂停")
100     @PreAuthorize("@ss.hasPermission('mcs:schedule:pause')")
101     public CommonResult pause(@RequestBody Long[] ids){
102         scheduleJobService.pause(ids);
103         
104         return new CommonResult();
105     }
106
107     @PutMapping("/resume")
108     @Operation(summary = "恢复")
109     @PreAuthorize("@ss.hasPermission('mcs:schedule:resume')")
110     public CommonResult resume(@RequestBody Long[] ids){
111         scheduleJobService.resume(ids);
112         return new CommonResult();
113     }
114
115 }