refactor(测试计划): 优化测试计划报告的生成逻辑
This commit is contained in:
parent
9ff8f971c6
commit
40445cb4c5
|
@ -1,28 +1,22 @@
|
||||||
package io.metersphere.plan.dto;
|
package io.metersphere.plan.dto;
|
||||||
|
|
||||||
import io.metersphere.plan.domain.TestPlanReportApiCase;
|
|
||||||
import io.metersphere.plan.domain.TestPlanReportApiScenario;
|
|
||||||
import io.metersphere.plan.domain.TestPlanReportBug;
|
|
||||||
import io.metersphere.plan.domain.TestPlanReportFunctionCase;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@Builder
|
@Builder
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
public class TestPlanReportDetailCaseDTO {
|
public class TestPlanReportDetailCaseDTO {
|
||||||
|
|
||||||
private List<TestPlanReportFunctionCase> functionCases;
|
private long functionCaseCount;
|
||||||
|
|
||||||
private List<TestPlanReportApiCase> apiCases;
|
private long apiCaseCount;
|
||||||
|
|
||||||
private List<TestPlanReportApiScenario> apiScenarios;
|
private long apiScenarioCount;
|
||||||
|
|
||||||
private List<TestPlanReportBug> bugs;
|
private long bugCount;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,9 @@ public interface ExtTestPlanReportApiCaseMapper {
|
||||||
* @param planId 计划ID
|
* @param planId 计划ID
|
||||||
* @return 接口用例列表
|
* @return 接口用例列表
|
||||||
*/
|
*/
|
||||||
List<TestPlanReportApiCase> getPlanExecuteCases(@Param("id") String planId);
|
List<TestPlanReportApiCase> getPlanExecuteCases(@Param("id") String planId, @Param("ids") List<String> ids);
|
||||||
|
|
||||||
|
List<String> getPlanExecuteCasesId(@Param("id") String planId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取项目下接口用例所属模块集合
|
* 获取项目下接口用例所属模块集合
|
||||||
|
|
|
@ -16,6 +16,10 @@
|
||||||
left join api_definition ad on atc.api_definition_id = ad.id
|
left join api_definition ad on atc.api_definition_id = ad.id
|
||||||
left join api_definition_module adm on ad.module_id = adm.id
|
left join api_definition_module adm on ad.module_id = adm.id
|
||||||
where tpac.test_plan_id = #{id} and atc.deleted = false
|
where tpac.test_plan_id = #{id} and atc.deleted = false
|
||||||
|
and tpac.id in
|
||||||
|
<foreach collection="ids" item="id" open="(" close=")" separator=",">
|
||||||
|
#{id}
|
||||||
|
</foreach>
|
||||||
group by tpac.id
|
group by tpac.id
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
@ -42,6 +46,14 @@
|
||||||
where test_plan_report_id = #{testPlanReportId} and test_plan_collection_id = #{collectionId}
|
where test_plan_report_id = #{testPlanReportId} and test_plan_collection_id = #{collectionId}
|
||||||
order by pos desc
|
order by pos desc
|
||||||
</select>
|
</select>
|
||||||
|
<select id="getPlanExecuteCasesId" resultType="java.lang.String">
|
||||||
|
select tpac.id
|
||||||
|
from test_plan_api_case tpac
|
||||||
|
inner join api_test_case atc on atc.id = tpac.api_case_id
|
||||||
|
where tpac.test_plan_id = #{id}
|
||||||
|
and atc.deleted = false
|
||||||
|
order by tpac.pos desc
|
||||||
|
</select>
|
||||||
|
|
||||||
<sql id="filter">
|
<sql id="filter">
|
||||||
<if test="request.filter != null and request.filter.size() > 0">
|
<if test="request.filter != null and request.filter.size() > 0">
|
||||||
|
|
|
@ -23,7 +23,10 @@ public interface ExtTestPlanReportApiScenarioMapper {
|
||||||
* @param planId 计划ID
|
* @param planId 计划ID
|
||||||
* @return 场景用例列表
|
* @return 场景用例列表
|
||||||
*/
|
*/
|
||||||
List<TestPlanReportApiScenario> getPlanExecuteCases(@Param("id") String planId);
|
List<TestPlanReportApiScenario> getPlanExecuteCases(@Param("id") String planId, @Param("ids") List<String> ids);
|
||||||
|
|
||||||
|
|
||||||
|
List<String> getPlanExecuteCasesId(@Param("id") String planId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取项目下场景用例所属模块集合
|
* 获取项目下场景用例所属模块集合
|
||||||
|
|
|
@ -15,6 +15,10 @@
|
||||||
from test_plan_api_scenario tpas join api_scenario aso on aso.id = tpas.api_scenario_id
|
from test_plan_api_scenario tpas join api_scenario aso on aso.id = tpas.api_scenario_id
|
||||||
left join api_scenario_module asm on aso.module_id = asm.id
|
left join api_scenario_module asm on aso.module_id = asm.id
|
||||||
where tpas.test_plan_id = #{id} and aso.deleted = false
|
where tpas.test_plan_id = #{id} and aso.deleted = false
|
||||||
|
and tpas.id in
|
||||||
|
<foreach collection="ids" item="id" open="(" separator="," close=")">
|
||||||
|
#{id}
|
||||||
|
</foreach>
|
||||||
group by tpas.id
|
group by tpas.id
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
@ -35,6 +39,14 @@
|
||||||
where tpras.test_plan_report_id = #{request.reportId}
|
where tpras.test_plan_report_id = #{request.reportId}
|
||||||
<include refid="filter"/>
|
<include refid="filter"/>
|
||||||
</select>
|
</select>
|
||||||
|
<select id="getPlanExecuteCasesId" resultType="java.lang.String">
|
||||||
|
select tpas.id
|
||||||
|
from test_plan_api_scenario tpas
|
||||||
|
inner join api_scenario aso on aso.id = tpas.api_scenario_id
|
||||||
|
where tpas.test_plan_id = #{id}
|
||||||
|
and aso.deleted = false
|
||||||
|
order by tpas.pos desc
|
||||||
|
</select>
|
||||||
|
|
||||||
<sql id="filter">
|
<sql id="filter">
|
||||||
<if test="request.filter != null and request.filter.size() > 0">
|
<if test="request.filter != null and request.filter.size() > 0">
|
||||||
|
|
|
@ -16,7 +16,9 @@ public interface ExtTestPlanReportBugMapper {
|
||||||
* @param planId 计划ID
|
* @param planId 计划ID
|
||||||
* @return 缺陷集合
|
* @return 缺陷集合
|
||||||
*/
|
*/
|
||||||
List<TestPlanReportBug> getPlanBugs(@Param("id") String planId);
|
List<TestPlanReportBug> getPlanBugs(@Param("id") String planId, @Param("ids") List<String> ids);
|
||||||
|
|
||||||
|
List<String> getPlanBugsId(@Param("id") String planId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分页查询报告关联的缺陷
|
* 分页查询报告关联的缺陷
|
||||||
|
|
|
@ -7,9 +7,21 @@
|
||||||
b.handle_user bugHandleUser, count(brc.id) bugCaseCount
|
b.handle_user bugHandleUser, count(brc.id) bugCaseCount
|
||||||
from bug_relation_case brc join bug b on brc.bug_id = b.id
|
from bug_relation_case brc join bug b on brc.bug_id = b.id
|
||||||
where brc.test_plan_id = #{id} and b.deleted = false
|
where brc.test_plan_id = #{id} and b.deleted = false
|
||||||
|
and brc.id in
|
||||||
|
<foreach collection="ids" item="bugId" open="(" close=")" separator=",">
|
||||||
|
#{bugId}
|
||||||
|
</foreach>
|
||||||
group by brc.bug_id
|
group by brc.bug_id
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="getPlanBugsId" resultType="java.lang.String">
|
||||||
|
select brc.id
|
||||||
|
from bug_relation_case brc
|
||||||
|
join bug b on brc.bug_id = b.id
|
||||||
|
where brc.test_plan_id = #{id}
|
||||||
|
and b.deleted = false
|
||||||
|
</select>
|
||||||
|
|
||||||
<select id="list" resultType="io.metersphere.bug.dto.response.BugDTO">
|
<select id="list" resultType="io.metersphere.bug.dto.response.BugDTO">
|
||||||
select distinct tprb.bug_id as id, tprb.bug_num as num, tprb.bug_title as title, tprb.bug_status as status, tprb.bug_handle_user as handleUserName,
|
select distinct tprb.bug_id as id, tprb.bug_num as num, tprb.bug_title as title, tprb.bug_status as status, tprb.bug_handle_user as handleUserName,
|
||||||
ifnull(tprb.bug_case_count, 0) as relationCaseCount
|
ifnull(tprb.bug_case_count, 0) as relationCaseCount
|
||||||
|
|
|
@ -17,7 +17,7 @@ public interface ExtTestPlanReportFunctionalCaseMapper {
|
||||||
* @param planId 计划ID
|
* @param planId 计划ID
|
||||||
* @return 功能用例列表
|
* @return 功能用例列表
|
||||||
*/
|
*/
|
||||||
List<TestPlanReportFunctionCase> getPlanExecuteCases(@Param("id") String planId);
|
List<TestPlanReportFunctionCase> getPlanExecuteCases(@Param("id") String planId, @Param("ids") List<String> ids);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取项目下功能用例所属模块集合
|
* 获取项目下功能用例所属模块集合
|
||||||
|
@ -53,4 +53,6 @@ public interface ExtTestPlanReportFunctionalCaseMapper {
|
||||||
* @return 关联的用例集合
|
* @return 关联的用例集合
|
||||||
*/
|
*/
|
||||||
List<ReportDetailCasePageDTO> list(@Param("request") TestPlanReportDetailPageRequest request);
|
List<ReportDetailCasePageDTO> list(@Param("request") TestPlanReportDetailPageRequest request);
|
||||||
|
|
||||||
|
List<String> getPlanExecuteCasesId(@Param("id") String testPlanId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,10 @@
|
||||||
from test_plan_functional_case tpfc join functional_case fc on tpfc.functional_case_id = fc.id
|
from test_plan_functional_case tpfc join functional_case fc on tpfc.functional_case_id = fc.id
|
||||||
left join functional_case_module fcm on fcm.id = fc.module_id
|
left join functional_case_module fcm on fcm.id = fc.module_id
|
||||||
where tpfc.test_plan_id = #{id} and fc.deleted = false
|
where tpfc.test_plan_id = #{id} and fc.deleted = false
|
||||||
|
and tpfc.id in
|
||||||
|
<foreach collection="ids" item="id" open="(" separator="," close=")">
|
||||||
|
#{id}
|
||||||
|
</foreach>
|
||||||
group by tpfc.id
|
group by tpfc.id
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
@ -56,6 +60,14 @@
|
||||||
where tprfc.test_plan_report_id = #{request.reportId}
|
where tprfc.test_plan_report_id = #{request.reportId}
|
||||||
<include refid="filter"/>
|
<include refid="filter"/>
|
||||||
</select>
|
</select>
|
||||||
|
<select id="getPlanExecuteCasesId" resultType="java.lang.String">
|
||||||
|
select tpfc.id
|
||||||
|
from test_plan_functional_case tpfc
|
||||||
|
inner join functional_case fc on tpfc.functional_case_id = fc.id
|
||||||
|
where tpfc.test_plan_id = #{id}
|
||||||
|
and fc.deleted = false
|
||||||
|
order by tpfc.pos
|
||||||
|
</select>
|
||||||
|
|
||||||
<sql id="filter">
|
<sql id="filter">
|
||||||
<if test="request.filter != null and request.filter.size() > 0">
|
<if test="request.filter != null and request.filter.size() > 0">
|
||||||
|
|
|
@ -114,7 +114,6 @@ public class PlanRunTestPlanApiCaseService {
|
||||||
String testPlanId = collection.getTestPlanId();
|
String testPlanId = collection.getTestPlanId();
|
||||||
|
|
||||||
List<TestPlanReportApiCase> testPlanReportApiCases = getTestPlanReportApiCases(testPlanReportId, collection);
|
List<TestPlanReportApiCase> testPlanReportApiCases = getTestPlanReportApiCases(testPlanReportId, collection);
|
||||||
testPlanReportApiCases.stream().sorted(Comparator.comparing(TestPlanReportApiCase::getPos));
|
|
||||||
if (CollectionUtils.isEmpty(testPlanReportApiCases)) {
|
if (CollectionUtils.isEmpty(testPlanReportApiCases)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -172,6 +171,7 @@ public class PlanRunTestPlanApiCaseService {
|
||||||
example.createCriteria()
|
example.createCriteria()
|
||||||
.andTestPlanReportIdEqualTo(testPlanReportId)
|
.andTestPlanReportIdEqualTo(testPlanReportId)
|
||||||
.andTestPlanCollectionIdEqualTo(collection.getId());
|
.andTestPlanCollectionIdEqualTo(collection.getId());
|
||||||
|
example.setOrderByClause(" pos asc");
|
||||||
return testPlanReportApiCaseMapper.selectByExample(example);
|
return testPlanReportApiCaseMapper.selectByExample(example);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -106,31 +106,26 @@ public class PlanRunTestPlanApiScenarioService {
|
||||||
String userId = testPlanExecutionQueue.getCreateUser();
|
String userId = testPlanExecutionQueue.getCreateUser();
|
||||||
TestPlanCollection collection = JSON.parseObject(testPlanExecutionQueue.getTestPlanCollectionJson(), TestPlanCollection.class);
|
TestPlanCollection collection = JSON.parseObject(testPlanExecutionQueue.getTestPlanCollectionJson(), TestPlanCollection.class);
|
||||||
String testPlanId = collection.getTestPlanId();
|
String testPlanId = collection.getTestPlanId();
|
||||||
|
|
||||||
List<TestPlanReportApiScenario> testPlanReportApiScenarios = getTestPlanReportApiScenarios(testPlanReportId, collection);
|
|
||||||
testPlanReportApiScenarios.stream().sorted(Comparator.comparing(TestPlanReportApiScenario::getPos));
|
|
||||||
if (CollectionUtils.isEmpty(testPlanReportApiScenarios)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
ApiRunModeConfigDTO runModeConfig = testPlanApiBatchRunBaseService.getApiRunModeConfig(collection);
|
|
||||||
|
|
||||||
Map<String, String> scenarioReportMap = initReport(testPlanReportApiScenarios, runModeConfig, userId);
|
|
||||||
|
|
||||||
List<TaskItem> taskItems = testPlanReportApiScenarios.stream()
|
|
||||||
.map(item -> apiExecuteService.getTaskItem(scenarioReportMap.get(item.getId()), item.getId())).toList();
|
|
||||||
|
|
||||||
TestPlan testPlan = testPlanMapper.selectByPrimaryKey(testPlanId);
|
TestPlan testPlan = testPlanMapper.selectByPrimaryKey(testPlanId);
|
||||||
|
ApiRunModeConfigDTO runModeConfig = testPlanApiBatchRunBaseService.getApiRunModeConfig(collection);
|
||||||
TaskBatchRequestDTO taskRequest = testPlanApiScenarioBatchRunService.getTaskBatchRequestDTO(testPlan.getProjectId(), runModeConfig);
|
TaskBatchRequestDTO taskRequest = testPlanApiScenarioBatchRunService.getTaskBatchRequestDTO(testPlan.getProjectId(), runModeConfig);
|
||||||
taskRequest.setTaskItems(taskItems);
|
|
||||||
taskRequest.getTaskInfo().setParentQueueId(parentQueueId);
|
taskRequest.getTaskInfo().setParentQueueId(parentQueueId);
|
||||||
taskRequest.getTaskInfo().setUserId(userId);
|
taskRequest.getTaskInfo().setUserId(userId);
|
||||||
taskRequest.getTaskInfo().setResourceType(ApiExecuteResourceType.PLAN_RUN_API_SCENARIO.name());
|
taskRequest.getTaskInfo().setResourceType(ApiExecuteResourceType.PLAN_RUN_API_SCENARIO.name());
|
||||||
|
|
||||||
|
List<TestPlanReportApiScenario> testPlanReportApiScenarios = getTestPlanReportApiScenarios(testPlanReportId, collection);
|
||||||
|
if (CollectionUtils.isEmpty(testPlanReportApiScenarios)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, String> scenarioReportMap = initReport(testPlanReportApiScenarios, runModeConfig, userId);
|
||||||
|
List<TaskItem> taskItems = testPlanReportApiScenarios.stream()
|
||||||
|
.map(item -> apiExecuteService.getTaskItem(scenarioReportMap.get(item.getId()), item.getId())).toList();
|
||||||
// 如果有父队列,则初始化执行集合,以便判断是否执行完毕
|
// 如果有父队列,则初始化执行集合,以便判断是否执行完毕
|
||||||
apiExecutionSetService.initSet(parentQueueId, testPlanReportApiScenarios.stream().map(TestPlanReportApiScenario::getId).toList());
|
apiExecutionSetService.initSet(parentQueueId, testPlanReportApiScenarios.stream().map(TestPlanReportApiScenario::getId).toList());
|
||||||
|
taskRequest.setTaskItems(taskItems);
|
||||||
apiExecuteService.batchExecute(taskRequest);
|
apiExecuteService.batchExecute(taskRequest);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -182,9 +177,11 @@ public class PlanRunTestPlanApiScenarioService {
|
||||||
example.createCriteria()
|
example.createCriteria()
|
||||||
.andTestPlanReportIdEqualTo(testPlanReportId)
|
.andTestPlanReportIdEqualTo(testPlanReportId)
|
||||||
.andTestPlanCollectionIdEqualTo(collection.getId());
|
.andTestPlanCollectionIdEqualTo(collection.getId());
|
||||||
|
example.setOrderByClause(" pos asc");
|
||||||
return testPlanReportApiScenarioMapper.selectByExample(example);
|
return testPlanReportApiScenarioMapper.selectByExample(example);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 执行串行的下一个任务
|
* 执行串行的下一个任务
|
||||||
*
|
*
|
||||||
|
|
|
@ -48,6 +48,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
|
@ -410,10 +411,10 @@ public class TestPlanReportService {
|
||||||
TestPlanReportSummary reportSummary = new TestPlanReportSummary();
|
TestPlanReportSummary reportSummary = new TestPlanReportSummary();
|
||||||
reportSummary.setId(IDGenerator.nextStr());
|
reportSummary.setId(IDGenerator.nextStr());
|
||||||
reportSummary.setTestPlanReportId(report.getId());
|
reportSummary.setTestPlanReportId(report.getId());
|
||||||
reportSummary.setFunctionalCaseCount((long) (CollectionUtils.isEmpty(reportCaseDetail.getFunctionCases()) ? 0 : reportCaseDetail.getFunctionCases().size()));
|
reportSummary.setFunctionalCaseCount(reportCaseDetail.getFunctionCaseCount());
|
||||||
reportSummary.setApiCaseCount((long) (CollectionUtils.isEmpty(reportCaseDetail.getApiCases()) ? 0 : reportCaseDetail.getApiCases().size()));
|
reportSummary.setApiCaseCount(reportCaseDetail.getApiCaseCount());
|
||||||
reportSummary.setApiScenarioCount((long) (CollectionUtils.isEmpty(reportCaseDetail.getApiScenarios()) ? 0 : reportCaseDetail.getApiScenarios().size()));
|
reportSummary.setApiScenarioCount(reportCaseDetail.getApiScenarioCount());
|
||||||
reportSummary.setBugCount((long) (CollectionUtils.isEmpty(reportCaseDetail.getBugs()) ? 0 : reportCaseDetail.getBugs().size()));
|
reportSummary.setBugCount(reportCaseDetail.getBugCount());
|
||||||
reportSummary.setPlanCount(genParam.getIntegrated() ? (long) childPlanIds.size() : 0);
|
reportSummary.setPlanCount(genParam.getIntegrated() ? (long) childPlanIds.size() : 0);
|
||||||
testPlanReportSummaryMapper.insertSelective(reportSummary);
|
testPlanReportSummaryMapper.insertSelective(reportSummary);
|
||||||
|
|
||||||
|
@ -433,130 +434,178 @@ public class TestPlanReportService {
|
||||||
// 缺陷数
|
// 缺陷数
|
||||||
List<ReportBugCountDTO> bugCountList = extTestPlanReportBugMapper.countPlanBug(genParam.getTestPlanId());
|
List<ReportBugCountDTO> bugCountList = extTestPlanReportBugMapper.countPlanBug(genParam.getTestPlanId());
|
||||||
Map<String, Long> bugCountMap = bugCountList.stream().collect(Collectors.toMap(ReportBugCountDTO::getRefCaseId, ReportBugCountDTO::getBugCount));
|
Map<String, Long> bugCountMap = bugCountList.stream().collect(Collectors.toMap(ReportBugCountDTO::getRefCaseId, ReportBugCountDTO::getBugCount));
|
||||||
|
|
||||||
|
AtomicLong funcCaseCount = new AtomicLong();
|
||||||
|
AtomicLong apiCaseCount = new AtomicLong();
|
||||||
|
AtomicLong apiScenarioCount = new AtomicLong();
|
||||||
|
AtomicLong bugCount = new AtomicLong();
|
||||||
// 功能用例
|
// 功能用例
|
||||||
List<TestPlanReportFunctionCase> reportFunctionCases = extTestPlanReportFunctionalCaseMapper.getPlanExecuteCases(genParam.getTestPlanId());
|
{
|
||||||
if (CollectionUtils.isNotEmpty(reportFunctionCases)) {
|
List<String> funcCaseIdList = extTestPlanReportFunctionalCaseMapper.getPlanExecuteCasesId(genParam.getTestPlanId());
|
||||||
// 用例等级
|
if (CollectionUtils.isNotEmpty(funcCaseIdList)) {
|
||||||
List<String> ids = reportFunctionCases.stream().map(TestPlanReportFunctionCase::getFunctionCaseId).distinct().toList();
|
SubListUtils.dealForSubList(funcCaseIdList, 200, (subList) -> {
|
||||||
List<SelectOption> options = extTestPlanReportFunctionalCaseMapper.getCasePriorityByIds(ids);
|
if (CollectionUtils.isEmpty(subList)) {
|
||||||
Map<String, String> casePriorityMap = options.stream().collect(Collectors.toMap(SelectOption::getValue, SelectOption::getText));
|
return;
|
||||||
// 用例模块
|
}
|
||||||
List<String> moduleIds = reportFunctionCases.stream().map(TestPlanReportFunctionCase::getFunctionCaseModule).filter(Objects::nonNull).toList();
|
List<TestPlanReportFunctionCase> reportFunctionCases = extTestPlanReportFunctionalCaseMapper.getPlanExecuteCases(genParam.getTestPlanId(), subList);
|
||||||
Map<String, String> moduleMap = getModuleMapByIds(moduleIds, CaseType.FUNCTIONAL_CASE.getKey());
|
funcCaseCount.addAndGet(reportFunctionCases.size());
|
||||||
// 关联的功能用例最新一次执行历史
|
// 用例等级
|
||||||
List<String> relateIds = reportFunctionCases.stream().map(TestPlanReportFunctionCase::getTestPlanFunctionCaseId).toList();
|
List<String> ids = reportFunctionCases.stream().map(TestPlanReportFunctionCase::getFunctionCaseId).distinct().toList();
|
||||||
TestPlanCaseExecuteHistoryExample example = new TestPlanCaseExecuteHistoryExample();
|
List<SelectOption> options = extTestPlanReportFunctionalCaseMapper.getCasePriorityByIds(ids);
|
||||||
example.createCriteria().andTestPlanCaseIdIn(relateIds);
|
Map<String, String> casePriorityMap = options.stream().collect(Collectors.toMap(SelectOption::getValue, SelectOption::getText));
|
||||||
List<TestPlanCaseExecuteHistory> functionalExecHisList = testPlanCaseExecuteHistoryMapper.selectByExample(example);
|
// 用例模块
|
||||||
Map<String, List<TestPlanCaseExecuteHistory>> functionalExecMap = functionalExecHisList.stream().collect(Collectors.groupingBy(TestPlanCaseExecuteHistory::getTestPlanCaseId));
|
List<String> moduleIds = reportFunctionCases.stream().map(TestPlanReportFunctionCase::getFunctionCaseModule).filter(Objects::nonNull).toList();
|
||||||
|
Map<String, String> moduleMap = getModuleMapByIds(moduleIds, CaseType.FUNCTIONAL_CASE.getKey());
|
||||||
|
// 关联的功能用例最新一次执行历史
|
||||||
|
List<String> relateIds = reportFunctionCases.stream().map(TestPlanReportFunctionCase::getTestPlanFunctionCaseId).toList();
|
||||||
|
TestPlanCaseExecuteHistoryExample example = new TestPlanCaseExecuteHistoryExample();
|
||||||
|
example.createCriteria().andTestPlanCaseIdIn(relateIds);
|
||||||
|
List<TestPlanCaseExecuteHistory> functionalExecHisList = testPlanCaseExecuteHistoryMapper.selectByExample(example);
|
||||||
|
Map<String, List<TestPlanCaseExecuteHistory>> functionalExecMap = functionalExecHisList.stream().collect(Collectors.groupingBy(TestPlanCaseExecuteHistory::getTestPlanCaseId));
|
||||||
|
|
||||||
for (TestPlanReportFunctionCase reportFunctionalCase : reportFunctionCases) {
|
for (TestPlanReportFunctionCase reportFunctionalCase : reportFunctionCases) {
|
||||||
reportFunctionalCase.setId(IDGenerator.nextStr());
|
reportFunctionalCase.setId(IDGenerator.nextStr());
|
||||||
reportFunctionalCase.setTestPlanReportId(report.getId());
|
reportFunctionalCase.setTestPlanReportId(report.getId());
|
||||||
reportFunctionalCase.setTestPlanName(genParam.getTestPlanName());
|
reportFunctionalCase.setTestPlanName(genParam.getTestPlanName());
|
||||||
if (reportFunctionalCase.getFunctionCaseModule() != null) {
|
if (reportFunctionalCase.getFunctionCaseModule() != null) {
|
||||||
reportFunctionalCase.setFunctionCaseModule(moduleMap.getOrDefault(reportFunctionalCase.getFunctionCaseModule(), reportFunctionalCase.getFunctionCaseModule()));
|
reportFunctionalCase.setFunctionCaseModule(moduleMap.getOrDefault(reportFunctionalCase.getFunctionCaseModule(), reportFunctionalCase.getFunctionCaseModule()));
|
||||||
}
|
}
|
||||||
reportFunctionalCase.setFunctionCasePriority(casePriorityMap.get(reportFunctionalCase.getFunctionCaseId()));
|
reportFunctionalCase.setFunctionCasePriority(casePriorityMap.get(reportFunctionalCase.getFunctionCaseId()));
|
||||||
List<TestPlanCaseExecuteHistory> hisList = functionalExecMap.get(reportFunctionalCase.getTestPlanFunctionCaseId());
|
List<TestPlanCaseExecuteHistory> hisList = functionalExecMap.get(reportFunctionalCase.getTestPlanFunctionCaseId());
|
||||||
if (CollectionUtils.isNotEmpty(hisList)) {
|
if (CollectionUtils.isNotEmpty(hisList)) {
|
||||||
Optional<String> lastExecuteHisOpt = hisList.stream().sorted(Comparator.comparing(TestPlanCaseExecuteHistory::getCreateTime).reversed()).map(TestPlanCaseExecuteHistory::getId).findFirst();
|
Optional<String> lastExecuteHisOpt = hisList.stream().sorted(Comparator.comparing(TestPlanCaseExecuteHistory::getCreateTime).reversed()).map(TestPlanCaseExecuteHistory::getId).findFirst();
|
||||||
reportFunctionalCase.setFunctionCaseExecuteReportId(lastExecuteHisOpt.orElse(null));
|
reportFunctionalCase.setFunctionCaseExecuteReportId(lastExecuteHisOpt.orElse(null));
|
||||||
} else {
|
} else {
|
||||||
reportFunctionalCase.setFunctionCaseExecuteReportId(null);
|
reportFunctionalCase.setFunctionCaseExecuteReportId(null);
|
||||||
}
|
}
|
||||||
reportFunctionalCase.setFunctionCaseBugCount(bugCountMap.containsKey(reportFunctionalCase.getTestPlanFunctionCaseId()) ? bugCountMap.get(reportFunctionalCase.getTestPlanFunctionCaseId()) : 0);
|
reportFunctionalCase.setFunctionCaseBugCount(bugCountMap.containsKey(reportFunctionalCase.getTestPlanFunctionCaseId()) ? bugCountMap.get(reportFunctionalCase.getTestPlanFunctionCaseId()) : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 插入计划功能用例关联数据 -> 报告内容
|
||||||
|
TestPlanReportFunctionCaseMapper batchMapper = sqlSession.getMapper(TestPlanReportFunctionCaseMapper.class);
|
||||||
|
batchMapper.batchInsert(reportFunctionCases);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
funcCaseIdList = null;
|
||||||
// 插入计划功能用例关联数据 -> 报告内容
|
|
||||||
TestPlanReportFunctionCaseMapper batchMapper = sqlSession.getMapper(TestPlanReportFunctionCaseMapper.class);
|
|
||||||
batchMapper.batchInsert(reportFunctionCases);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 接口用例
|
// 接口用例
|
||||||
List<TestPlanReportApiCase> reportApiCases = extTestPlanReportApiCaseMapper.getPlanExecuteCases(genParam.getTestPlanId());
|
{
|
||||||
if (CollectionUtils.isNotEmpty(reportApiCases)) {
|
List<String> testPlanReportApiCaseIdList = extTestPlanReportApiCaseMapper.getPlanExecuteCasesId(genParam.getTestPlanId());
|
||||||
// 用例模块
|
if (CollectionUtils.isNotEmpty(testPlanReportApiCaseIdList)) {
|
||||||
List<String> moduleIds = reportApiCases.stream().map(TestPlanReportApiCase::getApiCaseModule).filter(Objects::nonNull).toList();
|
SubListUtils.dealForSubList(testPlanReportApiCaseIdList, 200, (subList) -> {
|
||||||
Map<String, String> moduleMap = getModuleMapByIds(moduleIds, CaseType.API_CASE.getKey());
|
if (CollectionUtils.isEmpty(subList)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<TestPlanReportApiCase> reportApiCases = extTestPlanReportApiCaseMapper.getPlanExecuteCases(genParam.getTestPlanId(), subList);
|
||||||
|
apiCaseCount.addAndGet(reportApiCases.size());
|
||||||
|
List<String> moduleIds = reportApiCases.stream().map(TestPlanReportApiCase::getApiCaseModule).filter(Objects::nonNull).distinct().toList();
|
||||||
|
Map<String, String> moduleMap = getModuleMapByIds(moduleIds, CaseType.API_CASE.getKey());
|
||||||
|
|
||||||
for (TestPlanReportApiCase reportApiCase : reportApiCases) {
|
for (TestPlanReportApiCase reportApiCase : reportApiCases) {
|
||||||
reportApiCase.setId(IDGenerator.nextStr());
|
reportApiCase.setId(IDGenerator.nextStr());
|
||||||
reportApiCase.setTestPlanReportId(report.getId());
|
reportApiCase.setTestPlanReportId(report.getId());
|
||||||
reportApiCase.setTestPlanName(genParam.getTestPlanName());
|
reportApiCase.setTestPlanName(genParam.getTestPlanName());
|
||||||
if (reportApiCase.getApiCaseModule() != null) {
|
if (reportApiCase.getApiCaseModule() != null) {
|
||||||
reportApiCase.setApiCaseModule(moduleMap.getOrDefault(reportApiCase.getApiCaseModule(), reportApiCase.getApiCaseModule()));
|
reportApiCase.setApiCaseModule(moduleMap.getOrDefault(reportApiCase.getApiCaseModule(), reportApiCase.getApiCaseModule()));
|
||||||
}
|
}
|
||||||
// 根据不超过数据库字段最大长度压缩模块名
|
// 根据不超过数据库字段最大长度压缩模块名
|
||||||
reportApiCase.setApiCaseModule(ServiceUtils.compressName(reportApiCase.getApiCaseModule(), 450));
|
reportApiCase.setApiCaseModule(ServiceUtils.compressName(reportApiCase.getApiCaseModule(), 450));
|
||||||
if (!genParam.getUseManual()) {
|
if (!genParam.getUseManual()) {
|
||||||
// 接口执行时才更新结果
|
// 接口执行时才更新结果
|
||||||
reportApiCase.setApiCaseExecuteResult(null);
|
reportApiCase.setApiCaseExecuteResult(null);
|
||||||
reportApiCase.setApiCaseExecuteUser(null);
|
reportApiCase.setApiCaseExecuteUser(null);
|
||||||
reportApiCase.setApiCaseExecuteReportId(IDGenerator.nextStr());
|
reportApiCase.setApiCaseExecuteReportId(IDGenerator.nextStr());
|
||||||
}
|
}
|
||||||
reportApiCase.setApiCaseBugCount(bugCountMap.containsKey(reportApiCase.getTestPlanApiCaseId()) ? bugCountMap.get(reportApiCase.getTestPlanApiCaseId()) : 0);
|
reportApiCase.setApiCaseBugCount(bugCountMap.containsKey(reportApiCase.getTestPlanApiCaseId()) ? bugCountMap.get(reportApiCase.getTestPlanApiCaseId()) : 0);
|
||||||
|
}
|
||||||
|
// 插入计划接口用例关联数据 -> 报告内容
|
||||||
|
TestPlanReportApiCaseMapper batchMapper = sqlSession.getMapper(TestPlanReportApiCaseMapper.class);
|
||||||
|
batchMapper.batchInsert(reportApiCases);
|
||||||
|
sqlSession.flushStatements();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
// 插入计划接口用例关联数据 -> 报告内容
|
testPlanReportApiCaseIdList = null;
|
||||||
TestPlanReportApiCaseMapper batchMapper = sqlSession.getMapper(TestPlanReportApiCaseMapper.class);
|
|
||||||
batchMapper.batchInsert(reportApiCases);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 场景用例
|
// 场景用例
|
||||||
List<TestPlanReportApiScenario> reportApiScenarios = extTestPlanReportApiScenarioMapper.getPlanExecuteCases(genParam.getTestPlanId());
|
{
|
||||||
if (CollectionUtils.isNotEmpty(reportApiScenarios)) {
|
List<String> reportApiScenarioIdList = extTestPlanReportApiScenarioMapper.getPlanExecuteCasesId(genParam.getTestPlanId());
|
||||||
// 用例模块
|
if (CollectionUtils.isNotEmpty(reportApiScenarioIdList)) {
|
||||||
List<String> moduleIds = reportApiScenarios.stream().map(TestPlanReportApiScenario::getApiScenarioModule).filter(Objects::nonNull).toList();
|
SubListUtils.dealForSubList(reportApiScenarioIdList, 200, (subList) -> {
|
||||||
Map<String, String> moduleMap = getModuleMapByIds(moduleIds, CaseType.SCENARIO_CASE.getKey());
|
if (CollectionUtils.isEmpty(subList)) {
|
||||||
|
return;
|
||||||
for (TestPlanReportApiScenario reportApiScenario : reportApiScenarios) {
|
}
|
||||||
reportApiScenario.setId(IDGenerator.nextStr());
|
List<TestPlanReportApiScenario> reportApiScenarios = extTestPlanReportApiScenarioMapper.getPlanExecuteCases(genParam.getTestPlanId(), subList);
|
||||||
reportApiScenario.setTestPlanReportId(report.getId());
|
apiScenarioCount.addAndGet(reportApiScenarios.size());
|
||||||
reportApiScenario.setTestPlanName(genParam.getTestPlanName());
|
List<String> moduleIds = reportApiScenarios.stream().map(TestPlanReportApiScenario::getApiScenarioModule).filter(Objects::nonNull).distinct().toList();
|
||||||
if (reportApiScenario.getApiScenarioModule() != null) {
|
Map<String, String> moduleMap = getModuleMapByIds(moduleIds, CaseType.SCENARIO_CASE.getKey());
|
||||||
reportApiScenario.setApiScenarioModule(moduleMap.getOrDefault(reportApiScenario.getApiScenarioModule(), reportApiScenario.getApiScenarioModule()));
|
for (TestPlanReportApiScenario reportApiScenario : reportApiScenarios) {
|
||||||
}
|
reportApiScenario.setId(IDGenerator.nextStr());
|
||||||
// 根据不超过数据库字段最大长度压缩模块名
|
reportApiScenario.setTestPlanReportId(report.getId());
|
||||||
reportApiScenario.setApiScenarioModule(ServiceUtils.compressName(reportApiScenario.getApiScenarioModule(), 450));
|
reportApiScenario.setTestPlanName(genParam.getTestPlanName());
|
||||||
if (!genParam.getUseManual()) {
|
if (reportApiScenario.getApiScenarioModule() != null) {
|
||||||
// 接口执行时才更新结果
|
reportApiScenario.setApiScenarioModule(moduleMap.getOrDefault(reportApiScenario.getApiScenarioModule(), reportApiScenario.getApiScenarioModule()));
|
||||||
reportApiScenario.setApiScenarioExecuteResult(null);
|
}
|
||||||
reportApiScenario.setApiScenarioExecuteUser(null);
|
// 根据不超过数据库字段最大长度压缩模块名
|
||||||
reportApiScenario.setApiScenarioExecuteReportId(IDGenerator.nextStr());
|
reportApiScenario.setApiScenarioModule(ServiceUtils.compressName(reportApiScenario.getApiScenarioModule(), 450));
|
||||||
}
|
if (!genParam.getUseManual()) {
|
||||||
reportApiScenario.setApiScenarioBugCount(bugCountMap.containsKey(reportApiScenario.getTestPlanApiScenarioId()) ? bugCountMap.get(reportApiScenario.getTestPlanApiScenarioId()) : 0);
|
// 接口执行时才更新结果
|
||||||
|
reportApiScenario.setApiScenarioExecuteResult(null);
|
||||||
|
reportApiScenario.setApiScenarioExecuteUser(null);
|
||||||
|
reportApiScenario.setApiScenarioExecuteReportId(IDGenerator.nextStr());
|
||||||
|
}
|
||||||
|
reportApiScenario.setApiScenarioBugCount(bugCountMap.containsKey(reportApiScenario.getTestPlanApiScenarioId()) ? bugCountMap.get(reportApiScenario.getTestPlanApiScenarioId()) : 0);
|
||||||
|
}
|
||||||
|
// 插入计划场景用例关联数据 -> 报告内容
|
||||||
|
TestPlanReportApiScenarioMapper batchMapper = sqlSession.getMapper(TestPlanReportApiScenarioMapper.class);
|
||||||
|
batchMapper.batchInsert(reportApiScenarios);
|
||||||
|
sqlSession.flushStatements();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
// 插入计划场景用例关联数据 -> 报告内容
|
reportApiScenarioIdList = null;
|
||||||
TestPlanReportApiScenarioMapper batchMapper = sqlSession.getMapper(TestPlanReportApiScenarioMapper.class);
|
|
||||||
batchMapper.batchInsert(reportApiScenarios);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 计划报告缺陷内容
|
// 计划报告缺陷内容
|
||||||
List<TestPlanReportBug> reportBugs = extTestPlanReportBugMapper.getPlanBugs(genParam.getTestPlanId());
|
{
|
||||||
if (CollectionUtils.isNotEmpty(reportBugs)) {
|
List<String> reportBugIdList = extTestPlanReportBugMapper.getPlanBugsId(genParam.getTestPlanId());
|
||||||
// MS处理人会与第三方的值冲突, 分开查询
|
if (CollectionUtils.isNotEmpty(reportBugIdList)) {
|
||||||
List<SelectOption> headerOptions = bugCommonService.getHeaderHandlerOption(genParam.getProjectId());
|
SubListUtils.dealForSubList(reportBugIdList, 200, (subList) -> {
|
||||||
Map<String, String> headerHandleUserMap = headerOptions.stream().collect(Collectors.toMap(SelectOption::getValue, SelectOption::getText));
|
if (CollectionUtils.isEmpty(subList)) {
|
||||||
List<SelectOption> localOptions = bugCommonService.getLocalHandlerOption(genParam.getProjectId());
|
return;
|
||||||
Map<String, String> localHandleUserMap = localOptions.stream().collect(Collectors.toMap(SelectOption::getValue, SelectOption::getText));
|
}
|
||||||
Map<String, String> allStatusMap = bugCommonService.getAllStatusMap(genParam.getProjectId());
|
List<TestPlanReportBug> reportBugs = extTestPlanReportBugMapper.getPlanBugs(genParam.getTestPlanId(), subList);
|
||||||
reportBugs.forEach(reportBug -> {
|
// MS处理人会与第三方的值冲突, 分开查询
|
||||||
reportBug.setId(IDGenerator.nextStr());
|
List<SelectOption> headerOptions = bugCommonService.getHeaderHandlerOption(genParam.getProjectId());
|
||||||
reportBug.setTestPlanReportId(report.getId());
|
Map<String, String> headerHandleUserMap = headerOptions.stream().collect(Collectors.toMap(SelectOption::getValue, SelectOption::getText));
|
||||||
reportBug.setBugHandleUser(headerHandleUserMap.containsKey(reportBug.getBugHandleUser()) ?
|
List<SelectOption> localOptions = bugCommonService.getLocalHandlerOption(genParam.getProjectId());
|
||||||
headerHandleUserMap.get(reportBug.getBugHandleUser()) : localHandleUserMap.get(reportBug.getBugHandleUser()));
|
Map<String, String> localHandleUserMap = localOptions.stream().collect(Collectors.toMap(SelectOption::getValue, SelectOption::getText));
|
||||||
reportBug.setBugStatus(allStatusMap.get(reportBug.getBugStatus()));
|
Map<String, String> allStatusMap = bugCommonService.getAllStatusMap(genParam.getProjectId());
|
||||||
});
|
reportBugs.forEach(reportBug -> {
|
||||||
// 插入计划关联用例缺陷数据(去重) -> 报告内容
|
reportBug.setId(IDGenerator.nextStr());
|
||||||
TestPlanReportBugMapper batchMapper = sqlSession.getMapper(TestPlanReportBugMapper.class);
|
reportBug.setTestPlanReportId(report.getId());
|
||||||
batchMapper.batchInsert(reportBugs);
|
reportBug.setBugHandleUser(headerHandleUserMap.containsKey(reportBug.getBugHandleUser()) ?
|
||||||
|
headerHandleUserMap.get(reportBug.getBugHandleUser()) : localHandleUserMap.get(reportBug.getBugHandleUser()));
|
||||||
|
reportBug.setBugStatus(allStatusMap.get(reportBug.getBugStatus()));
|
||||||
|
});
|
||||||
|
// 插入计划关联用例缺陷数据(去重) -> 报告内容
|
||||||
|
TestPlanReportBugMapper batchMapper = sqlSession.getMapper(TestPlanReportBugMapper.class);
|
||||||
|
batchMapper.batchInsert(reportBugs);
|
||||||
|
sqlSession.flushStatements();
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
long beforeFlush = System.currentTimeMillis();
|
||||||
sqlSession.flushStatements();
|
sqlSession.flushStatements();
|
||||||
|
long beforeClose = System.currentTimeMillis();
|
||||||
|
System.out.println("flush time: " + (beforeClose - beforeFlush));
|
||||||
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);
|
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);
|
||||||
|
long afterFlush = System.currentTimeMillis();
|
||||||
|
System.out.println("close time: " + (afterFlush - beforeClose));
|
||||||
|
|
||||||
return TestPlanReportDetailCaseDTO.builder()
|
return TestPlanReportDetailCaseDTO.builder()
|
||||||
.functionCases(reportFunctionCases).apiCases(reportApiCases).apiScenarios(reportApiScenarios).bugs(reportBugs).build();
|
.functionCaseCount(funcCaseCount.get()).apiCaseCount(apiCaseCount.get()).apiScenarioCount(apiScenarioCount.get()).bugCount(bugCount.get()).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue