JobController.java 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  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.cleanCache();
  36. jobService.startNowById(id);
  37. return success("启动成功!");
  38. } catch (Exception e) {
  39. error(e);
  40. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  41. }
  42. }
  43. /**
  44. * 生成过去几天的数据
  45. *
  46. * @param day
  47. * @return
  48. */
  49. @ApiOperation(value = "生成过去几天的数据")
  50. @RequestMapping(value = "productDataByDay", method = RequestMethod.GET)
  51. public String productDataByDay( @ApiParam(name = "day", value = "距离今天的天数(如果是要生成昨天的数据,day=1)")@RequestParam(value = "day", required = true) int day) {
  52. try {
  53. jobService.cleanCache();
  54. jobService.productDataByDay(day);
  55. return success("启动成功!");
  56. } catch (Exception e) {
  57. error(e);
  58. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  59. }
  60. }
  61. /**
  62. * 生成过去某一天的全部的数据
  63. *
  64. * @param day
  65. * @return
  66. */
  67. @ApiOperation(value = "生成过去某一天的全部的数据")
  68. @RequestMapping(value = "productDataByOneDay", method = RequestMethod.GET)
  69. public String productDataByOneDay( @ApiParam(name = "day", value = "yyyy-MM-dd")@RequestParam(value = "day", required = true)String day) {
  70. try {
  71. jobService.cleanCache();
  72. jobService.productDataByOneDay(day);
  73. return success("启动成功!");
  74. } catch (Exception e) {
  75. error(e);
  76. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  77. }
  78. }
  79. /**
  80. * 生成过去某一天到某一天的全部的数据
  81. *
  82. * @param start
  83. * @param end
  84. * @return
  85. */
  86. @ApiOperation(value = "生成过去某一天到某一天的全部的数据(包含头尾)")
  87. @RequestMapping(value = "productDataByDayToDay", method = RequestMethod.GET)
  88. public String productDataByDayToDay( @ApiParam(name = "start", value = "yyyy-MM-dd", required = true)@RequestParam(value = "start", required = true)String start,
  89. @ApiParam(name = "end", value = "yyyy-MM-dd", required = true)@RequestParam(value = "end", required = true)String end) {
  90. try {
  91. jobService.cleanCache();
  92. jobService.productDataByDayToDay(start,end);
  93. return success("启动成功!");
  94. } catch (Exception e) {
  95. error(e);
  96. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  97. }
  98. }
  99. /**
  100. * 生成过去某一天到某一天的某个指标的数据
  101. *
  102. * @param start
  103. * @param end
  104. * @return
  105. */
  106. @ApiOperation(value = "生成过去某一天到某一天的某个指标的数据(包含头尾)")
  107. @RequestMapping(value = "productDataByDayToDayAndId", method = RequestMethod.GET)
  108. public String productDataByDayToDayAndId( @ApiParam(name = "start", value = "yyyy-MM-dd")@RequestParam(value = "start", required = true)String start,
  109. @ApiParam(name = "end", value = "yyyy-MM-dd")@RequestParam(value = "end", required = true)String end,
  110. @ApiParam(name = "id", value = "任务id")@RequestParam(value = "id", required = true)String id) {
  111. try {
  112. jobService.cleanCache();
  113. jobService.productDataByDayToDayAndId(start,end,id);
  114. return success("启动成功!");
  115. } catch (Exception e) {
  116. error(e);
  117. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  118. }
  119. }
  120. /**
  121. * 生成过去某一天的某一个指标的数据
  122. *
  123. * @param day
  124. * @return
  125. */
  126. @ApiOperation(value = "生成过去某一天的全部的数据")
  127. @RequestMapping(value = "productDataByOneDayWithId", method = RequestMethod.GET)
  128. public String productDataByOneDayWithId(
  129. @ApiParam(name = "day", value = "yyyy-MM-dd")@RequestParam(value = "day", required = true)String day,
  130. @ApiParam(name = "id", value = "任务id")@RequestParam(value = "id", required = true)String id) {
  131. try {
  132. jobService.cleanCache();
  133. jobService.productDataByOneDayWithId(day, id);
  134. return success("启动成功!");
  135. } catch (Exception e) {
  136. error(e);
  137. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  138. }
  139. }
  140. /**
  141. * 生成过去到现在的全部的数据
  142. *
  143. * @param day
  144. * @return
  145. */
  146. @ApiOperation(value = "生成过去到现在的全部的数据")
  147. @RequestMapping(value = "productDataByDayAndId", method = RequestMethod.GET)
  148. public String productDataByDayAndId(
  149. @ApiParam(name = "day", value = "距离今天的天数(如果是要生成昨天的数据,day=1)")@RequestParam(value = "day", required = true) int day,
  150. @ApiParam(name="id",required=true)@RequestParam(value = "id", required = true) String id) {
  151. try {
  152. jobService.cleanCache();
  153. jobService.productDataByDayAndId(day, id);
  154. return success("启动成功!");
  155. } catch (Exception e) {
  156. error(e);
  157. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  158. }
  159. }
  160. /**
  161. * 启动任务
  162. *
  163. * @param id id
  164. * @return
  165. */
  166. @ApiOperation(value = "启动单个任务")
  167. @RequestMapping(value = "startById", method = RequestMethod.GET)
  168. public String startById(
  169. @ApiParam(name="id",value="任务id",required=true)@RequestParam(value = "id", required = true) String id) {
  170. try {
  171. jobService.startById(id);
  172. return success("启动成功!");
  173. } catch (Exception e) {
  174. error(e);
  175. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  176. }
  177. }
  178. /**
  179. * 停止任务
  180. *
  181. * @param id id
  182. * @return
  183. */
  184. @ApiOperation(value = "停止单个任务")
  185. @RequestMapping(value = "stopById", method = RequestMethod.GET)
  186. public String stopById(@ApiParam(name="id",value="任务id",required=true)@RequestParam(value = "id", required = true)String id) {
  187. try {
  188. jobService.stopById(id);
  189. return success("停止成功!");
  190. } catch (Exception e) {
  191. error(e);
  192. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  193. }
  194. }
  195. /**
  196. * 停止所有任务
  197. *
  198. * @return
  199. */
  200. @ApiOperation(value = "停止所有任务")
  201. @RequestMapping(value = "stopAll", method = RequestMethod.GET)
  202. public String stopAll() {
  203. try {
  204. jobService.stopAll();
  205. return success("停止成功!");
  206. } catch (Exception e) {
  207. error(e);
  208. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  209. }
  210. }
  211. /**
  212. * 启动判断的任务
  213. *
  214. * @return
  215. */
  216. @ApiOperation(value = "启动檢查的任务")
  217. @RequestMapping(value = "startCheckSignJob", method = RequestMethod.GET)
  218. public String startCheckSignJob() {
  219. try {
  220. jobService.startCheckSignJob();
  221. return success("启动成功!");
  222. } catch (Exception e) {
  223. error(e);
  224. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  225. }
  226. }
  227. /**
  228. * 停止判断的任务
  229. *
  230. * @return
  231. */
  232. @ApiOperation(value = "停止檢查的任务")
  233. @RequestMapping(value = "stopCheckSignJob", method = RequestMethod.GET)
  234. public String stopCheckSignJob() {
  235. try {
  236. jobService.stopCheckSignJob();
  237. return success("停止成功!");
  238. } catch (Exception e) {
  239. error(e);
  240. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  241. }
  242. }
  243. /**
  244. * 启动判断的任务
  245. *
  246. * @return
  247. */
  248. @ApiOperation(value = "启动清除缓存的任务")
  249. @RequestMapping(value = "startCleanCacheJob", method = RequestMethod.GET)
  250. public String startCleanCacheJob() {
  251. try {
  252. jobService.startCleanCacheJob();
  253. return success("启动成功!");
  254. } catch (Exception e) {
  255. error(e);
  256. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  257. }
  258. }
  259. /**
  260. * 停止判断的任务
  261. *
  262. * @return
  263. */
  264. @ApiOperation(value = "停止清除缓存的任务")
  265. @RequestMapping(value = "stopCleanCacheJob", method = RequestMethod.GET)
  266. public String stopCleanCacheJob() {
  267. try {
  268. jobService.stopCleanCacheJob();
  269. return success("停止成功!");
  270. } catch (Exception e) {
  271. error(e);
  272. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  273. }
  274. }
  275. /**
  276. * 启动所有任务
  277. *
  278. * @return
  279. */
  280. @ApiOperation(value = "启动所有任务")
  281. @RequestMapping(value = "startAll", method = RequestMethod.GET)
  282. public String startAll() {
  283. try {
  284. jobService.startAll();
  285. return success("启动成功!");
  286. } catch (Exception e) {
  287. error(e);
  288. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  289. }
  290. }
  291. @ApiOperation(value = "清除緩存")
  292. @RequestMapping(value = "cleanCache", method = RequestMethod.GET)
  293. public String cleanCache() {
  294. try {
  295. jobService.cleanCache();
  296. return success("启动成功!");
  297. } catch (Exception e) {
  298. error(e);
  299. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  300. }
  301. }
  302. @ApiOperation(value = "查看緩存情况")
  303. @RequestMapping(value = "seeCache", method = RequestMethod.GET)
  304. public String seeCache() {
  305. try {
  306. String message=jobService.seeCache();
  307. return write(200,message);
  308. } catch (Exception e) {
  309. error(e);
  310. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  311. }
  312. }
  313. /**
  314. * 启动健康信息生成的任务
  315. *
  316. * @return
  317. */
  318. @ApiOperation(value = "启动健康信息生成的任务")
  319. @RequestMapping(value = "startHealthMessageJob", method = RequestMethod.GET)
  320. public String startHealthMessageJob() {
  321. try {
  322. jobService.startHealthMessageJob();
  323. return success("启动成功!");
  324. } catch (Exception e) {
  325. error(e);
  326. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  327. }
  328. }
  329. /**
  330. * 停止判断的任务
  331. *
  332. * @return
  333. */
  334. @ApiOperation(value = "停止健康信息生成的任务")
  335. @RequestMapping(value = "stopHealthMessageJob", method = RequestMethod.GET)
  336. public String stopHealthMessageJob() {
  337. try {
  338. jobService.stopHealthMessageJob();
  339. return success("停止成功!");
  340. } catch (Exception e) {
  341. error(e);
  342. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  343. }
  344. }
  345. //@RequestMapping(value = "startaaaa", method = RequestMethod.GET)
  346. public String startaaaa() {
  347. try {
  348. jobService.startaaaa();
  349. return success("启动成功!");
  350. } catch (Exception e) {
  351. error(e);
  352. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  353. }
  354. }
  355. /**
  356. * 生成过去某一天的健康消息
  357. *
  358. * @param day
  359. * @return
  360. */
  361. @ApiOperation(value = "生成过去某一天的健康消息")
  362. @RequestMapping(value = "productHealthDataByOneDay", method = RequestMethod.GET)
  363. public String productHealthDataByOneDay( @ApiParam(name = "day", value = "yyyy-MM-dd")
  364. @RequestParam(value = "day", required = true)String day) {
  365. try {
  366. jobService.productHealthDataByOneDay(day);
  367. return success("启动成功!");
  368. } catch (Exception e) {
  369. error(e);
  370. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  371. }
  372. }
  373. /**
  374. * 生成过去某一天到某一天的某个指标的数据
  375. *
  376. * @param start
  377. * @param end
  378. * @return
  379. */
  380. @ApiOperation(value = "生成过去某一天到某一天的健康消息(包含头尾)")
  381. @RequestMapping(value = "productHealthDataByDayToDay", method = RequestMethod.GET)
  382. public String productHealthDataByDayToDay( @ApiParam(name = "start", value = "yyyy-MM-dd")@RequestParam(value = "start", required = true)String start,
  383. @ApiParam(name = "end", value = "yyyy-MM-dd")@RequestParam(value = "end", required = true)String end
  384. ) {
  385. try {
  386. jobService.productHealthDataByDayToDay(start,end);
  387. return success("启动成功!");
  388. } catch (Exception e) {
  389. error(e);
  390. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  391. }
  392. }
  393. /**
  394. * 启动每天的统计报表任务
  395. *
  396. * @return
  397. */
  398. @ApiOperation(value = "启动每天的统计报表任务")
  399. @RequestMapping(value = "startEveryDayReportJob", method = RequestMethod.GET)
  400. public String startEveryDayReportJob() {
  401. try {
  402. jobService.startEveryDayReportJob();
  403. return success("启动成功!");
  404. } catch (Exception e) {
  405. error(e);
  406. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  407. }
  408. }
  409. /**
  410. * 停止每天的统计报表任务
  411. *
  412. * @return
  413. */
  414. @ApiOperation(value = "停止每天的统计报表任务")
  415. @RequestMapping(value = "stopEveryDayReportJob", method = RequestMethod.GET)
  416. public String stopEveryDayReportJob() {
  417. try {
  418. jobService.stopEveryDayReportJob();
  419. return success("停止成功!");
  420. } catch (Exception e) {
  421. error(e);
  422. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  423. }
  424. }
  425. /**
  426. * 启动通知任务
  427. *
  428. * @return
  429. */
  430. @ApiOperation(value = "启动通知任务")
  431. @RequestMapping(value = "startNoticeJob", method = RequestMethod.GET)
  432. public String startNoticeJob() {
  433. try {
  434. jobService.startNoticeJob();
  435. return success("启动成功!");
  436. } catch (Exception e) {
  437. error(e);
  438. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  439. }
  440. }
  441. /**
  442. * 启动通知任务
  443. *
  444. * @return
  445. */
  446. @ApiOperation(value = "停止通知任务")
  447. @RequestMapping(value = "stopNoticeJob", method = RequestMethod.GET)
  448. public String stopNoticeJob() {
  449. try {
  450. jobService.stopNoticeJob();
  451. return success("启动成功!");
  452. } catch (Exception e) {
  453. error(e);
  454. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  455. }
  456. }
  457. }