mirror of https://gitee.com/stylefeng/roses
【timer】整理timer模块的字段和业务
parent
0c4feb51a0
commit
20e7581c98
|
@ -6,8 +6,8 @@ import cn.stylefeng.roses.kernel.resource.api.annotation.PostResource;
|
||||||
import cn.stylefeng.roses.kernel.rule.pojo.request.BaseRequest;
|
import cn.stylefeng.roses.kernel.rule.pojo.request.BaseRequest;
|
||||||
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
|
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
|
||||||
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
|
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
|
||||||
import cn.stylefeng.roses.kernel.timer.modular.service.SysTimersService;
|
|
||||||
import cn.stylefeng.roses.kernel.timer.modular.param.SysTimersParam;
|
import cn.stylefeng.roses.kernel.timer.modular.param.SysTimersParam;
|
||||||
|
import cn.stylefeng.roses.kernel.timer.modular.service.SysTimersService;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
@ -28,39 +28,6 @@ public class SysTimersController {
|
||||||
@Resource
|
@Resource
|
||||||
private SysTimersService sysTimersService;
|
private SysTimersService sysTimersService;
|
||||||
|
|
||||||
/**
|
|
||||||
* 分页查询定时任务
|
|
||||||
*
|
|
||||||
* @author stylefeng
|
|
||||||
* @date 2020/6/30 18:26
|
|
||||||
*/
|
|
||||||
@GetResource(name = "分页查询定时任务", path = "/sysTimers/page")
|
|
||||||
public ResponseData page(SysTimersParam sysTimersParam) {
|
|
||||||
return new SuccessResponseData(sysTimersService.page(sysTimersParam));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取全部定时任务
|
|
||||||
*
|
|
||||||
* @author stylefeng
|
|
||||||
* @date 2020/6/30 18:26
|
|
||||||
*/
|
|
||||||
@GetResource(name = "获取全部定时任务", path = "/sysTimers/list")
|
|
||||||
public ResponseData list(SysTimersParam sysTimersParam) {
|
|
||||||
return new SuccessResponseData(sysTimersService.list(sysTimersParam));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查看详情定时任务
|
|
||||||
*
|
|
||||||
* @author stylefeng
|
|
||||||
* @date 2020/6/30 18:26
|
|
||||||
*/
|
|
||||||
@GetResource(name = "查看详情定时任务", path = "/sysTimers/detail")
|
|
||||||
public ResponseData detail(@Validated(SysTimersParam.detail.class) SysTimersParam sysTimersParam) {
|
|
||||||
return new SuccessResponseData(sysTimersService.detail(sysTimersParam));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加定时任务
|
* 添加定时任务
|
||||||
*
|
*
|
||||||
|
@ -73,18 +40,6 @@ public class SysTimersController {
|
||||||
return new SuccessResponseData();
|
return new SuccessResponseData();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除定时任务
|
|
||||||
*
|
|
||||||
* @author stylefeng
|
|
||||||
* @date 2020/6/30 18:26
|
|
||||||
*/
|
|
||||||
@PostResource(name = "删除定时任务", path = "/sysTimers/delete")
|
|
||||||
public ResponseData delete(@RequestBody @Validated(SysTimersParam.delete.class) SysTimersParam sysTimersParam) {
|
|
||||||
sysTimersService.delete(sysTimersParam);
|
|
||||||
return new SuccessResponseData();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 编辑定时任务
|
* 编辑定时任务
|
||||||
*
|
*
|
||||||
|
@ -98,15 +53,15 @@ public class SysTimersController {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取系统的所有任务列表
|
* 删除定时任务
|
||||||
*
|
*
|
||||||
* @author stylefeng
|
* @author stylefeng
|
||||||
* @date 2020/7/1 14:34
|
* @date 2020/6/30 18:26
|
||||||
*/
|
*/
|
||||||
@PostResource(name = "获取系统的所有任务列表", path = "/sysTimers/getActionClasses")
|
@PostResource(name = "删除定时任务", path = "/sysTimers/delete")
|
||||||
public ResponseData getActionClasses() {
|
public ResponseData delete(@RequestBody @Validated(SysTimersParam.delete.class) SysTimersParam sysTimersParam) {
|
||||||
List<String> actionClasses = sysTimersService.getActionClasses();
|
sysTimersService.delete(sysTimersParam);
|
||||||
return new SuccessResponseData(actionClasses);
|
return new SuccessResponseData();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -133,4 +88,49 @@ public class SysTimersController {
|
||||||
return new SuccessResponseData();
|
return new SuccessResponseData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查看详情定时任务
|
||||||
|
*
|
||||||
|
* @author stylefeng
|
||||||
|
* @date 2020/6/30 18:26
|
||||||
|
*/
|
||||||
|
@GetResource(name = "查看详情定时任务", path = "/sysTimers/detail")
|
||||||
|
public ResponseData detail(@Validated(SysTimersParam.detail.class) SysTimersParam sysTimersParam) {
|
||||||
|
return new SuccessResponseData(sysTimersService.detail(sysTimersParam));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询定时任务
|
||||||
|
*
|
||||||
|
* @author stylefeng
|
||||||
|
* @date 2020/6/30 18:26
|
||||||
|
*/
|
||||||
|
@GetResource(name = "分页查询定时任务", path = "/sysTimers/page")
|
||||||
|
public ResponseData page(SysTimersParam sysTimersParam) {
|
||||||
|
return new SuccessResponseData(sysTimersService.page(sysTimersParam));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取全部定时任务
|
||||||
|
*
|
||||||
|
* @author stylefeng
|
||||||
|
* @date 2020/6/30 18:26
|
||||||
|
*/
|
||||||
|
@GetResource(name = "获取全部定时任务", path = "/sysTimers/list")
|
||||||
|
public ResponseData list(SysTimersParam sysTimersParam) {
|
||||||
|
return new SuccessResponseData(sysTimersService.list(sysTimersParam));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取系统的所有任务列表
|
||||||
|
*
|
||||||
|
* @author stylefeng
|
||||||
|
* @date 2020/7/1 14:34
|
||||||
|
*/
|
||||||
|
@PostResource(name = "获取系统的所有任务列表", path = "/sysTimers/getActionClasses")
|
||||||
|
public ResponseData getActionClasses() {
|
||||||
|
List<String> actionClasses = sysTimersService.getActionClasses();
|
||||||
|
return new SuccessResponseData(actionClasses);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,10 +1,10 @@
|
||||||
package cn.stylefeng.roses.kernel.timer.modular.entity;
|
package cn.stylefeng.roses.kernel.timer.modular.entity;
|
||||||
|
|
||||||
|
import cn.stylefeng.roses.kernel.db.api.pojo.entity.BaseEntity;
|
||||||
import com.baomidou.mybatisplus.annotation.IdType;
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import cn.stylefeng.roses.kernel.db.api.pojo.entity.BaseEntity;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
@ -22,8 +22,8 @@ public class SysTimers extends BaseEntity {
|
||||||
/**
|
/**
|
||||||
* 定时器id
|
* 定时器id
|
||||||
*/
|
*/
|
||||||
@TableId(type = IdType.ASSIGN_ID)
|
@TableId(value = "timer_id", type = IdType.ASSIGN_ID)
|
||||||
private Long id;
|
private Long timerId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 任务名称
|
* 任务名称
|
||||||
|
@ -32,7 +32,7 @@ public class SysTimers extends BaseEntity {
|
||||||
private String timerName;
|
private String timerName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 执行任务的class的类名(实现了TimerTaskRunner接口的类的全称)
|
* 执行任务的class的类名(实现了TimerAction接口的类的全称)
|
||||||
*/
|
*/
|
||||||
@TableField("action_class")
|
@TableField("action_class")
|
||||||
private String actionClass;
|
private String actionClass;
|
||||||
|
@ -44,7 +44,7 @@ public class SysTimers extends BaseEntity {
|
||||||
private String cron;
|
private String cron;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 状态(字典 1运行 2停止)
|
* 状态:1-运行,2-停止
|
||||||
*/
|
*/
|
||||||
@TableField("job_status")
|
@TableField("job_status")
|
||||||
private Integer jobStatus;
|
private Integer jobStatus;
|
||||||
|
@ -55,4 +55,10 @@ public class SysTimers extends BaseEntity {
|
||||||
@TableField("remark")
|
@TableField("remark")
|
||||||
private String remark;
|
private String remark;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否删除:Y-被删除,N-未删除
|
||||||
|
*/
|
||||||
|
@TableField("del_flag")
|
||||||
|
private String delFlag;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,25 +20,25 @@ public class SysTimersParam extends BaseRequest {
|
||||||
/**
|
/**
|
||||||
* 定时器id
|
* 定时器id
|
||||||
*/
|
*/
|
||||||
@NotNull(message = "主键id不能为空,请检查id字段", groups = {edit.class, detail.class, delete.class, groupOne.class})
|
@NotNull(message = "主键timerId不能为空", groups = {edit.class, detail.class, delete.class, groupOne.class})
|
||||||
private Long id;
|
private Long timerId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 任务名称
|
* 任务名称
|
||||||
*/
|
*/
|
||||||
@NotBlank(message = "任务名称不能为空,请检查timerName字段", groups = {add.class, edit.class})
|
@NotBlank(message = "任务名称不能为空", groups = {add.class, edit.class})
|
||||||
private String timerName;
|
private String timerName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 执行任务的class的类名(实现了TimerTaskRunner接口的类的全称)
|
* 执行任务的class的类名(实现了TimerTaskRunner接口的类的全称)
|
||||||
*/
|
*/
|
||||||
@NotBlank(message = "任务的class的类名不能为空,请检查actionClass字段", groups = {add.class, edit.class})
|
@NotBlank(message = "任务的class的类名不能为空", groups = {add.class, edit.class})
|
||||||
private String actionClass;
|
private String actionClass;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 定时任务表达式
|
* 定时任务表达式
|
||||||
*/
|
*/
|
||||||
@NotBlank(message = "定时任务表达式不能为空,请检查cron字段", groups = {add.class, edit.class})
|
@NotBlank(message = "定时任务表达式不能为空", groups = {add.class, edit.class})
|
||||||
private String cron;
|
private String cron;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package cn.stylefeng.roses.kernel.timer.modular.service;
|
package cn.stylefeng.roses.kernel.timer.modular.service;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
|
||||||
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
|
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
|
||||||
import cn.stylefeng.roses.kernel.timer.modular.entity.SysTimers;
|
import cn.stylefeng.roses.kernel.timer.modular.entity.SysTimers;
|
||||||
import cn.stylefeng.roses.kernel.timer.modular.param.SysTimersParam;
|
import cn.stylefeng.roses.kernel.timer.modular.param.SysTimersParam;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -15,6 +15,61 @@ import java.util.List;
|
||||||
*/
|
*/
|
||||||
public interface SysTimersService extends IService<SysTimers> {
|
public interface SysTimersService extends IService<SysTimers> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加定时任务
|
||||||
|
*
|
||||||
|
* @param sysTimersParam 添加参数
|
||||||
|
* @author stylefeng
|
||||||
|
* @date 2020/6/30 18:26
|
||||||
|
*/
|
||||||
|
void add(SysTimersParam sysTimersParam);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 编辑定时任务
|
||||||
|
*
|
||||||
|
* @param sysTimersParam 编辑参数
|
||||||
|
* @author stylefeng
|
||||||
|
* @date 2020/6/30 18:26
|
||||||
|
*/
|
||||||
|
void edit(SysTimersParam sysTimersParam);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除定时任务
|
||||||
|
*
|
||||||
|
* @param sysTimersParam 删除参数
|
||||||
|
* @author stylefeng
|
||||||
|
* @date 2020/6/30 18:26
|
||||||
|
*/
|
||||||
|
void delete(SysTimersParam sysTimersParam);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 启动任务
|
||||||
|
*
|
||||||
|
* @param sysTimersParam 启动参数
|
||||||
|
* @author stylefeng
|
||||||
|
* @date 2020/7/1 14:36
|
||||||
|
*/
|
||||||
|
void start(SysTimersParam sysTimersParam);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 停止任务
|
||||||
|
*
|
||||||
|
* @param sysTimersParam 停止参数
|
||||||
|
* @author stylefeng
|
||||||
|
* @date 2020/7/1 14:36
|
||||||
|
*/
|
||||||
|
void stop(SysTimersParam sysTimersParam);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查看详情定时任务
|
||||||
|
*
|
||||||
|
* @param sysTimersParam 查看参数
|
||||||
|
* @return 定时任务
|
||||||
|
* @author stylefeng
|
||||||
|
* @date 2020/6/30 18:26
|
||||||
|
*/
|
||||||
|
SysTimers detail(SysTimersParam sysTimersParam);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分页查询定时任务
|
* 分页查询定时任务
|
||||||
*
|
*
|
||||||
|
@ -35,61 +90,6 @@ public interface SysTimersService extends IService<SysTimers> {
|
||||||
*/
|
*/
|
||||||
List<SysTimers> list(SysTimersParam sysTimersParam);
|
List<SysTimers> list(SysTimersParam sysTimersParam);
|
||||||
|
|
||||||
/**
|
|
||||||
* 添加定时任务
|
|
||||||
*
|
|
||||||
* @param sysTimersParam 添加参数
|
|
||||||
* @author stylefeng
|
|
||||||
* @date 2020/6/30 18:26
|
|
||||||
*/
|
|
||||||
void add(SysTimersParam sysTimersParam);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除定时任务
|
|
||||||
*
|
|
||||||
* @param sysTimersParam 删除参数
|
|
||||||
* @author stylefeng
|
|
||||||
* @date 2020/6/30 18:26
|
|
||||||
*/
|
|
||||||
void delete(SysTimersParam sysTimersParam);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 编辑定时任务
|
|
||||||
*
|
|
||||||
* @param sysTimersParam 编辑参数
|
|
||||||
* @author stylefeng
|
|
||||||
* @date 2020/6/30 18:26
|
|
||||||
*/
|
|
||||||
void edit(SysTimersParam sysTimersParam);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查看详情定时任务
|
|
||||||
*
|
|
||||||
* @param sysTimersParam 查看参数
|
|
||||||
* @return 定时任务
|
|
||||||
* @author stylefeng
|
|
||||||
* @date 2020/6/30 18:26
|
|
||||||
*/
|
|
||||||
SysTimers detail(SysTimersParam sysTimersParam);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 启动任务
|
|
||||||
*
|
|
||||||
* @param sysTimersParam 启动参数
|
|
||||||
* @author stylefeng
|
|
||||||
* @date 2020/7/1 14:36
|
|
||||||
*/
|
|
||||||
void start(SysTimersParam sysTimersParam);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 停止任务
|
|
||||||
*
|
|
||||||
* @param sysTimersParam 停止参数
|
|
||||||
* @author stylefeng
|
|
||||||
* @date 2020/7/1 14:36
|
|
||||||
*/
|
|
||||||
void stop(SysTimersParam sysTimersParam);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取所有可执行的任务列表
|
* 获取所有可执行的任务列表
|
||||||
*
|
*
|
||||||
|
|
|
@ -6,6 +6,17 @@ import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.cron.CronUtil;
|
import cn.hutool.cron.CronUtil;
|
||||||
import cn.hutool.extra.spring.SpringUtil;
|
import cn.hutool.extra.spring.SpringUtil;
|
||||||
|
import cn.stylefeng.roses.kernel.db.api.factory.PageFactory;
|
||||||
|
import cn.stylefeng.roses.kernel.db.api.factory.PageResultFactory;
|
||||||
|
import cn.stylefeng.roses.kernel.db.api.pojo.entity.BaseEntity;
|
||||||
|
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
|
||||||
|
import cn.stylefeng.roses.kernel.rule.enums.YesOrNotEnum;
|
||||||
|
import cn.stylefeng.roses.kernel.timer.api.TimerAction;
|
||||||
|
import cn.stylefeng.roses.kernel.timer.api.TimerExeService;
|
||||||
|
import cn.stylefeng.roses.kernel.timer.api.enums.TimerJobStatusEnum;
|
||||||
|
import cn.stylefeng.roses.kernel.timer.api.exception.TimerException;
|
||||||
|
import cn.stylefeng.roses.kernel.timer.api.exception.enums.TimerExceptionEnum;
|
||||||
|
import cn.stylefeng.roses.kernel.timer.modular.entity.SysTimers;
|
||||||
import cn.stylefeng.roses.kernel.timer.modular.mapper.SysTimersMapper;
|
import cn.stylefeng.roses.kernel.timer.modular.mapper.SysTimersMapper;
|
||||||
import cn.stylefeng.roses.kernel.timer.modular.param.SysTimersParam;
|
import cn.stylefeng.roses.kernel.timer.modular.param.SysTimersParam;
|
||||||
import cn.stylefeng.roses.kernel.timer.modular.service.SysTimersService;
|
import cn.stylefeng.roses.kernel.timer.modular.service.SysTimersService;
|
||||||
|
@ -13,15 +24,6 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import cn.stylefeng.roses.kernel.db.api.factory.PageFactory;
|
|
||||||
import cn.stylefeng.roses.kernel.db.api.factory.PageResultFactory;
|
|
||||||
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
|
|
||||||
import cn.stylefeng.roses.kernel.timer.api.TimerAction;
|
|
||||||
import cn.stylefeng.roses.kernel.timer.api.TimerExeService;
|
|
||||||
import cn.stylefeng.roses.kernel.timer.api.enums.TimerJobStatusEnum;
|
|
||||||
import cn.stylefeng.roses.kernel.timer.api.exception.TimerException;
|
|
||||||
import cn.stylefeng.roses.kernel.timer.api.exception.enums.TimerExceptionEnum;
|
|
||||||
import cn.stylefeng.roses.kernel.timer.modular.entity.SysTimers;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
@ -43,46 +45,6 @@ public class SysTimersServiceImpl extends ServiceImpl<SysTimersMapper, SysTimers
|
||||||
@Resource
|
@Resource
|
||||||
private TimerExeService timerExeService;
|
private TimerExeService timerExeService;
|
||||||
|
|
||||||
@Override
|
|
||||||
public PageResult<SysTimers> page(SysTimersParam sysTimersParam) {
|
|
||||||
|
|
||||||
// 构造条件
|
|
||||||
LambdaQueryWrapper<SysTimers> queryWrapper = new LambdaQueryWrapper<>();
|
|
||||||
if (ObjectUtil.isNotNull(sysTimersParam)) {
|
|
||||||
// 拼接查询条件-任务名称
|
|
||||||
if (ObjectUtil.isNotEmpty(sysTimersParam.getTimerName())) {
|
|
||||||
queryWrapper.like(SysTimers::getTimerName, sysTimersParam.getTimerName());
|
|
||||||
}
|
|
||||||
// 拼接查询条件-状态(字典 1运行 2停止)
|
|
||||||
if (ObjectUtil.isNotEmpty(sysTimersParam.getJobStatus())) {
|
|
||||||
queryWrapper.like(SysTimers::getJobStatus, sysTimersParam.getJobStatus());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 查询分页结果
|
|
||||||
Page<SysTimers> page = this.page(PageFactory.defaultPage(), queryWrapper);
|
|
||||||
return PageResultFactory.createPageResult(page);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<SysTimers> list(SysTimersParam sysTimersParam) {
|
|
||||||
|
|
||||||
// 构造条件
|
|
||||||
LambdaQueryWrapper<SysTimers> queryWrapper = new LambdaQueryWrapper<>();
|
|
||||||
if (ObjectUtil.isNotNull(sysTimersParam)) {
|
|
||||||
// 拼接查询条件-任务名称
|
|
||||||
if (ObjectUtil.isNotEmpty(sysTimersParam.getTimerName())) {
|
|
||||||
queryWrapper.like(SysTimers::getTimerName, sysTimersParam.getTimerName());
|
|
||||||
}
|
|
||||||
// 拼接查询条件-状态(字典 1运行 2停止)
|
|
||||||
if (ObjectUtil.isNotEmpty(sysTimersParam.getJobStatus())) {
|
|
||||||
queryWrapper.like(SysTimers::getJobStatus, sysTimersParam.getJobStatus());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.list(queryWrapper);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void add(SysTimersParam sysTimersParam) {
|
public void add(SysTimersParam sysTimersParam) {
|
||||||
|
|
||||||
|
@ -96,15 +58,6 @@ public class SysTimersServiceImpl extends ServiceImpl<SysTimersMapper, SysTimers
|
||||||
this.save(sysTimers);
|
this.save(sysTimers);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void delete(SysTimersParam sysTimersParam) {
|
|
||||||
|
|
||||||
// 先停止id为参数id的定时器
|
|
||||||
CronUtil.remove(String.valueOf(sysTimersParam.getId()));
|
|
||||||
|
|
||||||
this.removeById(sysTimersParam.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
@Override
|
@Override
|
||||||
public void edit(SysTimersParam sysTimersParam) {
|
public void edit(SysTimersParam sysTimersParam) {
|
||||||
|
@ -119,17 +72,25 @@ public class SysTimersServiceImpl extends ServiceImpl<SysTimersMapper, SysTimers
|
||||||
|
|
||||||
// 如果任务正在运行,则停掉这个任务,从新运行任务
|
// 如果任务正在运行,则停掉这个任务,从新运行任务
|
||||||
if (jobStatus.equals(TimerJobStatusEnum.RUNNING.getCode())) {
|
if (jobStatus.equals(TimerJobStatusEnum.RUNNING.getCode())) {
|
||||||
CronUtil.remove(String.valueOf(oldTimer.getId()));
|
CronUtil.remove(String.valueOf(oldTimer.getTimerId()));
|
||||||
timerExeService.startTimer(
|
timerExeService.startTimer(
|
||||||
String.valueOf(sysTimersParam.getId()),
|
String.valueOf(sysTimersParam.getTimerId()),
|
||||||
sysTimersParam.getCron(),
|
sysTimersParam.getCron(),
|
||||||
sysTimersParam.getActionClass());
|
sysTimersParam.getActionClass());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SysTimers detail(SysTimersParam sysTimersParam) {
|
public void delete(SysTimersParam sysTimersParam) {
|
||||||
return this.querySysTimers(sysTimersParam);
|
|
||||||
|
// 先停止id为参数id的定时器
|
||||||
|
CronUtil.remove(String.valueOf(sysTimersParam.getTimerId()));
|
||||||
|
|
||||||
|
// 逻辑删除定时任务
|
||||||
|
LambdaUpdateWrapper<SysTimers> updateWrapper = new LambdaUpdateWrapper<>();
|
||||||
|
updateWrapper.set(SysTimers::getDelFlag, YesOrNotEnum.Y.getCode());
|
||||||
|
updateWrapper.eq(SysTimers::getTimerId, sysTimersParam.getTimerId());
|
||||||
|
this.update(updateWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
@ -139,12 +100,12 @@ public class SysTimersServiceImpl extends ServiceImpl<SysTimersMapper, SysTimers
|
||||||
// 更新库中的状态
|
// 更新库中的状态
|
||||||
LambdaUpdateWrapper<SysTimers> wrapper = new LambdaUpdateWrapper<>();
|
LambdaUpdateWrapper<SysTimers> wrapper = new LambdaUpdateWrapper<>();
|
||||||
wrapper.set(SysTimers::getJobStatus, TimerJobStatusEnum.RUNNING.getCode())
|
wrapper.set(SysTimers::getJobStatus, TimerJobStatusEnum.RUNNING.getCode())
|
||||||
.eq(SysTimers::getId, sysTimersParam.getId());
|
.eq(SysTimers::getTimerId, sysTimersParam.getTimerId());
|
||||||
this.update(wrapper);
|
this.update(wrapper);
|
||||||
|
|
||||||
// 添加定时任务调度
|
// 添加定时任务调度
|
||||||
SysTimers sysTimers = this.querySysTimers(sysTimersParam);
|
SysTimers sysTimers = this.querySysTimers(sysTimersParam);
|
||||||
timerExeService.startTimer(String.valueOf(sysTimers.getId()), sysTimers.getCron(), sysTimers.getActionClass());
|
timerExeService.startTimer(String.valueOf(sysTimers.getTimerId()), sysTimers.getCron(), sysTimers.getActionClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
@ -154,12 +115,34 @@ public class SysTimersServiceImpl extends ServiceImpl<SysTimersMapper, SysTimers
|
||||||
// 更新库中的状态
|
// 更新库中的状态
|
||||||
LambdaUpdateWrapper<SysTimers> wrapper = new LambdaUpdateWrapper<>();
|
LambdaUpdateWrapper<SysTimers> wrapper = new LambdaUpdateWrapper<>();
|
||||||
wrapper.set(SysTimers::getJobStatus, TimerJobStatusEnum.STOP.getCode())
|
wrapper.set(SysTimers::getJobStatus, TimerJobStatusEnum.STOP.getCode())
|
||||||
.eq(SysTimers::getId, sysTimersParam.getId());
|
.eq(SysTimers::getTimerId, sysTimersParam.getTimerId());
|
||||||
this.update(wrapper);
|
this.update(wrapper);
|
||||||
|
|
||||||
// 关闭定时任务调度
|
// 关闭定时任务调度
|
||||||
SysTimers sysTimers = this.querySysTimers(sysTimersParam);
|
SysTimers sysTimers = this.querySysTimers(sysTimersParam);
|
||||||
timerExeService.stopTimer(String.valueOf(sysTimers.getId()));
|
timerExeService.stopTimer(String.valueOf(sysTimers.getTimerId()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SysTimers detail(SysTimersParam sysTimersParam) {
|
||||||
|
return this.querySysTimers(sysTimersParam);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageResult<SysTimers> page(SysTimersParam sysTimersParam) {
|
||||||
|
|
||||||
|
// 构造条件
|
||||||
|
LambdaQueryWrapper<SysTimers> queryWrapper = createWrapper(sysTimersParam);
|
||||||
|
|
||||||
|
// 查询分页结果
|
||||||
|
Page<SysTimers> page = this.page(PageFactory.defaultPage(), queryWrapper);
|
||||||
|
return PageResultFactory.createPageResult(page);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SysTimers> list(SysTimersParam sysTimersParam) {
|
||||||
|
LambdaQueryWrapper<SysTimers> queryWrapper = createWrapper(sysTimersParam);
|
||||||
|
return this.list(queryWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -182,12 +165,42 @@ public class SysTimersServiceImpl extends ServiceImpl<SysTimersMapper, SysTimers
|
||||||
* @date 2020/6/30 18:26
|
* @date 2020/6/30 18:26
|
||||||
*/
|
*/
|
||||||
private SysTimers querySysTimers(SysTimersParam sysTimersParam) {
|
private SysTimers querySysTimers(SysTimersParam sysTimersParam) {
|
||||||
SysTimers sysTimers = this.getById(sysTimersParam.getId());
|
SysTimers sysTimers = this.getById(sysTimersParam.getTimerId());
|
||||||
if (ObjectUtil.isEmpty(sysTimers)) {
|
if (ObjectUtil.isEmpty(sysTimers) || sysTimers.getDelFlag().equals(YesOrNotEnum.Y.getCode())) {
|
||||||
String userTip = StrUtil.format(TimerExceptionEnum.JOB_DETAIL_NOT_FOUND.getUserTip(), sysTimersParam.getId());
|
String userTip = StrUtil.format(TimerExceptionEnum.JOB_DETAIL_NOT_FOUND.getUserTip(), sysTimersParam.getTimerId());
|
||||||
throw new TimerException(TimerExceptionEnum.JOB_DETAIL_NOT_FOUND, userTip);
|
throw new TimerException(TimerExceptionEnum.JOB_DETAIL_NOT_FOUND, userTip);
|
||||||
}
|
}
|
||||||
return sysTimers;
|
return sysTimers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建wrapper
|
||||||
|
*
|
||||||
|
* @author fengshuonan
|
||||||
|
* @date 2020/12/19 17:02
|
||||||
|
*/
|
||||||
|
private LambdaQueryWrapper<SysTimers> createWrapper(SysTimersParam sysTimersParam) {
|
||||||
|
|
||||||
|
LambdaQueryWrapper<SysTimers> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
|
||||||
|
if (ObjectUtil.isNotNull(sysTimersParam)) {
|
||||||
|
// 拼接查询条件-任务名称
|
||||||
|
if (ObjectUtil.isNotEmpty(sysTimersParam.getTimerName())) {
|
||||||
|
queryWrapper.like(SysTimers::getTimerName, sysTimersParam.getTimerName());
|
||||||
|
}
|
||||||
|
// 拼接查询条件-状态(字典 1运行 2停止)
|
||||||
|
if (ObjectUtil.isNotEmpty(sysTimersParam.getJobStatus())) {
|
||||||
|
queryWrapper.like(SysTimers::getJobStatus, sysTimersParam.getJobStatus());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查询未删除的
|
||||||
|
queryWrapper.ne(SysTimers::getDelFlag, YesOrNotEnum.Y.getCode());
|
||||||
|
|
||||||
|
// 按类型升序排列,同类型的排在一起
|
||||||
|
queryWrapper.orderByDesc(BaseEntity::getCreateTime);
|
||||||
|
|
||||||
|
return queryWrapper;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue