feat(测试跟踪): 测试计划默认关联工作空间下所有项目

This commit is contained in:
shiziyuan9527 2021-02-19 16:12:04 +08:00
parent 54258fb01e
commit b289b4d267
3 changed files with 18 additions and 161 deletions

View File

@ -11,6 +11,7 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@ -26,23 +27,15 @@ public class TestPlanProjectService {
private TestPlanMapper testPlanMapper;
public List<String> getProjectIdsByPlanId(String planId) {
TestPlan testPlan = testPlanMapper.selectByPrimaryKey(planId);
TestPlanProjectExample example = new TestPlanProjectExample();
example.createCriteria().andTestPlanIdEqualTo(planId);
List<String> projectIds = testPlanProjectMapper.selectByExample(example)
.stream()
.map(TestPlanProject::getProjectId)
.collect(Collectors.toList());
if (testPlan != null && StringUtils.isNotBlank(testPlan.getProjectId())) {
if (!projectIds.contains(testPlan.getProjectId())) {
projectIds.add(testPlan.getProjectId());
}
TestPlan plan = testPlanMapper.selectByPrimaryKey(planId);
String workspaceId = plan.getWorkspaceId();
if (StringUtils.isNotBlank(workspaceId)) {
ProjectExample example = new ProjectExample();
example.createCriteria().andWorkspaceIdEqualTo(workspaceId);
List<Project> projects = projectMapper.selectByExample(example);
return projects.stream().map(Project::getId).collect(Collectors.toList());
}
if (projectIds.isEmpty()) {
return null;
}
return projectIds;
return new ArrayList<>();
}
public List<Project> getProjectByPlanId(TestCaseRelevanceRequest request) {

View File

@ -119,15 +119,6 @@ public class TestPlanService {
}
String testPlanId = UUID.randomUUID().toString();
List<String> projectIds = testPlan.getProjectIds();
projectIds.forEach(id -> {
TestPlanProject testPlanProject = new TestPlanProject();
testPlanProject.setProjectId(id);
testPlanProject.setTestPlanId(testPlanId);
testPlanProjectMapper.insertSelective(testPlanProject);
});
testPlan.setId(testPlanId);
testPlan.setStatus(TestPlanStatus.Prepare.name());
testPlan.setCreateTime(System.currentTimeMillis());
@ -166,7 +157,6 @@ public class TestPlanService {
}
public int editTestPlan(TestPlanDTO testPlan) {
editTestPlanProject(testPlan);
checkTestPlanExist(testPlan);
TestPlan res = testPlanMapper.selectByPrimaryKey(testPlan.getId()); // 先查一次库
if (!res.getStatus().equals(testPlan.getStatus())) { // 若有改变才更新时间
@ -213,70 +203,6 @@ public class TestPlanService {
return i;
}
private void editTestPlanProject(TestPlanDTO testPlan) {
// 将要进行关联的项目ID
List<String> projectIds = testPlan.getProjectIds();
// 如果将要关联的项目ID中包含测试计划所属ID则进行剔除
if (!CollectionUtils.isEmpty(projectIds)) {
if (projectIds.contains(testPlan.getProjectId())) {
projectIds.remove(testPlan.getProjectId());
}
}
// todo 优化 TestPlanList intoPlan 方法会触发此更新
if (StringUtils.isNotBlank(testPlan.getProjectId())) {
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.Criteria criteria1 = testPlanProjectExample.createCriteria();
criteria1.andTestPlanIdEqualTo(testPlan.getId());
if (!CollectionUtils.isEmpty(projectIds)) {
criteria1.andProjectIdNotIn(projectIds);
}
testPlanProjectMapper.deleteByExample(testPlanProjectExample);
// 关联的项目下的用例idList
List<String> caseIds = null;
// 测试计划所属项目下的用例不解除关联
projectIds.add(testPlan.getProjectId());
if (!CollectionUtils.isEmpty(projectIds)) {
TestCaseExample example = new TestCaseExample();
example.createCriteria().andProjectIdIn(projectIds);
List<TestCase> caseList = testCaseMapper.selectByExample(example);
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);
List<String> relevanceProjectIds = new ArrayList<>();
relevanceProjectIds.add(testPlan.getProjectId());
if (!CollectionUtils.isEmpty(testPlan.getProjectIds())) {
relevanceProjectIds.addAll(testPlan.getProjectIds());
}
testPlanApiCaseService.deleteByRelevanceProjectIds(testPlan.getId(), relevanceProjectIds);
testPlanScenarioCaseService.deleteByRelevanceProjectIds(testPlan.getId(), relevanceProjectIds);
testPlanLoadCaseService.deleteByRelevanceProjectIds(testPlan.getId(), relevanceProjectIds);
}
}
//计划内容
private Map<String, Object> getTestPlanParamMap(TestPlan testPlan) {
Long startTime = testPlan.getPlannedStartTime();
@ -331,7 +257,6 @@ public class TestPlanService {
public int deleteTestPlan(String planId) {
TestPlan testPlan = getTestPlan(planId);
deleteTestCaseByPlanId(planId);
testPlanProjectService.deleteTestPlanProjectByPlanId(planId);
testPlanApiCaseService.deleteByPlanId(planId);
testPlanScenarioCaseService.deleteByPlanId(planId);

View File

@ -19,30 +19,6 @@
<el-input v-model="form.name" :placeholder="$t('test_track.plan.input_plan_name')"></el-input>
</el-form-item>
</el-col>
<el-col :span="11" :offset="2">
<el-form-item :label-width="formLabelWidth" prop="projectIds">
<template slot="label">
<el-tooltip class="item" effect="dark" :content="$t('test_track.plan.related_tip')" placement="top">
<i class="el-icon-warning"/>
</el-tooltip>
{{ $t('test_track.plan.related_project') }}
</template>
<el-select
v-model="form.projectIds"
:placeholder="$t('test_track.plan.input_related_project')"
multiple
style="width: 100%"
filterable>
<el-option
v-for="item in projects"
:key="item.id"
:label="item.name"
:value="item.id">
</el-option>
</el-select>
</el-form-item>
</el-col>
</el-row>
<el-row>
@ -164,21 +140,18 @@ export default {
{required: true, message: this.$t('test_track.plan.input_plan_name'), trigger: 'blur'},
{max: 30, message: this.$t('test_track.length_less_than') + '30', trigger: 'blur'}
],
// projectIds: [{required: true, message: this.$t('test_track.plan.input_plan_project'), trigger: 'change'}],
principal: [{required: true, message: this.$t('test_track.plan.input_plan_principal'), trigger: 'change'}],
stage: [{required: true, message: this.$t('test_track.plan.input_plan_stage'), trigger: 'change'}],
description: [{max: 200, message: this.$t('test_track.length_less_than') + '200', trigger: 'blur'}]
},
formLabelWidth: "120px",
operationType: '',
projects: [],
principalOptions: []
};
},
methods: {
openTestPlanEditDialog(testPlan) {
this.resetForm();
this.getProjects();
this.setPrincipalOptions();
this.operationType = 'add';
if (testPlan) {
@ -198,34 +171,18 @@ export default {
let param = {};
Object.assign(param, this.form);
param.name = param.name.trim();
if (!this.validate(param)) {
if (param.name === '') {
this.$warning(this.$t('test_track.plan.input_plan_name'));
return;
}
param.workspaceId = localStorage.getItem(WORKSPACE_ID);
if (this.operationType === 'edit') {
const nowIds = param.projectIds;
let sign = true;
this.dbProjectIds.forEach(dbId => {
if (nowIds.indexOf(dbId) === -1 && sign) {
sign = false;
this.$confirm(this.$t('test_track.case.cancel_relevance_project'), this.$t('commons.prompt'), {
confirmButtonText: this.$t('commons.confirm'),
cancelButtonText: this.$t('commons.cancel'),
type: 'warning'
}).then(() => {
this.editTestPlan(param);
}).catch(() => {
this.$info(this.$t('commons.cancel'))
});
}
});
if (sign) {
this.editTestPlan(param);
}
} else {
this.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);
});
} else {
return false;
}
@ -242,24 +199,6 @@ export default {
}
return true;
},
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) {
this.projects = response.data.filter(da => da.id !== getCurrentProjectID());
} else {
this.$warning()(response.message);
}
});
},
setPrincipalOptions() {
let workspaceId = localStorage.getItem(WORKSPACE_ID);
this.$post('/user/ws/member/tester/list', {workspaceId: workspaceId}, response => {