From 09d7c3dc34e39cd61eaa6014df9ccafc9c3387a8 Mon Sep 17 00:00:00 2001 From: zhizhi wu <2377881365@qq.com> Date: Fri, 23 Jul 2021 18:22:07 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E5=BA=A6=E7=B3=BB=E7=BB=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resources/application-prod.properties | 2 +- .../src/main/resources/application.properties | 2 +- scheduler/pom.xml | 31 + .../ccsens/scheduler/api/JobController.java | 49 +- .../ccsens/scheduler/bean/dto/QuartzJob.java | 107 ++ .../scheduler/bean/dto/QuartzJobModule.java | 77 - .../ccsens/scheduler/bean/dto/QueryDto.java | 27 + .../com/ccsens/scheduler/bean/po/Task.java | 216 +++ .../ccsens/scheduler/bean/po/TaskExample.java | 1361 +++++++++++++++++ .../ccsens/scheduler/persist/dao/TaskDao.java | 9 + .../scheduler/persist/mapper/TaskMapper.java | 30 + .../scheduler/service/CoreJobService.java | 73 + .../scheduler/service/ICoreJobService.java | 9 + .../ccsens/scheduler/service/IJobService.java | 46 + .../ccsens/scheduler/service/JobService.java | 134 ++ .../com/ccsens/scheduler/util/CodeEnum.java | 11 +- .../com/ccsens/scheduler/util/Constant.java | 621 +------- .../ccsens/scheduler/util/QuartzJobUtil.java | 238 +-- .../scheduler/util/RestTemplateUtil.java | 156 ++ .../com/ccsens/scheduler/util/SmsUtil.java | 59 + .../src/main/resources/config/mail.setting | 4 + .../src/main/resources/mapper_dao/TaskDao.xml | 5 + .../main/resources/mapper_raw/TaskMapper.xml | 418 +++++ scheduler/src/main/resources/mbg.xml | 2 +- 24 files changed, 2845 insertions(+), 842 deletions(-) create mode 100644 scheduler/src/main/java/com/ccsens/scheduler/bean/dto/QuartzJob.java delete mode 100644 scheduler/src/main/java/com/ccsens/scheduler/bean/dto/QuartzJobModule.java create mode 100644 scheduler/src/main/java/com/ccsens/scheduler/bean/dto/QueryDto.java create mode 100644 scheduler/src/main/java/com/ccsens/scheduler/bean/po/Task.java create mode 100644 scheduler/src/main/java/com/ccsens/scheduler/bean/po/TaskExample.java create mode 100644 scheduler/src/main/java/com/ccsens/scheduler/persist/dao/TaskDao.java create mode 100644 scheduler/src/main/java/com/ccsens/scheduler/persist/mapper/TaskMapper.java create mode 100644 scheduler/src/main/java/com/ccsens/scheduler/service/CoreJobService.java create mode 100644 scheduler/src/main/java/com/ccsens/scheduler/service/ICoreJobService.java create mode 100644 scheduler/src/main/java/com/ccsens/scheduler/service/IJobService.java create mode 100644 scheduler/src/main/java/com/ccsens/scheduler/service/JobService.java create mode 100644 scheduler/src/main/java/com/ccsens/scheduler/util/RestTemplateUtil.java create mode 100644 scheduler/src/main/java/com/ccsens/scheduler/util/SmsUtil.java create mode 100644 scheduler/src/main/resources/config/mail.setting create mode 100644 scheduler/src/main/resources/mapper_dao/TaskDao.xml create mode 100644 scheduler/src/main/resources/mapper_raw/TaskMapper.xml diff --git a/ccmq/src/main/resources/application-prod.properties b/ccmq/src/main/resources/application-prod.properties index df81c1f..1b0f520 100644 --- a/ccmq/src/main/resources/application-prod.properties +++ b/ccmq/src/main/resources/application-prod.properties @@ -14,7 +14,7 @@ spring.servlet.multipart.max-request-size=100MB spring.redis.database=0 spring.redis.host=127.0.0.1 spring.redis.port=6379 -spring.redis.password=areowqr!@43ef +spring.redis.password= spring.redis.timeout=1000ms spring.redis.jedis.pool.max-active=200 spring.redis.jedis.pool.max-wait=-1ms diff --git a/ccmq/src/main/resources/application.properties b/ccmq/src/main/resources/application.properties index 47021f7..97e42eb 100644 --- a/ccmq/src/main/resources/application.properties +++ b/ccmq/src/main/resources/application.properties @@ -1,5 +1,5 @@ # ѡ񿪷{dev|test|prod} -spring.profiles.active=dev +spring.profiles.active=prod # Ӧ spring.application.name=tall-message diff --git a/scheduler/pom.xml b/scheduler/pom.xml index 4d3d2e6..6838018 100644 --- a/scheduler/pom.xml +++ b/scheduler/pom.xml @@ -171,6 +171,37 @@ poi-ooxml 3.17 + + com.alibaba + fastjson + 1.2.62 + + + javax.mail + mail + 1.5.0-b01 + + + + + org.mybatis.generator + mybatis-generator-maven-plugin + 1.3.7 + + ${basedir}/src/main/resources/mbg.xml + true + + + + mysql + mysql-connector-java + 5.1.34 + + + + + + \ No newline at end of file diff --git a/scheduler/src/main/java/com/ccsens/scheduler/api/JobController.java b/scheduler/src/main/java/com/ccsens/scheduler/api/JobController.java index beb6457..ba2bbf4 100644 --- a/scheduler/src/main/java/com/ccsens/scheduler/api/JobController.java +++ b/scheduler/src/main/java/com/ccsens/scheduler/api/JobController.java @@ -1,6 +1,9 @@ package com.ccsens.scheduler.api; -import com.ccsens.scheduler.bean.dto.QuartzJobModule; +import com.ccsens.scheduler.bean.dto.QuartzJob; +import com.ccsens.scheduler.bean.dto.QueryDto; +import com.ccsens.scheduler.service.IJobService; +import com.ccsens.scheduler.util.CodeEnum; import com.ccsens.scheduler.util.JsonResponse; import com.ccsens.scheduler.util.QuartzJobUtil; import io.swagger.annotations.ApiImplicitParams; @@ -22,16 +25,19 @@ import javax.annotation.Resource; @RequestMapping("/job") public class JobController { + @Resource - private QuartzJobUtil quartzJobUtil; + private IJobService jobService; @ApiOperation(value = "/添加任务",notes = "") @ApiImplicitParams({ }) @RequestMapping(value="add",method = RequestMethod.POST,produces = {"application/json;charset=UTF-8"}) - public JsonResponse add(@ApiParam @Validated @RequestBody QuartzJobModule job) { - quartzJobUtil.addJob(job); - return JsonResponse.newInstance().ok(); + public JsonResponse add(@ApiParam @Validated @RequestBody QueryDto dto) { + log.info("添加任务:{}", dto); + CodeEnum codeEnum = jobService.add(dto.getParam(), dto.getUserId()); + log.info("添加任务结果:{}", codeEnum); + return JsonResponse.newInstance().ok(codeEnum); } @@ -39,8 +45,10 @@ public class JobController { @ApiImplicitParams({ }) @RequestMapping(value="modifyTime",method = RequestMethod.POST,produces = {"application/json;charset=UTF-8"}) - public JsonResponse modifyTime(@ApiParam @Validated @RequestBody QuartzJobModule job) { - quartzJobUtil.modifyJobTime(job.getJobName(), job.getJobGroupName(), job.getCron()); + public JsonResponse modifyTime(@ApiParam @Validated @RequestBody QueryDto dto) { + log.info("修改任务:{}", dto); + CodeEnum codeEnum = jobService.modify(dto.getParam(), dto.getUserId()); + log.info("修改任务结果:{}", codeEnum); return JsonResponse.newInstance().ok(); } @@ -48,28 +56,31 @@ public class JobController { @ApiImplicitParams({ }) @RequestMapping(value="pause",method = RequestMethod.POST,produces = {"application/json;charset=UTF-8"}) - public JsonResponse pause(String jobName) { - log.info("停止任务"); - quartzJobUtil.pauseJob(jobName); - return JsonResponse.newInstance().ok(); + public JsonResponse pause(@ApiParam @Validated @RequestBody QueryDto dto) { + log.info("停止任务:{}", dto); + CodeEnum codeEnum = jobService.pause(dto.getParam(), dto.getUserId()); + log.info("停止任务结果:{}", codeEnum); + return JsonResponse.newInstance().ok(codeEnum); } @ApiOperation(value = "/恢复任务",notes = "") @ApiImplicitParams({ }) @RequestMapping(value="resume",method = RequestMethod.POST,produces = {"application/json;charset=UTF-8"}) - public JsonResponse resume(String jobName) { - log.info("恢复任务"); - quartzJobUtil.removeJob(jobName); - return JsonResponse.newInstance().ok(); + public JsonResponse resume(@ApiParam @Validated @RequestBody QueryDto dto) { + log.info("恢复任务:{}", dto); + CodeEnum codeEnum = jobService.resume(dto.getParam(), dto.getUserId()); + log.info("恢复任务结果:{}", codeEnum); + return JsonResponse.newInstance().ok(codeEnum); } @ApiOperation(value = "/移除任务",notes = "") @ApiImplicitParams({ }) @RequestMapping(value="remove",method = RequestMethod.POST,produces = {"application/json;charset=UTF-8"}) - public JsonResponse remove(String jobName) { - log.info("移除任务"); - quartzJobUtil.removeJob(jobName); - return JsonResponse.newInstance().ok(); + public JsonResponse remove(@ApiParam @Validated @RequestBody QueryDto dto) { + log.info("移除任务:{}", dto); + CodeEnum codeEnum = jobService.remove(dto.getParam(), dto.getUserId()); + log.info("移除任务结果:{}", dto); + return JsonResponse.newInstance().ok(codeEnum); } } diff --git a/scheduler/src/main/java/com/ccsens/scheduler/bean/dto/QuartzJob.java b/scheduler/src/main/java/com/ccsens/scheduler/bean/dto/QuartzJob.java new file mode 100644 index 0000000..83253e1 --- /dev/null +++ b/scheduler/src/main/java/com/ccsens/scheduler/bean/dto/QuartzJob.java @@ -0,0 +1,107 @@ +package com.ccsens.scheduler.bean.dto; + +import cn.hutool.core.util.StrUtil; +import com.ccsens.scheduler.util.Constant; +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.quartz.Job; +import org.quartz.JobDataMap; +import org.quartz.JobExecutionContext; +import org.springframework.util.ClassUtils; + +import javax.validation.constraints.NotEmpty; +import java.util.Date; + +/** + * @description: + * @author: whj + * @time: 2021/6/30 16:00 + */ +@Data +public class QuartzJob { + + @Data + @ApiModel("任务") + public static class Job{ + @NotEmpty + @ApiModelProperty("job名称") + private String jobName; + @ApiModelProperty("job组名") + private String jobGroupName = Constant.Quartz.QZ_JOB_GROUP_NAME; + @NotEmpty + @ApiModelProperty("定时器名称") + private String triggerName; + @ApiModelProperty("定时器组名") + private String triggerGroupName = Constant.Quartz.QZ_TRIGGER_GROUP_NAME; + @ApiModelProperty("触发器开始时间") + private long startTime; + @ApiModelProperty("触发器结束时间") + private long endTime; + @ApiModelProperty("执行定时任务的具体操作") + private byte job = 0; + @ApiModelProperty("自动迁移 0:不自动迁移 1:自动迁移") + private byte autoMove = 1; + @NotEmpty + @ApiModelProperty("cron表达式") + private String cron; + @ApiModelProperty("misfire对应的处理规则") + private String misfirePolicy = "withMisfireHandlingInstructionDoNothing"; + @ApiModelProperty("job的附加信息") + private JobDataMap jobDataMap = new JobDataMap(); + /** + * 校验 + * @return + */ + public boolean verify(){ + return !(StrUtil.isEmpty(jobName) + || StrUtil.isEmpty(jobGroupName) + || StrUtil.isEmpty(triggerName) + || StrUtil.isEmpty(triggerGroupName) + || StrUtil.isEmpty(cron) + || !ClassUtils.hasMethod(Job.class, "execute", JobExecutionContext.class) + ); + } + } + + @Data + @ApiModel("任务名称") + public static class Update { + @ApiModelProperty("定时器名称") + private String triggerName; + @ApiModelProperty("定时器组名") + private String triggerGroupName = Constant.Quartz.QZ_TRIGGER_GROUP_NAME; + @ApiModelProperty("表达式") + private String cron; + @ApiModelProperty("misfire对应的处理规则") + private String misfirePolicy = "withMisfireHandlingInstructionDoNothing"; + @ApiModelProperty("触发器开始时间") + private long startTime; + @ApiModelProperty("触发器结束时间") + private long endTime; + } + + @Data + @ApiModel("任务名称") + public static class Name{ + @ApiModelProperty("任务名") + private String jobName; + @ApiModelProperty("job组名") + private String jobGroupName = Constant.Quartz.QZ_JOB_GROUP_NAME; + } + + @Data + @ApiModel("删除任务") + public static class Del{ + @ApiModelProperty("任务名") + private String jobName; + @ApiModelProperty("job组名") + private String jobGroupName = Constant.Quartz.QZ_JOB_GROUP_NAME; + @ApiModelProperty("定时器名称") + private String triggerName; + @ApiModelProperty("定时器组名") + private String triggerGroupName = Constant.Quartz.QZ_TRIGGER_GROUP_NAME; + } + +} diff --git a/scheduler/src/main/java/com/ccsens/scheduler/bean/dto/QuartzJobModule.java b/scheduler/src/main/java/com/ccsens/scheduler/bean/dto/QuartzJobModule.java deleted file mode 100644 index b13a0f8..0000000 --- a/scheduler/src/main/java/com/ccsens/scheduler/bean/dto/QuartzJobModule.java +++ /dev/null @@ -1,77 +0,0 @@ -package com.ccsens.scheduler.bean.dto; - -import cn.hutool.core.util.StrUtil; -import com.ccsens.scheduler.util.Constant; -import com.fasterxml.jackson.annotation.JsonFormat; -import lombok.Data; -import org.quartz.Job; -import org.quartz.JobDataMap; -import org.quartz.JobExecutionContext; -import org.springframework.util.ClassUtils; - -import java.util.Date; - -/** - * @description: - * @author: whj - * @time: 2021/6/30 16:00 - */ -@Data -public class QuartzJobModule { - /** - * 触发器开始时间 - */ - @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") - private Date startTime; - /** - * 触发器结束时间 - */ - @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") - private Date endTime; - /** - * job名称 - */ - private String jobName; - /** - * job组名 - */ - private String jobGroupName = Constant.Quartz.QZ_JOB_GROUP_NAME; - /** - * 定时器名称 - */ - private String triggerName; - /** - * 定时器组名 - */ - private String triggerGroupName = Constant.Quartz.QZ_TRIGGER_GROUP_NAME; - /** - * 执行定时任务的具体操作 - */ - private String jobClass; - /** - * cron表达式 - */ - private String cron; - /** - * misfire对应的处理规则 - */ - private String misfirePolicy = "withMisfireHandlingInstructionDoNothing"; - /** - * job的附加信息 - */ - private JobDataMap jobDataMap = new JobDataMap(); - /** - * 校验 - * @return - */ - public boolean verify(){ - return !(StrUtil.isEmpty(jobName) - || StrUtil.isEmpty(jobGroupName) - || StrUtil.isEmpty(triggerName) - || StrUtil.isEmpty(triggerGroupName) - || StrUtil.isEmpty(cron) - || !ClassUtils.hasMethod(Job.class, "execute", JobExecutionContext.class) - ); - } - -} diff --git a/scheduler/src/main/java/com/ccsens/scheduler/bean/dto/QueryDto.java b/scheduler/src/main/java/com/ccsens/scheduler/bean/dto/QueryDto.java new file mode 100644 index 0000000..a6d0144 --- /dev/null +++ b/scheduler/src/main/java/com/ccsens/scheduler/bean/dto/QueryDto.java @@ -0,0 +1,27 @@ +package com.ccsens.scheduler.bean.dto; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.Valid; + +/** + * @program: ptpro + * @description: 编辑病人信息 + * @author: wu huijuan + * @create: 2019/10/30 14:33 + */ +@ApiModel +@Data +public class QueryDto { + @ApiModelProperty("真正的请求参数") + @Valid + private T param; + @ApiModelProperty("登录用户ID 前端不为userId赋值") + private Long userId; + @ApiModelProperty("用户名") + private String userName; + @ApiModelProperty("头像") + private String avatarUrl; +} diff --git a/scheduler/src/main/java/com/ccsens/scheduler/bean/po/Task.java b/scheduler/src/main/java/com/ccsens/scheduler/bean/po/Task.java new file mode 100644 index 0000000..0c6178e --- /dev/null +++ b/scheduler/src/main/java/com/ccsens/scheduler/bean/po/Task.java @@ -0,0 +1,216 @@ +package com.ccsens.scheduler.bean.po; + +import java.io.Serializable; +import java.util.Date; + +public class Task implements Serializable { + private Long id; + + private String jobName; + + private String jobGroupName; + + private String triggerName; + + private String triggerGroupName; + + private String cron; + + private String misfirePolicy; + + private Byte job; + + private Long startTime; + + private Long endTime; + + private Byte autoMove; + + private Byte notifyWay; + + private String notifyUrl; + + private String notifyParam; + + private Long appId; + + private Date createdAt; + + private Date updatedAt; + + private Byte recStatus; + + private static final long serialVersionUID = 1L; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getJobName() { + return jobName; + } + + public void setJobName(String jobName) { + this.jobName = jobName == null ? null : jobName.trim(); + } + + public String getJobGroupName() { + return jobGroupName; + } + + public void setJobGroupName(String jobGroupName) { + this.jobGroupName = jobGroupName == null ? null : jobGroupName.trim(); + } + + public String getTriggerName() { + return triggerName; + } + + public void setTriggerName(String triggerName) { + this.triggerName = triggerName == null ? null : triggerName.trim(); + } + + public String getTriggerGroupName() { + return triggerGroupName; + } + + public void setTriggerGroupName(String triggerGroupName) { + this.triggerGroupName = triggerGroupName == null ? null : triggerGroupName.trim(); + } + + public String getCron() { + return cron; + } + + public void setCron(String cron) { + this.cron = cron == null ? null : cron.trim(); + } + + public String getMisfirePolicy() { + return misfirePolicy; + } + + public void setMisfirePolicy(String misfirePolicy) { + this.misfirePolicy = misfirePolicy == null ? null : misfirePolicy.trim(); + } + + public Byte getJob() { + return job; + } + + public void setJob(Byte job) { + this.job = job; + } + + public Long getStartTime() { + return startTime; + } + + public void setStartTime(Long startTime) { + this.startTime = startTime; + } + + public Long getEndTime() { + return endTime; + } + + public void setEndTime(Long endTime) { + this.endTime = endTime; + } + + public Byte getAutoMove() { + return autoMove; + } + + public void setAutoMove(Byte autoMove) { + this.autoMove = autoMove; + } + + public Byte getNotifyWay() { + return notifyWay; + } + + public void setNotifyWay(Byte notifyWay) { + this.notifyWay = notifyWay; + } + + public String getNotifyUrl() { + return notifyUrl; + } + + public void setNotifyUrl(String notifyUrl) { + this.notifyUrl = notifyUrl == null ? null : notifyUrl.trim(); + } + + public String getNotifyParam() { + return notifyParam; + } + + public void setNotifyParam(String notifyParam) { + this.notifyParam = notifyParam == null ? null : notifyParam.trim(); + } + + public Long getAppId() { + return appId; + } + + public void setAppId(Long appId) { + this.appId = appId; + } + + public Date getCreatedAt() { + return createdAt; + } + + public void setCreatedAt(Date createdAt) { + this.createdAt = createdAt; + } + + public Date getUpdatedAt() { + return updatedAt; + } + + public void setUpdatedAt(Date updatedAt) { + this.updatedAt = updatedAt; + } + + public Byte getRecStatus() { + return recStatus; + } + + public void setRecStatus(Byte recStatus) { + this.recStatus = recStatus; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(getClass().getSimpleName()); + sb.append(" ["); + sb.append("Hash = ").append(hashCode()); + sb.append(", id=").append(id); + sb.append(", jobName=").append(jobName); + sb.append(", jobGroupName=").append(jobGroupName); + sb.append(", triggerName=").append(triggerName); + sb.append(", triggerGroupName=").append(triggerGroupName); + sb.append(", cron=").append(cron); + sb.append(", misfirePolicy=").append(misfirePolicy); + sb.append(", job=").append(job); + sb.append(", startTime=").append(startTime); + sb.append(", endTime=").append(endTime); + sb.append(", autoMove=").append(autoMove); + sb.append(", notifyWay=").append(notifyWay); + sb.append(", notifyUrl=").append(notifyUrl); + sb.append(", notifyParam=").append(notifyParam); + sb.append(", appId=").append(appId); + sb.append(", createdAt=").append(createdAt); + sb.append(", updatedAt=").append(updatedAt); + sb.append(", recStatus=").append(recStatus); + sb.append("]"); + return sb.toString(); + } +} \ No newline at end of file diff --git a/scheduler/src/main/java/com/ccsens/scheduler/bean/po/TaskExample.java b/scheduler/src/main/java/com/ccsens/scheduler/bean/po/TaskExample.java new file mode 100644 index 0000000..d101426 --- /dev/null +++ b/scheduler/src/main/java/com/ccsens/scheduler/bean/po/TaskExample.java @@ -0,0 +1,1361 @@ +package com.ccsens.scheduler.bean.po; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +public class TaskExample { + protected String orderByClause; + + protected boolean distinct; + + protected List oredCriteria; + + public TaskExample() { + oredCriteria = new ArrayList(); + } + + public void setOrderByClause(String orderByClause) { + this.orderByClause = orderByClause; + } + + public String getOrderByClause() { + return orderByClause; + } + + public void setDistinct(boolean distinct) { + this.distinct = distinct; + } + + public boolean isDistinct() { + return distinct; + } + + public List getOredCriteria() { + return oredCriteria; + } + + public void or(Criteria criteria) { + oredCriteria.add(criteria); + } + + public Criteria or() { + Criteria criteria = createCriteriaInternal(); + oredCriteria.add(criteria); + return criteria; + } + + public Criteria createCriteria() { + Criteria criteria = createCriteriaInternal(); + if (oredCriteria.size() == 0) { + oredCriteria.add(criteria); + } + return criteria; + } + + protected Criteria createCriteriaInternal() { + Criteria criteria = new Criteria(); + return criteria; + } + + public void clear() { + oredCriteria.clear(); + orderByClause = null; + distinct = false; + } + + protected abstract static class GeneratedCriteria { + protected List criteria; + + protected GeneratedCriteria() { + super(); + criteria = new ArrayList(); + } + + public boolean isValid() { + return criteria.size() > 0; + } + + public List getAllCriteria() { + return criteria; + } + + public List getCriteria() { + return criteria; + } + + protected void addCriterion(String condition) { + if (condition == null) { + throw new RuntimeException("Value for condition cannot be null"); + } + criteria.add(new Criterion(condition)); + } + + protected void addCriterion(String condition, Object value, String property) { + if (value == null) { + throw new RuntimeException("Value for " + property + " cannot be null"); + } + criteria.add(new Criterion(condition, value)); + } + + protected void addCriterion(String condition, Object value1, Object value2, String property) { + if (value1 == null || value2 == null) { + throw new RuntimeException("Between values for " + property + " cannot be null"); + } + criteria.add(new Criterion(condition, value1, value2)); + } + + public Criteria andIdIsNull() { + addCriterion("id is null"); + return (Criteria) this; + } + + public Criteria andIdIsNotNull() { + addCriterion("id is not null"); + return (Criteria) this; + } + + public Criteria andIdEqualTo(Long value) { + addCriterion("id =", value, "id"); + return (Criteria) this; + } + + public Criteria andIdNotEqualTo(Long value) { + addCriterion("id <>", value, "id"); + return (Criteria) this; + } + + public Criteria andIdGreaterThan(Long value) { + addCriterion("id >", value, "id"); + return (Criteria) this; + } + + public Criteria andIdGreaterThanOrEqualTo(Long value) { + addCriterion("id >=", value, "id"); + return (Criteria) this; + } + + public Criteria andIdLessThan(Long value) { + addCriterion("id <", value, "id"); + return (Criteria) this; + } + + public Criteria andIdLessThanOrEqualTo(Long value) { + addCriterion("id <=", value, "id"); + return (Criteria) this; + } + + public Criteria andIdIn(List values) { + addCriterion("id in", values, "id"); + return (Criteria) this; + } + + public Criteria andIdNotIn(List values) { + addCriterion("id not in", values, "id"); + return (Criteria) this; + } + + public Criteria andIdBetween(Long value1, Long value2) { + addCriterion("id between", value1, value2, "id"); + return (Criteria) this; + } + + public Criteria andIdNotBetween(Long value1, Long value2) { + addCriterion("id not between", value1, value2, "id"); + return (Criteria) this; + } + + public Criteria andJobNameIsNull() { + addCriterion("job_name is null"); + return (Criteria) this; + } + + public Criteria andJobNameIsNotNull() { + addCriterion("job_name is not null"); + return (Criteria) this; + } + + public Criteria andJobNameEqualTo(String value) { + addCriterion("job_name =", value, "jobName"); + return (Criteria) this; + } + + public Criteria andJobNameNotEqualTo(String value) { + addCriterion("job_name <>", value, "jobName"); + return (Criteria) this; + } + + public Criteria andJobNameGreaterThan(String value) { + addCriterion("job_name >", value, "jobName"); + return (Criteria) this; + } + + public Criteria andJobNameGreaterThanOrEqualTo(String value) { + addCriterion("job_name >=", value, "jobName"); + return (Criteria) this; + } + + public Criteria andJobNameLessThan(String value) { + addCriterion("job_name <", value, "jobName"); + return (Criteria) this; + } + + public Criteria andJobNameLessThanOrEqualTo(String value) { + addCriterion("job_name <=", value, "jobName"); + return (Criteria) this; + } + + public Criteria andJobNameLike(String value) { + addCriterion("job_name like", value, "jobName"); + return (Criteria) this; + } + + public Criteria andJobNameNotLike(String value) { + addCriterion("job_name not like", value, "jobName"); + return (Criteria) this; + } + + public Criteria andJobNameIn(List values) { + addCriterion("job_name in", values, "jobName"); + return (Criteria) this; + } + + public Criteria andJobNameNotIn(List values) { + addCriterion("job_name not in", values, "jobName"); + return (Criteria) this; + } + + public Criteria andJobNameBetween(String value1, String value2) { + addCriterion("job_name between", value1, value2, "jobName"); + return (Criteria) this; + } + + public Criteria andJobNameNotBetween(String value1, String value2) { + addCriterion("job_name not between", value1, value2, "jobName"); + return (Criteria) this; + } + + public Criteria andJobGroupNameIsNull() { + addCriterion("job_group_name is null"); + return (Criteria) this; + } + + public Criteria andJobGroupNameIsNotNull() { + addCriterion("job_group_name is not null"); + return (Criteria) this; + } + + public Criteria andJobGroupNameEqualTo(String value) { + addCriterion("job_group_name =", value, "jobGroupName"); + return (Criteria) this; + } + + public Criteria andJobGroupNameNotEqualTo(String value) { + addCriterion("job_group_name <>", value, "jobGroupName"); + return (Criteria) this; + } + + public Criteria andJobGroupNameGreaterThan(String value) { + addCriterion("job_group_name >", value, "jobGroupName"); + return (Criteria) this; + } + + public Criteria andJobGroupNameGreaterThanOrEqualTo(String value) { + addCriterion("job_group_name >=", value, "jobGroupName"); + return (Criteria) this; + } + + public Criteria andJobGroupNameLessThan(String value) { + addCriterion("job_group_name <", value, "jobGroupName"); + return (Criteria) this; + } + + public Criteria andJobGroupNameLessThanOrEqualTo(String value) { + addCriterion("job_group_name <=", value, "jobGroupName"); + return (Criteria) this; + } + + public Criteria andJobGroupNameLike(String value) { + addCriterion("job_group_name like", value, "jobGroupName"); + return (Criteria) this; + } + + public Criteria andJobGroupNameNotLike(String value) { + addCriterion("job_group_name not like", value, "jobGroupName"); + return (Criteria) this; + } + + public Criteria andJobGroupNameIn(List values) { + addCriterion("job_group_name in", values, "jobGroupName"); + return (Criteria) this; + } + + public Criteria andJobGroupNameNotIn(List values) { + addCriterion("job_group_name not in", values, "jobGroupName"); + return (Criteria) this; + } + + public Criteria andJobGroupNameBetween(String value1, String value2) { + addCriterion("job_group_name between", value1, value2, "jobGroupName"); + return (Criteria) this; + } + + public Criteria andJobGroupNameNotBetween(String value1, String value2) { + addCriterion("job_group_name not between", value1, value2, "jobGroupName"); + return (Criteria) this; + } + + public Criteria andTriggerNameIsNull() { + addCriterion("trigger_name is null"); + return (Criteria) this; + } + + public Criteria andTriggerNameIsNotNull() { + addCriterion("trigger_name is not null"); + return (Criteria) this; + } + + public Criteria andTriggerNameEqualTo(String value) { + addCriterion("trigger_name =", value, "triggerName"); + return (Criteria) this; + } + + public Criteria andTriggerNameNotEqualTo(String value) { + addCriterion("trigger_name <>", value, "triggerName"); + return (Criteria) this; + } + + public Criteria andTriggerNameGreaterThan(String value) { + addCriterion("trigger_name >", value, "triggerName"); + return (Criteria) this; + } + + public Criteria andTriggerNameGreaterThanOrEqualTo(String value) { + addCriterion("trigger_name >=", value, "triggerName"); + return (Criteria) this; + } + + public Criteria andTriggerNameLessThan(String value) { + addCriterion("trigger_name <", value, "triggerName"); + return (Criteria) this; + } + + public Criteria andTriggerNameLessThanOrEqualTo(String value) { + addCriterion("trigger_name <=", value, "triggerName"); + return (Criteria) this; + } + + public Criteria andTriggerNameLike(String value) { + addCriterion("trigger_name like", value, "triggerName"); + return (Criteria) this; + } + + public Criteria andTriggerNameNotLike(String value) { + addCriterion("trigger_name not like", value, "triggerName"); + return (Criteria) this; + } + + public Criteria andTriggerNameIn(List values) { + addCriterion("trigger_name in", values, "triggerName"); + return (Criteria) this; + } + + public Criteria andTriggerNameNotIn(List values) { + addCriterion("trigger_name not in", values, "triggerName"); + return (Criteria) this; + } + + public Criteria andTriggerNameBetween(String value1, String value2) { + addCriterion("trigger_name between", value1, value2, "triggerName"); + return (Criteria) this; + } + + public Criteria andTriggerNameNotBetween(String value1, String value2) { + addCriterion("trigger_name not between", value1, value2, "triggerName"); + return (Criteria) this; + } + + public Criteria andTriggerGroupNameIsNull() { + addCriterion("trigger_group_name is null"); + return (Criteria) this; + } + + public Criteria andTriggerGroupNameIsNotNull() { + addCriterion("trigger_group_name is not null"); + return (Criteria) this; + } + + public Criteria andTriggerGroupNameEqualTo(String value) { + addCriterion("trigger_group_name =", value, "triggerGroupName"); + return (Criteria) this; + } + + public Criteria andTriggerGroupNameNotEqualTo(String value) { + addCriterion("trigger_group_name <>", value, "triggerGroupName"); + return (Criteria) this; + } + + public Criteria andTriggerGroupNameGreaterThan(String value) { + addCriterion("trigger_group_name >", value, "triggerGroupName"); + return (Criteria) this; + } + + public Criteria andTriggerGroupNameGreaterThanOrEqualTo(String value) { + addCriterion("trigger_group_name >=", value, "triggerGroupName"); + return (Criteria) this; + } + + public Criteria andTriggerGroupNameLessThan(String value) { + addCriterion("trigger_group_name <", value, "triggerGroupName"); + return (Criteria) this; + } + + public Criteria andTriggerGroupNameLessThanOrEqualTo(String value) { + addCriterion("trigger_group_name <=", value, "triggerGroupName"); + return (Criteria) this; + } + + public Criteria andTriggerGroupNameLike(String value) { + addCriterion("trigger_group_name like", value, "triggerGroupName"); + return (Criteria) this; + } + + public Criteria andTriggerGroupNameNotLike(String value) { + addCriterion("trigger_group_name not like", value, "triggerGroupName"); + return (Criteria) this; + } + + public Criteria andTriggerGroupNameIn(List values) { + addCriterion("trigger_group_name in", values, "triggerGroupName"); + return (Criteria) this; + } + + public Criteria andTriggerGroupNameNotIn(List values) { + addCriterion("trigger_group_name not in", values, "triggerGroupName"); + return (Criteria) this; + } + + public Criteria andTriggerGroupNameBetween(String value1, String value2) { + addCriterion("trigger_group_name between", value1, value2, "triggerGroupName"); + return (Criteria) this; + } + + public Criteria andTriggerGroupNameNotBetween(String value1, String value2) { + addCriterion("trigger_group_name not between", value1, value2, "triggerGroupName"); + return (Criteria) this; + } + + public Criteria andCronIsNull() { + addCriterion("cron is null"); + return (Criteria) this; + } + + public Criteria andCronIsNotNull() { + addCriterion("cron is not null"); + return (Criteria) this; + } + + public Criteria andCronEqualTo(String value) { + addCriterion("cron =", value, "cron"); + return (Criteria) this; + } + + public Criteria andCronNotEqualTo(String value) { + addCriterion("cron <>", value, "cron"); + return (Criteria) this; + } + + public Criteria andCronGreaterThan(String value) { + addCriterion("cron >", value, "cron"); + return (Criteria) this; + } + + public Criteria andCronGreaterThanOrEqualTo(String value) { + addCriterion("cron >=", value, "cron"); + return (Criteria) this; + } + + public Criteria andCronLessThan(String value) { + addCriterion("cron <", value, "cron"); + return (Criteria) this; + } + + public Criteria andCronLessThanOrEqualTo(String value) { + addCriterion("cron <=", value, "cron"); + return (Criteria) this; + } + + public Criteria andCronLike(String value) { + addCriterion("cron like", value, "cron"); + return (Criteria) this; + } + + public Criteria andCronNotLike(String value) { + addCriterion("cron not like", value, "cron"); + return (Criteria) this; + } + + public Criteria andCronIn(List values) { + addCriterion("cron in", values, "cron"); + return (Criteria) this; + } + + public Criteria andCronNotIn(List values) { + addCriterion("cron not in", values, "cron"); + return (Criteria) this; + } + + public Criteria andCronBetween(String value1, String value2) { + addCriterion("cron between", value1, value2, "cron"); + return (Criteria) this; + } + + public Criteria andCronNotBetween(String value1, String value2) { + addCriterion("cron not between", value1, value2, "cron"); + return (Criteria) this; + } + + public Criteria andMisfirePolicyIsNull() { + addCriterion("misfire_policy is null"); + return (Criteria) this; + } + + public Criteria andMisfirePolicyIsNotNull() { + addCriterion("misfire_policy is not null"); + return (Criteria) this; + } + + public Criteria andMisfirePolicyEqualTo(String value) { + addCriterion("misfire_policy =", value, "misfirePolicy"); + return (Criteria) this; + } + + public Criteria andMisfirePolicyNotEqualTo(String value) { + addCriterion("misfire_policy <>", value, "misfirePolicy"); + return (Criteria) this; + } + + public Criteria andMisfirePolicyGreaterThan(String value) { + addCriterion("misfire_policy >", value, "misfirePolicy"); + return (Criteria) this; + } + + public Criteria andMisfirePolicyGreaterThanOrEqualTo(String value) { + addCriterion("misfire_policy >=", value, "misfirePolicy"); + return (Criteria) this; + } + + public Criteria andMisfirePolicyLessThan(String value) { + addCriterion("misfire_policy <", value, "misfirePolicy"); + return (Criteria) this; + } + + public Criteria andMisfirePolicyLessThanOrEqualTo(String value) { + addCriterion("misfire_policy <=", value, "misfirePolicy"); + return (Criteria) this; + } + + public Criteria andMisfirePolicyLike(String value) { + addCriterion("misfire_policy like", value, "misfirePolicy"); + return (Criteria) this; + } + + public Criteria andMisfirePolicyNotLike(String value) { + addCriterion("misfire_policy not like", value, "misfirePolicy"); + return (Criteria) this; + } + + public Criteria andMisfirePolicyIn(List values) { + addCriterion("misfire_policy in", values, "misfirePolicy"); + return (Criteria) this; + } + + public Criteria andMisfirePolicyNotIn(List values) { + addCriterion("misfire_policy not in", values, "misfirePolicy"); + return (Criteria) this; + } + + public Criteria andMisfirePolicyBetween(String value1, String value2) { + addCriterion("misfire_policy between", value1, value2, "misfirePolicy"); + return (Criteria) this; + } + + public Criteria andMisfirePolicyNotBetween(String value1, String value2) { + addCriterion("misfire_policy not between", value1, value2, "misfirePolicy"); + return (Criteria) this; + } + + public Criteria andJobIsNull() { + addCriterion("job is null"); + return (Criteria) this; + } + + public Criteria andJobIsNotNull() { + addCriterion("job is not null"); + return (Criteria) this; + } + + public Criteria andJobEqualTo(Byte value) { + addCriterion("job =", value, "job"); + return (Criteria) this; + } + + public Criteria andJobNotEqualTo(Byte value) { + addCriterion("job <>", value, "job"); + return (Criteria) this; + } + + public Criteria andJobGreaterThan(Byte value) { + addCriterion("job >", value, "job"); + return (Criteria) this; + } + + public Criteria andJobGreaterThanOrEqualTo(Byte value) { + addCriterion("job >=", value, "job"); + return (Criteria) this; + } + + public Criteria andJobLessThan(Byte value) { + addCriterion("job <", value, "job"); + return (Criteria) this; + } + + public Criteria andJobLessThanOrEqualTo(Byte value) { + addCriterion("job <=", value, "job"); + return (Criteria) this; + } + + public Criteria andJobIn(List values) { + addCriterion("job in", values, "job"); + return (Criteria) this; + } + + public Criteria andJobNotIn(List values) { + addCriterion("job not in", values, "job"); + return (Criteria) this; + } + + public Criteria andJobBetween(Byte value1, Byte value2) { + addCriterion("job between", value1, value2, "job"); + return (Criteria) this; + } + + public Criteria andJobNotBetween(Byte value1, Byte value2) { + addCriterion("job not between", value1, value2, "job"); + return (Criteria) this; + } + + public Criteria andStartTimeIsNull() { + addCriterion("start_time is null"); + return (Criteria) this; + } + + public Criteria andStartTimeIsNotNull() { + addCriterion("start_time is not null"); + return (Criteria) this; + } + + public Criteria andStartTimeEqualTo(Long value) { + addCriterion("start_time =", value, "startTime"); + return (Criteria) this; + } + + public Criteria andStartTimeNotEqualTo(Long value) { + addCriterion("start_time <>", value, "startTime"); + return (Criteria) this; + } + + public Criteria andStartTimeGreaterThan(Long value) { + addCriterion("start_time >", value, "startTime"); + return (Criteria) this; + } + + public Criteria andStartTimeGreaterThanOrEqualTo(Long value) { + addCriterion("start_time >=", value, "startTime"); + return (Criteria) this; + } + + public Criteria andStartTimeLessThan(Long value) { + addCriterion("start_time <", value, "startTime"); + return (Criteria) this; + } + + public Criteria andStartTimeLessThanOrEqualTo(Long value) { + addCriterion("start_time <=", value, "startTime"); + return (Criteria) this; + } + + public Criteria andStartTimeIn(List values) { + addCriterion("start_time in", values, "startTime"); + return (Criteria) this; + } + + public Criteria andStartTimeNotIn(List values) { + addCriterion("start_time not in", values, "startTime"); + return (Criteria) this; + } + + public Criteria andStartTimeBetween(Long value1, Long value2) { + addCriterion("start_time between", value1, value2, "startTime"); + return (Criteria) this; + } + + public Criteria andStartTimeNotBetween(Long value1, Long value2) { + addCriterion("start_time not between", value1, value2, "startTime"); + return (Criteria) this; + } + + public Criteria andEndTimeIsNull() { + addCriterion("end_time is null"); + return (Criteria) this; + } + + public Criteria andEndTimeIsNotNull() { + addCriterion("end_time is not null"); + return (Criteria) this; + } + + public Criteria andEndTimeEqualTo(Long value) { + addCriterion("end_time =", value, "endTime"); + return (Criteria) this; + } + + public Criteria andEndTimeNotEqualTo(Long value) { + addCriterion("end_time <>", value, "endTime"); + return (Criteria) this; + } + + public Criteria andEndTimeGreaterThan(Long value) { + addCriterion("end_time >", value, "endTime"); + return (Criteria) this; + } + + public Criteria andEndTimeGreaterThanOrEqualTo(Long value) { + addCriterion("end_time >=", value, "endTime"); + return (Criteria) this; + } + + public Criteria andEndTimeLessThan(Long value) { + addCriterion("end_time <", value, "endTime"); + return (Criteria) this; + } + + public Criteria andEndTimeLessThanOrEqualTo(Long value) { + addCriterion("end_time <=", value, "endTime"); + return (Criteria) this; + } + + public Criteria andEndTimeIn(List values) { + addCriterion("end_time in", values, "endTime"); + return (Criteria) this; + } + + public Criteria andEndTimeNotIn(List values) { + addCriterion("end_time not in", values, "endTime"); + return (Criteria) this; + } + + public Criteria andEndTimeBetween(Long value1, Long value2) { + addCriterion("end_time between", value1, value2, "endTime"); + return (Criteria) this; + } + + public Criteria andEndTimeNotBetween(Long value1, Long value2) { + addCriterion("end_time not between", value1, value2, "endTime"); + return (Criteria) this; + } + + public Criteria andAutoMoveIsNull() { + addCriterion("auto_move is null"); + return (Criteria) this; + } + + public Criteria andAutoMoveIsNotNull() { + addCriterion("auto_move is not null"); + return (Criteria) this; + } + + public Criteria andAutoMoveEqualTo(Byte value) { + addCriterion("auto_move =", value, "autoMove"); + return (Criteria) this; + } + + public Criteria andAutoMoveNotEqualTo(Byte value) { + addCriterion("auto_move <>", value, "autoMove"); + return (Criteria) this; + } + + public Criteria andAutoMoveGreaterThan(Byte value) { + addCriterion("auto_move >", value, "autoMove"); + return (Criteria) this; + } + + public Criteria andAutoMoveGreaterThanOrEqualTo(Byte value) { + addCriterion("auto_move >=", value, "autoMove"); + return (Criteria) this; + } + + public Criteria andAutoMoveLessThan(Byte value) { + addCriterion("auto_move <", value, "autoMove"); + return (Criteria) this; + } + + public Criteria andAutoMoveLessThanOrEqualTo(Byte value) { + addCriterion("auto_move <=", value, "autoMove"); + return (Criteria) this; + } + + public Criteria andAutoMoveIn(List values) { + addCriterion("auto_move in", values, "autoMove"); + return (Criteria) this; + } + + public Criteria andAutoMoveNotIn(List values) { + addCriterion("auto_move not in", values, "autoMove"); + return (Criteria) this; + } + + public Criteria andAutoMoveBetween(Byte value1, Byte value2) { + addCriterion("auto_move between", value1, value2, "autoMove"); + return (Criteria) this; + } + + public Criteria andAutoMoveNotBetween(Byte value1, Byte value2) { + addCriterion("auto_move not between", value1, value2, "autoMove"); + return (Criteria) this; + } + + public Criteria andNotifyWayIsNull() { + addCriterion("notify_way is null"); + return (Criteria) this; + } + + public Criteria andNotifyWayIsNotNull() { + addCriterion("notify_way is not null"); + return (Criteria) this; + } + + public Criteria andNotifyWayEqualTo(Byte value) { + addCriterion("notify_way =", value, "notifyWay"); + return (Criteria) this; + } + + public Criteria andNotifyWayNotEqualTo(Byte value) { + addCriterion("notify_way <>", value, "notifyWay"); + return (Criteria) this; + } + + public Criteria andNotifyWayGreaterThan(Byte value) { + addCriterion("notify_way >", value, "notifyWay"); + return (Criteria) this; + } + + public Criteria andNotifyWayGreaterThanOrEqualTo(Byte value) { + addCriterion("notify_way >=", value, "notifyWay"); + return (Criteria) this; + } + + public Criteria andNotifyWayLessThan(Byte value) { + addCriterion("notify_way <", value, "notifyWay"); + return (Criteria) this; + } + + public Criteria andNotifyWayLessThanOrEqualTo(Byte value) { + addCriterion("notify_way <=", value, "notifyWay"); + return (Criteria) this; + } + + public Criteria andNotifyWayIn(List values) { + addCriterion("notify_way in", values, "notifyWay"); + return (Criteria) this; + } + + public Criteria andNotifyWayNotIn(List values) { + addCriterion("notify_way not in", values, "notifyWay"); + return (Criteria) this; + } + + public Criteria andNotifyWayBetween(Byte value1, Byte value2) { + addCriterion("notify_way between", value1, value2, "notifyWay"); + return (Criteria) this; + } + + public Criteria andNotifyWayNotBetween(Byte value1, Byte value2) { + addCriterion("notify_way not between", value1, value2, "notifyWay"); + return (Criteria) this; + } + + public Criteria andNotifyUrlIsNull() { + addCriterion("notify_url is null"); + return (Criteria) this; + } + + public Criteria andNotifyUrlIsNotNull() { + addCriterion("notify_url is not null"); + return (Criteria) this; + } + + public Criteria andNotifyUrlEqualTo(String value) { + addCriterion("notify_url =", value, "notifyUrl"); + return (Criteria) this; + } + + public Criteria andNotifyUrlNotEqualTo(String value) { + addCriterion("notify_url <>", value, "notifyUrl"); + return (Criteria) this; + } + + public Criteria andNotifyUrlGreaterThan(String value) { + addCriterion("notify_url >", value, "notifyUrl"); + return (Criteria) this; + } + + public Criteria andNotifyUrlGreaterThanOrEqualTo(String value) { + addCriterion("notify_url >=", value, "notifyUrl"); + return (Criteria) this; + } + + public Criteria andNotifyUrlLessThan(String value) { + addCriterion("notify_url <", value, "notifyUrl"); + return (Criteria) this; + } + + public Criteria andNotifyUrlLessThanOrEqualTo(String value) { + addCriterion("notify_url <=", value, "notifyUrl"); + return (Criteria) this; + } + + public Criteria andNotifyUrlLike(String value) { + addCriterion("notify_url like", value, "notifyUrl"); + return (Criteria) this; + } + + public Criteria andNotifyUrlNotLike(String value) { + addCriterion("notify_url not like", value, "notifyUrl"); + return (Criteria) this; + } + + public Criteria andNotifyUrlIn(List values) { + addCriterion("notify_url in", values, "notifyUrl"); + return (Criteria) this; + } + + public Criteria andNotifyUrlNotIn(List values) { + addCriterion("notify_url not in", values, "notifyUrl"); + return (Criteria) this; + } + + public Criteria andNotifyUrlBetween(String value1, String value2) { + addCriterion("notify_url between", value1, value2, "notifyUrl"); + return (Criteria) this; + } + + public Criteria andNotifyUrlNotBetween(String value1, String value2) { + addCriterion("notify_url not between", value1, value2, "notifyUrl"); + return (Criteria) this; + } + + public Criteria andNotifyParamIsNull() { + addCriterion("notify_param is null"); + return (Criteria) this; + } + + public Criteria andNotifyParamIsNotNull() { + addCriterion("notify_param is not null"); + return (Criteria) this; + } + + public Criteria andNotifyParamEqualTo(String value) { + addCriterion("notify_param =", value, "notifyParam"); + return (Criteria) this; + } + + public Criteria andNotifyParamNotEqualTo(String value) { + addCriterion("notify_param <>", value, "notifyParam"); + return (Criteria) this; + } + + public Criteria andNotifyParamGreaterThan(String value) { + addCriterion("notify_param >", value, "notifyParam"); + return (Criteria) this; + } + + public Criteria andNotifyParamGreaterThanOrEqualTo(String value) { + addCriterion("notify_param >=", value, "notifyParam"); + return (Criteria) this; + } + + public Criteria andNotifyParamLessThan(String value) { + addCriterion("notify_param <", value, "notifyParam"); + return (Criteria) this; + } + + public Criteria andNotifyParamLessThanOrEqualTo(String value) { + addCriterion("notify_param <=", value, "notifyParam"); + return (Criteria) this; + } + + public Criteria andNotifyParamLike(String value) { + addCriterion("notify_param like", value, "notifyParam"); + return (Criteria) this; + } + + public Criteria andNotifyParamNotLike(String value) { + addCriterion("notify_param not like", value, "notifyParam"); + return (Criteria) this; + } + + public Criteria andNotifyParamIn(List values) { + addCriterion("notify_param in", values, "notifyParam"); + return (Criteria) this; + } + + public Criteria andNotifyParamNotIn(List values) { + addCriterion("notify_param not in", values, "notifyParam"); + return (Criteria) this; + } + + public Criteria andNotifyParamBetween(String value1, String value2) { + addCriterion("notify_param between", value1, value2, "notifyParam"); + return (Criteria) this; + } + + public Criteria andNotifyParamNotBetween(String value1, String value2) { + addCriterion("notify_param not between", value1, value2, "notifyParam"); + return (Criteria) this; + } + + public Criteria andAppIdIsNull() { + addCriterion("app_id is null"); + return (Criteria) this; + } + + public Criteria andAppIdIsNotNull() { + addCriterion("app_id is not null"); + return (Criteria) this; + } + + public Criteria andAppIdEqualTo(Long value) { + addCriterion("app_id =", value, "appId"); + return (Criteria) this; + } + + public Criteria andAppIdNotEqualTo(Long value) { + addCriterion("app_id <>", value, "appId"); + return (Criteria) this; + } + + public Criteria andAppIdGreaterThan(Long value) { + addCriterion("app_id >", value, "appId"); + return (Criteria) this; + } + + public Criteria andAppIdGreaterThanOrEqualTo(Long value) { + addCriterion("app_id >=", value, "appId"); + return (Criteria) this; + } + + public Criteria andAppIdLessThan(Long value) { + addCriterion("app_id <", value, "appId"); + return (Criteria) this; + } + + public Criteria andAppIdLessThanOrEqualTo(Long value) { + addCriterion("app_id <=", value, "appId"); + return (Criteria) this; + } + + public Criteria andAppIdIn(List values) { + addCriterion("app_id in", values, "appId"); + return (Criteria) this; + } + + public Criteria andAppIdNotIn(List values) { + addCriterion("app_id not in", values, "appId"); + return (Criteria) this; + } + + public Criteria andAppIdBetween(Long value1, Long value2) { + addCriterion("app_id between", value1, value2, "appId"); + return (Criteria) this; + } + + public Criteria andAppIdNotBetween(Long value1, Long value2) { + addCriterion("app_id not between", value1, value2, "appId"); + return (Criteria) this; + } + + public Criteria andCreatedAtIsNull() { + addCriterion("created_at is null"); + return (Criteria) this; + } + + public Criteria andCreatedAtIsNotNull() { + addCriterion("created_at is not null"); + return (Criteria) this; + } + + public Criteria andCreatedAtEqualTo(Date value) { + addCriterion("created_at =", value, "createdAt"); + return (Criteria) this; + } + + public Criteria andCreatedAtNotEqualTo(Date value) { + addCriterion("created_at <>", value, "createdAt"); + return (Criteria) this; + } + + public Criteria andCreatedAtGreaterThan(Date value) { + addCriterion("created_at >", value, "createdAt"); + return (Criteria) this; + } + + public Criteria andCreatedAtGreaterThanOrEqualTo(Date value) { + addCriterion("created_at >=", value, "createdAt"); + return (Criteria) this; + } + + public Criteria andCreatedAtLessThan(Date value) { + addCriterion("created_at <", value, "createdAt"); + return (Criteria) this; + } + + public Criteria andCreatedAtLessThanOrEqualTo(Date value) { + addCriterion("created_at <=", value, "createdAt"); + return (Criteria) this; + } + + public Criteria andCreatedAtIn(List values) { + addCriterion("created_at in", values, "createdAt"); + return (Criteria) this; + } + + public Criteria andCreatedAtNotIn(List values) { + addCriterion("created_at not in", values, "createdAt"); + return (Criteria) this; + } + + public Criteria andCreatedAtBetween(Date value1, Date value2) { + addCriterion("created_at between", value1, value2, "createdAt"); + return (Criteria) this; + } + + public Criteria andCreatedAtNotBetween(Date value1, Date value2) { + addCriterion("created_at not between", value1, value2, "createdAt"); + return (Criteria) this; + } + + public Criteria andUpdatedAtIsNull() { + addCriterion("updated_at is null"); + return (Criteria) this; + } + + public Criteria andUpdatedAtIsNotNull() { + addCriterion("updated_at is not null"); + return (Criteria) this; + } + + public Criteria andUpdatedAtEqualTo(Date value) { + addCriterion("updated_at =", value, "updatedAt"); + return (Criteria) this; + } + + public Criteria andUpdatedAtNotEqualTo(Date value) { + addCriterion("updated_at <>", value, "updatedAt"); + return (Criteria) this; + } + + public Criteria andUpdatedAtGreaterThan(Date value) { + addCriterion("updated_at >", value, "updatedAt"); + return (Criteria) this; + } + + public Criteria andUpdatedAtGreaterThanOrEqualTo(Date value) { + addCriterion("updated_at >=", value, "updatedAt"); + return (Criteria) this; + } + + public Criteria andUpdatedAtLessThan(Date value) { + addCriterion("updated_at <", value, "updatedAt"); + return (Criteria) this; + } + + public Criteria andUpdatedAtLessThanOrEqualTo(Date value) { + addCriterion("updated_at <=", value, "updatedAt"); + return (Criteria) this; + } + + public Criteria andUpdatedAtIn(List values) { + addCriterion("updated_at in", values, "updatedAt"); + return (Criteria) this; + } + + public Criteria andUpdatedAtNotIn(List values) { + addCriterion("updated_at not in", values, "updatedAt"); + return (Criteria) this; + } + + public Criteria andUpdatedAtBetween(Date value1, Date value2) { + addCriterion("updated_at between", value1, value2, "updatedAt"); + return (Criteria) this; + } + + public Criteria andUpdatedAtNotBetween(Date value1, Date value2) { + addCriterion("updated_at not between", value1, value2, "updatedAt"); + return (Criteria) this; + } + + public Criteria andRecStatusIsNull() { + addCriterion("rec_status is null"); + return (Criteria) this; + } + + public Criteria andRecStatusIsNotNull() { + addCriterion("rec_status is not null"); + return (Criteria) this; + } + + public Criteria andRecStatusEqualTo(Byte value) { + addCriterion("rec_status =", value, "recStatus"); + return (Criteria) this; + } + + public Criteria andRecStatusNotEqualTo(Byte value) { + addCriterion("rec_status <>", value, "recStatus"); + return (Criteria) this; + } + + public Criteria andRecStatusGreaterThan(Byte value) { + addCriterion("rec_status >", value, "recStatus"); + return (Criteria) this; + } + + public Criteria andRecStatusGreaterThanOrEqualTo(Byte value) { + addCriterion("rec_status >=", value, "recStatus"); + return (Criteria) this; + } + + public Criteria andRecStatusLessThan(Byte value) { + addCriterion("rec_status <", value, "recStatus"); + return (Criteria) this; + } + + public Criteria andRecStatusLessThanOrEqualTo(Byte value) { + addCriterion("rec_status <=", value, "recStatus"); + return (Criteria) this; + } + + public Criteria andRecStatusIn(List values) { + addCriterion("rec_status in", values, "recStatus"); + return (Criteria) this; + } + + public Criteria andRecStatusNotIn(List values) { + addCriterion("rec_status not in", values, "recStatus"); + return (Criteria) this; + } + + public Criteria andRecStatusBetween(Byte value1, Byte value2) { + addCriterion("rec_status between", value1, value2, "recStatus"); + return (Criteria) this; + } + + public Criteria andRecStatusNotBetween(Byte value1, Byte value2) { + addCriterion("rec_status not between", value1, value2, "recStatus"); + return (Criteria) this; + } + } + + public static class Criteria extends GeneratedCriteria { + + protected Criteria() { + super(); + } + } + + public static class Criterion { + private String condition; + + private Object value; + + private Object secondValue; + + private boolean noValue; + + private boolean singleValue; + + private boolean betweenValue; + + private boolean listValue; + + private String typeHandler; + + public String getCondition() { + return condition; + } + + public Object getValue() { + return value; + } + + public Object getSecondValue() { + return secondValue; + } + + public boolean isNoValue() { + return noValue; + } + + public boolean isSingleValue() { + return singleValue; + } + + public boolean isBetweenValue() { + return betweenValue; + } + + public boolean isListValue() { + return listValue; + } + + public String getTypeHandler() { + return typeHandler; + } + + protected Criterion(String condition) { + super(); + this.condition = condition; + this.typeHandler = null; + this.noValue = true; + } + + protected Criterion(String condition, Object value, String typeHandler) { + super(); + this.condition = condition; + this.value = value; + this.typeHandler = typeHandler; + if (value instanceof List) { + this.listValue = true; + } else { + this.singleValue = true; + } + } + + protected Criterion(String condition, Object value) { + this(condition, value, null); + } + + protected Criterion(String condition, Object value, Object secondValue, String typeHandler) { + super(); + this.condition = condition; + this.value = value; + this.secondValue = secondValue; + this.typeHandler = typeHandler; + this.betweenValue = true; + } + + protected Criterion(String condition, Object value, Object secondValue) { + this(condition, value, secondValue, null); + } + } +} \ No newline at end of file diff --git a/scheduler/src/main/java/com/ccsens/scheduler/persist/dao/TaskDao.java b/scheduler/src/main/java/com/ccsens/scheduler/persist/dao/TaskDao.java new file mode 100644 index 0000000..f3e34e4 --- /dev/null +++ b/scheduler/src/main/java/com/ccsens/scheduler/persist/dao/TaskDao.java @@ -0,0 +1,9 @@ +package com.ccsens.scheduler.persist.dao; + +import com.ccsens.scheduler.persist.mapper.TaskMapper; + +/** + * @author wu + */ +public interface TaskDao extends TaskMapper { +} diff --git a/scheduler/src/main/java/com/ccsens/scheduler/persist/mapper/TaskMapper.java b/scheduler/src/main/java/com/ccsens/scheduler/persist/mapper/TaskMapper.java new file mode 100644 index 0000000..f06e506 --- /dev/null +++ b/scheduler/src/main/java/com/ccsens/scheduler/persist/mapper/TaskMapper.java @@ -0,0 +1,30 @@ +package com.ccsens.scheduler.persist.mapper; + +import com.ccsens.scheduler.bean.po.Task; +import com.ccsens.scheduler.bean.po.TaskExample; +import java.util.List; +import org.apache.ibatis.annotations.Param; + +public interface TaskMapper { + long countByExample(TaskExample example); + + int deleteByExample(TaskExample example); + + int deleteByPrimaryKey(Long id); + + int insert(Task record); + + int insertSelective(Task record); + + List selectByExample(TaskExample example); + + Task selectByPrimaryKey(Long id); + + int updateByExampleSelective(@Param("record") Task record, @Param("example") TaskExample example); + + int updateByExample(@Param("record") Task record, @Param("example") TaskExample example); + + int updateByPrimaryKeySelective(Task record); + + int updateByPrimaryKey(Task record); +} \ No newline at end of file diff --git a/scheduler/src/main/java/com/ccsens/scheduler/service/CoreJobService.java b/scheduler/src/main/java/com/ccsens/scheduler/service/CoreJobService.java new file mode 100644 index 0000000..fde0072 --- /dev/null +++ b/scheduler/src/main/java/com/ccsens/scheduler/service/CoreJobService.java @@ -0,0 +1,73 @@ +package com.ccsens.scheduler.service; + +import cn.hutool.core.collection.CollectionUtil; +import cn.hutool.extra.mail.Mail; +import com.alibaba.fastjson.JSONObject; +import com.ccsens.scheduler.bean.po.Task; +import com.ccsens.scheduler.bean.po.TaskExample; +import com.ccsens.scheduler.persist.dao.TaskDao; +import com.ccsens.scheduler.util.Constant; +import com.ccsens.scheduler.util.RestTemplateUtil; +import lombok.extern.slf4j.Slf4j; +import org.quartz.JobExecutionContext; +import org.quartz.JobExecutionException; +import org.quartz.JobKey; +import org.quartz.TriggerKey; +import org.springframework.amqp.rabbit.core.RabbitTemplate; +import org.springframework.scheduling.quartz.QuartzJobBean; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import javax.validation.constraints.Email; +import java.util.List; + +/** + * @description: 任务调度 + * @author: whj + * @time: 2021/7/23 10:41 + */ +@Slf4j +@Service +public class CoreJobService extends QuartzJobBean implements ICoreJobService { + @Resource + private TaskDao taskDao; + @Resource + private RabbitTemplate rabbitTemplate; + + + @Override + protected void executeInternal(JobExecutionContext context) throws JobExecutionException { + + JobKey jobKey = context.getJobDetail().getKey(); + TriggerKey triggerKey = context.getTrigger().getKey(); + log.info("【{}】执行任务:{},{}", System.currentTimeMillis(), jobKey.getName(), triggerKey.getName()); + TaskExample example = new TaskExample(); + example.createCriteria().andJobNameEqualTo(jobKey.getName()).andJobGroupNameEqualTo(jobKey.getGroup()) + .andTriggerNameEqualTo(triggerKey.getName()).andTriggerGroupNameEqualTo(triggerKey.getGroup()); + List tasks = taskDao.selectByExample(example); + if (CollectionUtil.isEmpty(tasks)) { + log.error("未找到调度任务:{},{},{},{}", jobKey.getName(), jobKey.getGroup(), triggerKey.getName(), triggerKey.getGroup()); + } + + Task task = tasks.get(0); + log.info("task:{}", task); + switch (task.getNotifyWay()) { + case Constant.NotifyWay.HTTP: + RestTemplateUtil.postBody(task.getNotifyUrl(), JSONObject.parse(task.getNotifyParam())); + break; + case Constant.NotifyWay.MQ: + rabbitTemplate.convertAndSend(task.getNotifyUrl(), task.getNotifyParam()); + break; + case Constant.NotifyWay.EMAIL: + Mail.create().setContent() + break; + case Constant.NotifyWay.SMS: + break; + default: + break; + } + + + + } +} \ No newline at end of file diff --git a/scheduler/src/main/java/com/ccsens/scheduler/service/ICoreJobService.java b/scheduler/src/main/java/com/ccsens/scheduler/service/ICoreJobService.java new file mode 100644 index 0000000..96cc21f --- /dev/null +++ b/scheduler/src/main/java/com/ccsens/scheduler/service/ICoreJobService.java @@ -0,0 +1,9 @@ +package com.ccsens.scheduler.service; + +/** + * @description: + * @author: whj + * @time: 2021/7/23 11:21 + */ +public interface ICoreJobService { +} diff --git a/scheduler/src/main/java/com/ccsens/scheduler/service/IJobService.java b/scheduler/src/main/java/com/ccsens/scheduler/service/IJobService.java new file mode 100644 index 0000000..c0bbb15 --- /dev/null +++ b/scheduler/src/main/java/com/ccsens/scheduler/service/IJobService.java @@ -0,0 +1,46 @@ +package com.ccsens.scheduler.service; + +import com.ccsens.scheduler.bean.dto.QuartzJob; +import com.ccsens.scheduler.util.CodeEnum; + +/** + * @author whj + */ +public interface IJobService { + + /** + * 添加定时任务 + * @param job 任务 + * @param userId 操作人 + * @return 结果 + */ + CodeEnum add(QuartzJob.Job job, Long userId); + /** + * 修改定时任务 + * @param job 任务 + * @param userId 操作人 + * @return 结果 + */ + CodeEnum modify(QuartzJob.Update job, Long userId); + /** + * 暂停定时任务 + * @param job 任务名 + * @param userId 操作人 + * @return 结果 + */ + CodeEnum pause(QuartzJob.Name job, Long userId); + /** + * 重启定时任务 + * @param job 任务名 + * @param userId 操作人 + * @return 结果 + */ + CodeEnum resume(QuartzJob.Name job, Long userId); + /** + * 删除定时任务 + * @param job 任务名 + * @param userId 操作人 + * @return 结果 + */ + CodeEnum remove(QuartzJob.Del job, Long userId); +} diff --git a/scheduler/src/main/java/com/ccsens/scheduler/service/JobService.java b/scheduler/src/main/java/com/ccsens/scheduler/service/JobService.java new file mode 100644 index 0000000..49b1d98 --- /dev/null +++ b/scheduler/src/main/java/com/ccsens/scheduler/service/JobService.java @@ -0,0 +1,134 @@ +package com.ccsens.scheduler.service; + +import cn.hutool.core.collection.CollectionUtil; +import cn.hutool.core.util.StrUtil; +import com.ccsens.scheduler.bean.dto.QuartzJob; +import com.ccsens.scheduler.bean.po.Task; +import com.ccsens.scheduler.bean.po.TaskExample; +import com.ccsens.scheduler.persist.dao.TaskDao; +import com.ccsens.scheduler.util.CodeEnum; +import com.ccsens.scheduler.util.Constant; +import com.ccsens.scheduler.util.QuartzJobUtil; +import com.ccsens.scheduler.util.RedisUtil; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.BeanUtils; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.List; + +/** + * @description: + * @author: whj + * @time: 2021/7/23 11:53 + */ +@Slf4j +@Service +@Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class) +public class JobService implements IJobService { + + @Resource + private QuartzJobUtil quartzJobUtil; + @Resource + private RedisUtil redisUtil; + @Resource + private TaskDao taskDao; + + + @Override + public CodeEnum add(QuartzJob.Job job, Long userId) { + // 写缓存,防重复 + boolean writeSuc = redisUtil.setNx(Constant.Quartz.JOB_KEY_PREFIX + job.getJobName() + Constant.Quartz.JOB_KEY_SPLIT + job.getJobGroupName(), "", Constant.Quartz.JOB_KEY_EXPIRE_TIME); + log.info("缓存{}结果:{}", job.getJobName(), writeSuc); + if (!writeSuc) { + return CodeEnum.JOB_EXISTED; + } + // 添加任务 + boolean suc = quartzJobUtil.addJob(job); + log.info("添加Quartz任务成功:{}", suc); + if (!suc) { + return CodeEnum.JOB_ADD_FAIL; + } + Task task = new Task(); + BeanUtils.copyProperties(job, task); + taskDao.insertSelective(task); + log.info("添加任务成功"); + return CodeEnum.SUCCESS; + } + + @Override + public CodeEnum modify(QuartzJob.Update job, Long userId) { + // 写缓存,防重复 + boolean writeSuc = redisUtil.setNx(Constant.Quartz.JOB_KEY_PREFIX + job.getTriggerName() + Constant.Quartz.JOB_KEY_SPLIT + job.getTriggerGroupName(), "", Constant.Quartz.JOB_KEY_EXPIRE_TIME); + log.info("缓存{}结果:{}", job.getTriggerName() + Constant.Quartz.JOB_KEY_SPLIT + job.getTriggerGroupName(),writeSuc); + if (!writeSuc) { + return CodeEnum.JOB_EXISTED; + } + // 查询任务 + TaskExample example = new TaskExample(); + example.createCriteria().andTriggerNameEqualTo(job.getTriggerName()).andTriggerGroupNameEqualTo(job.getTriggerGroupName()); + List tasks = taskDao.selectByExample(example); + log.info("tasks:{}", tasks); + if (CollectionUtil.isEmpty(tasks)) { + return CodeEnum.JOB_NOT_EXISTED; + } + Task task = tasks.get(0); + boolean cronChange = (StrUtil.isNotBlank(job.getCron()) && !job.getCron().equals(task.getCron())) + || ((StrUtil.isNotBlank(job.getMisfirePolicy()) && !job.getMisfirePolicy().equals(task.getMisfirePolicy()))); + if (cronChange) { + log.info("cron需要变更"); + boolean modify = quartzJobUtil.modifyJobTime(job); + if (!modify) { + return CodeEnum.JOB_MODIFY_FAIL; + } + } + Task updateTask = new Task(); + BeanUtils.copyProperties(job, updateTask); + updateTask.setId(task.getId()); + return CodeEnum.SUCCESS; + } + + @Override + public CodeEnum pause(QuartzJob.Name job, Long userId) { + boolean pause = quartzJobUtil.pauseJob(job.getJobName(), job.getJobGroupName()); + if (!pause) { + return CodeEnum.JOB_PAUSE_FAIL; + } + Task task = new Task(); + task.setRecStatus(Constant.REC_STATUS.Disabled.value); + TaskExample example = new TaskExample(); + example.createCriteria().andJobNameEqualTo(job.getJobName()).andJobGroupNameEqualTo(job.getJobGroupName()); + taskDao.updateByExampleSelective(task, example); + return CodeEnum.SUCCESS; + } + + @Override + public CodeEnum resume(QuartzJob.Name job, Long userId) { + boolean resume = quartzJobUtil.resumeJob(job.getJobName(), job.getJobGroupName()); + if (!resume) { + return CodeEnum.JOB_RESUME_FAIL; + } + Task task = new Task(); + task.setRecStatus(Constant.REC_STATUS.Normal.value); + TaskExample example = new TaskExample(); + example.createCriteria().andJobNameEqualTo(job.getJobName()).andJobGroupNameEqualTo(job.getJobGroupName()); + taskDao.updateByExampleSelective(task, example); + return CodeEnum.SUCCESS; + } + + @Override + public CodeEnum remove(QuartzJob.Del job, Long userId) { + boolean remove = quartzJobUtil.removeJob(job.getJobName(), job.getJobGroupName(), job.getTriggerName(), job.getTriggerGroupName()); + if (!remove) { + return CodeEnum.JOB_DEL_FAIL; + } + Task task = new Task(); + task.setRecStatus(Constant.REC_STATUS.Deleted.value); + TaskExample example = new TaskExample(); + example.createCriteria().andJobNameEqualTo(job.getJobName()).andJobGroupNameEqualTo(job.getJobGroupName()); + taskDao.updateByExampleSelective(task, example); + return CodeEnum.SUCCESS; + } +} diff --git a/scheduler/src/main/java/com/ccsens/scheduler/util/CodeEnum.java b/scheduler/src/main/java/com/ccsens/scheduler/util/CodeEnum.java index ac5ec87..eb4de01 100644 --- a/scheduler/src/main/java/com/ccsens/scheduler/util/CodeEnum.java +++ b/scheduler/src/main/java/com/ccsens/scheduler/util/CodeEnum.java @@ -10,8 +10,15 @@ public enum CodeEnum { SUCCESS(200, "ok", true), SYS_ERROR(500, "网络繁忙,请您稍后重试", false), FILE_FORMAT_ERROR(1, "文件格式错误", true), - PARAM_NULL(6, "请检查您的参数是否填写完整。", true), - + PARAM_NULL(2, "请检查您的参数是否填写完整。", true), + URL_ERROR(3, "请求路径转换异常", true), + JOB_EXISTED(4, "任务已经存在,请不要重复添加或修改任务名。", true), + JOB_ADD_FAIL(5, "任务添加失败,请检查参数后重试。", true), + JOB_NOT_EXISTED(6, "任务不存在。", true), + JOB_MODIFY_FAIL(7, "任务修改失败,请检查参数后重试。", true), + JOB_PAUSE_FAIL(8, "任务暂停失败。", true), + JOB_RESUME_FAIL(9, "任务重启失败。", true), + JOB_DEL_FAIL(10, "任务删除失败。", true), ; public static CodeEnum getByCode(int code) { diff --git a/scheduler/src/main/java/com/ccsens/scheduler/util/Constant.java b/scheduler/src/main/java/com/ccsens/scheduler/util/Constant.java index f9dfc83..9fd8fc6 100644 --- a/scheduler/src/main/java/com/ccsens/scheduler/util/Constant.java +++ b/scheduler/src/main/java/com/ccsens/scheduler/util/Constant.java @@ -1,6 +1,10 @@ package com.ccsens.scheduler.util; + +import java.util.HashMap; +import java.util.Map; + public class Constant { @@ -9,10 +13,6 @@ public class Constant { public static final String PARAMETER_KEY_TOKEN = "token"; public static final String HEADER_KEY_TOKEN = "Authorization"; public static final String HEADER_KEY_TOKEN_PREFIX = "Bearer "; - public static final String REQUEST_KEY_CLAIMS = "claims"; - public static final String REQUEST_KEY_TOKEN_USERS = "Token_User"; - public static final String RANDOM_STR = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; - public static final String IMAGE_CODE = "image_code_"; public static final String DYNAMIC_DATASOURCE_SCHEMA_KEY = "${schema}"; public enum REC_STATUS { @@ -29,572 +29,55 @@ public class Constant { public static class Quartz { public static final String QZ_JOB_GROUP_NAME = "JOB_GROUP_NAME"; public static final String QZ_TRIGGER_GROUP_NAME = "TRIGGER_GROUP_NAME"; + public static final String JOB_KEY_PREFIX = "scheduler:job:"; + public static final long JOB_KEY_EXPIRE_TIME = 600; + public static final String JOB_KEY_SPLIT = ":"; + public static final Map JOB = new HashMap<>(); + static { + JOB.put((byte)0,"com.ccsens.scheduler.service.CoreJobService"); + } + } + + public static class NotifyWay{ + public static final byte HTTP = 0; + public static final byte MQ = 1; + public static final byte EMAIL = 2; + public static final byte SMS = 3; + } + + + + +// @SuppressWarnings("all") +// public enum Task_Check_Status{ +// PENDING(0,"未审核"),FAILURE(1,"审核未通过"),SUCCESS(2,"审核已通过"); +// public int value; +// public String phase; +// Task_Check_Status(int value,String thePhase){ +// this.value = value; +// this.phase = thePhase; +// } +// public static Task_Check_Status valueOf(int value) { // 手写的从int到enum的转换函数 +// switch (value) { +// case 0: return PENDING; +// case 1: return FAILURE; +// case 2: return SUCCESS; +// default: return null; +// } +// } +// public static Task_Check_Status phaseOf(String phase) { // 手写的从String到enum的转换函数 +// if(phase.equalsIgnoreCase("PENDING")) { +// return PENDING; +// }else if(phase.equalsIgnoreCase("FAILURE")) { +// return FAILURE; +// } else if(phase.equalsIgnoreCase("SUCCESS")) { +// return SUCCESS; +// } else { +// return null; +// } +// } +// } - } - - - - - public enum PARTI_LOGIN_STATUS { - SUCCESS(0,"登陆成功"), ToStep2(1,"进入下一步"); - - public int value; - public String phase; - PARTI_LOGIN_STATUS(int value,String thePhase){ - this.value =value; - this.phase = thePhase; - } - } - - public enum Gender{ - Unknown(0,"未知"),Male(1,"男"),Female(2,"女"); - - public int value; - public String phase; - Gender(int value,String thePhase){ - this.value =value; - this.phase = thePhase; - } - } - - public enum Parti_Verify_Type{ - Phone(0,"手机"),Email(1,"邮件"),Account(2,"账号"); - public int value; - public String phase; - Parti_Verify_Type(int value,String thePhase){ - this.value = value; - this.phase = thePhase; - } - public static Parti_Verify_Type valueOf(int value) { // 手写的从int到enum的转换函数 - switch (value) { - case 0: return Phone; - case 1: return Email; - case 2: return Account; - default: return null; - } - } - } - - public enum PartiVerify{ - None(0,"无验证"),Verify(1,"验证"); - public int value; - public String phase; - PartiVerify(int value,String thePhase){ - this.value = value; - this.phase = thePhase; - } - } - - public enum TASK_Execute_Type { - Start(0,"开始"),Complete(1,"完成"); - - public int value; - public String phase; - TASK_Execute_Type(int value,String thePhase){ - this.value = value; - this.phase = thePhase; - } - } - - - - public enum Message_Type{ - Heart(0x00,"Heart"),Ack(0x01,"Ack"),Auth(0x02,"Auth"),Channel(0x03,"Channel") - ,Sync(0x04,"Sync") - ,Node(0x05,"Node"),User(0x06,"User"), Timer(0x07,"Timer") - ,Error(0x99,"Error") - ,MasterStatus(0x10,"MasterStatus") - ,BatchSetting(0x11,"BatchSetting") - ,Admin(0x12,"Admin") - ,Ring(0x13,"Ring") - ,Deliver(0x14,"Deliver") - ,Game(0x15,"Game") - ,Chrome(0x15,"Chrome") - ,PPTCtl(0x15,"PPTCtl") - ,Count(0x16,"Count") - ,ChangeStatus(0x17,"ChangeStatus") - ,PROJECT_MESSAGE(0x18, "ProjectMessage"); - public int value; - public String phase; - Message_Type(int value,String thePhase){ - this.value = value; - this.phase = thePhase; - } - public static Message_Type valueOf(int value) { // 手写的从int到enum的转换函数 - switch (value) { - case 0x00: return Heart; - case 0x01: return Ack; - case 0x02: return Auth; - case 0x03: return Channel; - case 0x04: return Sync; - case 0x05: return Node; - case 0x06: return User; - case 0x07: return Timer; - case 0x10: return MasterStatus; - case 0x11: return BatchSetting; - case 0x12: return Admin; - case 0x13: return Ring; - case 0x14: return Deliver; - case 0x15: return Game; - case 0x16: return Count; - case 0x17: return ChangeStatus; - default: return null; - } - } - - public static Message_Type phaseOf(String phase) { // 手写的从String到enum的转换函数 - if("Sync".equalsIgnoreCase(phase)) { - return Sync; - } - if("Ack".equalsIgnoreCase(phase)) { - return Ack; - } - if("Node".equalsIgnoreCase(phase)) { - return Node; - } - if("User".equalsIgnoreCase(phase)) { - return User; - } - if("Heart".equalsIgnoreCase(phase)) { - return Heart; - } - if("Auth".equalsIgnoreCase(phase)) { - return Auth; - } - if("Channel".equalsIgnoreCase(phase)) { - return Channel; - } - if("Timer".equalsIgnoreCase(phase)) { - return Timer; - } - if("MasterStatus".equalsIgnoreCase(phase)) { - return MasterStatus; - } - if("BatchSetting".equalsIgnoreCase(phase)) { - return BatchSetting; - } - if(phase.equalsIgnoreCase("Admin")) { - return Admin; - } - if(phase.equalsIgnoreCase("Ring")) { - return Ring; - } - if(phase.equalsIgnoreCase("Deliver")) { - return Deliver; - } - if("Game".equalsIgnoreCase(phase)) { - return Game; - } - if("Count".equalsIgnoreCase(phase)) { - return Count; - } - if("ChangeStatus".equalsIgnoreCase(phase)) { - return Count; - }else { - return null; - } - } - } - public enum Message_Ack_Event{ - Ack(0,"Ack"); - public int value; - public String phase; - Message_Ack_Event(int value,String thePhase){ - this.value = value; - this.phase = thePhase; - } - public static Message_Ack_Event valueOf(int value) { // 手写的从int到enum的转换函数 - switch (value) { - case 0: return Ack; - default: return null; - } - } - public static Message_Ack_Event phaseOf(String phase) { // 手写的从String到enum的转换函数 - if(phase.equalsIgnoreCase("Ack")) { - return Ack; - } else { - return null; - } - } - } - - public enum Message_Sync_Event{ - ChangeDuration(0,"ChangeDuration"),Move(1,"Move"), - Remove(2,"Remove"),Add(3,"Add"),Start(4,"Start"),ChangeBeginTime(5,"ChangeBeginTime"),Show(6,"Show"); - public int value; - public String phase; - Message_Sync_Event(int value,String thePhase){ - this.value = value; - this.phase = thePhase; - } - public static Message_Sync_Event valueOf(int value) { // 手写的从int到enum的转换函数 - switch (value) { - case 0: return ChangeDuration; - case 1: return Move; - case 2: return Remove; - case 3: return Add; - case 4: return Start; - case 5: return ChangeBeginTime; - case 6: return Show; - default: return null; - } - } - public static Message_Sync_Event phaseOf(String phase) { // 手写的从String到enum的转换函数 - if(phase.equalsIgnoreCase("Start")) { - return Start; - } - if(phase.equalsIgnoreCase("ChangeDuration")) { - return ChangeDuration; - } - if(phase.equalsIgnoreCase("Move")) { - return Move; - } - if(phase.equalsIgnoreCase("Remove")) { - return Remove; - } - if(phase.equalsIgnoreCase("Add")) { - return Add; - } - if(phase.equalsIgnoreCase("ChangeBeginTime")) { - return ChangeBeginTime; - } - if(phase.equalsIgnoreCase("Show")) { - return Show; - } else { - return null; - } - } - } - - public enum Message_Node_Event{ - ChangeStatus(0,"ChangeStatus"),PostComment(1,"PostComment"),UploadDeliver(2,"UploadDeliver"); - public int value; - public String phase; - Message_Node_Event(int value,String thePhase){ - this.value = value; - this.phase = thePhase; - } - public static Message_Node_Event valueOf(int value) { // 手写的从int到enum的转换函数 - switch (value) { - case 0: return ChangeStatus; - case 1: return PostComment; - case 2: return UploadDeliver; - default: return null; - } - } - public static Message_Node_Event phaseOf(String phase) { // 手写的从String到enum的转换函数 - if(phase.equalsIgnoreCase("ChangeStatus")) { - return ChangeStatus; - } - if(phase.equalsIgnoreCase("PostComment")) { - return PostComment; - } - if(phase.equalsIgnoreCase("UploadDeliver")) { - return UploadDeliver; - } else { - return null; - } - } - } - - public enum Message_User_Event{ - HasRead(0,"HasRead"),User(1,"User"); - public int value; - public String phase; - Message_User_Event(int value,String thePhase){ - this.value = value; - this.phase = thePhase; - } - public static Message_User_Event valueOf(int value) { // 手写的从int到enum的转换函数 - switch (value) { - case 0: return HasRead; - case 1: return User; - default: return null; - } - } - public static Message_User_Event phaseOf(String phase) { // 手写的从String到enum的转换函数 - if(phase.equalsIgnoreCase("HasRead")) { - return HasRead; - } - if(phase.equalsIgnoreCase("User")) { - return User; - } else { - return null; - } - } - } - - public enum Message_Heart_Event{ - Heart(0,"Heart"); - public int value; - public String phase; - Message_Heart_Event(int value,String thePhase){ - this.value = value; - this.phase = thePhase; - } - public static Message_Heart_Event valueOf(int value) { // 手写的从int到enum的转换函数 - switch (value) { - case 0: return Heart; - default: return null; - } - } - public static Message_Heart_Event phaseOf(String phase) { // 手写的从String到enum的转换函数 - if(phase.equalsIgnoreCase("Heart")) { - return Heart; - } else { - return null; - } - } - } - - public enum Message_Auth_Event{ - Auth(0,"Auth"), - Answer(1,"Answer"); - public int value; - public String phase; - Message_Auth_Event(int value,String thePhase){ - this.value = value; - this.phase = thePhase; - } - public static Message_Auth_Event valueOf(int value) { // 手写的从int到enum的转换函数 - switch (value) { - case 0: return Auth; - case 1: return Answer; - default: return null; - } - } - public static Message_Auth_Event phaseOf(String phase) { // 手写的从String到enum的转换函数 - if(phase.equalsIgnoreCase("Auth")) { - return Auth; - } - if(phase.equalsIgnoreCase("Answer")) { - return Answer; - }else { - return null; - } - } - } - - public enum Message_Channel_Event{ - Channel(0,"Channel"); - public int value; - public String phase; - Message_Channel_Event(int value,String thePhase){ - this.value = value; - this.phase = thePhase; - } - public static Message_Channel_Event valueOf(int value) { // 手写的从int到enum的转换函数 - switch (value) { - case 0: return Channel; - default: return null; - } - } - public static Message_Channel_Event phaseOf(String phase) { // 手写的从String到enum的转换函数 - if(phase.equalsIgnoreCase("Channel")) { - return Channel; - } else { - return null; - } - } - } - public enum Message_MasterStatus_Event{ - Report(0,"Report"),Query(1,"Query"),Answer(2,"Answer"); - public int value; - public String phase; - Message_MasterStatus_Event(int value,String thePhase){ - this.value = value; - this.phase = thePhase; - } - public static Message_MasterStatus_Event valueOf(int value) { // 手写的从int到enum的转换函数 - switch (value) { - case 0: return Report; - case 1: return Query; - case 2: return Answer; - default: return null; - } - } - public static Message_MasterStatus_Event phaseOf(String phase) { // 手写的从String到enum的转换函数 - if(phase.equalsIgnoreCase("Report")) { - return Report; - } - if(phase.equalsIgnoreCase("Query")) { - return Query; - } - if(phase.equalsIgnoreCase("Answer")) { - return Answer; - } else { - return null; - } - } - } - @SuppressWarnings("all") - public enum Task_Check_Status{ - PENDING(0,"未审核"),FAILURE(1,"审核未通过"),SUCCESS(2,"审核已通过"); - public int value; - public String phase; - Task_Check_Status(int value,String thePhase){ - this.value = value; - this.phase = thePhase; - } - public static Task_Check_Status valueOf(int value) { // 手写的从int到enum的转换函数 - switch (value) { - case 0: return PENDING; - case 1: return FAILURE; - case 2: return SUCCESS; - default: return null; - } - } - public static Task_Check_Status phaseOf(String phase) { // 手写的从String到enum的转换函数 - if(phase.equalsIgnoreCase("PENDING")) { - return PENDING; - }else if(phase.equalsIgnoreCase("FAILURE")) { - return FAILURE; - } else if(phase.equalsIgnoreCase("SUCCESS")) { - return SUCCESS; - } else { - return null; - } - } - } - - - public enum Message_BatchSetting_Event{ - Apply(0,"Apply"),Answer(1,"Answer"); - public int value; - public String phase; - Message_BatchSetting_Event(int value,String thePhase){ - this.value = value; - this.phase = thePhase; - } - public static Message_BatchSetting_Event valueOf(int value) { // 手写的从int到enum的转换函数 - switch (value) { - case 0: return Apply; - case 1: return Answer; - default: return null; - } - } - public static Message_BatchSetting_Event phaseOf(String phase) { // 手写的从String到enum的转换函数 - if(phase.equalsIgnoreCase("Apply")) { - return Apply; - } - if(phase.equalsIgnoreCase("Answer")) { - return Answer; - } - return null; - } - } - - public enum Message_Admin_Event{ - FindAll(0,"FindAll"); - public int value; - public String phase; - Message_Admin_Event(int value,String thePhase){ - this.value = value; - this.phase = thePhase; - } - public static Message_Admin_Event valueOf(int value) { // 手写的从int到enum的转换函数 - switch (value) { - case 0: return FindAll; - default: return null; - } - } - public static Message_Admin_Event phaseOf(String phase) { // 手写的从String到enum的转换函数 - if(phase.equalsIgnoreCase("FindAll")) { - return FindAll; - } else { - return null; - } - } - } - - public enum Message_Ring_Event{ - Send(0,"Send") - ,Read(1,"Read"); - public int value; - public String phase; - Message_Ring_Event(int value,String thePhase){ - this.value = value; - this.phase = thePhase; - } - public static Message_Ring_Event valueOf(int value) { // 手写的从int到enum的转换函数 - switch (value) { - case 0: return Send; - case 1: return Read; - default: return null; - } - } - public static Message_Ring_Event phaseOf(String phase) { // 手写的从String到enum的转换函数 - if(phase.equalsIgnoreCase("Send")) { - return Send; - } - if(phase.equalsIgnoreCase("Read")) { - return Read; - } else { - return null; - } - } - } - public enum Message_Deliver_Event{ - Upload(0,"Upload") - ,Checker(1,"Checker") - ,Delete(2,"Delete"); - public int value; - public String phase; - Message_Deliver_Event(int value,String thePhase){ - this.value = value; - this.phase = thePhase; - } - public static Message_Deliver_Event valueOf(int value) { // 手写的从int到enum的转换函数 - switch (value) { - case 0: return Upload; - case 1: return Checker; - case 2: return Delete; - default: return null; - } - } - public static Message_Deliver_Event phaseOf(String phase) { // 手写的从String到enum的转换函数 - if(phase.equalsIgnoreCase("Upload")) { - return Upload; - } - if(phase.equalsIgnoreCase("Checker")) { - return Checker; - } - if(phase.equalsIgnoreCase("Delete")) { - return Delete; - } else { - return null; - } - } - } - - - //wbs表时间类型==================================================================/ - - - - /** - * redis类型 - */ - public enum RedisType{ - /**redis类型**/ - STRING(0,"字符串类型"), - LIST_INDEX(1,"列表-某一个"), - LIST_RANGE(2,"列表-范围"), - SET(3,"集合"), - SORT_SET_RANGE(4,"有序集合-index"), - SORT_SET_SCORE(5,"有序集合-分数"), - HASH_ITEM(6, "哈希-某一项"), - HASH(7, "哈希-全部"), - ; - /**类型code*/ - public int type; - /**类型*/ - public String message; - RedisType(int type, String message) { - this.type = type; - this.message = message; - } - } } diff --git a/scheduler/src/main/java/com/ccsens/scheduler/util/QuartzJobUtil.java b/scheduler/src/main/java/com/ccsens/scheduler/util/QuartzJobUtil.java index 1ca24c9..5611321 100644 --- a/scheduler/src/main/java/com/ccsens/scheduler/util/QuartzJobUtil.java +++ b/scheduler/src/main/java/com/ccsens/scheduler/util/QuartzJobUtil.java @@ -1,6 +1,6 @@ package com.ccsens.scheduler.util; -import com.ccsens.scheduler.bean.dto.QuartzJobModule; +import com.ccsens.scheduler.bean.dto.QuartzJob; import lombok.extern.slf4j.Slf4j; import org.quartz.*; import org.quartz.impl.triggers.CronTriggerImpl; @@ -26,48 +26,43 @@ public class QuartzJobUtil { /** * @Description: 添加一个定时任务 - * @param quartzModel + * @param jobModel 任务 */ - public void addJob(QuartzJobModule quartzModel) { - if (quartzModel.verify()) { + public boolean addJob(QuartzJob.Job jobModel) { + if (jobModel.verify()) { try { - JobDetail job = JobBuilder.newJob((Class) Class.forName(quartzModel.getJobClass())) - .withIdentity(quartzModel.getJobName(), quartzModel.getJobGroupName()) - .setJobData(quartzModel.getJobDataMap()).build(); + JobDetail job = JobBuilder.newJob((Class) Class.forName(Constant.Quartz.JOB.get(jobModel.getJob()))) + .withIdentity(jobModel.getJobName(), jobModel.getJobGroupName()) + .setJobData(jobModel.getJobDataMap()).build(); // 表达式调度构建器 - CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(quartzModel.getCron()); - handleCronScheduleMisfirePolicy(quartzModel, scheduleBuilder); + CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(jobModel.getCron()); + handleCronScheduleMisfirePolicy(jobModel.getMisfirePolicy(), scheduleBuilder); // 按新的cronExpression表达式构建一个新的trigger TriggerBuilder builder = TriggerBuilder.newTrigger() - .withIdentity(quartzModel.getTriggerName(), quartzModel.getTriggerGroupName()); - if (quartzModel.getStartTime() != null) { - builder.startAt(quartzModel.getStartTime()); - } - if (quartzModel.getEndTime() != null) { - builder.endAt(quartzModel.getEndTime()); - } - - + .withIdentity(jobModel.getTriggerName(), jobModel.getTriggerGroupName()); + setPeriod(builder, jobModel.getStartTime(), jobModel.getEndTime()); Trigger trigger = builder.withSchedule(scheduleBuilder).build(); scheduler.scheduleJob(job, trigger); // 启动 if (!scheduler.isShutdown()) { scheduler.start(); } + return true; } catch (Exception e) { - log.error("Add quartz job error, jobName = {}", quartzModel.getJobName(), e); + log.error("Add quartz job error, jobName = {}", jobModel.getJobName(), e); } } else { log.error("QuartzModel is invalid!"); } + return false; } - public static CronScheduleBuilder handleCronScheduleMisfirePolicy(QuartzJobModule job, CronScheduleBuilder cb) + public static CronScheduleBuilder handleCronScheduleMisfirePolicy(String misfirePolicy, CronScheduleBuilder cb) throws Exception { - switch (job.getMisfirePolicy()) { + switch (misfirePolicy) { case "withMisfireHandlingInstructionIgnoreMisfires": //以错过的第一个频率时间立刻开始执行 @@ -84,139 +79,59 @@ public class QuartzJobUtil { // 等待下次Cron触发频率到达时刻开始按照Cron频率依次执行 return cb.withMisfireHandlingInstructionDoNothing(); default: - throw new Exception("The task misfire policy '" + job.getMisfirePolicy() + "' cannot be used in cron schedule tasks"); + throw new Exception("The task misfire policy '" + misfirePolicy + "' cannot be used in cron schedule tasks"); } } + + /** * @Description: 修改一个任务的触发时间(使用默认的任务组名,触发器名,触发器组名) - * @param jobName - * @param cron + * @param jobModel 修改内容 */ - public void modifyJobTime(String jobName, String cron, Date startDate, Date endDate) { - TriggerKey triggerKey = TriggerKey.triggerKey(jobName, Constant.Quartz.QZ_TRIGGER_GROUP_NAME); - + public boolean modifyJobTime(QuartzJob.Update jobModel) { try { + TriggerKey triggerKey = TriggerKey.triggerKey(jobModel.getTriggerName(), jobModel.getTriggerGroupName()); CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey); if (trigger == null) { - return; + return false; } - String oldTime = trigger.getCronExpression(); - if (!oldTime.equalsIgnoreCase(cron)) { - CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(cron); + String oldCron = trigger.getCronExpression(); + if (!oldCron.equalsIgnoreCase(jobModel.getCron())) { + CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(jobModel.getCron()); + handleCronScheduleMisfirePolicy(jobModel.getMisfirePolicy(), scheduleBuilder); // 按新的cronExpression表达式重新构建trigger - trigger = trigger.getTriggerBuilder().withIdentity(triggerKey) - .startAt(startDate) - .endAt(endDate).withSchedule(scheduleBuilder).build(); + TriggerBuilder builder = trigger.getTriggerBuilder().withIdentity(triggerKey); + setPeriod(builder, jobModel.getStartTime(), jobModel.getEndTime()); + trigger = builder.withSchedule(scheduleBuilder).build(); // 按新的trigger重新设置job执行 scheduler.rescheduleJob(triggerKey, trigger); } + return true; } catch (Exception e) { - throw new RuntimeException(e); - } - } - - /** - * @Description:修改任务,(可以修改任务名,任务类,触发时间) - * 原理:移除原来的任务,添加新的任务 - * @param oldJobName - * :原任务名 - * @param jobName - * @param jobclass - * @param cron - */ - public void modifyJob(String oldJobName, String jobName, Class jobclass, String cron) { - TriggerKey triggerKey = TriggerKey.triggerKey(oldJobName, Constant.Quartz.QZ_TRIGGER_GROUP_NAME); - JobKey jobKey = JobKey.jobKey(oldJobName, Constant.Quartz.QZ_JOB_GROUP_NAME); - try { - // 任务不存在 - if (removeJob(oldJobName, triggerKey, jobKey)) { - return; - } - - JobDetail job = JobBuilder.newJob(jobclass).withIdentity(jobName, - Constant.Quartz.QZ_JOB_GROUP_NAME) - .build(); - // 表达式调度构建器 - CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(cron); - // 按新的cronExpression表达式构建一个新的trigger - Trigger newTrigger = TriggerBuilder.newTrigger().withIdentity(jobName, - Constant.Quartz.QZ_TRIGGER_GROUP_NAME) - .withSchedule(scheduleBuilder).build(); - - // 交给scheduler去调度 - scheduler.scheduleJob(job, newTrigger); - - // 启动 - if (!scheduler.isShutdown()) { - scheduler.start(); - System.err.println("添加新任务:" + jobName); - } - System.err.println("修改任务【" + oldJobName + "】为:" + jobName); - } - catch (Exception e) { - throw new RuntimeException(e); + log.error("修改任务异常", e); } - - } - - private boolean removeJob(String oldJobName, TriggerKey triggerKey, JobKey jobKey) throws SchedulerException { - Trigger trigger = scheduler.getTrigger(triggerKey); - if (trigger == null) { - return true; - } - // 停止触发器 - deleteJob(triggerKey, jobKey); - System.err.println("移除任务:" + oldJobName); return false; } - /** - * @Description: 修改一个任务的触发时间 - * @param triggerName - * @param triggerGroupName - * @param cron - */ - public void modifyJobTime(String triggerName, String triggerGroupName, String cron) { - TriggerKey triggerKey = TriggerKey.triggerKey(triggerName, triggerGroupName); - try { - CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey); - if (trigger == null) { - return; - } - String oldTime = trigger.getCronExpression(); - if (!oldTime.equalsIgnoreCase(cron)) { - // trigger已存在,则更新相应的定时设置 - CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(cron); - // 按新的cronExpression表达式重新构建trigger - trigger = trigger.getTriggerBuilder().withIdentity(triggerKey).withSchedule(scheduleBuilder).build(); - // 按新的trigger重新设置job执行 - scheduler.resumeTrigger(triggerKey); - } - } - catch (Exception e) { - throw new RuntimeException(e); - } - } /** - * @Description 移除一个任务(使用默认的任务组名,触发器名,触发器组名) - * @param jobName + * 设置定时器的起止时间 + * @param builder 定时器builder + * @param startTime 起始时间 + * @param endTime 终止时间 */ - public void removeJob(String jobName) { - TriggerKey triggerKey = TriggerKey.triggerKey(jobName, Constant.Quartz.QZ_TRIGGER_GROUP_NAME); - JobKey jobKey = JobKey.jobKey(jobName, Constant.Quartz.QZ_JOB_GROUP_NAME); - try { - Trigger trigger = scheduler.getTrigger(triggerKey); - if (trigger == null) { - return; - } - deleteJob(triggerKey, jobKey); - System.err.println("移除任务:" + jobName); + private void setPeriod(TriggerBuilder builder, long startTime, long endTime) { + if (startTime > 0) { + Date date = new Date(); + date.setTime(startTime); + builder.startAt(date); } - catch (Exception e) { - throw new RuntimeException(e); + if (endTime > 0) { + Date date = new Date(); + date.setTime(endTime); + builder.endAt(date); } } @@ -236,73 +151,52 @@ public class QuartzJobUtil { * @param triggerName * @param triggerGroupName */ - public void removeJob(String jobName, String jobGroupName, String triggerName, String triggerGroupName) { - TriggerKey triggerKey = TriggerKey.triggerKey(jobName, triggerGroupName); - JobKey jobKey = JobKey.jobKey(jobName, jobGroupName); + public boolean removeJob(String jobName, String jobGroupName, String triggerName, String triggerGroupName) { + try { + TriggerKey triggerKey = TriggerKey.triggerKey(triggerName, triggerGroupName); + JobKey jobKey = JobKey.jobKey(jobName, jobGroupName); deleteJob(triggerKey, jobKey); + return true; } catch (Exception e) { - throw new RuntimeException(e); - } - } - - /** - * @Description:暂停一个任务(使用默认组名) - * @param jobName - */ - public void pauseJob(String jobName) { - JobKey jobKey = JobKey.jobKey(jobName, Constant.Quartz.QZ_JOB_GROUP_NAME); - try { - scheduler.pauseJob(jobKey); - } - catch (SchedulerException e) { - e.printStackTrace(); + log.error("删除任务异常", e); } + return false; } /** * @Description:暂停一个任务 - * @param jobName - * @param jobGroupName + * @param jobName 任务名 + * @param jobGroupName 任务组名 */ - public void pauseJob(String jobName, String jobGroupName) { + public boolean pauseJob(String jobName, String jobGroupName) { JobKey jobKey = JobKey.jobKey(jobName, jobGroupName); try { scheduler.pauseJob(jobKey); + return true; } - catch (SchedulerException e) { - e.printStackTrace(); - } - } - - /** - * @Description:恢复一个任务(使用默认组名) - * @param jobName - */ - public void resumeJob(String jobName) { - JobKey jobKey = JobKey.jobKey(jobName, Constant.Quartz.QZ_JOB_GROUP_NAME); - try { - scheduler.resumeJob(jobKey); - } - catch (SchedulerException e) { - e.printStackTrace(); + catch (Exception e) { + log.error("暂停任务异常", e); } + return false; } /** * @Description:恢复一个任务 - * @param jobName - * @param jobGroupName + * @param jobName 任务名 + * @param jobGroupName 任务组名 */ - public void resumeJob(String jobName, String jobGroupName) { + public boolean resumeJob(String jobName, String jobGroupName) { JobKey jobKey = JobKey.jobKey(jobName, jobGroupName); try { scheduler.resumeJob(jobKey); + return true; } - catch (SchedulerException e) { - e.printStackTrace(); + catch (Exception e) { + log.error("重启失败", e); } + return false; } /** diff --git a/scheduler/src/main/java/com/ccsens/scheduler/util/RestTemplateUtil.java b/scheduler/src/main/java/com/ccsens/scheduler/util/RestTemplateUtil.java new file mode 100644 index 0000000..c4a9477 --- /dev/null +++ b/scheduler/src/main/java/com/ccsens/scheduler/util/RestTemplateUtil.java @@ -0,0 +1,156 @@ +package com.ccsens.scheduler.util; + +import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.ccsens.scheduler.exception.BaseException; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Component; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; +import org.springframework.web.client.RestTemplate; + +import javax.annotation.PostConstruct; +import javax.annotation.Resource; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.List; +import java.util.Map; + +@Slf4j +@Component +public class RestTemplateUtil { + + @Resource + private RestTemplate restTemplate; + + private static RestTemplateUtil util; + + @PostConstruct + public void init(){ + util = this; + util.restTemplate = this.restTemplate; + } + + public static Object getForEntity(String url, Map params, Class returnClass) { + + if (params != null && !params.isEmpty()) { + String questionMark = "?"; + String assignMark = "="; + String andMark = "&"; + if (!url.contains(questionMark)) { + url += questionMark; + } + for (String key : params.keySet()) { + if (url.endsWith(questionMark)) { + url += key + assignMark +params.get(key); + } else { + url += andMark + key + assignMark +params.get(key); + } + } + } + log.info("url:{}, params:{}", url, params); + ResponseEntity entity = util.restTemplate.getForEntity(url, String.class); + log.info("entity:{}",entity); + return JSONObject.parseObject(entity.getBody(), returnClass); + } + + public static String postBody(String url, Object params) { + log.info("路径:{}, 参数:{}", url, params); + HttpHeaders httpHeaders = new HttpHeaders(); + MediaType type= MediaType.parseMediaType("application/json;charset=UTF-8"); + httpHeaders.setContentType(type); + + JSONObject json = JSON.parseObject(JSON.toJSONString(params)); + HttpEntity> objectHttpEntity = new HttpEntity<>(json,httpHeaders); + URI uri; + try { + uri = new URI(url); + }catch (URISyntaxException e) { + log.error("转换路径异常", e); + throw new BaseException(CodeEnum.URL_ERROR); + } + + ResponseEntity response = util.restTemplate.postForEntity(uri, objectHttpEntity, String.class); + log.info("返回:{}", response); + return response.getBody(); + } + + public static String postBody(String url, List params) { + log.info("路径:{}, 参数:{}", url, params); + HttpHeaders httpHeaders = new HttpHeaders(); + MediaType type= MediaType.parseMediaType("application/json;charset=UTF-8"); + httpHeaders.setContentType(type); + + HttpEntity> objectHttpEntity = new HttpEntity<>(params,httpHeaders); + URI uri; + try { + uri = new URI(url); + }catch (URISyntaxException e) { + log.error("转换路径异常:{}", e); + throw new BaseException(CodeEnum.URL_ERROR); + } + + ResponseEntity response = util.restTemplate.postForEntity(uri, objectHttpEntity, String.class); + log.info("返回:{}", response); + return response.getBody(); + } + public static String postUrlEncode(String url, Object params) { + log.info("请求路径:{},请求参数:{}", url, params); + MultiValueMap paramMap; + if (params == null) { + paramMap = new LinkedMultiValueMap<>(); + } else { + JSONObject json = JSON.parseObject(JSON.toJSONString(params)); + paramMap = transMultiValueMap(json); + } + + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); + HttpEntity formEntity = new HttpEntity<>(paramMap, headers); + ResponseEntity result = util.restTemplate.postForEntity(url, formEntity, String.class); + log.info("接口返回结果:{}", result); + return result.getBody(); + } + + /** + * 发送multipart/form-data + * @author whj + * @date 2019/8/20 + * @param url 路径 + * @param params 参数 + * @return com.alibaba.fastjson.JSONObject + */ + public static JSONObject postImg(String url, JSONObject params) { + log.info("请求路径:{},请求参数:{}", url, params); + HttpHeaders headers = new HttpHeaders(); + headers.add("Accept", MediaType.APPLICATION_JSON.toString()); + headers.setContentType(MediaType.MULTIPART_FORM_DATA); + MultiValueMap paramMap = transMultiValueMap(params); + HttpEntity formEntity = new HttpEntity<>(paramMap, headers); + JSONObject result = util.restTemplate.postForObject(url, formEntity, JSONObject.class); + log.info("接口返回结果:{}", result); + return result; + } + + /** + * 将参数封装成MultiValueMap对象 + * @author whj + * @date 2019/8/20 + * @param params 参数 + * @return org.springframework.util.MultiValueMap + */ + private static MultiValueMap transMultiValueMap(JSONObject params) { + MultiValueMap paramMap = new LinkedMultiValueMap<>(); + for (String key: params.keySet()) { + paramMap.add(key, params.get(key)); + } + return paramMap; + } + + +} diff --git a/scheduler/src/main/java/com/ccsens/scheduler/util/SmsUtil.java b/scheduler/src/main/java/com/ccsens/scheduler/util/SmsUtil.java new file mode 100644 index 0000000..40f1253 --- /dev/null +++ b/scheduler/src/main/java/com/ccsens/scheduler/util/SmsUtil.java @@ -0,0 +1,59 @@ +package com.ccsens.scheduler.util; + +import cn.hutool.core.util.RandomUtil; +import cn.hutool.json.JSONException; +import com.github.qcloudsms.SmsSingleSender; +import com.github.qcloudsms.SmsSingleSenderResult; +import com.github.qcloudsms.httpclient.HTTPException; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +import java.io.IOException; + +@Slf4j +@Component +public class SmsUtil { + // 1400开头 + private static final int appid = 1400188778; + private static final String appkey = "c86ca104521ab2e28e1d4b558fdd665e"; + /** + * {1} 验证码{1}, 您正在通过{2}登录传控科技“时物链条”会议管理系统,请与{3}分钟内填写,如非本人操作,请忽略本短信。\ + */ + private static final int templateId = 286731; + /** + * {1} 您正在通过{2}登录传控科技“时物链条”会议管理系统,请与{2}分钟内填写,如非本人操作,请忽略本短信。 + */ + private static final int templateId1 = 286682; + /**验证码{1},{2}分钟内有效,如非本人操作请忽略 + * + */ + private static final int templateId2 = 686476; + private static final String smsSign = "传控科技"; + + public static void sendSms(String phone,String code,String appName,Integer seconds){ + String phoneNumbers[] = {phone}; + Integer minutes = (seconds - 1) / 60 + 1; + try { + //数组具体的元素个数和模板中变量个数必须一致,例如事例中templateId:5678对应一个变量,参数数组中元素个数也必须是一个 + String[] params = {code,String.valueOf(minutes)}; + SmsSingleSender ssender = new SmsSingleSender(appid, appkey); + // 签名参数未提供或者为空时,会使用默认签名发送短信 + SmsSingleSenderResult result = ssender.sendWithParam("86", phoneNumbers[0], + templateId2, params, smsSign, "", ""); + log.info(String.valueOf(result)); + } catch (HTTPException e) { + // HTTP响应码错误 + e.printStackTrace(); + } catch (JSONException e) { + // json解析错误 + e.printStackTrace(); + } catch (IOException e) { + // 网络IO错误 + e.printStackTrace(); + } + } + + public static String generateRandomSmsCode(int length){ + return RandomUtil.randomNumbers(4); + } +} diff --git a/scheduler/src/main/resources/config/mail.setting b/scheduler/src/main/resources/config/mail.setting new file mode 100644 index 0000000..6b1e97c --- /dev/null +++ b/scheduler/src/main/resources/config/mail.setting @@ -0,0 +1,4 @@ +host = smtp.ccsens.com +port = 25 +from = admin@ccsens.com +pass = q1w2e3 \ No newline at end of file diff --git a/scheduler/src/main/resources/mapper_dao/TaskDao.xml b/scheduler/src/main/resources/mapper_dao/TaskDao.xml new file mode 100644 index 0000000..5d43a57 --- /dev/null +++ b/scheduler/src/main/resources/mapper_dao/TaskDao.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/scheduler/src/main/resources/mapper_raw/TaskMapper.xml b/scheduler/src/main/resources/mapper_raw/TaskMapper.xml new file mode 100644 index 0000000..8e7273c --- /dev/null +++ b/scheduler/src/main/resources/mapper_raw/TaskMapper.xml @@ -0,0 +1,418 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + and ${criterion.condition} + + + and ${criterion.condition} #{criterion.value} + + + and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} + + + and ${criterion.condition} + + #{listItem} + + + + + + + + + + + + + + + + + + and ${criterion.condition} + + + and ${criterion.condition} #{criterion.value} + + + and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} + + + and ${criterion.condition} + + #{listItem} + + + + + + + + + + + id, job_name, job_group_name, trigger_name, trigger_group_name, cron, misfire_policy, + job, start_time, end_time, auto_move, notify_way, notify_url, notify_param, app_id, + created_at, updated_at, rec_status + + + + + delete from t_task + where id = #{id,jdbcType=BIGINT} + + + delete from t_task + + + + + + insert into t_task (id, job_name, job_group_name, + trigger_name, trigger_group_name, cron, + misfire_policy, job, start_time, + end_time, auto_move, notify_way, + notify_url, notify_param, app_id, + created_at, updated_at, rec_status + ) + values (#{id,jdbcType=BIGINT}, #{jobName,jdbcType=VARCHAR}, #{jobGroupName,jdbcType=VARCHAR}, + #{triggerName,jdbcType=VARCHAR}, #{triggerGroupName,jdbcType=VARCHAR}, #{cron,jdbcType=VARCHAR}, + #{misfirePolicy,jdbcType=VARCHAR}, #{job,jdbcType=TINYINT}, #{startTime,jdbcType=BIGINT}, + #{endTime,jdbcType=BIGINT}, #{autoMove,jdbcType=TINYINT}, #{notifyWay,jdbcType=TINYINT}, + #{notifyUrl,jdbcType=VARCHAR}, #{notifyParam,jdbcType=VARCHAR}, #{appId,jdbcType=BIGINT}, + #{createdAt,jdbcType=TIMESTAMP}, #{updatedAt,jdbcType=TIMESTAMP}, #{recStatus,jdbcType=TINYINT} + ) + + + insert into t_task + + + id, + + + job_name, + + + job_group_name, + + + trigger_name, + + + trigger_group_name, + + + cron, + + + misfire_policy, + + + job, + + + start_time, + + + end_time, + + + auto_move, + + + notify_way, + + + notify_url, + + + notify_param, + + + app_id, + + + created_at, + + + updated_at, + + + rec_status, + + + + + #{id,jdbcType=BIGINT}, + + + #{jobName,jdbcType=VARCHAR}, + + + #{jobGroupName,jdbcType=VARCHAR}, + + + #{triggerName,jdbcType=VARCHAR}, + + + #{triggerGroupName,jdbcType=VARCHAR}, + + + #{cron,jdbcType=VARCHAR}, + + + #{misfirePolicy,jdbcType=VARCHAR}, + + + #{job,jdbcType=TINYINT}, + + + #{startTime,jdbcType=BIGINT}, + + + #{endTime,jdbcType=BIGINT}, + + + #{autoMove,jdbcType=TINYINT}, + + + #{notifyWay,jdbcType=TINYINT}, + + + #{notifyUrl,jdbcType=VARCHAR}, + + + #{notifyParam,jdbcType=VARCHAR}, + + + #{appId,jdbcType=BIGINT}, + + + #{createdAt,jdbcType=TIMESTAMP}, + + + #{updatedAt,jdbcType=TIMESTAMP}, + + + #{recStatus,jdbcType=TINYINT}, + + + + + + update t_task + + + id = #{record.id,jdbcType=BIGINT}, + + + job_name = #{record.jobName,jdbcType=VARCHAR}, + + + job_group_name = #{record.jobGroupName,jdbcType=VARCHAR}, + + + trigger_name = #{record.triggerName,jdbcType=VARCHAR}, + + + trigger_group_name = #{record.triggerGroupName,jdbcType=VARCHAR}, + + + cron = #{record.cron,jdbcType=VARCHAR}, + + + misfire_policy = #{record.misfirePolicy,jdbcType=VARCHAR}, + + + job = #{record.job,jdbcType=TINYINT}, + + + start_time = #{record.startTime,jdbcType=BIGINT}, + + + end_time = #{record.endTime,jdbcType=BIGINT}, + + + auto_move = #{record.autoMove,jdbcType=TINYINT}, + + + notify_way = #{record.notifyWay,jdbcType=TINYINT}, + + + notify_url = #{record.notifyUrl,jdbcType=VARCHAR}, + + + notify_param = #{record.notifyParam,jdbcType=VARCHAR}, + + + app_id = #{record.appId,jdbcType=BIGINT}, + + + created_at = #{record.createdAt,jdbcType=TIMESTAMP}, + + + updated_at = #{record.updatedAt,jdbcType=TIMESTAMP}, + + + rec_status = #{record.recStatus,jdbcType=TINYINT}, + + + + + + + + update t_task + set id = #{record.id,jdbcType=BIGINT}, + job_name = #{record.jobName,jdbcType=VARCHAR}, + job_group_name = #{record.jobGroupName,jdbcType=VARCHAR}, + trigger_name = #{record.triggerName,jdbcType=VARCHAR}, + trigger_group_name = #{record.triggerGroupName,jdbcType=VARCHAR}, + cron = #{record.cron,jdbcType=VARCHAR}, + misfire_policy = #{record.misfirePolicy,jdbcType=VARCHAR}, + job = #{record.job,jdbcType=TINYINT}, + start_time = #{record.startTime,jdbcType=BIGINT}, + end_time = #{record.endTime,jdbcType=BIGINT}, + auto_move = #{record.autoMove,jdbcType=TINYINT}, + notify_way = #{record.notifyWay,jdbcType=TINYINT}, + notify_url = #{record.notifyUrl,jdbcType=VARCHAR}, + notify_param = #{record.notifyParam,jdbcType=VARCHAR}, + app_id = #{record.appId,jdbcType=BIGINT}, + created_at = #{record.createdAt,jdbcType=TIMESTAMP}, + updated_at = #{record.updatedAt,jdbcType=TIMESTAMP}, + rec_status = #{record.recStatus,jdbcType=TINYINT} + + + + + + update t_task + + + job_name = #{jobName,jdbcType=VARCHAR}, + + + job_group_name = #{jobGroupName,jdbcType=VARCHAR}, + + + trigger_name = #{triggerName,jdbcType=VARCHAR}, + + + trigger_group_name = #{triggerGroupName,jdbcType=VARCHAR}, + + + cron = #{cron,jdbcType=VARCHAR}, + + + misfire_policy = #{misfirePolicy,jdbcType=VARCHAR}, + + + job = #{job,jdbcType=TINYINT}, + + + start_time = #{startTime,jdbcType=BIGINT}, + + + end_time = #{endTime,jdbcType=BIGINT}, + + + auto_move = #{autoMove,jdbcType=TINYINT}, + + + notify_way = #{notifyWay,jdbcType=TINYINT}, + + + notify_url = #{notifyUrl,jdbcType=VARCHAR}, + + + notify_param = #{notifyParam,jdbcType=VARCHAR}, + + + app_id = #{appId,jdbcType=BIGINT}, + + + created_at = #{createdAt,jdbcType=TIMESTAMP}, + + + updated_at = #{updatedAt,jdbcType=TIMESTAMP}, + + + rec_status = #{recStatus,jdbcType=TINYINT}, + + + where id = #{id,jdbcType=BIGINT} + + + update t_task + set job_name = #{jobName,jdbcType=VARCHAR}, + job_group_name = #{jobGroupName,jdbcType=VARCHAR}, + trigger_name = #{triggerName,jdbcType=VARCHAR}, + trigger_group_name = #{triggerGroupName,jdbcType=VARCHAR}, + cron = #{cron,jdbcType=VARCHAR}, + misfire_policy = #{misfirePolicy,jdbcType=VARCHAR}, + job = #{job,jdbcType=TINYINT}, + start_time = #{startTime,jdbcType=BIGINT}, + end_time = #{endTime,jdbcType=BIGINT}, + auto_move = #{autoMove,jdbcType=TINYINT}, + notify_way = #{notifyWay,jdbcType=TINYINT}, + notify_url = #{notifyUrl,jdbcType=VARCHAR}, + notify_param = #{notifyParam,jdbcType=VARCHAR}, + app_id = #{appId,jdbcType=BIGINT}, + created_at = #{createdAt,jdbcType=TIMESTAMP}, + updated_at = #{updatedAt,jdbcType=TIMESTAMP}, + rec_status = #{recStatus,jdbcType=TINYINT} + where id = #{id,jdbcType=BIGINT} + + \ No newline at end of file diff --git a/scheduler/src/main/resources/mbg.xml b/scheduler/src/main/resources/mbg.xml index e23ca85..50aadf2 100644 --- a/scheduler/src/main/resources/mbg.xml +++ b/scheduler/src/main/resources/mbg.xml @@ -56,7 +56,7 @@ - +