JobController.java 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. package com.yihu.wlyy.statistics.controller;
  2. import com.yihu.wlyy.statistics.job.business.QuartzHelper;
  3. import com.yihu.wlyy.statistics.service.JobService;
  4. import io.swagger.annotations.Api;
  5. import io.swagger.annotations.ApiOperation;
  6. import io.swagger.annotations.ApiParam;
  7. import org.springframework.beans.factory.annotation.Autowired;
  8. import org.springframework.http.MediaType;
  9. import org.springframework.web.bind.annotation.RequestMapping;
  10. import org.springframework.web.bind.annotation.RequestMethod;
  11. import org.springframework.web.bind.annotation.RequestParam;
  12. import org.springframework.web.bind.annotation.RestController;
  13. /**
  14. * 任务启动
  15. *
  16. * @author chenweida
  17. */
  18. @RestController
  19. @RequestMapping(value = "/job", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
  20. @Api(description = "后台-任务控制")
  21. public class JobController extends BaseController {
  22. @Autowired
  23. private JobService jobService;
  24. /**
  25. * 启动任务
  26. *
  27. * @param id id
  28. * @return
  29. */
  30. @ApiOperation(value = "根据ID立即单个任务")
  31. @RequestMapping(value = "startNowById", method = RequestMethod.GET)
  32. public String startNowById(
  33. @ApiParam(name = "id", value = "任务ID")@RequestParam(value = "id", required = true) String id) {
  34. try {
  35. jobService.startNowById(id);
  36. return success("启动成功!");
  37. } catch (Exception e) {
  38. error(e);
  39. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  40. }
  41. }
  42. /**
  43. * 生成过去几天的数据
  44. *
  45. * @param day
  46. * @return
  47. */
  48. @ApiOperation(value = "生成过去几天的数据")
  49. @RequestMapping(value = "productDataByDay", method = RequestMethod.GET)
  50. public String productDataByDay( @ApiParam(name = "day", value = "距离今天的天数(如果是要生成昨天的数据,day=1)")@RequestParam(value = "day", required = true) int day) {
  51. try {
  52. jobService.productDataByDay(day);
  53. return success("启动成功!");
  54. } catch (Exception e) {
  55. error(e);
  56. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  57. }
  58. }
  59. /**
  60. * 生成过去某一天的全部的数据
  61. *
  62. * @param day
  63. * @return
  64. */
  65. @ApiOperation(value = "生成过去某一天的全部的数据")
  66. @RequestMapping(value = "productDataByOneDay", method = RequestMethod.GET)
  67. public String productDataByOneDay( @ApiParam(name = "day", value = "yyyy-MM-dd")@RequestParam(value = "day", required = true)String day) {
  68. try {
  69. jobService.productDataByOneDay(day);
  70. return success("启动成功!");
  71. } catch (Exception e) {
  72. error(e);
  73. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  74. }
  75. }
  76. /**
  77. * 生成过去某一天的某一个指标的数据
  78. *
  79. * @param day
  80. * @return
  81. */
  82. @ApiOperation(value = "生成过去某一天的全部的数据")
  83. @RequestMapping(value = "productDataByOneDayWithId", method = RequestMethod.GET)
  84. public String productDataByOneDayWithId(
  85. @ApiParam(name = "day", value = "yyyy-MM-dd")@RequestParam(value = "day", required = true)String day,
  86. @ApiParam(name = "id", value = "任务id")@RequestParam(value = "id", required = true)String id) {
  87. try {
  88. jobService.productDataByOneDayWithId(day, id);
  89. return success("启动成功!");
  90. } catch (Exception e) {
  91. error(e);
  92. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  93. }
  94. }
  95. /**
  96. * 生成过去到现在的全部的数据
  97. *
  98. * @param day
  99. * @return
  100. */
  101. @ApiOperation(value = "生成过去到现在的全部的数据")
  102. @RequestMapping(value = "productDataByDayAndId", method = RequestMethod.GET)
  103. public String productDataByDayAndId(
  104. @ApiParam(name = "day", value = "距离今天的天数(如果是要生成昨天的数据,day=1)")@RequestParam(value = "day", required = true) int day,
  105. @ApiParam(name="id",required=true)@RequestParam(value = "id", required = true) String id) {
  106. try {
  107. jobService.productDataByDayAndId(day, id);
  108. return success("启动成功!");
  109. } catch (Exception e) {
  110. error(e);
  111. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  112. }
  113. }
  114. /**
  115. * 启动任务
  116. *
  117. * @param id id
  118. * @return
  119. */
  120. @ApiOperation(value = "启动单个任务")
  121. @RequestMapping(value = "startById", method = RequestMethod.GET)
  122. public String startById(
  123. @ApiParam(name="id",required=true)@RequestParam(value = "id", required = true) String id) {
  124. try {
  125. jobService.startById(id);
  126. return success("启动成功!");
  127. } catch (Exception e) {
  128. error(e);
  129. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  130. }
  131. }
  132. /**
  133. * 停止任务
  134. *
  135. * @param id id
  136. * @return
  137. */
  138. @ApiOperation(value = "停止单个任务")
  139. @RequestMapping(value = "stopById", method = RequestMethod.GET)
  140. public String stopById(@ApiParam(name="id",required=true)@RequestParam(value = "id", required = true)String id) {
  141. try {
  142. jobService.stopById(id);
  143. return success("停止成功!");
  144. } catch (Exception e) {
  145. error(e);
  146. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  147. }
  148. }
  149. /**
  150. * 停止所有任务
  151. *
  152. * @return
  153. */
  154. @ApiOperation(value = "停止所有任务")
  155. @RequestMapping(value = "stopAll", method = RequestMethod.GET)
  156. public String stopAll() {
  157. try {
  158. jobService.stopAll();
  159. return success("停止成功!");
  160. } catch (Exception e) {
  161. error(e);
  162. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  163. }
  164. }
  165. /**
  166. * 启动判断的任务
  167. *
  168. * @return
  169. */
  170. @ApiOperation(value = "启动檢查的任务")
  171. @RequestMapping(value = "startCheckSignJob", method = RequestMethod.GET)
  172. public String startCheckSignJob() {
  173. try {
  174. jobService.startCheckSignJob();
  175. return success("启动成功!");
  176. } catch (Exception e) {
  177. error(e);
  178. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  179. }
  180. }
  181. /**
  182. * 停止判断的任务
  183. *
  184. * @return
  185. */
  186. @ApiOperation(value = "停止檢查的任务")
  187. @RequestMapping(value = "stopCheckSignJob", method = RequestMethod.GET)
  188. public String stopCheckSignJob() {
  189. try {
  190. jobService.stopCheckSignJob();
  191. return success("停止成功!");
  192. } catch (Exception e) {
  193. error(e);
  194. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  195. }
  196. }
  197. /**
  198. * 启动所有任务
  199. *
  200. * @return
  201. */
  202. @ApiOperation(value = "启动所有任务")
  203. @RequestMapping(value = "startAll", method = RequestMethod.GET)
  204. public String startAll() {
  205. try {
  206. jobService.startAll();
  207. return success("启动成功!");
  208. } catch (Exception e) {
  209. error(e);
  210. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  211. }
  212. }
  213. //@RequestMapping(value = "startaaaa", method = RequestMethod.GET)
  214. public String startaaaa() {
  215. try {
  216. jobService.startaaaa();
  217. return success("启动成功!");
  218. } catch (Exception e) {
  219. error(e);
  220. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  221. }
  222. }
  223. }