diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsTCPSampler.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsTCPSampler.java index 1a5f5b276b..77f3cb0c45 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsTCPSampler.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsTCPSampler.java @@ -159,7 +159,9 @@ public class MsTCPSampler extends MsTestElement { } if (config.getConfig() == null) { // 单独接口执行 - this.setProjectId(config.getProjectId()); + if(StringUtils.isNotEmpty(config.getProjectId())) { + this.setProjectId(config.getProjectId()); + } config.setConfig(ElementUtil.getEnvironmentConfig(StringUtils.isNotEmpty(this.getEnvironmentId()) ? this.getEnvironmentId() : useEnvironment, this.getProjectId(), this.isMockEnvironment())); } EnvironmentConfig envConfig = null; diff --git a/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioSerialService.java b/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioSerialService.java index 8f3ebb3ff8..b795b29085 100644 --- a/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioSerialService.java +++ b/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioSerialService.java @@ -215,7 +215,7 @@ public class ApiScenarioSerialService { group.setName(runRequest.getReportId()); group.setProjectId(caseWithBLOBs.getProjectId()); - MsTestElement testElement = parse(data, testId, envId); + MsTestElement testElement = parse(data, testId, envId, caseWithBLOBs.getProjectId()); group.setHashTree(new LinkedList<>()); group.getHashTree().add(testElement); testPlan.getHashTree().add(group); @@ -235,7 +235,7 @@ public class ApiScenarioSerialService { return null; } - private MsTestElement parse(String api, String planId, String envId) { + private MsTestElement parse(String api, String planId, String envId, String projectId) { try { JSONObject element = JSON.parseObject(api, Feature.DisableSpecialKeyDetect); ElementUtil.dataFormatting(element); @@ -258,6 +258,9 @@ public class ApiScenarioSerialService { } if (element.getString("type").equals("TCPSampler")) { MsTCPSampler msTCPSampler = JSON.parseObject(api, MsTCPSampler.class, Feature.DisableSpecialKeyDetect); + if (StringUtils.isEmpty(msTCPSampler.getProjectId())) { + msTCPSampler.setProjectId(projectId); + } if (StringUtils.isNotEmpty(envId)) { msTCPSampler.setUseEnvironment(envId); }