refactor(测试计划): 删除测试计划时同时删除相关联数据

This commit is contained in:
shiziyuan9527 2020-09-08 15:20:30 +08:00
parent 1d84cda5fe
commit fbce41bb3e
5 changed files with 40 additions and 11 deletions

View File

@ -16,13 +16,14 @@ import io.metersphere.controller.request.ProjectRequest;
import io.metersphere.dto.ProjectDTO; import io.metersphere.dto.ProjectDTO;
import io.metersphere.i18n.Translator; import io.metersphere.i18n.Translator;
import io.metersphere.performance.service.PerformanceTestService; import io.metersphere.performance.service.PerformanceTestService;
import io.metersphere.track.request.testcase.QueryTestPlanRequest;
import io.metersphere.track.request.testplan.DeleteTestPlanRequest; import io.metersphere.track.request.testplan.DeleteTestPlanRequest;
import io.metersphere.track.service.TestCaseService; import io.metersphere.track.service.TestCaseService;
import io.metersphere.track.service.TestPlanProjectService;
import io.metersphere.track.service.TestPlanService; import io.metersphere.track.service.TestPlanService;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
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.List; import java.util.List;
@ -54,6 +55,8 @@ public class ProjectService {
private TestCaseService testCaseService; private TestCaseService testCaseService;
@Resource @Resource
private APITestService apiTestService; private APITestService apiTestService;
@Resource
private TestPlanProjectService testPlanProjectService;
public Project addProject(Project project) { public Project addProject(Project project) {
if (StringUtils.isBlank(project.getName())) { if (StringUtils.isBlank(project.getName())) {
@ -96,21 +99,22 @@ public class ProjectService {
performanceTestService.delete(deleteTestPlanRequest); performanceTestService.delete(deleteTestPlanRequest);
}); });
// TODO 删除项目下 测试跟踪 相关 // 删除项目下 测试跟踪 相关
deleteTrackResourceByProjectId(projectId); deleteTrackResourceByProjectId(projectId);
// TODO 删除项目下 接口测试 相关 // 删除项目下 接口测试 相关
deleteAPIResourceByProjectId(projectId); deleteAPIResourceByProjectId(projectId);
// delete project // delete project
projectMapper.deleteByPrimaryKey(projectId); projectMapper.deleteByPrimaryKey(projectId);
} }
private void deleteTrackResourceByProjectId(String projectId) { private void deleteTrackResourceByProjectId(String projectId) {
QueryTestPlanRequest request = new QueryTestPlanRequest(); List<String> testPlanIds = testPlanProjectService.getPlanIdByProjectId(projectId);
request.setProjectId(projectId); if (!CollectionUtils.isEmpty(testPlanIds)) {
testPlanService.listTestPlan(request).forEach(testPlan -> { testPlanIds.forEach(testPlanId -> {
testPlanService.deleteTestPlan(testPlan.getId()); testPlanService.deleteTestPlan(testPlanId);
}); });
}
testCaseService.deleteTestCaseByProjectId(projectId); testCaseService.deleteTestCaseByProjectId(projectId);
} }

View File

@ -271,7 +271,6 @@ public class TestCaseNodeService {
} }
public List<TestCaseNodeDTO> getAllNodeByPlanId(QueryNodeRequest request) { public List<TestCaseNodeDTO> getAllNodeByPlanId(QueryNodeRequest request) {
// todo jenkins 获取模块
String planId = request.getTestPlanId(); String planId = request.getTestPlanId();
String projectId = request.getProjectId(); String projectId = request.getProjectId();
TestPlan testPlan = testPlanMapper.selectByPrimaryKey(planId); TestPlan testPlan = testPlanMapper.selectByPrimaryKey(planId);

View File

@ -6,8 +6,10 @@ import io.metersphere.base.domain.TestPlanProject;
import io.metersphere.base.domain.TestPlanProjectExample; import io.metersphere.base.domain.TestPlanProjectExample;
import io.metersphere.base.mapper.ProjectMapper; import io.metersphere.base.mapper.ProjectMapper;
import io.metersphere.base.mapper.TestPlanProjectMapper; import io.metersphere.base.mapper.TestPlanProjectMapper;
import org.python.antlr.ast.Str;
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.ArrayList; import java.util.ArrayList;
@ -46,4 +48,23 @@ public class TestPlanProjectService {
List<Project> projects = projectMapper.selectByExample(projectExample); List<Project> projects = projectMapper.selectByExample(projectExample);
return Optional.ofNullable(projects).orElse(new ArrayList<>()); 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());
}
} }

View File

@ -131,6 +131,7 @@ public class TestPlanService {
public int deleteTestPlan(String planId) { public int deleteTestPlan(String planId) {
deleteTestCaseByPlanId(planId); deleteTestCaseByPlanId(planId);
testPlanProjectService.deleteTestPlanProjectByPlanId(planId);
return testPlanMapper.deleteByPrimaryKey(planId); return testPlanMapper.deleteByPrimaryKey(planId);
} }

View File

@ -192,9 +192,13 @@ export default {
this.total = data.itemCount; this.total = data.itemCount;
this.tableData = data.listObject; this.tableData = data.listObject;
for (let i = 0; i < this.tableData.length; i++) { 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.$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);
}) })
} }
}); });