Commit efbd8cad495f5e5769f3fd551d1cd0e326eae90f
1 parent
f38aada2
Job 代码的初始化
Showing
28 changed files
with
578 additions
and
462 deletions
ruoyi-quartz/src/main/java/com/ruoyi/quartz/config/ScheduleConfig.java
| ... | ... | @@ -14,6 +14,7 @@ import java.util.Properties; |
| 14 | 14 | */ |
| 15 | 15 | @Configuration |
| 16 | 16 | public class ScheduleConfig { |
| 17 | + | |
| 17 | 18 | @Bean |
| 18 | 19 | public SchedulerFactoryBean schedulerFactoryBean(DataSource dataSource) { |
| 19 | 20 | SchedulerFactoryBean factory = new SchedulerFactoryBean(); |
| ... | ... | @@ -23,14 +24,7 @@ public class ScheduleConfig { |
| 23 | 24 | Properties prop = new Properties(); |
| 24 | 25 | prop.put("org.quartz.scheduler.instanceName", "RuoyiScheduler"); |
| 25 | 26 | prop.put("org.quartz.scheduler.instanceId", "AUTO"); |
| 26 | - // 线程池配置 | |
| 27 | - prop.put("org.quartz.threadPool.class", "org.quartz.simpl.SimpleThreadPool"); | |
| 28 | - prop.put("org.quartz.threadPool.threadCount", "20"); | |
| 29 | - prop.put("org.quartz.threadPool.threadPriority", "5"); | |
| 30 | - // JobStore配置 | |
| 31 | - prop.put("org.quartz.jobStore.class", "org.quartz.impl.jdbcjobstore.JobStoreTX"); | |
| 32 | 27 | // 集群配置 |
| 33 | - prop.put("org.quartz.jobStore.isClustered", "true"); | |
| 34 | 28 | prop.put("org.quartz.jobStore.clusterCheckinInterval", "15000"); |
| 35 | 29 | prop.put("org.quartz.jobStore.maxMisfiresToHandleAtATime", "1"); |
| 36 | 30 | prop.put("org.quartz.jobStore.txIsolationLevelSerializable", "true"); |
| ... | ... | @@ -38,7 +32,6 @@ public class ScheduleConfig { |
| 38 | 32 | // sqlserver 启用 |
| 39 | 33 | // prop.put("org.quartz.jobStore.selectWithLockSQL", "SELECT * FROM {0}LOCKS UPDLOCK WHERE LOCK_NAME = ?"); |
| 40 | 34 | prop.put("org.quartz.jobStore.misfireThreshold", "12000"); |
| 41 | - prop.put("org.quartz.jobStore.tablePrefix", "QRTZ_"); | |
| 42 | 35 | factory.setQuartzProperties(prop); |
| 43 | 36 | |
| 44 | 37 | factory.setSchedulerName("RuoyiScheduler"); |
| ... | ... | @@ -48,8 +41,7 @@ public class ScheduleConfig { |
| 48 | 41 | // 可选,QuartzScheduler |
| 49 | 42 | // 启动时更新己存在的Job,这样就不用每次修改targetObject后删除qrtz_job_details表对应记录了 |
| 50 | 43 | factory.setOverwriteExistingJobs(true); |
| 51 | - // 设置自动启动,默认为true | |
| 52 | - factory.setAutoStartup(true); | |
| 44 | + | |
| 53 | 45 | |
| 54 | 46 | return factory; |
| 55 | 47 | } | ... | ... |
ruoyi-quartz/src/main/java/com/ruoyi/quartz/service/ISysJobLogService.java deleted
| 1 | -package com.ruoyi.quartz.service; | |
| 2 | - | |
| 3 | -import java.util.List; | |
| 4 | - | |
| 5 | -import com.ruoyi.quartz.domain.SysJobLog; | |
| 6 | - | |
| 7 | -/** | |
| 8 | - * 定时任务调度日志信息信息 服务层 | |
| 9 | - * | |
| 10 | - * @author ruoyi | |
| 11 | - */ | |
| 12 | -public interface ISysJobLogService { | |
| 13 | - /** | |
| 14 | - * 获取quartz调度器日志的计划任务 | |
| 15 | - * | |
| 16 | - * @param jobLog 调度日志信息 | |
| 17 | - * @return 调度任务日志集合 | |
| 18 | - */ | |
| 19 | - public List<SysJobLog> selectJobLogList(SysJobLog jobLog); | |
| 20 | - | |
| 21 | - /** | |
| 22 | - * 通过调度任务日志ID查询调度信息 | |
| 23 | - * | |
| 24 | - * @param jobLogId 调度任务日志ID | |
| 25 | - * @return 调度任务日志对象信息 | |
| 26 | - */ | |
| 27 | - public SysJobLog selectJobLogById(Long jobLogId); | |
| 28 | - | |
| 29 | - /** | |
| 30 | - * 新增任务日志 | |
| 31 | - * | |
| 32 | - * @param jobLog 调度日志信息 | |
| 33 | - */ | |
| 34 | - public void addJobLog(SysJobLog jobLog); | |
| 35 | - | |
| 36 | - /** | |
| 37 | - * 批量删除调度日志信息 | |
| 38 | - * | |
| 39 | - * @param logIds 需要删除的日志ID | |
| 40 | - * @return 结果 | |
| 41 | - */ | |
| 42 | - public int deleteJobLogByIds(Long[] logIds); | |
| 43 | - | |
| 44 | - /** | |
| 45 | - * 删除任务日志 | |
| 46 | - * | |
| 47 | - * @param jobId 调度日志ID | |
| 48 | - * @return 结果 | |
| 49 | - */ | |
| 50 | - public int deleteJobLogById(Long jobId); | |
| 51 | - | |
| 52 | - /** | |
| 53 | - * 清空任务日志 | |
| 54 | - */ | |
| 55 | - public void cleanJobLog(); | |
| 56 | -} |
ruoyi-quartz/src/main/java/com/ruoyi/quartz/service/ISysJobService.java deleted
| 1 | -package com.ruoyi.quartz.service; | |
| 2 | - | |
| 3 | -import java.util.List; | |
| 4 | - | |
| 5 | -import org.quartz.SchedulerException; | |
| 6 | -import com.ruoyi.common.exception.job.TaskException; | |
| 7 | -import com.ruoyi.quartz.domain.SysJob; | |
| 8 | - | |
| 9 | -/** | |
| 10 | - * 定时任务调度信息信息 服务层 | |
| 11 | - * | |
| 12 | - * @author ruoyi | |
| 13 | - */ | |
| 14 | -public interface ISysJobService { | |
| 15 | - /** | |
| 16 | - * 获取quartz调度器的计划任务 | |
| 17 | - * | |
| 18 | - * @param job 调度信息 | |
| 19 | - * @return 调度任务集合 | |
| 20 | - */ | |
| 21 | - public List<SysJob> selectJobList(SysJob job); | |
| 22 | - | |
| 23 | - /** | |
| 24 | - * 通过调度任务ID查询调度信息 | |
| 25 | - * | |
| 26 | - * @param jobId 调度任务ID | |
| 27 | - * @return 调度任务对象信息 | |
| 28 | - */ | |
| 29 | - public SysJob selectJobById(Long jobId); | |
| 30 | - | |
| 31 | - /** | |
| 32 | - * 暂停任务 | |
| 33 | - * | |
| 34 | - * @param job 调度信息 | |
| 35 | - * @return 结果 | |
| 36 | - */ | |
| 37 | - public int pauseJob(SysJob job) throws SchedulerException; | |
| 38 | - | |
| 39 | - /** | |
| 40 | - * 恢复任务 | |
| 41 | - * | |
| 42 | - * @param job 调度信息 | |
| 43 | - * @return 结果 | |
| 44 | - */ | |
| 45 | - public int resumeJob(SysJob job) throws SchedulerException; | |
| 46 | - | |
| 47 | - /** | |
| 48 | - * 删除任务后,所对应的trigger也将被删除 | |
| 49 | - * | |
| 50 | - * @param job 调度信息 | |
| 51 | - * @return 结果 | |
| 52 | - */ | |
| 53 | - public int deleteJob(SysJob job) throws SchedulerException; | |
| 54 | - | |
| 55 | - /** | |
| 56 | - * 批量删除调度信息 | |
| 57 | - * | |
| 58 | - * @param jobIds 需要删除的任务ID | |
| 59 | - * @return 结果 | |
| 60 | - */ | |
| 61 | - public void deleteJobByIds(Long[] jobIds) throws SchedulerException; | |
| 62 | - | |
| 63 | - /** | |
| 64 | - * 任务调度状态修改 | |
| 65 | - * | |
| 66 | - * @param job 调度信息 | |
| 67 | - * @return 结果 | |
| 68 | - */ | |
| 69 | - public int changeStatus(SysJob job) throws SchedulerException; | |
| 70 | - | |
| 71 | - /** | |
| 72 | - * 立即运行任务 | |
| 73 | - * | |
| 74 | - * @param job 调度信息 | |
| 75 | - * @return 结果 | |
| 76 | - */ | |
| 77 | - public void run(SysJob job) throws SchedulerException; | |
| 78 | - | |
| 79 | - /** | |
| 80 | - * 新增任务 | |
| 81 | - * | |
| 82 | - * @param job 调度信息 | |
| 83 | - * @return 结果 | |
| 84 | - */ | |
| 85 | - public int insertJob(SysJob job) throws SchedulerException, TaskException; | |
| 86 | - | |
| 87 | - /** | |
| 88 | - * 更新任务 | |
| 89 | - * | |
| 90 | - * @param job 调度信息 | |
| 91 | - * @return 结果 | |
| 92 | - */ | |
| 93 | - public int updateJob(SysJob job) throws SchedulerException, TaskException; | |
| 94 | - | |
| 95 | - /** | |
| 96 | - * 校验cron表达式是否有效 | |
| 97 | - * | |
| 98 | - * @param cronExpression 表达式 | |
| 99 | - * @return 结果 | |
| 100 | - */ | |
| 101 | - public boolean checkCronExpressionIsValid(String cronExpression); | |
| 102 | -} |
ruoyi-quartz/src/main/java/com/ruoyi/quartz/service/impl/SysJobServiceImpl.java
| ... | ... | @@ -32,18 +32,6 @@ public class SysJobServiceImpl implements ISysJobService { |
| 32 | 32 | private SysJobMapper jobMapper; |
| 33 | 33 | |
| 34 | 34 | /** |
| 35 | - * 项目启动时,初始化定时器 主要是防止手动修改数据库导致未同步到定时任务处理(注:不能手动修改数据库ID和任务组名,否则会导致脏数据) | |
| 36 | - */ | |
| 37 | - @PostConstruct | |
| 38 | - public void init() throws SchedulerException, TaskException { | |
| 39 | - scheduler.clear(); | |
| 40 | - List<SysJob> jobList = jobMapper.selectJobAll(); | |
| 41 | - for (SysJob job : jobList) { | |
| 42 | - ScheduleUtils.createScheduleJob(scheduler, job); | |
| 43 | - } | |
| 44 | - } | |
| 45 | - | |
| 46 | - /** | |
| 47 | 35 | * 获取quartz调度器的计划任务列表 |
| 48 | 36 | * |
| 49 | 37 | * @param job 调度信息 | ... | ... |
ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/RyTask.java deleted
| 1 | -package com.ruoyi.quartz.task; | |
| 2 | - | |
| 3 | -import org.springframework.stereotype.Component; | |
| 4 | -import com.ruoyi.common.utils.StringUtils; | |
| 5 | - | |
| 6 | -/** | |
| 7 | - * 定时任务调度测试 | |
| 8 | - * | |
| 9 | - * @author ruoyi | |
| 10 | - */ | |
| 11 | -@Component("ryTask") | |
| 12 | -public class RyTask { | |
| 13 | - public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i) { | |
| 14 | - System.out.println(StringUtils.format("执行多参方法: 字符串类型{},布尔类型{},长整型{},浮点型{},整形{}", s, b, l, d, i)); | |
| 15 | - } | |
| 16 | - | |
| 17 | - public void ryParams(String params) { | |
| 18 | - System.out.println("执行有参方法:" + params); | |
| 19 | - } | |
| 20 | - | |
| 21 | - public void ryNoParams() { | |
| 22 | - System.out.println("执行无参方法"); | |
| 23 | - } | |
| 24 | -} |
ruoyi-quartz/src/main/java/com/ruoyi/quartz/util/JobInvokeUtil.java deleted
| 1 | -package com.ruoyi.quartz.util; | |
| 2 | - | |
| 3 | -import java.lang.reflect.InvocationTargetException; | |
| 4 | -import java.lang.reflect.Method; | |
| 5 | -import java.util.LinkedList; | |
| 6 | -import java.util.List; | |
| 7 | - | |
| 8 | -import com.ruoyi.common.utils.StringUtils; | |
| 9 | -import com.ruoyi.common.utils.spring.SpringUtils; | |
| 10 | -import com.ruoyi.quartz.domain.SysJob; | |
| 11 | - | |
| 12 | -/** | |
| 13 | - * 任务执行工具 | |
| 14 | - * | |
| 15 | - * @author ruoyi | |
| 16 | - */ | |
| 17 | -public class JobInvokeUtil { | |
| 18 | - /** | |
| 19 | - * 执行方法 | |
| 20 | - * | |
| 21 | - * @param sysJob 系统任务 | |
| 22 | - */ | |
| 23 | - public static void invokeMethod(SysJob sysJob) throws Exception { | |
| 24 | - String invokeTarget = sysJob.getInvokeTarget(); | |
| 25 | - String beanName = getBeanName(invokeTarget); | |
| 26 | - String methodName = getMethodName(invokeTarget); | |
| 27 | - List<Object[]> methodParams = getMethodParams(invokeTarget); | |
| 28 | - | |
| 29 | - if (!isValidClassName(beanName)) { | |
| 30 | - Object bean = SpringUtils.getBean(beanName); | |
| 31 | - invokeMethod(bean, methodName, methodParams); | |
| 32 | - } else { | |
| 33 | - Object bean = Class.forName(beanName).newInstance(); | |
| 34 | - invokeMethod(bean, methodName, methodParams); | |
| 35 | - } | |
| 36 | - } | |
| 37 | - | |
| 38 | - /** | |
| 39 | - * 调用任务方法 | |
| 40 | - * | |
| 41 | - * @param bean 目标对象 | |
| 42 | - * @param methodName 方法名称 | |
| 43 | - * @param methodParams 方法参数 | |
| 44 | - */ | |
| 45 | - private static void invokeMethod(Object bean, String methodName, List<Object[]> methodParams) | |
| 46 | - throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, | |
| 47 | - InvocationTargetException { | |
| 48 | - if (StringUtils.isNotNull(methodParams) && methodParams.size() > 0) { | |
| 49 | - Method method = bean.getClass().getDeclaredMethod(methodName, getMethodParamsType(methodParams)); | |
| 50 | - method.invoke(bean, getMethodParamsValue(methodParams)); | |
| 51 | - } else { | |
| 52 | - Method method = bean.getClass().getDeclaredMethod(methodName); | |
| 53 | - method.invoke(bean); | |
| 54 | - } | |
| 55 | - } | |
| 56 | - | |
| 57 | - /** | |
| 58 | - * 校验是否为为class包名 | |
| 59 | - * | |
| 60 | - * @param str 名称 | |
| 61 | - * @return true是 false否 | |
| 62 | - */ | |
| 63 | - public static boolean isValidClassName(String invokeTarget) { | |
| 64 | - return StringUtils.countMatches(invokeTarget, ".") > 1; | |
| 65 | - } | |
| 66 | - | |
| 67 | - /** | |
| 68 | - * 获取bean名称 | |
| 69 | - * | |
| 70 | - * @param invokeTarget 目标字符串 | |
| 71 | - * @return bean名称 | |
| 72 | - */ | |
| 73 | - public static String getBeanName(String invokeTarget) { | |
| 74 | - String beanName = StringUtils.substringBefore(invokeTarget, "("); | |
| 75 | - return StringUtils.substringBeforeLast(beanName, "."); | |
| 76 | - } | |
| 77 | - | |
| 78 | - /** | |
| 79 | - * 获取bean方法 | |
| 80 | - * | |
| 81 | - * @param invokeTarget 目标字符串 | |
| 82 | - * @return method方法 | |
| 83 | - */ | |
| 84 | - public static String getMethodName(String invokeTarget) { | |
| 85 | - String methodName = StringUtils.substringBefore(invokeTarget, "("); | |
| 86 | - return StringUtils.substringAfterLast(methodName, "."); | |
| 87 | - } | |
| 88 | - | |
| 89 | - /** | |
| 90 | - * 获取method方法参数相关列表 | |
| 91 | - * | |
| 92 | - * @param invokeTarget 目标字符串 | |
| 93 | - * @return method方法相关参数列表 | |
| 94 | - */ | |
| 95 | - public static List<Object[]> getMethodParams(String invokeTarget) { | |
| 96 | - String methodStr = StringUtils.substringBetween(invokeTarget, "(", ")"); | |
| 97 | - if (StringUtils.isEmpty(methodStr)) { | |
| 98 | - return null; | |
| 99 | - } | |
| 100 | - String[] methodParams = methodStr.split(","); | |
| 101 | - List<Object[]> classs = new LinkedList<>(); | |
| 102 | - for (int i = 0; i < methodParams.length; i++) { | |
| 103 | - String str = StringUtils.trimToEmpty(methodParams[i]); | |
| 104 | - // String字符串类型,包含' | |
| 105 | - if (StringUtils.contains(str, "'")) { | |
| 106 | - classs.add(new Object[]{StringUtils.replace(str, "'", ""), String.class}); | |
| 107 | - } | |
| 108 | - // boolean布尔类型,等于true或者false | |
| 109 | - else if (StringUtils.equals(str, "true") || StringUtils.equalsIgnoreCase(str, "false")) { | |
| 110 | - classs.add(new Object[]{Boolean.valueOf(str), Boolean.class}); | |
| 111 | - } | |
| 112 | - // long长整形,包含L | |
| 113 | - else if (StringUtils.containsIgnoreCase(str, "L")) { | |
| 114 | - classs.add(new Object[]{Long.valueOf(StringUtils.replaceIgnoreCase(str, "L", "")), Long.class}); | |
| 115 | - } | |
| 116 | - // double浮点类型,包含D | |
| 117 | - else if (StringUtils.containsIgnoreCase(str, "D")) { | |
| 118 | - classs.add(new Object[]{Double.valueOf(StringUtils.replaceIgnoreCase(str, "D", "")), Double.class}); | |
| 119 | - } | |
| 120 | - // 其他类型归类为整形 | |
| 121 | - else { | |
| 122 | - classs.add(new Object[]{Integer.valueOf(str), Integer.class}); | |
| 123 | - } | |
| 124 | - } | |
| 125 | - return classs; | |
| 126 | - } | |
| 127 | - | |
| 128 | - /** | |
| 129 | - * 获取参数类型 | |
| 130 | - * | |
| 131 | - * @param methodParams 参数相关列表 | |
| 132 | - * @return 参数类型列表 | |
| 133 | - */ | |
| 134 | - public static Class<?>[] getMethodParamsType(List<Object[]> methodParams) { | |
| 135 | - Class<?>[] classs = new Class<?>[methodParams.size()]; | |
| 136 | - int index = 0; | |
| 137 | - for (Object[] os : methodParams) { | |
| 138 | - classs[index] = (Class<?>) os[1]; | |
| 139 | - index++; | |
| 140 | - } | |
| 141 | - return classs; | |
| 142 | - } | |
| 143 | - | |
| 144 | - /** | |
| 145 | - * 获取参数值 | |
| 146 | - * | |
| 147 | - * @param methodParams 参数相关列表 | |
| 148 | - * @return 参数值列表 | |
| 149 | - */ | |
| 150 | - public static Object[] getMethodParamsValue(List<Object[]> methodParams) { | |
| 151 | - Object[] classs = new Object[methodParams.size()]; | |
| 152 | - int index = 0; | |
| 153 | - for (Object[] os : methodParams) { | |
| 154 | - classs[index] = (Object) os[0]; | |
| 155 | - index++; | |
| 156 | - } | |
| 157 | - return classs; | |
| 158 | - } | |
| 159 | -} |
ruoyi-quartz/src/main/java/com/ruoyi/quartz/util/QuartzDisallowConcurrentExecution.java deleted
| 1 | -package com.ruoyi.quartz.util; | |
| 2 | - | |
| 3 | -import org.quartz.DisallowConcurrentExecution; | |
| 4 | -import org.quartz.JobExecutionContext; | |
| 5 | -import com.ruoyi.quartz.domain.SysJob; | |
| 6 | - | |
| 7 | -/** | |
| 8 | - * 定时任务处理(禁止并发执行) | |
| 9 | - * | |
| 10 | - * @author ruoyi | |
| 11 | - */ | |
| 12 | -@DisallowConcurrentExecution | |
| 13 | -public class QuartzDisallowConcurrentExecution extends AbstractQuartzJob { | |
| 14 | - @Override | |
| 15 | - protected void doExecute(JobExecutionContext context, SysJob sysJob) throws Exception { | |
| 16 | - JobInvokeUtil.invokeMethod(sysJob); | |
| 17 | - } | |
| 18 | -} |
ruoyi-quartz/src/main/java/com/ruoyi/quartz/util/QuartzJobExecution.java deleted
| 1 | -package com.ruoyi.quartz.util; | |
| 2 | - | |
| 3 | -import org.quartz.JobExecutionContext; | |
| 4 | -import com.ruoyi.quartz.domain.SysJob; | |
| 5 | - | |
| 6 | -/** | |
| 7 | - * 定时任务处理(允许并发执行) | |
| 8 | - * | |
| 9 | - * @author ruoyi | |
| 10 | - */ | |
| 11 | -public class QuartzJobExecution extends AbstractQuartzJob { | |
| 12 | - @Override | |
| 13 | - protected void doExecute(JobExecutionContext context, SysJob sysJob) throws Exception { | |
| 14 | - JobInvokeUtil.invokeMethod(sysJob); | |
| 15 | - } | |
| 16 | -} |
ruoyi-quartz/src/main/java/com/ruoyi/quartz/util/ScheduleUtils.java
| ... | ... | @@ -21,65 +21,6 @@ import com.ruoyi.quartz.domain.SysJob; |
| 21 | 21 | * @author ruoyi |
| 22 | 22 | */ |
| 23 | 23 | public class ScheduleUtils { |
| 24 | - /** | |
| 25 | - * 得到quartz任务类 | |
| 26 | - * | |
| 27 | - * @param sysJob 执行计划 | |
| 28 | - * @return 具体执行任务类 | |
| 29 | - */ | |
| 30 | - private static Class<? extends Job> getQuartzJobClass(SysJob sysJob) { | |
| 31 | - boolean isConcurrent = "0".equals(sysJob.getConcurrent()); | |
| 32 | - return isConcurrent ? QuartzJobExecution.class : QuartzDisallowConcurrentExecution.class; | |
| 33 | - } | |
| 34 | - | |
| 35 | - /** | |
| 36 | - * 构建任务触发对象 | |
| 37 | - */ | |
| 38 | - public static TriggerKey getTriggerKey(Long jobId, String jobGroup) { | |
| 39 | - return TriggerKey.triggerKey(ScheduleConstants.TASK_CLASS_NAME + jobId, jobGroup); | |
| 40 | - } | |
| 41 | - | |
| 42 | - /** | |
| 43 | - * 构建任务键对象 | |
| 44 | - */ | |
| 45 | - public static JobKey getJobKey(Long jobId, String jobGroup) { | |
| 46 | - return JobKey.jobKey(ScheduleConstants.TASK_CLASS_NAME + jobId, jobGroup); | |
| 47 | - } | |
| 48 | - | |
| 49 | - /** | |
| 50 | - * 创建定时任务 | |
| 51 | - */ | |
| 52 | - public static void createScheduleJob(Scheduler scheduler, SysJob job) throws SchedulerException, TaskException { | |
| 53 | - Class<? extends Job> jobClass = getQuartzJobClass(job); | |
| 54 | - // 构建job信息 | |
| 55 | - Long jobId = job.getJobId(); | |
| 56 | - String jobGroup = job.getJobGroup(); | |
| 57 | - JobDetail jobDetail = JobBuilder.newJob(jobClass).withIdentity(getJobKey(jobId, jobGroup)).build(); | |
| 58 | - | |
| 59 | - // 表达式调度构建器 | |
| 60 | - CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(job.getCronExpression()); | |
| 61 | - cronScheduleBuilder = handleCronScheduleMisfirePolicy(job, cronScheduleBuilder); | |
| 62 | - | |
| 63 | - // 按新的cronExpression表达式构建一个新的trigger | |
| 64 | - CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity(getTriggerKey(jobId, jobGroup)) | |
| 65 | - .withSchedule(cronScheduleBuilder).build(); | |
| 66 | - | |
| 67 | - // 放入参数,运行时的方法可以获取 | |
| 68 | - jobDetail.getJobDataMap().put(ScheduleConstants.TASK_PROPERTIES, job); | |
| 69 | - | |
| 70 | - // 判断是否存在 | |
| 71 | - if (scheduler.checkExists(getJobKey(jobId, jobGroup))) { | |
| 72 | - // 防止创建时存在数据问题 先移除,然后在执行创建操作 | |
| 73 | - scheduler.deleteJob(getJobKey(jobId, jobGroup)); | |
| 74 | - } | |
| 75 | - | |
| 76 | - scheduler.scheduleJob(jobDetail, trigger); | |
| 77 | - | |
| 78 | - // 暂停任务 | |
| 79 | - if (job.getStatus().equals(ScheduleConstants.Status.PAUSE.getValue())) { | |
| 80 | - scheduler.pauseJob(ScheduleUtils.getJobKey(jobId, jobGroup)); | |
| 81 | - } | |
| 82 | - } | |
| 83 | 24 | |
| 84 | 25 | /** |
| 85 | 26 | * 设置定时任务策略 | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/infra/controller/job/InfJobController.java
0 → 100644
| 1 | +package cn.iocoder.dashboard.modules.infra.controller.job; | |
| 2 | + | |
| 3 | +import cn.iocoder.dashboard.common.pojo.CommonResult; | |
| 4 | +import cn.iocoder.dashboard.common.pojo.PageResult; | |
| 5 | +import cn.iocoder.dashboard.framework.excel.core.util.ExcelUtils; | |
| 6 | +import cn.iocoder.dashboard.framework.logger.operatelog.core.annotations.OperateLog; | |
| 7 | +import cn.iocoder.dashboard.modules.infra.controller.job.vo.job.*; | |
| 8 | +import cn.iocoder.dashboard.modules.infra.convert.job.InfJobConvert; | |
| 9 | +import cn.iocoder.dashboard.modules.infra.dal.dataobject.job.InfJobDO; | |
| 10 | +import cn.iocoder.dashboard.modules.infra.service.job.InfJobService; | |
| 11 | +import io.swagger.annotations.Api; | |
| 12 | +import io.swagger.annotations.ApiImplicitParam; | |
| 13 | +import io.swagger.annotations.ApiOperation; | |
| 14 | +import org.springframework.security.access.prepost.PreAuthorize; | |
| 15 | +import org.springframework.validation.annotation.Validated; | |
| 16 | +import org.springframework.web.bind.annotation.*; | |
| 17 | + | |
| 18 | +import javax.annotation.Resource; | |
| 19 | +import javax.servlet.http.HttpServletResponse; | |
| 20 | +import javax.validation.Valid; | |
| 21 | +import java.io.IOException; | |
| 22 | +import java.util.Collection; | |
| 23 | +import java.util.List; | |
| 24 | + | |
| 25 | +import static cn.iocoder.dashboard.common.pojo.CommonResult.success; | |
| 26 | +import static cn.iocoder.dashboard.framework.logger.operatelog.core.enums.OperateTypeEnum.EXPORT; | |
| 27 | + | |
| 28 | +@Api(tags = "定时任务") | |
| 29 | +@RestController | |
| 30 | +@RequestMapping("/infra/job") | |
| 31 | +@Validated | |
| 32 | +public class InfJobController { | |
| 33 | + | |
| 34 | + @Resource | |
| 35 | + private InfJobService jobService; | |
| 36 | + | |
| 37 | + @PostMapping("/create") | |
| 38 | + @ApiOperation("创建定时任务") | |
| 39 | + @PreAuthorize("@ss.hasPermission('infra:job:create')") | |
| 40 | + public CommonResult<Long> createJob(@Valid @RequestBody InfJobCreateReqVO createReqVO) { | |
| 41 | + return success(jobService.createJob(createReqVO)); | |
| 42 | + } | |
| 43 | + | |
| 44 | + @PutMapping("/update") | |
| 45 | + @ApiOperation("更新定时任务") | |
| 46 | + @PreAuthorize("@ss.hasPermission('infra:job:update')") | |
| 47 | + public CommonResult<Boolean> updateJob(@Valid @RequestBody InfJobUpdateReqVO updateReqVO) { | |
| 48 | + jobService.updateJob(updateReqVO); | |
| 49 | + return success(true); | |
| 50 | + } | |
| 51 | + | |
| 52 | + @DeleteMapping("/delete") | |
| 53 | + @ApiOperation("删除定时任务") | |
| 54 | + @ApiImplicitParam(name = "id", value = "编号", required = true) | |
| 55 | + @PreAuthorize("@ss.hasPermission('infra:job:delete')") | |
| 56 | + public CommonResult<Boolean> deleteJob(@RequestParam("id") Long id) { | |
| 57 | + jobService.deleteJob(id); | |
| 58 | + return success(true); | |
| 59 | + } | |
| 60 | + | |
| 61 | + @GetMapping("/get") | |
| 62 | + @ApiOperation("获得定时任务") | |
| 63 | + @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class) | |
| 64 | + @PreAuthorize("@ss.hasPermission('infra:job:query')") | |
| 65 | + public CommonResult<InfJobRespVO> getJob(@RequestParam("id") Long id) { | |
| 66 | + InfJobDO job = jobService.getJob(id); | |
| 67 | + return success(InfJobConvert.INSTANCE.convert(job)); | |
| 68 | + } | |
| 69 | + | |
| 70 | + @GetMapping("/list") | |
| 71 | + @ApiOperation("获得定时任务列表") | |
| 72 | + @ApiImplicitParam(name = "ids", value = "编号列表", required = true, dataTypeClass = List.class) | |
| 73 | + @PreAuthorize("@ss.hasPermission('infra:job:query')") | |
| 74 | + public CommonResult<List<InfJobRespVO>> getJobList(@RequestParam("ids") Collection<Long> ids) { | |
| 75 | + List<InfJobDO> list = jobService.getJobList(ids); | |
| 76 | + return success(InfJobConvert.INSTANCE.convertList(list)); | |
| 77 | + } | |
| 78 | + | |
| 79 | + @GetMapping("/page") | |
| 80 | + @ApiOperation("获得定时任务分页") | |
| 81 | + @PreAuthorize("@ss.hasPermission('infra:job:query')") | |
| 82 | + public CommonResult<PageResult<InfJobRespVO>> getJobPage(@Valid InfJobPageReqVO pageVO) { | |
| 83 | + PageResult<InfJobDO> pageResult = jobService.getJobPage(pageVO); | |
| 84 | + return success(InfJobConvert.INSTANCE.convertPage(pageResult)); | |
| 85 | + } | |
| 86 | + | |
| 87 | + @GetMapping("/export-excel") | |
| 88 | + @ApiOperation("导出定时任务 Excel") | |
| 89 | + @PreAuthorize("@ss.hasPermission('infra:job:export')") | |
| 90 | + @OperateLog(type = EXPORT) | |
| 91 | + public void exportJobExcel(@Valid InfJobExportReqVO exportReqVO, | |
| 92 | + HttpServletResponse response) throws IOException { | |
| 93 | + List<InfJobDO> list = jobService.getJobList(exportReqVO); | |
| 94 | + // 导出 Excel | |
| 95 | + List<InfJobExcelVO> datas = InfJobConvert.INSTANCE.convertList02(list); | |
| 96 | + ExcelUtils.write(response, "定时任务.xls", "数据", InfJobExcelVO.class, datas); | |
| 97 | + } | |
| 98 | + | |
| 99 | +} | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/infra/controller/job/vo/job/InfJobBaseVO.java
0 → 100644
| 1 | +package cn.iocoder.dashboard.modules.infra.controller.job.vo.job; | |
| 2 | + | |
| 3 | +import io.swagger.annotations.ApiModelProperty; | |
| 4 | +import lombok.Data; | |
| 5 | +import org.springframework.format.annotation.DateTimeFormat; | |
| 6 | + | |
| 7 | +import javax.validation.constraints.NotNull; | |
| 8 | +import java.util.Date; | |
| 9 | + | |
| 10 | +import static cn.iocoder.dashboard.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | |
| 11 | + | |
| 12 | +/** | |
| 13 | +* 定时任务 Base VO,提供给添加、修改、详细的子 VO 使用 | |
| 14 | +* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 | |
| 15 | +*/ | |
| 16 | +@Data | |
| 17 | +public class InfJobBaseVO { | |
| 18 | + | |
| 19 | + @ApiModelProperty(value = "任务名称", required = true, example = "测试任务") | |
| 20 | + @NotNull(message = "任务名称不能为空") | |
| 21 | + private String name; | |
| 22 | + | |
| 23 | + @ApiModelProperty(value = "任务状态", required = true, example = "1", notes = "参见 InfJobStatusEnum 枚举") | |
| 24 | + @NotNull(message = "任务状态不能为空") | |
| 25 | + private Integer status; | |
| 26 | + | |
| 27 | + @ApiModelProperty(value = "处理器的名字", required = true, example = "sysUserSessionTimeoutJob") | |
| 28 | + @NotNull(message = "处理器的名字不能为空") | |
| 29 | + private String handlerName; | |
| 30 | + | |
| 31 | + @ApiModelProperty(value = "处理器的参数", example = "yudao") | |
| 32 | + private String handlerParam; | |
| 33 | + | |
| 34 | + @ApiModelProperty(value = "CRON 表达式", required = true, example = "0/10 * * * * ? *") | |
| 35 | + @NotNull(message = "CRON 表达式不能为空") | |
| 36 | + private String cronExpression; | |
| 37 | + | |
| 38 | + @ApiModelProperty(value = "最后一次执行的开始时间") | |
| 39 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 40 | + private Date executeBeginTime; | |
| 41 | + | |
| 42 | + @ApiModelProperty(value = "最后一次执行的结束时间") | |
| 43 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 44 | + private Date executeEndTime; | |
| 45 | + | |
| 46 | + @ApiModelProperty(value = "上一次触发时间") | |
| 47 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 48 | + private Date firePrevTime; | |
| 49 | + | |
| 50 | + @ApiModelProperty(value = "下一次触发时间") | |
| 51 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 52 | + private Date fireNextTime; | |
| 53 | + | |
| 54 | + @ApiModelProperty(value = "监控超时时间", example = "1000") | |
| 55 | + private Integer monitorTimeout; | |
| 56 | + | |
| 57 | +} | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/infra/controller/job/vo/job/InfJobCreateReqVO.java
0 → 100644
| 1 | +package cn.iocoder.dashboard.modules.infra.controller.job.vo.job; | |
| 2 | + | |
| 3 | +import io.swagger.annotations.ApiModel; | |
| 4 | +import lombok.Data; | |
| 5 | +import lombok.EqualsAndHashCode; | |
| 6 | +import lombok.ToString; | |
| 7 | + | |
| 8 | +@ApiModel("定时任务创建 Request VO") | |
| 9 | +@Data | |
| 10 | +@EqualsAndHashCode(callSuper = true) | |
| 11 | +@ToString(callSuper = true) | |
| 12 | +public class InfJobCreateReqVO extends InfJobBaseVO { | |
| 13 | + | |
| 14 | +} | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/infra/controller/job/vo/job/InfJobExcelVO.java
0 → 100644
| 1 | +package cn.iocoder.dashboard.modules.infra.controller.job.vo.job; | |
| 2 | + | |
| 3 | +import cn.iocoder.dashboard.framework.excel.core.annotations.DictFormat; | |
| 4 | +import cn.iocoder.dashboard.framework.excel.core.convert.DictConvert; | |
| 5 | +import com.alibaba.excel.annotation.ExcelProperty; | |
| 6 | +import lombok.Data; | |
| 7 | + | |
| 8 | +import java.util.Date; | |
| 9 | + | |
| 10 | +import static cn.iocoder.dashboard.modules.system.enums.dict.SysDictTypeEnum.INF_JOB_STATUS; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * 定时任务 Excel VO | |
| 14 | + * | |
| 15 | + * @author 芋道源码 | |
| 16 | + */ | |
| 17 | +@Data | |
| 18 | +public class InfJobExcelVO { | |
| 19 | + | |
| 20 | + @ExcelProperty("任务编号") | |
| 21 | + private Long id; | |
| 22 | + | |
| 23 | + @ExcelProperty("任务名称") | |
| 24 | + private String name; | |
| 25 | + | |
| 26 | + @ExcelProperty(value = "任务状态", converter = DictConvert.class) | |
| 27 | + @DictFormat(INF_JOB_STATUS) | |
| 28 | + private Integer status; | |
| 29 | + | |
| 30 | + @ExcelProperty("处理器的名字") | |
| 31 | + private String handlerName; | |
| 32 | + | |
| 33 | + @ExcelProperty("处理器的参数") | |
| 34 | + private String handlerParam; | |
| 35 | + | |
| 36 | + @ExcelProperty("CRON 表达式") | |
| 37 | + private String cronExpression; | |
| 38 | + | |
| 39 | + @ExcelProperty("最后一次执行的开始时间") | |
| 40 | + private Date executeBeginTime; | |
| 41 | + | |
| 42 | + @ExcelProperty("最后一次执行的结束时间") | |
| 43 | + private Date executeEndTime; | |
| 44 | + | |
| 45 | + @ExcelProperty("上一次触发时间") | |
| 46 | + private Date firePrevTime; | |
| 47 | + | |
| 48 | + @ExcelProperty("下一次触发时间") | |
| 49 | + private Date fireNextTime; | |
| 50 | + | |
| 51 | + @ExcelProperty("监控超时时间") | |
| 52 | + private Integer monitorTimeout; | |
| 53 | + | |
| 54 | + @ExcelProperty("创建时间") | |
| 55 | + private Date createTime; | |
| 56 | + | |
| 57 | +} | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/infra/controller/job/vo/job/InfJobExportReqVO.java
0 → 100644
| 1 | +package cn.iocoder.dashboard.modules.infra.controller.job.vo.job; | |
| 2 | + | |
| 3 | +import io.swagger.annotations.ApiModel; | |
| 4 | +import io.swagger.annotations.ApiModelProperty; | |
| 5 | +import lombok.Data; | |
| 6 | + | |
| 7 | +@ApiModel(value = "定时任务 Excel 导出 Request VO", description = "参数和 InfJobPageReqVO 是一致的") | |
| 8 | +@Data | |
| 9 | +public class InfJobExportReqVO { | |
| 10 | + | |
| 11 | + @ApiModelProperty(value = "任务名称", example = "测试任务", notes = "模糊匹配") | |
| 12 | + private String name; | |
| 13 | + | |
| 14 | + @ApiModelProperty(value = "任务状态", example = "1", notes = "参见 InfJobStatusEnum 枚举") | |
| 15 | + private Integer status; | |
| 16 | + | |
| 17 | + @ApiModelProperty(value = "处理器的名字", example = "sysUserSessionTimeoutJob", notes = "模糊匹配") | |
| 18 | + private String handlerName; | |
| 19 | + | |
| 20 | +} | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/infra/controller/job/vo/job/InfJobPageReqVO.java
0 → 100644
| 1 | +package cn.iocoder.dashboard.modules.infra.controller.job.vo.job; | |
| 2 | + | |
| 3 | +import cn.iocoder.dashboard.common.pojo.PageParam; | |
| 4 | +import io.swagger.annotations.ApiModel; | |
| 5 | +import io.swagger.annotations.ApiModelProperty; | |
| 6 | +import lombok.Data; | |
| 7 | +import lombok.EqualsAndHashCode; | |
| 8 | +import lombok.ToString; | |
| 9 | + | |
| 10 | +@ApiModel("定时任务分页 Request VO") | |
| 11 | +@Data | |
| 12 | +@EqualsAndHashCode(callSuper = true) | |
| 13 | +@ToString(callSuper = true) | |
| 14 | +public class InfJobPageReqVO extends PageParam { | |
| 15 | + | |
| 16 | + @ApiModelProperty(value = "任务名称", example = "测试任务", notes = "模糊匹配") | |
| 17 | + private String name; | |
| 18 | + | |
| 19 | + @ApiModelProperty(value = "任务状态", example = "1", notes = "参见 InfJobStatusEnum 枚举") | |
| 20 | + private Integer status; | |
| 21 | + | |
| 22 | + @ApiModelProperty(value = "处理器的名字", example = "sysUserSessionTimeoutJob", notes = "模糊匹配") | |
| 23 | + private String handlerName; | |
| 24 | + | |
| 25 | +} | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/infra/controller/job/vo/job/InfJobRespVO.java
0 → 100644
| 1 | +package cn.iocoder.dashboard.modules.infra.controller.job.vo.job; | |
| 2 | + | |
| 3 | +import io.swagger.annotations.ApiModel; | |
| 4 | +import io.swagger.annotations.ApiModelProperty; | |
| 5 | +import lombok.Data; | |
| 6 | +import lombok.EqualsAndHashCode; | |
| 7 | +import lombok.ToString; | |
| 8 | + | |
| 9 | +import java.util.Date; | |
| 10 | + | |
| 11 | +@ApiModel("定时任务 Response VO") | |
| 12 | +@Data | |
| 13 | +@EqualsAndHashCode(callSuper = true) | |
| 14 | +@ToString(callSuper = true) | |
| 15 | +public class InfJobRespVO extends InfJobBaseVO { | |
| 16 | + | |
| 17 | + @ApiModelProperty(value = "任务编号", required = true, example = "1024") | |
| 18 | + private Long id; | |
| 19 | + | |
| 20 | + @ApiModelProperty(value = "创建时间", required = true) | |
| 21 | + private Date createTime; | |
| 22 | + | |
| 23 | +} | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/infra/controller/job/vo/job/InfJobUpdateReqVO.java
0 → 100644
| 1 | +package cn.iocoder.dashboard.modules.infra.controller.job.vo.job; | |
| 2 | + | |
| 3 | +import io.swagger.annotations.ApiModel; | |
| 4 | +import io.swagger.annotations.ApiModelProperty; | |
| 5 | +import lombok.Data; | |
| 6 | +import lombok.EqualsAndHashCode; | |
| 7 | +import lombok.ToString; | |
| 8 | + | |
| 9 | +import javax.validation.constraints.NotNull; | |
| 10 | + | |
| 11 | +@ApiModel("定时任务更新 Request VO") | |
| 12 | +@Data | |
| 13 | +@EqualsAndHashCode(callSuper = true) | |
| 14 | +@ToString(callSuper = true) | |
| 15 | +public class InfJobUpdateReqVO extends InfJobBaseVO { | |
| 16 | + | |
| 17 | + @ApiModelProperty(value = "任务编号", required = true, example = "1024") | |
| 18 | + @NotNull(message = "任务编号不能为空") | |
| 19 | + private Long id; | |
| 20 | + | |
| 21 | +} | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/infra/convert/job/InfJobConvert.java
0 → 100644
| 1 | +package cn.iocoder.dashboard.modules.infra.convert.job; | |
| 2 | + | |
| 3 | +import cn.iocoder.dashboard.common.pojo.PageResult; | |
| 4 | +import cn.iocoder.dashboard.modules.infra.controller.job.vo.job.InfJobCreateReqVO; | |
| 5 | +import cn.iocoder.dashboard.modules.infra.controller.job.vo.job.InfJobExcelVO; | |
| 6 | +import cn.iocoder.dashboard.modules.infra.controller.job.vo.job.InfJobRespVO; | |
| 7 | +import cn.iocoder.dashboard.modules.infra.controller.job.vo.job.InfJobUpdateReqVO; | |
| 8 | +import cn.iocoder.dashboard.modules.infra.dal.dataobject.job.InfJobDO; | |
| 9 | +import org.mapstruct.Mapper; | |
| 10 | +import org.mapstruct.factory.Mappers; | |
| 11 | + | |
| 12 | +import java.util.List; | |
| 13 | + | |
| 14 | +/** | |
| 15 | + * 定时任务 Convert | |
| 16 | + * | |
| 17 | + * @author 芋道源码 | |
| 18 | + */ | |
| 19 | +@Mapper | |
| 20 | +public interface InfJobConvert { | |
| 21 | + | |
| 22 | + InfJobConvert INSTANCE = Mappers.getMapper(InfJobConvert.class); | |
| 23 | + | |
| 24 | + InfJobDO convert(InfJobCreateReqVO bean); | |
| 25 | + | |
| 26 | + InfJobDO convert(InfJobUpdateReqVO bean); | |
| 27 | + | |
| 28 | + InfJobRespVO convert(InfJobDO bean); | |
| 29 | + | |
| 30 | + List<InfJobRespVO> convertList(List<InfJobDO> list); | |
| 31 | + | |
| 32 | + PageResult<InfJobRespVO> convertPage(PageResult<InfJobDO> page); | |
| 33 | + | |
| 34 | + List<InfJobExcelVO> convertList02(List<InfJobDO> list); | |
| 35 | + | |
| 36 | +} | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/infra/dal/dataobject/job/InfJobDO.java
| ... | ... | @@ -2,6 +2,8 @@ package cn.iocoder.dashboard.modules.infra.dal.dataobject.job; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.dashboard.framework.mybatis.core.dataobject.BaseDO; |
| 4 | 4 | import cn.iocoder.dashboard.modules.infra.enums.job.InfJobStatusEnum; |
| 5 | +import com.baomidou.mybatisplus.annotation.FieldStrategy; | |
| 6 | +import com.baomidou.mybatisplus.annotation.TableField; | |
| 5 | 7 | import com.baomidou.mybatisplus.annotation.TableId; |
| 6 | 8 | import com.baomidou.mybatisplus.annotation.TableName; |
| 7 | 9 | import lombok.Data; |
| ... | ... | @@ -43,6 +45,7 @@ public class InfJobDO extends BaseDO { |
| 43 | 45 | /** |
| 44 | 46 | * 处理器的参数 |
| 45 | 47 | */ |
| 48 | + @TableField(updateStrategy = FieldStrategy.IGNORED) | |
| 46 | 49 | private String handlerParam; |
| 47 | 50 | |
| 48 | 51 | // ========== 时间相关字段 ========== |
| ... | ... | @@ -76,12 +79,11 @@ public class InfJobDO extends BaseDO { |
| 76 | 79 | |
| 77 | 80 | // ========== 监控相关字段 ========== |
| 78 | 81 | /** |
| 79 | - * 监控开关 | |
| 80 | - */ | |
| 81 | - private Boolean monitorSwitch; | |
| 82 | - /** | |
| 83 | 82 | * 监控超时时间,单位:毫秒 |
| 83 | + * | |
| 84 | + * 注意,这里的超时的目的,不是进行任务的取消,而是告警任务的执行时间过长 | |
| 84 | 85 | */ |
| 86 | + @TableField(updateStrategy = FieldStrategy.IGNORED) | |
| 85 | 87 | private Integer monitorTimeout; |
| 86 | 88 | |
| 87 | 89 | // TODO misfirePolicy | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/infra/dal/mysql/job/InfJobMapper.java
0 → 100644
| 1 | +package cn.iocoder.dashboard.modules.infra.dal.mysql.job; | |
| 2 | + | |
| 3 | +import cn.iocoder.dashboard.common.pojo.PageResult; | |
| 4 | +import cn.iocoder.dashboard.framework.mybatis.core.mapper.BaseMapperX; | |
| 5 | +import cn.iocoder.dashboard.framework.mybatis.core.query.QueryWrapperX; | |
| 6 | +import cn.iocoder.dashboard.modules.infra.controller.job.vo.job.InfJobExportReqVO; | |
| 7 | +import cn.iocoder.dashboard.modules.infra.controller.job.vo.job.InfJobPageReqVO; | |
| 8 | +import cn.iocoder.dashboard.modules.infra.dal.dataobject.job.InfJobDO; | |
| 9 | +import org.apache.ibatis.annotations.Mapper; | |
| 10 | + | |
| 11 | +import java.util.List; | |
| 12 | + | |
| 13 | +/** | |
| 14 | + * 定时任务 Mapper | |
| 15 | + * | |
| 16 | + * @author 芋道源码 | |
| 17 | + */ | |
| 18 | +@Mapper | |
| 19 | +public interface InfJobMapper extends BaseMapperX<InfJobDO> { | |
| 20 | + | |
| 21 | + default PageResult<InfJobDO> selectPage(InfJobPageReqVO reqVO) { | |
| 22 | + return selectPage(reqVO, new QueryWrapperX<InfJobDO>() | |
| 23 | + .likeIfPresent("name", reqVO.getName()) | |
| 24 | + .eqIfPresent("status", reqVO.getStatus()) | |
| 25 | + .likeIfPresent("handler_name", reqVO.getHandlerName()) | |
| 26 | + ); | |
| 27 | + } | |
| 28 | + | |
| 29 | + default List<InfJobDO> selectList(InfJobExportReqVO reqVO) { | |
| 30 | + return selectList(new QueryWrapperX<InfJobDO>() | |
| 31 | + .likeIfPresent("name", reqVO.getName()) | |
| 32 | + .eqIfPresent("status", reqVO.getStatus()) | |
| 33 | + .likeIfPresent("handler_name", reqVO.getHandlerName()) | |
| 34 | + ); | |
| 35 | + } | |
| 36 | + | |
| 37 | +} | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/infra/dal/mysql/package-info.java deleted
| 1 | -package cn.iocoder.dashboard.modules.infra.dal.mysql; |
src/main/java/cn/iocoder/dashboard/modules/infra/enums/InfErrorCodeConstants.java
| ... | ... | @@ -15,4 +15,7 @@ public interface InfErrorCodeConstants { |
| 15 | 15 | ErrorCode CONFIG_CAN_NOT_DELETE_SYSTEM_TYPE = new ErrorCode(1001000003, "不能删除类型为系统内置的参数配置"); |
| 16 | 16 | ErrorCode CONFIG_GET_VALUE_ERROR_IF_SENSITIVE = new ErrorCode(1001000004, "不允许获取敏感配置到前端"); |
| 17 | 17 | |
| 18 | + // ========== 定时任务 1001001000 ========== | |
| 19 | + ErrorCode JOB_NOT_EXISTS = new ErrorCode(1001001000, "定时任务不存在"); | |
| 20 | + | |
| 18 | 21 | } | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/infra/service/job/InfJobService.java
0 → 100644
| 1 | +package cn.iocoder.dashboard.modules.infra.service.job; | |
| 2 | + | |
| 3 | +import cn.iocoder.dashboard.common.pojo.PageResult; | |
| 4 | +import cn.iocoder.dashboard.modules.infra.controller.job.vo.job.InfJobCreateReqVO; | |
| 5 | +import cn.iocoder.dashboard.modules.infra.controller.job.vo.job.InfJobExportReqVO; | |
| 6 | +import cn.iocoder.dashboard.modules.infra.controller.job.vo.job.InfJobPageReqVO; | |
| 7 | +import cn.iocoder.dashboard.modules.infra.controller.job.vo.job.InfJobUpdateReqVO; | |
| 8 | +import cn.iocoder.dashboard.modules.infra.dal.dataobject.job.InfJobDO; | |
| 9 | + | |
| 10 | +import javax.validation.Valid; | |
| 11 | +import java.util.Collection; | |
| 12 | +import java.util.List; | |
| 13 | + | |
| 14 | +/** | |
| 15 | + * 定时任务 Service 接口 | |
| 16 | + * | |
| 17 | + * @author 芋道源码 | |
| 18 | + */ | |
| 19 | +public interface InfJobService { | |
| 20 | + | |
| 21 | + /** | |
| 22 | + * 创建定时任务 | |
| 23 | + * | |
| 24 | + * @param createReqVO 创建信息 | |
| 25 | + * @return 编号 | |
| 26 | + */ | |
| 27 | + Long createJob(@Valid InfJobCreateReqVO createReqVO); | |
| 28 | + | |
| 29 | + /** | |
| 30 | + * 更新定时任务 | |
| 31 | + * | |
| 32 | + * @param updateReqVO 更新信息 | |
| 33 | + */ | |
| 34 | + void updateJob(@Valid InfJobUpdateReqVO updateReqVO); | |
| 35 | + | |
| 36 | + /** | |
| 37 | + * 删除定时任务 | |
| 38 | + * | |
| 39 | + * @param id 编号 | |
| 40 | + */ | |
| 41 | + void deleteJob(Long id); | |
| 42 | + | |
| 43 | + /** | |
| 44 | + * 获得定时任务 | |
| 45 | + * | |
| 46 | + * @param id 编号 | |
| 47 | + * @return 定时任务 | |
| 48 | + */ | |
| 49 | + InfJobDO getJob(Long id); | |
| 50 | + | |
| 51 | + /** | |
| 52 | + * 获得定时任务列表 | |
| 53 | + * | |
| 54 | + * @param ids 编号 | |
| 55 | + * @return 定时任务列表 | |
| 56 | + */ | |
| 57 | + List<InfJobDO> getJobList(Collection<Long> ids); | |
| 58 | + | |
| 59 | + /** | |
| 60 | + * 获得定时任务分页 | |
| 61 | + * | |
| 62 | + * @param pageReqVO 分页查询 | |
| 63 | + * @return 定时任务分页 | |
| 64 | + */ | |
| 65 | + PageResult<InfJobDO> getJobPage(InfJobPageReqVO pageReqVO); | |
| 66 | + | |
| 67 | + /** | |
| 68 | + * 获得定时任务列表, 用于 Excel 导出 | |
| 69 | + * | |
| 70 | + * @param exportReqVO 查询条件 | |
| 71 | + * @return 定时任务分页 | |
| 72 | + */ | |
| 73 | + List<InfJobDO> getJobList(InfJobExportReqVO exportReqVO); | |
| 74 | + | |
| 75 | +} | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/infra/service/job/impl/InfJobServiceImpl.java
0 → 100644
| 1 | +package cn.iocoder.dashboard.modules.infra.service.job.impl; | |
| 2 | + | |
| 3 | +import cn.iocoder.dashboard.common.exception.util.ServiceExceptionUtil; | |
| 4 | +import cn.iocoder.dashboard.common.pojo.PageResult; | |
| 5 | +import cn.iocoder.dashboard.modules.infra.controller.job.vo.job.InfJobCreateReqVO; | |
| 6 | +import cn.iocoder.dashboard.modules.infra.controller.job.vo.job.InfJobExportReqVO; | |
| 7 | +import cn.iocoder.dashboard.modules.infra.controller.job.vo.job.InfJobPageReqVO; | |
| 8 | +import cn.iocoder.dashboard.modules.infra.controller.job.vo.job.InfJobUpdateReqVO; | |
| 9 | +import cn.iocoder.dashboard.modules.infra.convert.job.InfJobConvert; | |
| 10 | +import cn.iocoder.dashboard.modules.infra.dal.dataobject.job.InfJobDO; | |
| 11 | +import cn.iocoder.dashboard.modules.infra.dal.mysql.job.InfJobMapper; | |
| 12 | +import cn.iocoder.dashboard.modules.infra.service.job.InfJobService; | |
| 13 | +import org.springframework.stereotype.Service; | |
| 14 | +import org.springframework.validation.annotation.Validated; | |
| 15 | + | |
| 16 | +import javax.annotation.Resource; | |
| 17 | +import java.util.Collection; | |
| 18 | +import java.util.List; | |
| 19 | + | |
| 20 | +import static cn.iocoder.dashboard.modules.infra.enums.InfErrorCodeConstants.JOB_NOT_EXISTS; | |
| 21 | + | |
| 22 | +/** | |
| 23 | + * 定时任务 Service 实现类 | |
| 24 | + * | |
| 25 | + * @author 芋道源码 | |
| 26 | + */ | |
| 27 | +@Service | |
| 28 | +@Validated | |
| 29 | +public class InfJobServiceImpl implements InfJobService { | |
| 30 | + | |
| 31 | + @Resource | |
| 32 | + private InfJobMapper jobMapper; | |
| 33 | + | |
| 34 | + @Override | |
| 35 | + public Long createJob(InfJobCreateReqVO createReqVO) { | |
| 36 | + // 插入 | |
| 37 | + InfJobDO job = InfJobConvert.INSTANCE.convert(createReqVO); | |
| 38 | + jobMapper.insert(job); | |
| 39 | + // 返回 | |
| 40 | + return job.getId(); | |
| 41 | + } | |
| 42 | + | |
| 43 | + @Override | |
| 44 | + public void updateJob(InfJobUpdateReqVO updateReqVO) { | |
| 45 | + // 校验存在 | |
| 46 | + this.validateJobExists(updateReqVO.getId()); | |
| 47 | + // 更新 | |
| 48 | + InfJobDO updateObj = InfJobConvert.INSTANCE.convert(updateReqVO); | |
| 49 | + jobMapper.updateById(updateObj); | |
| 50 | + } | |
| 51 | + | |
| 52 | + @Override | |
| 53 | + public void deleteJob(Long id) { | |
| 54 | + // 校验存在 | |
| 55 | + this.validateJobExists(id); | |
| 56 | + // 更新 | |
| 57 | + jobMapper.deleteById(id); | |
| 58 | + } | |
| 59 | + | |
| 60 | + private void validateJobExists(Long id) { | |
| 61 | + if (jobMapper.selectById(id) == null) { | |
| 62 | + throw ServiceExceptionUtil.exception(JOB_NOT_EXISTS); | |
| 63 | + } | |
| 64 | + } | |
| 65 | + | |
| 66 | + @Override | |
| 67 | + public InfJobDO getJob(Long id) { | |
| 68 | + return jobMapper.selectById(id); | |
| 69 | + } | |
| 70 | + | |
| 71 | + @Override | |
| 72 | + public List<InfJobDO> getJobList(Collection<Long> ids) { | |
| 73 | + return jobMapper.selectBatchIds(ids); | |
| 74 | + } | |
| 75 | + | |
| 76 | + @Override | |
| 77 | + public PageResult<InfJobDO> getJobPage(InfJobPageReqVO pageReqVO) { | |
| 78 | + return jobMapper.selectPage(pageReqVO); | |
| 79 | + } | |
| 80 | + | |
| 81 | + @Override | |
| 82 | + public List<InfJobDO> getJobList(InfJobExportReqVO exportReqVO) { | |
| 83 | + return jobMapper.selectList(exportReqVO); | |
| 84 | + } | |
| 85 | + | |
| 86 | +} | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/infra/service/package-info.java deleted
| 1 | -package cn.iocoder.dashboard.modules.infra.service; |
src/main/java/cn/iocoder/dashboard/modules/system/enums/dict/SysDictTypeEnum.java
src/main/resources/codegen/java/controller/vo/baseVO.vm
| ... | ... | @@ -4,6 +4,16 @@ import lombok.*; |
| 4 | 4 | import java.util.*; |
| 5 | 5 | import io.swagger.annotations.*; |
| 6 | 6 | import javax.validation.constraints.*; |
| 7 | +## 处理 Date 字段的引入 | |
| 8 | +#foreach ($column in $columns) | |
| 9 | +#if (${column.createOperation} && ${column.updateOperation} && ${column.listOperationResult})##通用操作 | |
| 10 | + && ${column.javaType} == "Date")## 时间类型 | |
| 11 | +import org.springframework.format.annotation.DateTimeFormat; | |
| 12 | + | |
| 13 | +import static ${DateUtilsClassName}.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | |
| 14 | +#break | |
| 15 | +#end | |
| 16 | +#end | |
| 7 | 17 | |
| 8 | 18 | /** |
| 9 | 19 | * ${table.classComment} Base VO,提供给添加、修改、详细的子 VO 使用 | ... | ... |
src/test/java/cn/iocoder/dashboard/framework/quartz/core/scheduler/SchedulerManagerTest.java
| ... | ... | @@ -30,6 +30,12 @@ class SchedulerManagerTest { |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | @Test |
| 33 | + public void testDeleteJob() throws SchedulerException { | |
| 34 | + String jobHandlerName = StrUtil.lowerFirst(SysUserSessionTimeoutJob.class.getSimpleName()); | |
| 35 | + schedulerManager.deleteJob(jobHandlerName); | |
| 36 | + } | |
| 37 | + | |
| 38 | + @Test | |
| 33 | 39 | public void testPauseJob() throws SchedulerException { |
| 34 | 40 | String jobHandlerName = StrUtil.lowerFirst(SysUserSessionTimeoutJob.class.getSimpleName()); |
| 35 | 41 | schedulerManager.pauseJob(jobHandlerName); | ... | ... |