From 40445cb4c53b9785fc189332dfd2059f0b8fa1dc Mon Sep 17 00:00:00 2001 From: Jianguo-Genius Date: Wed, 4 Sep 2024 18:10:32 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92):?= =?UTF-8?q?=20=E4=BC=98=E5=8C=96=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92?= =?UTF-8?q?=E6=8A=A5=E5=91=8A=E7=9A=84=E7=94=9F=E6=88=90=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plan/dto/TestPlanReportDetailCaseDTO.java | 14 +- .../ExtTestPlanReportApiCaseMapper.java | 4 +- .../mapper/ExtTestPlanReportApiCaseMapper.xml | 12 + .../ExtTestPlanReportApiScenarioMapper.java | 5 +- .../ExtTestPlanReportApiScenarioMapper.xml | 12 + .../mapper/ExtTestPlanReportBugMapper.java | 4 +- .../mapper/ExtTestPlanReportBugMapper.xml | 12 + ...ExtTestPlanReportFunctionalCaseMapper.java | 4 +- .../ExtTestPlanReportFunctionalCaseMapper.xml | 12 + .../PlanRunTestPlanApiCaseService.java | 2 +- .../PlanRunTestPlanApiScenarioService.java | 29 +- .../plan/service/TestPlanReportService.java | 263 +++++++++++------- 12 files changed, 235 insertions(+), 138 deletions(-) diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/TestPlanReportDetailCaseDTO.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/TestPlanReportDetailCaseDTO.java index afe163f45b..519908d4f1 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/TestPlanReportDetailCaseDTO.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/TestPlanReportDetailCaseDTO.java @@ -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 functionCases; + private long functionCaseCount; - private List apiCases; + private long apiCaseCount; - private List apiScenarios; + private long apiScenarioCount; - private List bugs; + private long bugCount; } diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanReportApiCaseMapper.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanReportApiCaseMapper.java index f1a529e9ad..b2d934d08d 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanReportApiCaseMapper.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanReportApiCaseMapper.java @@ -23,7 +23,9 @@ public interface ExtTestPlanReportApiCaseMapper { * @param planId 计划ID * @return 接口用例列表 */ - List getPlanExecuteCases(@Param("id") String planId); + List getPlanExecuteCases(@Param("id") String planId, @Param("ids") List ids); + + List getPlanExecuteCasesId(@Param("id") String planId); /** * 获取项目下接口用例所属模块集合 diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanReportApiCaseMapper.xml b/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanReportApiCaseMapper.xml index 8fda7d0a5d..eb896cacea 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanReportApiCaseMapper.xml +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanReportApiCaseMapper.xml @@ -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 + + #{id} + group by tpac.id @@ -42,6 +46,14 @@ where test_plan_report_id = #{testPlanReportId} and test_plan_collection_id = #{collectionId} order by pos desc + diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanReportApiScenarioMapper.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanReportApiScenarioMapper.java index d378735e0c..fc1f71fb4c 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanReportApiScenarioMapper.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanReportApiScenarioMapper.java @@ -23,7 +23,10 @@ public interface ExtTestPlanReportApiScenarioMapper { * @param planId 计划ID * @return 场景用例列表 */ - List getPlanExecuteCases(@Param("id") String planId); + List getPlanExecuteCases(@Param("id") String planId, @Param("ids") List ids); + + + List getPlanExecuteCasesId(@Param("id") String planId); /** * 获取项目下场景用例所属模块集合 diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanReportApiScenarioMapper.xml b/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanReportApiScenarioMapper.xml index e9d7534f32..baa401fde4 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanReportApiScenarioMapper.xml +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanReportApiScenarioMapper.xml @@ -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 + + #{id} + group by tpas.id @@ -35,6 +39,14 @@ where tpras.test_plan_report_id = #{request.reportId} + diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanReportBugMapper.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanReportBugMapper.java index 6c2e453a79..f80fec51dc 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanReportBugMapper.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanReportBugMapper.java @@ -16,7 +16,9 @@ public interface ExtTestPlanReportBugMapper { * @param planId 计划ID * @return 缺陷集合 */ - List getPlanBugs(@Param("id") String planId); + List getPlanBugs(@Param("id") String planId, @Param("ids") List ids); + + List getPlanBugsId(@Param("id") String planId); /** * 分页查询报告关联的缺陷 diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanReportBugMapper.xml b/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanReportBugMapper.xml index 9a97856c6f..ca49027452 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanReportBugMapper.xml +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanReportBugMapper.xml @@ -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 + + #{bugId} + group by brc.bug_id + + @@ -56,6 +60,14 @@ where tprfc.test_plan_report_id = #{request.reportId} + diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/PlanRunTestPlanApiCaseService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/PlanRunTestPlanApiCaseService.java index bad09c974a..282599347c 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/PlanRunTestPlanApiCaseService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/PlanRunTestPlanApiCaseService.java @@ -114,7 +114,6 @@ public class PlanRunTestPlanApiCaseService { String testPlanId = collection.getTestPlanId(); List 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); } diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/PlanRunTestPlanApiScenarioService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/PlanRunTestPlanApiScenarioService.java index d0b84ebd24..9d70050736 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/PlanRunTestPlanApiScenarioService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/PlanRunTestPlanApiScenarioService.java @@ -106,31 +106,26 @@ public class PlanRunTestPlanApiScenarioService { String userId = testPlanExecutionQueue.getCreateUser(); TestPlanCollection collection = JSON.parseObject(testPlanExecutionQueue.getTestPlanCollectionJson(), TestPlanCollection.class); String testPlanId = collection.getTestPlanId(); - - List testPlanReportApiScenarios = getTestPlanReportApiScenarios(testPlanReportId, collection); - testPlanReportApiScenarios.stream().sorted(Comparator.comparing(TestPlanReportApiScenario::getPos)); - if (CollectionUtils.isEmpty(testPlanReportApiScenarios)) { - return true; - } - - ApiRunModeConfigDTO runModeConfig = testPlanApiBatchRunBaseService.getApiRunModeConfig(collection); - - Map scenarioReportMap = initReport(testPlanReportApiScenarios, runModeConfig, userId); - - List 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 testPlanReportApiScenarios = getTestPlanReportApiScenarios(testPlanReportId, collection); + if (CollectionUtils.isEmpty(testPlanReportApiScenarios)) { + return true; + } + + Map scenarioReportMap = initReport(testPlanReportApiScenarios, runModeConfig, userId); + List 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); } + /** * 执行串行的下一个任务 * diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanReportService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanReportService.java index c82ad124e5..8a119984db 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanReportService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanReportService.java @@ -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 bugCountList = extTestPlanReportBugMapper.countPlanBug(genParam.getTestPlanId()); Map 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 reportFunctionCases = extTestPlanReportFunctionalCaseMapper.getPlanExecuteCases(genParam.getTestPlanId()); - if (CollectionUtils.isNotEmpty(reportFunctionCases)) { - // 用例等级 - List ids = reportFunctionCases.stream().map(TestPlanReportFunctionCase::getFunctionCaseId).distinct().toList(); - List options = extTestPlanReportFunctionalCaseMapper.getCasePriorityByIds(ids); - Map casePriorityMap = options.stream().collect(Collectors.toMap(SelectOption::getValue, SelectOption::getText)); - // 用例模块 - List moduleIds = reportFunctionCases.stream().map(TestPlanReportFunctionCase::getFunctionCaseModule).filter(Objects::nonNull).toList(); - Map moduleMap = getModuleMapByIds(moduleIds, CaseType.FUNCTIONAL_CASE.getKey()); - // 关联的功能用例最新一次执行历史 - List relateIds = reportFunctionCases.stream().map(TestPlanReportFunctionCase::getTestPlanFunctionCaseId).toList(); - TestPlanCaseExecuteHistoryExample example = new TestPlanCaseExecuteHistoryExample(); - example.createCriteria().andTestPlanCaseIdIn(relateIds); - List functionalExecHisList = testPlanCaseExecuteHistoryMapper.selectByExample(example); - Map> functionalExecMap = functionalExecHisList.stream().collect(Collectors.groupingBy(TestPlanCaseExecuteHistory::getTestPlanCaseId)); + { + List funcCaseIdList = extTestPlanReportFunctionalCaseMapper.getPlanExecuteCasesId(genParam.getTestPlanId()); + if (CollectionUtils.isNotEmpty(funcCaseIdList)) { + SubListUtils.dealForSubList(funcCaseIdList, 200, (subList) -> { + if (CollectionUtils.isEmpty(subList)) { + return; + } + List reportFunctionCases = extTestPlanReportFunctionalCaseMapper.getPlanExecuteCases(genParam.getTestPlanId(), subList); + funcCaseCount.addAndGet(reportFunctionCases.size()); + // 用例等级 + List ids = reportFunctionCases.stream().map(TestPlanReportFunctionCase::getFunctionCaseId).distinct().toList(); + List options = extTestPlanReportFunctionalCaseMapper.getCasePriorityByIds(ids); + Map casePriorityMap = options.stream().collect(Collectors.toMap(SelectOption::getValue, SelectOption::getText)); + // 用例模块 + List moduleIds = reportFunctionCases.stream().map(TestPlanReportFunctionCase::getFunctionCaseModule).filter(Objects::nonNull).toList(); + Map moduleMap = getModuleMapByIds(moduleIds, CaseType.FUNCTIONAL_CASE.getKey()); + // 关联的功能用例最新一次执行历史 + List relateIds = reportFunctionCases.stream().map(TestPlanReportFunctionCase::getTestPlanFunctionCaseId).toList(); + TestPlanCaseExecuteHistoryExample example = new TestPlanCaseExecuteHistoryExample(); + example.createCriteria().andTestPlanCaseIdIn(relateIds); + List functionalExecHisList = testPlanCaseExecuteHistoryMapper.selectByExample(example); + Map> 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 hisList = functionalExecMap.get(reportFunctionalCase.getTestPlanFunctionCaseId()); - if (CollectionUtils.isNotEmpty(hisList)) { - Optional 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 hisList = functionalExecMap.get(reportFunctionalCase.getTestPlanFunctionCaseId()); + if (CollectionUtils.isNotEmpty(hisList)) { + Optional 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 reportApiCases = extTestPlanReportApiCaseMapper.getPlanExecuteCases(genParam.getTestPlanId()); - if (CollectionUtils.isNotEmpty(reportApiCases)) { - // 用例模块 - List moduleIds = reportApiCases.stream().map(TestPlanReportApiCase::getApiCaseModule).filter(Objects::nonNull).toList(); - Map moduleMap = getModuleMapByIds(moduleIds, CaseType.API_CASE.getKey()); + { + List testPlanReportApiCaseIdList = extTestPlanReportApiCaseMapper.getPlanExecuteCasesId(genParam.getTestPlanId()); + if (CollectionUtils.isNotEmpty(testPlanReportApiCaseIdList)) { + SubListUtils.dealForSubList(testPlanReportApiCaseIdList, 200, (subList) -> { + if (CollectionUtils.isEmpty(subList)) { + return; + } + List reportApiCases = extTestPlanReportApiCaseMapper.getPlanExecuteCases(genParam.getTestPlanId(), subList); + apiCaseCount.addAndGet(reportApiCases.size()); + List moduleIds = reportApiCases.stream().map(TestPlanReportApiCase::getApiCaseModule).filter(Objects::nonNull).distinct().toList(); + Map 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 reportApiScenarios = extTestPlanReportApiScenarioMapper.getPlanExecuteCases(genParam.getTestPlanId()); - if (CollectionUtils.isNotEmpty(reportApiScenarios)) { - // 用例模块 - List moduleIds = reportApiScenarios.stream().map(TestPlanReportApiScenario::getApiScenarioModule).filter(Objects::nonNull).toList(); - Map 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 reportApiScenarioIdList = extTestPlanReportApiScenarioMapper.getPlanExecuteCasesId(genParam.getTestPlanId()); + if (CollectionUtils.isNotEmpty(reportApiScenarioIdList)) { + SubListUtils.dealForSubList(reportApiScenarioIdList, 200, (subList) -> { + if (CollectionUtils.isEmpty(subList)) { + return; + } + List reportApiScenarios = extTestPlanReportApiScenarioMapper.getPlanExecuteCases(genParam.getTestPlanId(), subList); + apiScenarioCount.addAndGet(reportApiScenarios.size()); + List moduleIds = reportApiScenarios.stream().map(TestPlanReportApiScenario::getApiScenarioModule).filter(Objects::nonNull).distinct().toList(); + Map 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 reportBugs = extTestPlanReportBugMapper.getPlanBugs(genParam.getTestPlanId()); - if (CollectionUtils.isNotEmpty(reportBugs)) { - // MS处理人会与第三方的值冲突, 分开查询 - List headerOptions = bugCommonService.getHeaderHandlerOption(genParam.getProjectId()); - Map headerHandleUserMap = headerOptions.stream().collect(Collectors.toMap(SelectOption::getValue, SelectOption::getText)); - List localOptions = bugCommonService.getLocalHandlerOption(genParam.getProjectId()); - Map localHandleUserMap = localOptions.stream().collect(Collectors.toMap(SelectOption::getValue, SelectOption::getText)); - Map 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 reportBugIdList = extTestPlanReportBugMapper.getPlanBugsId(genParam.getTestPlanId()); + if (CollectionUtils.isNotEmpty(reportBugIdList)) { + SubListUtils.dealForSubList(reportBugIdList, 200, (subList) -> { + if (CollectionUtils.isEmpty(subList)) { + return; + } + List reportBugs = extTestPlanReportBugMapper.getPlanBugs(genParam.getTestPlanId(), subList); + // MS处理人会与第三方的值冲突, 分开查询 + List headerOptions = bugCommonService.getHeaderHandlerOption(genParam.getProjectId()); + Map headerHandleUserMap = headerOptions.stream().collect(Collectors.toMap(SelectOption::getValue, SelectOption::getText)); + List localOptions = bugCommonService.getLocalHandlerOption(genParam.getProjectId()); + Map localHandleUserMap = localOptions.stream().collect(Collectors.toMap(SelectOption::getValue, SelectOption::getText)); + Map 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(); }