9 changed files with 65 additions and 198 deletions
@ -1,176 +0,0 @@ |
|||
package cn.chjyj.szwh.controller; |
|||
|
|||
import cn.chjyj.szwh.dto.JobAndTriggerDto; |
|||
import cn.chjyj.szwh.service.QuartzService; |
|||
import com.alibaba.fastjson2.JSONObject; |
|||
import com.github.pagehelper.PageInfo; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.web.bind.annotation.GetMapping; |
|||
import org.springframework.web.bind.annotation.PostMapping; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.bind.annotation.ResponseBody; |
|||
|
|||
import java.util.HashMap; |
|||
import java.util.Map; |
|||
|
|||
import org.quartz.SchedulerException; |
|||
import org.springframework.util.StringUtils; |
|||
import org.springframework.web.bind.annotation.*; |
|||
|
|||
|
|||
/** |
|||
* @Author: CJ |
|||
* @Date: 2021-11-2 11:41 |
|||
*/ |
|||
@RestController |
|||
@RequestMapping(path = "/quartz") |
|||
public class QuartzController { |
|||
|
|||
@Autowired |
|||
private QuartzService quartzService; |
|||
|
|||
/** |
|||
* 新增定时任务 |
|||
* |
|||
* @param jName 任务名称 |
|||
* @param jGroup 任务组 |
|||
* @param tName 触发器名称 |
|||
* @param tGroup 触发器组 |
|||
* @param cron cron表达式 |
|||
* @return ResultMap |
|||
*/ |
|||
@PostMapping(path = "/addjob") |
|||
@ResponseBody |
|||
public JSONObject addjob(String jName, String jGroup, String tName, String tGroup, String cron) { |
|||
JSONObject jsonObject = new JSONObject(); |
|||
try { |
|||
quartzService.addjob(jName, jGroup, tName, tGroup, cron); |
|||
jsonObject.put("code",200); |
|||
jsonObject.put("msg","添加任务成功"); |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
jsonObject.put("code",400); |
|||
jsonObject.put("msg","添加任务失败"); |
|||
} |
|||
return jsonObject; |
|||
} |
|||
|
|||
/** |
|||
* 暂停任务 |
|||
* |
|||
* @param jName 任务名称 |
|||
* @param jGroup 任务组 |
|||
* @return ResultMap |
|||
*/ |
|||
@PostMapping(path = "/pausejob") |
|||
@ResponseBody |
|||
public JSONObject pausejob(String jName, String jGroup) { |
|||
JSONObject jsonObject = new JSONObject(); |
|||
try { |
|||
quartzService.pausejob(jName, jGroup); |
|||
jsonObject.put("code",200); |
|||
jsonObject.put("msg","暂停任务成功"); |
|||
} catch (SchedulerException e) { |
|||
e.printStackTrace(); |
|||
jsonObject.put("code",200); |
|||
jsonObject.put("msg","暂停任务失败"); |
|||
} |
|||
return jsonObject; |
|||
} |
|||
|
|||
/** |
|||
* 恢复任务 |
|||
* |
|||
* @param jName 任务名称 |
|||
* @param jGroup 任务组 |
|||
* @return ResultMap |
|||
*/ |
|||
@PostMapping(path = "/resumejob") |
|||
@ResponseBody |
|||
public JSONObject resumejob(String jName, String jGroup) { |
|||
JSONObject jsonObject = new JSONObject(); |
|||
try { |
|||
quartzService.resumejob(jName, jGroup); |
|||
jsonObject.put("code",200); |
|||
jsonObject.put("msg","恢复任务成功"); |
|||
} catch (SchedulerException e) { |
|||
e.printStackTrace(); |
|||
jsonObject.put("code",400); |
|||
jsonObject.put("msg","恢复任务失败"); |
|||
} |
|||
return jsonObject; |
|||
} |
|||
|
|||
/** |
|||
* 重启任务 |
|||
* |
|||
* @param jName 任务名称 |
|||
* @param jGroup 任务组 |
|||
* @param cron cron表达式 |
|||
* @return ResultMap |
|||
*/ |
|||
@PostMapping(path = "/reschedulejob") |
|||
@ResponseBody |
|||
public JSONObject rescheduleJob(String jName, String jGroup, String cron) { |
|||
JSONObject jsonObject =new JSONObject(); |
|||
try { |
|||
quartzService.rescheduleJob(jName, jGroup, cron); |
|||
jsonObject.put("code",200); |
|||
jsonObject.put("msg","重启任务成功"); |
|||
} catch (SchedulerException e) { |
|||
e.printStackTrace(); |
|||
jsonObject.put("code",400); |
|||
jsonObject.put("msg","重启任务失败"); |
|||
} |
|||
return jsonObject; |
|||
} |
|||
|
|||
/** |
|||
* 删除任务 |
|||
* |
|||
* @param jName 任务名称 |
|||
* @param jGroup 任务组 |
|||
* @return ResultMap |
|||
*/ |
|||
@PostMapping(path = "/deletejob") |
|||
@ResponseBody |
|||
public JSONObject deletejob(String jName, String jGroup) { |
|||
JSONObject jsonObject = new JSONObject(); |
|||
try { |
|||
quartzService.deletejob(jName, jGroup); |
|||
jsonObject.put("code",200); |
|||
jsonObject.put("msg","删除任务成功"); |
|||
} catch (SchedulerException e) { |
|||
e.printStackTrace(); |
|||
jsonObject.put("code",400); |
|||
jsonObject.put("msg","删除任务失败"); |
|||
} |
|||
return jsonObject; |
|||
} |
|||
|
|||
/** |
|||
* 查询任务 |
|||
* |
|||
* @param pageNum 页码 |
|||
* @param pageSize 每页显示多少条数据 |
|||
* @return Map |
|||
*/ |
|||
@GetMapping(path = "/queryjob") |
|||
@ResponseBody |
|||
public JSONObject queryjob(Integer pageNum, Integer pageSize) { |
|||
JSONObject jsonObject = new JSONObject(); |
|||
PageInfo<JobAndTriggerDto> pageInfo = quartzService.getJobAndTriggerDetails(pageNum, pageSize); |
|||
Map<String, Object> map = new HashMap<>(); |
|||
if (pageInfo!=null) { |
|||
map.put("JobAndTrigger", pageInfo); |
|||
map.put("number", pageInfo.getTotal()); |
|||
jsonObject.put("code",200); |
|||
jsonObject.put("msg","查询任务成功"); |
|||
jsonObject.put("data",map); |
|||
}else{ |
|||
jsonObject.put("code",400); |
|||
jsonObject.put("msg","查询任务成功失败,没有数据"); |
|||
} |
|||
return jsonObject; |
|||
} |
|||
} |
|||
Loading…
Reference in new issue