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