JobController.java 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. package com.yihu.jw.care.web;
  2. import com.yihu.jw.care.job.QuartzHelper;
  3. import com.yihu.jw.care.job.consult.FinishConsultJob;
  4. import com.yihu.jw.care.job.message.DoctorSendUnreadJob;
  5. import com.yihu.jw.care.job.message.PatientSendUnreadJob;
  6. import com.yihu.jw.care.service.JobService;
  7. import com.yihu.jw.care.util.SystemConf;
  8. import com.yihu.jw.restmodel.web.ObjEnvelop;
  9. import io.swagger.annotations.Api;
  10. import io.swagger.annotations.ApiOperation;
  11. import org.slf4j.LoggerFactory;
  12. import org.springframework.beans.factory.annotation.Autowired;
  13. import org.springframework.http.MediaType;
  14. import org.springframework.web.bind.annotation.RequestMapping;
  15. import org.springframework.web.bind.annotation.RequestMethod;
  16. import org.springframework.web.bind.annotation.RestController;
  17. import java.util.HashMap;
  18. /**
  19. * 任务启动
  20. *
  21. * @author chenweida
  22. */
  23. @RestController
  24. @RequestMapping(value = "/job", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
  25. @Api(description = "后台-任务控制")
  26. public class JobController extends BaseController {
  27. private org.slf4j.Logger logger = LoggerFactory.getLogger(JobController.class);
  28. private final JobService jobService;
  29. private final QuartzHelper quartzHelper;
  30. @Autowired
  31. public JobController(JobService jobService, QuartzHelper quartzHelper) {
  32. this.jobService = jobService;
  33. this.quartzHelper = quartzHelper;
  34. }
  35. @RequestMapping(value = "removeJob", method = RequestMethod.GET)
  36. public String removeJob(String taskId) {
  37. try {
  38. if(quartzHelper.isExistJob(taskId)){
  39. quartzHelper.removeJob(taskId);
  40. return success("删除成功!");
  41. }
  42. return success("删除成功!");
  43. } catch (Exception e) {
  44. error(e);
  45. return invalidUserException(e, -1, "删除失败:" + e.getMessage());
  46. }
  47. }
  48. @RequestMapping(value = "getCalendar", method = RequestMethod.GET)
  49. public ObjEnvelop getCalendar() throws Exception{
  50. return success(quartzHelper.getCalendar());
  51. }
  52. @RequestMapping(value = "isExist", method = RequestMethod.GET)
  53. public String isExist(String taskId) {
  54. try {
  55. if(quartzHelper.isExistJob(taskId)){
  56. return success("job已经存在!");
  57. }
  58. return success("job不存在!");
  59. } catch (Exception e) {
  60. error(e);
  61. return invalidUserException(e, -1, "执行失败:" + e.getMessage());
  62. }
  63. }
  64. @RequestMapping(value = "reStartById", method = RequestMethod.GET)
  65. public String reStartById(String taskId) {
  66. try {
  67. if(quartzHelper.isExistJob(taskId)){
  68. quartzHelper.removeJob(taskId);
  69. }
  70. switch(taskId){
  71. case "finish_consult_job":
  72. if (!quartzHelper.isExistJob("finish_consult_job")) {
  73. String trigger = SystemConf.getInstance().getSystemProperties().getProperty("finish_consult_job");
  74. quartzHelper.addJob(FinishConsultJob.class, trigger, "finish_consult_job", new HashMap<String, Object>());
  75. logger.info("finish_consult_job success");
  76. } else {
  77. logger.info("finish_consult_job exist");
  78. }
  79. break;
  80. case "DOCTOR_SEND_UNREAD_MES_JOB":
  81. if (!quartzHelper.isExistJob("DOCTOR_SEND_UNREAD_MES_JOB")) {
  82. String trigger = SystemConf.getInstance().getSystemProperties().getProperty("DOCTOR_SEND_UNREAD_MES_JOB");
  83. quartzHelper.addJob(DoctorSendUnreadJob.class, trigger, "DOCTOR_SEND_UNREAD_MES_JOB", new HashMap<String, Object>());
  84. logger.info("DOCTOR_SEND_UNREAD_MES_JOB success");
  85. } else {
  86. logger.info("DOCTOR_SEND_UNREAD_MES_JOB exist");
  87. }
  88. break;
  89. case "PATIENT_SEND_UNREAD_MES_JOB":
  90. if (!quartzHelper.isExistJob("PATIENT_SEND_UNREAD_MES_JOB")) {
  91. String trigger = SystemConf.getInstance().getSystemProperties().getProperty("PATIENT_SEND_UNREAD_MES_JOB");
  92. quartzHelper.addJob(PatientSendUnreadJob.class, trigger, "PATIENT_SEND_UNREAD_MES_JOB", new HashMap<String, Object>());
  93. logger.info("PATIENT_SEND_UNREAD_MES_JOB success");
  94. } else {
  95. logger.info("PATIENT_SEND_UNREAD_MES_JOB exist");
  96. }
  97. break;
  98. default :
  99. }
  100. return success("启动成功!");
  101. } catch (Exception e) {
  102. error(e);
  103. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  104. }
  105. }
  106. /**
  107. * 生成过去几天的数据
  108. *
  109. * @param day
  110. * @return
  111. */
  112. @RequestMapping(value = "productDataByDay", method = RequestMethod.GET)
  113. public String productDataByDay(Integer day) {
  114. try {
  115. jobService.productDataByDay(day);
  116. return success("启动成功!");
  117. } catch (Exception e) {
  118. error(e);
  119. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  120. }
  121. }
  122. /**
  123. * 生成过去某一天的全部的数据
  124. *
  125. * @param day
  126. * @return
  127. */
  128. @RequestMapping(value = "productDataByOneDay", method = RequestMethod.GET)
  129. public String productDataByOneDay(String day) {
  130. try {
  131. jobService.productDataByOneDay(day);
  132. return success("启动成功!");
  133. } catch (Exception e) {
  134. error(e);
  135. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  136. }
  137. }
  138. /**
  139. * 生成过去某一天的某一个指标的数据
  140. *
  141. * @param day
  142. * @return
  143. */
  144. @RequestMapping(value = "productDataByOneDayWithId", method = RequestMethod.GET)
  145. public String productDataByOneDayWithId(String day, String id) {
  146. try {
  147. jobService.productDataByOneDayWithId(day, id);
  148. return success("启动成功!");
  149. } catch (Exception e) {
  150. error(e);
  151. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  152. }
  153. }
  154. /**
  155. * 生成过去某几天的某一个指标的数据
  156. *
  157. * @param day
  158. * @return
  159. */
  160. @RequestMapping(value = "productDataByDayAndId", method = RequestMethod.GET)
  161. public String productDataByDayAndId(Integer day, String id) {
  162. try {
  163. jobService.productDataByDayAndId(day, id);
  164. return success("启动成功!");
  165. } catch (Exception e) {
  166. error(e);
  167. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  168. }
  169. }
  170. /**
  171. * 启动任务
  172. *
  173. * @param id id
  174. * @return
  175. */
  176. @RequestMapping(value = "startById", method = RequestMethod.GET)
  177. public String startById(String id) {
  178. try {
  179. jobService.startById(id);
  180. return success("启动成功!");
  181. } catch (Exception e) {
  182. error(e);
  183. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  184. }
  185. }
  186. /**
  187. * 停止任务
  188. *
  189. * @param id id
  190. * @return
  191. */
  192. @RequestMapping(value = "stopById", method = RequestMethod.GET)
  193. public String stopById(String id) {
  194. try {
  195. jobService.stopById(id);
  196. return success("停止成功!");
  197. } catch (Exception e) {
  198. error(e);
  199. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  200. }
  201. }
  202. /**
  203. * 停止所有任务
  204. *
  205. * @return
  206. */
  207. @RequestMapping(value = "stopAll", method = RequestMethod.GET)
  208. public String stopAll() {
  209. try {
  210. jobService.stopAll();
  211. return success("停止成功!");
  212. } catch (Exception e) {
  213. error(e);
  214. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  215. }
  216. }
  217. /**
  218. * 启动所有任务
  219. *
  220. * @return
  221. */
  222. @RequestMapping(value = "startAll", method = RequestMethod.GET)
  223. public String startAll() {
  224. try {
  225. jobService.startAll();
  226. return success("启动成功!");
  227. } catch (Exception e) {
  228. error(e);
  229. return invalidUserException(e, -1, "启动失败:" + e.getMessage());
  230. }
  231. }
  232. @RequestMapping(value = "/testNow", method = RequestMethod.POST)
  233. @ApiOperation("立即执行")
  234. public String executeSignFamilyPayResultJob() {
  235. try {
  236. quartzHelper.startNow(FinishConsultJob.class, "finish_consult_job", null);
  237. quartzHelper.startNow(DoctorSendUnreadJob.class, "DOCTOR_SEND_UNREAD_MES_JOB", null);
  238. quartzHelper.startNow(PatientSendUnreadJob.class, "PATIENT_SEND_UNREAD_MES_JOB", null);
  239. return write(200, "启动成功");
  240. } catch (Exception e) {
  241. error(e);
  242. return error(-1, e.getMessage());
  243. }
  244. }
  245. }