From 3812c7b1d905338533341a0a0a1560f48735ad85 Mon Sep 17 00:00:00 2001 From: song-tianyang Date: Fri, 21 Apr 2023 13:45:46 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92):=20?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92UI?= =?UTF-8?q?=E7=94=A8=E4=BE=8B=E6=97=B6=E4=B8=8D=E5=86=8D=E5=BE=AA=E7=8E=AF?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E6=89=80=E5=B1=9E=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1025646 --user=宋天阳 【测试跟踪】测试计划-进入接口场景和UI用例列表-每个用例都会调用一次环境接口 https://www.tapd.cn/55049933/s/1365167 --- .../api/dto/automation/ApiScenarioDTO.java | 2 + .../service/EnvironmentService.java | 52 ++ .../plan/TestPlanScenarioCaseService.java | 44 +- .../comonents/api/TestPlanApiScenarioList.vue | 121 ++- .../comonents/ui/TestPlanUiScenarioList.vue | 700 ++++++++++-------- 5 files changed, 532 insertions(+), 387 deletions(-) create mode 100644 api-test/backend/src/main/java/io/metersphere/service/EnvironmentService.java diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/automation/ApiScenarioDTO.java b/api-test/backend/src/main/java/io/metersphere/api/dto/automation/ApiScenarioDTO.java index 5bb3c8fe60..882e509ce6 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/dto/automation/ApiScenarioDTO.java +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/automation/ApiScenarioDTO.java @@ -35,4 +35,6 @@ public class ApiScenarioDTO extends ApiScenarioWithBLOBs { private String creator; private String workspaceName; private String workspaceId; + //用于测试计划场景表格中环境展示 + private Map tableShowEnv; } diff --git a/api-test/backend/src/main/java/io/metersphere/service/EnvironmentService.java b/api-test/backend/src/main/java/io/metersphere/service/EnvironmentService.java new file mode 100644 index 0000000000..4f7c44dc09 --- /dev/null +++ b/api-test/backend/src/main/java/io/metersphere/service/EnvironmentService.java @@ -0,0 +1,52 @@ +package io.metersphere.service; + +import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs; +import io.metersphere.base.domain.Project; +import io.metersphere.base.mapper.ApiTestEnvironmentMapper; +import io.metersphere.environment.service.BaseEnvGroupProjectService; +import jakarta.annotation.Resource; +import jakarta.transaction.Transactional; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Service; + +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +@Service +@Transactional +public class EnvironmentService { + @Resource + private BaseEnvGroupProjectService envGroupProjectService; + @Resource + private ApiTestEnvironmentMapper apiTestEnvironmentMapper; + @Resource + private BaseProjectService baseProjectService; + + public Map getEnvNameMap(String groupId) { + Map map = envGroupProjectService.getEnvMap(groupId); + Set set = map.keySet(); + HashMap envMap = new HashMap<>(16); + if (set.isEmpty()) { + return envMap; + } + for (String projectId : set) { + String envId = map.get(projectId); + if (StringUtils.isBlank(envId)) { + continue; + } + Project project = baseProjectService.getProjectById(projectId); + ApiTestEnvironmentWithBLOBs environment = apiTestEnvironmentMapper.selectByPrimaryKey(envId); + if (project == null || environment == null) { + continue; + } + String projectName = project.getName(); + String envName = environment.getName(); + if (StringUtils.isBlank(projectName) || StringUtils.isBlank(envName)) { + continue; + } + envMap.put(projectName, envName); + } + return envMap; + } +} 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 fb2b9da5a0..5aa601ae75 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 @@ -34,10 +34,7 @@ import io.metersphere.environment.service.BaseEnvironmentService; import io.metersphere.i18n.Translator; import io.metersphere.log.vo.OperatingLogDetails; import io.metersphere.request.ResetOrderRequest; -import io.metersphere.service.BaseProjectApplicationService; -import io.metersphere.service.BaseProjectService; -import io.metersphere.service.BaseUserService; -import io.metersphere.service.ServiceUtils; +import io.metersphere.service.*; import io.metersphere.service.definition.ApiDefinitionExecResultService; import io.metersphere.service.plan.remote.TestPlanService; import io.metersphere.service.scenario.ApiScenarioModuleService; @@ -111,19 +108,46 @@ public class TestPlanScenarioCaseService { @Lazy @Resource private ApiScenarioReportStructureService apiScenarioReportStructureService; + @Resource + private EnvironmentService environmentService; public List list(TestPlanScenarioRequest request) { request.setProjectId(null); request.setOrders(ServiceUtils.getDefaultSortOrder(request.getOrders())); - List apiTestCases = extTestPlanScenarioCaseMapper.list(request); - if (CollectionUtils.isEmpty(apiTestCases)) { - return apiTestCases; + List scenarioDTOList = extTestPlanScenarioCaseMapper.list(request); + if (CollectionUtils.isEmpty(scenarioDTOList)) { + return scenarioDTOList; } - buildProjectInfo(apiTestCases); - buildUserInfo(apiTestCases); - return apiTestCases; + buildProjectInfo(scenarioDTOList); + buildUserInfo(scenarioDTOList); + return buildEnvironment(scenarioDTOList); } + private List buildEnvironment(List scenarioDTOList) { + List returnData = new ArrayList<>(); + + scenarioDTOList.forEach(scenario -> { + if (StringUtils.equalsIgnoreCase(scenario.getEnvironmentType(), EnvironmentType.GROUP.name())) { + if (StringUtils.isNotEmpty(scenario.getEnvironmentGroupId())) { + Map map = environmentService.getEnvNameMap(scenario.getEnvironmentGroupId()); + scenario.setTableShowEnv(map); + } + } else if (StringUtils.equalsIgnoreCase(scenario.getEnvironmentType(), EnvironmentType.JSON.name())) { + try { + if (StringUtils.isNotEmpty(scenario.getEnvironment())) { + Map environmentMap = this.getScenarioCaseEnv(JSON.parseMap(scenario.getEnvironment())); + scenario.setTableShowEnv(environmentMap); + } + } catch (Exception e) { + LogUtil.error("测试计划场景环境解析报错!", e); + } + } + returnData.add(scenario); + }); + return returnData; + } + + public void buildProjectInfo(List apiTestCases) { List projectIds = apiTestCases.stream() .map(ApiScenarioDTO::getProjectId) diff --git a/test-track/frontend/src/business/plan/view/comonents/api/TestPlanApiScenarioList.vue b/test-track/frontend/src/business/plan/view/comonents/api/TestPlanApiScenarioList.vue index e687882264..b1c92d10c2 100644 --- a/test-track/frontend/src/business/plan/view/comonents/api/TestPlanApiScenarioList.vue +++ b/test-track/frontend/src/business/plan/view/comonents/api/TestPlanApiScenarioList.vue @@ -87,7 +87,7 @@ :filters="apiscenariofilters.LEVEL_FILTERS" > @@ -107,16 +107,16 @@ {{ k }} -
+
{{ v }}: + >{{ v }}: {{ - k - }}
+ k + }}
+ +
+
+ +
+
+ - - + + - +
@@ -268,7 +274,7 @@ @close="search" /> - + @@ -280,7 +286,7 @@ import { getCurrentProjectID, getCurrentWorkspaceId, } from "metersphere-frontend/src/utils/token"; -import {getUUID, strMapToObj} from "metersphere-frontend/src/utils"; +import { getUUID, strMapToObj } from "metersphere-frontend/src/utils"; import { hasLicense, hasPermission, @@ -293,36 +299,31 @@ import { getCustomTableWidth, initCondition, } from "metersphere-frontend/src/utils/tableUtils"; -import { - ENV_TYPE, - TEST_PLAN_SCENARIO_CASE, -} from "metersphere-frontend/src/utils/constants"; +import { TEST_PLAN_SCENARIO_CASE } from "metersphere-frontend/src/utils/constants"; import HeaderLabelOperate from "metersphere-frontend/src/components/head/HeaderLabelOperate"; import BatchEdit from "@/business/case/components/BatchEdit"; import MsPlanRunMode from "@/business/plan/common/PlanRunModeWithEnv"; import PriorityTableItem from "@/business/common/tableItems/planview/PriorityTableItem"; -import {API_SCENARIO_FILTERS} from "metersphere-frontend/src/utils/table-constants"; +import { API_SCENARIO_FILTERS } from "metersphere-frontend/src/utils/table-constants"; import MsTaskCenter from "metersphere-frontend/src/components/task/TaskCenter"; import MsTable from "metersphere-frontend/src/components/table/MsTable"; import MsTableColumn from "metersphere-frontend/src/components/table/MsTableColumn"; import MsUpdateTimeColumn from "metersphere-frontend/src/components/table/MsUpdateTimeColumn"; import MsCreateTimeColumn from "metersphere-frontend/src/components/table/MsCreateTimeColumn"; -import {editTestPlanScenarioCaseOrder} from "@/api/remote/plan/test-plan"; +import { editTestPlanScenarioCaseOrder } from "@/api/remote/plan/test-plan"; import { testPlanScenarioCaseBatchDelete, testPlanScenarioCaseBatchUpdateEnv, testPlanScenarioCaseDelete, testPlanScenarioCaseRun, testPlanScenarioCaseSelectAllTableRows, - testPlanScenarioEnv, testPlanScenarioList, } from "@/api/remote/plan/test-plan-scenario"; -import {environmentGroupGetProjectMapName} from "@/api/environment-group"; -import {apiAutomationReduction} from "@/api/remote/api/api-automation"; +import { apiAutomationReduction } from "@/api/remote/api/api-automation"; import MicroApp from "metersphere-frontend/src/components/MicroApp"; import MsTestPlanApiStatus from "@/business/plan/view/comonents/api/TestPlanApiStatus"; -import {getVersionFilters} from "@/business/utils/sdk-utils"; -import {TEST_PLAN_API_SCENARIO_CONFIGS} from "metersphere-frontend/src/components/search/search-components"; +import { getVersionFilters } from "@/business/utils/sdk-utils"; +import { TEST_PLAN_API_SCENARIO_CONFIGS } from "metersphere-frontend/src/components/search/search-components"; import MsTestPlanRunModeWithEnv from "@/business/plan/common/TestPlanRunModeWithEnv"; export default { @@ -484,7 +485,7 @@ export default { if (this.planId) { this.condition.planId = this.planId; testPlanScenarioList( - {pageNum: this.currentPage, pageSize: this.pageSize}, + { pageNum: this.currentPage, pageSize: this.pageSize }, this.condition ).then((response) => { let data = response.data; @@ -497,25 +498,9 @@ export default { }); this.tableData.forEach((item) => { try { - let envs; - const type = item.environmentType; - if (type === ENV_TYPE.GROUP && item.environmentGroupId) { - environmentGroupGetProjectMapName(item.environmentGroupId).then( - (res) => { - let data = res.data; - if (data) { - envs = new Map(Object.entries(data)); - this.$set(item, "envs", res.data); - } - } - ); - } else if (type === ENV_TYPE.JSON) { - envs = JSON.parse(item.environment); - if (envs) { - testPlanScenarioEnv(envs).then((res) => { - this.$set(item, "envs", res.data); - }); - } + let data = item.tableShowEnv; + if (data) { + this.$set(item, "envs", data); } } catch (error) { this.$set(item, "envs", {}); @@ -558,7 +543,7 @@ export default { let rows = this.orderBySelectRows(this.$refs.table.selectRows); if (this.planId) { let selectParam = buildBatchParam(this); - let param = {config: config, planCaseIds: []}; + let param = { config: config, planCaseIds: [] }; param.ids = rows.map((r) => r.id); rows.forEach((row) => { this.buildExecuteParam(param, row); @@ -577,7 +562,7 @@ export default { }, execute(row) { this.infoDb = false; - let param = {planCaseIds: []}; + let param = { planCaseIds: [] }; this.reportId = ""; this.buildExecuteParam(param, row); param.triggerMode = "MANUAL"; @@ -695,25 +680,25 @@ export default { openById(item) { let automationData = this.$router.resolve( "/api/automation/default/" + - getUUID() + - "/scenario/edit:" + - item.caseId + - "/" + - item.projectId + - "/" + - getCurrentWorkspaceId() + getUUID() + + "/scenario/edit:" + + item.caseId + + "/" + + item.projectId + + "/" + + getCurrentWorkspaceId() ); window.open(automationData.href, "_blank"); }, getTagToolTips(tags) { try { - let showTips = ''; + let showTips = ""; tags.forEach((item) => { - showTips += item + ','; + showTips += item + ","; }); return showTips.substr(0, showTips.length - 1); } catch (e) { - return ''; + return ""; } }, }, diff --git a/test-track/frontend/src/business/plan/view/comonents/ui/TestPlanUiScenarioList.vue b/test-track/frontend/src/business/plan/view/comonents/ui/TestPlanUiScenarioList.vue index d53451ab81..813f581263 100644 --- a/test-track/frontend/src/business/plan/view/comonents/ui/TestPlanUiScenarioList.vue +++ b/test-track/frontend/src/business/plan/view/comonents/ui/TestPlanUiScenarioList.vue @@ -7,7 +7,8 @@ :projectId="projectId" :plan-status="planStatus" @refresh="filterSearch" - @relevanceCase="$emit('relevanceCase', 'scenario')"/> + @relevanceCase="$emit('relevanceCase', 'scenario')" + /> - - -