JobController.java 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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", required = true)@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 start
  80. * @param end
  81. * @return
  82. */
  83. @ApiOperation(value = "生成过去某一天到某一天的全部的数据")
  84. @RequestMapping(value = "productDataByDayToDay", method = RequestMethod.GET)
  85. public String productDataByDayToDay( @ApiParam(name = "start", value = "yyyy-MM-dd", required = true)@RequestParam(value = "start", required = true)String start,
  86. @ApiParam(name = "end", value = "yyyy-MM-dd", required = true)@RequestParam(value = "end", required = true)String end) {
  87. try {
  88. jobService.productDataByDayToDay(start,end);
  89. return success("启动成功!");
  90. } catch (Exception e) {
  91. error(e);
  92. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  93. }
  94. }
  95. /**
  96. * 生成过去某一天到某一天的某个指标的数据
  97. *
  98. * @param start
  99. * @param end
  100. * @return
  101. */
  102. @ApiOperation(value = "生成过去某一天到某一天的某个指标的数据")
  103. @RequestMapping(value = "productDataByDayToDayAndId", method = RequestMethod.GET)
  104. public String productDataByDayToDayAndId( @ApiParam(name = "start", value = "yyyy-MM-dd")@RequestParam(value = "start", required = true)String start,
  105. @ApiParam(name = "end", value = "yyyy-MM-dd")@RequestParam(value = "end", required = true)String end,
  106. @ApiParam(name = "id", value = "任务id")@RequestParam(value = "id", required = true)String id) {
  107. try {
  108. jobService.productDataByDayToDayAndId(start,end,id);
  109. return success("启动成功!");
  110. } catch (Exception e) {
  111. error(e);
  112. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  113. }
  114. }
  115. /**
  116. * 生成过去某一天的某一个指标的数据
  117. *
  118. * @param day
  119. * @return
  120. */
  121. @ApiOperation(value = "生成过去某一天的全部的数据")
  122. @RequestMapping(value = "productDataByOneDayWithId", method = RequestMethod.GET)
  123. public String productDataByOneDayWithId(
  124. @ApiParam(name = "day", value = "yyyy-MM-dd")@RequestParam(value = "day", required = true)String day,
  125. @ApiParam(name = "id", value = "任务id")@RequestParam(value = "id", required = true)String id) {
  126. try {
  127. jobService.productDataByOneDayWithId(day, id);
  128. return success("启动成功!");
  129. } catch (Exception e) {
  130. error(e);
  131. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  132. }
  133. }
  134. /**
  135. * 生成过去到现在的全部的数据
  136. *
  137. * @param day
  138. * @return
  139. */
  140. @ApiOperation(value = "生成过去到现在的全部的数据")
  141. @RequestMapping(value = "productDataByDayAndId", method = RequestMethod.GET)
  142. public String productDataByDayAndId(
  143. @ApiParam(name = "day", value = "距离今天的天数(如果是要生成昨天的数据,day=1)")@RequestParam(value = "day", required = true) int day,
  144. @ApiParam(name="id",required=true)@RequestParam(value = "id", required = true) String id) {
  145. try {
  146. jobService.productDataByDayAndId(day, id);
  147. return success("启动成功!");
  148. } catch (Exception e) {
  149. error(e);
  150. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  151. }
  152. }
  153. /**
  154. * 启动任务
  155. *
  156. * @param id id
  157. * @return
  158. */
  159. @ApiOperation(value = "启动单个任务")
  160. @RequestMapping(value = "startById", method = RequestMethod.GET)
  161. public String startById(
  162. @ApiParam(name="id",value="任务id",required=true)@RequestParam(value = "id", required = true) String id) {
  163. try {
  164. jobService.startById(id);
  165. return success("启动成功!");
  166. } catch (Exception e) {
  167. error(e);
  168. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  169. }
  170. }
  171. /**
  172. * 停止任务
  173. *
  174. * @param id id
  175. * @return
  176. */
  177. @ApiOperation(value = "停止单个任务")
  178. @RequestMapping(value = "stopById", method = RequestMethod.GET)
  179. public String stopById(@ApiParam(name="id",value="任务id",required=true)@RequestParam(value = "id", required = true)String id) {
  180. try {
  181. jobService.stopById(id);
  182. return success("停止成功!");
  183. } catch (Exception e) {
  184. error(e);
  185. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  186. }
  187. }
  188. /**
  189. * 停止所有任务
  190. *
  191. * @return
  192. */
  193. @ApiOperation(value = "停止所有任务")
  194. @RequestMapping(value = "stopAll", method = RequestMethod.GET)
  195. public String stopAll() {
  196. try {
  197. jobService.stopAll();
  198. return success("停止成功!");
  199. } catch (Exception e) {
  200. error(e);
  201. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  202. }
  203. }
  204. /**
  205. * 启动判断的任务
  206. *
  207. * @return
  208. */
  209. @ApiOperation(value = "启动檢查的任务")
  210. @RequestMapping(value = "startCheckSignJob", method = RequestMethod.GET)
  211. public String startCheckSignJob() {
  212. try {
  213. jobService.startCheckSignJob();
  214. return success("启动成功!");
  215. } catch (Exception e) {
  216. error(e);
  217. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  218. }
  219. }
  220. /**
  221. * 停止判断的任务
  222. *
  223. * @return
  224. */
  225. @ApiOperation(value = "停止檢查的任务")
  226. @RequestMapping(value = "stopCheckSignJob", method = RequestMethod.GET)
  227. public String stopCheckSignJob() {
  228. try {
  229. jobService.stopCheckSignJob();
  230. return success("停止成功!");
  231. } catch (Exception e) {
  232. error(e);
  233. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  234. }
  235. }
  236. /**
  237. * 启动所有任务
  238. *
  239. * @return
  240. */
  241. @ApiOperation(value = "启动所有任务")
  242. @RequestMapping(value = "startAll", method = RequestMethod.GET)
  243. public String startAll() {
  244. try {
  245. jobService.startAll();
  246. return success("启动成功!");
  247. } catch (Exception e) {
  248. error(e);
  249. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  250. }
  251. }
  252. //@RequestMapping(value = "startaaaa", method = RequestMethod.GET)
  253. public String startaaaa() {
  254. try {
  255. jobService.startaaaa();
  256. return success("启动成功!");
  257. } catch (Exception e) {
  258. error(e);
  259. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  260. }
  261. }
  262. }