|
@@ -7,6 +7,7 @@ import com.sky.ioc.tool.ReturnMsg;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.quartz.SchedulerException;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
@@ -32,24 +33,6 @@ public class QuartzJobController {
|
|
|
return ReturnMsg.ok("创建定时任务成功");
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 通过id删除
|
|
|
- *
|
|
|
- * @param id
|
|
|
- * @return
|
|
|
- */
|
|
|
- @ApiOperation("删除定时任务")
|
|
|
- @PostMapping(value = "/deljob")
|
|
|
- public ReturnMsg<?> delete(@RequestParam(name = "id", required = true) String id) {
|
|
|
- QuartzJob quartzJob = quartzJobService.getById(id);
|
|
|
- if (quartzJob == null) {
|
|
|
- return ReturnMsg.fail("未找到对应实体");
|
|
|
- }
|
|
|
- quartzJobService.deleteAndStopJob(quartzJob);
|
|
|
- return ReturnMsg.ok("删除成功!");
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
|
|
|
@ApiOperation("定时任务列表")
|
|
|
@GetMapping(value = "/getJobList")
|
|
@@ -61,4 +44,61 @@ public class QuartzJobController {
|
|
|
return quartzJobService.pageList(name,groupName,status,pageStart,pageSize);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ @ApiOperation("编辑定时任务")
|
|
|
+ @PostMapping(value = "/editJob")
|
|
|
+ public ReturnMsg<?> editJob(@RequestBody QuartzJob quartzJob) {
|
|
|
+ // QuartzJob quartzJob = quartzJobService.getById(id);
|
|
|
+ if (quartzJob == null) {
|
|
|
+ return ReturnMsg.fail("未找到对应实体");
|
|
|
+ }else {
|
|
|
+ try {
|
|
|
+ quartzJobService.editAndScheduleJob(quartzJob);
|
|
|
+ return ReturnMsg.ok("操作成功!");
|
|
|
+ } catch (SchedulerException e) {
|
|
|
+ // throw new RuntimeException(e);
|
|
|
+ return ReturnMsg.ok("失败!"+e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation("删除定时任务")
|
|
|
+ @PostMapping(value = "/deleteJob")
|
|
|
+ public ReturnMsg<?> deleteJob(@RequestParam(name = "id", required = true) Integer id) {
|
|
|
+ QuartzJob quartzJob = quartzJobService.getById(id);
|
|
|
+ if (quartzJob == null) {
|
|
|
+ return ReturnMsg.fail("未找到对应实体");
|
|
|
+ }else {
|
|
|
+ quartzJobService.deleteAndStopJob(quartzJob);
|
|
|
+ return ReturnMsg.ok("操作成功!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation("启动/停止定时任务")
|
|
|
+ @PostMapping(value = "/stopAndScheduleJob")
|
|
|
+ public ReturnMsg<?> stopAndScheduleJob(@RequestParam(name = "id", required = true) Integer id,
|
|
|
+ @RequestParam(name = "status", required = true) Integer status) {
|
|
|
+ QuartzJob quartzJob = quartzJobService.getById(id);
|
|
|
+ quartzJob.setStatus(status);
|
|
|
+ if (quartzJob == null) {
|
|
|
+ return ReturnMsg.fail("未找到对应实体");
|
|
|
+ }else {
|
|
|
+ if (status==0){
|
|
|
+ //启动
|
|
|
+ quartzJobService.resumeJob(quartzJob);
|
|
|
+ return ReturnMsg.ok("操作成功!");
|
|
|
+ }else{
|
|
|
+ //暂停
|
|
|
+ try {
|
|
|
+ quartzJobService.editAndScheduleJob(quartzJob);
|
|
|
+ return ReturnMsg.ok("操作成功!");
|
|
|
+ } catch (SchedulerException e) {
|
|
|
+ // throw new RuntimeException(e);
|
|
|
+ return ReturnMsg.ok("失败!"+e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|