From 493ed748f92f1616910748fd2e913d8fbce41266 Mon Sep 17 00:00:00 2001 From: guoyuqi Date: Wed, 26 Jan 2022 14:44:35 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=9C=BA=E6=99=AF=E5=AF=BC=E5=85=A5=E6=B2=A1?= =?UTF-8?q?=E9=80=89=E6=A8=A1=E5=9D=97=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1010016--user=郭雨琦 【ID1010016】场景导入没有选模块时应该导到未规划模块下,否则会导致导入的场景统计不正确 --- .../api/service/ApiAutomationService.java | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java index a250cacb20..1c51b15abd 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java @@ -5,6 +5,7 @@ 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; @@ -138,6 +139,7 @@ public class ApiAutomationService { @Resource private ExtProjectVersionMapper extProjectVersionMapper; + private ThreadLocal currentScenarioOrder = new ThreadLocal<>(); public ApiScenarioDTO getDto(String id) { @@ -469,13 +471,7 @@ public class ApiAutomationService { } if (StringUtils.isEmpty(request.getApiScenarioModuleId()) || "default-module".equals(request.getApiScenarioModuleId())) { - ApiScenarioModuleExample example = new ApiScenarioModuleExample(); - example.createCriteria().andProjectIdEqualTo(request.getProjectId()).andNameEqualTo("未规划场景"); - List modules = apiScenarioModuleMapper.selectByExample(example); - if (CollectionUtils.isNotEmpty(modules)) { - scenario.setApiScenarioModuleId(modules.get(0).getId()); - scenario.setModulePath(modules.get(0).getName()); - } + replenishScenarioModuleIdPath(request.getProjectId(), apiScenarioModuleMapper, scenario); } saveFollows(scenario.getId(), request.getFollows()); if (StringUtils.isEmpty(request.getVersionId())) { @@ -1367,6 +1363,13 @@ 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())){ + replenishScenarioModuleIdPath(request.getProjectId(), apiScenarioModuleMapper, item); + } + + if(StringUtils.isBlank(item.getCreateUser())){ + item.setCreateUser(SessionUtils.getUserId()); + } if (item.getName().length() > 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 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) { Long order = currentScenarioOrder.get(); if (order == null) {