fix(接口测试): 解决场景导入没选模块的问题

--bug=1010016--user=郭雨琦 【ID1010016】场景导入没有选模块时应该导到未规划模块下,否则会导致导入的场景统计不正确
This commit is contained in:
guoyuqi 2022-01-26 14:44:35 +08:00 committed by xiaomeinvG
parent d5240ab15a
commit d7db073997
1 changed files with 20 additions and 7 deletions

View File

@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import io.metersphere.api.dto.*; import io.metersphere.api.dto.*;
import io.metersphere.api.dto.automation.*; 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.ScenarioImport;
import io.metersphere.api.dto.automation.parse.ScenarioImportParserFactory; import io.metersphere.api.dto.automation.parse.ScenarioImportParserFactory;
import io.metersphere.api.dto.datacount.ApiDataCountResult; import io.metersphere.api.dto.datacount.ApiDataCountResult;
@ -138,6 +139,7 @@ public class ApiAutomationService {
@Resource @Resource
private ExtProjectVersionMapper extProjectVersionMapper; private ExtProjectVersionMapper extProjectVersionMapper;
private ThreadLocal<Long> currentScenarioOrder = new ThreadLocal<>(); private ThreadLocal<Long> currentScenarioOrder = new ThreadLocal<>();
public ApiScenarioDTO getDto(String id) { public ApiScenarioDTO getDto(String id) {
@ -469,13 +471,7 @@ public class ApiAutomationService {
} }
if (StringUtils.isEmpty(request.getApiScenarioModuleId()) || "default-module".equals(request.getApiScenarioModuleId())) { if (StringUtils.isEmpty(request.getApiScenarioModuleId()) || "default-module".equals(request.getApiScenarioModuleId())) {
ApiScenarioModuleExample example = new ApiScenarioModuleExample(); replenishScenarioModuleIdPath(request.getProjectId(), apiScenarioModuleMapper, scenario);
example.createCriteria().andProjectIdEqualTo(request.getProjectId()).andNameEqualTo("未规划场景");
List<ApiScenarioModule> modules = apiScenarioModuleMapper.selectByExample(example);
if (CollectionUtils.isNotEmpty(modules)) {
scenario.setApiScenarioModuleId(modules.get(0).getId());
scenario.setModulePath(modules.get(0).getName());
}
} }
saveFollows(scenario.getId(), request.getFollows()); saveFollows(scenario.getId(), request.getFollows());
if (StringUtils.isEmpty(request.getVersionId())) { if (StringUtils.isEmpty(request.getVersionId())) {
@ -1367,6 +1363,13 @@ public class ApiAutomationService {
request.setDefaultVersion(defaultVersion); request.setDefaultVersion(defaultVersion);
for (int i = 0; i < data.size(); i++) { for (int i = 0; i < data.size(); i++) {
ApiScenarioWithBLOBs item = data.get(i); ApiScenarioWithBLOBs item = data.get(i);
if(StringUtils.isBlank(item.getApiScenarioModuleId())|| "default-module".equals(item.getApiScenarioModuleId())){
replenishScenarioModuleIdPath(request.getProjectId(), apiScenarioModuleMapper, item);
}
if(StringUtils.isBlank(item.getCreateUser())){
item.setCreateUser(SessionUtils.getUserId());
}
if (item.getName().length() > 255) { if (item.getName().length() > 255) {
item.setName(item.getName().substring(0, 255)); item.setName(item.getName().substring(0, 255));
} }
@ -1395,6 +1398,16 @@ public class ApiAutomationService {
} }
} }
private void replenishScenarioModuleIdPath(String request, ApiScenarioModuleMapper apiScenarioModuleMapper, ApiScenarioWithBLOBs item) {
ApiScenarioModuleExample example = new ApiScenarioModuleExample();
example.createCriteria().andProjectIdEqualTo(request).andNameEqualTo("未规划场景");
List<ApiScenarioModule> modules = apiScenarioModuleMapper.selectByExample(example);
if (CollectionUtils.isNotEmpty(modules)) {
item.setApiScenarioModuleId(modules.get(0).getId());
item.setModulePath(modules.get(0).getName());
}
}
private Long getImportNextOrder(String projectId) { private Long getImportNextOrder(String projectId) {
Long order = currentScenarioOrder.get(); Long order = currentScenarioOrder.get();
if (order == null) { if (order == null) {