diff --git a/core/core-backend/src/main/java/io/dataease/commons/utils/CronUtils.java b/core/core-backend/src/main/java/io/dataease/commons/utils/CronUtils.java index f23cff758b..f396f5df1d 100644 --- a/core/core-backend/src/main/java/io/dataease/commons/utils/CronUtils.java +++ b/core/core-backend/src/main/java/io/dataease/commons/utils/CronUtils.java @@ -1,6 +1,6 @@ package io.dataease.commons.utils; -import io.dataease.task.dao.auto.entity.CoreSysTask; +import io.dataease.utils.LogUtil; import org.apache.commons.lang3.ObjectUtils; import org.quartz.CronExpression; import org.quartz.CronScheduleBuilder; @@ -12,19 +12,9 @@ import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; -/** - * @author song.tianyang - * @Date 2020/12/17 4:06 下午 - * @Description CRON解析类 - */ public class CronUtils { - /** - * 解析表达式,获取CronTrigger - * - * @param cron - * @return - */ + public static CronTrigger getCronTrigger(String cron) { if (!CronExpression.isValidExpression(cron)) { throw new RuntimeException("cron :" + cron + "表达式解析错误"); @@ -32,28 +22,6 @@ public class CronUtils { return TriggerBuilder.newTrigger().withIdentity("Calculate Date").withSchedule(CronScheduleBuilder.cronSchedule(cron)).build(); } - /** - * 获取以指定时间为开始时间的下一次执行时间 - * - * @param cron - * @param start - * @return - */ - public static Date getNextTriggerTime(String cron, Date start) { - if (start == null) { - return getNextTriggerTime(cron); - } else { - CronTrigger trigger = getCronTrigger(cron); - return trigger.getFireTimeAfter(start); - } - } - - /** - * 获取以当前日期为准的下一次执行时间 - * - * @param cron - * @return - */ public static Date getNextTriggerTime(String cron) { Date date = null; try { @@ -61,38 +29,39 @@ public class CronUtils { Date startDate = trigger.getStartTime(); date = trigger.getFireTimeAfter(startDate); } catch (Exception e) { - + LogUtil.error(e.getMessage(), e); } return date; } - public static String cron(CoreSysTask taskEntity) { - if (taskEntity.getRateType() == -1) { - return taskEntity.getRateVal(); + public static String cron(Integer rateType, String rateVal) { + if (rateType == 0) { + return rateVal; } SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date date = null; try { - date = sdf.parse(taskEntity.getRateVal()); + date = sdf.parse(rateVal); } catch (ParseException e) { e.printStackTrace(); } Calendar instance = Calendar.getInstance(); + assert date != null; instance.setTime(date); - if (taskEntity.getRateType() == 0) { + if (rateType == 1) { return instance.get(Calendar.SECOND) + " " + instance.get(Calendar.MINUTE) + " " + instance.get(Calendar.HOUR_OF_DAY) + " * * ?"; } - if (taskEntity.getRateType() == 1) { + if (rateType == 2) { return instance.get(Calendar.SECOND) + " " + instance.get(Calendar.MINUTE) + " " + instance.get(Calendar.HOUR_OF_DAY) + " ? * " + getDayOfWeek(instance); } - if (taskEntity.getRateType() == 2) { + if (rateType == 3) { return instance.get(Calendar.SECOND) + " " + instance.get(Calendar.MINUTE) + " " + instance.get(Calendar.HOUR_OF_DAY) + " " + @@ -102,13 +71,6 @@ public class CronUtils { return null; } - public static String cron() { - Calendar instance = Calendar.getInstance(); - instance.add(Calendar.SECOND, 5); - return instance.get(Calendar.SECOND) + " " + - instance.get(Calendar.MINUTE) + " " + - instance.get(Calendar.HOUR_OF_DAY) + " * * ?"; - } private static String getDayOfWeek(Calendar instance) { int index = instance.get(Calendar.DAY_OF_WEEK); @@ -120,7 +82,7 @@ public class CronUtils { public static Boolean taskExpire(Long endTime) { if (ObjectUtils.isEmpty(endTime)) return false; - Long now = System.currentTimeMillis(); + long now = System.currentTimeMillis(); return now > endTime; } diff --git a/core/core-backend/src/main/java/io/dataease/datasource/manage/DatasourceSyncManage.java b/core/core-backend/src/main/java/io/dataease/datasource/manage/DatasourceSyncManage.java index 13f8192082..d2a98d3cf3 100644 --- a/core/core-backend/src/main/java/io/dataease/datasource/manage/DatasourceSyncManage.java +++ b/core/core-backend/src/main/java/io/dataease/datasource/manage/DatasourceSyncManage.java @@ -18,11 +18,9 @@ import io.dataease.datasource.request.DatasourceRequest; import io.dataease.datasource.request.EngineRequest; import io.dataease.datasource.server.DatasourceServer; import io.dataease.datasource.server.DatasourceTaskServer; -import io.dataease.datasource.server.EngineServer; import io.dataease.exception.DEException; -import io.dataease.job.sechedule.ExtractDataJob; -import io.dataease.job.sechedule.ScheduleManager; -import io.dataease.utils.JsonUtil; +import io.dataease.job.schedule.ExtractDataJob; +import io.dataease.job.schedule.ScheduleManager; import io.dataease.utils.LogUtil; import jakarta.annotation.Resource; import org.apache.commons.lang3.StringUtils; diff --git a/core/core-backend/src/main/java/io/dataease/datasource/server/DatasourceServer.java b/core/core-backend/src/main/java/io/dataease/datasource/server/DatasourceServer.java index c393560ee9..05923ea7d3 100644 --- a/core/core-backend/src/main/java/io/dataease/datasource/server/DatasourceServer.java +++ b/core/core-backend/src/main/java/io/dataease/datasource/server/DatasourceServer.java @@ -35,8 +35,8 @@ import io.dataease.datasource.request.DatasourceRequest; import io.dataease.engine.constant.SQLConstants; import io.dataease.exception.DEException; import io.dataease.i18n.Translator; -import io.dataease.job.sechedule.CheckDsStatusJob; -import io.dataease.job.sechedule.ScheduleManager; +import io.dataease.job.schedule.CheckDsStatusJob; +import io.dataease.job.schedule.ScheduleManager; import io.dataease.license.config.XpackInteract; import io.dataease.log.DeLog; import io.dataease.model.BusiNodeRequest; diff --git a/core/core-backend/src/main/java/io/dataease/job/sechedule/CheckDsStatusJob.java b/core/core-backend/src/main/java/io/dataease/job/schedule/CheckDsStatusJob.java similarity index 83% rename from core/core-backend/src/main/java/io/dataease/job/sechedule/CheckDsStatusJob.java rename to core/core-backend/src/main/java/io/dataease/job/schedule/CheckDsStatusJob.java index 71c63b3b70..54cbd97a2e 100644 --- a/core/core-backend/src/main/java/io/dataease/job/sechedule/CheckDsStatusJob.java +++ b/core/core-backend/src/main/java/io/dataease/job/schedule/CheckDsStatusJob.java @@ -1,11 +1,13 @@ -package io.dataease.job.sechedule; +package io.dataease.job.schedule; import io.dataease.datasource.server.DatasourceServer; import io.dataease.utils.CommonBeanFactory; import io.dataease.utils.LogUtil; import jakarta.annotation.Resource; -import org.quartz.*; +import org.quartz.Job; +import org.quartz.JobExecutionContext; +import org.quartz.JobExecutionException; import org.springframework.stereotype.Component; @Component diff --git a/core/core-backend/src/main/java/io/dataease/job/sechedule/DeScheduleJob.java b/core/core-backend/src/main/java/io/dataease/job/schedule/DeScheduleJob.java similarity index 96% rename from core/core-backend/src/main/java/io/dataease/job/sechedule/DeScheduleJob.java rename to core/core-backend/src/main/java/io/dataease/job/schedule/DeScheduleJob.java index a6336d567a..029036ecc0 100644 --- a/core/core-backend/src/main/java/io/dataease/job/sechedule/DeScheduleJob.java +++ b/core/core-backend/src/main/java/io/dataease/job/schedule/DeScheduleJob.java @@ -1,4 +1,4 @@ -package io.dataease.job.sechedule; +package io.dataease.job.schedule; import io.dataease.utils.LogUtil; import org.quartz.*; diff --git a/core/core-backend/src/main/java/io/dataease/job/schedule/DeTaskExecutor.java b/core/core-backend/src/main/java/io/dataease/job/schedule/DeTaskExecutor.java new file mode 100644 index 0000000000..ffa7d2b056 --- /dev/null +++ b/core/core-backend/src/main/java/io/dataease/job/schedule/DeTaskExecutor.java @@ -0,0 +1,45 @@ +package io.dataease.job.schedule; + +import io.dataease.commons.utils.CronUtils; +import io.dataease.license.config.XpackInteract; +import jakarta.annotation.Resource; +import org.apache.commons.lang3.ObjectUtils; +import org.quartz.JobDataMap; +import org.quartz.JobKey; +import org.quartz.TriggerKey; +import org.springframework.stereotype.Component; + +import java.util.Date; + +@Component +public class DeTaskExecutor { + + @Resource + private ScheduleManager scheduleManager; + + @XpackInteract(value = "xpackTaskExecutor", replace = true) + public boolean execute(Long taskId) { + return false; + } + + public void addOrUpdateTask(Long taskId, String cron, Long startTime, Long endTime) { + if (CronUtils.taskExpire(endTime)) { + return; + } + String key = taskId.toString(); + JobKey jobKey = new JobKey(key, key); + TriggerKey triggerKey = new TriggerKey(key, key); + JobDataMap jobDataMap = new JobDataMap(); + jobDataMap.put("taskId", taskId); + Date end = null; + if (ObjectUtils.isNotEmpty(endTime)) end = new Date(endTime); + scheduleManager.addOrUpdateCronJob(jobKey, triggerKey, DeXpackScheduleJob.class, cron, new Date(startTime), end, jobDataMap); + } + + public void removeTask(Long taskId) { + String key = taskId.toString(); + JobKey jobKey = new JobKey(key); + TriggerKey triggerKey = new TriggerKey(key); + scheduleManager.removeJob(jobKey, triggerKey); + } +} diff --git a/core/core-backend/src/main/java/io/dataease/job/schedule/DeXpackScheduleJob.java b/core/core-backend/src/main/java/io/dataease/job/schedule/DeXpackScheduleJob.java new file mode 100644 index 0000000000..2a0f1903b1 --- /dev/null +++ b/core/core-backend/src/main/java/io/dataease/job/schedule/DeXpackScheduleJob.java @@ -0,0 +1,24 @@ +package io.dataease.job.schedule; + +import io.dataease.utils.CommonBeanFactory; +import jakarta.annotation.Resource; +import org.quartz.*; +import org.springframework.stereotype.Component; + +import java.util.Objects; + +@Component +public class DeXpackScheduleJob implements Job { + @Resource + private DeTaskExecutor deTaskExecutor; + @Override + public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException { + Trigger trigger = jobExecutionContext.getTrigger(); + JobKey jobKey = trigger.getJobKey(); + JobDataMap jobDataMap = jobExecutionContext.getJobDetail().getJobDataMap(); + Long taskId = jobDataMap.getLong("taskId"); + if (!deTaskExecutor.execute(taskId)) { + Objects.requireNonNull(CommonBeanFactory.getBean(ScheduleManager.class)).removeJob(jobKey, trigger.getKey()); + } + } +} diff --git a/core/core-backend/src/main/java/io/dataease/job/sechedule/ExtractDataJob.java b/core/core-backend/src/main/java/io/dataease/job/schedule/ExtractDataJob.java similarity index 79% rename from core/core-backend/src/main/java/io/dataease/job/sechedule/ExtractDataJob.java rename to core/core-backend/src/main/java/io/dataease/job/schedule/ExtractDataJob.java index 729ef22f7f..0ffbaae2b7 100644 --- a/core/core-backend/src/main/java/io/dataease/job/sechedule/ExtractDataJob.java +++ b/core/core-backend/src/main/java/io/dataease/job/schedule/ExtractDataJob.java @@ -1,14 +1,13 @@ -package io.dataease.job.sechedule; +package io.dataease.job.schedule; import io.dataease.datasource.manage.DatasourceSyncManage; -import io.dataease.datasource.server.DatasourceServer; import io.dataease.utils.CommonBeanFactory; import org.quartz.JobExecutionContext; import org.springframework.stereotype.Component; @Component -public class ExtractDataJob extends DeScheduleJob{ +public class ExtractDataJob extends DeScheduleJob { private DatasourceSyncManage datasourceSyncManage; public ExtractDataJob() { diff --git a/core/core-backend/src/main/java/io/dataease/job/sechedule/Schedular.java b/core/core-backend/src/main/java/io/dataease/job/schedule/Schedular.java similarity index 92% rename from core/core-backend/src/main/java/io/dataease/job/sechedule/Schedular.java rename to core/core-backend/src/main/java/io/dataease/job/schedule/Schedular.java index cb42755571..88de462f25 100644 --- a/core/core-backend/src/main/java/io/dataease/job/sechedule/Schedular.java +++ b/core/core-backend/src/main/java/io/dataease/job/schedule/Schedular.java @@ -1,4 +1,4 @@ -package io.dataease.job.sechedule; +package io.dataease.job.schedule; import com.fit2cloud.quartz.anno.QuartzScheduled; import io.dataease.datasource.server.DatasourceServer; @@ -6,7 +6,6 @@ import jakarta.annotation.Resource; import org.springframework.stereotype.Component; - @Component public class Schedular { diff --git a/core/core-backend/src/main/java/io/dataease/job/sechedule/ScheduleManager.java b/core/core-backend/src/main/java/io/dataease/job/schedule/ScheduleManager.java similarity index 94% rename from core/core-backend/src/main/java/io/dataease/job/sechedule/ScheduleManager.java rename to core/core-backend/src/main/java/io/dataease/job/schedule/ScheduleManager.java index 8231f94386..6691644506 100644 --- a/core/core-backend/src/main/java/io/dataease/job/sechedule/ScheduleManager.java +++ b/core/core-backend/src/main/java/io/dataease/job/schedule/ScheduleManager.java @@ -1,4 +1,4 @@ -package io.dataease.job.sechedule; +package io.dataease.job.schedule; import io.dataease.exception.DEException; @@ -8,7 +8,6 @@ import jakarta.annotation.Resource; import org.quartz.*; import org.springframework.stereotype.Component; - import java.util.Date; import java.util.HashMap; import java.util.List; @@ -31,7 +30,7 @@ public class ScheduleManager { * @throws SchedulerException */ public void addSimpleJob(JobKey jobKey, TriggerKey triggerKey, Class extends Job> cls, int repeatIntervalTime, - JobDataMap jobDataMap) throws SchedulerException { + JobDataMap jobDataMap) throws SchedulerException { JobBuilder jobBuilder = JobBuilder.newJob(cls).withIdentity(jobKey); @@ -64,7 +63,7 @@ public class ScheduleManager { * @param jobDataMap */ public void addCronJob(JobKey jobKey, TriggerKey triggerKey, Class jobClass, String cron, Date startTime, - Date endTime, JobDataMap jobDataMap) { + Date endTime, JobDataMap jobDataMap) { try { LogUtil.info("addCronJob: " + triggerKey.getName() + "," + triggerKey.getGroup()); @@ -105,7 +104,7 @@ public class ScheduleManager { } public void addCronJob(JobKey jobKey, TriggerKey triggerKey, Class jobClass, String cron, Date startTime, - Date endTime) { + Date endTime) { addCronJob(jobKey, triggerKey, jobClass, cron, startTime, endTime, null); } @@ -315,7 +314,7 @@ public class ScheduleManager { * @throws SchedulerException */ public void addOrUpdateSimpleJob(JobKey jobKey, TriggerKey triggerKey, Class clz, - int intervalTime, JobDataMap jobDataMap) throws SchedulerException { + int intervalTime, JobDataMap jobDataMap) throws SchedulerException { if (scheduler.checkExists(triggerKey)) { modifySimpleJobTime(triggerKey, intervalTime); @@ -326,20 +325,20 @@ public class ScheduleManager { } public void addOrUpdateSingleJob(JobKey jobKey, TriggerKey triggerKey, Class clz, - Date date, JobDataMap jobDataMap) throws DEException { + Date date, JobDataMap jobDataMap) throws DEException { try { if (scheduler.checkExists(triggerKey)) { modifySingleJobTime(triggerKey, date); } else { addSingleJob(jobKey, triggerKey, clz, date, jobDataMap); } - }catch (Exception e){ + } catch (Exception e) { DEException.throwException(e); } } public void addOrUpdateSingleJob(JobKey jobKey, TriggerKey triggerKey, Class clz, - Date date) throws SchedulerException { + Date date) throws SchedulerException { addOrUpdateSingleJob(jobKey, triggerKey, clz, date, null); } @@ -359,7 +358,7 @@ public class ScheduleManager { * @throws SchedulerException */ public void addOrUpdateCronJob(JobKey jobKey, TriggerKey triggerKey, Class jobClass, String cron, Date startTime, - Date endTime, JobDataMap jobDataMap) throws DEException { + Date endTime, JobDataMap jobDataMap) throws DEException { LogUtil.info("AddOrUpdateCronJob: " + jobKey.getName() + "," + triggerKey.getGroup()); try { @@ -368,13 +367,13 @@ public class ScheduleManager { } else { addCronJob(jobKey, triggerKey, jobClass, cron, startTime, endTime, jobDataMap); } - }catch (Exception e){ + } catch (Exception e) { DEException.throwException(e); } } public void addOrUpdateCronJob(JobKey jobKey, TriggerKey triggerKey, Class jobClass, String cron, Date startTime, - Date endTime) throws SchedulerException { + Date endTime) throws SchedulerException { addOrUpdateCronJob(jobKey, triggerKey, jobClass, cron, startTime, endTime, null); } diff --git a/core/core-backend/src/main/java/io/dataease/task/dao/auto/entity/CoreSysTask.java b/core/core-backend/src/main/java/io/dataease/task/dao/auto/entity/CoreSysTask.java deleted file mode 100644 index c906457fd4..0000000000 --- a/core/core-backend/src/main/java/io/dataease/task/dao/auto/entity/CoreSysTask.java +++ /dev/null @@ -1,167 +0,0 @@ -package io.dataease.task.dao.auto.entity; - -import com.baomidou.mybatisplus.annotation.IdType; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; -import java.io.Serializable; - -/** - *
- * - *
- * - * @author fit2cloud - * @since 2023-04-12 - */ -@TableName("core_sys_task") -public class CoreSysTask implements Serializable { - - private static final long serialVersionUID = 1L; - - /** - * 任务ID - */ - @TableId(value = "task_id", type = IdType.AUTO) - private Long taskId; - - /** - * 任务名称 - */ - private String taskName; - - /** - * 任务类型 - */ - private String taskType; - - /** - * 开始时间 - */ - private Long startTime; - - /** - * 结束时间 - */ - private Long endTime; - - /** - * 频率方式 - */ - private Integer rateType; - - /** - * 频率值 - */ - private String rateVal; - - /** - * 创建者ID - */ - private Long creator; - - /** - * 创建时间 - */ - private Long createTime; - - /** - * 运行状态 - */ - private Boolean status; - - public Long getTaskId() { - return taskId; - } - - public void setTaskId(Long taskId) { - this.taskId = taskId; - } - - public String getTaskName() { - return taskName; - } - - public void setTaskName(String taskName) { - this.taskName = taskName; - } - - public String getTaskType() { - return taskType; - } - - public void setTaskType(String taskType) { - this.taskType = taskType; - } - - 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 Integer getRateType() { - return rateType; - } - - public void setRateType(Integer rateType) { - this.rateType = rateType; - } - - public String getRateVal() { - return rateVal; - } - - public void setRateVal(String rateVal) { - this.rateVal = rateVal; - } - - public Long getCreator() { - return creator; - } - - public void setCreator(Long creator) { - this.creator = creator; - } - - public Long getCreateTime() { - return createTime; - } - - public void setCreateTime(Long createTime) { - this.createTime = createTime; - } - - public Boolean getStatus() { - return status; - } - - public void setStatus(Boolean status) { - this.status = status; - } - - @Override - public String toString() { - return "CoreSysTask{" + - "taskId = " + taskId + - ", taskName = " + taskName + - ", taskType = " + taskType + - ", startTime = " + startTime + - ", endTime = " + endTime + - ", rateType = " + rateType + - ", rateVal = " + rateVal + - ", creator = " + creator + - ", createTime = " + createTime + - ", status = " + status + - "}"; - } -} diff --git a/core/core-backend/src/main/java/io/dataease/task/dao/auto/mapper/CoreSysTaskMapper.java b/core/core-backend/src/main/java/io/dataease/task/dao/auto/mapper/CoreSysTaskMapper.java deleted file mode 100644 index f44d0878dc..0000000000 --- a/core/core-backend/src/main/java/io/dataease/task/dao/auto/mapper/CoreSysTaskMapper.java +++ /dev/null @@ -1,16 +0,0 @@ -package io.dataease.task.dao.auto.mapper; - -import io.dataease.task.dao.auto.entity.CoreSysTask; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; - -/** - *- * Mapper 接口 - *
- * - * @author fit2cloud - * @since 2023-04-12 - */ -public interface CoreSysTaskMapper extends BaseMapper