Browse Source

定时任务接口 通知接口修改返回值

ZhangManMan 2 years ago
parent
commit
3e820ed4da

+ 64 - 0
src/main/java/com/sky/ioc/controller/scene/QuartzJobController.java

@@ -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);
+    }
+
+}

+ 1 - 28
src/main/java/com/sky/ioc/controller/scene/StrategyController.java

@@ -23,8 +23,7 @@ public class StrategyController {
     @Autowired
     StrategyService strategyService;
 
-    @Autowired
-    private IQuartzJobService quartzJobService;
+
 
     @ApiOperation("创建策略")
     @PostMapping(value = "/add")
@@ -59,33 +58,7 @@ public class StrategyController {
         return strategyService.delBatchById(ids);
     }
 
-    @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("删除成功!");
-    }
 
     public static void main(String[] args){
 

+ 4 - 0
src/main/java/com/sky/ioc/entity/QuartzJob.java

@@ -23,6 +23,10 @@ public class QuartzJob implements Serializable {
      */
     private String createBy;
 
+    /**组名*/
+    private String groupName;
+    /**任务名*/
+    private String name;
 
     /**
      * 修改人

+ 23 - 0
src/main/java/com/sky/ioc/mapper/job/QuartzJobMapper.java

@@ -3,9 +3,32 @@ package com.sky.ioc.mapper.job;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.sky.ioc.entity.QuartzJob;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
+
+import java.util.List;
 
 @Mapper
 public interface QuartzJobMapper extends BaseMapper<QuartzJob> {
 
+    @Select("<script>" +
+            " select * from sys_quartz_job where 1=1 " +
+            "<if test='name!=null and name!=\"\"'>" +
+            " and name like #{name} " +
+            "</if>" +
+            "<if test='groupName!=null and groupName!=\"\"'>" +
+            " and groupName like #{groupName} " +
+            "</if>" +
+            "<if test='status!=null '>" +
+            " and status = #{status} " +
+            "</if>" +
+            "<if test='pageStart!=null and pageSize!=null '>" +
+            "  limit #{pageSize} offset #{pageStart} " +
+            "</if>" +
+            "</script>")
+    List<QuartzJob> pageList(@Param("name") String name, @Param("groupName") String groupName,
+                             @Param("status")  Integer status,
+                             @Param("pageStart") Integer pageStart,@Param("pageSize")  Integer pageSize);
+
 
 }

+ 1 - 1
src/main/java/com/sky/ioc/mapper/notice/NoticeMapper.java

@@ -14,7 +14,7 @@ import java.util.Map;
 public interface NoticeMapper extends BaseMapper<Notice> {
 
     @Select("<script>" +
-            "select id,title,content,address,type,time from notice where is_del=0 " +
+            "select id,title,content,address,type,time,status from notice where is_del=0 " +
             "<if test='noticeParam!=null and noticeParam.startTime != null '>" +
             "<![CDATA[ and time >= #{noticeParam.startTime} AND time <= #{noticeParam.endTime} ]]> " +
             "</if>" +

+ 3 - 0
src/main/java/com/sky/ioc/service/job/IQuartzJobService.java

@@ -2,6 +2,7 @@ package com.sky.ioc.service.job;
 
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.sky.ioc.entity.QuartzJob;
+import com.sky.ioc.tool.ReturnMsg;
 import org.quartz.SchedulerException;
 
 public interface IQuartzJobService extends IService<QuartzJob> {
@@ -15,4 +16,6 @@ public interface IQuartzJobService extends IService<QuartzJob> {
     boolean resumeJob(QuartzJob quartzJob);
 
     void test(String param);
+
+    ReturnMsg pageList(String name,String groupName,Integer status,Integer pageStart,Integer pageSize);
 }

+ 10 - 0
src/main/java/com/sky/ioc/service/job/impl/QuartzJobServiceImpl.java

@@ -5,11 +5,14 @@ import com.sky.ioc.constant.Constant;
 import com.sky.ioc.entity.QuartzJob;
 import com.sky.ioc.mapper.job.QuartzJobMapper;
 import com.sky.ioc.service.job.IQuartzJobService;
+import com.sky.ioc.tool.ReturnMsg;
 import lombok.extern.slf4j.Slf4j;
 import org.quartz.*;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+
 @Slf4j
 @Service
 public class QuartzJobServiceImpl extends ServiceImpl<QuartzJobMapper, QuartzJob> implements IQuartzJobService {
@@ -50,6 +53,13 @@ public class QuartzJobServiceImpl extends ServiceImpl<QuartzJobMapper, QuartzJob
         System.out.println("param====>"+param);
     }
 
+    @Override
+    public ReturnMsg pageList(String name, String groupName, Integer status, Integer pageStart, Integer pageSize) {
+
+        List<QuartzJob> lists = quartzJobMapper.pageList(name,groupName,status,pageStart,pageSize);
+        return ReturnMsg.ok(lists);
+    }
+
     /**
      * 编辑&启停定时任务
      * @throws SchedulerException