From 7a6151ab794403e66e65cab61db63bb79a0dabdb Mon Sep 17 00:00:00 2001 From: shiziyuan9527 Date: Fri, 18 Sep 2020 11:09:37 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92):=20?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92=E5=8F=AF=E4=BB=A5=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E6=89=80=E5=B1=9E=E9=A1=B9=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../track/controller/TestPlanController.java | 4 +- .../io/metersphere/track/dto/TestPlanDTO.java | 3 ++ .../track/service/TestPlanService.java | 42 ++++++++++++++++++- .../track/case/components/SwitchProject.vue | 2 +- .../track/plan/components/TestPlanEdit.vue | 31 ++++++++++---- .../review/components/TestCaseReviewEdit.vue | 6 ++- 6 files changed, 74 insertions(+), 14 deletions(-) diff --git a/backend/src/main/java/io/metersphere/track/controller/TestPlanController.java b/backend/src/main/java/io/metersphere/track/controller/TestPlanController.java index 6fbea3d40d..7f9135fcb9 100644 --- a/backend/src/main/java/io/metersphere/track/controller/TestPlanController.java +++ b/backend/src/main/java/io/metersphere/track/controller/TestPlanController.java @@ -81,8 +81,8 @@ public class TestPlanController { @PostMapping("/edit") @RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR) - public void editTestPlan(@RequestBody TestPlan testPlan) { - testPlanService.editTestPlan(testPlan); + public void editTestPlan(@RequestBody TestPlanDTO testPlanDTO) { + testPlanService.editTestPlan(testPlanDTO); } @PostMapping("/edit/status/{planId}") diff --git a/backend/src/main/java/io/metersphere/track/dto/TestPlanDTO.java b/backend/src/main/java/io/metersphere/track/dto/TestPlanDTO.java index 232c77ada0..a9b9fb545f 100644 --- a/backend/src/main/java/io/metersphere/track/dto/TestPlanDTO.java +++ b/backend/src/main/java/io/metersphere/track/dto/TestPlanDTO.java @@ -4,8 +4,11 @@ import io.metersphere.base.domain.TestPlan; import lombok.Getter; import lombok.Setter; +import java.util.List; + @Getter @Setter public class TestPlanDTO extends TestPlan { private String projectName; + private List projectIds; } 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 bdd198c510..7f95cd805d 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanService.java @@ -34,6 +34,7 @@ import org.apache.ibatis.session.SqlSessionFactory; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.CollectionUtils; import javax.annotation.Resource; import java.util.*; @@ -110,12 +111,51 @@ public class TestPlanService { return Optional.ofNullable(testPlanMapper.selectByPrimaryKey(testPlanId)).orElse(new TestPlan()); } - public int editTestPlan(TestPlan testPlan) { + public int editTestPlan(TestPlanDTO testPlan) { + editTestPlanProject(testPlan); testPlan.setUpdateTime(System.currentTimeMillis()); checkTestPlanExist(testPlan); return testPlanMapper.updateByPrimaryKeySelective(testPlan); } + private void editTestPlanProject(TestPlanDTO testPlan) { + List projectIds = testPlan.getProjectIds(); + if (!CollectionUtils.isEmpty(projectIds)) { + TestPlanProjectExample testPlanProjectExample1 = new TestPlanProjectExample(); + testPlanProjectExample1.createCriteria().andTestPlanIdEqualTo(testPlan.getId()); + List testPlanProjects = testPlanProjectMapper.selectByExample(testPlanProjectExample1); + // 已经关联的项目idList + List dbProjectIds = testPlanProjects.stream().map(TestPlanProject::getProjectId).collect(Collectors.toList()); + // 修改后传过来的项目idList,如果还未关联,进行关联 + projectIds.forEach(projectId -> { + if (!dbProjectIds.contains(projectId)) { + TestPlanProject testPlanProject = new TestPlanProject(); + testPlanProject.setTestPlanId(testPlan.getId()); + testPlanProject.setProjectId(projectId); + testPlanProjectMapper.insert(testPlanProject); + } + }); + + TestPlanProjectExample testPlanProjectExample = new TestPlanProjectExample(); + testPlanProjectExample.createCriteria().andTestPlanIdEqualTo(testPlan.getId()).andProjectIdNotIn(projectIds); + testPlanProjectMapper.deleteByExample(testPlanProjectExample); + + // 关联的项目下的用例idList + TestCaseExample example = new TestCaseExample(); + example.createCriteria().andProjectIdIn(projectIds); + List caseList = testCaseMapper.selectByExample(example); + List caseIds = caseList.stream().map(TestCase::getId).collect(Collectors.toList()); + + // 取消关联所属项目下的用例和计划的关系 + TestPlanTestCaseExample testPlanTestCaseExample = new TestPlanTestCaseExample(); + TestPlanTestCaseExample.Criteria criteria = testPlanTestCaseExample.createCriteria().andPlanIdEqualTo(testPlan.getId()); + if (!CollectionUtils.isEmpty(caseIds)) { + criteria.andCaseIdNotIn(caseIds); + } + testPlanTestCaseMapper.deleteByExample(testPlanTestCaseExample); + } + } + private void checkTestPlanExist(TestPlan testPlan) { if (testPlan.getName() != null) { TestPlanExample example = new TestPlanExample(); diff --git a/frontend/src/business/components/track/case/components/SwitchProject.vue b/frontend/src/business/components/track/case/components/SwitchProject.vue index 57b9335340..035d52312e 100644 --- a/frontend/src/business/components/track/case/components/SwitchProject.vue +++ b/frontend/src/business/components/track/case/components/SwitchProject.vue @@ -4,7 +4,7 @@ :close-on-click-modal="false" class="ms-switch-project" > - + { - this.$success(this.$t('commons.save_success')); - this.dialogFormVisible = false; - this.$emit("refresh"); - // 发送广播,刷新 head 上的最新列表 - TrackEvent.$emit(LIST_CHANGE); - }); + + if (this.operationType === 'edit') { + this.$confirm('取消项目关联会同时取消该项目下已关联的测试用例', '提示', { + confirmButtonText: this.$t('commons.confirm'), + cancelButtonText: this.$t('commons.cancel'), + type: 'warning' + }).then(() => { + this.editTestPlan(param); + }).catch(() => { + this.$info(this.$t('commons.cancel')) + }); + } else { + this.editTestPlan(param); + } } else { return false; } }); }, + editTestPlan(param) { + this.$post('/test/plan/' + this.operationType, param, () => { + this.$success(this.$t('commons.save_success')); + this.dialogFormVisible = false; + this.$emit("refresh"); + // 发送广播,刷新 head 上的最新列表 + TrackEvent.$emit(LIST_CHANGE); + }); + }, getProjects() { this.$get("/project/listAll", (response) => { if (response.success) { diff --git a/frontend/src/business/components/track/review/components/TestCaseReviewEdit.vue b/frontend/src/business/components/track/review/components/TestCaseReviewEdit.vue index 7dfc0298b8..aaeea31402 100644 --- a/frontend/src/business/components/track/review/components/TestCaseReviewEdit.vue +++ b/frontend/src/business/components/track/review/components/TestCaseReviewEdit.vue @@ -6,6 +6,7 @@ :title="operationType === 'edit' ? '编辑用例评审' : '创建用例评审'" :visible.sync="dialogFormVisible" @close="close" + v-loading="result.loading" width="65%"> @@ -122,6 +123,7 @@ export default { data() { return { dialogFormVisible: false, + result: {}, form: { name: '', projectIds: [], @@ -187,7 +189,7 @@ export default { }); }, getProjects() { - this.$get("/project/listAll", (response) => { + this.result = this.$get("/project/listAll", (response) => { if (response.success) { this.projects = response.data; } else { @@ -197,7 +199,7 @@ export default { }, setReviewerOptions() { let workspaceId = localStorage.getItem(WORKSPACE_ID); - this.$post('/user/ws/member/tester/list', {workspaceId: workspaceId}, response => { + this.result = this.$post('/user/ws/member/tester/list', {workspaceId: workspaceId}, response => { this.reviewerOptions = response.data; }); },