Browse Source

调度系统

master
zhizhi wu 4 years ago
parent
commit
09d7c3dc34
  1. 2
      ccmq/src/main/resources/application-prod.properties
  2. 2
      ccmq/src/main/resources/application.properties
  3. 31
      scheduler/pom.xml
  4. 49
      scheduler/src/main/java/com/ccsens/scheduler/api/JobController.java
  5. 107
      scheduler/src/main/java/com/ccsens/scheduler/bean/dto/QuartzJob.java
  6. 77
      scheduler/src/main/java/com/ccsens/scheduler/bean/dto/QuartzJobModule.java
  7. 27
      scheduler/src/main/java/com/ccsens/scheduler/bean/dto/QueryDto.java
  8. 216
      scheduler/src/main/java/com/ccsens/scheduler/bean/po/Task.java
  9. 1361
      scheduler/src/main/java/com/ccsens/scheduler/bean/po/TaskExample.java
  10. 9
      scheduler/src/main/java/com/ccsens/scheduler/persist/dao/TaskDao.java
  11. 30
      scheduler/src/main/java/com/ccsens/scheduler/persist/mapper/TaskMapper.java
  12. 73
      scheduler/src/main/java/com/ccsens/scheduler/service/CoreJobService.java
  13. 9
      scheduler/src/main/java/com/ccsens/scheduler/service/ICoreJobService.java
  14. 46
      scheduler/src/main/java/com/ccsens/scheduler/service/IJobService.java
  15. 134
      scheduler/src/main/java/com/ccsens/scheduler/service/JobService.java
  16. 11
      scheduler/src/main/java/com/ccsens/scheduler/util/CodeEnum.java
  17. 621
      scheduler/src/main/java/com/ccsens/scheduler/util/Constant.java
  18. 238
      scheduler/src/main/java/com/ccsens/scheduler/util/QuartzJobUtil.java
  19. 156
      scheduler/src/main/java/com/ccsens/scheduler/util/RestTemplateUtil.java
  20. 59
      scheduler/src/main/java/com/ccsens/scheduler/util/SmsUtil.java
  21. 4
      scheduler/src/main/resources/config/mail.setting
  22. 5
      scheduler/src/main/resources/mapper_dao/TaskDao.xml
  23. 418
      scheduler/src/main/resources/mapper_raw/TaskMapper.xml
  24. 2
      scheduler/src/main/resources/mbg.xml

2
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

2
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

31
scheduler/pom.xml

@ -171,6 +171,37 @@
<artifactId>poi-ooxml</artifactId>
<version>3.17</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.62</version>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.5.0-b01</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.7</version>
<configuration>
<configurationFile>${basedir}/src/main/resources/mbg.xml</configurationFile>
<overwrite>true</overwrite>
</configuration>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.34</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>

49
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<QuartzJob.Job> 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<QuartzJob.Update> 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<QuartzJob.Name> 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<QuartzJob.Name> 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<QuartzJob.Del> dto) {
log.info("移除任务:{}", dto);
CodeEnum codeEnum = jobService.remove(dto.getParam(), dto.getUserId());
log.info("移除任务结果:{}", dto);
return JsonResponse.newInstance().ok(codeEnum);
}
}

107
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;
}
}

77
scheduler/src/main/java/com/ccsens/scheduler/bean/dto/QuartzJobModule.java

@ -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)
);
}
}

27
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<T> {
@ApiModelProperty("真正的请求参数")
@Valid
private T param;
@ApiModelProperty("登录用户ID 前端不为userId赋值")
private Long userId;
@ApiModelProperty("用户名")
private String userName;
@ApiModelProperty("头像")
private String avatarUrl;
}

216
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();
}
}

1361
scheduler/src/main/java/com/ccsens/scheduler/bean/po/TaskExample.java

File diff suppressed because it is too large

9
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 {
}

30
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<Task> 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);
}

73
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<Task> 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;
}
}
}

9
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 {
}

46
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);
}

