mirror of
https://gitee.com/fit2cloud-feizhiyun/MeterSphere.git
synced 2024-12-02 12:09:13 +08:00
feat(测试计划): 测试计划可以修改所属项目
This commit is contained in:
parent
afcbe9bcdc
commit
7a6151ab79
@ -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}")
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
});
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user