refactor(测试计划): 删除测试计划时同时删除相关联数据
This commit is contained in:
parent
1d84cda5fe
commit
fbce41bb3e
|
@ -16,13 +16,14 @@ import io.metersphere.controller.request.ProjectRequest;
|
|||
import io.metersphere.dto.ProjectDTO;
|
||||
import io.metersphere.i18n.Translator;
|
||||
import io.metersphere.performance.service.PerformanceTestService;
|
||||
import io.metersphere.track.request.testcase.QueryTestPlanRequest;
|
||||
import io.metersphere.track.request.testplan.DeleteTestPlanRequest;
|
||||
import io.metersphere.track.service.TestCaseService;
|
||||
import io.metersphere.track.service.TestPlanProjectService;
|
||||
import io.metersphere.track.service.TestPlanService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
@ -54,6 +55,8 @@ public class ProjectService {
|
|||
private TestCaseService testCaseService;
|
||||
@Resource
|
||||
private APITestService apiTestService;
|
||||
@Resource
|
||||
private TestPlanProjectService testPlanProjectService;
|
||||
|
||||
public Project addProject(Project project) {
|
||||
if (StringUtils.isBlank(project.getName())) {
|
||||
|
@ -96,21 +99,22 @@ public class ProjectService {
|
|||
performanceTestService.delete(deleteTestPlanRequest);
|
||||
});
|
||||
|
||||
// TODO 删除项目下 测试跟踪 相关
|
||||
// 删除项目下 测试跟踪 相关
|
||||
deleteTrackResourceByProjectId(projectId);
|
||||
|
||||
// TODO 删除项目下 接口测试 相关
|
||||
// 删除项目下 接口测试 相关
|
||||
deleteAPIResourceByProjectId(projectId);
|
||||
// delete project
|
||||
projectMapper.deleteByPrimaryKey(projectId);
|
||||
}
|
||||
|
||||
private void deleteTrackResourceByProjectId(String projectId) {
|
||||
QueryTestPlanRequest request = new QueryTestPlanRequest();
|
||||
request.setProjectId(projectId);
|
||||
testPlanService.listTestPlan(request).forEach(testPlan -> {
|
||||
testPlanService.deleteTestPlan(testPlan.getId());
|
||||
});
|
||||
List<String> testPlanIds = testPlanProjectService.getPlanIdByProjectId(projectId);
|
||||
if (!CollectionUtils.isEmpty(testPlanIds)) {
|
||||
testPlanIds.forEach(testPlanId -> {
|
||||
testPlanService.deleteTestPlan(testPlanId);
|
||||
});
|
||||
}
|
||||
testCaseService.deleteTestCaseByProjectId(projectId);
|
||||
}
|
||||
|
||||
|
|
|
@ -271,7 +271,6 @@ public class TestCaseNodeService {
|
|||
}
|
||||
|
||||
public List<TestCaseNodeDTO> getAllNodeByPlanId(QueryNodeRequest request) {
|
||||
// todo jenkins 获取模块
|
||||
String planId = request.getTestPlanId();
|
||||
String projectId = request.getProjectId();
|
||||
TestPlan testPlan = testPlanMapper.selectByPrimaryKey(planId);
|
||||
|
|
|
@ -6,8 +6,10 @@ import io.metersphere.base.domain.TestPlanProject;
|
|||
import io.metersphere.base.domain.TestPlanProjectExample;
|
||||
import io.metersphere.base.mapper.ProjectMapper;
|
||||
import io.metersphere.base.mapper.TestPlanProjectMapper;
|
||||
import org.python.antlr.ast.Str;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
|
@ -46,4 +48,23 @@ public class TestPlanProjectService {
|
|||
List<Project> projects = projectMapper.selectByExample(projectExample);
|
||||
return Optional.ofNullable(projects).orElse(new ArrayList<>());
|
||||
}
|
||||
|
||||
public void deleteTestPlanProjectByPlanId(String planId) {
|
||||
TestPlanProjectExample testPlanProjectExample = new TestPlanProjectExample();
|
||||
testPlanProjectExample.createCriteria().andTestPlanIdEqualTo(planId);
|
||||
testPlanProjectMapper.deleteByExample(testPlanProjectExample);
|
||||
}
|
||||
|
||||
public List<String> getPlanIdByProjectId(String projectId) {
|
||||
TestPlanProjectExample testPlanProjectExample = new TestPlanProjectExample();
|
||||
testPlanProjectExample.createCriteria().andProjectIdEqualTo(projectId);
|
||||
List<TestPlanProject> testPlanProjects = testPlanProjectMapper.selectByExample(testPlanProjectExample);
|
||||
if (CollectionUtils.isEmpty(testPlanProjects)) {
|
||||
return null;
|
||||
}
|
||||
return testPlanProjects
|
||||
.stream()
|
||||
.map(TestPlanProject::getTestPlanId)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -131,6 +131,7 @@ public class TestPlanService {
|
|||
|
||||
public int deleteTestPlan(String planId) {
|
||||
deleteTestCaseByPlanId(planId);
|
||||
testPlanProjectService.deleteTestPlanProjectByPlanId(planId);
|
||||
return testPlanMapper.deleteByPrimaryKey(planId);
|
||||
}
|
||||
|
||||
|
|
|
@ -192,9 +192,13 @@ export default {
|
|||
this.total = data.itemCount;
|
||||
this.tableData = data.listObject;
|
||||
for (let i = 0; i < this.tableData.length; i++) {
|
||||
let path = "/test/plan/project/name/" + this.tableData[i].id;
|
||||
let path = "/test/plan/project/" + this.tableData[i].id;
|
||||
this.$get(path, res => {
|
||||
this.$set(this.tableData[i], "projectName", res.data);
|
||||
let arr = res.data;
|
||||
let projectName = arr.map(data => data.name).join("、");
|
||||
let projectIds = arr.map(data => data.id);
|
||||
this.$set(this.tableData[i], "projectName", projectName);
|
||||
this.$set(this.tableData[i], "projectIds", projectIds);
|
||||
})
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue