组织,工作空间相关资源关联删除

This commit is contained in:
shiziyuan9527 2020-05-06 14:12:03 +08:00
parent 69586479ba
commit b0c5bd52ec
5 changed files with 82 additions and 3 deletions

View File

@ -67,6 +67,23 @@ public class OrganizationService {
}
public void deleteOrganization(String organizationId) {
WorkspaceExample example = new WorkspaceExample();
WorkspaceExample.Criteria criteria = example.createCriteria();
criteria.andOrganizationIdEqualTo(organizationId);
// delete workspace
List<Workspace> workspaces = workspaceMapper.selectByExample(example);
List<String> workspaceIdList = workspaces.stream().map(Workspace::getId).collect(Collectors.toList());
for (String workspaceId : workspaceIdList) {
workspaceService.deleteWorkspace(workspaceId);
}
// delete organization member
UserRoleExample userRoleExample = new UserRoleExample();
userRoleExample.createCriteria().andSourceIdEqualTo(organizationId);
userRoleMapper.deleteByExample(userRoleExample);
// delete org
organizationMapper.deleteByPrimaryKey(organizationId);
}

View File

@ -50,13 +50,35 @@ public class PerformanceTestService {
@Resource
private LoadTestReportLogMapper loadTestReportLogMapper;
@Resource
private LoadTestReportResultMapper loadTestReportResultMapper;
@Resource
private TestResourceService testResourceService;
@Resource
private ReportService reportService;
public List<LoadTestDTO> list(QueryTestPlanRequest request) {
return extLoadTestMapper.list(request);
}
public void delete(DeleteTestPlanRequest request) {
String testId = request.getId();
LoadTestReportExample loadTestReportExample = new LoadTestReportExample();
loadTestReportExample.createCriteria().andTestIdEqualTo(testId);
List<LoadTestReport> loadTestReports = loadTestReportMapper.selectByExample(loadTestReportExample);
List<String> reportIdList = loadTestReports.stream().map(LoadTestReport::getId).collect(Collectors.toList());
// delete load_test_report_result
LoadTestReportResultExample loadTestReportResultExample = new LoadTestReportResultExample();
loadTestReportResultExample.createCriteria().andReportIdIn(reportIdList);
loadTestReportResultMapper.deleteByExample(loadTestReportResultExample);
// delete load_test_report, delete load_test_report_detail
reportIdList.forEach(reportId -> {
loadTestReportDetailMapper.deleteByPrimaryKey(reportId);
reportService.deleteReport(reportId);
});
// delete load_test
loadTestMapper.deleteByPrimaryKey(request.getId());
deleteFileByTestId(request.getId());

View File

@ -1,11 +1,15 @@
package io.metersphere.service;
import io.metersphere.base.domain.LoadTest;
import io.metersphere.base.domain.LoadTestExample;
import io.metersphere.base.domain.Project;
import io.metersphere.base.domain.ProjectExample;
import io.metersphere.base.mapper.LoadTestMapper;
import io.metersphere.base.mapper.ProjectMapper;
import io.metersphere.base.mapper.ext.ExtProjectMapper;
import io.metersphere.commons.exception.MSException;
import io.metersphere.controller.request.ProjectRequest;
import io.metersphere.controller.request.testplan.DeleteTestPlanRequest;
import io.metersphere.dto.ProjectDTO;
import io.metersphere.i18n.Translator;
import io.metersphere.user.SessionUtils;
@ -16,6 +20,7 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
@Service
@Transactional(rollbackFor = Exception.class)
@ -24,6 +29,10 @@ public class ProjectService {
private ProjectMapper projectMapper;
@Resource
private ExtProjectMapper extProjectMapper;
@Resource
private PerformanceTestService performanceTestService;
@Resource
private LoadTestMapper loadTestMapper;
public Project addProject(Project project) {
if (StringUtils.isBlank(project.getName())) {
@ -54,11 +63,27 @@ public class ProjectService {
}
public void deleteProject(String projectId) {
// delete test
LoadTestExample loadTestExample = new LoadTestExample();
loadTestExample.createCriteria().andProjectIdEqualTo(projectId);
List<LoadTest> loadTests = loadTestMapper.selectByExample(loadTestExample);
List<String> loadTestIdList = loadTests.stream().map(LoadTest::getId).collect(Collectors.toList());
loadTestIdList.forEach(loadTestId -> {
DeleteTestPlanRequest deleteTestPlanRequest = new DeleteTestPlanRequest();
deleteTestPlanRequest.setId(loadTestId);
performanceTestService.delete(deleteTestPlanRequest);
});
// TODO 删除项目下 测试跟踪 相关
// TODO 删除项目下 接口测试 相关
// delete project
projectMapper.deleteByPrimaryKey(projectId);
}
public void updateProject(Project project) {
project.setCreateTime(null);// 创建时间禁止修改
project.setCreateTime(null);
project.setUpdateTime(System.currentTimeMillis());
projectMapper.updateByPrimaryKeySelective(project);
}

View File

@ -97,6 +97,21 @@ public class WorkspaceService {
}
public void deleteWorkspace(String workspaceId) {
// delete project
ProjectExample projectExample = new ProjectExample();
projectExample.createCriteria().andWorkspaceIdEqualTo(workspaceId);
List<Project> projectList = projectMapper.selectByExample(projectExample);
List<String> projectIdList = projectList.stream().map(Project::getId).collect(Collectors.toList());
projectIdList.forEach(projectId -> {
projectService.deleteProject(projectId);
});
// delete workspace member
UserRoleExample userRoleExample = new UserRoleExample();
userRoleExample.createCriteria().andSourceIdEqualTo(workspaceId);
userRoleMapper.deleteByExample(userRoleExample);
// delete workspace
workspaceMapper.deleteByPrimaryKey(workspaceId);
}

View File

@ -56,7 +56,7 @@ export default {
workspace: {
'create': '创建工作空间',
'update': '修改工作空间',
'delete_confirm': '删除工作空间会联删除该工作空间下的资源,确定要删除吗?',
'delete_confirm': '删除工作空间会联删除该工作空间下的资源,确定要删除吗?',
'add': '添加工作空间',
'input_name': '请输入工作空间名称',
'search_by_name': '根据名称搜索',
@ -67,7 +67,7 @@ export default {
organization: {
'create': '创建组织',
'modify': '修改组织',
'delete_confirm': '这个组织确定要删除吗?',
'delete_confirm': '删除组织会关联删除该组织下的资源,确定要删除吗?',
'input_name': '请输入组织名称',
'select_organization': '请选择组织',
'search_by_name': '根据名称搜索',