diff --git a/backend/src/main/java/io/metersphere/api/controller/ApiDefinitionController.java b/backend/src/main/java/io/metersphere/api/controller/ApiDefinitionController.java index 6be94e45a0..99180bed1d 100644 --- a/backend/src/main/java/io/metersphere/api/controller/ApiDefinitionController.java +++ b/backend/src/main/java/io/metersphere/api/controller/ApiDefinitionController.java @@ -41,6 +41,13 @@ public class ApiDefinitionController { return PageUtils.setPageInfo(page, apiDefinitionService.list(request)); } + @PostMapping("/list/relevance/{goPage}/{pageSize}") + public Pager> listRelevance(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody ApiDefinitionRequest request) { + Page page = PageHelper.startPage(goPage, pageSize, true); + request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId()); + return PageUtils.setPageInfo(page, apiDefinitionService.listRelevance(request)); + } + @PostMapping("/list/all") public List list(@RequestBody ApiDefinitionRequest request) { return apiDefinitionService.list(request); diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/ApiDefinitionRequest.java b/backend/src/main/java/io/metersphere/api/dto/definition/ApiDefinitionRequest.java index 2a3cb83eea..9c18000c7d 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/ApiDefinitionRequest.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/ApiDefinitionRequest.java @@ -20,6 +20,7 @@ public class ApiDefinitionRequest { private String name; private String workspaceId; private String userId; + private String planId; private boolean recent = false; private List orders; private List filters; 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 da1c4eed4a..e1ca7a75a0 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java @@ -78,23 +78,7 @@ public class ApiDefinitionService { public List list(ApiDefinitionRequest request) { request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders())); List resList = extApiDefinitionMapper.list(request); - if (!resList.isEmpty()) { - List ids = resList.stream().map(ApiDefinitionResult::getId).collect(Collectors.toList()); - List results = extApiDefinitionMapper.selectByIds(ids); - 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.setCaseTotal(compRes.getCaseTotal()); - res.setCasePassingRate(compRes.getPassRate()); - res.setCaseStatus(compRes.getStatus()); - } else { - res.setCaseTotal("-"); - res.setCasePassingRate("-"); - res.setCaseStatus("-"); - } - } - } + calculateResult(resList); return resList; } @@ -466,4 +450,31 @@ public class ApiDefinitionService { example.createCriteria().andIdIn(ids); return apiDefinitionMapper.selectByExample(example); } + + public List listRelevance(ApiDefinitionRequest request) { + request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders())); + List resList = extApiDefinitionMapper.listRelevance(request); + calculateResult(resList); + return resList; + } + + public void calculateResult(List resList) { + if (!resList.isEmpty()) { + List ids = resList.stream().map(ApiDefinitionResult::getId).collect(Collectors.toList()); + List results = extApiDefinitionMapper.selectByIds(ids); + 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.setCaseTotal(compRes.getCaseTotal()); + res.setCasePassingRate(compRes.getPassRate()); + res.setCaseStatus(compRes.getStatus()); + } else { + res.setCaseTotal("-"); + res.setCasePassingRate("-"); + res.setCaseStatus("-"); + } + } + } + } } 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 30702b8122..e4576036f1 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 @@ -28,4 +28,6 @@ public interface ExtApiDefinitionMapper { List countApiCoverageByProjectID(String projectId); ApiDefinition getNextNum(@Param("projectId") String projectId); + + List listRelevance(@Param("request")ApiDefinitionRequest request); } \ 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 c6c91a5300..869ed0906f 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 @@ -295,4 +295,52 @@ + + \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanApiCaseMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanApiCaseMapper.xml index 55291b8a4d..d126e3372c 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanApiCaseMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanApiCaseMapper.xml @@ -19,7 +19,7 @@ select t.id, t.environment_id, t.create_time, t.update_time, c.id as case_id, c.project_id, c.name, c.api_definition_id, c.priority, c.description, c.create_user_id, c.update_user_id, - a.module_id, a.path, a.protocol, ader.status execResult + a.module_id, a.path, a.protocol, t.status execResult from test_plan_api_case t inner join @@ -32,24 +32,6 @@ api_definition a on c.api_definition_id = a.id - left join ( - select - e.status, e.id, e.resource_id - from - api_definition_exec_result e - left join ( - select - max(start_time) start_time , resource_id - from - api_definition_exec_result - group by - resource_id - ) as b - on e.resource_id = b.resource_id - where - e.start_time = b.start_time and e.type = 'API_PLAN' - ) as ader - on t.id = ader.resource_id and a.protocol = #{request.protocol} diff --git a/frontend/src/business/components/api/automation/scenario/api/RelevanceApiList.vue b/frontend/src/business/components/api/automation/scenario/api/RelevanceApiList.vue index 2ec3dfe33a..0ef1ed56f5 100644 --- a/frontend/src/business/components/api/automation/scenario/api/RelevanceApiList.vue +++ b/frontend/src/business/components/api/automation/scenario/api/RelevanceApiList.vue @@ -156,6 +156,7 @@ default: false, }, projectId: String, + planId: String, isTestPlan: Boolean }, created: function () { @@ -194,7 +195,12 @@ if (this.currentProtocol != null) { this.condition.protocol = this.currentProtocol; } - this.result = this.$post("/api/definition/list/" + this.currentPage + "/" + this.pageSize, this.condition, response => { + let url = '/api/definition/list/'; + if (this.isTestPlan) { + url = '/api/definition/list/relevance/'; + this.condition.planId = this.planId; + } + this.result = this.$post(url + this.currentPage + "/" + this.pageSize, this.condition, response => { this.total = response.data.itemCount; this.tableData = response.data.listObject; }); diff --git a/frontend/src/business/components/track/plan/view/comonents/api/TestCaseApiRelevance.vue b/frontend/src/business/components/track/plan/view/comonents/api/TestCaseApiRelevance.vue index a4d9f046f4..2f52de0af6 100644 --- a/frontend/src/business/components/track/plan/view/comonents/api/TestCaseApiRelevance.vue +++ b/frontend/src/business/components/track/plan/view/comonents/api/TestCaseApiRelevance.vue @@ -23,6 +23,7 @@ :is-api-list-enable="isApiListEnable" :project-id="projectId" :is-test-plan="true" + :plan-id="planId" @isApiListEnableChange="isApiListEnableChange" ref="apiList"/>