refactor(测试计划): 优化测试计划报告的生成逻辑

This commit is contained in:
Jianguo-Genius 2024-09-04 18:10:32 +08:00 committed by 建国
parent 9ff8f971c6
commit 40445cb4c5
12 changed files with 235 additions and 138 deletions

View File

@ -1,28 +1,22 @@
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.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
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;
}

View File

@ -23,7 +23,9 @@ public interface ExtTestPlanReportApiCaseMapper {
* @param planId 计划ID
* @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);
/**
* 获取项目下接口用例所属模块集合

View File

@ -16,6 +16,10 @@
left join api_definition ad on atc.api_definition_id = ad.id
left join api_definition_module adm on ad.module_id = adm.id
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
</select>
@ -42,6 +46,14 @@
where test_plan_report_id = #{testPlanReportId} and test_plan_collection_id = #{collectionId}
order by pos desc
</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">
<if test="request.filter != null and request.filter.size() > 0">

View File

@ -23,7 +23,10 @@ public interface ExtTestPlanReportApiScenarioMapper {
* @param planId 计划ID
* @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);
/**
* 获取项目下场景用例所属模块集合

View File

@ -15,6 +15,10 @@
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
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
</select>
@ -35,6 +39,14 @@
where tpras.test_plan_report_id = #{request.reportId}
<include refid="filter"/>
</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">
<if test="request.filter != null and request.filter.size() > 0">

View File

@ -16,7 +16,9 @@ public interface ExtTestPlanReportBugMapper {
* @param planId 计划ID
* @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);
/**
* 分页查询报告关联的缺陷

View File

@ -7,9 +7,21 @@
b.handle_user bugHandleUser, count(brc.id) bugCaseCount
from bug_relation_case brc join bug b on brc.bug_id = b.id
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
</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 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

View File

@ -17,7 +17,7 @@ public interface ExtTestPlanReportFunctionalCaseMapper {
* @param planId 计划ID
* @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 关联的用例集合
*/
List<ReportDetailCasePageDTO> list(@Param("request") TestPlanReportDetailPageRequest request);
List<String> getPlanExecuteCasesId(@Param("id") String testPlanId);
}

View File

@ -9,6 +9,10 @@
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
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
</select>
@ -56,6 +60,14 @@
where tprfc.test_plan_report_id = #{request.reportId}
<include refid="filter"/>
</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">
<if test="request.filter != null and request.filter.size() > 0">

View File

