From a28ef40419c8a9af586132523b83a6800e5eb9c6 Mon Sep 17 00:00:00 2001 From: xiongxiaoqing Date: Wed, 14 Apr 2021 22:02:50 +0800 Subject: [PATCH] Exclude case from other project when counting total case --- .../metersphere/api/service/ApiDefinitionService.java | 10 +++++----- .../base/mapper/ext/ExtApiDefinitionMapper.java | 4 +++- .../base/mapper/ext/ExtApiDefinitionMapper.xml | 1 + 3 files changed, 9 insertions(+), 6 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 13e1023985..51d4720c5a 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java @@ -108,7 +108,7 @@ public class ApiDefinitionService { public List list(ApiDefinitionRequest request) { request = this.initRequest(request, true, true); List resList = extApiDefinitionMapper.list(request); - calculateResult(resList); + calculateResult(resList, request.getProjectId()); return resList; } @@ -839,21 +839,21 @@ public class ApiDefinitionService { public List listRelevance(ApiDefinitionRequest request) { request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders())); List resList = extApiDefinitionMapper.listRelevance(request); - calculateResult(resList); + calculateResult(resList, request.getProjectId()); return resList; } public List listRelevanceReview(ApiDefinitionRequest request) { request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders())); List resList = extApiDefinitionMapper.listRelevanceReview(request); - calculateResult(resList); + calculateResult(resList, request.getProjectId()); return resList; } - public void calculateResult(List resList) { + public void calculateResult(List resList, String projectId) { if (!resList.isEmpty()) { List ids = resList.stream().map(ApiDefinitionResult::getId).collect(Collectors.toList()); - List results = extApiDefinitionMapper.selectByIds(ids); + List results = extApiDefinitionMapper.selectByIds(ids, projectId); Map resultMap = results.stream().collect(Collectors.toMap(ApiComputeResult::getApiDefinitionId, Function.identity())); for (ApiDefinitionResult res : resList) { ApiComputeResult compRes = resultMap.get(res.getId()); 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 d7c94b2436..37f919f171 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 @@ -17,7 +17,9 @@ public interface ExtApiDefinitionMapper { List list(@Param("request") ApiDefinitionRequest request); - List selectByIds(@Param("ids") List ids); + //List selectByIds(@Param("ids") List ids); + + List selectByIds(@Param("ids") List ids, @Param("projectId") String projectId); int removeToGc(@Param("ids") List ids); 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 207d5b9bb3..76f2f11a2a 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 @@ -93,6 +93,7 @@ CONCAT(FORMAT(SUM(IF (t2.`status`='success',1,0))/COUNT(t1.id)*100,2),'%') passRate FROM api_test_case t1 LEFT JOIN api_definition_exec_result t2 ON t1.last_result_id=t2.id + WHERE t1.project_id = #{projectId} group by t1.api_definition_id having t1.api_definition_id in #{v}