134
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<Task> 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;
}
}

11
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) {

621
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<Byte, String> 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;
}
}
}

238
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<? extends Job>) Class.forName(quartzModel.getJobClass()))
.withIdentity(quartzModel.getJobName(), quartzModel.getJobGroupName())
.setJobData(quartzModel.getJobDataMap()).build();
JobDetail job = JobBuilder.newJob((Class<? extends Job>) 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<Trigger> 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<CronTrigger> 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<? extends Trigger> 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;
}
/**

156
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<String, Object> 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<String> 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<Map<String, Object>> 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<String> response = util.restTemplate.postForEntity(uri, objectHttpEntity, String.class);
log.info("返回:{}", response);
return response.getBody();
}
public static String postBody(String url, List<? extends Object> params) {
log.info("路径:{}, 参数:{}", url, params);
HttpHeaders httpHeaders = new HttpHeaders();
MediaType type= MediaType.parseMediaType("application/json;charset=UTF-8");
httpHeaders.setContentType(type);
HttpEntity<List<? extends Object>> 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<String> 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<String, Object> 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<MultiValueMap> formEntity = new HttpEntity<>(paramMap, headers);
ResponseEntity<String> 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<String, Object> paramMap = transMultiValueMap(params);
HttpEntity<MultiValueMap> 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<java.lang.String,java.lang.Object>
*/
private static MultiValueMap<String, Object> transMultiValueMap(JSONObject params) {
MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<>();
for (String key: params.keySet()) {
paramMap.add(key, params.get(key));
}
return paramMap;
}
}

59
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);
}
}

4
scheduler/src/main/resources/config/mail.setting

@ -0,0 +1,4 @@
host = smtp.ccsens.com
port = 25
from = admin@ccsens.com
pass = q1w2e3

5
scheduler/src/main/resources/mapper_dao/TaskDao.xml

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ccsens.scheduler.persist.dao.TaskDao">
</mapper>

418
scheduler/src/main/resources/mapper_raw/TaskMapper.xml