@ -114,7 +114,6 @@ public class PlanRunTestPlanApiCaseService {
String testPlanId = collection.getTestPlanId();
List<TestPlanReportApiCase> testPlanReportApiCases = getTestPlanReportApiCases(testPlanReportId, collection);
testPlanReportApiCases.stream().sorted(Comparator.comparing(TestPlanReportApiCase::getPos));
if (CollectionUtils.isEmpty(testPlanReportApiCases)) {
return true;
}
@ -172,6 +171,7 @@ public class PlanRunTestPlanApiCaseService {
example.createCriteria()
.andTestPlanReportIdEqualTo(testPlanReportId)
.andTestPlanCollectionIdEqualTo(collection.getId());
example.setOrderByClause(" pos asc");
return testPlanReportApiCaseMapper.selectByExample(example);
}

View File

@ -106,31 +106,26 @@ public class PlanRunTestPlanApiScenarioService {
String userId = testPlanExecutionQueue.getCreateUser();
TestPlanCollection collection = JSON.parseObject(testPlanExecutionQueue.getTestPlanCollectionJson(), TestPlanCollection.class);
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);
ApiRunModeConfigDTO runModeConfig = testPlanApiBatchRunBaseService.getApiRunModeConfig(collection);
TaskBatchRequestDTO taskRequest = testPlanApiScenarioBatchRunService.getTaskBatchRequestDTO(testPlan.getProjectId(), runModeConfig);
taskRequest.setTaskItems(taskItems);
taskRequest.getTaskInfo().setParentQueueId(parentQueueId);
taskRequest.getTaskInfo().setUserId(userId);
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());
taskRequest.setTaskItems(taskItems);
apiExecuteService.batchExecute(taskRequest);
return false;
}
@ -182,9 +177,11 @@ public class PlanRunTestPlanApiScenarioService {
example.createCriteria()
.andTestPlanReportIdEqualTo(testPlanReportId)
.andTestPlanCollectionIdEqualTo(collection.getId());
example.setOrderByClause(" pos asc");
return testPlanReportApiScenarioMapper.selectByExample(example);
}
/**
* 执行串行的下一个任务
*

View File

@ -48,6 +48,7 @@ import org.springframework.transaction.annotation.Transactional;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.concurrent.atomic.AtomicLong;
import java.util.stream.Collectors;
@Service
@ -410,10 +411,10 @@ public class TestPlanReportService {
TestPlanReportSummary reportSummary = new TestPlanReportSummary();
reportSummary.setId(IDGenerator.nextStr());
reportSummary.setTestPlanReportId(report.getId());
reportSummary.setFunctionalCaseCount((long) (CollectionUtils.isEmpty(reportCaseDetail.getFunctionCases()) ? 0 : reportCaseDetail.getFunctionCases().size()));
reportSummary.setApiCaseCount((long) (CollectionUtils.isEmpty(reportCaseDetail.getApiCases()) ? 0 : reportCaseDetail.getApiCases().size()));
reportSummary.setApiScenarioCount((long) (CollectionUtils.isEmpty(reportCaseDetail.getApiScenarios()) ? 0 : reportCaseDetail.getApiScenarios().size()));
reportSummary.setBugCount((long) (CollectionUtils.isEmpty(reportCaseDetail.getBugs()) ? 0 : reportCaseDetail.getBugs().size()));
reportSummary.setFunctionalCaseCount(reportCaseDetail.getFunctionCaseCount());
reportSummary.setApiCaseCount(reportCaseDetail.getApiCaseCount());
reportSummary.setApiScenarioCount(reportCaseDetail.getApiScenarioCount());
reportSummary.setBugCount(reportCaseDetail.getBugCount());
reportSummary.setPlanCount(genParam.getIntegrated() ? (long) childPlanIds.size() : 0);
testPlanReportSummaryMapper.insertSelective(reportSummary);
@ -433,130 +434,178 @@ public class TestPlanReportService {
// 缺陷数
List<ReportBugCountDTO> bugCountList = extTestPlanReportBugMapper.countPlanBug(genParam.getTestPlanId());
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> ids = reportFunctionCases.stream().map(TestPlanReportFunctionCase::getFunctionCaseId).distinct().toList();
List<SelectOption> options = extTestPlanReportFunctionalCaseMapper.getCasePriorityByIds(ids);
Map<String, String> casePriorityMap = options.stream().collect(Collectors.toMap(SelectOption::getValue, SelectOption::getText));
// 用例模块
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));
{
List<String> funcCaseIdList = extTestPlanReportFunctionalCaseMapper.getPlanExecuteCasesId(genParam.getTestPlanId());
if (CollectionUtils.isNotEmpty(funcCaseIdList)) {
SubListUtils.dealForSubList(funcCaseIdList, 200, (subList) -> {
if (CollectionUtils.isEmpty(subList)) {
return;
}
List<TestPlanReportFunctionCase> reportFunctionCases = extTestPlanReportFunctionalCaseMapper.getPlanExecuteCases(genParam.getTestPlanId(), subList);
funcCaseCount.addAndGet(reportFunctionCases.size());
// 用例等级
List<String> ids = reportFunctionCases.stream().map(TestPlanReportFunctionCase::getFunctionCaseId).distinct().toList();
List<SelectOption> options = extTestPlanReportFunctionalCaseMapper.getCasePriorityByIds(ids);
Map<String, String> casePriorityMap = options.stream().collect(Collectors.toMap(SelectOption::getValue, SelectOption::getText));
// 用例模块
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) {
reportFunctionalCase.setId(IDGenerator.nextStr());
reportFunctionalCase.setTestPlanReportId(report.getId());
reportFunctionalCase.setTestPlanName(genParam.getTestPlanName());
if (reportFunctionalCase.getFunctionCaseModule() != null) {
reportFunctionalCase.setFunctionCaseModule(moduleMap.getOrDefault(reportFunctionalCase.getFunctionCaseModule(), reportFunctionalCase.getFunctionCaseModule()));
}
reportFunctionalCase.setFunctionCasePriority(casePriorityMap.get(reportFunctionalCase.getFunctionCaseId()));
List<TestPlanCaseExecuteHistory> hisList = functionalExecMap.get(reportFunctionalCase.getTestPlanFunctionCaseId());
if (CollectionUtils.isNotEmpty(hisList)) {
Optional<String> lastExecuteHisOpt = hisList.stream().sorted(Comparator.comparing(TestPlanCaseExecuteHistory::getCreateTime).reversed()).map(TestPlanCaseExecuteHistory::getId).findFirst();
reportFunctionalCase.setFunctionCaseExecuteReportId(lastExecuteHisOpt.orElse(null));
} else {
reportFunctionalCase.setFunctionCaseExecuteReportId(null);
}
reportFunctionalCase.setFunctionCaseBugCount(bugCountMap.containsKey(reportFunctionalCase.getTestPlanFunctionCaseId()) ? bugCountMap.get(reportFunctionalCase.getTestPlanFunctionCaseId()) : 0);
for (TestPlanReportFunctionCase reportFunctionalCase : reportFunctionCases) {
reportFunctionalCase.setId(IDGenerator.nextStr());
reportFunctionalCase.setTestPlanReportId(report.getId());
reportFunctionalCase.setTestPlanName(genParam.getTestPlanName());
if (reportFunctionalCase.getFunctionCaseModule() != null) {
reportFunctionalCase.setFunctionCaseModule(moduleMap.getOrDefault(reportFunctionalCase.getFunctionCaseModule(), reportFunctionalCase.getFunctionCaseModule()));
}
reportFunctionalCase.setFunctionCasePriority(casePriorityMap.get(reportFunctionalCase.getFunctionCaseId()));
List<TestPlanCaseExecuteHistory> hisList = functionalExecMap.get(reportFunctionalCase.getTestPlanFunctionCaseId());
if (CollectionUtils.isNotEmpty(hisList)) {
Optional<String> lastExecuteHisOpt = hisList.stream().sorted(Comparator.comparing(TestPlanCaseExecuteHistory::getCreateTime).reversed()).map(TestPlanCaseExecuteHistory::getId).findFirst();
reportFunctionalCase.setFunctionCaseExecuteReportId(lastExecuteHisOpt.orElse(null));
} else {
reportFunctionalCase.setFunctionCaseExecuteReportId(null);
}
reportFunctionalCase.setFunctionCaseBugCount(bugCountMap.containsKey(reportFunctionalCase.getTestPlanFunctionCaseId()) ? bugCountMap.get(reportFunctionalCase.getTestPlanFunctionCaseId()) : 0);
}
// 插入计划功能用例关联数据 -> 报告内容
TestPlanReportFunctionCaseMapper batchMapper = sqlSession.getMapper(TestPlanReportFunctionCaseMapper.class);
batchMapper.batchInsert(reportFunctionCases);
});
}
// 插入计划功能用例关联数据 -> 报告内容
TestPlanReportFunctionCaseMapper batchMapper = sqlSession.getMapper(TestPlanReportFunctionCaseMapper.class);
batchMapper.batchInsert(reportFunctionCases);
funcCaseIdList = null;
}
// 接口用例
List<TestPlanReportApiCase> reportApiCases = extTestPlanReportApiCaseMapper.getPlanExecuteCases(genParam.getTestPlanId());
if (CollectionUtils.isNotEmpty(reportApiCases)) {
// 用例模块
List<String> moduleIds = reportApiCases.stream().map(TestPlanReportApiCase::getApiCaseModule).filter(Objects::nonNull).toList();
Map<String, String> moduleMap = getModuleMapByIds(moduleIds, CaseType.API_CASE.getKey());
{
List<String> testPlanReportApiCaseIdList = extTestPlanReportApiCaseMapper.getPlanExecuteCasesId(genParam.getTestPlanId());
if (CollectionUtils.isNotEmpty(testPlanReportApiCaseIdList)) {
SubListUtils.dealForSubList(testPlanReportApiCaseIdList, 200, (subList) -> {
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) {
reportApiCase.setId(IDGenerator.nextStr());
reportApiCase.setTestPlanReportId(report.getId());
reportApiCase.setTestPlanName(genParam.getTestPlanName());
if (reportApiCase.getApiCaseModule() != null) {
reportApiCase.setApiCaseModule(moduleMap.getOrDefault(reportApiCase.getApiCaseModule(), reportApiCase.getApiCaseModule()));
}
// 根据不超过数据库字段最大长度压缩模块名
reportApiCase.setApiCaseModule(ServiceUtils.compressName(reportApiCase.getApiCaseModule(), 450));
if (!genParam.getUseManual()) {
// 接口执行时才更新结果
reportApiCase.setApiCaseExecuteResult(null);
reportApiCase.setApiCaseExecuteUser(null);
reportApiCase.setApiCaseExecuteReportId(IDGenerator.nextStr());
}
reportApiCase.setApiCaseBugCount(bugCountMap.containsKey(reportApiCase.getTestPlanApiCaseId()) ? bugCountMap.get(reportApiCase.getTestPlanApiCaseId()) : 0);
for (TestPlanReportApiCase reportApiCase : reportApiCases) {
reportApiCase.setId(IDGenerator.nextStr());
reportApiCase.setTestPlanReportId(report.getId());
reportApiCase.setTestPlanName(genParam.getTestPlanName());
if (reportApiCase.getApiCaseModule() != null) {
reportApiCase.setApiCaseModule(moduleMap.getOrDefault(reportApiCase.getApiCaseModule(), reportApiCase.getApiCaseModule()));
}
// 根据不超过数据库字段最大长度压缩模块名
reportApiCase.setApiCaseModule(ServiceUtils.compressName(reportApiCase.getApiCaseModule(), 450));
if (!genParam.getUseManual()) {
// 接口执行时才更新结果
reportApiCase.setApiCaseExecuteResult(null);
reportApiCase.setApiCaseExecuteUser(null);
reportApiCase.setApiCaseExecuteReportId(IDGenerator.nextStr());
}
reportApiCase.setApiCaseBugCount(bugCountMap.containsKey(reportApiCase.getTestPlanApiCaseId()) ? bugCountMap.get(reportApiCase.getTestPlanApiCaseId()) : 0);
}
// 插入计划接口用例关联数据 -> 报告内容
TestPlanReportApiCaseMapper batchMapper = sqlSession.getMapper(TestPlanReportApiCaseMapper.class);
batchMapper.batchInsert(reportApiCases);
sqlSession.flushStatements();
});
}
// 插入计划接口用例关联数据 -> 报告内容
TestPlanReportApiCaseMapper batchMapper = sqlSession.getMapper(TestPlanReportApiCaseMapper.class);
batchMapper.batchInsert(reportApiCases);
testPlanReportApiCaseIdList = null;
}
// 场景用例
List<TestPlanReportApiScenario> reportApiScenarios = extTestPlanReportApiScenarioMapper.getPlanExecuteCases(genParam.getTestPlanId());
if (CollectionUtils.isNotEmpty(reportApiScenarios)) {
// 用例模块
List<String> moduleIds = reportApiScenarios.stream().map(TestPlanReportApiScenario::getApiScenarioModule).filter(Objects::nonNull).toList();
Map<String, String> moduleMap = getModuleMapByIds(moduleIds, CaseType.SCENARIO_CASE.getKey());
for (TestPlanReportApiScenario reportApiScenario : reportApiScenarios) {
reportApiScenario.setId(IDGenerator.nextStr());
reportApiScenario.setTestPlanReportId(report.getId());
reportApiScenario.setTestPlanName(genParam.getTestPlanName());
if (reportApiScenario.getApiScenarioModule() != null) {
reportApiScenario.setApiScenarioModule(moduleMap.getOrDefault(reportApiScenario.getApiScenarioModule(), reportApiScenario.getApiScenarioModule()));
}
// 根据不超过数据库字段最大长度压缩模块名
reportApiScenario.setApiScenarioModule(ServiceUtils.compressName(reportApiScenario.getApiScenarioModule(), 450));
if (!genParam.getUseManual()) {
// 接口执行时才更新结果
reportApiScenario.setApiScenarioExecuteResult(null);
reportApiScenario.setApiScenarioExecuteUser(null);
reportApiScenario.setApiScenarioExecuteReportId(IDGenerator.nextStr());
}
reportApiScenario.setApiScenarioBugCount(bugCountMap.containsKey(reportApiScenario.getTestPlanApiScenarioId()) ? bugCountMap.get(reportApiScenario.getTestPlanApiScenarioId()) : 0);
{
List<String> reportApiScenarioIdList = extTestPlanReportApiScenarioMapper.getPlanExecuteCasesId(genParam.getTestPlanId());
if (CollectionUtils.isNotEmpty(reportApiScenarioIdList)) {
SubListUtils.dealForSubList(reportApiScenarioIdList, 200, (subList) -> {
if (CollectionUtils.isEmpty(subList)) {
return;
}
List<TestPlanReportApiScenario> reportApiScenarios = extTestPlanReportApiScenarioMapper.getPlanExecuteCases(genParam.getTestPlanId(), subList);
apiScenarioCount.addAndGet(reportApiScenarios.size());
List<String> moduleIds = reportApiScenarios.stream().map(TestPlanReportApiScenario::getApiScenarioModule).filter(Objects::nonNull).distinct().toList();
Map<String, String> moduleMap = getModuleMapByIds(moduleIds, CaseType.SCENARIO_CASE.getKey());
for (TestPlanReportApiScenario reportApiScenario : reportApiScenarios) {
reportApiScenario.setId(IDGenerator.nextStr());
reportApiScenario.setTestPlanReportId(report.getId());
reportApiScenario.setTestPlanName(genParam.getTestPlanName());
if (reportApiScenario.getApiScenarioModule() != null) {
reportApiScenario.setApiScenarioModule(moduleMap.getOrDefault(reportApiScenario.getApiScenarioModule(), reportApiScenario.getApiScenarioModule()));
}
// 根据不超过数据库字段最大长度压缩模块名
reportApiScenario.setApiScenarioModule(ServiceUtils.compressName(reportApiScenario.getApiScenarioModule(), 450));
if (!genParam.getUseManual()) {
// 接口执行时才更新结果
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();
});
}
// 插入计划场景用例关联数据 -> 报告内容
TestPlanReportApiScenarioMapper batchMapper = sqlSession.getMapper(TestPlanReportApiScenarioMapper.class);
batchMapper.batchInsert(reportApiScenarios);
reportApiScenarioIdList = null;
}
// 计划报告缺陷内容
List<TestPlanReportBug> reportBugs = extTestPlanReportBugMapper.getPlanBugs(genParam.getTestPlanId());
if (CollectionUtils.isNotEmpty(reportBugs)) {
// MS处理人会与第三方的值冲突, 分开查询
List<SelectOption> headerOptions = bugCommonService.getHeaderHandlerOption(genParam.getProjectId());
Map<String, String> headerHandleUserMap = headerOptions.stream().collect(Collectors.toMap(SelectOption::getValue, SelectOption::getText));
List<SelectOption> localOptions = bugCommonService.getLocalHandlerOption(genParam.getProjectId());
Map<String, String> localHandleUserMap = localOptions.stream().collect(Collectors.toMap(SelectOption::getValue, SelectOption::getText));
Map<String, String> allStatusMap = bugCommonService.getAllStatusMap(genParam.getProjectId());
reportBugs.forEach(reportBug -> {
reportBug.setId(IDGenerator.nextStr());
reportBug.setTestPlanReportId(report.getId());
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);
{
List<String> reportBugIdList = extTestPlanReportBugMapper.getPlanBugsId(genParam.getTestPlanId());
if (CollectionUtils.isNotEmpty(reportBugIdList)) {
SubListUtils.dealForSubList(reportBugIdList, 200, (subList) -> {
if (CollectionUtils.isEmpty(subList)) {
return;
}
List<TestPlanReportBug> reportBugs = extTestPlanReportBugMapper.getPlanBugs(genParam.getTestPlanId(), subList);
// MS处理人会与第三方的值冲突, 分开查询
List<SelectOption> headerOptions = bugCommonService.getHeaderHandlerOption(genParam.getProjectId());
Map<String, String> headerHandleUserMap = headerOptions.stream().collect(Collectors.toMap(SelectOption::getValue, SelectOption::getText));
List<SelectOption> localOptions = bugCommonService.getLocalHandlerOption(genParam.getProjectId());
Map<String, String> localHandleUserMap = localOptions.stream().collect(Collectors.toMap(SelectOption::getValue, SelectOption::getText));
Map<String, String> allStatusMap = bugCommonService.getAllStatusMap(genParam.getProjectId());
reportBugs.forEach(reportBug -> {
reportBug.setId(IDGenerator.nextStr());
reportBug.setTestPlanReportId(report.getId());
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();
long beforeClose = System.currentTimeMillis();
System.out.println("flush time: " + (beforeClose - beforeFlush));
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);
long afterFlush = System.currentTimeMillis();
System.out.println("close time: " + (afterFlush - beforeClose));
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();
}