diff --git a/backend/src/main/java/io/metersphere/api/controller/ApiAutomationController.java b/backend/src/main/java/io/metersphere/api/controller/ApiAutomationController.java index 19ec738175..4fdb076cd3 100644 --- a/backend/src/main/java/io/metersphere/api/controller/ApiAutomationController.java +++ b/backend/src/main/java/io/metersphere/api/controller/ApiAutomationController.java @@ -97,7 +97,7 @@ public class ApiAutomationController { } @GetMapping("/getApiScenario/{id}") - public ApiScenarioDTO getScenarioDefinition(@PathVariable String id) { + public ApiScenarioWithBLOBs getScenarioDefinition(@PathVariable String id) { return apiAutomationService.getApiScenario(id); } @@ -106,6 +106,11 @@ public class ApiAutomationController { return apiAutomationService.getApiScenarioEnv(request.getDefinition()); } + @GetMapping("/getApiScenarioProjectId/{id}") + public ScenarioEnv getApiScenarioProjectId(@PathVariable String id) { + return apiAutomationService.getApiScenarioProjectId(id); + } + @PostMapping("/getApiScenarios") public List getApiScenarios(@RequestBody List ids) { return apiAutomationService.getApiScenarios(ids); 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 cd5a06e9b4..f4fedfeebc 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 @@ -28,6 +28,7 @@ import org.apache.jorphan.collections.HashTree; import java.net.URL; import java.net.URLDecoder; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.regex.Matcher; @@ -134,7 +135,17 @@ public class MsHTTPSamplerProxy extends MsTestElement { this.setProjectId(getParentProjectId()); } else { // 1.8 之前 数据 - this.setProjectId("historyProjectID"); + if (config.getConfig() != null) { + if (config.getConfig().containsKey("historyProjectID")) { + this.setProjectId("historyProjectID"); + } else { + // 测试计划执行 + Iterator it = config.getConfig().keySet().iterator(); + if (it.hasNext()) { + this.setProjectId(it.next()); + } + } + } } // 添加环境中的公共变量 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 19aa55f9f4..a577698cf3 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java @@ -361,15 +361,8 @@ public class ApiAutomationService { } } - public ApiScenarioDTO getApiScenario(String id) { - ApiScenarioDTO apiScenarioDTO = new ApiScenarioDTO(); - ApiScenarioWithBLOBs scenarioWithBLOBs = apiScenarioMapper.selectByPrimaryKey(id); - if (scenarioWithBLOBs != null) { - BeanUtils.copyBean(apiScenarioDTO, scenarioWithBLOBs); - setApiScenarioProjectIds(apiScenarioDTO); - return apiScenarioDTO; - } - return null; + public ApiScenarioWithBLOBs getApiScenario(String id) { + return apiScenarioMapper.selectByPrimaryKey(id); } public ScenarioEnv getApiScenarioEnv(String definition) { @@ -408,7 +401,7 @@ public class ApiAutomationService { } } else if (StringUtils.equals(tr.getType(), "scenario")) { if (tr.isEnable()) { - ApiScenarioDTO apiScenario = getApiScenario(tr.getId()); + ApiScenarioWithBLOBs apiScenario = getApiScenario(tr.getId()); env.getProjectIds().add(apiScenario.getProjectId()); String scenarioDefinition = apiScenario.getScenarioDefinition(); JSONObject element1 = JSON.parseObject(scenarioDefinition); @@ -433,7 +426,9 @@ public class ApiAutomationService { if (!tr.isEnable()) { continue; } - env.getProjectIds().add(tr.getProjectId()); + if (StringUtils.equals(tr.getType(), "scenario")) { + env.getProjectIds().add(tr.getProjectId()); + } if (CollectionUtils.isNotEmpty(tr.getHashTree())) { getHashTree(tr.getHashTree(), env); } @@ -477,7 +472,7 @@ public class ApiAutomationService { } } else if (StringUtils.equals(tr.getType(), "scenario")) { if (tr.isEnable()) { - ApiScenarioDTO apiScenario = getApiScenario(tr.getId()); + ApiScenarioWithBLOBs apiScenario = getApiScenario(tr.getId()); env.getProjectIds().add(apiScenario.getProjectId()); String scenarioDefinition = apiScenario.getScenarioDefinition(); JSONObject element1 = JSON.parseObject(scenarioDefinition); @@ -502,7 +497,9 @@ public class ApiAutomationService { if (!tr.isEnable()) { continue; } - env.getProjectIds().add(tr.getProjectId()); + if (StringUtils.equals(tr.getType(), "scenario")) { + env.getProjectIds().add(tr.getProjectId()); + } if (CollectionUtils.isNotEmpty(tr.getHashTree())) { getHashTree(tr.getHashTree(), env); } @@ -1330,4 +1327,24 @@ public class ApiAutomationService { }catch (Exception e){ } } + + public ScenarioEnv getApiScenarioProjectId(String id) { + ApiScenarioWithBLOBs scenario = apiScenarioMapper.selectByPrimaryKey(id); + ScenarioEnv scenarioEnv = new ScenarioEnv(); + if (scenario == null) { + return scenarioEnv; + } + + String definition = scenario.getScenarioDefinition(); + if (StringUtils.isBlank(definition)) { + return scenarioEnv; + } + + scenarioEnv = getApiScenarioEnv(definition); + scenarioEnv.getProjectIds().remove(null); + if (scenarioEnv.getProjectIds().isEmpty()) { + scenarioEnv.getProjectIds().add(scenario.getProjectId()); + } + return scenarioEnv; + } } diff --git a/frontend/src/business/components/api/automation/scenario/testplan/TestPlanList.vue b/frontend/src/business/components/api/automation/scenario/testplan/TestPlanList.vue index 2e3f7a0249..3ff38018e6 100644 --- a/frontend/src/business/components/api/automation/scenario/testplan/TestPlanList.vue +++ b/frontend/src/business/components/api/automation/scenario/testplan/TestPlanList.vue @@ -235,8 +235,9 @@ export default { }, setScenarioSelectRows(rows) { this.projectIds.clear(); + this.map.clear(); rows.forEach(row => { - this.result = this.$get('/api/automation/getApiScenario/' + row.id, res => { + this.result = this.$get('/api/automation/getApiScenarioProjectId/' + row.id, res => { let data = res.data; data.projectIds.forEach(d => this.projectIds.add(d)); this.map.set(row.id, data.projectIds); diff --git a/frontend/src/business/components/track/case/components/BatchEdit.vue b/frontend/src/business/components/track/case/components/BatchEdit.vue index 4f5c8e63c2..ff2f165f6b 100644 --- a/frontend/src/business/components/track/case/components/BatchEdit.vue +++ b/frontend/src/business/components/track/case/components/BatchEdit.vue @@ -130,9 +130,10 @@ this.$set(this.form, "value", ""); if (val === 'projectEnv' && this.isScenario !== '') { this.projectIds.clear(); + this.map.clear(); this.selectRows.forEach(row => { let id = this.isScenario === 'scenario' ? row.id : row.caseId; - this.result = this.$get('/api/automation/getApiScenario/' + id, res => { + this.result = this.$get('/api/automation/getApiScenarioProjectId/' + id, res => { let data = res.data; data.projectIds.forEach(d => this.projectIds.add(d)); this.map.set(row.id, data.projectIds); diff --git a/frontend/src/business/components/track/plan/view/comonents/api/RelevanceScenarioList.vue b/frontend/src/business/components/track/plan/view/comonents/api/RelevanceScenarioList.vue index 9c5e67ae5f..8f21b688e6 100644 --- a/frontend/src/business/components/track/plan/view/comonents/api/RelevanceScenarioList.vue +++ b/frontend/src/business/components/track/plan/view/comonents/api/RelevanceScenarioList.vue @@ -168,8 +168,9 @@ }, initProjectIds() { this.projectIds.clear(); + this.map.clear(); this.selectRows.forEach(row => { - this.result = this.$get('/api/automation/getApiScenario/' + row.id, res => { + this.result = this.$get('/api/automation/getApiScenarioProjectId/' + row.id, res => { let data = res.data; data.projectIds.forEach(d => this.projectIds.add(d)); this.map.set(row.id, data.projectIds);