feat(测试计划): 测试计划可以修改所属项目
This commit is contained in:
parent
afcbe9bcdc
commit
7a6151ab79
|
@ -81,8 +81,8 @@ public class TestPlanController {
|
||||||
|
|
||||||
@PostMapping("/edit")
|
@PostMapping("/edit")
|
||||||
@RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR)
|
@RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR)
|
||||||
public void editTestPlan(@RequestBody TestPlan testPlan) {
|
public void editTestPlan(@RequestBody TestPlanDTO testPlanDTO) {
|
||||||
testPlanService.editTestPlan(testPlan);
|
testPlanService.editTestPlan(testPlanDTO);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/edit/status/{planId}")
|
@PostMapping("/edit/status/{planId}")
|
||||||
|
|
|
@ -4,8 +4,11 @@ import io.metersphere.base.domain.TestPlan;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
public class TestPlanDTO extends TestPlan {
|
public class TestPlanDTO extends TestPlan {
|
||||||
private String projectName;
|
private String projectName;
|
||||||
|
private List<String> projectIds;
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,7 @@ import org.apache.ibatis.session.SqlSessionFactory;
|
||||||
import org.springframework.context.annotation.Lazy;
|
import org.springframework.context.annotation.Lazy;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
@ -110,12 +111,51 @@ public class TestPlanService {
|
||||||
return Optional.ofNullable(testPlanMapper.selectByPrimaryKey(testPlanId)).orElse(new TestPlan());
|
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());
|
testPlan.setUpdateTime(System.currentTimeMillis());
|
||||||
checkTestPlanExist(testPlan);
|
checkTestPlanExist(testPlan);
|
||||||
return testPlanMapper.updateByPrimaryKeySelective(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) {
|
private void checkTestPlanExist(TestPlan testPlan) {
|
||||||
if (testPlan.getName() != null) {
|
if (testPlan.getName() != null) {
|
||||||
TestPlanExample example = new TestPlanExample();
|
TestPlanExample example = new TestPlanExample();
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
:close-on-click-modal="false"
|
:close-on-click-modal="false"
|
||||||
class="ms-switch-project"
|
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
|
<el-table
|
||||||
:data="tableData"
|
:data="tableData"
|
||||||
highlight-current-row
|
highlight-current-row
|
||||||
|
|
|
@ -24,7 +24,6 @@
|
||||||
<el-col :span="11" :offset="2">
|
<el-col :span="11" :offset="2">
|
||||||
<el-form-item :label="$t('test_track.plan.plan_project')" :label-width="formLabelWidth" prop="projectIds">
|
<el-form-item :label="$t('test_track.plan.plan_project')" :label-width="formLabelWidth" prop="projectIds">
|
||||||
<el-select
|
<el-select
|
||||||
:disabled="(form.status == null) ? false : true"
|
|
||||||
v-model="form.projectIds"
|
v-model="form.projectIds"
|
||||||
:placeholder="$t('test_track.plan.input_plan_project')"
|
:placeholder="$t('test_track.plan.input_plan_project')"
|
||||||
multiple
|
multiple
|
||||||
|
@ -175,18 +174,34 @@ export default {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
param.workspaceId = localStorage.getItem(WORKSPACE_ID);
|
param.workspaceId = localStorage.getItem(WORKSPACE_ID);
|
||||||
this.$post('/test/plan/' + this.operationType, param, () => {
|
|
||||||
this.$success(this.$t('commons.save_success'));
|
if (this.operationType === 'edit') {
|
||||||
this.dialogFormVisible = false;
|
this.$confirm('取消项目关联会同时取消该项目下已关联的测试用例', '提示', {
|
||||||
this.$emit("refresh");
|
confirmButtonText: this.$t('commons.confirm'),
|
||||||
// 发送广播,刷新 head 上的最新列表
|
cancelButtonText: this.$t('commons.cancel'),
|
||||||
TrackEvent.$emit(LIST_CHANGE);
|
type: 'warning'
|
||||||
});
|
}).then(() => {
|
||||||
|
this.editTestPlan(param);
|
||||||
|
}).catch(() => {
|
||||||
|
this.$info(this.$t('commons.cancel'))
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.editTestPlan(param);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return false;
|
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() {
|
getProjects() {
|
||||||
this.$get("/project/listAll", (response) => {
|
this.$get("/project/listAll", (response) => {
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
:title="operationType === 'edit' ? '编辑用例评审' : '创建用例评审'"
|
:title="operationType === 'edit' ? '编辑用例评审' : '创建用例评审'"
|
||||||
:visible.sync="dialogFormVisible"
|
:visible.sync="dialogFormVisible"
|
||||||
@close="close"
|
@close="close"
|
||||||
|
v-loading="result.loading"
|
||||||
width="65%">
|
width="65%">
|
||||||
|
|
||||||
<el-form :model="form" :rules="rules" ref="reviewForm">
|
<el-form :model="form" :rules="rules" ref="reviewForm">
|
||||||
|
@ -122,6 +123,7 @@ export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
dialogFormVisible: false,
|
dialogFormVisible: false,
|
||||||
|
result: {},
|
||||||
form: {
|
form: {
|
||||||
name: '',
|
name: '',
|
||||||
projectIds: [],
|
projectIds: [],
|
||||||
|
@ -187,7 +189,7 @@ export default {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
getProjects() {
|
getProjects() {
|
||||||
this.$get("/project/listAll", (response) => {
|
this.result = this.$get("/project/listAll", (response) => {
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
this.projects = response.data;
|
this.projects = response.data;
|
||||||
} else {
|
} else {
|
||||||
|
@ -197,7 +199,7 @@ export default {
|
||||||
},
|
},
|
||||||
setReviewerOptions() {
|
setReviewerOptions() {
|
||||||
let workspaceId = localStorage.getItem(WORKSPACE_ID);
|
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;
|
this.reviewerOptions = response.data;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue