JobController.java 8.1 KB

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