From a2c6ba1b889e11027f3f6174278fb54785931210 Mon Sep 17 00:00:00 2001 From: AgAngle <1323481023@qq.com> Date: Mon, 25 Mar 2024 20:34:20 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E6=89=B9=E9=87=8F=E6=89=A7=E8=A1=8C=E5=90=8C=E4=B8=80=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E5=AE=9A=E4=B9=89=E4=B8=8B=E7=9A=84=E5=A4=9A=E4=B8=AA?= =?UTF-8?q?=E7=94=A8=E4=BE=8B=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/parser/step/ApiStepParser.java | 1 - .../definition/ApiTestCaseService.java | 38 ++++++++++++++----- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/parser/step/ApiStepParser.java b/backend/services/api-test/src/main/java/io/metersphere/api/parser/step/ApiStepParser.java index 76b34b805f..3ab48ceb49 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/parser/step/ApiStepParser.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/parser/step/ApiStepParser.java @@ -62,7 +62,6 @@ public class ApiStepParser extends StepParser { } else { return parse2MsTestElement(getStepBlobString(step.getId())); } - } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiTestCaseService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiTestCaseService.java index 096b72b8bf..66ca168807 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiTestCaseService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiTestCaseService.java @@ -559,21 +559,35 @@ public class ApiTestCaseService extends MoveNodeService { apiTestCaseMapper.updateByPrimaryKeySelective(update); } - public List getModuleInfoByIds(List ids) { + public List getModuleInfoByIds(List apiCaseIds) { // 获取接口定义ID和用例ID的映射 - Map apiCaseDefinitionMap = extApiTestCaseMapper.getApiCaseDefinitionInfo(ids) - .stream() - .collect(Collectors.toMap(ApiTestCase::getApiDefinitionId, ApiTestCase::getId)); + List apiTestCases = extApiTestCaseMapper.getApiCaseDefinitionInfo(apiCaseIds); + + List definitionIds = apiTestCases.stream() + .map(ApiTestCase::getApiDefinitionId) + .distinct() + .toList(); - List definitionIds = apiCaseDefinitionMap.keySet().stream().collect(Collectors.toList()); if (CollectionUtils.isEmpty(definitionIds)) { return List.of(); } - List definitionExecuteInfos = extApiDefinitionMapper.getApiDefinitionExecuteInfo(definitionIds); - // 将 resourceId 从定义ID替换成用例ID - definitionExecuteInfos.forEach(info -> - info.setResourceId(apiCaseDefinitionMap.get(info.getResourceId()))); - return definitionExecuteInfos; + + Map definitionExecuteInfoMap = extApiDefinitionMapper.getApiDefinitionExecuteInfo(definitionIds).stream() + .collect(Collectors.toMap(ApiDefinitionExecuteInfo::getResourceId, Function.identity())); + + return apiTestCases.stream().map(apiTestCase -> { + ApiDefinitionExecuteInfo apiDefinitionExecuteInfo = definitionExecuteInfoMap.get(apiTestCase.getApiDefinitionId()); + if (apiDefinitionExecuteInfo == null) { + return null; + } else { + // 将 resourceId 从定义ID替换成用例ID + apiDefinitionExecuteInfo = BeanUtils.copyBean(new ApiDefinitionExecuteInfo(), apiDefinitionExecuteInfo); + apiDefinitionExecuteInfo.setResourceId(apiTestCase.getId()); + return apiDefinitionExecuteInfo; + } + }) + .filter(item -> item != null) + .toList(); } public void handleFileAssociationUpgrade(FileAssociation originFileAssociation, FileMetadata newFileMetadata) { @@ -602,6 +616,7 @@ public class ApiTestCaseService extends MoveNodeService { /** * 接口执行 * 传请求详情执行 + * * @param request * @return */ @@ -615,6 +630,7 @@ public class ApiTestCaseService extends MoveNodeService { /** * 接口执行 * 传ID执行 + * * @param id * @param reportId * @param userId @@ -633,6 +649,7 @@ public class ApiTestCaseService extends MoveNodeService { /** * 接口执行 * 保存报告 + * * @param runRequest * @param apiTestCase * @param reportId @@ -664,6 +681,7 @@ public class ApiTestCaseService extends MoveNodeService { /** * 接口调试 * 不存报告,实时获取结果 + * * @param request * @return */