feat(测试计划): 测试计划可以修改所属项目

This commit is contained in:
shiziyuan9527 2020-09-18 11:09:37 +08:00
parent afcbe9bcdc
commit 7a6151ab79
6 changed files with 74 additions and 14 deletions

View File

@ -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}")

View File

@ -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<String> projectIds;
}

View File

@ -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<String> projectIds = testPlan.getProjectIds();
if (!CollectionUtils.isEmpty(projectIds)) {
TestPlanProjectExample testPlanProjectExample1 = new TestPlanProjectExample();
testPlanProjectExample1.createCriteria().andTestPlanIdEqualTo(testPlan.getId());
List<TestPlanProject> testPlanProjects = testPlanProjectMapper.selectByExample(testPlanProjectExample1);
// 已经关联的项目idList
List<String> 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<TestCase> caseList = testCaseMapper.selectByExample(example);
List<String> 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();

View File

@ -4,7 +4,7 @@
:close-on-click-modal="false"
class="ms-switch-project"
>
<ms-table-header :condition.sync="condition" @search="initData" title="" :show-create="false"/>
<ms-table-header :condition.sync="condition" @search="initData" title="切换项目" :show-create="false"/>
<el-table
:data="tableData"
highlight-current-row

View File

@ -24,7 +24,6 @@
<el-col :span="11" :offset="2">
<el-form-item :label="$t('test_track.plan.plan_project')" :label-width="formLabelWidth" prop="projectIds">
<el-select
:disabled="(form.status == null) ? false : true"
v-model="form.projectIds"
:placeholder="$t('test_track.plan.input_plan_project')"
multiple
@ -175,18 +174,34 @@ export default {
return;
}
param.workspaceId = localStorage.getItem(WORKSPACE_ID);
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);
});
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) {

View File

@ -6,6 +6,7 @@
:title="operationType === 'edit' ? '编辑用例评审' : '创建用例评审'"
:visible.sync="dialogFormVisible"
@close="close"
v-loading="result.loading"
width="65%">
<el-form :model="form" :rules="rules" ref="reviewForm">
@ -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;
});
},