forked from github/dataease
refactor: 优化设计缺陷,增加展示字段
This commit is contained in:
parent
87af7c9bc0
commit
d02d10c48c
@ -1,10 +1,15 @@
|
||||
package io.dataease.commons.utils;
|
||||
|
||||
import io.dataease.plugins.common.entity.GlobalTaskEntity;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.quartz.CronExpression;
|
||||
import org.quartz.CronScheduleBuilder;
|
||||
import org.quartz.CronTrigger;
|
||||
import org.quartz.TriggerBuilder;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
@ -58,5 +63,54 @@ public class CronUtils {
|
||||
return date;
|
||||
}
|
||||
|
||||
public static String cron(GlobalTaskEntity taskEntity) {
|
||||
if (taskEntity.getRateType() == -1) {
|
||||
return taskEntity.getRateVal();
|
||||
}
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
Date date = null;
|
||||
try {
|
||||
date = sdf.parse(taskEntity.getRateVal());
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Calendar instance = Calendar.getInstance();
|
||||
instance.setTime(date);
|
||||
|
||||
if (taskEntity.getRateType() == 0) {
|
||||
return instance.get(Calendar.SECOND) + " " +
|
||||
instance.get(Calendar.MINUTE) + " " +
|
||||
instance.get(Calendar.HOUR_OF_DAY) + " * * ?";
|
||||
}
|
||||
if (taskEntity.getRateType() == 1) {
|
||||
return instance.get(Calendar.SECOND) + " " +
|
||||
instance.get(Calendar.MINUTE) + " " +
|
||||
instance.get(Calendar.HOUR_OF_DAY) + " ? * " +
|
||||
getDayOfWeek(instance);
|
||||
}
|
||||
if (taskEntity.getRateType() == 2) {
|
||||
return instance.get(Calendar.SECOND) + " " +
|
||||
instance.get(Calendar.MINUTE) + " " +
|
||||
instance.get(Calendar.HOUR_OF_DAY) + " " +
|
||||
instance.get(Calendar.DATE) + " * ?";
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
private static String getDayOfWeek(Calendar instance) {
|
||||
int index = instance.get(Calendar.DAY_OF_WEEK);
|
||||
index = (index + 1) % 7;
|
||||
return String.valueOf(index);
|
||||
}
|
||||
|
||||
// 判断任务是否过期
|
||||
public static Boolean taskExpire(Long endTime) {
|
||||
if (ObjectUtils.isEmpty(endTime))
|
||||
return false;
|
||||
Long now = System.currentTimeMillis();
|
||||
return now > endTime;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,14 +1,13 @@
|
||||
package io.dataease.job.sechedule.strategy;
|
||||
|
||||
import io.dataease.commons.utils.CronUtils;
|
||||
import io.dataease.job.sechedule.ScheduleManager;
|
||||
import io.dataease.plugins.common.entity.GlobalTaskEntity;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.quartz.*;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public abstract class TaskHandler implements InitializingBean {
|
||||
@ -17,7 +16,7 @@ public abstract class TaskHandler implements InitializingBean {
|
||||
// 1。首先看看是否过期
|
||||
Long endTime = taskEntity.getEndTime();
|
||||
removeTask(scheduleManager, taskEntity);
|
||||
if (taskExpire(endTime)) { // 过期了就删除任务
|
||||
if (CronUtils.taskExpire(endTime)) { // 过期了就删除任务
|
||||
return;
|
||||
}
|
||||
JobKey jobKey = new JobKey(taskEntity.getTaskId().toString());
|
||||
@ -28,55 +27,17 @@ public abstract class TaskHandler implements InitializingBean {
|
||||
new Date(taskEntity.getEndTime());
|
||||
}
|
||||
Class<? extends TaskHandler> executor = this.getClass();
|
||||
String cron = cron(taskEntity);
|
||||
String cron = CronUtils.cron(taskEntity);
|
||||
scheduleManager.addOrUpdateCronJob(jobKey, triggerKey, executor, cron, start, end, jobDataMap(taskEntity));
|
||||
}
|
||||
|
||||
protected abstract JobDataMap jobDataMap(GlobalTaskEntity taskEntity);
|
||||
|
||||
private String cron(GlobalTaskEntity taskEntity) {
|
||||
if (taskEntity.getRateType() == -1) {
|
||||
return taskEntity.getRateVal();
|
||||
}
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
Date date = null;
|
||||
try {
|
||||
date = sdf.parse(taskEntity.getRateVal());
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Calendar instance = Calendar.getInstance();
|
||||
instance.setTime(date);
|
||||
|
||||
if (taskEntity.getRateType() == 0) {
|
||||
return instance.get(Calendar.SECOND) + " " +
|
||||
instance.get(Calendar.MINUTE) + " " +
|
||||
instance.get(Calendar.HOUR_OF_DAY) + " * * ?";
|
||||
}
|
||||
if (taskEntity.getRateType() == 1) {
|
||||
return instance.get(Calendar.SECOND) + " " +
|
||||
instance.get(Calendar.MINUTE) + " " +
|
||||
instance.get(Calendar.HOUR_OF_DAY) + " ? * " +
|
||||
getDayOfWeek(instance);
|
||||
}
|
||||
if (taskEntity.getRateType() == 2) {
|
||||
return instance.get(Calendar.SECOND) + " " +
|
||||
instance.get(Calendar.MINUTE) + " " +
|
||||
instance.get(Calendar.HOUR_OF_DAY) + " " +
|
||||
instance.get(Calendar.DATE) + " * ?";
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public abstract void resetRunningInstance(Long taskId);
|
||||
|
||||
private String getDayOfWeek(Calendar instance) {
|
||||
int index = instance.get(Calendar.DAY_OF_WEEK);
|
||||
index = (index + 1) % 7;
|
||||
return String.valueOf(index);
|
||||
}
|
||||
|
||||
|
||||
public void removeTask(ScheduleManager scheduleManager, GlobalTaskEntity taskEntity) {
|
||||
JobKey jobKey = new JobKey(taskEntity.getTaskId().toString());
|
||||
@ -89,13 +50,7 @@ public abstract class TaskHandler implements InitializingBean {
|
||||
scheduleManager.fireNow(jobKey);
|
||||
}
|
||||
|
||||
// 判断任务是否过期
|
||||
public Boolean taskExpire(Long endTime) {
|
||||
if (ObjectUtils.isEmpty(endTime))
|
||||
return false;
|
||||
Long now = System.currentTimeMillis();
|
||||
return now > endTime;
|
||||
}
|
||||
|
||||
|
||||
protected abstract Boolean taskIsRunning(Long taskId);
|
||||
|
||||
|
@ -7,6 +7,7 @@ import io.dataease.auth.service.impl.AuthUserServiceImpl;
|
||||
import io.dataease.auth.util.JWTUtils;
|
||||
import io.dataease.base.mapper.ext.ExtTaskMapper;
|
||||
import io.dataease.commons.utils.CommonBeanFactory;
|
||||
import io.dataease.commons.utils.CronUtils;
|
||||
import io.dataease.commons.utils.LogUtil;
|
||||
import io.dataease.commons.utils.ServletUtils;
|
||||
import io.dataease.job.sechedule.ScheduleManager;
|
||||
@ -67,7 +68,7 @@ public class EmailTaskHandler extends TaskHandler implements Job {
|
||||
JobDataMap jobDataMap = context.getJobDetail().getJobDataMap();
|
||||
GlobalTaskEntity taskEntity = (GlobalTaskEntity) jobDataMap.get("taskEntity");
|
||||
ScheduleManager scheduleManager = SpringContextUtil.getBean(ScheduleManager.class);
|
||||
if (taskExpire(taskEntity.getEndTime())) {
|
||||
if (CronUtils.taskExpire(taskEntity.getEndTime())) {
|
||||
removeTask(scheduleManager, taskEntity);
|
||||
return;
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ import io.dataease.plugins.xpack.email.dto.response.XpackTaskGridDTO;
|
||||
import io.dataease.plugins.xpack.email.dto.response.XpackTaskInstanceDTO;
|
||||
import io.dataease.plugins.xpack.email.service.EmailXpackService;
|
||||
import io.dataease.service.ScheduleService;
|
||||
import io.swagger.annotations.Api;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -28,7 +28,7 @@ import java.util.concurrent.Future;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@Api(tags = "xpack:定时报告")
|
||||
|
||||
@RequestMapping("/plugin/task")
|
||||
@RestController
|
||||
public class XEmailTaskServer {
|
||||
@ -45,6 +45,28 @@ public class XEmailTaskServer {
|
||||
EmailXpackService emailXpackService = SpringContextUtil.getBean(EmailXpackService.class);
|
||||
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
|
||||
List<XpackTaskGridDTO> tasks = emailXpackService.taskGrid(request);
|
||||
if (CollectionUtils.isNotEmpty(tasks)) {
|
||||
tasks.forEach(item -> {
|
||||
if (CronUtils.taskExpire(item.getEndTime())) {
|
||||
item.setNextExecTime(null);
|
||||
}else {
|
||||
GlobalTaskEntity globalTaskEntity = new GlobalTaskEntity();
|
||||
globalTaskEntity.setRateType(item.getRateType());
|
||||
globalTaskEntity.setRateVal(item.getRateVal());
|
||||
try{
|
||||
String cron = CronUtils.cron(globalTaskEntity);
|
||||
if (StringUtils.isNotBlank(cron)) {
|
||||
Long nextTime = CronUtils.getNextTriggerTime(cron).getTime();
|
||||
item.setNextExecTime(nextTime);
|
||||
}
|
||||
}catch (Exception e) {
|
||||
item.setNextExecTime(null);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
Pager<List<XpackTaskGridDTO>> listPager = PageUtils.setPageInfo(page, tasks);
|
||||
return listPager;
|
||||
}
|
||||
@ -133,6 +155,12 @@ public class XEmailTaskServer {
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/stop/{taskId}")
|
||||
public void stop(@PathVariable Long taskId) throws Exception {
|
||||
EmailXpackService emailXpackService = SpringContextUtil.getBean(EmailXpackService.class);
|
||||
emailXpackService.stop(taskId);
|
||||
}
|
||||
|
||||
@PostMapping("/queryInstancies/{goPage}/{pageSize}")
|
||||
public Pager<List<XpackTaskInstanceDTO>> instancesGrid(@PathVariable int goPage, @PathVariable int pageSize,
|
||||
@RequestBody XpackGridRequest request) {
|
||||
|
@ -131,6 +131,7 @@ export default {
|
||||
default_login: 'Normal'
|
||||
},
|
||||
commons: {
|
||||
stop: 'Stop',
|
||||
first_login_tips: 'Please change the initial password',
|
||||
roger_that: 'Roger That',
|
||||
apply: 'Apply',
|
||||
@ -347,6 +348,8 @@ export default {
|
||||
ukey_title: 'API Keys',
|
||||
thumbnail: 'thumbnail',
|
||||
confirm_delete: 'Confirm delete',
|
||||
confirm_stop: 'Confirm stop',
|
||||
stop_success: 'Stop success',
|
||||
treeselect: {
|
||||
no_children_text: 'No sub-options.',
|
||||
no_options_text: 'No options available.',
|
||||
@ -1739,7 +1742,8 @@ export default {
|
||||
search_by_name: 'Search by name',
|
||||
exec_time: 'Execute time',
|
||||
status: 'Execute status',
|
||||
pixel_error: 'Pixel only support {800 - 10000} * {500 - 6250}'
|
||||
pixel_error: 'Pixel only support {800 - 10000} * {500 - 6250}',
|
||||
next_exec_time: 'Next execute time'
|
||||
|
||||
},
|
||||
emailtask: {
|
||||
|
@ -131,6 +131,7 @@ export default {
|
||||
default_login: '普通登錄'
|
||||
},
|
||||
commons: {
|
||||
stop: '停止',
|
||||
first_login_tips: '您使用的是初始密碼,記得修改密碼哦',
|
||||
roger_that: '知道了',
|
||||
apply: '應用',
|
||||
@ -347,6 +348,8 @@ export default {
|
||||
ukey_title: 'API Keys',
|
||||
thumbnail: '縮略圖',
|
||||
confirm_delete: '確認刪除',
|
||||
confirm_stop: '確認停止',
|
||||
stop_success: '停止成功',
|
||||
treeselect: {
|
||||
no_children_text: '沒有子節點',
|
||||
no_options_text: '沒有可用選項',
|
||||
@ -1749,7 +1752,8 @@ export default {
|
||||
search_by_name: '根據名稱搜索',
|
||||
exec_time: '執行時間',
|
||||
status: '執行狀態',
|
||||
pixel_error: '分辨率支持{800 - 10000} * {500 - 6250}'
|
||||
pixel_error: '分辨率支持{800 - 10000} * {500 - 6250}',
|
||||
next_exec_time: '下次執行時間'
|
||||
|
||||
},
|
||||
emailtask: {
|
||||
|
@ -131,6 +131,7 @@ export default {
|
||||
default_login: '普通登录'
|
||||
},
|
||||
commons: {
|
||||
stop: '停止',
|
||||
first_login_tips: '您使用的是初始密码,记得修改密码哦',
|
||||
roger_that: '知道了',
|
||||
apply: '应用',
|
||||
@ -348,6 +349,8 @@ export default {
|
||||
ukey_title: 'API Keys',
|
||||
thumbnail: '缩略图',
|
||||
confirm_delete: '确认删除',
|
||||
confirm_stop: '确认停止',
|
||||
stop_success: '停止成功',
|
||||
treeselect: {
|
||||
no_children_text: '没有子节点',
|
||||
no_options_text: '没有可用选项',
|
||||
@ -1759,7 +1762,8 @@ export default {
|
||||
search_by_name: '根据名称搜索',
|
||||
exec_time: '执行时间',
|
||||
status: '执行状态',
|
||||
pixel_error: '分辨率支持{800 - 10000} * {500 - 6250}'
|
||||
pixel_error: '分辨率支持{800 - 10000} * {500 - 6250}',
|
||||
next_exec_time: '下次执行时间'
|
||||
|
||||
},
|
||||
emailtask: {
|
||||
|
Loading…
Reference in New Issue
Block a user