任务调度
This commit is contained in:
@@ -35,11 +35,6 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
@EnableTransactionManagement
|
@EnableTransactionManagement
|
||||||
@EnableMethodCache(basePackages = "org.nl")
|
@EnableMethodCache(basePackages = "org.nl")
|
||||||
@EnableCreateCacheAnnotation
|
@EnableCreateCacheAnnotation
|
||||||
@ComponentScan(
|
|
||||||
excludeFilters = {
|
|
||||||
@ComponentScan.Filter(type = FilterType.REGEX, pattern = "org.nl.modules.quartz.*"),
|
|
||||||
@ComponentScan.Filter(type = FilterType.REGEX, pattern = "com.github.loki4j.*")}
|
|
||||||
)
|
|
||||||
public class AppRun {
|
public class AppRun {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
package org.nl.modules.quartz.config;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import netscape.javascript.JSObject;
|
||||||
|
import org.nl.modules.quartz.utils.QuartzManage;
|
||||||
|
import org.nl.modules.wql.core.bean.WQLObject;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.boot.ApplicationArguments;
|
||||||
|
import org.springframework.boot.ApplicationRunner;
|
||||||
|
import org.springframework.core.annotation.Order;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author: lyd
|
||||||
|
* @description:
|
||||||
|
* @Date: 2022/12/5
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Order(100)
|
||||||
|
public class JobRunner implements ApplicationRunner {
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(JobRunner.class);
|
||||||
|
// private final QuartzJobRepository quartzJobRepository;
|
||||||
|
private final QuartzManage quartzManage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 项目启动时重新激活启用的定时任务
|
||||||
|
*
|
||||||
|
* @param applicationArguments /
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void run(ApplicationArguments applicationArguments) {
|
||||||
|
log.info("--------------------注入定时任务---------------------");
|
||||||
|
WQLObject jobTab = WQLObject.getWQLObject("sys_quartz_job");
|
||||||
|
JSONArray quartzJobs = jobTab.query("is_pause = '0'").getResultJSONArray(0);
|
||||||
|
quartzJobs.forEach( job -> quartzManage.addJob((JSONObject) job));
|
||||||
|
log.info("--------------------定时任务注入完成---------------------");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
package org.nl.modules.quartz.config;
|
||||||
|
|
||||||
|
import org.quartz.Scheduler;
|
||||||
|
import org.quartz.spi.TriggerFiredBundle;
|
||||||
|
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.scheduling.quartz.AdaptableJobFactory;
|
||||||
|
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author: lyd
|
||||||
|
* @description: 定时任务配置
|
||||||
|
* @Date: 2022/12/5
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class QuartzConfig {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解决Job中注入Spring Bean为null的问题
|
||||||
|
*/
|
||||||
|
@Component("quartzJobFactory")
|
||||||
|
public static class QuartzJobFactory extends AdaptableJobFactory {
|
||||||
|
|
||||||
|
private final AutowireCapableBeanFactory capableBeanFactory;
|
||||||
|
|
||||||
|
public QuartzJobFactory(AutowireCapableBeanFactory capableBeanFactory) {
|
||||||
|
this.capableBeanFactory = capableBeanFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception {
|
||||||
|
|
||||||
|
//调用父类的方法
|
||||||
|
Object jobInstance = super.createJobInstance(bundle);
|
||||||
|
capableBeanFactory.autowireBean(jobInstance);
|
||||||
|
return jobInstance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 注入scheduler到spring
|
||||||
|
* @param quartzJobFactory /
|
||||||
|
* @return Scheduler
|
||||||
|
* @throws Exception /
|
||||||
|
*/
|
||||||
|
@Bean(name = "scheduler")
|
||||||
|
public Scheduler scheduler(QuartzJobFactory quartzJobFactory) throws Exception {
|
||||||
|
SchedulerFactoryBean factoryBean=new SchedulerFactoryBean();
|
||||||
|
factoryBean.setJobFactory(quartzJobFactory);
|
||||||
|
factoryBean.afterPropertiesSet();
|
||||||
|
Scheduler scheduler=factoryBean.getScheduler();
|
||||||
|
scheduler.start();
|
||||||
|
return scheduler;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,92 @@
|
|||||||
|
package org.nl.modules.quartz.rest;
|
||||||
|
|
||||||
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.nl.modules.logging.annotation.Log;
|
||||||
|
import org.nl.modules.quartz.service.QuartzJobService;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author: lyd
|
||||||
|
* @description:
|
||||||
|
* @Date: 2022/12/5
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RequestMapping("/api/jobs")
|
||||||
|
@Api(tags = "系统:定时任务管理")
|
||||||
|
public class QuartzJobController {
|
||||||
|
private final QuartzJobService quartzJobService;
|
||||||
|
|
||||||
|
@GetMapping
|
||||||
|
@Log("查询点位")
|
||||||
|
@ApiOperation("查询点位")
|
||||||
|
//@SaCheckPermission("timing:list")
|
||||||
|
public ResponseEntity<Object> query(@RequestParam Map whereJson, Pageable page) {
|
||||||
|
return new ResponseEntity<>(quartzJobService.queryAll(whereJson, page), HttpStatus.OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation("查询任务执行日志")
|
||||||
|
@GetMapping(value = "/logs")
|
||||||
|
@SaCheckPermission("timing:list")
|
||||||
|
public ResponseEntity<Object> queryJobLog(@RequestParam Map criteria, Pageable pageable) {
|
||||||
|
return new ResponseEntity<>(quartzJobService.queryAllLog(criteria, pageable), HttpStatus.OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Log("新增定时任务")
|
||||||
|
@ApiOperation("新增定时任务")
|
||||||
|
@PostMapping
|
||||||
|
// @SaCheckPermission("timing:add")
|
||||||
|
public ResponseEntity<Object> create(@RequestBody JSONObject resources) {
|
||||||
|
quartzJobService.create(resources);
|
||||||
|
return new ResponseEntity<>(HttpStatus.CREATED);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Log("修改定时任务")
|
||||||
|
@ApiOperation("修改定时任务")
|
||||||
|
@PutMapping
|
||||||
|
// @SaCheckPermission("timing:edit")
|
||||||
|
public ResponseEntity<Object> update(@RequestBody JSONObject resources) {
|
||||||
|
quartzJobService.update(resources);
|
||||||
|
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Log("更改定时任务状态")
|
||||||
|
@ApiOperation("更改定时任务状态")
|
||||||
|
@PutMapping(value = "/{id}")
|
||||||
|
// @SaCheckPermission("timing:edit")
|
||||||
|
public ResponseEntity<Object> update(@PathVariable Long id) {
|
||||||
|
quartzJobService.updateIsPause(quartzJobService.findById(id));
|
||||||
|
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Log("执行定时任务")
|
||||||
|
@ApiOperation("执行定时任务")
|
||||||
|
@PutMapping(value = "/exec/{id}")
|
||||||
|
// @SaCheckPermission("timing:edit")
|
||||||
|
public ResponseEntity<Object> execution(@PathVariable Long id) {
|
||||||
|
quartzJobService.execution(quartzJobService.findById(id));
|
||||||
|
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Log("删除定时任务")
|
||||||
|
@ApiOperation("删除定时任务")
|
||||||
|
@DeleteMapping
|
||||||
|
// @SaCheckPermission("timing:del")
|
||||||
|
public ResponseEntity<Object> delete(@RequestBody Set<Long> ids) {
|
||||||
|
quartzJobService.delete(ids);
|
||||||
|
return new ResponseEntity<>(HttpStatus.OK);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
package org.nl.modules.quartz.service;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author: lyd
|
||||||
|
* @description:
|
||||||
|
* @Date: 2022/12/5
|
||||||
|
*/
|
||||||
|
public interface QuartzJobService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询
|
||||||
|
* @param whereJson
|
||||||
|
* @param page
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Object queryAll(Map whereJson, Pageable page);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加
|
||||||
|
* @param resources
|
||||||
|
*/
|
||||||
|
void create(JSONObject resources);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 日志查询
|
||||||
|
* @param criteria
|
||||||
|
* @param pageable
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Object queryAllLog(Map criteria, Pageable pageable);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改任务
|
||||||
|
* @param resources
|
||||||
|
*/
|
||||||
|
void update(JSONObject resources);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据ID查询
|
||||||
|
*
|
||||||
|
* @param id ID
|
||||||
|
* @return /
|
||||||
|
*/
|
||||||
|
JSONObject findById(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 立即执行定时任务
|
||||||
|
*
|
||||||
|
* @param quartzJob /
|
||||||
|
*/
|
||||||
|
void execution(JSONObject quartzJob);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更改定时任务状态
|
||||||
|
*
|
||||||
|
* @param job /
|
||||||
|
*/
|
||||||
|
void updateIsPause(JSONObject job);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行子任务
|
||||||
|
*
|
||||||
|
* @param tasks /
|
||||||
|
* @throws InterruptedException /
|
||||||
|
*/
|
||||||
|
void executionSubJob(String[] tasks) throws InterruptedException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除
|
||||||
|
* @param ids
|
||||||
|
*/
|
||||||
|
void delete(Set<Long> ids);
|
||||||
|
}
|
||||||
@@ -0,0 +1,219 @@
|
|||||||
|
package org.nl.modules.quartz.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import cn.hutool.core.util.IdUtil;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.nl.modules.common.exception.BadRequestException;
|
||||||
|
import org.nl.modules.common.utils.RedisUtils;
|
||||||
|
import org.nl.modules.common.utils.SecurityUtils;
|
||||||
|
import org.nl.modules.quartz.service.QuartzJobService;
|
||||||
|
import org.nl.modules.quartz.utils.QuartzManage;
|
||||||
|
import org.nl.modules.wql.core.bean.ResultBean;
|
||||||
|
import org.nl.modules.wql.core.bean.WQLObject;
|
||||||
|
import org.nl.modules.wql.util.WqlUtil;
|
||||||
|
import org.quartz.CronExpression;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author: lyd
|
||||||
|
* @description:
|
||||||
|
* @Date: 2022/12/5
|
||||||
|
*/
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Service(value = "quartzJobService")
|
||||||
|
public class QuartzJobServiceImpl implements QuartzJobService {
|
||||||
|
|
||||||
|
private final RedisUtils redisUtils;
|
||||||
|
private final QuartzManage quartzManage;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object queryAll(Map whereJson, Pageable page) {
|
||||||
|
WQLObject quartzTab = WQLObject.getWQLObject("sys_quartz_job");
|
||||||
|
String param = "1 = 1";
|
||||||
|
if (ObjectUtil.isNotEmpty(whereJson.get("job_name"))) {
|
||||||
|
String job_name = whereJson.get("job_name").toString();
|
||||||
|
param = param + " AND job_name like '%" + job_name + "%'";
|
||||||
|
}
|
||||||
|
ResultBean rb = quartzTab.pagequery(WqlUtil.getHttpContext(page), param, "update_time desc");
|
||||||
|
final JSONObject json = rb.pageResult();
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加
|
||||||
|
*
|
||||||
|
* @param resources
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public void create(JSONObject resources) {
|
||||||
|
if (!CronExpression.isValidExpression(resources.getString("cron_expression"))) {
|
||||||
|
throw new BadRequestException("cron表达式格式错误");
|
||||||
|
}
|
||||||
|
WQLObject quartzTab = WQLObject.getWQLObject("sys_quartz_job");
|
||||||
|
Long userId = SecurityUtils.getCurrentUserId();
|
||||||
|
String nickName = SecurityUtils.getCurrentNickName();
|
||||||
|
String now = DateUtil.now();
|
||||||
|
resources.put("job_id", IdUtil.getSnowflake(1,1).nextId());
|
||||||
|
resources.put("create_id", userId);
|
||||||
|
resources.put("create_name", nickName);
|
||||||
|
resources.put("create_time", now);
|
||||||
|
resources.put("update_optid", userId);
|
||||||
|
resources.put("update_optname", nickName);
|
||||||
|
resources.put("update_time", now);
|
||||||
|
quartzTab.insert(resources);
|
||||||
|
// 添加任务
|
||||||
|
quartzManage.addJob(resources);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 日志查询
|
||||||
|
*
|
||||||
|
* @param criteria
|
||||||
|
* @param pageable
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Object queryAllLog(Map criteria, Pageable pageable) {
|
||||||
|
WQLObject logTab = WQLObject.getWQLObject("sys_quartz_log");
|
||||||
|
String param = "1=1";
|
||||||
|
if (ObjectUtil.isNotEmpty(criteria.get("job_name"))) {
|
||||||
|
param = param + " AND job_name = '" + criteria.get("job_name").toString() + "'";
|
||||||
|
}
|
||||||
|
if (ObjectUtil.isNotEmpty(criteria.get("is_success"))) {
|
||||||
|
param = param + " AND is_success = '" + criteria.get("is_success").toString() + "'";
|
||||||
|
}
|
||||||
|
if (ObjectUtil.isNotEmpty(criteria.get("createTime"))) {
|
||||||
|
param = param + " AND create_time >= " + criteria.get("begin_time") + " AND" +
|
||||||
|
" create_time <= " + criteria.get("end_time");
|
||||||
|
}
|
||||||
|
ResultBean rb = logTab.pagequery(WqlUtil.getHttpContext(pageable), param, "create_time desc");
|
||||||
|
final JSONObject json = rb.pageResult();
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改任务
|
||||||
|
*
|
||||||
|
* @param resources
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public void update(JSONObject resources) {
|
||||||
|
WQLObject jobTab = WQLObject.getWQLObject("sys_quartz_job");
|
||||||
|
JSONObject entity = this.findById(resources.getLong("job_id"));
|
||||||
|
if (entity == null) {
|
||||||
|
throw new BadRequestException("被删除或无权限,操作失败!");
|
||||||
|
}
|
||||||
|
if (!CronExpression.isValidExpression(resources.getString("cron_expression"))) {
|
||||||
|
throw new BadRequestException("cron表达式格式错误");
|
||||||
|
}
|
||||||
|
if (StrUtil.isNotEmpty(resources.getString("sub_task"))) {
|
||||||
|
List<String> tasks = Arrays.asList(resources.getString("sub_task").split("[,,]"));
|
||||||
|
if (tasks.contains(resources.getString("job_id"))) {
|
||||||
|
throw new BadRequestException("子任务中不能添加当前任务ID");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
resources.put("update_optid", SecurityUtils.getCurrentUserId());
|
||||||
|
resources.put("update_optname", SecurityUtils.getCurrentNickName());
|
||||||
|
resources.put("update_time", DateUtil.now());
|
||||||
|
jobTab.update(resources);
|
||||||
|
quartzManage.updateJobCron(resources);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据ID查询
|
||||||
|
*
|
||||||
|
* @param id ID
|
||||||
|
* @return /
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public JSONObject findById(Long id) {
|
||||||
|
WQLObject jobTab = WQLObject.getWQLObject("sys_quartz_job");
|
||||||
|
JSONObject entity = jobTab.query("job_id = '" + id + "'").uniqueResult(0);
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 立即执行定时任务
|
||||||
|
*
|
||||||
|
* @param quartzJob /
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void execution(JSONObject quartzJob) {
|
||||||
|
quartzManage.runJobNow(quartzJob);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更改定时任务状态
|
||||||
|
*
|
||||||
|
* @param quartzJob /
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void updateIsPause(JSONObject quartzJob) {
|
||||||
|
WQLObject jobTab = WQLObject.getWQLObject("sys_quartz_job");
|
||||||
|
if (quartzJob.getString("is_pause").equals("1")) {
|
||||||
|
quartzManage.resumeJob(quartzJob);
|
||||||
|
quartzJob.put("is_pause", "0");
|
||||||
|
} else {
|
||||||
|
quartzManage.pauseJob(quartzJob);
|
||||||
|
quartzJob.put("is_pause", "1");
|
||||||
|
}
|
||||||
|
jobTab.update(quartzJob);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行子任务
|
||||||
|
*
|
||||||
|
* @param tasks /
|
||||||
|
* @throws InterruptedException /
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void executionSubJob(String[] tasks) throws InterruptedException {
|
||||||
|
for (String id : tasks) {
|
||||||
|
JSONObject quartzJob = findById(Long.parseLong(id));
|
||||||
|
// 执行任务
|
||||||
|
String uuid = IdUtil.simpleUUID();
|
||||||
|
quartzJob.put("job_id", uuid);
|
||||||
|
// 执行任务
|
||||||
|
execution(quartzJob);
|
||||||
|
// 获取执行状态,如果执行失败则停止后面的子任务执行
|
||||||
|
Boolean result = (Boolean) redisUtils.get(uuid);
|
||||||
|
while (result == null) {
|
||||||
|
// 休眠5秒,再次获取子任务执行情况
|
||||||
|
Thread.sleep(5000);
|
||||||
|
result = (Boolean) redisUtils.get(uuid);
|
||||||
|
}
|
||||||
|
if (!result) {
|
||||||
|
redisUtils.del(uuid);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除
|
||||||
|
*
|
||||||
|
* @param ids
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void delete(Set<Long> ids) {
|
||||||
|
WQLObject jobTab = WQLObject.getWQLObject("sys_quartz_job");
|
||||||
|
WQLObject logTab = WQLObject.getWQLObject("sys_quartz_log");
|
||||||
|
for (Long id : ids) {
|
||||||
|
JSONObject quartzJob = findById(id);
|
||||||
|
quartzManage.deleteJob(quartzJob);
|
||||||
|
jobTab.delete(quartzJob);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package org.nl.modules.quartz.task;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author: lyd
|
||||||
|
* @description: 测试任务
|
||||||
|
* @Date: 2022/12/5
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
public class TestTask {
|
||||||
|
|
||||||
|
public void run(){
|
||||||
|
log.info("run 执行成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run1(String str){
|
||||||
|
log.info("run1 执行成功,参数为: {}" + str);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run2(){
|
||||||
|
log.info("run2 执行成功");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,102 @@
|
|||||||
|
package org.nl.modules.quartz.utils;
|
||||||
|
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import cn.hutool.core.util.IdUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.nl.config.thread.ThreadPoolExecutorUtil;
|
||||||
|
import org.nl.modules.common.utils.RedisUtils;
|
||||||
|
import org.nl.modules.common.utils.ThrowableUtil;
|
||||||
|
import org.nl.modules.quartz.service.QuartzJobService;
|
||||||
|
import org.nl.modules.wql.core.bean.WQLObject;
|
||||||
|
import org.nl.modules.wql.util.SpringContextHolder;
|
||||||
|
import org.quartz.JobExecutionContext;
|
||||||
|
import org.springframework.scheduling.annotation.Async;
|
||||||
|
import org.springframework.scheduling.quartz.QuartzJobBean;
|
||||||
|
|
||||||
|
import java.util.concurrent.Future;
|
||||||
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author: lyd
|
||||||
|
* @description:
|
||||||
|
* @Date: 2022/12/5
|
||||||
|
*/
|
||||||
|
@Async
|
||||||
|
@SuppressWarnings({"unchecked", "all"})
|
||||||
|
@Slf4j
|
||||||
|
public class ExecutionJob extends QuartzJobBean {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 该处仅供参考
|
||||||
|
*/
|
||||||
|
private final static ThreadPoolExecutor EXECUTOR = ThreadPoolExecutorUtil.getPoll();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void executeInternal(JobExecutionContext context) {
|
||||||
|
JSONObject quartzJob = (JSONObject) context.getMergedJobDataMap().get(QuartzManage.JOB_KEY);
|
||||||
|
// 获取spring bean
|
||||||
|
QuartzJobService quartzJobService = SpringContextHolder.getBean(QuartzJobService.class);
|
||||||
|
RedisUtils redisUtils = SpringContextHolder.getBean(RedisUtils.class);
|
||||||
|
WQLObject logTab = WQLObject.getWQLObject("sys_quartz_log");
|
||||||
|
|
||||||
|
String uuid = quartzJob.getString("job_id");
|
||||||
|
|
||||||
|
JSONObject logDto = new JSONObject();
|
||||||
|
logDto.put("log_id", IdUtil.getSnowflake(1,1).nextId());
|
||||||
|
logDto.put("create_time", DateUtil.now()); // ????
|
||||||
|
logDto.put("job_name", quartzJob.getString("job_name"));
|
||||||
|
logDto.put("bean_name", quartzJob.getString("bean_name"));
|
||||||
|
logDto.put("method_name", quartzJob.getString("method_name"));
|
||||||
|
logDto.put("params", quartzJob.getString("params"));
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
logDto.put("cron_expression", quartzJob.getString("cron_expression"));
|
||||||
|
try {
|
||||||
|
// 执行任务
|
||||||
|
System.out.println("--------------------------------------------------------------");
|
||||||
|
System.out.println("任务开始执行,任务名称:" + quartzJob.getString("bean_name"));
|
||||||
|
QuartzRunnable task = new QuartzRunnable(quartzJob.getString("bean_name"), quartzJob.getString("method_name"),
|
||||||
|
quartzJob.getString("params"));
|
||||||
|
Future<?> future = EXECUTOR.submit(task);
|
||||||
|
future.get();
|
||||||
|
long times = System.currentTimeMillis() - startTime;
|
||||||
|
logDto.put("time", times);
|
||||||
|
if (StrUtil.isNotEmpty(uuid)) {
|
||||||
|
redisUtils.set(uuid, true);
|
||||||
|
}
|
||||||
|
// 任务状态
|
||||||
|
logDto.put("is_success", "1");
|
||||||
|
System.out.println("任务执行完毕,任务名称:" + quartzJob.getString("job_name") + ", 执行时间:" + times + "毫秒");
|
||||||
|
System.out.println("--------------------------------------------------------------");
|
||||||
|
// 判断是否存在子任务
|
||||||
|
if (StrUtil.isNotEmpty(quartzJob.getString("sub_task"))) {
|
||||||
|
String[] tasks = quartzJob.getString("sub_task").split("[,,]");
|
||||||
|
// 执行子任务
|
||||||
|
quartzJobService.executionSubJob(tasks);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (StrUtil.isNotEmpty(uuid)) {
|
||||||
|
redisUtils.set(uuid, false);
|
||||||
|
}
|
||||||
|
System.out.println("任务执行失败,任务名称:" + quartzJob.getString("job_name"));
|
||||||
|
System.out.println("--------------------------------------------------------------");
|
||||||
|
long times = System.currentTimeMillis() - startTime;
|
||||||
|
logDto.put("time", times);
|
||||||
|
// 任务状态 0:成功 1:失败
|
||||||
|
logDto.put("is_success", "0");
|
||||||
|
logDto.put("exception_detail", ThrowableUtil.getStackTrace(e));
|
||||||
|
// 任务如果失败了则暂停
|
||||||
|
if (quartzJob.getString("pause_after_failure") != null && quartzJob.getString("pause_after_failure").equals("1")) {
|
||||||
|
quartzJob.put("is_pause", "0");
|
||||||
|
//更新状态
|
||||||
|
quartzJobService.updateIsPause(quartzJob);
|
||||||
|
}
|
||||||
|
//异常时候打印日志
|
||||||
|
log.info(logDto.toString());
|
||||||
|
logTab.insert(logDto);
|
||||||
|
} finally {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,156 @@
|
|||||||
|
package org.nl.modules.quartz.utils;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.nl.modules.common.exception.BadRequestException;
|
||||||
|
import org.quartz.*;
|
||||||
|
import org.quartz.impl.triggers.CronTriggerImpl;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import static org.quartz.TriggerBuilder.newTrigger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author: lyd
|
||||||
|
* @description: 任务管理
|
||||||
|
* @Date: 2022/12/5
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
public class QuartzManage {
|
||||||
|
private static final String JOB_NAME = "TASK_";
|
||||||
|
public static final String JOB_KEY = "JOB_KEY";
|
||||||
|
|
||||||
|
@Resource(name = "scheduler")
|
||||||
|
private Scheduler scheduler;
|
||||||
|
|
||||||
|
public void addJob(JSONObject quartzJob){
|
||||||
|
try {
|
||||||
|
// 构建job信息
|
||||||
|
JobDetail jobDetail = JobBuilder.newJob(ExecutionJob.class).
|
||||||
|
withIdentity(JOB_NAME + quartzJob.getString("job_id")).build();
|
||||||
|
|
||||||
|
//通过触发器名和cron 表达式创建 Trigger
|
||||||
|
Trigger cronTrigger = newTrigger()
|
||||||
|
.withIdentity(JOB_NAME + quartzJob.getString("job_id"))
|
||||||
|
.startNow()
|
||||||
|
.withSchedule(CronScheduleBuilder.cronSchedule(quartzJob.getString("cron_expression")))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
cronTrigger.getJobDataMap().put(QuartzManage.JOB_KEY, quartzJob);
|
||||||
|
|
||||||
|
//重置启动时间
|
||||||
|
((CronTriggerImpl)cronTrigger).setStartTime(new Date());
|
||||||
|
|
||||||
|
//执行定时任务
|
||||||
|
scheduler.scheduleJob(jobDetail,cronTrigger);
|
||||||
|
|
||||||
|
// 暂停任务
|
||||||
|
if (quartzJob.getString("is_pause").equals("1")) {
|
||||||
|
pauseJob(quartzJob);
|
||||||
|
}
|
||||||
|
} catch (Exception e){
|
||||||
|
log.error("创建定时任务失败", e);
|
||||||
|
throw new BadRequestException("创建定时任务失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行任务
|
||||||
|
* @param quartzJob
|
||||||
|
*/
|
||||||
|
public void runJobNow(JSONObject quartzJob) {
|
||||||
|
try {
|
||||||
|
TriggerKey triggerKey = TriggerKey.triggerKey(JOB_NAME + quartzJob.getString("job_id"));
|
||||||
|
CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey);
|
||||||
|
// 如果不存在则创建一个定时任务
|
||||||
|
if(trigger == null) {
|
||||||
|
addJob(quartzJob);
|
||||||
|
}
|
||||||
|
JobDataMap dataMap = new JobDataMap();
|
||||||
|
dataMap.put(QuartzManage.JOB_KEY, quartzJob);
|
||||||
|
JobKey jobKey = JobKey.jobKey(JOB_NAME + quartzJob.getString("job_id"));
|
||||||
|
scheduler.triggerJob(jobKey,dataMap);
|
||||||
|
} catch (Exception e){
|
||||||
|
log.error("定时任务执行失败", e);
|
||||||
|
throw new BadRequestException("定时任务执行失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 暂停一个job
|
||||||
|
* @param quartzJob /
|
||||||
|
*/
|
||||||
|
public void pauseJob(JSONObject quartzJob){
|
||||||
|
try {
|
||||||
|
JobKey jobKey = JobKey.jobKey(JOB_NAME + quartzJob.getString("job_id"));
|
||||||
|
scheduler.pauseJob(jobKey);
|
||||||
|
} catch (Exception e){
|
||||||
|
log.error("定时任务暂停失败", e);
|
||||||
|
throw new BadRequestException("定时任务暂停失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新job cron表达式
|
||||||
|
* @param quartzJob /
|
||||||
|
*/
|
||||||
|
public void updateJobCron(JSONObject quartzJob) {
|
||||||
|
try {
|
||||||
|
TriggerKey triggerKey = TriggerKey.triggerKey(JOB_NAME + quartzJob.getString("job_id"));
|
||||||
|
CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey);
|
||||||
|
// 如果不存在则创建一个定时任务
|
||||||
|
if(trigger == null){
|
||||||
|
addJob(quartzJob);
|
||||||
|
trigger = (CronTrigger) scheduler.getTrigger(triggerKey);
|
||||||
|
}
|
||||||
|
CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(quartzJob.getString("cron_expression"));
|
||||||
|
trigger = trigger.getTriggerBuilder().withIdentity(triggerKey).withSchedule(scheduleBuilder).build();
|
||||||
|
//重置启动时间
|
||||||
|
((CronTriggerImpl)trigger).setStartTime(new Date());
|
||||||
|
trigger.getJobDataMap().put(QuartzManage.JOB_KEY, quartzJob);
|
||||||
|
|
||||||
|
scheduler.rescheduleJob(triggerKey, trigger);
|
||||||
|
// 暂停任务
|
||||||
|
if (quartzJob.getString("is_pause").equals("1")) {
|
||||||
|
pauseJob(quartzJob);
|
||||||
|
}
|
||||||
|
} catch (Exception e){
|
||||||
|
log.error("更新定时任务失败", e);
|
||||||
|
throw new BadRequestException("更新定时任务失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 恢复一个job
|
||||||
|
* @param quartzJob /
|
||||||
|
*/
|
||||||
|
public void resumeJob(JSONObject quartzJob) {
|
||||||
|
try {
|
||||||
|
TriggerKey triggerKey = TriggerKey.triggerKey(JOB_NAME + quartzJob.getString("job_id"));
|
||||||
|
CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey);
|
||||||
|
// 如果不存在则创建一个定时任务
|
||||||
|
if(trigger == null) {
|
||||||
|
addJob(quartzJob);
|
||||||
|
}
|
||||||
|
JobKey jobKey = JobKey.jobKey(JOB_NAME + quartzJob.getString("job_id"));
|
||||||
|
scheduler.resumeJob(jobKey);
|
||||||
|
} catch (Exception e){
|
||||||
|
log.error("恢复定时任务失败", e);
|
||||||
|
throw new BadRequestException("恢复定时任务失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteJob(JSONObject quartzJob) {
|
||||||
|
try {
|
||||||
|
JobKey jobKey = JobKey.jobKey(JOB_NAME + quartzJob.getString("job_id"));
|
||||||
|
scheduler.pauseJob(jobKey);
|
||||||
|
scheduler.deleteJob(jobKey);
|
||||||
|
} catch (Exception e){
|
||||||
|
log.error("删除定时任务失败", e);
|
||||||
|
throw new BadRequestException("删除定时任务失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
package org.nl.modules.quartz.utils;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.nl.modules.wql.util.SpringContextHolder;
|
||||||
|
import org.springframework.util.ReflectionUtils;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author: lyd
|
||||||
|
* @description: 执行定时任务
|
||||||
|
* @Date: 2022/12/5
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class QuartzRunnable implements Callable {
|
||||||
|
|
||||||
|
private final Object target;
|
||||||
|
private final Method method;
|
||||||
|
private final String params;
|
||||||
|
|
||||||
|
QuartzRunnable(String beanName, String methodName, String params)
|
||||||
|
throws NoSuchMethodException, SecurityException {
|
||||||
|
this.target = SpringContextHolder.getBean(beanName);
|
||||||
|
this.params = params;
|
||||||
|
|
||||||
|
if (StrUtil.isNotEmpty(params)) {
|
||||||
|
this.method = target.getClass().getDeclaredMethod(methodName, String.class);
|
||||||
|
} else {
|
||||||
|
this.method = target.getClass().getDeclaredMethod(methodName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object call() throws Exception {
|
||||||
|
ReflectionUtils.makeAccessible(method);
|
||||||
|
if (StrUtil.isNotEmpty(params)) {
|
||||||
|
method.invoke(target, params);
|
||||||
|
} else {
|
||||||
|
method.invoke(target);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
@@ -4,7 +4,7 @@
|
|||||||
<div class="head-container">
|
<div class="head-container">
|
||||||
<div v-if="crud.props.searchToggle">
|
<div v-if="crud.props.searchToggle">
|
||||||
<!-- 搜索 -->
|
<!-- 搜索 -->
|
||||||
<el-input v-model="query.jobName" clearable size="mini" placeholder="输入任务名称搜索" style="width: 200px;" class="filter-item" @keyup.enter.native="toQuery" />
|
<el-input v-model="query.job_name" clearable size="mini" placeholder="输入任务名称搜索" style="width: 200px;" class="filter-item" @keyup.enter.native="toQuery" />
|
||||||
<rrOperation />
|
<rrOperation />
|
||||||
</div>
|
</div>
|
||||||
<crudOperation :permission="permission">
|
<crudOperation :permission="permission">
|
||||||
@@ -23,21 +23,21 @@
|
|||||||
<!--Form表单-->
|
<!--Form表单-->
|
||||||
<el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" append-to-body width="730px">
|
<el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" append-to-body width="730px">
|
||||||
<el-form ref="form" :inline="true" :model="form" :rules="rules" size="mini" label-width="100px">
|
<el-form ref="form" :inline="true" :model="form" :rules="rules" size="mini" label-width="100px">
|
||||||
<el-form-item label="任务名称" prop="jobName">
|
<el-form-item label="任务名称" prop="job_name">
|
||||||
<el-input v-model="form.jobName" style="width: 220px;" />
|
<el-input v-model="form.job_name" style="width: 220px;" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="任务描述" prop="description">
|
<el-form-item label="任务描述" prop="description">
|
||||||
<el-input v-model="form.description" style="width: 220px;" />
|
<el-input v-model="form.description" style="width: 220px;" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="Bean名称" prop="beanName">
|
<el-form-item label="Bean名称" prop="bean_name">
|
||||||
<el-input v-model="form.beanName" style="width: 220px;" />
|
<el-input v-model="form.bean_name" style="width: 220px;" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="执行方法" prop="methodName">
|
<el-form-item label="执行方法" prop="method_name">
|
||||||
<el-input v-model="form.methodName" style="width: 220px;" />
|
<el-input v-model="form.method_name" style="width: 220px;" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="Cron表达式" prop="cronExpression">
|
<el-form-item label="Cron表达式" prop="cron_expression">
|
||||||
<!-- <el-input v-model="form.cronExpression" style="width: 220px;" />-->
|
<!-- <el-input v-model="form.cronExpression" style="width: 220px;" />-->
|
||||||
<el-input v-model="form.cronExpression" placeholder="请输入CRON 表达式" style="width: 220px;">
|
<el-input v-model="form.cron_expression" placeholder="请输入CRON 表达式" style="width: 220px;">
|
||||||
<template slot="append">
|
<template slot="append">
|
||||||
<el-button type="primary" @click="handleShowCron">
|
<el-button type="primary" @click="handleShowCron">
|
||||||
生成表达式
|
生成表达式
|
||||||
@@ -47,24 +47,24 @@
|
|||||||
</el-input>
|
</el-input>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="子任务ID">
|
<el-form-item label="子任务ID">
|
||||||
<el-input v-model="form.subTask" placeholder="多个用逗号隔开,按顺序执行" style="width: 220px;" />
|
<el-input v-model="form.sub_task" placeholder="多个用逗号隔开,按顺序执行" style="width: 220px;" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="任务负责人" prop="personInCharge">
|
<el-form-item label="任务负责人" prop="person_in_charge">
|
||||||
<el-input v-model="form.personInCharge" style="width: 220px;" />
|
<el-input v-model="form.person_in_charge" style="width: 220px;" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="告警邮箱" prop="email">
|
<el-form-item label="告警邮箱" prop="email">
|
||||||
<el-input v-model="form.email" placeholder="多个邮箱用逗号隔开" style="width: 220px;" />
|
<el-input v-model="form.email" placeholder="多个邮箱用逗号隔开" style="width: 220px;" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="失败后暂停">
|
<el-form-item label="失败后暂停">
|
||||||
<el-radio-group v-model="form.pauseAfterFailure" style="width: 220px">
|
<el-radio-group v-model="form.pause_after_failure" style="width: 220px">
|
||||||
<el-radio :label="true">是</el-radio>
|
<el-radio label="1">是</el-radio>
|
||||||
<el-radio :label="false">否</el-radio>
|
<el-radio label="0">否</el-radio>
|
||||||
</el-radio-group>
|
</el-radio-group>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="任务状态">
|
<el-form-item label="任务状态">
|
||||||
<el-radio-group v-model="form.isPause" style="width: 220px">
|
<el-radio-group v-model="form.is_pause" style="width: 220px">
|
||||||
<el-radio :label="false">启用</el-radio>
|
<el-radio label="0">启用</el-radio>
|
||||||
<el-radio :label="true">暂停</el-radio>
|
<el-radio label="1">暂停</el-radio>
|
||||||
</el-radio-group>
|
</el-radio-group>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="参数内容">
|
<el-form-item label="参数内容">
|
||||||
@@ -79,40 +79,40 @@
|
|||||||
<!--表格渲染-->
|
<!--表格渲染-->
|
||||||
<el-table ref="table" v-loading="crud.loading" :data="crud.data" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
|
<el-table ref="table" v-loading="crud.loading" :data="crud.data" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
|
||||||
<el-table-column :selectable="checkboxT" type="selection" width="55" />
|
<el-table-column :selectable="checkboxT" type="selection" width="55" />
|
||||||
<el-table-column show-overflow-tooltip prop="id" label="任务ID" />
|
<!-- <el-table-column show-overflow-tooltip prop="job_id" label="任务ID" />-->
|
||||||
<el-table-column show-overflow-tooltip prop="jobName" label="任务名称" min-width="120" />
|
<el-table-column show-overflow-tooltip prop="job_name" label="任务名称" min-width="120" />
|
||||||
<el-table-column show-overflow-tooltip prop="beanName" label="Bean名称" />
|
<el-table-column show-overflow-tooltip prop="bean_name" label="Bean名称" />
|
||||||
<el-table-column show-overflow-tooltip prop="methodName" label="执行方法" />
|
<el-table-column show-overflow-tooltip prop="method_name" label="执行方法" />
|
||||||
<el-table-column show-overflow-tooltip prop="params" label="参数" />
|
<el-table-column show-overflow-tooltip prop="params" label="参数" />
|
||||||
<el-table-column show-overflow-tooltip prop="cronExpression" label="cron表达式" min-width="100" show-tooltip-when-overflow />
|
<el-table-column show-overflow-tooltip prop="cron_expression" label="cron表达式" min-width="100" show-tooltip-when-overflow />
|
||||||
<el-table-column show-overflow-tooltip prop="isPause" width="90px" label="状态">
|
<el-table-column show-overflow-tooltip prop="is_pause" width="90px" label="状态">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<el-tag :type="scope.row.isPause ? 'warning' : 'success'">{{ scope.row.isPause ? '已暂停' : '运行中' }}</el-tag>
|
<el-tag :type="scope.row.is_pause ? 'warning' : 'success'">{{ scope.row.is_pause=='1' ? '已暂停' : '运行中' }}</el-tag>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column show-overflow-tooltip prop="description" width="150px" label="描述" />
|
<el-table-column show-overflow-tooltip prop="description" width="150px" label="描述" />
|
||||||
<el-table-column show-overflow-tooltip prop="createTime" width="136px" label="创建日期">
|
<el-table-column show-overflow-tooltip prop="createTime" width="136px" label="创建日期">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<span>{{ parseTime(scope.row.createTime) }}</span>
|
<span>{{ parseTime(scope.row.create_time) }}</span>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column v-permission="['admin','timing:edit','timing:del']" label="操作" width="170px" align="center" fixed="right">
|
<el-table-column v-permission="['admin','timing:edit','timing:del']" label="操作" width="170px" align="center" fixed="right">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<el-button v-permission="['admin','timing:edit']" size="mini" style="margin-right: 3px;" type="text" @click="crud.toEdit(scope.row)">编辑</el-button>
|
<el-button v-permission="['admin','timing:edit']" size="mini" style="margin-right: 3px;" type="text" @click="crud.toEdit(scope.row)">编辑</el-button>
|
||||||
<el-button v-permission="['admin','timing:edit']" style="margin-left: -2px" type="text" size="mini" @click="execute(scope.row.id)">执行</el-button>
|
<el-button v-permission="['admin','timing:edit']" style="margin-left: -2px" type="text" size="mini" @click="execute(scope.row.job_id)">执行</el-button>
|
||||||
<el-button v-permission="['admin','timing:edit']" style="margin-left: 3px" type="text" size="mini" @click="updateStatus(scope.row.id,scope.row.isPause ? '恢复' : '暂停')">
|
<el-button v-permission="['admin','timing:edit']" style="margin-left: 3px" type="text" size="mini" @click="updateStatus(scope.row.job_id,scope.row.is_pause ? '恢复' : '暂停')">
|
||||||
{{ scope.row.isPause ? '恢复' : '暂停' }}
|
{{ scope.row.is_pause ? '恢复' : '暂停' }}
|
||||||
</el-button>
|
</el-button>
|
||||||
<el-popover
|
<el-popover
|
||||||
:ref="scope.row.id"
|
:ref="scope.row.job_id"
|
||||||
v-permission="['admin','timing:del']"
|
v-permission="['admin','timing:del']"
|
||||||
placement="top"
|
placement="top"
|
||||||
width="200"
|
width="200"
|
||||||
>
|
>
|
||||||
<p>确定停止并删除该任务吗?</p>
|
<p>确定停止并删除该任务吗?</p>
|
||||||
<div style="text-align: right; margin: 0">
|
<div style="text-align: right; margin: 0">
|
||||||
<el-button size="mini" type="text" @click="$refs[scope.row.id].doClose()">取消</el-button>
|
<el-button size="mini" type="text" @click="$refs[scope.row.job_id].doClose()">取消</el-button>
|
||||||
<el-button :loading="delLoading" type="primary" size="mini" @click="delMethod(scope.row.id)">确定</el-button>
|
<el-button :loading="delLoading" type="primary" size="mini" @click="delMethod(scope.row.job_id)">确定</el-button>
|
||||||
</div>
|
</div>
|
||||||
<el-button slot="reference" type="text" size="mini">删除</el-button>
|
<el-button slot="reference" type="text" size="mini">删除</el-button>
|
||||||
</el-popover>
|
</el-popover>
|
||||||
@@ -134,15 +134,14 @@ import CRUD, { presenter, header, form, crud } from '@crud/crud'
|
|||||||
import rrOperation from '@crud/RR.operation'
|
import rrOperation from '@crud/RR.operation'
|
||||||
import crudOperation from '@crud/CRUD.operation'
|
import crudOperation from '@crud/CRUD.operation'
|
||||||
import pagination from '@crud/Pagination'
|
import pagination from '@crud/Pagination'
|
||||||
import DateRangePicker from '@/components/DateRangePicker'
|
|
||||||
import Crontab from './components/crontab'
|
import Crontab from './components/crontab'
|
||||||
|
|
||||||
const defaultForm = { id: null, jobName: null, subTask: null, beanName: null, methodName: null, params: null, cronExpression: null, pauseAfterFailure: true, isPause: false, personInCharge: null, email: null, description: null }
|
const defaultForm = { job_id: null, bean_name: null, cron_expression: null, is_pause: '0', job_name: null, method_name: null, params: null, description: null, person_in_charge: null, email: null, sub_task: null, pause_after_failure: '1', create_id: null, create_name: null, create_time: null, update_optid: null, update_optname: null, update_time: null }
|
||||||
export default {
|
export default {
|
||||||
name: 'Timing',
|
name: 'Timing',
|
||||||
components: { Log, pagination, crudOperation, rrOperation, DateRangePicker, Crontab },
|
components: { Log, pagination, crudOperation, rrOperation, Crontab },
|
||||||
cruds() {
|
cruds() {
|
||||||
return CRUD({ title: '定时任务', url: 'api/jobs', crudMethod: { ...crudJob }})
|
return CRUD({ title: '定时任务', idField: 'job_id', url: 'api/jobs', crudMethod: { ...crudJob }})
|
||||||
},
|
},
|
||||||
mixins: [presenter(), header(), form(defaultForm), crud()],
|
mixins: [presenter(), header(), form(defaultForm), crud()],
|
||||||
data() {
|
data() {
|
||||||
@@ -154,22 +153,22 @@ export default {
|
|||||||
del: ['admin', 'timing:del']
|
del: ['admin', 'timing:del']
|
||||||
},
|
},
|
||||||
rules: {
|
rules: {
|
||||||
jobName: [
|
job_name: [
|
||||||
{ required: true, message: '请输入任务名称', trigger: 'blur' }
|
{ required: true, message: '请输入任务名称', trigger: 'blur' }
|
||||||
],
|
],
|
||||||
description: [
|
description: [
|
||||||
{ required: true, message: '请输入任务描述', trigger: 'blur' }
|
{ required: true, message: '请输入任务描述', trigger: 'blur' }
|
||||||
],
|
],
|
||||||
beanName: [
|
bean_name: [
|
||||||
{ required: true, message: '请输入Bean名称', trigger: 'blur' }
|
{ required: true, message: '请输入Bean名称', trigger: 'blur' }
|
||||||
],
|
],
|
||||||
methodName: [
|
method_name: [
|
||||||
{ required: true, message: '请输入方法名称', trigger: 'blur' }
|
{ required: true, message: '请输入方法名称', trigger: 'blur' }
|
||||||
],
|
],
|
||||||
cronExpression: [
|
cron_expression: [
|
||||||
{ required: true, message: '请输入Cron表达式', trigger: 'blur' }
|
{ required: true, message: '请输入Cron表达式', trigger: 'blur' }
|
||||||
],
|
],
|
||||||
personInCharge: [
|
person_in_charge: [
|
||||||
{ required: true, message: '请输入负责人名称', trigger: 'blur' }
|
{ required: true, message: '请输入负责人名称', trigger: 'blur' }
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -222,16 +221,16 @@ export default {
|
|||||||
this.$refs.log.doInit()
|
this.$refs.log.doInit()
|
||||||
},
|
},
|
||||||
checkboxT(row, rowIndex) {
|
checkboxT(row, rowIndex) {
|
||||||
return row.id !== 1
|
return row.job_id !== 1
|
||||||
},
|
},
|
||||||
/** cron表达式按钮操作 */
|
/** cron表达式按钮操作 */
|
||||||
handleShowCron() {
|
handleShowCron() {
|
||||||
this.expression = this.form.cronExpression
|
this.expression = this.form.cron_expression
|
||||||
this.openCron = true
|
this.openCron = true
|
||||||
},
|
},
|
||||||
/** 确定后回传值 */
|
/** 确定后回传值 */
|
||||||
crontabFill(value) {
|
crontabFill(value) {
|
||||||
this.form.cronExpression = value
|
this.form.cron_expression = value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,34 +2,34 @@
|
|||||||
<el-dialog :visible.sync="dialog" append-to-body title="执行日志" width="88%">
|
<el-dialog :visible.sync="dialog" append-to-body title="执行日志" width="88%">
|
||||||
<!-- 搜索 -->
|
<!-- 搜索 -->
|
||||||
<div class="head-container">
|
<div class="head-container">
|
||||||
<el-input v-model="query.jobName" clearable size="mini" placeholder="输入任务名称搜索" style="width: 200px;" class="filter-item" @keyup.enter.native="toQuery" />
|
<el-input v-model="query.job_name" clearable size="mini" placeholder="输入任务名称搜索" style="width: 200px;" class="filter-item" @keyup.enter.native="toQuery" />
|
||||||
<date-range-picker v-model="query.createTime" class="date-item" />
|
<date-range-picker v-model="query.createTime" class="date-item" />
|
||||||
<el-select v-model="query.isSuccess" placeholder="日志状态" clearable size="mini" class="filter-item" style="width: 110px" @change="toQuery">
|
<el-select v-model="query.is_success" placeholder="日志状态" clearable size="mini" class="filter-item" style="width: 110px" @change="toQuery">
|
||||||
<el-option v-for="item in enabledTypeOptions" :key="item.key" :label="item.display_name" :value="item.key" />
|
<el-option v-for="item in enabledTypeOptions" :key="item.key" :label="item.display_name" :value="item.key" />
|
||||||
</el-select>
|
</el-select>
|
||||||
<el-button class="filter-item" size="mini" type="success" icon="el-icon-search" @click="toQuery">搜索</el-button>
|
<el-button class="filter-item" size="mini" type="success" icon="el-icon-search" @click="toQuery">搜索</el-button>
|
||||||
</div>
|
</div>
|
||||||
<!--表格渲染-->
|
<!--表格渲染-->
|
||||||
<el-table v-loading="loading" :data="data" style="width: 100%;margin-top: -10px;">
|
<el-table v-loading="loading" :data="data" style="width: 100%;margin-top: -10px;">
|
||||||
<el-table-column show-overflow-tooltip prop="jobName" label="任务名称" />
|
<el-table-column show-overflow-tooltip prop="job_name" label="任务名称" />
|
||||||
<el-table-column show-overflow-tooltip prop="beanName" label="Bean名称" />
|
<el-table-column show-overflow-tooltip prop="bean_name" label="Bean名称" />
|
||||||
<el-table-column show-overflow-tooltip prop="methodName" label="执行方法" />
|
<el-table-column show-overflow-tooltip prop="method_name" label="执行方法" />
|
||||||
<el-table-column show-overflow-tooltip prop="params" width="120px" label="参数" />
|
<el-table-column show-overflow-tooltip prop="params" width="120px" label="参数" />
|
||||||
<el-table-column show-overflow-tooltip prop="cronExpression" label="cron表达式" />
|
<el-table-column show-overflow-tooltip prop="cron_expression" label="cron表达式" />
|
||||||
<el-table-column prop="createTime" label="异常详情" width="110px">
|
<el-table-column prop="create_time" label="异常详情" width="110px">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<el-button v-show="scope.row.exceptionDetail" size="mini" type="text" @click="info(scope.row.exceptionDetail)">查看详情</el-button>
|
<el-button v-show="scope.row.exception_detail" size="mini" type="text" @click="info(scope.row.exception_detail)">查看详情</el-button>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column show-overflow-tooltip align="center" prop="time" width="100px" label="耗时(毫秒)" />
|
<el-table-column show-overflow-tooltip align="center" prop="time" width="100px" label="耗时(毫秒)" />
|
||||||
<el-table-column align="center" prop="isSuccess" width="80px" label="状态">
|
<el-table-column align="center" prop="is_success" width="80px" label="状态">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<el-tag :type="scope.row.isSuccess ? 'success' : 'danger'">{{ scope.row.isSuccess ? '成功' : '失败' }}</el-tag>
|
<el-tag :type="scope.row.is_success ? 'success' : 'danger'">{{ scope.row.is_success ? '成功' : '失败' }}</el-tag>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column min-width="100" show-overflow-tooltip prop="createTime" label="创建日期">
|
<el-table-column min-width="100" show-overflow-tooltip prop="create_time" label="创建日期">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<span>{{ parseTime(scope.row.createTime) }}</span>
|
<span>{{ parseTime(scope.row.create_time) }}</span>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
</el-table>
|
</el-table>
|
||||||
@@ -60,8 +60,8 @@ export default {
|
|||||||
title: '任务日志',
|
title: '任务日志',
|
||||||
errorInfo: '', errorDialog: false,
|
errorInfo: '', errorDialog: false,
|
||||||
enabledTypeOptions: [
|
enabledTypeOptions: [
|
||||||
{ key: 'true', display_name: '成功' },
|
{ key: '1', display_name: '成功' },
|
||||||
{ key: 'false', display_name: '失败' }
|
{ key: '0', display_name: '失败' }
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user