fix(接口测试): 回收站批量删除时删除所有的版本

This commit is contained in:
CaptainB 2022-01-26 18:49:47 +08:00 committed by 刘瑞斌
parent 5e265e99ee
commit fd6819efd8
2 changed files with 36 additions and 6 deletions

View File

@ -5,7 +5,6 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import io.metersphere.api.dto.*;
import io.metersphere.api.dto.automation.*;
import io.metersphere.api.dto.automation.parse.ApiScenarioImportUtil;
import io.metersphere.api.dto.automation.parse.ScenarioImport;
import io.metersphere.api.dto.automation.parse.ScenarioImportParserFactory;
import io.metersphere.api.dto.datacount.ApiDataCountResult;
@ -1363,11 +1362,11 @@ public class ApiAutomationService {
request.setDefaultVersion(defaultVersion);
for (int i = 0; i < data.size(); i++) {
ApiScenarioWithBLOBs item = data.get(i);
if(StringUtils.isBlank(item.getApiScenarioModuleId())|| "default-module".equals(item.getApiScenarioModuleId())){
if (StringUtils.isBlank(item.getApiScenarioModuleId()) || "default-module".equals(item.getApiScenarioModuleId())) {
replenishScenarioModuleIdPath(request.getProjectId(), apiScenarioModuleMapper, item);
}
if(StringUtils.isBlank(item.getCreateUser())){
if (StringUtils.isBlank(item.getCreateUser())) {
item.setCreateUser(SessionUtils.getUserId());
}
if (item.getName().length() > 255) {
@ -1617,7 +1616,21 @@ public class ApiAutomationService {
public void deleteBatchByCondition(ApiScenarioBatchRequest request) {
ServiceUtils.getSelectAllIds(request, request.getCondition(),
(query) -> extApiScenarioMapper.selectIdsByQuery(query));
this.deleteBatch(request.getIds());
List<String> ids = request.getIds();
if (CollectionUtils.isEmpty(ids)) {
return;
}
ids.forEach(id -> {
ApiScenarioWithBLOBs scenario = apiScenarioMapper.selectByPrimaryKey(id);
if (scenario == null) {
return;
}
ApiScenarioExample example = new ApiScenarioExample();
example.createCriteria().andRefIdEqualTo(scenario.getRefId());
List<ApiScenario> apiScenarios = apiScenarioMapper.selectByExample(example);
List<String> apiIds = apiScenarios.stream().map(ApiScenario::getId).collect(Collectors.toList());
this.deleteBatch(apiIds);
});
}
/**

View File

@ -1320,8 +1320,25 @@ public class ApiDefinitionService {
}
public void deleteByParams(ApiBatchRequest request) {
apiDefinitionMapper.deleteByExample(getBatchExample(request));
apiTestCaseService.deleteBatchByDefinitionId(request.getIds());
List<String> ids = request.getIds();
if (CollectionUtils.isEmpty(ids)) {
return;
}
ids.forEach(id -> {
// 把所有版本的api移到回收站
ApiDefinitionWithBLOBs api = apiDefinitionMapper.selectByPrimaryKey(id);
if (api == null) {
return;
}
ApiDefinitionExample example = new ApiDefinitionExample();
example.createCriteria().andRefIdEqualTo(api.getRefId());
List<ApiDefinition> apiDefinitions = apiDefinitionMapper.selectByExample(example);
List<String> apiIds = apiDefinitions.stream().map(ApiDefinition::getId).collect(Collectors.toList());
apiTestCaseService.deleteBatchByDefinitionId(apiIds);
//
apiDefinitionMapper.deleteByExample(example);
});
}
public ApiDefinitionExample getBatchExample(ApiBatchRequest request) {