feat(接口测试): 查询后台任务的上次和下次执行时间
This commit is contained in:
parent
5dfe0330bc
commit
6315e15e90
|
@ -45,6 +45,9 @@ public class TaskHubScheduleDTO implements Serializable {
|
||||||
@Schema(description = "运行规则(cron表达式)")
|
@Schema(description = "运行规则(cron表达式)")
|
||||||
private String value;
|
private String value;
|
||||||
|
|
||||||
|
@Schema(description = "上次完成时间")
|
||||||
|
private Long lastTime;
|
||||||
|
|
||||||
@Schema(description = "下次执行时间")
|
@Schema(description = "下次执行时间")
|
||||||
private Long nextTime;
|
private Long nextTime;
|
||||||
|
|
||||||
|
|
|
@ -42,10 +42,11 @@ public interface ExtScheduleMapper {
|
||||||
|
|
||||||
List<Schedule> getSchedule(@Param("request") TaskCenterScheduleBatchRequest request, @Param("projectIds") List<String> projectIds);
|
List<Schedule> getSchedule(@Param("request") TaskCenterScheduleBatchRequest request, @Param("projectIds") List<String> projectIds);
|
||||||
|
|
||||||
|
|
||||||
int countByProjectIds(@Param("ids") List<String> ids);
|
int countByProjectIds(@Param("ids") List<String> ids);
|
||||||
|
|
||||||
List<TaskHubScheduleDTO> selectScheduleList(@Param("request") BasePageRequest request, @Param("projectIds") List<String> projectIds);
|
List<TaskHubScheduleDTO> selectScheduleList(@Param("request") BasePageRequest request, @Param("projectIds") List<String> projectIds);
|
||||||
|
|
||||||
List<Schedule> getSchedules(@Param("request") TableBatchProcessDTO request, @Param("projectIds") List<String> projectIds);
|
List<Schedule> getSchedules(@Param("request") TableBatchProcessDTO request, @Param("projectIds") List<String> projectIds);
|
||||||
|
|
||||||
|
List<TaskHubScheduleDTO> getLastAndNextTime(@Param("resourceIds") List<String> resourceIds);
|
||||||
}
|
}
|
||||||
|
|
|
@ -366,6 +366,13 @@
|
||||||
</include>
|
</include>
|
||||||
</where>
|
</where>
|
||||||
</select>
|
</select>
|
||||||
|
<select id="getLastAndNextTime" resultType="io.metersphere.system.dto.taskhub.TaskHubScheduleDTO">
|
||||||
|
SELECT JOB_NAME AS resource_id, NEXT_FIRE_TIME AS nextTime, PREV_FIRE_TIME AS lastTime
|
||||||
|
FROM QRTZ_TRIGGERS WHERE TRIGGER_NAME IN
|
||||||
|
<foreach collection="resourceIds" item="resourceId" separator="," open="(" close=")">
|
||||||
|
#{resourceId}
|
||||||
|
</foreach>
|
||||||
|
</select>
|
||||||
|
|
||||||
<sql id="taskCenterQuery">
|
<sql id="taskCenterQuery">
|
||||||
<if test="projectIds != null and projectIds.size() > 0">
|
<if test="projectIds != null and projectIds.size() > 0">
|
||||||
|
|
|
@ -51,13 +51,16 @@ import org.apache.ibatis.session.ExecutorType;
|
||||||
import org.apache.ibatis.session.SqlSession;
|
import org.apache.ibatis.session.SqlSession;
|
||||||
import org.apache.ibatis.session.SqlSessionFactory;
|
import org.apache.ibatis.session.SqlSessionFactory;
|
||||||
import org.mybatis.spring.SqlSessionUtils;
|
import org.mybatis.spring.SqlSessionUtils;
|
||||||
|
import org.quartz.CronExpression;
|
||||||
import org.quartz.JobKey;
|
import org.quartz.JobKey;
|
||||||
import org.quartz.TriggerKey;
|
import org.quartz.TriggerKey;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Propagation;
|
import org.springframework.transaction.annotation.Propagation;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.text.ParseException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
@ -233,10 +236,35 @@ public class BaseTaskHubService {
|
||||||
.flatMap(item -> Stream.of(item.getCreateUserName()))
|
.flatMap(item -> Stream.of(item.getCreateUserName()))
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
Map<String, String> userMap = userLoginService.getUserNameMap(new ArrayList<>(userSet));
|
Map<String, String> userMap = userLoginService.getUserNameMap(new ArrayList<>(userSet));
|
||||||
list.forEach(item -> {
|
|
||||||
|
List<String> resourceIds = list.stream()
|
||||||
|
.filter(item -> StringUtils.isNotBlank(item.getResourceId()))
|
||||||
|
.map(TaskHubScheduleDTO::getResourceId)
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
Map<String, TaskHubScheduleDTO> trigerTimeMap = Map.of();
|
||||||
|
if (CollectionUtils.isNotEmpty(resourceIds)) {
|
||||||
|
trigerTimeMap = extScheduleMapper.getLastAndNextTime(resourceIds)
|
||||||
|
.stream()
|
||||||
|
.collect(Collectors.toMap(TaskHubScheduleDTO::getResourceId, Function.identity()));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (TaskHubScheduleDTO item : list) {
|
||||||
item.setCreateUserName(userMap.getOrDefault(item.getCreateUserName(), StringUtils.EMPTY));
|
item.setCreateUserName(userMap.getOrDefault(item.getCreateUserName(), StringUtils.EMPTY));
|
||||||
item.setOrganizationName(orgMap.getOrDefault(item.getProjectId(), StringUtils.EMPTY));
|
item.setOrganizationName(orgMap.getOrDefault(item.getProjectId(), StringUtils.EMPTY));
|
||||||
});
|
if (trigerTimeMap.get(item.getResourceId()) != null) {
|
||||||
|
item.setNextTime(trigerTimeMap.get(item.getResourceId()).getNextTime());
|
||||||
|
item.setLastTime(trigerTimeMap.get(item.getResourceId()).getLastTime());
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
CronExpression cron = new CronExpression(item.getValue());
|
||||||
|
Date date = new Date(System.currentTimeMillis());
|
||||||
|
item.setNextTime(cron.getNextValidTimeAfter(date).getTime());
|
||||||
|
} catch (ParseException e) {
|
||||||
|
LogUtils.error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue