From 56f9247739783199de414c62b6ae6c7f122655d5 Mon Sep 17 00:00:00 2001 From: song-tianyang Date: Tue, 5 Jul 2022 17:53:08 +0800 Subject: [PATCH] =?UTF-8?q?style(=E6=B5=8B=E8=AF=95=E8=B7=9F=E8=B8=AA):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92=E6=8A=A5?= =?UTF-8?q?=E5=91=8A=E5=AF=BC=E5=87=BA=E5=90=8E=E6=8E=A5=E5=8F=A3=E7=94=A8?= =?UTF-8?q?=E4=BE=8B=E4=B8=8D=E5=B1=95=E7=A4=BA=E8=BF=90=E8=A1=8C=E7=BB=93?= =?UTF-8?q?=E6=9E=9C=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1014464 --user=宋天阳 【测试计划】测试报告导出后,点击接口用例不显示接口执行内容 https://www.tapd.cn/55049933/s/1195124 --- .../track/service/TestPlanService.java | 41 +++++++++++++------ 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/backend/src/main/java/io/metersphere/track/service/TestPlanService.java b/backend/src/main/java/io/metersphere/track/service/TestPlanService.java index d3decacaa6..06aa5b0a44 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanService.java @@ -182,6 +182,8 @@ public class TestPlanService { private TestPlanExecutionQueueService testPlanExecutionQueueService; @Resource private ApiDefinitionExecResultMapper apiDefinitionExecResultMapper; + @Resource + private ExtApiDefinitionExecResultMapper extApiDefinitionExecResultMapper; public synchronized TestPlan addTestPlan(AddTestPlanRequest testPlan) { if (getTestPlanByName(testPlan.getName()).size() > 0) { @@ -1412,18 +1414,31 @@ public class TestPlanService { public void buildApiResponse(List cases) { if (!CollectionUtils.isEmpty(cases)) { - List reportIds = cases.stream().map(TestPlanFailureApiDTO::getReportId).collect(Collectors.toList()); - ApiDefinitionExecResultExample example = new ApiDefinitionExecResultExample(); - example.createCriteria().andIdIn(reportIds); - List results = apiDefinitionExecResultMapper.selectByExampleWithBLOBs(example); - // 格式化数据结果 - Map resultMap = results.stream().collect(Collectors.toMap(ApiDefinitionExecResult::getId, item -> item, (k, v) -> k)); - cases.forEach(item -> { - if (resultMap.get(item.getReportId()) != null && - StringUtils.isNotBlank(resultMap.get(item.getReportId()).getContent())) { - item.setResponse(resultMap.get(item.getReportId()).getContent()); + List reportIds = new ArrayList<>(); + for (TestPlanFailureApiDTO apiCase : cases) { + if (StringUtils.isEmpty(apiCase.getReportId())) { + ApiDefinitionExecResultWithBLOBs result = extApiDefinitionExecResultMapper.selectPlanApiMaxResultByTestIdAndType(apiCase.getId(), "API_PLAN"); + if (result != null && StringUtils.isNotBlank(result.getContent())) { + apiCase.setReportId(result.getId()); + apiCase.setResponse(result.getContent()); + } + } else { + reportIds.add(apiCase.getReportId()); } - }); + } + if (CollectionUtils.isNotEmpty(reportIds)) { + ApiDefinitionExecResultExample example = new ApiDefinitionExecResultExample(); + example.createCriteria().andIdIn(reportIds); + List results = apiDefinitionExecResultMapper.selectByExampleWithBLOBs(example); + // 格式化数据结果 + Map resultMap = results.stream().collect(Collectors.toMap(ApiDefinitionExecResult::getId, item -> item, (k, v) -> k)); + cases.forEach(item -> { + if (resultMap.get(item.getReportId()) != null && + StringUtils.isNotBlank(resultMap.get(item.getReportId()).getContent())) { + item.setResponse(resultMap.get(item.getReportId()).getContent()); + } + }); + } } } @@ -1563,9 +1578,9 @@ public class TestPlanService { List scenarioAllCases = null; if (checkReportConfig(config, "api", "all")) { // 接口 - apiAllCases = testPlanApiCaseService.getByApiExecReportIds(testPlanExecuteReportDTO.getTestPlanApiCaseIdAndReportIdMap(),testPlanExecuteReportDTO.getApiCaseInfoDTOMap()); + apiAllCases = testPlanApiCaseService.getByApiExecReportIds(testPlanExecuteReportDTO.getTestPlanApiCaseIdAndReportIdMap(), testPlanExecuteReportDTO.getApiCaseInfoDTOMap()); //场景 - scenarioAllCases = testPlanScenarioCaseService.getAllCases(testPlanExecuteReportDTO.getTestPlanScenarioIdAndReportIdMap(),testPlanExecuteReportDTO.getScenarioInfoDTOMap()); + scenarioAllCases = testPlanScenarioCaseService.getAllCases(testPlanExecuteReportDTO.getTestPlanScenarioIdAndReportIdMap(), testPlanExecuteReportDTO.getScenarioInfoDTOMap()); this.checkApiCaseCreatorName(apiAllCases, scenarioAllCases); report.setApiAllCases(apiAllCases); report.setScenarioAllCases(scenarioAllCases);