package com.chenxuan.controller; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.chenxuan.base.controller.BaseController; import com.chenxuan.base.entity.AjaxResult; import com.chenxuan.bean.annotation.LogAnnotation; import com.chenxuan.entity.dto.ScheduleJobDto; import com.chenxuan.entity.model.ScheduleJob; import com.chenxuan.enums.OperateType; import com.chenxuan.service.ScheduleJobService; import org.quartz.SchedulerException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; /** * @ClassName:ScheduleJobController * @Description: 定时任务控制器 * @Author: Arno_Fu * @CreatTime:12/26/2019 - 4:57 PM * @Version V1.0 */ @RestController @RequestMapping("/quartz/job") public class ScheduleJobController extends BaseController { @Autowired private ScheduleJobService scheduleJobService; /** * 获取定时列表 */ @GetMapping("/page") public AjaxResult page(ScheduleJobDto dto) { Page page = scheduleJobService.queryPage(dto); return AjaxResult.success(page); } /** * 返回编辑页面数据 * * @param jobId * @return */ @GetMapping("/info") public AjaxResult info(@RequestParam("jobId") Long jobId) { ScheduleJob job = scheduleJobService.getById(jobId); return AjaxResult.success(job); } /** * 新增定时任务 * * @param job * @return * @throws SchedulerException */ @PostMapping("/add") @LogAnnotation(module = "新增定时任务", operateType = OperateType.INSERT) public AjaxResult add(@RequestBody ScheduleJob job) throws SchedulerException { return scheduleJobService.add(job); } /** * 编辑定时任务 * * @param job * @return * @throws SchedulerException */ @PutMapping("/update") public AjaxResult update(@RequestBody ScheduleJob job) throws SchedulerException { return scheduleJobService.update(job); } /** * 启动定时任务 * * @param jobIds * @return * @throws SchedulerException */ @GetMapping("/start") public AjaxResult start(@RequestParam("jobIds") String[] jobIds) throws SchedulerException { return returnAjax(scheduleJobService.start(jobIds)); } /** * 暂停定时任务 * * @param jobIds * @return * @throws SchedulerException */ @GetMapping("/pause") public AjaxResult pause(@RequestParam("jobIds") String[] jobIds) throws SchedulerException { return returnAjax(scheduleJobService.pause(jobIds)); } /** * 删除定时任务 * * @param jobIds * @return * @throws SchedulerException */ @DeleteMapping("/delete") public AjaxResult delete(@RequestParam("jobIds") String[] jobIds) throws SchedulerException { return scheduleJobService.delete(jobIds); } /** * 启动所有的定时任务 * * @return * @throws SchedulerException */ @GetMapping("/startAllJob") public AjaxResult startAllJob() throws SchedulerException { scheduleJobService.startAllJob(); return AjaxResult.success(); } /** * 暂停所有的定时任务 * * @return * @throws SchedulerException */ @GetMapping("/pauseAllJob") public AjaxResult pauseAllJob() throws SchedulerException { scheduleJobService.pauseAllJob(); return AjaxResult.success(); } }