SchedulerEndPoint.java 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package com.yihu.ehr.resolve.controller;
  2. import com.yihu.ehr.constants.ApiVersion;
  3. import com.yihu.ehr.constants.ServiceApi;
  4. import com.yihu.ehr.controller.EnvelopRestEndPoint;
  5. import com.yihu.ehr.resolve.config.SchedulerConfig;
  6. import com.yihu.ehr.resolve.job.SchedulerManager;
  7. import io.swagger.annotations.Api;
  8. import io.swagger.annotations.ApiOperation;
  9. import io.swagger.annotations.ApiParam;
  10. import org.quartz.*;
  11. import org.springframework.beans.factory.annotation.Autowired;
  12. import org.springframework.http.HttpStatus;
  13. import org.springframework.http.MediaType;
  14. import org.springframework.http.ResponseEntity;
  15. import org.springframework.web.bind.annotation.RequestMapping;
  16. import org.springframework.web.bind.annotation.RequestMethod;
  17. import org.springframework.web.bind.annotation.RequestParam;
  18. import org.springframework.web.bind.annotation.RestController;
  19. /**
  20. * @author Sand
  21. * @version 1.0
  22. * @created 2016.03.31 10:30
  23. */
  24. @RestController
  25. @RequestMapping(value = ApiVersion.Version1_0, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
  26. @Api(value = "SchedulerEndPoint", description = "资源化入库任务", tags = {"档案解析服务-资源化入库任务"})
  27. public class SchedulerEndPoint extends EnvelopRestEndPoint {
  28. @Autowired
  29. private SchedulerConfig schedulerConfig;
  30. @Autowired
  31. private SchedulerManager schedulerManager;
  32. @Autowired
  33. private Scheduler scheduler;
  34. @ApiOperation(value = "设置任务调度器状态")
  35. @RequestMapping(value = ServiceApi.PackageResolve.Scheduler, method = RequestMethod.PUT)
  36. public ResponseEntity<String> updateScheduler(
  37. @ApiParam(name = "pause", value = "true:暂停 , false:执行", required = true, defaultValue = "true")
  38. @RequestParam(value = "pause") boolean pause) {
  39. try {
  40. if (pause) {
  41. scheduler.pauseAll();
  42. } else {
  43. scheduler.resumeAll();
  44. }
  45. return new ResponseEntity<>((String) null, HttpStatus.OK);
  46. } catch (SchedulerException e) {
  47. return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
  48. }
  49. }
  50. @ApiOperation(value = "添加任务数量,返回当前系统最大任务限制数")
  51. @RequestMapping(value = ServiceApi.PackageResolve.Scheduler, method = RequestMethod.POST)
  52. public ResponseEntity<Integer> addJob(
  53. @ApiParam(name = "count", value = "任务数量(不要超过系统设定值)", required = true, defaultValue = "4")
  54. @RequestParam(value = "count") int count,
  55. @ApiParam(name = "cronExp", value = "触发器CRON表达式", required = true, defaultValue = "0/1 * * * * ?")
  56. @RequestParam(value = "cronExp") String cronExp) throws Exception {
  57. if (count > schedulerConfig.getMaxSize()) {
  58. count = schedulerConfig.getMaxSize();
  59. }
  60. schedulerManager.addJob(count, cronExp);
  61. return new ResponseEntity<>(schedulerConfig.getMaxSize(), HttpStatus.OK);
  62. }
  63. @ApiOperation(value = "删除解析任务")
  64. @RequestMapping(value = ServiceApi.PackageResolve.Scheduler, method = RequestMethod.DELETE)
  65. public ResponseEntity<String> removeJob(
  66. @ApiParam(name = "count", value = "任务数量", required = true, defaultValue = "4")
  67. @RequestParam(value = "count") int count) throws Exception {
  68. schedulerManager.minusJob(count);
  69. return new ResponseEntity<>((String) null, HttpStatus.OK);
  70. }
  71. @ApiOperation(value = "获取当前任务数量")
  72. @RequestMapping(value = ServiceApi.PackageResolve.Scheduler, method = RequestMethod.GET)
  73. public ResponseEntity<Integer> count() throws Exception {
  74. int count = schedulerManager.getJobSize();
  75. return new ResponseEntity<>(count, HttpStatus.OK);
  76. }
  77. }