feat(测试计划): 任务中心支持计划组父子层级查看

--story=1015333 --user=宋昌昌 【测试计划】完成剩余功能 https://www.tapd.cn/55049933/s/1543343
This commit is contained in:
song-cc-rock 2024-07-03 15:21:13 +08:00 committed by Craftsman
parent 5e647b2070
commit 307be50c14
7 changed files with 70 additions and 29 deletions

View File

@ -5,6 +5,8 @@ import lombok.Data;
import java.io.Serial; import java.io.Serial;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
/** /**
* @author: LAN * @author: LAN
@ -66,5 +68,9 @@ public class TaskCenterDTO implements Serializable {
@Schema(description = "执行历史是否被清理") @Schema(description = "执行历史是否被清理")
private boolean historyDeleted = false; private boolean historyDeleted = false;
@Schema(description = "计划组ID")
private String parentId;
@Schema(description = "计划组子任务")
private List<TaskCenterDTO> children = new ArrayList<>();
} }

View File

@ -47,6 +47,8 @@ public interface ExtTestPlanReportMapper {
List<TaskCenterDTO> taskCenterlist(@Param("request") TaskCenterPageRequest request, @Param("projectIds") List<String> projectIds, List<TaskCenterDTO> taskCenterlist(@Param("request") TaskCenterPageRequest request, @Param("projectIds") List<String> projectIds,
@Param("startTime") long startTime, @Param("endTime") long endTime); @Param("startTime") long startTime, @Param("endTime") long endTime);
List<TaskCenterDTO> getChildTaskCenter(@Param("ids") List<String> groupReportIds);
List<TestPlanReportDetailResponse> getPlanReportListById(@Param("request") TestPlanReportDetailPageRequest request); List<TestPlanReportDetailResponse> getPlanReportListById(@Param("request") TestPlanReportDetailPageRequest request);
List<ReportDTO> getReports(@Param("request") TaskCenterBatchRequest request, @Param("projectIds") List<String> projectIds, List<ReportDTO> getReports(@Param("request") TaskCenterBatchRequest request, @Param("projectIds") List<String> projectIds,

View File

@ -70,8 +70,8 @@
tpr.create_user AS operationName, tpr.create_user AS operationName,
tpr.trigger_mode, tpr.trigger_mode,
tpr.start_time, tpr.start_time,
'' as parentId,
project.organization_id, project.organization_id,
tp.num AS resourceNum, tp.num AS resourceNum,
tp.name AS resourceName, tp.name AS resourceName,
tp.id AS resourceId tp.id AS resourceId
@ -81,6 +81,8 @@
left join project on tpr.project_id = project.id left join project on tpr.project_id = project.id
where where
tpr.start_time BETWEEN #{startTime} AND #{endTime} tpr.start_time BETWEEN #{startTime} AND #{endTime}
<!-- 独立报告 && 计划组报告 -->
and tpr.id = tpr.parent_id
<if test="projectIds != null and projectIds.size() > 0"> <if test="projectIds != null and projectIds.size() > 0">
and and
tpr.project_id IN tpr.project_id IN
@ -96,6 +98,37 @@
</if> </if>
<include refid="filter"/> <include refid="filter"/>
</select> </select>
<select id="getChildTaskCenter" resultType="io.metersphere.system.dto.taskcenter.TaskCenterDTO">
select
distinct tpr.id,
tpr.project_id,
tpr.integrated,
tpr.result_status as status,
tpr.exec_status,
tpr.start_time as operationTime,
tpr.create_user as operationName,
tpr.trigger_mode,
tpr.start_time,
tpr.parent_id as parentId,
project.organization_id,
tp.num as resourceNum,
tp.name as resourceName,
tp.id as resourceId
from
test_plan_report tpr
inner join test_plan tp ON tpr.test_plan_id = tp.id
left join project on tpr.project_id = project.id
where
tpr.id != tpr.parent_id
<if test="ids != null and ids.size() > 0">
and tpr.parent_id in
<foreach collection="ids" item="id" separator="," open="(" close=")">
#{id}
</foreach>
</if>
</select>
<select id="getPlanReportListById" <select id="getPlanReportListById"
resultType="io.metersphere.plan.dto.response.TestPlanReportDetailResponse"> resultType="io.metersphere.plan.dto.response.TestPlanReportDetailResponse">

View File

@ -827,9 +827,7 @@ public class TestPlanService extends TestPlanBaseUtilsService {
List<String> userIds = hisList.stream().map(TestPlanExecuteHisDTO::getOperationUser).distinct().toList(); List<String> userIds = hisList.stream().map(TestPlanExecuteHisDTO::getOperationUser).distinct().toList();
List<OptionDTO> userOptions = baseUserMapper.selectUserOptionByIds(userIds); List<OptionDTO> userOptions = baseUserMapper.selectUserOptionByIds(userIds);
Map<String, String> userMap = userOptions.stream().collect(Collectors.toMap(OptionDTO::getId, OptionDTO::getName)); Map<String, String> userMap = userOptions.stream().collect(Collectors.toMap(OptionDTO::getId, OptionDTO::getName));
hisList.forEach(his -> { hisList.forEach(his -> his.setOperationUser(userMap.getOrDefault(his.getOperationUser(), his.getOperationUser())));
his.setOperationUser(userMap.getOrDefault(his.getOperationUser(), his.getOperationUser()));
});
return hisList; return hisList;
} }

View File

@ -4,7 +4,6 @@ import com.github.pagehelper.Page;
import com.github.pagehelper.page.PageMethod; import com.github.pagehelper.page.PageMethod;
import io.metersphere.api.dto.definition.ExecuteReportDTO; import io.metersphere.api.dto.definition.ExecuteReportDTO;
import io.metersphere.api.dto.report.ReportDTO; import io.metersphere.api.dto.report.ReportDTO;
import io.metersphere.api.mapper.ExtApiReportMapper;
import io.metersphere.api.mapper.ExtApiScenarioReportMapper; import io.metersphere.api.mapper.ExtApiScenarioReportMapper;
import io.metersphere.engine.MsHttpClient; import io.metersphere.engine.MsHttpClient;
import io.metersphere.plan.mapper.ExtTestPlanReportMapper; import io.metersphere.plan.mapper.ExtTestPlanReportMapper;
@ -78,8 +77,6 @@ public class TestPlanTaskCenterService {
@Resource @Resource
OperationLogService operationLogService; OperationLogService operationLogService;
@Resource @Resource
ExtApiReportMapper extApiReportMapper;
@Resource
ExtApiScenarioReportMapper extApiScenarioReportMapper; ExtApiScenarioReportMapper extApiScenarioReportMapper;
@Resource @Resource
TestPlanExecuteService testPlanExecuteService; TestPlanExecuteService testPlanExecuteService;
@ -132,21 +129,26 @@ public class TestPlanTaskCenterService {
if (CollectionUtils.isNotEmpty(projectIds)) { if (CollectionUtils.isNotEmpty(projectIds)) {
Map<String, ExecuteReportDTO> historyDeletedMap = new HashMap<>(); Map<String, ExecuteReportDTO> historyDeletedMap = new HashMap<>();
list = extTestPlanReportMapper.taskCenterlist(request, isSystem ? new ArrayList<>() : projectIds, DateUtils.getDailyStartTime(), DateUtils.getDailyEndTime()); list = extTestPlanReportMapper.taskCenterlist(request, isSystem ? new ArrayList<>() : projectIds, DateUtils.getDailyStartTime(), DateUtils.getDailyEndTime());
//执行历史列表 // 查询计划组的任务的子计划任务
List<String> groupReportIds = list.stream().filter(TaskCenterDTO::isIntegrated).map(TaskCenterDTO::getId).toList();
if (CollectionUtils.isNotEmpty(groupReportIds)) {
List<TaskCenterDTO> childTaskCenterList = extTestPlanReportMapper.getChildTaskCenter(groupReportIds);
Map<String, List<TaskCenterDTO>> childTaskMap = childTaskCenterList.stream().collect(Collectors.groupingBy(TaskCenterDTO::getParentId));
list.forEach(item -> {
if (CollectionUtils.isNotEmpty(childTaskMap.get(item.getId()))) {
item.setChildren(childTaskMap.get(item.getId()));
}
});
}
// 执行历史列表
List<String> reportIds = list.stream().map(TaskCenterDTO::getId).toList(); List<String> reportIds = list.stream().map(TaskCenterDTO::getId).toList();
if (CollectionUtils.isNotEmpty(reportIds)) { if (CollectionUtils.isNotEmpty(reportIds)) {
List<ExecuteReportDTO> historyDeletedList = extTestPlanReportMapper.getHistoryDeleted(reportIds); List<ExecuteReportDTO> historyDeletedList = extTestPlanReportMapper.getHistoryDeleted(reportIds);
historyDeletedMap = historyDeletedList.stream().collect(Collectors.toMap(ExecuteReportDTO::getId, Function.identity())); historyDeletedMap = historyDeletedList.stream().collect(Collectors.toMap(ExecuteReportDTO::getId, Function.identity()));
} }
processTaskCenter(list, projectList, projectIds, historyDeletedMap);
}
return list; // 准备参数
}
private void processTaskCenter(List<TaskCenterDTO> list, List<OptionDTO> projectList, List<String> projectIds, Map<String, ExecuteReportDTO> historyDeletedMap) {
if (!list.isEmpty()) {
// 取所有的userid
Set<String> userSet = list.stream() Set<String> userSet = list.stream()
.flatMap(item -> Stream.of(item.getOperationName())) .flatMap(item -> Stream.of(item.getOperationName()))
.collect(Collectors.toSet()); .collect(Collectors.toSet());
@ -156,12 +158,22 @@ public class TestPlanTaskCenterService {
// 组织 // 组织
List<OptionDTO> orgListByProjectList = getOrgListByProjectIds(projectIds); List<OptionDTO> orgListByProjectList = getOrgListByProjectIds(projectIds);
Map<String, String> orgMap = orgListByProjectList.stream().collect(Collectors.toMap(OptionDTO::getId, OptionDTO::getName)); Map<String, String> orgMap = orgListByProjectList.stream().collect(Collectors.toMap(OptionDTO::getId, OptionDTO::getName));
processTaskCenter(list, userMap, projectMap, orgMap, historyDeletedMap);
}
return list;
}
private void processTaskCenter(List<TaskCenterDTO> list, Map<String, String> userMap, Map<String, String> projectMap, Map<String, String> orgMap, Map<String, ExecuteReportDTO> historyDeletedMap) {
if (!list.isEmpty()) {
list.forEach(item -> { list.forEach(item -> {
item.setOperationName(userMap.getOrDefault(item.getOperationName(), StringUtils.EMPTY)); item.setOperationName(userMap.getOrDefault(item.getOperationName(), StringUtils.EMPTY));
item.setProjectName(projectMap.getOrDefault(item.getProjectId(), StringUtils.EMPTY)); item.setProjectName(projectMap.getOrDefault(item.getProjectId(), StringUtils.EMPTY));
item.setOrganizationName(orgMap.getOrDefault(item.getProjectId(), StringUtils.EMPTY)); item.setOrganizationName(orgMap.getOrDefault(item.getProjectId(), StringUtils.EMPTY));
item.setHistoryDeleted(MapUtils.isNotEmpty(historyDeletedMap) && !historyDeletedMap.containsKey(item.getId())); item.setHistoryDeleted(MapUtils.isNotEmpty(historyDeletedMap) && !historyDeletedMap.containsKey(item.getId()));
if (CollectionUtils.isNotEmpty(item.getChildren())) {
processTaskCenter(item.getChildren(), userMap, projectMap, orgMap, historyDeletedMap);
}
}); });
} }
} }

View File

@ -10,8 +10,6 @@ import io.metersphere.plan.domain.TestPlanReportApiCase;
import io.metersphere.plan.domain.TestPlanReportApiScenario; import io.metersphere.plan.domain.TestPlanReportApiScenario;
import io.metersphere.plan.mapper.TestPlanReportApiCaseMapper; import io.metersphere.plan.mapper.TestPlanReportApiCaseMapper;
import io.metersphere.plan.mapper.TestPlanReportApiScenarioMapper; import io.metersphere.plan.mapper.TestPlanReportApiScenarioMapper;
import io.metersphere.project.mapper.ProjectApplicationMapper;
import io.metersphere.project.mapper.ProjectTestResourcePoolMapper;
import io.metersphere.sdk.constants.ExecStatus; import io.metersphere.sdk.constants.ExecStatus;
import io.metersphere.sdk.constants.SessionConstants; import io.metersphere.sdk.constants.SessionConstants;
import io.metersphere.sdk.constants.TaskCenterResourceType; import io.metersphere.sdk.constants.TaskCenterResourceType;
@ -23,8 +21,6 @@ import io.metersphere.system.dto.sdk.BaseCondition;
import io.metersphere.system.dto.table.TableBatchProcessDTO; import io.metersphere.system.dto.table.TableBatchProcessDTO;
import io.metersphere.system.dto.taskcenter.request.TaskCenterBatchRequest; import io.metersphere.system.dto.taskcenter.request.TaskCenterBatchRequest;
import io.metersphere.system.dto.taskcenter.request.TaskCenterPageRequest; import io.metersphere.system.dto.taskcenter.request.TaskCenterPageRequest;
import io.metersphere.system.mapper.TestResourcePoolBlobMapper;
import io.metersphere.system.mapper.TestResourcePoolMapper;
import io.metersphere.system.utils.Pager; import io.metersphere.system.utils.Pager;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.junit.jupiter.api.*; import org.junit.jupiter.api.*;
@ -68,14 +64,6 @@ public class TestPlanTaskCenterControllerTests extends BaseTest {
@Resource @Resource
private ApiScenarioReportService apiScenarioReportService; private ApiScenarioReportService apiScenarioReportService;
@Resource @Resource
private TestResourcePoolMapper testResourcePoolMapper;
@Resource
private TestResourcePoolBlobMapper testResourcePoolBlobMapper;
@Resource
private ProjectTestResourcePoolMapper projectTestResourcePoolMapper;
@Resource
private ProjectApplicationMapper projectApplicationMapper;
@Resource
private TestPlanReportApiCaseMapper testPlanReportApiCaseMapper; private TestPlanReportApiCaseMapper testPlanReportApiCaseMapper;
@Resource @Resource
private TestPlanReportApiScenarioMapper testPlanReportApiScenarioMapper; private TestPlanReportApiScenarioMapper testPlanReportApiScenarioMapper;

View File

@ -9,6 +9,8 @@ VALUES
('test-plan-report-id-3', 'test_plan_id_1', '测试一下计划报告3', 'admin', UNIX_TIMESTAMP()*1000, UNIX_TIMESTAMP()*1000, UNIX_TIMESTAMP()*1000, 'MANUAL', 'RUNNING', '-', '99.99', 100.00, '100001100001',1, 0, null, '测试一下计划'), ('test-plan-report-id-3', 'test_plan_id_1', '测试一下计划报告3', 'admin', UNIX_TIMESTAMP()*1000, UNIX_TIMESTAMP()*1000, UNIX_TIMESTAMP()*1000, 'MANUAL', 'RUNNING', '-', '99.99', 100.00, '100001100001',1, 0, null, '测试一下计划'),
('test-plan-report-id-4', 'test_plan_id_1', '测试一下计划报告4', 'admin', UNIX_TIMESTAMP()*1000, UNIX_TIMESTAMP()*1000, UNIX_TIMESTAMP()*1000, 'MANUAL', 'RUNNING', '-', '99.99', 100.00, '100001100001', 1, 0, null, '测试一下计划'), ('test-plan-report-id-4', 'test_plan_id_1', '测试一下计划报告4', 'admin', UNIX_TIMESTAMP()*1000, UNIX_TIMESTAMP()*1000, UNIX_TIMESTAMP()*1000, 'MANUAL', 'RUNNING', '-', '99.99', 100.00, '100001100001', 1, 0, null, '测试一下计划'),
('test-plan-report-id-1-1', 'test_plan_id_1', '测试一下计划报告1-1', 'admin', UNIX_TIMESTAMP()*1000, UNIX_TIMESTAMP()*1000, UNIX_TIMESTAMP()*1000, 'MANUAL', 'RUNNING', '-', '99.99', 100.00, '100001100001', 1, 0, 'test-plan-report-id-1', '测试一下计划'), ('test-plan-report-id-1-1', 'test_plan_id_1', '测试一下计划报告1-1', 'admin', UNIX_TIMESTAMP()*1000, UNIX_TIMESTAMP()*1000, UNIX_TIMESTAMP()*1000, 'MANUAL', 'RUNNING', '-', '99.99', 100.00, '100001100001', 1, 0, 'test-plan-report-id-1', '测试一下计划'),
('test-plan-report-id-1-2', 'test_plan_id_1', '测试一下计划报告1-2', 'admin', UNIX_TIMESTAMP()*1000, UNIX_TIMESTAMP()*1000, UNIX_TIMESTAMP()*1000, 'MANUAL', 'RUNNING', '-', '99.99', 100.00, '100001100001', 1, 0, 'test-plan-report-id-1', '测试一下计划'); ('test-plan-report-id-1-2', 'test_plan_id_1', '测试一下计划报告1-2', 'admin', UNIX_TIMESTAMP()*1000, UNIX_TIMESTAMP()*1000, UNIX_TIMESTAMP()*1000, 'MANUAL', 'RUNNING', '-', '99.99', 100.00, '100001100001', 1, 0, 'test-plan-report-id-1-2', '测试一下计划'),
('test-plan-report-id-1-3', 'test_plan_id_1', '测试一下计划报告1-3', 'admin', UNIX_TIMESTAMP()*1000, UNIX_TIMESTAMP()*1000, UNIX_TIMESTAMP()*1000, 'MANUAL', 'RUNNING', '-', '99.99', 100.00, '100001100001', 0, 0, 'test-plan-report-id-1-2', '测试一下计划'),
('test-plan-report-id-1-4', 'test_plan_id_1', '测试一下计划报告1-4', 'admin', UNIX_TIMESTAMP()*1000, UNIX_TIMESTAMP()*1000, UNIX_TIMESTAMP()*1000, 'MANUAL', 'RUNNING', '-', '99.99', 100.00, '100001100001', 1, 0, 'test-plan-report-id-1-4', '测试一下计划');