From e45ff554f14cecfd6c9a170d71cffc84359a198f Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Mon, 24 Jan 2022 16:48:01 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E5=8A=9F=E8=83=BD=E7=94=A8?= =?UTF-8?q?=E4=BE=8B=E5=85=B3=E8=81=94=E6=B5=8B=E8=AF=95=E6=94=B9=E6=88=90?= =?UTF-8?q?=E5=A4=9A=E5=AF=B9=E5=A4=9A=E7=9A=84=E5=85=B3=E7=B3=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/definition/ApiTestCaseRequest.java | 5 +++ .../base/mapper/TestCaseTestMapper.xml | 42 +++++++++++-------- .../commons/utils/ServiceUtils.java | 36 ++++++++++++++++ .../service/ProjectVersionService.java | 2 + .../request/testplan/LoadCaseRequest.java | 2 + .../track/service/TestCaseService.java | 24 +++++++---- backend/src/main/java/io/metersphere/xpack | 2 +- .../case/components/TestCaseApiRelate.vue | 5 +++ .../case/components/TestCaseLoadRelate.vue | 5 +++ .../case/components/TestCaseRelateApiList.vue | 16 +++---- .../components/TestCaseRelateLoadList.vue | 5 +++ .../components/TestCaseRelateScenarioList.vue | 19 +++------ .../components/TestCaseScenarioRelate.vue | 5 +++ .../case/components/TestCaseTestRelate.vue | 5 +++ .../comonents/api/TestPlanApiCaseList.vue | 9 ---- .../comonents/api/TestPlanApiScenarioList.vue | 5 --- .../comonents/api/TestPlanCaseListHeader.vue | 6 +-- .../api/TestPlanScenarioListHeader.vue | 5 +-- .../functional/FunctionalTestCaseList.vue | 5 --- .../functional/TestPlanFunctional.vue | 16 +------ .../comonents/load/TestPlanLoadCaseList.vue | 11 +---- 21 files changed, 125 insertions(+), 105 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/ApiTestCaseRequest.java b/backend/src/main/java/io/metersphere/api/dto/definition/ApiTestCaseRequest.java index 45b74c64f2..5d2cb7c796 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/ApiTestCaseRequest.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/ApiTestCaseRequest.java @@ -41,4 +41,9 @@ public class ApiTestCaseRequest extends BaseQueryRequest { * 是否需要查询环境字段 */ private boolean selectEnvironment = false; + + /** + * 查询排除一些接口 + */ + private List notInIds; } diff --git a/backend/src/main/java/io/metersphere/base/mapper/TestCaseTestMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/TestCaseTestMapper.xml index 811b502fcc..fe8ed9e325 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/TestCaseTestMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/TestCaseTestMapper.xml @@ -146,16 +146,12 @@ atc.num, atc.priority, atc.tags, - project_version.id versionId, - project_version.name versionName + atc.version_id FROM api_test_case atc - LEFT JOIN test_case_test tct ON atc.id = tct.test_id INNER JOIN api_definition ad ON ad.id = atc.api_definition_id - INNER JOIN project_version on atc.project_id = project_version.project_id and atc.version_id = project_version.id WHERE - tct.test_id IS NULL - AND atc. STATUS != 'Trash' + (atc.status is null or atc.status != 'Trash') and ad.protocol = #{request.protocol} @@ -167,6 +163,12 @@ or atc.tags like CONCAT('%', #{request.name},'%') or atc.num like CONCAT('%', #{request.name},'%')) + + and atc.id not in + + #{notInId} + + and ad.module_id in @@ -396,16 +398,12 @@ atc.step_total, atc. STATUS, atc.tags, - project_version.id versionId, - project_version.name versionName + atc.version_id FROM api_scenario atc LEFT JOIN test_case_test tct ON atc.id = tct.test_id - LEFT JOIN project_version ON atc.project_id = project_version.project_id - AND project_version.id = atc.version_id WHERE - tct.test_id IS NULL - AND atc. STATUS != 'Trash' + (atc.status is null or atc.status != 'Trash') and atc.project_id = #{request.projectId} @@ -414,6 +412,12 @@ or atc.tags like CONCAT('%', #{request.name},'%') or atc.num like CONCAT('%', #{request.name},'%')) + + and atc.id not in + + #{notInId} + + and atc.api_scenario_module_id in @@ -456,16 +460,12 @@ atc. STATUS, atc.create_time, atc.update_time, - project_version.name versionName, - project_version.id versionId + atc.version_id FROM load_test atc LEFT JOIN test_case_test tct ON atc.id = tct.test_id - LEFT JOIN project_version ON atc.project_id = project_version.project_id - AND atc.version_id = project_version.id WHERE - tct.test_id IS NULL - AND atc. STATUS != 'Trash' + (atc.status is null or atc.status != 'Trash') and atc.project_id = #{request.projectId} @@ -476,6 +476,12 @@ + + and atc.id not in + + #{notInId} + + diff --git a/backend/src/main/java/io/metersphere/commons/utils/ServiceUtils.java b/backend/src/main/java/io/metersphere/commons/utils/ServiceUtils.java index 56b00c82b4..63930c4617 100644 --- a/backend/src/main/java/io/metersphere/commons/utils/ServiceUtils.java +++ b/backend/src/main/java/io/metersphere/commons/utils/ServiceUtils.java @@ -1,12 +1,15 @@ package io.metersphere.commons.utils; +import io.metersphere.api.dto.definition.ApiTestCaseDTO; import io.metersphere.base.domain.Project; +import io.metersphere.base.domain.ProjectVersion; import io.metersphere.base.domain.User; import io.metersphere.commons.exception.MSException; import io.metersphere.controller.request.BaseQueryRequest; import io.metersphere.controller.request.OrderRequest; import io.metersphere.controller.request.ResetOrderRequest; import io.metersphere.service.ProjectService; +import io.metersphere.service.ProjectVersionService; import io.metersphere.service.UserService; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; @@ -240,4 +243,37 @@ public class ServiceUtils { public static String getCopyName(String name) { return "copy_" + name + "_" + UUID.randomUUID().toString().substring(0, 4); } + + public static void buildVersionInfo(List list) { + ProjectVersionService projectVersionService = CommonBeanFactory.getBean(ProjectVersionService.class); + List versionIds = list.stream() + .map(i -> { + Class clazz = i.getClass(); + try { + Method getVersionId = clazz.getMethod("getVersionId"); + return getVersionId.invoke(i).toString(); + } catch (Exception e) { + LogUtil.error(e); + return i.toString(); + } + }) + .distinct() + .collect(Collectors.toList()); + + Map versionNameMap = projectVersionService.getProjectVersionByIds(versionIds). + stream() + .collect(Collectors.toMap(ProjectVersion::getId, ProjectVersion::getName)); + + list.forEach(i -> { + Class clazz = i.getClass(); + try { + Method setVersionName = clazz.getMethod("setVersionName", String.class); + Method getVersionId = clazz.getMethod("getVersionId"); + Object versionId = getVersionId.invoke(i); + setVersionName.invoke(i, versionNameMap.get(versionId)); + } catch (Exception e) { + LogUtil.error(e); + } + }); + } } diff --git a/backend/src/main/java/io/metersphere/service/ProjectVersionService.java b/backend/src/main/java/io/metersphere/service/ProjectVersionService.java index ceed2533fe..30b00cdd8a 100644 --- a/backend/src/main/java/io/metersphere/service/ProjectVersionService.java +++ b/backend/src/main/java/io/metersphere/service/ProjectVersionService.java @@ -20,4 +20,6 @@ public interface ProjectVersionService { List getProjectVersions(String projectId); void changeStatus(String id, String status); + + List getProjectVersionByIds(List versionIds); } diff --git a/backend/src/main/java/io/metersphere/track/request/testplan/LoadCaseRequest.java b/backend/src/main/java/io/metersphere/track/request/testplan/LoadCaseRequest.java index 1f076f7b86..860e4e0356 100644 --- a/backend/src/main/java/io/metersphere/track/request/testplan/LoadCaseRequest.java +++ b/backend/src/main/java/io/metersphere/track/request/testplan/LoadCaseRequest.java @@ -23,4 +23,6 @@ public class LoadCaseRequest extends TestPlanLoadCase { private String refId; // 测试计划是否允许重复 private boolean repeatCase; + + private List notInIds; } diff --git a/backend/src/main/java/io/metersphere/track/service/TestCaseService.java b/backend/src/main/java/io/metersphere/track/service/TestCaseService.java index 1fbe6e8089..5ee87a9cc7 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestCaseService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestCaseService.java @@ -2121,7 +2121,21 @@ public class TestCaseService { } public List getTestCaseApiCaseRelateList(ApiTestCaseRequest request) { - return testCaseTestMapper.relevanceApiList(request); + List apiTestCaseDTOS = testCaseTestMapper.relevanceApiList(request); + ServiceUtils.buildVersionInfo(apiTestCaseDTOS); + return apiTestCaseDTOS; + } + + public List getTestCaseScenarioCaseRelateList(ApiScenarioRequest request) { + List apiScenarioDTOS = testCaseTestMapper.relevanceScenarioList(request); + ServiceUtils.buildVersionInfo(apiScenarioDTOS); + return apiScenarioDTOS; + } + + public List getTestCaseLoadCaseRelateList(LoadCaseRequest request) { + List loadTestDTOS = testCaseTestMapper.relevanceLoadList(request); + ServiceUtils.buildVersionInfo(loadTestDTOS); + return loadTestDTOS; } public void relateTest(String type, String caseId, List apiIds) { @@ -2231,14 +2245,6 @@ public class TestCaseService { return caseIds; } - public List getTestCaseScenarioCaseRelateList(ApiScenarioRequest request) { - return testCaseTestMapper.relevanceScenarioList(request); - } - - public List getTestCaseLoadCaseRelateList(LoadCaseRequest request) { - return testCaseTestMapper.relevanceLoadList(request); - } - public TestCaseWithBLOBs getTestCaseStep(String testCaseId) { return extTestCaseMapper.getTestCaseStep(testCaseId); } diff --git a/backend/src/main/java/io/metersphere/xpack b/backend/src/main/java/io/metersphere/xpack index 822aeec921..efef7ac19f 160000 --- a/backend/src/main/java/io/metersphere/xpack +++ b/backend/src/main/java/io/metersphere/xpack @@ -1 +1 @@ -Subproject commit 822aeec9210db1933e89410eae111c04b1c81b75 +Subproject commit efef7ac19f97c762792969275e1fd80ec1f10c66 diff --git a/frontend/src/business/components/track/case/components/TestCaseApiRelate.vue b/frontend/src/business/components/track/case/components/TestCaseApiRelate.vue index 1938b8f09b..bae02b4f43 100644 --- a/frontend/src/business/components/track/case/components/TestCaseApiRelate.vue +++ b/frontend/src/business/components/track/case/components/TestCaseApiRelate.vue @@ -21,6 +21,7 @@ :current-protocol="currentProtocol" :select-node-ids="selectNodeIds" :project-id="projectId" + :not-in-ids="notInIds" :versionEnable="versionEnable" ref="apiCaseList"/> @@ -57,6 +58,10 @@ export default { versionEnable: { type: Boolean, default: false + }, + notInIds: { + type: Array, + default: null } }, methods: { diff --git a/frontend/src/business/components/track/case/components/TestCaseLoadRelate.vue b/frontend/src/business/components/track/case/components/TestCaseLoadRelate.vue index 40eea28c53..96b92ee2ca 100644 --- a/frontend/src/business/components/track/case/components/TestCaseLoadRelate.vue +++ b/frontend/src/business/components/track/case/components/TestCaseLoadRelate.vue @@ -8,6 +8,7 @@ @@ -47,6 +48,10 @@ export default { versionEnable: { type: Boolean, default: false + }, + notInIds: { + type: Array, + default: null } }, methods: { diff --git a/frontend/src/business/components/track/case/components/TestCaseRelateApiList.vue b/frontend/src/business/components/track/case/components/TestCaseRelateApiList.vue index 1231a65a1c..b64e746ab7 100644 --- a/frontend/src/business/components/track/case/components/TestCaseRelateApiList.vue +++ b/frontend/src/business/components/track/case/components/TestCaseRelateApiList.vue @@ -54,17 +54,6 @@ :content="itemName" style="margin-left: 0px; margin-right: 2px"> - - - - - - - - - - - { this.total = response.data.itemCount; diff --git a/frontend/src/business/components/track/case/components/TestCaseRelateLoadList.vue b/frontend/src/business/components/track/case/components/TestCaseRelateLoadList.vue index c5b131b9a8..edfe56f088 100644 --- a/frontend/src/business/components/track/case/components/TestCaseRelateLoadList.vue +++ b/frontend/src/business/components/track/case/components/TestCaseRelateLoadList.vue @@ -114,6 +114,10 @@ export default { props: { projectId: String, versionEnable: Boolean, + notInIds: { + type: Array, + default: null + } }, created: function () { this.initTable(); @@ -141,6 +145,7 @@ export default { } else if (this.projectId != null) { this.condition.projectId = this.projectId; } + this.condition.notInIds = this.notInIds; let url = '/test/case/relevance/load/list/'; this.result = this.$post(this.buildPagePath(url), this.condition, response => { this.total = response.data.itemCount; diff --git a/frontend/src/business/components/track/case/components/TestCaseRelateScenarioList.vue b/frontend/src/business/components/track/case/components/TestCaseRelateScenarioList.vue index 31f0bfafa5..0ca3f8a91f 100644 --- a/frontend/src/business/components/track/case/components/TestCaseRelateScenarioList.vue +++ b/frontend/src/business/components/track/case/components/TestCaseRelateScenarioList.vue @@ -24,20 +24,6 @@ sortable=true> - - - - - - - - - - - - - - @@ -142,6 +128,10 @@ export default { selectNodeIds: Array, projectId: String, versionEnable: Boolean, + notInIds: { + type: Array, + default: null + } }, created: function () { this.initTable(); @@ -174,6 +164,7 @@ export default { this.condition.projectId = this.projectId; } let url = '/test/case/relevance/scenario/list/'; + this.condition.notInIds = this.notInIds; this.result = this.$post(this.buildPagePath(url), this.condition, response => { this.total = response.data.itemCount; this.tableData = response.data.listObject; diff --git a/frontend/src/business/components/track/case/components/TestCaseScenarioRelate.vue b/frontend/src/business/components/track/case/components/TestCaseScenarioRelate.vue index aecc7ee64d..cfbc054cec 100644 --- a/frontend/src/business/components/track/case/components/TestCaseScenarioRelate.vue +++ b/frontend/src/business/components/track/case/components/TestCaseScenarioRelate.vue @@ -20,6 +20,7 @@ @@ -60,6 +61,10 @@ export default { type: Boolean, default: false }, + notInIds: { + type: Array, + default: null + } }, methods: { open() { diff --git a/frontend/src/business/components/track/case/components/TestCaseTestRelate.vue b/frontend/src/business/components/track/case/components/TestCaseTestRelate.vue index e198ac27c0..fc43b98d84 100644 --- a/frontend/src/business/components/track/case/components/TestCaseTestRelate.vue +++ b/frontend/src/business/components/track/case/components/TestCaseTestRelate.vue @@ -50,17 +50,20 @@ @@ -97,6 +100,7 @@ export default { } } ], + notInIds: null } }, props: ['caseId', 'readOnly', 'versionEnable'], @@ -127,6 +131,7 @@ export default { initTable() { this.result = getRelateTest(this.caseId, (data) => { this.data = data; + this.notInIds = data.map(i => i.testId); }); }, } diff --git a/frontend/src/business/components/track/plan/view/comonents/api/TestPlanApiCaseList.vue b/frontend/src/business/components/track/plan/view/comonents/api/TestPlanApiCaseList.vue index 13819b4847..363e4308c3 100644 --- a/frontend/src/business/components/track/plan/view/comonents/api/TestPlanApiCaseList.vue +++ b/frontend/src/business/components/track/plan/view/comonents/api/TestPlanApiCaseList.vue @@ -6,7 +6,6 @@ :project-id="getProjectId()" :condition="condition" :plan-id="planId" - @changeVersion="changeVersion" @refresh="initTable" @relevanceCase="$emit('relevanceCase')" @setEnvironment="setEnvironment" @@ -647,14 +646,6 @@ export default { } }); }, - changeVersion(currentVersion) { - if (currentVersion == "") { - this.condition.versionId = null; - } else { - this.condition.versionId = currentVersion; - } - this.initTable(); - }, getVersionOptions() { if (hasLicense()) { this.$get('/project/version/get-project-versions/' + getCurrentProjectID(), response => { diff --git a/frontend/src/business/components/track/plan/view/comonents/api/TestPlanApiScenarioList.vue b/frontend/src/business/components/track/plan/view/comonents/api/TestPlanApiScenarioList.vue index d1e499de69..7a3c980215 100644 --- a/frontend/src/business/components/track/plan/view/comonents/api/TestPlanApiScenarioList.vue +++ b/frontend/src/business/components/track/plan/view/comonents/api/TestPlanApiScenarioList.vue @@ -5,7 +5,6 @@ @@ -570,10 +569,6 @@ export default { }); } }, - changeVersion(currentVersion) { - this.condition.versionId = currentVersion || null; - this.search(); - }, getVersionOptions() { if (hasLicense()) { this.$get('/project/version/get-project-versions/' + getCurrentProjectID(), response => { diff --git a/frontend/src/business/components/track/plan/view/comonents/api/TestPlanCaseListHeader.vue b/frontend/src/business/components/track/plan/view/comonents/api/TestPlanCaseListHeader.vue index 88256c098c..244c076c1c 100644 --- a/frontend/src/business/components/track/plan/view/comonents/api/TestPlanCaseListHeader.vue +++ b/frontend/src/business/components/track/plan/view/comonents/api/TestPlanCaseListHeader.vue @@ -11,7 +11,6 @@ - @@ -21,12 +20,9 @@ import MsTableHeader from "../../../../../common/components/MsTableHeader"; import MsTableButton from "../../../../../common/components/MsTableButton"; import MsEnvironmentSelect from "../../../../../api/definition/components/case/MsEnvironmentSelect"; -const requireComponent = require.context('@/business/components/xpack/', true, /\.vue$/); -const VersionSelect = requireComponent.keys().length > 0 ? requireComponent("./version/VersionSelect.vue") : {}; - export default { name: "TestPlanCaseListHeader", - components: {MsEnvironmentSelect, MsTableButton, MsTableHeader, 'VersionSelect': VersionSelect.default}, + components: {MsEnvironmentSelect, MsTableButton, MsTableHeader}, props: ['condition', 'projectId', 'isReadOnly', 'planId'], methods: { setEnvironment(data) { diff --git a/frontend/src/business/components/track/plan/view/comonents/api/TestPlanScenarioListHeader.vue b/frontend/src/business/components/track/plan/view/comonents/api/TestPlanScenarioListHeader.vue index 432639287d..0dcf83da79 100644 --- a/frontend/src/business/components/track/plan/view/comonents/api/TestPlanScenarioListHeader.vue +++ b/frontend/src/business/components/track/plan/view/comonents/api/TestPlanScenarioListHeader.vue @@ -11,7 +11,6 @@ - @@ -21,13 +20,11 @@ import MsTableHeader from "../../../../../common/components/MsTableHeader"; import MsTableButton from "../../../../../common/components/MsTableButton"; import MsEnvironmentSelect from "../../../../../api/definition/components/case/MsEnvironmentSelect"; -const requireComponent = require.context('@/business/components/xpack/', true, /\.vue$/); -const VersionSelect = requireComponent.keys().length > 0 ? requireComponent("./version/VersionSelect.vue") : {}; export default { name: "TestPlanScenarioListHeader", components: { - MsEnvironmentSelect, MsTableButton, MsTableHeader, 'VersionSelect': VersionSelect.default, + MsEnvironmentSelect, MsTableButton, MsTableHeader }, props: ['condition', 'isReadOnly', 'projectId'], methods: {} diff --git a/frontend/src/business/components/track/plan/view/comonents/functional/FunctionalTestCaseList.vue b/frontend/src/business/components/track/plan/view/comonents/functional/FunctionalTestCaseList.vue index 6f341dd088..dc71d04d42 100644 --- a/frontend/src/business/components/track/plan/view/comonents/functional/FunctionalTestCaseList.vue +++ b/frontend/src/business/components/track/plan/view/comonents/functional/FunctionalTestCaseList.vue @@ -409,7 +409,6 @@ export default { selectNodeIds: { type: Array }, - currentVersion: null, versionEnable: { type: Boolean, default: false @@ -439,10 +438,6 @@ export default { }, condition() { this.$emit('setCondition', this.condition); - }, - currentVersion(){ - this.condition.versionId = this.currentVersion; - this.initTableData(); } }, created() { diff --git a/frontend/src/business/components/track/plan/view/comonents/functional/TestPlanFunctional.vue b/frontend/src/business/components/track/plan/view/comonents/functional/TestPlanFunctional.vue index 3eb5ae892e..fb8a302d8c 100644 --- a/frontend/src/business/components/track/plan/view/comonents/functional/TestPlanFunctional.vue +++ b/frontend/src/business/components/track/plan/view/comonents/functional/TestPlanFunctional.vue @@ -17,16 +17,13 @@ :right-tip="$t('test_track.case.minder')" :right-content="$t('test_track.case.minder')" :middle-button-enable="false"> - + 0 ? requireComponent("./version/VersionSelect.vue") : {}; export default { name: "TestPlanFunctional", @@ -82,7 +78,6 @@ export default { FunctionalTestCaseList, MsTestPlanCommonComponent, NodeTree, - 'VersionSelect': VersionSelect.default, }, data() { return { @@ -93,8 +88,7 @@ export default { selectNode: {}, condition: {}, tmpActiveDom: null, - tmpPath: null, - currentVersion: null, + tmpPath: null }; }, props: [ @@ -185,9 +179,6 @@ export default { } else { return true; } - }, - changeVersion(currentVersion) { - this.currentVersion = currentVersion || null; } } }; @@ -195,7 +186,4 @@ export default { diff --git a/frontend/src/business/components/track/plan/view/comonents/load/TestPlanLoadCaseList.vue b/frontend/src/business/components/track/plan/view/comonents/load/TestPlanLoadCaseList.vue index 747c247cb0..cb5cd774dd 100644 --- a/frontend/src/business/components/track/plan/view/comonents/load/TestPlanLoadCaseList.vue +++ b/frontend/src/business/components/track/plan/view/comonents/load/TestPlanLoadCaseList.vue @@ -5,8 +5,7 @@ @@ -469,14 +468,6 @@ export default { clearInterval(this.refreshScheduler); } }, - changeVersion(currentVersion) { - if (currentVersion == "") { - this.condition.versionId = null; - } else { - this.condition.versionId = currentVersion; - } - this.initTable(); - }, getVersionOptions() { if (hasLicense()) { this.$get('/project/version/get-project-versions/' + getCurrentProjectID(), response => {