From 7dbef8d2a65f2cbde66830e4bce29be6983d758c Mon Sep 17 00:00:00 2001 From: guoyuqi Date: Tue, 20 Dec 2022 15:28:30 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=B5=8B=E8=AF=95=E8=B7=9F=E8=B8=AA):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=80=9A=E8=BF=87=E5=8A=9F=E8=83=BD=E7=94=A8?= =?UTF-8?q?=E4=BE=8B=E5=AF=BC=E5=85=A5=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92?= =?UTF-8?q?=E7=9A=84=E5=85=B6=E4=BB=96=E7=94=A8=E4=BE=8B=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E7=8E=AF=E5=A2=83=E5=AF=BC=E8=87=B4=E6=97=A0=E6=B3=95=E8=BF=90?= =?UTF-8?q?=E8=A1=8C=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1020897--user=郭雨琦 https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001020897 --- .../plan/TestPlanApiCaseController.java | 5 +++++ .../plan/TestPlanScenarioCaseController.java | 5 +++++ .../service/plan/TestPlanApiCaseService.java | 14 ++++++++++++++ .../plan/TestPlanScenarioCaseService.java | 14 ++++++++++++++ .../controller/TestPlanController.java | 5 +++++ .../plan/service/TestPlanService.java | 15 ++++++++++++++- .../remote/api/PlanTestPlanApiCaseService.java | 4 ++++ .../api/PlanTestPlanScenarioCaseService.java | 4 ++++ .../ui/PlanTestPlanUiScenarioCaseService.java | 4 ++++ .../frontend/src/api/remote/plan/test-plan.js | 12 ++++++++---- .../plan/common/TestPlanRunModeWithEnv.vue | 18 ++++++++++++++++-- 11 files changed, 93 insertions(+), 7 deletions(-) diff --git a/api-test/backend/src/main/java/io/metersphere/controller/plan/TestPlanApiCaseController.java b/api-test/backend/src/main/java/io/metersphere/controller/plan/TestPlanApiCaseController.java index 5da3252803..58869caa67 100644 --- a/api-test/backend/src/main/java/io/metersphere/controller/plan/TestPlanApiCaseController.java +++ b/api-test/backend/src/main/java/io/metersphere/controller/plan/TestPlanApiCaseController.java @@ -158,6 +158,11 @@ public class TestPlanApiCaseController { return testPlanApiCaseService.getApiCaseEnv(planId); } + @GetMapping("/get/project/ids/{planId}") + public List getApiCaseProjectIds(@PathVariable("planId") String planId) { + return testPlanApiCaseService.getApiCaseProjectIds(planId); + } + @GetMapping("/is/executing/{planId}") public Boolean isExecuting(@PathVariable("planId") String planId) { return testPlanApiCaseService.isExecuting(planId); diff --git a/api-test/backend/src/main/java/io/metersphere/controller/plan/TestPlanScenarioCaseController.java b/api-test/backend/src/main/java/io/metersphere/controller/plan/TestPlanScenarioCaseController.java index 70ae0cddbd..e0f79c2568 100644 --- a/api-test/backend/src/main/java/io/metersphere/controller/plan/TestPlanScenarioCaseController.java +++ b/api-test/backend/src/main/java/io/metersphere/controller/plan/TestPlanScenarioCaseController.java @@ -175,6 +175,11 @@ public class TestPlanScenarioCaseController { return testPlanScenarioCaseService.getApiScenarioEnv(planId); } + @GetMapping("/get/project/ids/{planId}") + public List getApiScenarioProjectIds(@PathVariable("planId") String planId) { + return testPlanScenarioCaseService.getApiScenarioProjectIds(planId); + } + @PostMapping("/plan/report") public ApiPlanReportDTO buildApiReport(@RequestBody ApiPlanReportRequest request) { return testPlanScenarioCaseService.buildApiReport(request); diff --git a/api-test/backend/src/main/java/io/metersphere/service/plan/TestPlanApiCaseService.java b/api-test/backend/src/main/java/io/metersphere/service/plan/TestPlanApiCaseService.java index e18a091aa1..4d726e1f00 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/plan/TestPlanApiCaseService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/plan/TestPlanApiCaseService.java @@ -817,4 +817,18 @@ public class TestPlanApiCaseService { List results = apiDefinitionExecResultMapper.selectByExampleWithBLOBs(example); return results; } + + public List getApiCaseProjectIds(String planId) { + TestPlanApiCaseExample caseExample = new TestPlanApiCaseExample(); + caseExample.createCriteria().andTestPlanIdEqualTo(planId); + List testPlanApiCases = testPlanApiCaseMapper.selectByExample(caseExample); + List apiCaseIds = testPlanApiCases.stream().map(TestPlanApiCase::getApiCaseId).collect(Collectors.toList()); + if (CollectionUtils.isEmpty(apiCaseIds)) { + return new ArrayList<>(); + } + ApiTestCaseExample example = new ApiTestCaseExample(); + example.createCriteria().andIdIn(apiCaseIds); + List apiTestCases = apiTestCaseMapper.selectByExample(example); + return apiTestCases.stream().map(ApiTestCase::getProjectId).collect(Collectors.toList()); + } } diff --git a/api-test/backend/src/main/java/io/metersphere/service/plan/TestPlanScenarioCaseService.java b/api-test/backend/src/main/java/io/metersphere/service/plan/TestPlanScenarioCaseService.java index f412017812..673eac2f64 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/plan/TestPlanScenarioCaseService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/plan/TestPlanScenarioCaseService.java @@ -1245,4 +1245,18 @@ public class TestPlanScenarioCaseService { public String selectProjectId(String testPlanId) { return extTestPlanScenarioCaseMapper.selectProjectId(testPlanId); } + + public List getApiScenarioProjectIds(String planId) { + TestPlanApiScenarioExample scenarioExample = new TestPlanApiScenarioExample(); + scenarioExample.createCriteria().andTestPlanIdEqualTo(planId); + List testPlanApiScenarios = testPlanApiScenarioMapper.selectByExample(scenarioExample); + List scenarioIds = testPlanApiScenarios.stream().map(TestPlanApiScenario::getApiScenarioId).collect(Collectors.toList()); + if (CollectionUtils.isEmpty(scenarioIds)) { + return new ArrayList<>(); + } + ApiScenarioExample example = new ApiScenarioExample(); + example.createCriteria().andIdIn(scenarioIds); + List apiScenarios = apiScenarioMapper.selectByExample(example); + return apiScenarios.stream().map(ApiScenario::getProjectId).collect(Collectors.toList()); + } } diff --git a/test-track/backend/src/main/java/io/metersphere/controller/TestPlanController.java b/test-track/backend/src/main/java/io/metersphere/controller/TestPlanController.java index 2a03aea7c8..e549627258 100644 --- a/test-track/backend/src/main/java/io/metersphere/controller/TestPlanController.java +++ b/test-track/backend/src/main/java/io/metersphere/controller/TestPlanController.java @@ -227,6 +227,11 @@ public class TestPlanController { return testPlanService.getPlanCaseEnv(plan.getId()); } + @PostMapping("/case/relevance/project/ids") + public List getRelevanceProjectIds(@RequestBody TestPlan plan) { + return testPlanService.getRelevanceProjectIds(plan.getId()); + } + @PostMapping("/edit/run/config") public void updateRunModeConfig(@RequestBody TestPlanRunRequest testplanRunRequest) { diff --git a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanService.java b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanService.java index 01e4cbc553..e31861e574 100644 --- a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanService.java +++ b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanService.java @@ -2059,7 +2059,7 @@ public class TestPlanService { } if (serviceIdSet.contains(MicroServiceName.UI_TEST)) { List apiDefinitionLists = planTestPlanUiScenarioCaseService.selectExtForPlanReport(reportId); - if(CollectionUtils.isNotEmpty(apiDefinitionLists)){ + if (CollectionUtils.isNotEmpty(apiDefinitionLists)) { UiScenarioReportWithBLOBs apiDefinition = apiDefinitionLists.get(0); convertEnvConfig(apiDefinition.getEnvConfig(), testPlanExtReportDTO); getResourcePool(apiDefinition.getActuator(), testPlanExtReportDTO); @@ -2068,4 +2068,17 @@ public class TestPlanService { } return testPlanExtReportDTO; } + + public List getRelevanceProjectIds(String planId) { + List projectIds = new ArrayList<>(); + List apiCaseProjectIds = planTestPlanApiCaseService.getApiCaseProjectIds(planId); + List apiScenarioProjectIds = planTestPlanScenarioCaseService.getApiScenarioProjectIds(planId); + if (DiscoveryUtil.hasService(MicroServiceName.UI_TEST)) { + List uiScenarioProjectIds = planTestPlanUiScenarioCaseService.getUiScenarioProjectIds(planId); + projectIds.addAll(uiScenarioProjectIds); + } + projectIds.addAll(apiCaseProjectIds); + projectIds.addAll(apiScenarioProjectIds); + return projectIds.stream().distinct().collect(Collectors.toList()); + } } diff --git a/test-track/backend/src/main/java/io/metersphere/plan/service/remote/api/PlanTestPlanApiCaseService.java b/test-track/backend/src/main/java/io/metersphere/plan/service/remote/api/PlanTestPlanApiCaseService.java index 90e593e214..0ce57537bf 100644 --- a/test-track/backend/src/main/java/io/metersphere/plan/service/remote/api/PlanTestPlanApiCaseService.java +++ b/test-track/backend/src/main/java/io/metersphere/plan/service/remote/api/PlanTestPlanApiCaseService.java @@ -131,6 +131,10 @@ public class PlanTestPlanApiCaseService extends ApiTestService { return (Map>) microService.getForData(serviceName, BASE_UEL + "/get/env/" + planId); } + public List getApiCaseProjectIds(String planId) { + return (List) microService.getForData(serviceName, BASE_UEL + "/get/project/ids/" + planId); + } + public Boolean isCaseExecuting(String planId) { return (Boolean) microService.getForData(serviceName, BASE_UEL + "/is/executing/" + planId); } diff --git a/test-track/backend/src/main/java/io/metersphere/plan/service/remote/api/PlanTestPlanScenarioCaseService.java b/test-track/backend/src/main/java/io/metersphere/plan/service/remote/api/PlanTestPlanScenarioCaseService.java index 1e9b4e6f19..e9344fd0e8 100644 --- a/test-track/backend/src/main/java/io/metersphere/plan/service/remote/api/PlanTestPlanScenarioCaseService.java +++ b/test-track/backend/src/main/java/io/metersphere/plan/service/remote/api/PlanTestPlanScenarioCaseService.java @@ -143,6 +143,10 @@ public class PlanTestPlanScenarioCaseService extends ApiTestService { return microService.getForData(serviceName, BASE_UEL + "/get/env/" + planId, Map.class); } + public List getApiScenarioProjectIds(String planId) { + return microService.getForData(serviceName, BASE_UEL + "/get/project/ids/" + planId, List.class); + } + public ApiPlanReportDTO getApiReport(ApiPlanReportRequest request) { return microService.postForData(serviceName, BASE_UEL + "/plan/report", request, ApiPlanReportDTO.class); } diff --git a/test-track/backend/src/main/java/io/metersphere/plan/service/remote/ui/PlanTestPlanUiScenarioCaseService.java b/test-track/backend/src/main/java/io/metersphere/plan/service/remote/ui/PlanTestPlanUiScenarioCaseService.java index bbd04cbbfd..a4cf43759e 100644 --- a/test-track/backend/src/main/java/io/metersphere/plan/service/remote/ui/PlanTestPlanUiScenarioCaseService.java +++ b/test-track/backend/src/main/java/io/metersphere/plan/service/remote/ui/PlanTestPlanUiScenarioCaseService.java @@ -157,4 +157,8 @@ public class PlanTestPlanUiScenarioCaseService extends UiTestService { public Map> getUiScenarioEnv(String planId) { return microService.getForData(serviceName, BASE_URL + "/get/env/" + planId, Map.class); } + + public List getUiScenarioProjectIds(String planId) { + return microService.getForData(serviceName, BASE_URL + "/get/project/ids/" + planId, List.class); + } } diff --git a/test-track/frontend/src/api/remote/plan/test-plan.js b/test-track/frontend/src/api/remote/plan/test-plan.js index bd663bd004..ed209ce08e 100644 --- a/test-track/frontend/src/api/remote/plan/test-plan.js +++ b/test-track/frontend/src/api/remote/plan/test-plan.js @@ -289,12 +289,16 @@ export function updateSchedule(param){ return post(BASE_URL + 'schedule/update',param); } -export function getApiScenarioEnv(param){ - return post(BASE_URL + 'api/scenario/env',param); +export function getApiScenarioEnv(param) { + return post(BASE_URL + 'api/scenario/env', param); } -export function getPlanCaseEnv(param){ - return post(BASE_URL + 'case/env',param); +export function getPlanCaseEnv(param) { + return post(BASE_URL + 'case/env', param); +} + +export function getPlanCaseProjectIds(param) { + return post(BASE_URL + 'case/relevance/project/ids', param); } export function run(testId, reportId) { diff --git a/test-track/frontend/src/business/plan/common/TestPlanRunModeWithEnv.vue b/test-track/frontend/src/business/plan/common/TestPlanRunModeWithEnv.vue index b4d40a763a..eee3536ba5 100644 --- a/test-track/frontend/src/business/plan/common/TestPlanRunModeWithEnv.vue +++ b/test-track/frontend/src/business/plan/common/TestPlanRunModeWithEnv.vue @@ -200,7 +200,7 @@ import {getCurrentProjectID, getOwnerProjects} from "@/business/utils/sdk-utils" import {getQuotaValidResourcePools} from "@/api/remote/resource-pool"; import EnvGroupPopover from "@/business/plan/env/EnvGroupPopover"; import {getApiCaseEnv} from "@/api/remote/plan/test-plan-api-case"; -import {getApiScenarioEnv, getPlanCaseEnv} from "@/api/remote/plan/test-plan"; +import {getApiScenarioEnv, getPlanCaseEnv, getPlanCaseProjectIds} from "@/api/remote/plan/test-plan"; import EnvGroupWithOption from "../env/EnvGroupWithOption"; import EnvironmentGroup from "@/business/plan/env/EnvironmentGroupList"; import EnvSelectPopover from "@/business/plan/env/EnvSelectPopover"; @@ -402,9 +402,23 @@ export default { this.projectIds.add(d); } } - this.$refs.envSelectPopover.open(); + if (this.projectIds.size === 0) { + param = {id: this.planId}; + getPlanCaseProjectIds(param).then((res) => { + let data = res.data; + if (data) { + for (let i = 0; i < data.length; i++) { + this.projectIds.add(data[i]); + } + } + this.$refs.envSelectPopover.open(); + }); + } else { + this.$refs.envSelectPopover.open(); + } }); } + }, handleCommand(command) { if (