package com.example.demo.controller; import com.example.demo.base.Constants; import com.example.demo.domain.QrtzTask; import com.example.demo.model.dto.QuartzTaskDTO; import com.example.demo.service.JobService; import com.example.demo.service.QrTaskService; import com.example.demo.util.Response; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; import org.quartz.SchedulerException; import org.springframework.context.annotation.Lazy; import org.springframework.web.bind.annotation.*; import java.util.List; @RestController @Tag(name = "任务管理") @RequestMapping(Constants.QUARTZ_API + "/task") @RequiredArgsConstructor(onConstructor_ = {@Lazy}) public class QuartzController { private final JobService jobService; private final QrTaskService qrTaskService; @Operation(summary = "添加任务") @PostMapping("/addTask") public void addTask(@RequestBody QuartzTaskDTO quartzTaskDTO) throws SchedulerException { QrtzTask qrtzTask = qrTaskService.addQuartzTask(quartzTaskDTO); if (quartzTaskDTO.getTaskType().equals(1)) { jobService.addJob(qrtzTask); } } @Operation(summary = "删除任务") @PostMapping("/deleteTasks") public String deleteTasks(@RequestBody List taskIds) throws SchedulerException { return Response.success(qrTaskService.deleteQuartzTask(taskIds)); } @Operation(summary = "查询任务") @PostMapping("/getTasks") public String getTasks(@RequestBody QuartzTaskDTO quartzTaskDTO) { return Response.success(qrTaskService.getTasks(quartzTaskDTO)); } @Operation(summary = "更新任务") @PostMapping("/update") public void update(@RequestBody QuartzTaskDTO quartzTaskDTO) throws InterruptedException, SchedulerException { QrtzTask qrtzTask = qrTaskService.updateQuartzTask(quartzTaskDTO); jobService.updateJob(qrtzTask); } @Operation(summary = "暂停任务") @GetMapping("/pauseJob") public void pauseJob(Integer taskId) throws SchedulerException { jobService.pauseJob(taskId); } @Operation(summary = "继续任务") @GetMapping("/resumeJob") public void resumeJob(Integer taskId) throws SchedulerException { jobService.resumeJob(taskId); } }