QuartzController.java 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. package com.jiayue.ipfcst.console.controller;
  2. import com.jiayue.ipfcst.aop.SaveValidate;
  3. import com.jiayue.ipfcst.common.core.web.vo.ResponseVO;
  4. import com.jiayue.ipfcst.common.data.entity.Quartz;
  5. import com.jiayue.ipfcst.console.service.InitJobClassService;
  6. import com.jiayue.ipfcst.console.service.QuartzService;
  7. import com.jiayue.ipfcst.console.service.SysParameterService;
  8. import lombok.SneakyThrows;
  9. import lombok.extern.slf4j.Slf4j;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.web.bind.annotation.*;
  12. import java.util.Map;
  13. /**
  14. * 定时控制类
  15. *
  16. * @author bizy
  17. * @version 1.0
  18. * @since 2018/10/22 11:29
  19. */
  20. @RestController
  21. @Slf4j
  22. public class QuartzController {
  23. @Autowired
  24. QuartzService quartzService;
  25. @Autowired
  26. InitJobClassService initJobClassService;
  27. @Autowired
  28. SysParameterService sysParameterService;
  29. /**
  30. * 添加定时任务
  31. *
  32. * @param qt 定时任务对象
  33. * @return 状态bean
  34. */
  35. @SaveValidate
  36. @SneakyThrows
  37. @PostMapping(value = "quartzs")
  38. public ResponseVO addQuartz(@RequestBody final Quartz qt) {
  39. final Quartz quartz = quartzService.findByClass(qt.getExecuteClass());
  40. if (null != quartz) {
  41. return ResponseVO.fail("添加失败,任务已存在!");
  42. } else {
  43. final boolean flag = quartzService.save(qt);
  44. if (flag) {
  45. return ResponseVO.success("添加成功!");
  46. } else {
  47. return ResponseVO.fail("添加失败!");
  48. }
  49. }
  50. }
  51. /**
  52. * 修改定时任务状态
  53. *
  54. * @param qt 定时任务对象
  55. * @return 状态bean
  56. */
  57. @SaveValidate
  58. @SneakyThrows
  59. @PutMapping(value = "quartzs")
  60. public ResponseVO stateQuartz(@RequestBody final Quartz qt) {
  61. final boolean flag = quartzService.save(qt);
  62. if (flag) {
  63. return ResponseVO.success("修改成功!");
  64. } else {
  65. return ResponseVO.success("修改成功!");
  66. }
  67. }
  68. /**
  69. * 删除定时任务
  70. *
  71. * @param ids
  72. * @return
  73. */
  74. @SneakyThrows
  75. @RequestMapping(value = "quartzs/delete/{ids}", method = RequestMethod.DELETE)
  76. public ResponseVO deleteQuartzById(@PathVariable final String ids) {
  77. if (quartzService.deleteById(ids)) {
  78. return ResponseVO.success("删除成功!");
  79. }
  80. return ResponseVO.fail("删除失败!没有查询到id对应的定时任务");
  81. }
  82. /**
  83. * 根据jobName模糊查询
  84. *
  85. * @param page 页数
  86. * @param size 每页几条
  87. * @param jobName jobName
  88. * @return Map<String, Object>
  89. */
  90. @SneakyThrows
  91. @GetMapping(value = "quartzs/{page}/{size}/{jobName}/{jobType}")
  92. public ResponseVO getQuartzs(
  93. @PathVariable final Integer page, @PathVariable final Integer size, @PathVariable String jobName,
  94. @PathVariable String jobType) {
  95. if (jobName.equals("1")) {
  96. jobName = "";
  97. }
  98. if (jobType.equals("1")) {
  99. jobType = "";
  100. }
  101. final Map<String, Object> map = quartzService.getQuartz(jobName, jobType, page, size);
  102. return ResponseVO.success(map);
  103. }
  104. @SneakyThrows
  105. @GetMapping(value = "initJobClasses/initJob")
  106. public ResponseVO initJobClass() {
  107. Boolean b = quartzService.initJobClass();
  108. if (!b) {
  109. return ResponseVO.fail("初始化失败,请检查sql文件是否存在");
  110. }
  111. return ResponseVO.success("初始化成功!");
  112. }
  113. }