xiangpei
2025-04-18 ccadf9480d4e6a9dcc227a2a0b1f9ae0612e36fd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package com.monkeylessey.job.controller;
 
import com.monkeylessey.group.Add;
import com.monkeylessey.group.Update;
import com.monkeylessey.job.domain.form.SysJobForm;
import com.monkeylessey.job.domain.query.SysJobQuery;
import com.monkeylessey.job.service.SysJobService;
import com.monkeylessey.response.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
 
import java.util.List;
 
/**
 * 定时任务表 前端控制器
 *
 * @author 向培
 * @since 2022-06-08
 */
@Validated
@RequiredArgsConstructor
@Api(value = "定时任务表", tags = "定时任务表")
@RestController
@RequestMapping("/sys-job")
public class SysJobController {
 
    private final SysJobService sysJobService;
 
    @PostMapping("/execute/once")
    @PreAuthorize("hasAuthority('job:once')")
    @ApiOperation(value = "执行一次", notes = "执行一次")
    public Result executeJobOnce(@RequestBody @Validated(Update.class) SysJobForm form) {
        return sysJobService.executeJobOnce(form);
    }
 
    @PostMapping("/pause/job")
    @PreAuthorize("hasAuthority('job:pause')")
    @ApiOperation(value = "暂停任务", notes = "暂停任务")
    public Result pauseJob(@RequestBody @Validated(Update.class) SysJobForm form) {
        return sysJobService.pauseJob(form);
    }
 
    @PostMapping("/start/job")
    @PreAuthorize("hasAuthority('job:run')")
    @ApiOperation(value = "启动任务", notes = "启动任务")
    public Result startJob(@RequestBody @Validated(Update.class) SysJobForm form) {
        return sysJobService.startJob(form);
    }
 
    @PostMapping("/")
    @PreAuthorize("hasAuthority('job:add')")
    @ApiOperation(value = "添加定时任务", notes = "添加定时任务")
    public Result addSysJob(@RequestBody @Validated(Add.class) SysJobForm form) {
        return sysJobService.addSysJob(form);
    }
 
    @PutMapping("/")
    @PreAuthorize("hasAuthority('job:edit')")
    @ApiOperation(value = "修改定时任务", notes = "修改定时任务")
    public Result editSysJob(@RequestBody @Validated(Update.class) SysJobForm form) {
        return sysJobService.editSysJob(form);
    }
 
    @DeleteMapping("/{id}")
    @PreAuthorize("hasAuthority('job:del')")
    @ApiOperation(value = "删除定时任务", notes = "删除定时任务")
    public Result deleteSysJob(@PathVariable("id") String id) {
        return sysJobService.deleteSysJobById(id);
    }
 
    @DeleteMapping("/batch")
    @PreAuthorize("hasAuthority('job:del:batch')")
    @ApiOperation(value = "批量删除定时任务", notes = "批量删除定时任务")
    public Result deleteSysJobByIds(@RequestBody List<String> ids) {
        return sysJobService.deleteSysJobByIds(ids);
    }
 
    @GetMapping("/page")
    @PreAuthorize("hasAuthority('job:page')")
    @ApiOperation(value = "定时任务分页", notes = "定时任务分页")
    public Result getSysJobPage(SysJobQuery query) {
        return sysJobService.getSysJobByPage(query);
    }
 
    @GetMapping("/{id}")
    @PreAuthorize("hasAuthority('job:detail')")
    @ApiOperation(value = "id查找", notes = "id查找")
    public Result getSysJobPage(@PathVariable("id") String id) {
        return sysJobService.getSysJobById(id);
    }
}