提交 | 用户 | 时间
|
516ef4
|
1 |
package com.iailab.module.shasteel.job.controller.admin; |
L |
2 |
|
|
3 |
import com.iailab.framework.common.pojo.CommonResult; |
|
4 |
import com.iailab.framework.common.pojo.PageResult; |
|
5 |
import com.iailab.framework.common.util.object.BeanUtils; |
|
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.framework.tenant.core.context.TenantContextHolder; |
|
11 |
import com.iailab.module.shasteel.job.dto.ScheduleJobDTO; |
|
12 |
import com.iailab.module.shasteel.job.entity.ScheduleJobEntity; |
|
13 |
import com.iailab.module.shasteel.job.service.ScheduleJobService; |
|
14 |
import com.iailab.module.shasteel.job.vo.ScheduleJobReqVO; |
|
15 |
import io.swagger.v3.oas.annotations.Operation; |
|
16 |
import io.swagger.v3.oas.annotations.tags.Tag; |
|
17 |
import org.springframework.security.access.prepost.PreAuthorize; |
|
18 |
import org.springframework.validation.annotation.Validated; |
|
19 |
import org.springframework.web.bind.annotation.*; |
|
20 |
|
|
21 |
import javax.annotation.Resource; |
|
22 |
|
|
23 |
import static com.iailab.framework.common.pojo.CommonResult.success; |
|
24 |
|
|
25 |
/** |
|
26 |
* 定时任务 |
|
27 |
* |
|
28 |
* @author Mark sunlightcs@gmail.com |
|
29 |
*/ |
|
30 |
@RestController |
ccf754
|
31 |
@RequestMapping("/shasteel/job/schedule") |
516ef4
|
32 |
@Tag(name = "定时任务") |
L |
33 |
public class ScheduleJobController { |
|
34 |
@Resource |
|
35 |
private ScheduleJobService scheduleJobService; |
|
36 |
|
|
37 |
@GetMapping("page") |
|
38 |
@Operation(summary = "分页") |
ccf754
|
39 |
@PreAuthorize("@ss.hasPermission('shasteel:schedule:query')") |
516ef4
|
40 |
public CommonResult<PageResult<ScheduleJobDTO>> page(@Validated ScheduleJobReqVO reqVO){ |
L |
41 |
reqVO.setTenantId(TenantContextHolder.getTenantId()); |
|
42 |
PageResult<ScheduleJobEntity> page = scheduleJobService.page(reqVO); |
|
43 |
|
|
44 |
return success(BeanUtils.toBean(page, ScheduleJobDTO.class)); |
|
45 |
} |
|
46 |
|
|
47 |
@GetMapping("info") |
|
48 |
@Operation(summary = "信息") |
ccf754
|
49 |
@PreAuthorize("@ss.hasPermission('shasteel:schedule:query')") |
516ef4
|
50 |
public CommonResult<ScheduleJobDTO> info(@RequestParam("id") Long id){ |
L |
51 |
ScheduleJobDTO schedule = scheduleJobService.get(id); |
|
52 |
|
|
53 |
return new CommonResult<ScheduleJobDTO>().setData(schedule); |
|
54 |
} |
|
55 |
|
|
56 |
@PostMapping("/create") |
|
57 |
@Operation(summary = "保存") |
ccf754
|
58 |
@PreAuthorize("@ss.hasPermission('shasteel:schedule:create')") |
516ef4
|
59 |
public CommonResult save(@RequestBody ScheduleJobDTO dto){ |
L |
60 |
ValidationUtils.validate(dto, AddGroup.class, DefaultGroup.class); |
|
61 |
|
|
62 |
scheduleJobService.save(dto); |
|
63 |
|
|
64 |
return new CommonResult(); |
|
65 |
} |
|
66 |
|
|
67 |
@PutMapping("/update") |
|
68 |
@Operation(summary = "修改") |
ccf754
|
69 |
@PreAuthorize("@ss.hasPermission('shasteel:schedule:update')") |
516ef4
|
70 |
public CommonResult update(@RequestBody ScheduleJobDTO dto){ |
L |
71 |
ValidationUtils.validate(dto, UpdateGroup.class, DefaultGroup.class); |
|
72 |
|
|
73 |
scheduleJobService.update(dto); |
|
74 |
|
|
75 |
return new CommonResult(); |
|
76 |
} |
|
77 |
|
|
78 |
@DeleteMapping("/delete") |
|
79 |
@Operation(summary = "删除") |
ccf754
|
80 |
@PreAuthorize("@ss.hasPermission('shasteel:schedule:delete')") |
516ef4
|
81 |
public CommonResult delete(@RequestParam("id") Long id){ |
L |
82 |
scheduleJobService.deleteBatch(id); |
|
83 |
|
|
84 |
return new CommonResult(); |
|
85 |
} |
|
86 |
|
|
87 |
@PutMapping("/run") |
|
88 |
@Operation(summary = "立即执行") |
|
89 |
public CommonResult run(@RequestParam("id") Long id){ |
|
90 |
Long[] ids = new Long[1]; |
|
91 |
ids[0] = id; |
|
92 |
scheduleJobService.run(ids); |
|
93 |
|
|
94 |
return new CommonResult(); |
|
95 |
} |
|
96 |
|
|
97 |
@PutMapping("/pause") |
|
98 |
@Operation(summary = "暂停") |
|
99 |
public CommonResult pause(@RequestParam("id") Long id){ |
|
100 |
Long[] ids = new Long[1]; |
|
101 |
ids[0] = id; |
|
102 |
scheduleJobService.pause(ids); |
|
103 |
|
|
104 |
return new CommonResult(); |
|
105 |
} |
|
106 |
|
|
107 |
@PutMapping("/resume") |
|
108 |
@Operation(summary = "恢复") |
|
109 |
public CommonResult resume(@RequestParam("id") Long id){ |
|
110 |
Long[] ids = new Long[1]; |
|
111 |
ids[0] = id; |
|
112 |
scheduleJobService.resume(ids); |
|
113 |
|
|
114 |
return new CommonResult(); |
|
115 |
} |
|
116 |
|
|
117 |
} |