1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
|
@RestController @RequestMapping("/sys/quartzJob") @Slf4j @Api(tags = "定时任务接口") public class QuartzJobController { @Autowired private QuartzJobService quartzJobService; @Autowired private Scheduler scheduler;
@ApiOperation(value = "分页列表查询", notes = "分页列表查询") @RequestMapping(value = "/list", method = RequestMethod.GET) public ApiResult queryPageList(QuartzJob quartzJob, @RequestParam(value = "page", defaultValue = "1") int page, @RequestParam(value = "pageSize", defaultValue = "20") int pageSize) { Page<QuartzJob> list = quartzJobService.selectList(quartzJob,page,pageSize); ApiResult apiResult = new ApiResult(); if (CollectionUtils.isNotEmpty(list.getItems())){ apiResult.setData(list); } return ApiResult.ok("list",list);
}
@ApiOperation(value = "添加定时任务", notes = "添加定时任务") @RequestMapping(value = "/add", method = RequestMethod.POST) public ApiResult add(@RequestBody QuartzJob quartzJob) { boolean b = quartzJobService.saveAndScheduleJob(quartzJob); if (b == true) { return ApiResult.ok("add"); } return ApiResult.fail("add","添加定时任务失败"); }
@ApiOperation(value = "更新定时任务", notes = "更新定时任务") @RequestMapping(value = "/edit", method ={RequestMethod.PUT, RequestMethod.POST}) public ApiResult eidt(@RequestBody QuartzJob quartzJob) { try { quartzJobService.editAndScheduleJob(quartzJob); } catch (SchedulerException e) { log.error(e.getMessage(),e); return ApiResult.fail("edit","更新定时任务失败!"); } return ApiResult.ok("edit"); }
@ApiOperation(value = "通过id删除", notes = "通过id删除") @RequestMapping(value = "/delete", method = RequestMethod.DELETE) public ApiResult delete(@RequestParam(name = "id", required = true) String id) { QuartzJob quartzJob = quartzJobService.getById(Long.valueOf(id)); if (quartzJob == null) { return ApiResult.fail("delete","未找到对应实体"); } quartzJobService.deleteAndStopJob(Long.valueOf(id)); return ApiResult.ok("delete");
}
@ApiOperation(value = "批量删除", notes = "批量删除") @RequestMapping(value = "/deleteBatch", method = RequestMethod.DELETE) public ApiResult deleteBatch(@RequestParam(name = "ids", required = true) String ids) { if (ids == null || "".equals(ids.trim())) { return ApiResult.fail("deleteBatch","参数不识别!"); } for (String id : Arrays.asList(ids.split(","))) { QuartzJob job = quartzJobService.getById(Long.valueOf(id)); quartzJobService.deleteAndStopJob(Long.valueOf(id)); } return ApiResult.ok("deleteBatch"); }
@GetMapping(value = "/pause") @ApiOperation(value = "停止定时任务") public ApiResult pauseJob(@RequestParam(name = "id") String id) { QuartzJob job = quartzJobService.getById(Long.valueOf(id)); if (job == null) { return ApiResult.fail("pause","定时任务不存在!"); } quartzJobService.pause(job); return ApiResult.ok("pause"); }
@GetMapping(value = "/resume") @ApiOperation(value = "启动定时任务") public ApiResult resumeJob(@RequestParam(name = "id") String id) { QuartzJob job = quartzJobService.getById(Long.valueOf(id)); if (job == null) { return ApiResult.fail("resume","定时任务不存在!"); } quartzJobService.resumeJob(job); return ApiResult.ok("resume"); }
@ApiOperation(value = "通过id查询", notes = "通过id查询") @RequestMapping(value = "/queryById", method = RequestMethod.GET) public ApiResult queryById(@RequestParam(name = "id", required = true) String id) { QuartzJob quartzJob = quartzJobService.getById(Long.valueOf(id)); ApiResult apiResult = new ApiResult(); apiResult.setData(quartzJob); return apiResult; }
@ApiOperation(value = "立即执行", notes = "立即执行") @GetMapping("/execute") public ApiResult execute(@RequestParam(name = "id", required = true) String id) { QuartzJob quartzJob = quartzJobService.getById(Long.valueOf(id)); if (quartzJob == null) { return ApiResult.fail("execute","未找到对应实体"); } try { quartzJobService.execute(quartzJob); } catch (Exception e) { log.info("定时任务 立即执行失败>>"+e.getMessage()); return ApiResult.fail("execute","执行失败!"); } return ApiResult.ok("execute"); }
}
|