refactor(系统设置): 优化任务中心查询逻辑
This commit is contained in:
parent
82752b5bf7
commit
de37367c62
|
@ -2,30 +2,53 @@
|
|||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="io.metersphere.system.mapper.ExtScheduleMapper">
|
||||
<select id="taskCenterSchedulelist" resultType="io.metersphere.system.dto.taskcenter.TaskCenterScheduleDTO">
|
||||
SELECT task.* from (
|
||||
SELECT
|
||||
schedule.id,
|
||||
schedule.name as taskname,
|
||||
schedule.project_id,
|
||||
'API_SCENARIO' as resource_type,
|
||||
api_scenario.num as resource_num,
|
||||
api_scenario.name as resource_name,
|
||||
api_scenario.id as resource_id,
|
||||
schedule.value,
|
||||
schedule.enable,
|
||||
schedule.resource_id,
|
||||
schedule.resource_type,
|
||||
schedule.create_user AS createUserName,
|
||||
schedule.create_time
|
||||
FROM
|
||||
schedule
|
||||
inner join api_scenario on schedule.resource_id = api_scenario.id
|
||||
|
||||
union all
|
||||
SELECT
|
||||
schedule.id,
|
||||
schedule.name as taskname,
|
||||
schedule.project_id,
|
||||
'API_IMPORT' as resource_type,
|
||||
ads.num as resource_num,
|
||||
ads.name as resource_name,
|
||||
ads.id as resource_id,
|
||||
schedule.value,
|
||||
schedule.enable,
|
||||
schedule.create_user AS createUserName,
|
||||
schedule.create_time
|
||||
FROM
|
||||
schedule
|
||||
inner join api_definition_swagger ads on schedule.resource_id = ads.id
|
||||
|
||||
) task
|
||||
where
|
||||
schedule.resource_type in
|
||||
task.resource_type in
|
||||
<foreach collection="resourceTypes" item="resourceType" separator="," open="(" close=")">
|
||||
#{resourceType}
|
||||
</foreach>
|
||||
and schedule.project_id IN
|
||||
and task.project_id IN
|
||||
<foreach collection="projectIds" item="projectId" separator="," open="(" close=")">
|
||||
#{projectId}
|
||||
</foreach>
|
||||
<if test="request.keyword != null and request.keyword != ''">
|
||||
and (
|
||||
schedule.name like concat('%', #{request.keyword},'%')
|
||||
task.resource_name like concat('%', #{request.keyword},'%')
|
||||
)
|
||||
</if>
|
||||
<include refid="taskCenterScheduleFilters">
|
||||
|
@ -39,7 +62,7 @@
|
|||
<if test="values != null and values.size() > 0">
|
||||
<choose>
|
||||
<when test="key=='resourceType'">
|
||||
and schedule.resource_type in
|
||||
and task.resource_type in
|
||||
<include refid="io.metersphere.system.mapper.BaseMapper.filterInWrapper"/>
|
||||
</when>
|
||||
</choose>
|
||||
|
|
|
@ -2,10 +2,8 @@ package io.metersphere.system.service;
|
|||
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.page.PageMethod;
|
||||
import io.metersphere.api.domain.ApiScenario;
|
||||
import io.metersphere.project.domain.Project;
|
||||
import io.metersphere.project.mapper.ProjectMapper;
|
||||
import io.metersphere.sdk.constants.ScheduleResourceType;
|
||||
import io.metersphere.sdk.exception.MSException;
|
||||
import io.metersphere.sdk.util.Translator;
|
||||
import io.metersphere.system.domain.Organization;
|
||||
|
@ -28,7 +26,6 @@ import org.springframework.stereotype.Service;
|
|||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
|
@ -124,10 +121,6 @@ public class TaskCenterService {
|
|||
|
||||
|
||||
list.forEach(item -> {
|
||||
String resourceId = item.getResourceId();
|
||||
if (ScheduleTagType.TEST_RESOURCE.toString().equals(scheduleTagType)) {
|
||||
processTaskCenterScheduleData(list, resourceId, item);
|
||||
}
|
||||
item.setCreateUserName(userMap.getOrDefault(item.getCreateUserName(), StringUtils.EMPTY));
|
||||
item.setProjectName(projectMap.getOrDefault(item.getProjectId(), StringUtils.EMPTY));
|
||||
item.setOrganizationName(orgMap.getOrDefault(item.getProjectId(), StringUtils.EMPTY));
|
||||
|
@ -136,30 +129,6 @@ public class TaskCenterService {
|
|||
}
|
||||
}
|
||||
|
||||
private void processTaskCenterScheduleData (List<TaskCenterScheduleDTO> list, String resourceId, TaskCenterScheduleDTO taskCenterScheduleDTO) {
|
||||
// 业务数据
|
||||
// 根据 resourceType 分组,并获取每个类型对应的 resourceId 数组
|
||||
Map<String, List<String>> resultMap = list.stream()
|
||||
.collect(Collectors.groupingBy(TaskCenterScheduleDTO::getResourceType,
|
||||
Collectors.mapping(TaskCenterScheduleDTO::getResourceId, Collectors.toList())));
|
||||
Map<String, ApiScenario> apiScenarioMap = new HashMap<>();
|
||||
resultMap.forEach((type, resourceIds) ->{
|
||||
if (type.equals(ScheduleResourceType.API_SCENARIO.toString())) {
|
||||
List<ApiScenario> apiScenarios = extScheduleMapper.getApiScenarioListByIds(resourceIds);
|
||||
apiScenarioMap.putAll(apiScenarios.stream().collect(Collectors.toMap(ApiScenario::getId, Function.identity())));
|
||||
}
|
||||
});
|
||||
|
||||
// TODO ui test load test ...
|
||||
if (apiScenarioMap.containsKey(resourceId)) {
|
||||
ApiScenario apiScenario = apiScenarioMap.get(resourceId);
|
||||
taskCenterScheduleDTO.setResourceName(apiScenario.getName());
|
||||
taskCenterScheduleDTO.setResourceNum(apiScenario.getNum());
|
||||
} else {
|
||||
taskCenterScheduleDTO.setResourceName(StringUtils.EMPTY);
|
||||
}
|
||||
}
|
||||
|
||||
private List<OptionDTO> getProjectOption(String id){
|
||||
return baseProjectMapper.getProjectOptionsById(id);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue