From c4bc0ce27bd71575c261f3fd0d4e7062a265437f Mon Sep 17 00:00:00 2001 From: wxg0103 <727495428@qq.com> Date: Tue, 23 Aug 2022 19:49:03 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E5=AE=9A=E4=B9=89):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=8E=A5=E5=8F=A3=E5=AE=9A=E4=B9=89=E5=9B=9E?= =?UTF-8?q?=E6=94=B6=E7=AB=99=E7=94=A8=E4=BE=8B=E6=95=B0=E4=B8=BA0?= =?UTF-8?q?=E7=9A=84=E7=BC=BA=E9=99=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1016199 --user=王孝刚 【接口测试】回收站-api-用例数显示为0(api下有case) https://www.tapd.cn/55049933/s/1231791 --- .../api/service/ApiDefinitionService.java | 63 ++++++++++++------- .../mapper/ext/ExtApiDefinitionMapper.java | 2 + .../mapper/ext/ExtApiDefinitionMapper.xml | 14 +++++ 3 files changed, 56 insertions(+), 23 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java index e87feae42b..b644c82d29 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java @@ -183,7 +183,7 @@ public class ApiDefinitionService { buildUserInfo(resList); if (StringUtils.isNotBlank(request.getProjectId())) { buildProjectInfo(resList, request.getProjectId()); - calculateResult(resList, request.getProjectId()); + calculateResult(resList, request.getProjectId(), request); } else { buildProjectInfoWithoutProject(resList); } @@ -2119,31 +2119,48 @@ public class ApiDefinitionService { if (!resList.isEmpty()) { List ids = resList.stream().map(ApiDefinitionResult::getId).collect(Collectors.toList()); List results = extApiDefinitionMapper.selectByIdsAndStatusIsNotTrash(ids, projectId); - Map resultMap = results.stream().collect(Collectors.toMap(ApiComputeResult::getApiDefinitionId, Function.identity())); - for (ApiDefinitionResult res : resList) { - ApiComputeResult compRes = resultMap.get(res.getId()); - if (compRes != null) { - res.setCaseType("apiCase"); - res.setCaseTotal(String.valueOf(compRes.getCaseTotal())); - res.setCasePassingRate(compRes.getPassRate()); - // 状态优先级 未执行,未通过,通过 - if ((compRes.getError() + compRes.getSuccess()) < compRes.getCaseTotal()) { - res.setCaseStatus(Translator.get("not_execute")); - } else if (compRes.getError() > 0) { - res.setCaseStatus(Translator.get("execute_not_pass")); - } else { - res.setCaseStatus(Translator.get("execute_pass")); - } + calculateResultList(resList, results); + } + } + + private void calculateResultList(List resList, List results) { + Map resultMap = results.stream().collect(Collectors.toMap(ApiComputeResult::getApiDefinitionId, Function.identity())); + for (ApiDefinitionResult res : resList) { + ApiComputeResult compRes = resultMap.get(res.getId()); + if (compRes != null) { + res.setCaseType("apiCase"); + res.setCaseTotal(String.valueOf(compRes.getCaseTotal())); + res.setCasePassingRate(compRes.getPassRate()); + // 状态优先级 未执行,未通过,通过 + if ((compRes.getError() + compRes.getSuccess()) < compRes.getCaseTotal()) { + res.setCaseStatus(Translator.get("not_execute")); + } else if (compRes.getError() > 0) { + res.setCaseStatus(Translator.get("execute_not_pass")); } else { - res.setCaseType("apiCase"); - res.setCaseTotal("0"); - res.setCasePassingRate("-"); - res.setCaseStatus("-"); - } - if (StringUtils.equalsIgnoreCase("esb", res.getMethod())) { - esbApiParamService.handleApiEsbParams(res); + res.setCaseStatus(Translator.get("execute_pass")); } + } else { + res.setCaseType("apiCase"); + res.setCaseTotal("0"); + res.setCasePassingRate("-"); + res.setCaseStatus("-"); } + if (StringUtils.equalsIgnoreCase("esb", res.getMethod())) { + esbApiParamService.handleApiEsbParams(res); + } + } + } + + public void calculateResult(List resList, String projectId, ApiDefinitionRequest request) { + if (!resList.isEmpty()) { + List ids = resList.stream().map(ApiDefinitionResult::getId).collect(Collectors.toList()); + List results = new ArrayList<>(); + if (request != null && request.getFilters().containsKey("status") && request.getFilters().get("status").get(0).equals("Trash")) { + results = extApiDefinitionMapper.selectByIdsAndStatusIsTrash(ids, projectId); + } else { + results = extApiDefinitionMapper.selectByIdsAndStatusIsNotTrash(ids, projectId); + } + calculateResultList(resList, results); } } diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionMapper.java b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionMapper.java index 7b25afb3dd..53bdeecbb5 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionMapper.java +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionMapper.java @@ -37,6 +37,8 @@ public interface ExtApiDefinitionMapper { List selectByIdsAndStatusIsNotTrash(@Param("ids") List ids, @Param("projectId") String projectId); + List selectByIdsAndStatusIsTrash(@Param("ids") List ids, @Param("projectId") String projectId); + // int removeToGc(@Param("ids") List ids); int removeToGcByExample(ApiDefinitionExampleWithOperation example); diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionMapper.xml index c696ad945a..0a4ebbe764 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionMapper.xml @@ -131,6 +131,20 @@ + + and api_definition.name