|
@@ -0,0 +1,64 @@
|
|
|
+package com.sky.ioc.controller.scene;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.sky.ioc.entity.QuartzJob;
|
|
|
+import com.sky.ioc.service.job.IQuartzJobService;
|
|
|
+import com.sky.ioc.tool.ReturnMsg;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+@Api(tags ="定时任务")
|
|
|
+@Slf4j
|
|
|
+@RestController
|
|
|
+@RequestMapping("/quartz_job")
|
|
|
+public class QuartzJobController {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IQuartzJobService quartzJobService;
|
|
|
+
|
|
|
+ @ApiOperation("创建定时任务")
|
|
|
+ @PostMapping(value = "/addjob")
|
|
|
+ public ReturnMsg addjob(@RequestBody QuartzJob quartzJob){
|
|
|
+ List<QuartzJob> list = quartzJobService.list(new QueryWrapper<QuartzJob>().eq("job_class_name", quartzJob.getJobClassName()));
|
|
|
+ if (list != null && list.size() > 0) {
|
|
|
+ return ReturnMsg.fail("该定时任务类名已存在");
|
|
|
+ }
|
|
|
+ quartzJobService.saveAndScheduleJob(quartzJob);
|
|
|
+ return ReturnMsg.ok("创建定时任务成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过id删除
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ApiOperation("删除定时任务")
|
|
|
+ @PostMapping(value = "/deljob")
|
|
|
+ public ReturnMsg<?> delete(@RequestParam(name = "id", required = true) String id) {
|
|
|
+ QuartzJob quartzJob = quartzJobService.getById(id);
|
|
|
+ if (quartzJob == null) {
|
|
|
+ return ReturnMsg.fail("未找到对应实体");
|
|
|
+ }
|
|
|
+ quartzJobService.deleteAndStopJob(quartzJob);
|
|
|
+ return ReturnMsg.ok("删除成功!");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @ApiOperation("定时任务列表")
|
|
|
+ @GetMapping(value = "/getJobList")
|
|
|
+ public ReturnMsg getJobList(@RequestParam(name = "name", required = false) String name,
|
|
|
+ @RequestParam(name = "groupName", required = false) String groupName,
|
|
|
+ @RequestParam(name = "status", required = false) Integer status,
|
|
|
+ @RequestParam(name = "pageStart", required = false,defaultValue = "0") Integer pageStart,
|
|
|
+ @RequestParam(name = "pageSize", required = false,defaultValue = "10") Integer pageSize) {
|
|
|
+ return quartzJobService.pageList(name,groupName,status,pageStart,pageSize);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|