26 changed files with 1812 additions and 11 deletions
@ -0,0 +1,23 @@ |
|||
package cn.chjyj.szwh.bean; |
|||
|
|||
public class CronTrigger extends CronTriggerKey { |
|||
private String cronExpression; |
|||
|
|||
private String timeZoneId; |
|||
|
|||
public String getCronExpression() { |
|||
return cronExpression; |
|||
} |
|||
|
|||
public void setCronExpression(String cronExpression) { |
|||
this.cronExpression = cronExpression == null ? null : cronExpression.trim(); |
|||
} |
|||
|
|||
public String getTimeZoneId() { |
|||
return timeZoneId; |
|||
} |
|||
|
|||
public void setTimeZoneId(String timeZoneId) { |
|||
this.timeZoneId = timeZoneId == null ? null : timeZoneId.trim(); |
|||
} |
|||
} |
|||
@ -0,0 +1,33 @@ |
|||
package cn.chjyj.szwh.bean; |
|||
|
|||
public class CronTriggerKey { |
|||
private String schedName; |
|||
|
|||
private String triggerName; |
|||
|
|||
private String triggerGroup; |
|||
|
|||
public String getSchedName() { |
|||
return schedName; |
|||
} |
|||
|
|||
public void setSchedName(String schedName) { |
|||
this.schedName = schedName == null ? null : schedName.trim(); |
|||
} |
|||
|
|||
public String getTriggerName() { |
|||
return triggerName; |
|||
} |
|||
|
|||
public void setTriggerName(String triggerName) { |
|||
this.triggerName = triggerName == null ? null : triggerName.trim(); |
|||
} |
|||
|
|||
public String getTriggerGroup() { |
|||
return triggerGroup; |
|||
} |
|||
|
|||
public void setTriggerGroup(String triggerGroup) { |
|||
this.triggerGroup = triggerGroup == null ? null : triggerGroup.trim(); |
|||
} |
|||
} |
|||
@ -0,0 +1,130 @@ |
|||
package cn.chjyj.szwh.bean; |
|||
|
|||
import java.math.BigInteger; |
|||
|
|||
/** |
|||
* Quartz 定时bean |
|||
*/ |
|||
|
|||
public class JobAndTrigger { |
|||
/** |
|||
* 定时任务名称 |
|||
*/ |
|||
private String jobName; |
|||
/** |
|||
* 定时任务组 |
|||
*/ |
|||
private String jobGroup; |
|||
/** |
|||
* 定时任务全类名 |
|||
*/ |
|||
private String jobClassName; |
|||
/** |
|||
* 触发器名称 |
|||
*/ |
|||
private String triggerName; |
|||
/** |
|||
* 触发器组 |
|||
*/ |
|||
private String triggerGroup; |
|||
/** |
|||
* 重复间隔 |
|||
*/ |
|||
private BigInteger repeatInterval; |
|||
/** |
|||
* 触发次数 |
|||
*/ |
|||
private BigInteger timesTriggered; |
|||
/** |
|||
* cron 表达式 |
|||
*/ |
|||
private String cronExpression; |
|||
/** |
|||
* 时区 |
|||
*/ |
|||
private String timeZoneId; |
|||
/** |
|||
* 定时任务状态 |
|||
*/ |
|||
private String triggerState; |
|||
|
|||
public String getJobName() { |
|||
return jobName; |
|||
} |
|||
|
|||
public void setJobName(String jobName) { |
|||
this.jobName = jobName; |
|||
} |
|||
|
|||
public String getJobGroup() { |
|||
return jobGroup; |
|||
} |
|||
|
|||
public void setJobGroup(String jobGroup) { |
|||
this.jobGroup = jobGroup; |
|||
} |
|||
|
|||
public String getJobClassName() { |
|||
return jobClassName; |
|||
} |
|||
|
|||
public void setJobClassName(String jobClassName) { |
|||
this.jobClassName = jobClassName; |
|||
} |
|||
|
|||
public String getTriggerName() { |
|||
return triggerName; |
|||
} |
|||
|
|||
public void setTriggerName(String triggerName) { |
|||
this.triggerName = triggerName; |
|||
} |
|||
|
|||
public String getTriggerGroup() { |
|||
return triggerGroup; |
|||
} |
|||
|
|||
public void setTriggerGroup(String triggerGroup) { |
|||
this.triggerGroup = triggerGroup; |
|||
} |
|||
|
|||
public BigInteger getRepeatInterval() { |
|||
return repeatInterval; |
|||
} |
|||
|
|||
public void setRepeatInterval(BigInteger repeatInterval) { |
|||
this.repeatInterval = repeatInterval; |
|||
} |
|||
|
|||
public BigInteger getTimesTriggered() { |
|||
return timesTriggered; |
|||
} |
|||
|
|||
public void setTimesTriggered(BigInteger timesTriggered) { |
|||
this.timesTriggered = timesTriggered; |
|||
} |
|||
|
|||
public String getCronExpression() { |
|||
return cronExpression; |
|||
} |
|||
|
|||
public void setCronExpression(String cronExpression) { |
|||
this.cronExpression = cronExpression; |
|||
} |
|||
|
|||
public String getTimeZoneId() { |
|||
return timeZoneId; |
|||
} |
|||
|
|||
public void setTimeZoneId(String timeZoneId) { |
|||
this.timeZoneId = timeZoneId; |
|||
} |
|||
|
|||
public String getTriggerState() { |
|||
return triggerState; |
|||
} |
|||
|
|||
public void setTriggerState(String triggerState) { |
|||
this.triggerState = triggerState; |
|||
} |
|||
} |
|||
@ -0,0 +1,73 @@ |
|||
package cn.chjyj.szwh.bean; |
|||
|
|||
public class JobDetail extends JobDetailKey { |
|||
private String description; |
|||
|
|||
private String jobClassName; |
|||
|
|||
private String isDurable; |
|||
|
|||
private String isNonconcurrent; |
|||
|
|||
private String isUpdateData; |
|||
|
|||
private String requestsRecovery; |
|||
|
|||
private byte[] jobData; |
|||
|
|||
public String getDescription() { |
|||
return description; |
|||
} |
|||
|
|||
public void setDescription(String description) { |
|||
this.description = description == null ? null : description.trim(); |
|||
} |
|||
|
|||
public String getJobClassName() { |
|||
return jobClassName; |
|||
} |
|||
|
|||
public void setJobClassName(String jobClassName) { |
|||
this.jobClassName = jobClassName == null ? null : jobClassName.trim(); |
|||
} |
|||
|
|||
public String getIsDurable() { |
|||
return isDurable; |
|||
} |
|||
|
|||
public void setIsDurable(String isDurable) { |
|||
this.isDurable = isDurable == null ? null : isDurable.trim(); |
|||
} |
|||
|
|||
public String getIsNonconcurrent() { |
|||
return isNonconcurrent; |
|||
} |
|||
|
|||
public void setIsNonconcurrent(String isNonconcurrent) { |
|||
this.isNonconcurrent = isNonconcurrent == null ? null : isNonconcurrent.trim(); |
|||
} |
|||
|
|||
public String getIsUpdateData() { |
|||
return isUpdateData; |
|||
} |
|||
|
|||
public void setIsUpdateData(String isUpdateData) { |
|||
this.isUpdateData = isUpdateData == null ? null : isUpdateData.trim(); |
|||
} |
|||
|
|||
public String getRequestsRecovery() { |
|||
return requestsRecovery; |
|||
} |
|||
|
|||
public void setRequestsRecovery(String requestsRecovery) { |
|||
this.requestsRecovery = requestsRecovery == null ? null : requestsRecovery.trim(); |
|||
} |
|||
|
|||
public byte[] getJobData() { |
|||
return jobData; |
|||
} |
|||
|
|||
public void setJobData(byte[] jobData) { |
|||
this.jobData = jobData; |
|||
} |
|||
} |
|||
@ -0,0 +1,33 @@ |
|||
package cn.chjyj.szwh.bean; |
|||
|
|||
public class JobDetailKey { |
|||
private String schedName; |
|||
|
|||
private String jobName; |
|||
|
|||
private String jobGroup; |
|||
|
|||
public String getSchedName() { |
|||
return schedName; |
|||
} |
|||
|
|||
public void setSchedName(String schedName) { |
|||
this.schedName = schedName == null ? null : schedName.trim(); |
|||
} |
|||
|
|||
public String getJobName() { |
|||
return jobName; |
|||
} |
|||
|
|||
public void setJobName(String jobName) { |
|||
this.jobName = jobName == null ? null : jobName.trim(); |
|||
} |
|||
|
|||
public String getJobGroup() { |
|||
return jobGroup; |
|||
} |
|||
|
|||
public void setJobGroup(String jobGroup) { |
|||
this.jobGroup = jobGroup == null ? null : jobGroup.trim(); |
|||
} |
|||
} |
|||
@ -0,0 +1,133 @@ |
|||
package cn.chjyj.szwh.bean; |
|||
|
|||
public class Trigger extends TriggerKey { |
|||
private String jobName; |
|||
|
|||
private String jobGroup; |
|||
|
|||
private String description; |
|||
|
|||
private Long nextFireTime; |
|||
|
|||
private Long prevFireTime; |
|||
|
|||
private Integer priority; |
|||
|
|||
private String triggerState; |
|||
|
|||
private String triggerType; |
|||
|
|||
private Long startTime; |
|||
|
|||
private Long endTime; |
|||
|
|||
private String calendarName; |
|||
|
|||
private Short misfireInstr; |
|||
|
|||
private byte[] jobData; |
|||
|
|||
public String getJobName() { |
|||
return jobName; |
|||
} |
|||
|
|||
public void setJobName(String jobName) { |
|||
this.jobName = jobName == null ? null : jobName.trim(); |
|||
} |
|||
|
|||
public String getJobGroup() { |
|||
return jobGroup; |
|||
} |
|||
|
|||
public void setJobGroup(String jobGroup) { |
|||
this.jobGroup = jobGroup == null ? null : jobGroup.trim(); |
|||
} |
|||
|
|||
public String getDescription() { |
|||
return description; |
|||
} |
|||
|
|||
public void setDescription(String description) { |
|||
this.description = description == null ? null : description.trim(); |
|||
} |
|||
|
|||
public Long getNextFireTime() { |
|||
return nextFireTime; |
|||
} |
|||
|
|||
public void setNextFireTime(Long nextFireTime) { |
|||
this.nextFireTime = nextFireTime; |
|||
} |
|||
|
|||
public Long getPrevFireTime() { |
|||
return prevFireTime; |
|||
} |
|||
|
|||
public void setPrevFireTime(Long prevFireTime) { |
|||
this.prevFireTime = prevFireTime; |
|||
} |
|||
|
|||
public Integer getPriority() { |
|||
return priority; |
|||
} |
|||
|
|||
public void setPriority(Integer priority) { |
|||
this.priority = priority; |
|||
} |
|||
|
|||
public String getTriggerState() { |
|||
return triggerState; |
|||
} |
|||
|
|||
public void setTriggerState(String triggerState) { |
|||
this.triggerState = triggerState == null ? null : triggerState.trim(); |
|||
} |
|||
|
|||
public String getTriggerType() { |
|||
return triggerType; |
|||
} |
|||
|
|||
public void setTriggerType(String triggerType) { |
|||
this.triggerType = triggerType == null ? null : triggerType.trim(); |
|||
} |
|||
|
|||
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 String getCalendarName() { |
|||
return calendarName; |
|||
} |
|||
|
|||
public void setCalendarName(String calendarName) { |
|||
this.calendarName = calendarName == null ? null : calendarName.trim(); |
|||
} |
|||
|
|||
public Short getMisfireInstr() { |
|||
return misfireInstr; |
|||
} |
|||
|
|||
public void setMisfireInstr(Short misfireInstr) { |
|||
this.misfireInstr = misfireInstr; |
|||
} |
|||
|
|||
public byte[] getJobData() { |
|||
return jobData; |
|||
} |
|||
|
|||
public void setJobData(byte[] jobData) { |
|||
this.jobData = jobData; |
|||
} |
|||
} |
|||
@ -0,0 +1,33 @@ |
|||
package cn.chjyj.szwh.bean; |
|||
|
|||
public class TriggerKey { |
|||
private String schedName; |
|||
|
|||
private String triggerName; |
|||
|
|||
private String triggerGroup; |
|||
|
|||
public String getSchedName() { |
|||
return schedName; |
|||
} |
|||
|
|||
public void setSchedName(String schedName) { |
|||
this.schedName = schedName == null ? null : schedName.trim(); |
|||
} |
|||
|
|||
public String getTriggerName() { |
|||
return triggerName; |
|||
} |
|||
|
|||
public void setTriggerName(String triggerName) { |
|||
this.triggerName = triggerName == null ? null : triggerName.trim(); |
|||
} |
|||
|
|||
public String getTriggerGroup() { |
|||
return triggerGroup; |
|||
} |
|||
|
|||
public void setTriggerGroup(String triggerGroup) { |
|||
this.triggerGroup = triggerGroup == null ? null : triggerGroup.trim(); |
|||
} |
|||
} |
|||
@ -0,0 +1,59 @@ |
|||
package cn.chjyj.szwh.configure; |
|||
|
|||
import org.quartz.Scheduler; |
|||
import org.quartz.ee.servlet.QuartzInitializerListener; |
|||
import org.springframework.beans.factory.config.PropertiesFactoryBean; |
|||
import org.springframework.boot.autoconfigure.quartz.SchedulerFactoryBeanCustomizer; |
|||
import org.springframework.context.annotation.Bean; |
|||
import org.springframework.context.annotation.Configuration; |
|||
import org.springframework.core.io.ClassPathResource; |
|||
import org.springframework.scheduling.quartz.SchedulerFactoryBean; |
|||
|
|||
import java.io.IOException; |
|||
import java.util.Properties; |
|||
|
|||
/** |
|||
* @Author: CJ |
|||
* @Date: 2021-11-1 19:34 |
|||
*/ |
|||
@Configuration |
|||
public class QuartzConfig implements SchedulerFactoryBeanCustomizer { |
|||
|
|||
@Bean |
|||
public Properties properties() throws IOException { |
|||
PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean(); |
|||
// 对quartz.properties文件进行读取
|
|||
propertiesFactoryBean.setLocation(new ClassPathResource("/quartz.properties")); |
|||
// 在quartz.properties中的属性被读取并注入后再初始化对象
|
|||
propertiesFactoryBean.afterPropertiesSet(); |
|||
return propertiesFactoryBean.getObject(); |
|||
} |
|||
|
|||
@Bean |
|||
public SchedulerFactoryBean schedulerFactoryBean() throws IOException { |
|||
SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean(); |
|||
schedulerFactoryBean.setQuartzProperties(properties()); |
|||
return schedulerFactoryBean; |
|||
} |
|||
|
|||
/* |
|||
* quartz初始化监听器 |
|||
*/ |
|||
@Bean |
|||
public QuartzInitializerListener executorListener() { |
|||
return new QuartzInitializerListener(); |
|||
} |
|||
|
|||
/* |
|||
* 通过SchedulerFactoryBean获取Scheduler的实例 |
|||
*/ |
|||
@Bean |
|||
public Scheduler scheduler() throws IOException { |
|||
return schedulerFactoryBean().getScheduler(); |
|||
} |
|||
|
|||
@Override |
|||
public void customize(SchedulerFactoryBean schedulerFactoryBean) { |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,176 @@ |
|||
package cn.chjyj.szwh.controller; |
|||
|
|||
import cn.chjyj.szwh.dto.JobAndTriggerDto; |
|||
import cn.chjyj.szwh.service.QuartzService; |
|||
import com.alibaba.fastjson.JSONObject; |
|||
import com.github.pagehelper.PageInfo; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.web.bind.annotation.GetMapping; |
|||
import org.springframework.web.bind.annotation.PostMapping; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.bind.annotation.ResponseBody; |
|||
|
|||
import java.util.HashMap; |
|||
import java.util.Map; |
|||
|
|||
import org.quartz.SchedulerException; |
|||
import org.springframework.util.StringUtils; |
|||
import org.springframework.web.bind.annotation.*; |
|||
|
|||
|
|||
/** |
|||
* @Author: CJ |
|||
* @Date: 2021-11-2 11:41 |
|||
*/ |
|||
@RestController |
|||
@RequestMapping(path = "/quartz") |
|||
public class QuartzController { |
|||
|
|||
@Autowired |
|||
private QuartzService quartzService; |
|||
|
|||
/** |
|||
* 新增定时任务 |
|||
* |
|||
* @param jName 任务名称 |
|||
* @param jGroup 任务组 |
|||
* @param tName 触发器名称 |
|||
* @param tGroup 触发器组 |
|||
* @param cron cron表达式 |
|||
* @return ResultMap |
|||
*/ |
|||
@PostMapping(path = "/addjob") |
|||
@ResponseBody |
|||
public JSONObject addjob(String jName, String jGroup, String tName, String tGroup, String cron) { |
|||
JSONObject jsonObject = new JSONObject(); |
|||
try { |
|||
quartzService.addjob(jName, jGroup, tName, tGroup, cron); |
|||
jsonObject.put("code",200); |
|||
jsonObject.put("msg","添加任务成功"); |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
jsonObject.put("code",400); |
|||
jsonObject.put("msg","添加任务失败"); |
|||
} |
|||
return jsonObject; |
|||
} |
|||
|
|||
/** |
|||
* 暂停任务 |
|||
* |
|||
* @param jName 任务名称 |
|||
* @param jGroup 任务组 |
|||
* @return ResultMap |
|||
*/ |
|||
@PostMapping(path = "/pausejob") |
|||
@ResponseBody |
|||
public JSONObject pausejob(String jName, String jGroup) { |
|||
JSONObject jsonObject = new JSONObject(); |
|||
try { |
|||
quartzService.pausejob(jName, jGroup); |
|||
jsonObject.put("code",200); |
|||
jsonObject.put("msg","暂停任务成功"); |
|||
} catch (SchedulerException e) { |
|||
e.printStackTrace(); |
|||
jsonObject.put("code",200); |
|||
jsonObject.put("msg","暂停任务失败"); |
|||
} |
|||
return jsonObject; |
|||
} |
|||
|
|||
/** |
|||
* 恢复任务 |
|||
* |
|||
* @param jName 任务名称 |
|||
* @param jGroup 任务组 |
|||
* @return ResultMap |
|||
*/ |
|||
@PostMapping(path = "/resumejob") |
|||
@ResponseBody |
|||
public JSONObject resumejob(String jName, String jGroup) { |
|||
JSONObject jsonObject = new JSONObject(); |
|||
try { |
|||
quartzService.resumejob(jName, jGroup); |
|||
jsonObject.put("code",200); |
|||
jsonObject.put("msg","恢复任务成功"); |
|||
} catch (SchedulerException e) { |
|||
e.printStackTrace(); |
|||
jsonObject.put("code",400); |
|||
jsonObject.put("msg","恢复任务失败"); |
|||
} |
|||
return jsonObject; |
|||
} |
|||
|
|||
/** |
|||
* 重启任务 |
|||
* |
|||
* @param jName 任务名称 |
|||
* @param jGroup 任务组 |
|||
* @param cron cron表达式 |
|||
* @return ResultMap |
|||
*/ |
|||
@PostMapping(path = "/reschedulejob") |
|||
@ResponseBody |
|||
public JSONObject rescheduleJob(String jName, String jGroup, String cron) { |
|||
JSONObject jsonObject =new JSONObject(); |
|||
try { |
|||
quartzService.rescheduleJob(jName, jGroup, cron); |
|||
jsonObject.put("code",200); |
|||
jsonObject.put("msg","重启任务成功"); |
|||
} catch (SchedulerException e) { |
|||
e.printStackTrace(); |
|||
jsonObject.put("code",400); |
|||
jsonObject.put("msg","重启任务失败"); |
|||
} |
|||
return jsonObject; |
|||
} |
|||
|
|||
/** |
|||
* 删除任务 |
|||
* |
|||
* @param jName 任务名称 |
|||
* @param jGroup 任务组 |
|||
* @return ResultMap |
|||
*/ |
|||
@PostMapping(path = "/deletejob") |
|||
@ResponseBody |
|||
public JSONObject deletejob(String jName, String jGroup) { |
|||
JSONObject jsonObject = new JSONObject(); |
|||
try { |
|||
quartzService.deletejob(jName, jGroup); |
|||
jsonObject.put("code",200); |
|||
jsonObject.put("msg","删除任务成功"); |
|||
} catch (SchedulerException e) { |
|||
e.printStackTrace(); |
|||
jsonObject.put("code",400); |
|||
jsonObject.put("msg","删除任务失败"); |
|||
} |
|||
return jsonObject; |
|||
} |
|||
|
|||
/** |
|||
* 查询任务 |
|||
* |
|||
* @param pageNum 页码 |
|||
* @param pageSize 每页显示多少条数据 |
|||
* @return Map |
|||
*/ |
|||
@GetMapping(path = "/queryjob") |
|||
@ResponseBody |
|||
public JSONObject queryjob(Integer pageNum, Integer pageSize) { |
|||
JSONObject jsonObject = new JSONObject(); |
|||
PageInfo<JobAndTriggerDto> pageInfo = quartzService.getJobAndTriggerDetails(pageNum, pageSize); |
|||
Map<String, Object> map = new HashMap<>(); |
|||
if (!StringUtils.isEmpty(pageInfo.getTotal())) { |
|||
map.put("JobAndTrigger", pageInfo); |
|||
map.put("number", pageInfo.getTotal()); |
|||
jsonObject.put("code",200); |
|||
jsonObject.put("msg","查询任务成功"); |
|||
jsonObject.put("data",map); |
|||
}else{ |
|||
jsonObject.put("code",400); |
|||
jsonObject.put("msg","查询任务成功失败,没有数据"); |
|||
} |
|||
return jsonObject; |
|||
} |
|||
} |
|||
@ -0,0 +1,100 @@ |
|||
package cn.chjyj.szwh.dto; |
|||
|
|||
import java.math.BigInteger; |
|||
|
|||
/** |
|||
*@Author: CJ |
|||
*@Date: 2021-11-2 14:15 |
|||
*/ |
|||
public class JobAndTriggerDto { |
|||
|
|||
private String JOB_NAME; |
|||
|
|||
private String JOB_GROUP; |
|||
|
|||
private String JOB_CLASS_NAME; |
|||
|
|||
private String TRIGGER_NAME; |
|||
|
|||
private String TRIGGER_GROUP; |
|||
|
|||
private BigInteger REPEAT_INTERVAL; |
|||
|
|||
private BigInteger TIMES_TRIGGERED; |
|||
|
|||
private String CRON_EXPRESSION; |
|||
|
|||
private String TIME_ZONE_ID; |
|||
|
|||
public String getJOB_NAME() { |
|||
return JOB_NAME; |
|||
} |
|||
|
|||
public void setJOB_NAME(String JOB_NAME) { |
|||
this.JOB_NAME = JOB_NAME; |
|||
} |
|||
|
|||
public String getJOB_GROUP() { |
|||
return JOB_GROUP; |
|||
} |
|||
|
|||
public void setJOB_GROUP(String JOB_GROUP) { |
|||
this.JOB_GROUP = JOB_GROUP; |
|||
} |
|||
|
|||
public String getJOB_CLASS_NAME() { |
|||
return JOB_CLASS_NAME; |
|||
} |
|||
|
|||
public void setJOB_CLASS_NAME(String JOB_CLASS_NAME) { |
|||
this.JOB_CLASS_NAME = JOB_CLASS_NAME; |
|||
} |
|||
|
|||
public String getTRIGGER_NAME() { |
|||
return TRIGGER_NAME; |
|||
} |
|||
|
|||
public void setTRIGGER_NAME(String TRIGGER_NAME) { |
|||
this.TRIGGER_NAME = TRIGGER_NAME; |
|||
} |
|||
|
|||
public String getTRIGGER_GROUP() { |
|||
return TRIGGER_GROUP; |
|||
} |
|||
|
|||
public void setTRIGGER_GROUP(String TRIGGER_GROUP) { |
|||
this.TRIGGER_GROUP = TRIGGER_GROUP; |
|||
} |
|||
|
|||
public BigInteger getREPEAT_INTERVAL() { |
|||
return REPEAT_INTERVAL; |
|||
} |
|||
|
|||
public void setREPEAT_INTERVAL(BigInteger REPEAT_INTERVAL) { |
|||
this.REPEAT_INTERVAL = REPEAT_INTERVAL; |
|||
} |
|||
|
|||
public BigInteger getTIMES_TRIGGERED() { |
|||
return TIMES_TRIGGERED; |
|||
} |
|||
|
|||
public void setTIMES_TRIGGERED(BigInteger TIMES_TRIGGERED) { |
|||
this.TIMES_TRIGGERED = TIMES_TRIGGERED; |
|||
} |
|||
|
|||
public String getCRON_EXPRESSION() { |
|||
return CRON_EXPRESSION; |
|||
} |
|||
|
|||
public void setCRON_EXPRESSION(String CRON_EXPRESSION) { |
|||
this.CRON_EXPRESSION = CRON_EXPRESSION; |
|||
} |
|||
|
|||
public String getTIME_ZONE_ID() { |
|||
return TIME_ZONE_ID; |
|||
} |
|||
|
|||
public void setTIME_ZONE_ID(String TIME_ZONE_ID) { |
|||
this.TIME_ZONE_ID = TIME_ZONE_ID; |
|||
} |
|||
} |
|||
@ -0,0 +1,29 @@ |
|||
package cn.chjyj.szwh.job; |
|||
|
|||
|
|||
import cn.chjyj.szwh.dto.JobAndTriggerDto; |
|||
import cn.chjyj.szwh.service.QuartzService; |
|||
import com.github.pagehelper.PageInfo; |
|||
import org.apache.commons.logging.Log; |
|||
import org.apache.commons.logging.LogFactory; |
|||
import org.quartz.Job; |
|||
import org.quartz.JobExecutionContext; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
|
|||
/** |
|||
*@Author: CJ |
|||
*@Date: 2021-11-2 11:33 |
|||
*/ |
|||
public class HelloJob implements Job { |
|||
private static Log log = LogFactory.getLog(HelloJob.class); |
|||
@Autowired |
|||
private QuartzService quartzService; |
|||
|
|||
@Override |
|||
public void execute(JobExecutionContext jobExecutionContext) { |
|||
//QuartzService quartzService = (QuartzService) SpringUtil.getBean("quartzServiceImpl");
|
|||
PageInfo<JobAndTriggerDto> jobAndTriggerDetails = quartzService.getJobAndTriggerDetails(1, 10); |
|||
log.info("任务列表总数为:" + jobAndTriggerDetails.getTotal()); |
|||
log.info("Hello Job执行时间: " + System.currentTimeMillis()); |
|||
} |
|||
} |
|||
@ -0,0 +1,18 @@ |
|||
package cn.chjyj.szwh.mapper; |
|||
|
|||
import org.example.pojo.CronTrigger; |
|||
import org.example.pojo.CronTriggerKey; |
|||
|
|||
public interface CronTriggerMapper { |
|||
int deleteByPrimaryKey(CronTriggerKey key); |
|||
|
|||
int insert(CronTrigger record); |
|||
|
|||
int insertSelective(CronTrigger record); |
|||
|
|||
CronTrigger selectByPrimaryKey(CronTriggerKey key); |
|||
|
|||
int updateByPrimaryKeySelective(CronTrigger record); |
|||
|
|||
int updateByPrimaryKey(CronTrigger record); |
|||
} |
|||
@ -0,0 +1,28 @@ |
|||
package cn.chjyj.szwh.mapper; |
|||
|
|||
|
|||
import cn.chjyj.szwh.bean.JobDetail; |
|||
import cn.chjyj.szwh.bean.JobDetailKey; |
|||
import cn.chjyj.szwh.dto.JobAndTriggerDto; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import java.util.List; |
|||
|
|||
@Component |
|||
public interface JobDetailMapper { |
|||
int deleteByPrimaryKey(JobDetailKey key); |
|||
|
|||
int insert(JobDetail record); |
|||
|
|||
int insertSelective(JobDetail record); |
|||
|
|||
JobDetail selectByPrimaryKey(JobDetailKey key); |
|||
|
|||
int updateByPrimaryKeySelective(JobDetail record); |
|||
|
|||
int updateByPrimaryKeyWithBLOBs(JobDetail record); |
|||
|
|||
int updateByPrimaryKey(JobDetail record); |
|||
|
|||
List<JobAndTriggerDto> getJobAndTriggerDetails(); |
|||
} |
|||
@ -0,0 +1,20 @@ |
|||
package cn.chjyj.szwh.mapper; |
|||
|
|||
import org.example.pojo.Trigger; |
|||
import org.example.pojo.TriggerKey; |
|||
|
|||
public interface TriggerMapper { |
|||
int deleteByPrimaryKey(TriggerKey key); |
|||
|
|||
int insert(Trigger record); |
|||
|
|||
int insertSelective(Trigger record); |
|||
|
|||
Trigger selectByPrimaryKey(TriggerKey key); |
|||
|
|||
int updateByPrimaryKeySelective(Trigger record); |
|||
|
|||
int updateByPrimaryKeyWithBLOBs(Trigger record); |
|||
|
|||
int updateByPrimaryKey(Trigger record); |
|||
} |
|||
@ -0,0 +1,24 @@ |
|||
package cn.chjyj.szwh.service; |
|||
|
|||
import cn.chjyj.szwh.dto.JobAndTriggerDto; |
|||
import com.github.pagehelper.PageInfo; |
|||
import org.quartz.SchedulerException; |
|||
|
|||
/** |
|||
*@Author: CJ |
|||
*@Date: 2021-11-2 14:20 |
|||
*/ |
|||
public interface QuartzService { |
|||
|
|||
PageInfo<JobAndTriggerDto> getJobAndTriggerDetails(Integer pageNum, Integer pageSize); |
|||
|
|||
void addjob(String jName, String jGroup, String tName, String tGroup, String cron); |
|||
|
|||
void pausejob(String jName, String jGroupe) throws SchedulerException; |
|||
|
|||
void resumejob(String jName, String jGroup) throws SchedulerException; |
|||
|
|||
void rescheduleJob(String jName, String jGroup, String cron) throws SchedulerException; |
|||
|
|||
void deletejob(String jName, String jGroup) throws SchedulerException; |
|||
} |
|||
@ -0,0 +1,98 @@ |
|||
package cn.chjyj.szwh.service.impl; |
|||
|
|||
import cn.chjyj.szwh.dto.JobAndTriggerDto; |
|||
import cn.chjyj.szwh.job.HelloJob; |
|||
import cn.chjyj.szwh.mapper.JobDetailMapper; |
|||
import cn.chjyj.szwh.service.QuartzService; |
|||
import com.github.pagehelper.PageHelper; |
|||
import com.github.pagehelper.PageInfo; |
|||
import org.apache.commons.logging.Log; |
|||
import org.apache.commons.logging.LogFactory; |
|||
import org.quartz.*; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
import java.util.List; |
|||
|
|||
/** |
|||
*@Author: CJ |
|||
*@Date: 2021-11-2 14:20 |
|||
*/ |
|||
|
|||
@Service |
|||
public class QuartzServiceImpl implements QuartzService { |
|||
private Log log = LogFactory.getLog(QuartzServiceImpl.class); |
|||
|
|||
@Autowired |
|||
private JobDetailMapper jobDetailMapper; |
|||
|
|||
@Autowired |
|||
private Scheduler scheduler; |
|||
|
|||
@Override |
|||
public PageInfo<JobAndTriggerDto> getJobAndTriggerDetails(Integer pageNum, Integer pageSize) { |
|||
PageHelper.startPage(pageNum, pageSize); |
|||
List<JobAndTriggerDto> list = jobDetailMapper.getJobAndTriggerDetails(); |
|||
PageInfo<JobAndTriggerDto> pageInfo = new PageInfo<>(list); |
|||
return pageInfo; |
|||
} |
|||
|
|||
/** |
|||
* 新增定时任务 |
|||
* |
|||
* @param jName 任务名称 |
|||
* @param jGroup 任务组 |
|||
* @param tName 触发器名称 |
|||
* @param tGroup 触发器组 |
|||
* @param cron cron表达式 |
|||
*/ |
|||
@Override |
|||
public void addjob(String jName, String jGroup, String tName, String tGroup, String cron) { |
|||
try { |
|||
// 构建JobDetail
|
|||
JobDetail jobDetail = JobBuilder.newJob(HelloJob.class) |
|||
.withIdentity(jName, jGroup) |
|||
.build(); |
|||
// 按新的cronExpression表达式构建一个新的trigger
|
|||
CronTrigger trigger = TriggerBuilder.newTrigger() |
|||
.withIdentity(tName, tGroup) |
|||
.startNow() |
|||
.withSchedule(CronScheduleBuilder.cronSchedule(cron)) |
|||
.build(); |
|||
// 启动调度器
|
|||
scheduler.start(); |
|||
scheduler.scheduleJob(jobDetail, trigger); |
|||
} catch (Exception e) { |
|||
log.info("创建定时任务失败" + e); |
|||
} |
|||
} |
|||
|
|||
@Override |
|||
public void pausejob(String jName, String jGroup) throws SchedulerException { |
|||
scheduler.pauseJob(JobKey.jobKey(jName, jGroup)); |
|||
} |
|||
|
|||
@Override |
|||
public void resumejob(String jName, String jGroup) throws SchedulerException { |
|||
scheduler.resumeJob(JobKey.jobKey(jName, jGroup)); |
|||
} |
|||
|
|||
@Override |
|||
public void rescheduleJob(String jName, String jGroup, String cron) throws SchedulerException { |
|||
TriggerKey triggerKey = TriggerKey.triggerKey(jName, jGroup); |
|||
// 表达式调度构建器
|
|||
CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(cron); |
|||
CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey); |
|||
// 按新的cronExpression表达式重新构建trigger
|
|||
trigger = trigger.getTriggerBuilder().withIdentity(triggerKey).withSchedule(scheduleBuilder).build(); |
|||
// 按新的trigger重新设置job执行,重启触发器
|
|||
scheduler.rescheduleJob(triggerKey, trigger); |
|||
} |
|||
|
|||
@Override |
|||
public void deletejob(String jName, String jGroup) throws SchedulerException { |
|||
scheduler.pauseTrigger(TriggerKey.triggerKey(jName, jGroup)); |
|||
scheduler.unscheduleJob(TriggerKey.triggerKey(jName, jGroup)); |
|||
scheduler.deleteJob(JobKey.jobKey(jName, jGroup)); |
|||
} |
|||
} |
|||
@ -0,0 +1,93 @@ |
|||
<?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="org.example.mapper.CronTriggerMapper"> |
|||
<resultMap id="BaseResultMap" type="org.example.pojo.CronTrigger"> |
|||
<id column="SCHED_NAME" jdbcType="VARCHAR" property="schedName" /> |
|||
<id column="TRIGGER_NAME" jdbcType="VARCHAR" property="triggerName" /> |
|||
<id column="TRIGGER_GROUP" jdbcType="VARCHAR" property="triggerGroup" /> |
|||
<result column="CRON_EXPRESSION" jdbcType="VARCHAR" property="cronExpression" /> |
|||
<result column="TIME_ZONE_ID" jdbcType="VARCHAR" property="timeZoneId" /> |
|||
</resultMap> |
|||
<sql id="Base_Column_List"> |
|||
SCHED_NAME, TRIGGER_NAME, TRIGGER_GROUP, CRON_EXPRESSION, TIME_ZONE_ID |
|||
</sql> |
|||
<select id="selectByPrimaryKey" parameterType="org.example.pojo.CronTriggerKey" resultMap="BaseResultMap"> |
|||
select |
|||
<include refid="Base_Column_List" /> |
|||
from qrtz_cron_triggers |
|||
where SCHED_NAME = #{schedName,jdbcType=VARCHAR} |
|||
and TRIGGER_NAME = #{triggerName,jdbcType=VARCHAR} |
|||
and TRIGGER_GROUP = #{triggerGroup,jdbcType=VARCHAR} |
|||
</select> |
|||
<delete id="deleteByPrimaryKey" parameterType="org.example.pojo.CronTriggerKey"> |
|||
delete from qrtz_cron_triggers |
|||
where SCHED_NAME = #{schedName,jdbcType=VARCHAR} |
|||
and TRIGGER_NAME = #{triggerName,jdbcType=VARCHAR} |
|||
and TRIGGER_GROUP = #{triggerGroup,jdbcType=VARCHAR} |
|||
</delete> |
|||
<insert id="insert" parameterType="org.example.pojo.CronTrigger"> |
|||
insert into qrtz_cron_triggers (SCHED_NAME, TRIGGER_NAME, TRIGGER_GROUP, |
|||
CRON_EXPRESSION, TIME_ZONE_ID) |
|||
values (#{schedName,jdbcType=VARCHAR}, #{triggerName,jdbcType=VARCHAR}, #{triggerGroup,jdbcType=VARCHAR}, |
|||
#{cronExpression,jdbcType=VARCHAR}, #{timeZoneId,jdbcType=VARCHAR}) |
|||
</insert> |
|||
<insert id="insertSelective" parameterType="org.example.pojo.CronTrigger"> |
|||
insert into qrtz_cron_triggers |
|||
<trim prefix="(" suffix=")" suffixOverrides=","> |
|||
<if test="schedName != null"> |
|||
SCHED_NAME, |
|||
</if> |
|||
<if test="triggerName != null"> |
|||
TRIGGER_NAME, |
|||
</if> |
|||
<if test="triggerGroup != null"> |
|||
TRIGGER_GROUP, |
|||
</if> |
|||
<if test="cronExpression != null"> |
|||
CRON_EXPRESSION, |
|||
</if> |
|||
<if test="timeZoneId != null"> |
|||
TIME_ZONE_ID, |
|||
</if> |
|||
</trim> |
|||
<trim prefix="values (" suffix=")" suffixOverrides=","> |
|||
<if test="schedName != null"> |
|||
#{schedName,jdbcType=VARCHAR}, |
|||
</if> |
|||
<if test="triggerName != null"> |
|||
#{triggerName,jdbcType=VARCHAR}, |
|||
</if> |
|||
<if test="triggerGroup != null"> |
|||
#{triggerGroup,jdbcType=VARCHAR}, |
|||
</if> |
|||
<if test="cronExpression != null"> |
|||
#{cronExpression,jdbcType=VARCHAR}, |
|||
</if> |
|||
<if test="timeZoneId != null"> |
|||
#{timeZoneId,jdbcType=VARCHAR}, |
|||
</if> |
|||
</trim> |
|||
</insert> |
|||
<update id="updateByPrimaryKeySelective" parameterType="org.example.pojo.CronTrigger"> |
|||
update qrtz_cron_triggers |
|||
<set> |
|||
<if test="cronExpression != null"> |
|||
CRON_EXPRESSION = #{cronExpression,jdbcType=VARCHAR}, |
|||
</if> |
|||
<if test="timeZoneId != null"> |
|||
TIME_ZONE_ID = #{timeZoneId,jdbcType=VARCHAR}, |
|||
</if> |
|||
</set> |
|||
where SCHED_NAME = #{schedName,jdbcType=VARCHAR} |
|||
and TRIGGER_NAME = #{triggerName,jdbcType=VARCHAR} |
|||
and TRIGGER_GROUP = #{triggerGroup,jdbcType=VARCHAR} |
|||
</update> |
|||
<update id="updateByPrimaryKey" parameterType="org.example.pojo.CronTrigger"> |
|||
update qrtz_cron_triggers |
|||
set CRON_EXPRESSION = #{cronExpression,jdbcType=VARCHAR}, |
|||
TIME_ZONE_ID = #{timeZoneId,jdbcType=VARCHAR} |
|||
where SCHED_NAME = #{schedName,jdbcType=VARCHAR} |
|||
and TRIGGER_NAME = #{triggerName,jdbcType=VARCHAR} |
|||
and TRIGGER_GROUP = #{triggerGroup,jdbcType=VARCHAR} |
|||
</update> |
|||
</mapper> |
|||
@ -0,0 +1,194 @@ |
|||
<?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="org.example.mapper.JobDetailMapper"> |
|||
<resultMap id="BaseResultMap" type="org.example.pojo.JobDetail"> |
|||
<id column="SCHED_NAME" jdbcType="VARCHAR" property="schedName"/> |
|||
<id column="JOB_NAME" jdbcType="VARCHAR" property="jobName"/> |
|||
<id column="JOB_GROUP" jdbcType="VARCHAR" property="jobGroup"/> |
|||
<result column="DESCRIPTION" jdbcType="VARCHAR" property="description"/> |
|||
<result column="JOB_CLASS_NAME" jdbcType="VARCHAR" property="jobClassName"/> |
|||
<result column="IS_DURABLE" jdbcType="VARCHAR" property="isDurable"/> |
|||
<result column="IS_NONCONCURRENT" jdbcType="VARCHAR" property="isNonconcurrent"/> |
|||
<result column="IS_UPDATE_DATA" jdbcType="VARCHAR" property="isUpdateData"/> |
|||
<result column="REQUESTS_RECOVERY" jdbcType="VARCHAR" property="requestsRecovery"/> |
|||
</resultMap> |
|||
<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="org.example.pojo.JobDetail"> |
|||
<result column="JOB_DATA" jdbcType="LONGVARBINARY" property="jobData"/> |
|||
</resultMap> |
|||
<sql id="Base_Column_List"> |
|||
SCHED_NAME |
|||
, JOB_NAME, JOB_GROUP, DESCRIPTION, JOB_CLASS_NAME, IS_DURABLE, IS_NONCONCURRENT, |
|||
IS_UPDATE_DATA, REQUESTS_RECOVERY |
|||
</sql> |
|||
<sql id="Blob_Column_List"> |
|||
JOB_DATA |
|||
</sql> |
|||
|
|||
<select id="getJobAndTriggerDetails" resultType="org.example.dto.JobAndTriggerDto"> |
|||
SELECT DISTINCT |
|||
qrtz_job_details.JOB_NAME, |
|||
qrtz_job_details.JOB_GROUP, |
|||
qrtz_job_details.JOB_CLASS_NAME, |
|||
qrtz_triggers.TRIGGER_NAME, |
|||
qrtz_triggers.TRIGGER_GROUP, |
|||
qrtz_cron_triggers.CRON_EXPRESSION, |
|||
qrtz_cron_triggers.TIME_ZONE_ID |
|||
FROM |
|||
qrtz_job_details |
|||
LEFT JOIN qrtz_triggers ON qrtz_triggers.TRIGGER_GROUP = qrtz_job_details.JOB_GROUP |
|||
LEFT JOIN qrtz_cron_triggers ON qrtz_job_details.JOB_NAME = qrtz_triggers.JOB_NAME |
|||
WHERE |
|||
qrtz_triggers.TRIGGER_NAME = qrtz_cron_triggers.TRIGGER_NAME |
|||
AND qrtz_triggers.TRIGGER_GROUP = qrtz_cron_triggers.TRIGGER_GROUP |
|||
</select> |
|||
|
|||
<select id="selectByPrimaryKey" parameterType="org.example.pojo.JobDetailKey" resultMap="ResultMapWithBLOBs"> |
|||
select |
|||
<include refid="Base_Column_List"/> |
|||
, |
|||
<include refid="Blob_Column_List"/> |
|||
from qrtz_job_details |
|||
where SCHED_NAME = #{schedName,jdbcType=VARCHAR} |
|||
and JOB_NAME = #{jobName,jdbcType=VARCHAR} |
|||
and JOB_GROUP = #{jobGroup,jdbcType=VARCHAR} |
|||
</select> |
|||
<delete id="deleteByPrimaryKey" parameterType="org.example.pojo.JobDetailKey"> |
|||
delete |
|||
from qrtz_job_details |
|||
where SCHED_NAME = #{schedName,jdbcType=VARCHAR} |
|||
and JOB_NAME = #{jobName,jdbcType=VARCHAR} |
|||
and JOB_GROUP = #{jobGroup,jdbcType=VARCHAR} |
|||
</delete> |
|||
<insert id="insert" parameterType="org.example.pojo.JobDetail"> |
|||
insert into qrtz_job_details (SCHED_NAME, JOB_NAME, JOB_GROUP, |
|||
DESCRIPTION, JOB_CLASS_NAME, IS_DURABLE, |
|||
IS_NONCONCURRENT, IS_UPDATE_DATA, REQUESTS_RECOVERY, |
|||
JOB_DATA) |
|||
values (#{schedName,jdbcType=VARCHAR}, #{jobName,jdbcType=VARCHAR}, #{jobGroup,jdbcType=VARCHAR}, |
|||
#{description,jdbcType=VARCHAR}, #{jobClassName,jdbcType=VARCHAR}, #{isDurable,jdbcType=VARCHAR}, |
|||
#{isNonconcurrent,jdbcType=VARCHAR}, #{isUpdateData,jdbcType=VARCHAR}, |
|||
#{requestsRecovery,jdbcType=VARCHAR}, |
|||
#{jobData,jdbcType=LONGVARBINARY}) |
|||
</insert> |
|||
<insert id="insertSelective" parameterType="org.example.pojo.JobDetail"> |
|||
insert into qrtz_job_details |
|||
<trim prefix="(" suffix=")" suffixOverrides=","> |
|||
<if test="schedName != null"> |
|||
SCHED_NAME, |
|||
</if> |
|||
<if test="jobName != null"> |
|||
JOB_NAME, |
|||
</if> |
|||
<if test="jobGroup != null"> |
|||
JOB_GROUP, |
|||
</if> |
|||
<if test="description != null"> |
|||
DESCRIPTION, |
|||
</if> |
|||
<if test="jobClassName != null"> |
|||
JOB_CLASS_NAME, |
|||
</if> |
|||
<if test="isDurable != null"> |
|||
IS_DURABLE, |
|||
</if> |
|||
<if test="isNonconcurrent != null"> |
|||
IS_NONCONCURRENT, |
|||
</if> |
|||
<if test="isUpdateData != null"> |
|||
IS_UPDATE_DATA, |
|||
</if> |
|||
<if test="requestsRecovery != null"> |
|||
REQUESTS_RECOVERY, |
|||
</if> |
|||
<if test="jobData != null"> |
|||
JOB_DATA, |
|||
</if> |
|||
</trim> |
|||
<trim prefix="values (" suffix=")" suffixOverrides=","> |
|||
<if test="schedName != null"> |
|||
#{schedName,jdbcType=VARCHAR}, |
|||
</if> |
|||
<if test="jobName != null"> |
|||
#{jobName,jdbcType=VARCHAR}, |
|||
</if> |
|||
<if test="jobGroup != null"> |
|||
#{jobGroup,jdbcType=VARCHAR}, |
|||
</if> |
|||
<if test="description != null"> |
|||
#{description,jdbcType=VARCHAR}, |
|||
</if> |
|||
<if test="jobClassName != null"> |
|||
#{jobClassName,jdbcType=VARCHAR}, |
|||
</if> |
|||
<if test="isDurable != null"> |
|||
#{isDurable,jdbcType=VARCHAR}, |
|||
</if> |
|||
<if test="isNonconcurrent != null"> |
|||
#{isNonconcurrent,jdbcType=VARCHAR}, |
|||
</if> |
|||
<if test="isUpdateData != null"> |
|||
#{isUpdateData,jdbcType=VARCHAR}, |
|||
</if> |
|||
<if test="requestsRecovery != null"> |
|||
#{requestsRecovery,jdbcType=VARCHAR}, |
|||
</if> |
|||
<if test="jobData != null"> |
|||
#{jobData,jdbcType=LONGVARBINARY}, |
|||
</if> |
|||
</trim> |
|||
</insert> |
|||
<update id="updateByPrimaryKeySelective" parameterType="org.example.pojo.JobDetail"> |
|||
update qrtz_job_details |
|||
<set> |
|||
<if test="description != null"> |
|||
DESCRIPTION = #{description,jdbcType=VARCHAR}, |
|||
</if> |
|||
<if test="jobClassName != null"> |
|||
JOB_CLASS_NAME = #{jobClassName,jdbcType=VARCHAR}, |
|||
</if> |
|||
<if test="isDurable != null"> |
|||
IS_DURABLE = #{isDurable,jdbcType=VARCHAR}, |
|||
</if> |
|||
<if test="isNonconcurrent != null"> |
|||
IS_NONCONCURRENT = #{isNonconcurrent,jdbcType=VARCHAR}, |
|||
</if> |
|||
<if test="isUpdateData != null"> |
|||
IS_UPDATE_DATA = #{isUpdateData,jdbcType=VARCHAR}, |
|||
</if> |
|||
<if test="requestsRecovery != null"> |
|||
REQUESTS_RECOVERY = #{requestsRecovery,jdbcType=VARCHAR}, |
|||
</if> |
|||
<if test="jobData != null"> |
|||
JOB_DATA = #{jobData,jdbcType=LONGVARBINARY}, |
|||
</if> |
|||
</set> |
|||
where SCHED_NAME = #{schedName,jdbcType=VARCHAR} |
|||
and JOB_NAME = #{jobName,jdbcType=VARCHAR} |
|||
and JOB_GROUP = #{jobGroup,jdbcType=VARCHAR} |
|||
</update> |
|||
<update id="updateByPrimaryKeyWithBLOBs" parameterType="org.example.pojo.JobDetail"> |
|||
update qrtz_job_details |
|||
set DESCRIPTION = #{description,jdbcType=VARCHAR}, |
|||
JOB_CLASS_NAME = #{jobClassName,jdbcType=VARCHAR}, |
|||
IS_DURABLE = #{isDurable,jdbcType=VARCHAR}, |
|||
IS_NONCONCURRENT = #{isNonconcurrent,jdbcType=VARCHAR}, |
|||
IS_UPDATE_DATA = #{isUpdateData,jdbcType=VARCHAR}, |
|||
REQUESTS_RECOVERY = #{requestsRecovery,jdbcType=VARCHAR}, |
|||
JOB_DATA = #{jobData,jdbcType=LONGVARBINARY} |
|||
where SCHED_NAME = #{schedName,jdbcType=VARCHAR} |
|||
and JOB_NAME = #{jobName,jdbcType=VARCHAR} |
|||
and JOB_GROUP = #{jobGroup,jdbcType=VARCHAR} |
|||
</update> |
|||
<update id="updateByPrimaryKey" parameterType="org.example.pojo.JobDetail"> |
|||
update qrtz_job_details |
|||
set DESCRIPTION = #{description,jdbcType=VARCHAR}, |
|||
JOB_CLASS_NAME = #{jobClassName,jdbcType=VARCHAR}, |
|||
IS_DURABLE = #{isDurable,jdbcType=VARCHAR}, |
|||
IS_NONCONCURRENT = #{isNonconcurrent,jdbcType=VARCHAR}, |
|||
IS_UPDATE_DATA = #{isUpdateData,jdbcType=VARCHAR}, |
|||
REQUESTS_RECOVERY = #{requestsRecovery,jdbcType=VARCHAR} |
|||
where SCHED_NAME = #{schedName,jdbcType=VARCHAR} |
|||
and JOB_NAME = #{jobName,jdbcType=VARCHAR} |
|||
and JOB_GROUP = #{jobGroup,jdbcType=VARCHAR} |
|||
</update> |
|||
</mapper> |
|||
@ -0,0 +1,249 @@ |
|||
<?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="org.example.mapper.TriggerMapper"> |
|||
<resultMap id="BaseResultMap" type="org.example.pojo.Trigger"> |
|||
<id column="SCHED_NAME" jdbcType="VARCHAR" property="schedName" /> |
|||
<id column="TRIGGER_NAME" jdbcType="VARCHAR" property="triggerName" /> |
|||
<id column="TRIGGER_GROUP" jdbcType="VARCHAR" property="triggerGroup" /> |
|||
<result column="JOB_NAME" jdbcType="VARCHAR" property="jobName" /> |
|||
<result column="JOB_GROUP" jdbcType="VARCHAR" property="jobGroup" /> |
|||
<result column="DESCRIPTION" jdbcType="VARCHAR" property="description" /> |
|||
<result column="NEXT_FIRE_TIME" jdbcType="BIGINT" property="nextFireTime" /> |
|||
<result column="PREV_FIRE_TIME" jdbcType="BIGINT" property="prevFireTime" /> |
|||
<result column="PRIORITY" jdbcType="INTEGER" property="priority" /> |
|||
<result column="TRIGGER_STATE" jdbcType="VARCHAR" property="triggerState" /> |
|||
<result column="TRIGGER_TYPE" jdbcType="VARCHAR" property="triggerType" /> |
|||
<result column="START_TIME" jdbcType="BIGINT" property="startTime" /> |
|||
<result column="END_TIME" jdbcType="BIGINT" property="endTime" /> |
|||
<result column="CALENDAR_NAME" jdbcType="VARCHAR" property="calendarName" /> |
|||
<result column="MISFIRE_INSTR" jdbcType="SMALLINT" property="misfireInstr" /> |
|||
</resultMap> |
|||
<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="org.example.pojo.Trigger"> |
|||
<result column="JOB_DATA" jdbcType="LONGVARBINARY" property="jobData" /> |
|||
</resultMap> |
|||
<sql id="Base_Column_List"> |
|||
SCHED_NAME, TRIGGER_NAME, TRIGGER_GROUP, JOB_NAME, JOB_GROUP, DESCRIPTION, NEXT_FIRE_TIME, |
|||
PREV_FIRE_TIME, PRIORITY, TRIGGER_STATE, TRIGGER_TYPE, START_TIME, END_TIME, CALENDAR_NAME, |
|||
MISFIRE_INSTR |
|||
</sql> |
|||
<sql id="Blob_Column_List"> |
|||
JOB_DATA |
|||
</sql> |
|||
<select id="selectByPrimaryKey" parameterType="org.example.pojo.TriggerKey" resultMap="ResultMapWithBLOBs"> |
|||
select |
|||
<include refid="Base_Column_List" /> |
|||
, |
|||
<include refid="Blob_Column_List" /> |
|||
from qrtz_triggers |
|||
where SCHED_NAME = #{schedName,jdbcType=VARCHAR} |
|||
and TRIGGER_NAME = #{triggerName,jdbcType=VARCHAR} |
|||
and TRIGGER_GROUP = #{triggerGroup,jdbcType=VARCHAR} |
|||
</select> |
|||
<delete id="deleteByPrimaryKey" parameterType="org.example.pojo.TriggerKey"> |
|||
delete from qrtz_triggers |
|||
where SCHED_NAME = #{schedName,jdbcType=VARCHAR} |
|||
and TRIGGER_NAME = #{triggerName,jdbcType=VARCHAR} |
|||
and TRIGGER_GROUP = #{triggerGroup,jdbcType=VARCHAR} |
|||
</delete> |
|||
<insert id="insert" parameterType="org.example.pojo.Trigger"> |
|||
insert into qrtz_triggers (SCHED_NAME, TRIGGER_NAME, TRIGGER_GROUP, |
|||
JOB_NAME, JOB_GROUP, DESCRIPTION, |
|||
NEXT_FIRE_TIME, PREV_FIRE_TIME, PRIORITY, |
|||
TRIGGER_STATE, TRIGGER_TYPE, START_TIME, |
|||
END_TIME, CALENDAR_NAME, MISFIRE_INSTR, |
|||
JOB_DATA) |
|||
values (#{schedName,jdbcType=VARCHAR}, #{triggerName,jdbcType=VARCHAR}, #{triggerGroup,jdbcType=VARCHAR}, |
|||
#{jobName,jdbcType=VARCHAR}, #{jobGroup,jdbcType=VARCHAR}, #{description,jdbcType=VARCHAR}, |
|||
#{nextFireTime,jdbcType=BIGINT}, #{prevFireTime,jdbcType=BIGINT}, #{priority,jdbcType=INTEGER}, |
|||
#{triggerState,jdbcType=VARCHAR}, #{triggerType,jdbcType=VARCHAR}, #{startTime,jdbcType=BIGINT}, |
|||
#{endTime,jdbcType=BIGINT}, #{calendarName,jdbcType=VARCHAR}, #{misfireInstr,jdbcType=SMALLINT}, |
|||
#{jobData,jdbcType=LONGVARBINARY}) |
|||
</insert> |
|||
<insert id="insertSelective" parameterType="org.example.pojo.Trigger"> |
|||
insert into qrtz_triggers |
|||
<trim prefix="(" suffix=")" suffixOverrides=","> |
|||
<if test="schedName != null"> |
|||
SCHED_NAME, |
|||
</if> |
|||
<if test="triggerName != null"> |
|||
TRIGGER_NAME, |
|||
</if> |
|||
<if test="triggerGroup != null"> |
|||
TRIGGER_GROUP, |
|||
</if> |
|||
<if test="jobName != null"> |
|||
JOB_NAME, |
|||
</if> |
|||
<if test="jobGroup != null"> |
|||
JOB_GROUP, |
|||
</if> |
|||
<if test="description != null"> |
|||
DESCRIPTION, |
|||
</if> |
|||
<if test="nextFireTime != null"> |
|||
NEXT_FIRE_TIME, |
|||
</if> |
|||
<if test="prevFireTime != null"> |
|||
PREV_FIRE_TIME, |
|||
</if> |
|||
<if test="priority != null"> |
|||
PRIORITY, |
|||
</if> |
|||
<if test="triggerState != null"> |
|||
TRIGGER_STATE, |
|||
</if> |
|||
<if test="triggerType != null"> |
|||
TRIGGER_TYPE, |
|||
</if> |
|||
<if test="startTime != null"> |
|||
START_TIME, |
|||
</if> |
|||
<if test="endTime != null"> |
|||
END_TIME, |
|||
</if> |
|||
<if test="calendarName != null"> |
|||
CALENDAR_NAME, |
|||
</if> |
|||
<if test="misfireInstr != null"> |
|||
MISFIRE_INSTR, |
|||
</if> |
|||
<if test="jobData != null"> |
|||
JOB_DATA, |
|||
</if> |
|||
</trim> |
|||
<trim prefix="values (" suffix=")" suffixOverrides=","> |
|||
<if test="schedName != null"> |
|||
#{schedName,jdbcType=VARCHAR}, |
|||
</if> |
|||
<if test="triggerName != null"> |
|||
#{triggerName,jdbcType=VARCHAR}, |
|||
</if> |
|||
<if test="triggerGroup != null"> |
|||
#{triggerGroup,jdbcType=VARCHAR}, |
|||
</if> |
|||
<if test="jobName != null"> |
|||
#{jobName,jdbcType=VARCHAR}, |
|||
</if> |
|||
<if test="jobGroup != null"> |
|||
#{jobGroup,jdbcType=VARCHAR}, |
|||
</if> |
|||
<if test="description != null"> |
|||
#{description,jdbcType=VARCHAR}, |
|||
</if> |
|||
<if test="nextFireTime != null"> |
|||
#{nextFireTime,jdbcType=BIGINT}, |
|||
</if> |
|||
<if test="prevFireTime != null"> |
|||
#{prevFireTime,jdbcType=BIGINT}, |
|||
</if> |
|||
<if test="priority != null"> |
|||
#{priority,jdbcType=INTEGER}, |
|||
</if> |
|||
<if test="triggerState != null"> |
|||
#{triggerState,jdbcType=VARCHAR}, |
|||
</if> |
|||
<if test="triggerType != null"> |
|||
#{triggerType,jdbcType=VARCHAR}, |
|||
</if> |
|||
<if test="startTime != null"> |
|||
#{startTime,jdbcType=BIGINT}, |
|||
</if> |
|||
<if test="endTime != null"> |
|||
#{endTime,jdbcType=BIGINT}, |
|||
</if> |
|||
<if test="calendarName != null"> |
|||
#{calendarName,jdbcType=VARCHAR}, |
|||
</if> |
|||
<if test="misfireInstr != null"> |
|||
#{misfireInstr,jdbcType=SMALLINT}, |
|||
</if> |
|||
<if test="jobData != null"> |
|||
#{jobData,jdbcType=LONGVARBINARY}, |
|||
</if> |
|||
</trim> |
|||
</insert> |
|||
<update id="updateByPrimaryKeySelective" parameterType="org.example.pojo.Trigger"> |
|||
update qrtz_triggers |
|||
<set> |
|||
<if test="jobName != null"> |
|||
JOB_NAME = #{jobName,jdbcType=VARCHAR}, |
|||
</if> |
|||
<if test="jobGroup != null"> |
|||
JOB_GROUP = #{jobGroup,jdbcType=VARCHAR}, |
|||
</if> |
|||
<if test="description != null"> |
|||
DESCRIPTION = #{description,jdbcType=VARCHAR}, |
|||
</if> |
|||
<if test="nextFireTime != null"> |
|||
NEXT_FIRE_TIME = #{nextFireTime,jdbcType=BIGINT}, |
|||
</if> |
|||
<if test="prevFireTime != null"> |
|||
PREV_FIRE_TIME = #{prevFireTime,jdbcType=BIGINT}, |
|||
</if> |
|||
<if test="priority != null"> |
|||
PRIORITY = #{priority,jdbcType=INTEGER}, |
|||
</if> |
|||
<if test="triggerState != null"> |
|||
TRIGGER_STATE = #{triggerState,jdbcType=VARCHAR}, |
|||
</if> |
|||
<if test="triggerType != null"> |
|||
TRIGGER_TYPE = #{triggerType,jdbcType=VARCHAR}, |
|||
</if> |
|||
<if test="startTime != null"> |
|||
START_TIME = #{startTime,jdbcType=BIGINT}, |
|||
</if> |
|||
<if test="endTime != null"> |
|||
END_TIME = #{endTime,jdbcType=BIGINT}, |
|||
</if> |
|||
<if test="calendarName != null"> |
|||
CALENDAR_NAME = #{calendarName,jdbcType=VARCHAR}, |
|||
</if> |
|||
<if test="misfireInstr != null"> |
|||
MISFIRE_INSTR = #{misfireInstr,jdbcType=SMALLINT}, |
|||
</if> |
|||
<if test="jobData != null"> |
|||
JOB_DATA = #{jobData,jdbcType=LONGVARBINARY}, |
|||
</if> |
|||
</set> |
|||
where SCHED_NAME = #{schedName,jdbcType=VARCHAR} |
|||
and TRIGGER_NAME = #{triggerName,jdbcType=VARCHAR} |
|||
and TRIGGER_GROUP = #{triggerGroup,jdbcType=VARCHAR} |
|||
</update> |
|||
<update id="updateByPrimaryKeyWithBLOBs" parameterType="org.example.pojo.Trigger"> |
|||
update qrtz_triggers |
|||
set JOB_NAME = #{jobName,jdbcType=VARCHAR}, |
|||
JOB_GROUP = #{jobGroup,jdbcType=VARCHAR}, |
|||
DESCRIPTION = #{description,jdbcType=VARCHAR}, |
|||
NEXT_FIRE_TIME = #{nextFireTime,jdbcType=BIGINT}, |
|||
PREV_FIRE_TIME = #{prevFireTime,jdbcType=BIGINT}, |
|||
PRIORITY = #{priority,jdbcType=INTEGER}, |
|||
TRIGGER_STATE = #{triggerState,jdbcType=VARCHAR}, |
|||
TRIGGER_TYPE = #{triggerType,jdbcType=VARCHAR}, |
|||
START_TIME = #{startTime,jdbcType=BIGINT}, |
|||
END_TIME = #{endTime,jdbcType=BIGINT}, |
|||
CALENDAR_NAME = #{calendarName,jdbcType=VARCHAR}, |
|||
MISFIRE_INSTR = #{misfireInstr,jdbcType=SMALLINT}, |
|||
JOB_DATA = #{jobData,jdbcType=LONGVARBINARY} |
|||
where SCHED_NAME = #{schedName,jdbcType=VARCHAR} |
|||
and TRIGGER_NAME = #{triggerName,jdbcType=VARCHAR} |
|||
and TRIGGER_GROUP = #{triggerGroup,jdbcType=VARCHAR} |
|||
</update> |
|||
<update id="updateByPrimaryKey" parameterType="org.example.pojo.Trigger"> |
|||
update qrtz_triggers |
|||
set JOB_NAME = #{jobName,jdbcType=VARCHAR}, |
|||
JOB_GROUP = #{jobGroup,jdbcType=VARCHAR}, |
|||
DESCRIPTION = #{description,jdbcType=VARCHAR}, |
|||
NEXT_FIRE_TIME = #{nextFireTime,jdbcType=BIGINT}, |
|||
PREV_FIRE_TIME = #{prevFireTime,jdbcType=BIGINT}, |
|||
PRIORITY = #{priority,jdbcType=INTEGER}, |
|||
TRIGGER_STATE = #{triggerState,jdbcType=VARCHAR}, |
|||
TRIGGER_TYPE = #{triggerType,jdbcType=VARCHAR}, |
|||
START_TIME = #{startTime,jdbcType=BIGINT}, |
|||
END_TIME = #{endTime,jdbcType=BIGINT}, |
|||
CALENDAR_NAME = #{calendarName,jdbcType=VARCHAR}, |
|||
MISFIRE_INSTR = #{misfireInstr,jdbcType=SMALLINT} |
|||
where SCHED_NAME = #{schedName,jdbcType=VARCHAR} |
|||
and TRIGGER_NAME = #{triggerName,jdbcType=VARCHAR} |
|||
and TRIGGER_GROUP = #{triggerGroup,jdbcType=VARCHAR} |
|||
</update> |
|||
</mapper> |
|||
@ -0,0 +1,53 @@ |
|||
#主要分为scheduler、threadPool、jobStore、dataSource等部分 |
|||
|
|||
|
|||
org.quartz.scheduler.instanceId=AUTO |
|||
org.quartz.scheduler.instanceName=DefaultQuartzScheduler |
|||
#如果您希望Quartz Scheduler通过RMI作为服务器导出本身,则将“rmi.export”标志设置为true |
|||
#在同一个配置文件中为'org.quartz.scheduler.rmi.export'和'org.quartz.scheduler.rmi.proxy'指定一个'true'值是没有意义的,如果你这样做'export'选项将被忽略 |
|||
org.quartz.scheduler.rmi.export=false |
|||
#如果要连接(使用)远程服务的调度程序,则将“org.quartz.scheduler.rmi.proxy”标志设置为true。您还必须指定RMI注册表进程的主机和端口 - 通常是“localhost”端口1099 |
|||
org.quartz.scheduler.rmi.proxy=false |
|||
org.quartz.scheduler.wrapJobExecutionInUserTransaction=false |
|||
|
|||
|
|||
#实例化ThreadPool时,使用的线程类为SimpleThreadPool |
|||
org.quartz.threadPool.class=org.quartz.simpl.SimpleThreadPool |
|||
#threadCount和threadPriority将以setter的形式注入ThreadPool实例 |
|||
#并发个数 如果你只有几个工作每天触发几次 那么1个线程就可以,如果你有成千上万的工作,每分钟都有很多工作 那么久需要50-100之间. |
|||
#只有1到100之间的数字是非常实用的 |
|||
org.quartz.threadPool.threadCount=5 |
|||
#优先级 默认值为5 |
|||
org.quartz.threadPool.threadPriority=5 |
|||
#可以是“true”或“false”,默认为false |
|||
org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread=true |
|||
|
|||
|
|||
#在被认为“misfired”(失火)之前,调度程序将“tolerate(容忍)”一个Triggers(触发器)将其下一个启动时间通过的毫秒数。默认值(如果您在配置中未输入此属性)为60000(60秒) |
|||
org.quartz.jobStore.misfireThreshold=5000 |
|||
# 默认存储在内存中,RAMJobStore快速轻便,但是当进程终止时,所有调度信息都会丢失 |
|||
#org.quartz.jobStore.class=org.quartz.simpl.RAMJobStore |
|||
|
|||
#持久化方式,默认存储在内存中,此处使用数据库方式 |
|||
org.quartz.jobStore.class=org.quartz.impl.jdbcjobstore.JobStoreTX |
|||
#您需要为JobStore选择一个DriverDelegate才能使用。DriverDelegate负责执行特定数据库可能需要的任何JDBC工作 |
|||
# StdJDBCDelegate是一个使用“vanilla”JDBC代码(和SQL语句)来执行其工作的委托,用于完全符合JDBC的驱动程序 |
|||
org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.StdJDBCDelegate |
|||
#可以将“org.quartz.jobStore.useProperties”配置参数设置为“true”(默认为false),以指示JDBCJobStore将JobDataMaps中的所有值都作为字符串, |
|||
#因此可以作为名称 - 值对存储而不是在BLOB列中以其序列化形式存储更多复杂的对象。从长远来看,这是更安全的,因为您避免了将非String类序列化为BLOB的类版本问题 |
|||
org.quartz.jobStore.useProperties=true |
|||
#表前缀 |
|||
org.quartz.jobStore.tablePrefix=QRTZ_ |
|||
#数据源别名,自定义 |
|||
org.quartz.jobStore.dataSource=qzDS |
|||
|
|||
|
|||
#使用阿里的druid作为数据库连接池 |
|||
org.quartz.dataSource.qzDS.connectionProvider.class=org.example.config.DruidPoolingconnectionProvider |
|||
org.quartz.dataSource.qzDS.URL=jdbc:mysql://127.0.0.1:3306/test_quartz?characterEncoding=utf8&useSSL=false&autoReconnect=true&serverTimezone=UTC |
|||
org.quartz.dataSource.qzDS.user=root |
|||
org.quartz.dataSource.qzDS.password=123456 |
|||
org.quartz.dataSource.qzDS.driver=com.mysql.jdbc.Driver |
|||
org.quartz.dataSource.qzDS.maxConnections=10 |
|||
#设置为“true”以打开群集功能。如果您有多个Quartz实例使用同一组数据库表,则此属性必须设置为“true”,否则您将遇到破坏 |
|||
#org.quartz.jobStore.isClustered=false |
|||
Loading…
Reference in new issue