@ -0,0 +1,418 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ccsens.scheduler.persist.mapper.TaskMapper">
<resultMap id="BaseResultMap" type="com.ccsens.scheduler.bean.po.Task">
<id column="id" jdbcType="BIGINT" property="id" />
<result column="job_name" jdbcType="VARCHAR" property="jobName" />
<result column="job_group_name" jdbcType="VARCHAR" property="jobGroupName" />
<result column="trigger_name" jdbcType="VARCHAR" property="triggerName" />
<result column="trigger_group_name" jdbcType="VARCHAR" property="triggerGroupName" />
<result column="cron" jdbcType="VARCHAR" property="cron" />
<result column="misfire_policy" jdbcType="VARCHAR" property="misfirePolicy" />
<result column="job" jdbcType="TINYINT" property="job" />
<result column="start_time" jdbcType="BIGINT" property="startTime" />
<result column="end_time" jdbcType="BIGINT" property="endTime" />
<result column="auto_move" jdbcType="TINYINT" property="autoMove" />
<result column="notify_way" jdbcType="TINYINT" property="notifyWay" />
<result column="notify_url" jdbcType="VARCHAR" property="notifyUrl" />
<result column="notify_param" jdbcType="VARCHAR" property="notifyParam" />
<result column="app_id" jdbcType="BIGINT" property="appId" />
<result column="created_at" jdbcType="TIMESTAMP" property="createdAt" />
<result column="updated_at" jdbcType="TIMESTAMP" property="updatedAt" />
<result column="rec_status" jdbcType="TINYINT" property="recStatus" />
</resultMap>
<sql id="Example_Where_Clause">
<where>
<foreach collection="oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Update_By_Example_Where_Clause">
<where>
<foreach collection="example.oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Base_Column_List">
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
</sql>
<select id="selectByExample" parameterType="com.ccsens.scheduler.bean.po.TaskExample" resultMap="BaseResultMap">
select
<if test="distinct">
distinct
</if>
<include refid="Base_Column_List" />
from t_task
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
</select>
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from t_task
where id = #{id,jdbcType=BIGINT}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
delete from t_task
where id = #{id,jdbcType=BIGINT}
</delete>
<delete id="deleteByExample" parameterType="com.ccsens.scheduler.bean.po.TaskExample">
delete from t_task
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</delete>
<insert id="insert" parameterType="com.ccsens.scheduler.bean.po.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>
<insert id="insertSelective" parameterType="com.ccsens.scheduler.bean.po.Task">
insert into t_task
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="jobName != null">
job_name,
</if>
<if test="jobGroupName != null">
job_group_name,
</if>
<if test="triggerName != null">
trigger_name,
</if>
<if test="triggerGroupName != null">
trigger_group_name,
</if>
<if test="cron != null">
cron,
</if>
<if test="misfirePolicy != null">
misfire_policy,
</if>
<if test="job != null">
job,
</if>
<if test="startTime != null">
start_time,
</if>
<if test="endTime != null">
end_time,
</if>
<if test="autoMove != null">
auto_move,
</if>
<if test="notifyWay != null">
notify_way,
</if>
<if test="notifyUrl != null">
notify_url,
</if>
<if test="notifyParam != null">
notify_param,
</if>
<if test="appId != null">
app_id,
</if>
<if test="createdAt != null">
created_at,
</if>
<if test="updatedAt != null">
updated_at,
</if>
<if test="recStatus != null">
rec_status,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=BIGINT},
</if>
<if test="jobName != null">
#{jobName,jdbcType=VARCHAR},
</if>
<if test="jobGroupName != null">
#{jobGroupName,jdbcType=VARCHAR},
</if>
<if test="triggerName != null">
#{triggerName,jdbcType=VARCHAR},
</if>
<if test="triggerGroupName != null">
#{triggerGroupName,jdbcType=VARCHAR},
</if>
<if test="cron != null">
#{cron,jdbcType=VARCHAR},
</if>
<if test="misfirePolicy != null">
#{misfirePolicy,jdbcType=VARCHAR},
</if>
<if test="job != null">
#{job,jdbcType=TINYINT},
</if>
<if test="startTime != null">
#{startTime,jdbcType=BIGINT},
</if>
<if test="endTime != null">
#{endTime,jdbcType=BIGINT},
</if>
<if test="autoMove != null">
#{autoMove,jdbcType=TINYINT},
</if>
<if test="notifyWay != null">
#{notifyWay,jdbcType=TINYINT},
</if>
<if test="notifyUrl != null">
#{notifyUrl,jdbcType=VARCHAR},
</if>
<if test="notifyParam != null">
#{notifyParam,jdbcType=VARCHAR},
</if>
<if test="appId != null">
#{appId,jdbcType=BIGINT},
</if>
<if test="createdAt != null">
#{createdAt,jdbcType=TIMESTAMP},
</if>
<if test="updatedAt != null">
#{updatedAt,jdbcType=TIMESTAMP},
</if>
<if test="recStatus != null">
#{recStatus,jdbcType=TINYINT},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="com.ccsens.scheduler.bean.po.TaskExample" resultType="java.lang.Long">
select count(*) from t_task
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</select>
<update id="updateByExampleSelective" parameterType="map">
update t_task
<set>
<if test="record.id != null">
id = #{record.id,jdbcType=BIGINT},
</if>
<if test="record.jobName != null">
job_name = #{record.jobName,jdbcType=VARCHAR},
</if>
<if test="record.jobGroupName != null">
job_group_name = #{record.jobGroupName,jdbcType=VARCHAR},
</if>
<if test="record.triggerName != null">
trigger_name = #{record.triggerName,jdbcType=VARCHAR},
</if>
<if test="record.triggerGroupName != null">
trigger_group_name = #{record.triggerGroupName,jdbcType=VARCHAR},
</if>
<if test="record.cron != null">
cron = #{record.cron,jdbcType=VARCHAR},
</if>
<if test="record.misfirePolicy != null">
misfire_policy = #{record.misfirePolicy,jdbcType=VARCHAR},
</if>
<if test="record.job != null">
job = #{record.job,jdbcType=TINYINT},
</if>
<if test="record.startTime != null">
start_time = #{record.startTime,jdbcType=BIGINT},
</if>
<if test="record.endTime != null">
end_time = #{record.endTime,jdbcType=BIGINT},
</if>
<if test="record.autoMove != null">
auto_move = #{record.autoMove,jdbcType=TINYINT},
</if>
<if test="record.notifyWay != null">
notify_way = #{record.notifyWay,jdbcType=TINYINT},
</if>
<if test="record.notifyUrl != null">
notify_url = #{record.notifyUrl,jdbcType=VARCHAR},
</if>
<if test="record.notifyParam != null">
notify_param = #{record.notifyParam,jdbcType=VARCHAR},
</if>
<if test="record.appId != null">
app_id = #{record.appId,jdbcType=BIGINT},
</if>
<if test="record.createdAt != null">
created_at = #{record.createdAt,jdbcType=TIMESTAMP},
</if>
<if test="record.updatedAt != null">
updated_at = #{record.updatedAt,jdbcType=TIMESTAMP},
</if>
<if test="record.recStatus != null">
rec_status = #{record.recStatus,jdbcType=TINYINT},
</if>
</set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByExample" parameterType="map">
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}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByPrimaryKeySelective" parameterType="com.ccsens.scheduler.bean.po.Task">
update t_task
<set>
<if test="jobName != null">
job_name = #{jobName,jdbcType=VARCHAR},
</if>
<if test="jobGroupName != null">
job_group_name = #{jobGroupName,jdbcType=VARCHAR},
</if>
<if test="triggerName != null">
trigger_name = #{triggerName,jdbcType=VARCHAR},
</if>
<if test="triggerGroupName != null">
trigger_group_name = #{triggerGroupName,jdbcType=VARCHAR},
</if>
<if test="cron != null">
cron = #{cron,jdbcType=VARCHAR},
</if>
<if test="misfirePolicy != null">
misfire_policy = #{misfirePolicy,jdbcType=VARCHAR},
</if>
<if test="job != null">
job = #{job,jdbcType=TINYINT},
</if>
<if test="startTime != null">
start_time = #{startTime,jdbcType=BIGINT},
</if>
<if test="endTime != null">
end_time = #{endTime,jdbcType=BIGINT},
</if>
<if test="autoMove != null">
auto_move = #{autoMove,jdbcType=TINYINT},
</if>
<if test="notifyWay != null">
notify_way = #{notifyWay,jdbcType=TINYINT},
</if>
<if test="notifyUrl != null">
notify_url = #{notifyUrl,jdbcType=VARCHAR},
</if>
<if test="notifyParam != null">
notify_param = #{notifyParam,jdbcType=VARCHAR},
</if>
<if test="appId != null">
app_id = #{appId,jdbcType=BIGINT},
</if>
<if test="createdAt != null">
created_at = #{createdAt,jdbcType=TIMESTAMP},
</if>
<if test="updatedAt != null">
updated_at = #{updatedAt,jdbcType=TIMESTAMP},
</if>
<if test="recStatus != null">
rec_status = #{recStatus,jdbcType=TINYINT},
</if>
</set>
where id = #{id,jdbcType=BIGINT}
</update>
<update id="updateByPrimaryKey" parameterType="com.ccsens.scheduler.bean.po.Task">
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}
</update>
</mapper>

2
scheduler/src/main/resources/mbg.xml

@ -56,7 +56,7 @@
<property name="enableSubPackages" value="false" />
</javaClientGenerator>
<table tableName="t_file_commit" domainObjectName="FileCommit"/>
<table tableName="t_task" domainObjectName="Task"/>

Loading…
Cancel
Save