JobController.java 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  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. @ApiOperation(value = "立即启动健康信息生成的任务")
  330. @RequestMapping(value = "startHealthMessageJobNow", method = RequestMethod.GET)
  331. public String startHealthMessageJobNow() {
  332. try {
  333. jobService.startHealthMessageJobNow();
  334. return success("启动成功!");
  335. } catch (Exception e) {
  336. error(e);
  337. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  338. }
  339. }
  340. /**
  341. * 停止判断的任务
  342. *
  343. * @return
  344. */
  345. @ApiOperation(value = "停止健康信息生成的任务")
  346. @RequestMapping(value = "stopHealthMessageJob", method = RequestMethod.GET)
  347. public String stopHealthMessageJob() {
  348. try {
  349. jobService.stopHealthMessageJob();
  350. return success("停止成功!");
  351. } catch (Exception e) {
  352. error(e);
  353. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  354. }
  355. }
  356. //@RequestMapping(value = "startaaaa", method = RequestMethod.GET)
  357. public String startaaaa() {
  358. try {
  359. jobService.startaaaa();
  360. return success("启动成功!");
  361. } catch (Exception e) {
  362. error(e);
  363. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  364. }
  365. }
  366. /**
  367. * 生成过去某一天的健康消息
  368. *
  369. * @param day
  370. * @return
  371. */
  372. @ApiOperation(value = "生成过去某一天的健康消息")
  373. @RequestMapping(value = "productHealthDataByOneDay", method = RequestMethod.GET)
  374. public String productHealthDataByOneDay( @ApiParam(name = "day", value = "yyyy-MM-dd")
  375. @RequestParam(value = "day", required = true)String day) {
  376. try {
  377. jobService.productHealthDataByOneDay(day);
  378. return success("启动成功!");
  379. } catch (Exception e) {
  380. error(e);
  381. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  382. }
  383. }
  384. /**
  385. * 生成过去某一天到某一天的某个指标的数据
  386. *
  387. * @param start
  388. * @param end
  389. * @return
  390. */
  391. @ApiOperation(value = "生成过去某一天到某一天的健康消息(包含头尾)")
  392. @RequestMapping(value = "productHealthDataByDayToDay", method = RequestMethod.GET)
  393. public String productHealthDataByDayToDay( @ApiParam(name = "start", value = "yyyy-MM-dd")@RequestParam(value = "start", required = true)String start,
  394. @ApiParam(name = "end", value = "yyyy-MM-dd")@RequestParam(value = "end", required = true)String end
  395. ) {
  396. try {
  397. jobService.productHealthDataByDayToDay(start,end);
  398. return success("启动成功!");
  399. } catch (Exception e) {
  400. error(e);
  401. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  402. }
  403. }
  404. /**
  405. * 启动每天的统计报表任务
  406. *
  407. * @return
  408. */
  409. @ApiOperation(value = "启动每天的统计报表任务")
  410. @RequestMapping(value = "startEveryDayReportJob", method = RequestMethod.GET)
  411. public String startEveryDayReportJob() {
  412. try {
  413. jobService.startEveryDayReportJob();
  414. return success("启动成功!");
  415. } catch (Exception e) {
  416. error(e);
  417. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  418. }
  419. }
  420. /**
  421. * 停止每天的统计报表任务
  422. *
  423. * @return
  424. */
  425. @ApiOperation(value = "停止每天的统计报表任务")
  426. @RequestMapping(value = "stopEveryDayReportJob", method = RequestMethod.GET)
  427. public String stopEveryDayReportJob() {
  428. try {
  429. jobService.stopEveryDayReportJob();
  430. return success("停止成功!");
  431. } catch (Exception e) {
  432. error(e);
  433. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  434. }
  435. }
  436. /**
  437. * 启动通知任务
  438. *
  439. * @return
  440. */
  441. @ApiOperation(value = "启动通知任务")
  442. @RequestMapping(value = "startNoticeJob", method = RequestMethod.GET)
  443. public String startNoticeJob() {
  444. try {
  445. jobService.startNoticeJob();
  446. return success("启动成功!");
  447. } catch (Exception e) {
  448. error(e);
  449. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  450. }
  451. }
  452. /**
  453. * 启动通知任务
  454. *
  455. * @return
  456. */
  457. @ApiOperation(value = "立即启动通知任务")
  458. @RequestMapping(value = "startNoticeJobNow", method = RequestMethod.GET)
  459. public String startNoticeJobNow() {
  460. try {
  461. jobService.startNoticeJobNow();
  462. return success("启动成功!");
  463. } catch (Exception e) {
  464. error(e);
  465. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  466. }
  467. }
  468. /**
  469. * 启动通知任务
  470. *
  471. * @return
  472. */
  473. @ApiOperation(value = "停止通知任务")
  474. @RequestMapping(value = "stopNoticeJob", method = RequestMethod.GET)
  475. public String stopNoticeJob() {
  476. try {
  477. jobService.stopNoticeJob();
  478. return success("启动成功!");
  479. } catch (Exception e) {
  480. error(e);
  481. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  482. }
  483. }
  484. /******************************** 随访计划消息 ****************************************************/
  485. @ApiOperation(value = "启动随访计划消息任务")
  486. @RequestMapping(value = "startFollowupPlantJob", method = RequestMethod.GET)
  487. public String startFollowupPlantJob() {
  488. try {
  489. jobService.startFollowupPlantJob();
  490. return success("启动成功!");
  491. } catch (Exception e) {
  492. error(e);
  493. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  494. }
  495. }
  496. @ApiOperation(value = "停止随访计划消息任务")
  497. @RequestMapping(value = "stopFollowupPlantJob", method = RequestMethod.GET)
  498. public String stopFollowupPlantJob() {
  499. try {
  500. jobService.stopFollowupPlantJob();
  501. return success("停止成功!");
  502. } catch (Exception e) {
  503. error(e);
  504. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  505. }
  506. }
  507. }