diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/MsScenario.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/MsScenario.java index 6267b7ee35..478a7a5805 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/MsScenario.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/MsScenario.java @@ -89,6 +89,7 @@ public class MsScenario extends MsTestElement { if (scenario != null && StringUtils.isNotEmpty(scenario.getScenarioDefinition())) { JSONObject element = JSON.parseObject(scenario.getScenarioDefinition()); this.setName(scenario.getName()); + this.setProjectId(scenario.getProjectId()); hashTree = mapper.readValue(element.getString("hashTree"), new TypeReference>() { }); // 场景变量 diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java index 4e0a353f18..2584f58a20 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java @@ -126,8 +126,14 @@ public class MsHTTPSamplerProxy extends MsTestElement { config.setConfig(getEnvironmentConfig(useEnvironment)); } - // 1.8 之前历史数据 - if (StringUtils.isEmpty(this.getProjectId()) && config.getConfig() != null && !config.getConfig().isEmpty()) { + // 数据兼容处理 + if(config.getConfig() != null && StringUtils.isNotEmpty(this.getProjectId()) && config.getConfig().containsKey(this.getProjectId())){ + // 1.8 之后 当前正常数据 + } else if (config.getConfig() != null && config.getConfig().containsKey(getParentProjectId())) { + // 1.8 前后 混合数据 + this.setProjectId(getParentProjectId()); + } else { + // 1.8 之前 数据 this.setProjectId("historyProjectID"); } @@ -279,6 +285,17 @@ public class MsHTTPSamplerProxy extends MsTestElement { return false; } + private String getParentProjectId() { + MsTestElement parent = this.getParent(); + while(parent != null) { + if (StringUtils.isNotBlank(parent.getProjectId())) { + return parent.getProjectId(); + } + parent = parent.getParent(); + } + return ""; + } + private String getRestParameters(String path) { StringBuffer stringBuffer = new StringBuffer(); stringBuffer.append(path); 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 f3d2dd1433..19aa55f9f4 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java @@ -409,6 +409,7 @@ public class ApiAutomationService { } else if (StringUtils.equals(tr.getType(), "scenario")) { if (tr.isEnable()) { ApiScenarioDTO apiScenario = getApiScenario(tr.getId()); + env.getProjectIds().add(apiScenario.getProjectId()); String scenarioDefinition = apiScenario.getScenarioDefinition(); JSONObject element1 = JSON.parseObject(scenarioDefinition); LinkedList hashTree1 = mapper.readValue(element1.getString("hashTree"), new TypeReference>(){}); @@ -432,6 +433,7 @@ public class ApiAutomationService { if (!tr.isEnable()) { continue; } + env.getProjectIds().add(tr.getProjectId()); if (CollectionUtils.isNotEmpty(tr.getHashTree())) { getHashTree(tr.getHashTree(), env); } @@ -476,6 +478,7 @@ public class ApiAutomationService { } else if (StringUtils.equals(tr.getType(), "scenario")) { if (tr.isEnable()) { ApiScenarioDTO apiScenario = getApiScenario(tr.getId()); + env.getProjectIds().add(apiScenario.getProjectId()); String scenarioDefinition = apiScenario.getScenarioDefinition(); JSONObject element1 = JSON.parseObject(scenarioDefinition); LinkedList hashTree1 = mapper.readValue(element1.getString("hashTree"), new TypeReference>(){}); @@ -499,6 +502,7 @@ public class ApiAutomationService { if (!tr.isEnable()) { continue; } + env.getProjectIds().add(tr.getProjectId()); if (CollectionUtils.isNotEmpty(tr.getHashTree())) { getHashTree(tr.getHashTree(), env); }