fix(X-Pack): 修复数据填报缺失文件

This commit is contained in:
ulleo 2024-08-07 15:21:42 +08:00
parent 4f5057ce9a
commit 52d4412d0b
2 changed files with 138 additions and 0 deletions

View File

@ -0,0 +1,111 @@
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;
import java.util.Map;
@Component("deDataFillingTaskExecutor")
public class DeDataFillingTaskExecutor {
protected static final String IS_TEMP_TASK = "isTempTask";
protected static final String IS_RETRY_TASK = "isRetryTask";
private static final String JOB_GROUP = "REPORT_TASK";
private static final String RETRY_JOB_GROUP = "RETRY_REPORT_TASK";
private static final String TEMP_JOB_GROUP = "TEMP_REPORT_TASK";
@Resource
private ScheduleManager scheduleManager;
@XpackInteract(value = "dataFillingTaskExecutor", replace = true)
public boolean execute(Map<String, Object> taskData) {
return false;
}
@XpackInteract(value = "dataFillingTaskExecutor", replace = true)
public void init() {
}
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, JOB_GROUP);
TriggerKey triggerKey = new TriggerKey(key, JOB_GROUP);
JobDataMap jobDataMap = new JobDataMap();
jobDataMap.put("taskId", taskId);
jobDataMap.put(IS_TEMP_TASK, false);
Date end = null;
if (ObjectUtils.isNotEmpty(endTime)) end = new Date(endTime);
scheduleManager.addOrUpdateCronJob(jobKey, triggerKey, DeXpackDataFillingScheduleJob.class, cron, startTime == null ? null : new Date(startTime), end, jobDataMap);
}
public void addRetryTask(Long taskId, Integer retryLimit, Integer retryInterval) {
long saltTime = 3000L;
long interval = retryInterval == null ? 5L : retryInterval;
long intervalMill = interval * 60000L;
long now = System.currentTimeMillis();
String cron = "0 */" + interval + " * * * ?";
long endTime = (retryLimit + 1) * intervalMill + now - saltTime;
String key = taskId.toString();
if (CronUtils.taskExpire(endTime)) {
return;
}
JobKey jobKey = new JobKey(key, RETRY_JOB_GROUP);
TriggerKey triggerKey = new TriggerKey(key, RETRY_JOB_GROUP);
JobDataMap jobDataMap = new JobDataMap();
jobDataMap.put("taskId", taskId);
jobDataMap.put(IS_RETRY_TASK, true);
Date end = null;
if (ObjectUtils.isNotEmpty(endTime)) end = new Date(endTime);
scheduleManager.addOrUpdateCronJob(jobKey, triggerKey, DeXpackDataFillingScheduleJob.class, cron, new Date(now), end, jobDataMap);
}
public boolean fireNow(Long taskId) throws Exception {
String key = taskId.toString();
JobKey jobKey = new JobKey(key, JOB_GROUP);
if (scheduleManager.exist(jobKey)) {
scheduleManager.fireNow(jobKey);
return true;
}
return false;
}
public void addTempTask(Long taskId, Long startTime) {
String key = taskId.toString();
JobKey jobKey = new JobKey(key, TEMP_JOB_GROUP);
TriggerKey triggerKey = new TriggerKey(key, TEMP_JOB_GROUP);
JobDataMap jobDataMap = new JobDataMap();
jobDataMap.put(IS_TEMP_TASK, true);
String cron = CronUtils.tempCron();
jobDataMap.put("taskId", taskId);
scheduleManager.addOrUpdateCronJob(jobKey, triggerKey, DeXpackDataFillingScheduleJob.class, cron, new Date(startTime), null, jobDataMap);
}
public void removeTask(Long taskId, boolean isTemp) {
String key = taskId.toString();
JobKey jobKey = new JobKey(key, isTemp ? TEMP_JOB_GROUP : JOB_GROUP);
TriggerKey triggerKey = new TriggerKey(key, isTemp ? TEMP_JOB_GROUP : JOB_GROUP);
scheduleManager.removeJob(jobKey, triggerKey);
}
public void removeRetryTask(Long taskId) {
String key = taskId.toString();
JobKey jobKey = new JobKey(key, RETRY_JOB_GROUP);
TriggerKey triggerKey = new TriggerKey(key, RETRY_JOB_GROUP);
scheduleManager.removeJob(jobKey, triggerKey);
}
public void clearRetryTask() throws Exception {
scheduleManager.clearByGroup(RETRY_JOB_GROUP);
}
}

View File

@ -0,0 +1,27 @@
package io.dataease.job.schedule;
import io.dataease.license.utils.LicenseUtil;
import io.dataease.utils.CommonBeanFactory;
import org.quartz.*;
import org.springframework.stereotype.Component;
import java.util.Objects;
@Component
public class DeXpackDataFillingScheduleJob implements Job {
@Override
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
Trigger trigger = jobExecutionContext.getTrigger();
JobKey jobKey = trigger.getJobKey();
JobDataMap jobDataMap = jobExecutionContext.getJobDetail().getJobDataMap();
DeDataFillingTaskExecutor deTaskExecutor = CommonBeanFactory.getBean(DeDataFillingTaskExecutor.class);
assert deTaskExecutor != null;
LicenseUtil.validate();
boolean taskLoaded = deTaskExecutor.execute(jobDataMap);
if (!taskLoaded) {
Objects.requireNonNull(CommonBeanFactory.getBean(ScheduleManager.class)).removeJob(jobKey, trigger.getKey());
}
}
}