From fbce41bb3e17100321aef4aaa4c20cd91d10122c Mon Sep 17 00:00:00 2001 From: shiziyuan9527 Date: Tue, 8 Sep 2020 15:20:30 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92):?= =?UTF-8?q?=20=E5=88=A0=E9=99=A4=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92?= =?UTF-8?q?=E6=97=B6=E5=90=8C=E6=97=B6=E5=88=A0=E9=99=A4=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E8=81=94=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../metersphere/service/ProjectService.java | 20 +++++++++++------- .../track/service/TestCaseNodeService.java | 1 - .../track/service/TestPlanProjectService.java | 21 +++++++++++++++++++ .../track/service/TestPlanService.java | 1 + .../track/plan/components/TestPlanList.vue | 8 +++++-- 5 files changed, 40 insertions(+), 11 deletions(-) diff --git a/backend/src/main/java/io/metersphere/service/ProjectService.java b/backend/src/main/java/io/metersphere/service/ProjectService.java index 4c268c729a..292fbf8229 100644 --- a/backend/src/main/java/io/metersphere/service/ProjectService.java +++ b/backend/src/main/java/io/metersphere/service/ProjectService.java @@ -16,13 +16,14 @@ import io.metersphere.controller.request.ProjectRequest; import io.metersphere.dto.ProjectDTO; import io.metersphere.i18n.Translator; import io.metersphere.performance.service.PerformanceTestService; -import io.metersphere.track.request.testcase.QueryTestPlanRequest; import io.metersphere.track.request.testplan.DeleteTestPlanRequest; import io.metersphere.track.service.TestCaseService; +import io.metersphere.track.service.TestPlanProjectService; import io.metersphere.track.service.TestPlanService; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.CollectionUtils; import javax.annotation.Resource; import java.util.List; @@ -54,6 +55,8 @@ public class ProjectService { private TestCaseService testCaseService; @Resource private APITestService apiTestService; + @Resource + private TestPlanProjectService testPlanProjectService; public Project addProject(Project project) { if (StringUtils.isBlank(project.getName())) { @@ -96,21 +99,22 @@ public class ProjectService { performanceTestService.delete(deleteTestPlanRequest); }); - // TODO 删除项目下 测试跟踪 相关 + // 删除项目下 测试跟踪 相关 deleteTrackResourceByProjectId(projectId); - // TODO 删除项目下 接口测试 相关 + // 删除项目下 接口测试 相关 deleteAPIResourceByProjectId(projectId); // delete project projectMapper.deleteByPrimaryKey(projectId); } private void deleteTrackResourceByProjectId(String projectId) { - QueryTestPlanRequest request = new QueryTestPlanRequest(); - request.setProjectId(projectId); - testPlanService.listTestPlan(request).forEach(testPlan -> { - testPlanService.deleteTestPlan(testPlan.getId()); - }); + List testPlanIds = testPlanProjectService.getPlanIdByProjectId(projectId); + if (!CollectionUtils.isEmpty(testPlanIds)) { + testPlanIds.forEach(testPlanId -> { + testPlanService.deleteTestPlan(testPlanId); + }); + } testCaseService.deleteTestCaseByProjectId(projectId); } diff --git a/backend/src/main/java/io/metersphere/track/service/TestCaseNodeService.java b/backend/src/main/java/io/metersphere/track/service/TestCaseNodeService.java index f7e9ffc50d..4a003fdf16 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestCaseNodeService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestCaseNodeService.java @@ -271,7 +271,6 @@ public class TestCaseNodeService { } public List getAllNodeByPlanId(QueryNodeRequest request) { - // todo jenkins 获取模块 String planId = request.getTestPlanId(); String projectId = request.getProjectId(); TestPlan testPlan = testPlanMapper.selectByPrimaryKey(planId); diff --git a/backend/src/main/java/io/metersphere/track/service/TestPlanProjectService.java b/backend/src/main/java/io/metersphere/track/service/TestPlanProjectService.java index c713dc67f1..49cb890fe4 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanProjectService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanProjectService.java @@ -6,8 +6,10 @@ import io.metersphere.base.domain.TestPlanProject; import io.metersphere.base.domain.TestPlanProjectExample; import io.metersphere.base.mapper.ProjectMapper; import io.metersphere.base.mapper.TestPlanProjectMapper; +import org.python.antlr.ast.Str; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.CollectionUtils; import javax.annotation.Resource; import java.util.ArrayList; @@ -46,4 +48,23 @@ public class TestPlanProjectService { List projects = projectMapper.selectByExample(projectExample); return Optional.ofNullable(projects).orElse(new ArrayList<>()); } + + public void deleteTestPlanProjectByPlanId(String planId) { + TestPlanProjectExample testPlanProjectExample = new TestPlanProjectExample(); + testPlanProjectExample.createCriteria().andTestPlanIdEqualTo(planId); + testPlanProjectMapper.deleteByExample(testPlanProjectExample); + } + + public List getPlanIdByProjectId(String projectId) { + TestPlanProjectExample testPlanProjectExample = new TestPlanProjectExample(); + testPlanProjectExample.createCriteria().andProjectIdEqualTo(projectId); + List testPlanProjects = testPlanProjectMapper.selectByExample(testPlanProjectExample); + if (CollectionUtils.isEmpty(testPlanProjects)) { + return null; + } + return testPlanProjects + .stream() + .map(TestPlanProject::getTestPlanId) + .collect(Collectors.toList()); + } } diff --git a/backend/src/main/java/io/metersphere/track/service/TestPlanService.java b/backend/src/main/java/io/metersphere/track/service/TestPlanService.java index 22a5d2ff56..b7b6b30cc7 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanService.java @@ -131,6 +131,7 @@ public class TestPlanService { public int deleteTestPlan(String planId) { deleteTestCaseByPlanId(planId); + testPlanProjectService.deleteTestPlanProjectByPlanId(planId); return testPlanMapper.deleteByPrimaryKey(planId); } diff --git a/frontend/src/business/components/track/plan/components/TestPlanList.vue b/frontend/src/business/components/track/plan/components/TestPlanList.vue index 05a4df3e37..98293943e9 100644 --- a/frontend/src/business/components/track/plan/components/TestPlanList.vue +++ b/frontend/src/business/components/track/plan/components/TestPlanList.vue @@ -192,9 +192,13 @@ export default { this.total = data.itemCount; this.tableData = data.listObject; for (let i = 0; i < this.tableData.length; i++) { - let path = "/test/plan/project/name/" + this.tableData[i].id; + let path = "/test/plan/project/" + this.tableData[i].id; this.$get(path, res => { - this.$set(this.tableData[i], "projectName", res.data); + let arr = res.data; + let projectName = arr.map(data => data.name).join("、"); + let projectIds = arr.map(data => data.id); + this.$set(this.tableData[i], "projectName", projectName); + this.$set(this.tableData[i], "projectIds", projectIds); }) } });