企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
``` @RestController @RequestMapping("/quartz") public class QuartzController { @Autowired private MyQuartzScheduler quartzScheduler; @Autowired private TaskMapper taskMapper; /** * 添加任务 * @param name * @param cron * @param url */ @PostMapping("/add") public Msg addJob(@RequestParam("name") String name, @RequestParam("cron") String cron, @RequestParam("url") String url){ Task task = new Task(); task.setGroupname("group01"); task.setName(name); task.setCron(cron); task.setUrl(url); task.setStatus(false); task.setCreatetime(System.currentTimeMillis()/1000); int re = taskMapper.insert(task); if (re > 0){ return new Msg(0, 0, "添加成功", ""); } return new Msg(1, 0, "添加失败", ""); } @GetMapping("/list") public Msg getJobs(@RequestParam("status") Boolean status){ Task task = new Task(); task.setStatus(status); List<Task> list = taskMapper.select(task); String o = JSON.toJSON(list).toString(); return new Msg(0, list.size(), "查询成功", o); } @GetMapping("/start") public void startJob(){ Task task = new Task(); task.setGroupname("酒店"); task.setName("日报"); task.setCron("0/5 * * * * ?"); task.setUrl("http://www.baidu.com"); try { quartzScheduler.startJob(MyJob.class, task); System.out.println("任务启动"); } catch (Exception e) { e.printStackTrace(); } } @GetMapping("/info") public void getJobInfo(@RequestParam("name") String name, @RequestParam("group") String group) throws Exception{ CronTrigger cronTrigger = quartzScheduler.getJobInfo(name, group); System.out.println(cronTrigger.getCronExpression()); } ```