fix (接口测试): 删除项目级联删除接口测试相关资源
This commit is contained in:
parent
60f41171b2
commit
03d3dceb32
|
@ -0,0 +1,61 @@
|
||||||
|
package io.metersphere.api.service;
|
||||||
|
|
||||||
|
import io.metersphere.base.domain.*;
|
||||||
|
import io.metersphere.base.mapper.ApiDefinitionMapper;
|
||||||
|
import io.metersphere.base.mapper.ApiModuleMapper;
|
||||||
|
import io.metersphere.base.mapper.ApiScenarioMapper;
|
||||||
|
import io.metersphere.base.mapper.ApiScenarioModuleMapper;
|
||||||
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Transactional
|
||||||
|
/**
|
||||||
|
* 接口测试所有级联删除资源
|
||||||
|
*/
|
||||||
|
public class ApiTestDelService {
|
||||||
|
@Resource
|
||||||
|
private ApiDefinitionService apiDefinitionService;
|
||||||
|
@Resource
|
||||||
|
private ApiAutomationService apiAutomationService;
|
||||||
|
@Resource
|
||||||
|
private ApiScenarioMapper apiScenarioMapper;
|
||||||
|
@Resource
|
||||||
|
private ApiDefinitionMapper apiDefinitionMapper;
|
||||||
|
@Resource
|
||||||
|
private ApiModuleMapper apiModuleMapper;
|
||||||
|
@Resource
|
||||||
|
private ApiScenarioModuleMapper apiScenarioModuleMapper;
|
||||||
|
|
||||||
|
public void delete(String projectId) {
|
||||||
|
ApiDefinitionExample example = new ApiDefinitionExample();
|
||||||
|
example.createCriteria().andProjectIdEqualTo(projectId);
|
||||||
|
// api and case
|
||||||
|
List<String> apiIds = apiDefinitionMapper.selectByExample(example).stream().map(ApiDefinition::getId).collect(Collectors.toList());
|
||||||
|
if (CollectionUtils.isNotEmpty(apiIds)) {
|
||||||
|
apiDefinitionService.deleteBatch(apiIds);
|
||||||
|
}
|
||||||
|
// scenario
|
||||||
|
ApiScenarioExample scenarioExample = new ApiScenarioExample();
|
||||||
|
scenarioExample.createCriteria().andProjectIdEqualTo(projectId);
|
||||||
|
List<String> scenarios = apiScenarioMapper.selectByExample(scenarioExample).stream().map(ApiScenario::getId).collect(Collectors.toList());
|
||||||
|
if (CollectionUtils.isNotEmpty(scenarios)) {
|
||||||
|
apiAutomationService.deleteBatch(scenarios);
|
||||||
|
}
|
||||||
|
// api module
|
||||||
|
ApiModuleExample moduleExample = new ApiModuleExample();
|
||||||
|
moduleExample.createCriteria().andProjectIdEqualTo(projectId);
|
||||||
|
apiModuleMapper.deleteByExample(moduleExample);
|
||||||
|
|
||||||
|
// scenario module
|
||||||
|
ApiScenarioModuleExample scenarioModuleExample = new ApiScenarioModuleExample();
|
||||||
|
scenarioModuleExample.createCriteria().andProjectIdEqualTo(projectId);
|
||||||
|
apiScenarioModuleMapper.deleteByExample(scenarioModuleExample);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,6 +5,7 @@ import io.metersphere.api.dto.DeleteAPITestRequest;
|
||||||
import io.metersphere.api.dto.QueryAPITestRequest;
|
import io.metersphere.api.dto.QueryAPITestRequest;
|
||||||
import io.metersphere.api.service.APITestService;
|
import io.metersphere.api.service.APITestService;
|
||||||
import io.metersphere.api.service.ApiAutomationService;
|
import io.metersphere.api.service.ApiAutomationService;
|
||||||
|
import io.metersphere.api.service.ApiTestDelService;
|
||||||
import io.metersphere.api.service.ApiTestEnvironmentService;
|
import io.metersphere.api.service.ApiTestEnvironmentService;
|
||||||
import io.metersphere.api.tcp.TCPPool;
|
import io.metersphere.api.tcp.TCPPool;
|
||||||
import io.metersphere.base.domain.*;
|
import io.metersphere.base.domain.*;
|
||||||
|
@ -89,7 +90,8 @@ public class ProjectService {
|
||||||
private ExtUserMapper extUserMapper;
|
private ExtUserMapper extUserMapper;
|
||||||
@Resource
|
@Resource
|
||||||
private ScheduleService scheduleService;
|
private ScheduleService scheduleService;
|
||||||
|
@Resource
|
||||||
|
private ApiTestDelService apiTestDelService;
|
||||||
@Value("${tcp.mock.port}")
|
@Value("${tcp.mock.port}")
|
||||||
private String tcpMockPorts;
|
private String tcpMockPorts;
|
||||||
|
|
||||||
|
@ -189,6 +191,7 @@ public class ProjectService {
|
||||||
|
|
||||||
// 删除项目下 接口测试 相关
|
// 删除项目下 接口测试 相关
|
||||||
deleteAPIResourceByProjectId(projectId);
|
deleteAPIResourceByProjectId(projectId);
|
||||||
|
apiTestDelService.delete(projectId);
|
||||||
|
|
||||||
// User Group
|
// User Group
|
||||||
deleteProjectUserGroup(projectId);
|
deleteProjectUserGroup(projectId);
|
||||||
|
|
Loading…
Reference in New Issue