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