From 8f43deaf41af42d52cd0320a585b88dcbe6f195a Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Tue, 25 May 2021 19:01:57 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E6=B5=8B=E8=AF=95=E7=94=A8?= =?UTF-8?q?=E4=BE=8B=E6=A8=A1=E5=9D=97=E6=A0=91=E5=8A=A0=E8=BD=BD=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/service/ApiModuleService.java | 7 +- .../mapper/ext/ExtApiDefinitionMapper.java | 4 +- .../mapper/ext/ExtApiDefinitionMapper.xml | 97 ++++++++++--------- 3 files changed, 57 insertions(+), 51 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/service/ApiModuleService.java b/backend/src/main/java/io/metersphere/api/service/ApiModuleService.java index 09e88479e8..a227616dc8 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiModuleService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiModuleService.java @@ -93,16 +93,11 @@ public class ApiModuleService extends NodeTreeService { moduleIds = this.nodeList(apiModules, node.getId(), moduleIds); moduleIds.add(node.getId()); request.setModuleIds(moduleIds); - int num = this.getCaseNum(request); - node.setCaseNum(num); + node.setCaseNum(extApiDefinitionMapper.moduleCount(request)); }); return getNodeTrees(apiModules); } - private int getCaseNum(ApiDefinitionRequest request) { - return extApiDefinitionMapper.list(request).size(); - } - public static List nodeList(List apiNodes, String pid, List list) { for (ApiModuleDTO node : apiNodes) { //遍历出父id等于参数的id,add进子节点集合 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 37f919f171..bc48afd234 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,6 +17,8 @@ public interface ExtApiDefinitionMapper { List list(@Param("request") ApiDefinitionRequest request); + int moduleCount(@Param("request") ApiDefinitionRequest request); + //List selectByIds(@Param("ids") List ids); List selectByIds(@Param("ids") List ids, @Param("projectId") String projectId); @@ -46,4 +48,4 @@ public interface ExtApiDefinitionMapper { List selectEffectiveIdByProjectId(String projectId); List listByIds(@Param("ids") List ids); -} \ No newline at end of file +} 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 76f2f11a2a..bdda804945 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 @@ -487,6 +487,40 @@ WHERE project_id = #{0} AND status != 'Trash' AND protocol = 'HTTP' + + + + + + + + + and api_definition.status in + + #{value} + + + + and api_definition.method in + + #{value} + + + + and api_definition.user_id in + + #{value} + + + + + + + + @@ -504,12 +538,6 @@ AND api_definition.protocol = #{request.protocol} - - AND project.workspace_id = #{request.workspaceId} - - - AND project.id = #{request.projectId} - AND api_definition.id = #{request.id} @@ -522,41 +550,24 @@ AND api_definition.module_id = #{request.moduleId} - - AND api_definition.project_id = #{request.projectId} - - - AND api_definition.module_id in - - #{nodeId} - - - - - - - - and api_definition.status in - - #{value} - - - - and api_definition.method in - - #{value} - - - - and api_definition.user_id in - - #{value} - - - - - - + + + AND api_definition.module_id in + + #{nodeId} + + + + AND api_definition.project_id = #{request.projectId} + + + AND project.id = #{request.projectId} + + + AND project.workspace_id = #{request.workspaceId} + + + and api_definition.id not in (SELECT api_definition_id FROM api_test_case) @@ -565,8 +576,6 @@ and api_definition.id in (SELECT api_definition_id FROM api_test_case) - - - \ No newline at end of file +