diff --git a/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioReferenceIdMapper.java b/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioReferenceIdMapper.java index 090c3ae220..8df7aa27c8 100644 --- a/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioReferenceIdMapper.java +++ b/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioReferenceIdMapper.java @@ -9,4 +9,7 @@ public interface ExtApiScenarioReferenceIdMapper { List selectUrlByProjectId(@Param("projectId") String projectId, @Param("versionId") String versionId); List selectReferenceIdByIds(List ids); + + int selectByScenarioIds(List ids); + } diff --git a/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioReferenceIdMapper.xml b/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioReferenceIdMapper.xml index 0465bf64ea..c527c2f097 100644 --- a/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioReferenceIdMapper.xml +++ b/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioReferenceIdMapper.xml @@ -28,5 +28,16 @@ and api_scenario.status != 'Trash' and api_scenario_reference_id.reference_type = 'REF' + \ No newline at end of file diff --git a/api-test/backend/src/main/java/io/metersphere/controller/scenario/ApiScenarioController.java b/api-test/backend/src/main/java/io/metersphere/controller/scenario/ApiScenarioController.java index 4363d98b49..68fcdb6670 100644 --- a/api-test/backend/src/main/java/io/metersphere/controller/scenario/ApiScenarioController.java +++ b/api-test/backend/src/main/java/io/metersphere/controller/scenario/ApiScenarioController.java @@ -209,6 +209,11 @@ public class ApiScenarioController { return apiAutomationService.getScenarioDetail(ids); } + @PostMapping("/get-scenario-step") + public int getScenarioStep(@RequestBody List ids) { + return apiAutomationService.getScenarioStep(ids); + } + @PostMapping(value = "/run/debug") @MsAuditLog(module = OperLogModule.API_AUTOMATION, type = OperLogConstants.DEBUG, title = "#request.scenarioName", sourceId = "#request.scenarioId", project = "#request.projectId") public String runDebug(@RequestPart("request") RunDefinitionRequest request, @RequestPart(value = "bodyFiles", required = false) List bodyFiles, @RequestPart(value = "scenarioFiles", required = false) List scenarioFiles) { diff --git a/api-test/backend/src/main/java/io/metersphere/service/MsHashTreeService.java b/api-test/backend/src/main/java/io/metersphere/service/MsHashTreeService.java index 50136ecb89..3406984ac6 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/MsHashTreeService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/MsHashTreeService.java @@ -365,6 +365,9 @@ public class MsHashTreeService { public void caseFormatting(JSONObject element, List caseIds, ParameterConfig msParameter) { List caseInfos = apiTestCaseService.selectByCaseIds(caseIds); + if(CollectionUtils.isEmpty(caseInfos)){ + return; + } Map caseMap = caseInfos.stream() .collect(Collectors.toMap(ApiTestCase::getId, a -> a, (k1, k2) -> k1)); if (element != null && ElementConstants.REQUESTS.contains(element.optString(TYPE))) { diff --git a/api-test/backend/src/main/java/io/metersphere/service/scenario/ApiScenarioService.java b/api-test/backend/src/main/java/io/metersphere/service/scenario/ApiScenarioService.java index 613faba3ce..ac6adc1f7b 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/scenario/ApiScenarioService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/scenario/ApiScenarioService.java @@ -841,6 +841,9 @@ public class ApiScenarioService { } } + public int getScenarioStep(List ids) { + return extApiScenarioReferenceIdMapper.selectByScenarioIds(ids); + } public List getScenarioDetail(List ids) { if (CollectionUtils.isEmpty(ids)) { return new ArrayList<>(); diff --git a/api-test/frontend/src/api/scenario.js b/api-test/frontend/src/api/scenario.js index 2d3f186190..a12bf7e31b 100644 --- a/api-test/frontend/src/api/scenario.js +++ b/api-test/frontend/src/api/scenario.js @@ -67,6 +67,10 @@ export function getApiScenarios(params) { return post('/api/automation/get-scenario-list', params); } +export function getApiScenarioStep(params) { + return post('/api/automation/get-scenario-step', params); +} + export function genPerformanceTestJmx(params) { return post('/api/automation/gen-jmx', params); } diff --git a/api-test/frontend/src/business/automation/scenario/api/ApiRelevance.vue b/api-test/frontend/src/business/automation/scenario/api/ApiRelevance.vue index 7f43237127..a242c959ec 100644 --- a/api-test/frontend/src/business/automation/scenario/api/ApiRelevance.vue +++ b/api-test/frontend/src/business/automation/scenario/api/ApiRelevance.vue @@ -91,6 +91,7 @@ import RelevanceDialog from '@/business/commons/RelevanceDialog'; import TestCaseRelevanceBase from '@/business/commons/TestCaseRelevanceBase'; import { hasLicense } from 'metersphere-frontend/src/utils/permission'; import TableSelectCountBar from '@/business/automation/scenario/api/TableSelectCountBar'; +import { operationConfirm } from 'metersphere-frontend/src/utils'; export default { name: 'ApiRelevance', @@ -156,38 +157,56 @@ export default { api.projectId = this.projectId; }); let params = this.$refs.apiList.getConditions(); - this.result = apiListBatch(params).then( - (response) => { - let apis = response.data; - if (apis.length === 0) { - this.$warning('请选择接口'); - this.buttonIsWorking = false; + this.result = apiListBatch(params).then((response) => { + let apis = response.data; + if (apis.length === 0) { + this.$warning(this.$t('automation.case_message')); + this.buttonIsWorking = false; + } else { + if (apis.length > 500) { + operationConfirm( + this, + this.$t('automation.scenario_step_ref_message', [apis.length]) + '?', + () => { + this.$emit('save', apis, 'API', reference); + this.$refs.baseRelevance.close(); + }, + () => { + this.buttonIsWorking = false; + } + ); } else { this.$emit('save', apis, 'API', reference); this.$refs.baseRelevance.close(); } - }, - (error) => { - this.buttonIsWorking = false; } - ); + }); } else { let params = this.$refs.apiCaseList.getConditions(); - this.result = getApiCaseWithBLOBs(params).then( - (response) => { - let apiCases = response.data; - if (apiCases.length === 0) { - this.$warning('请选择案例'); - this.buttonIsWorking = false; + this.result = getApiCaseWithBLOBs(params).then((response) => { + let apiCases = response.data; + if (apiCases.length === 0) { + this.$warning(this.$t('automation.case_message')); + this.buttonIsWorking = false; + } else { + if (apiCases.length > 500) { + operationConfirm( + this, + this.$t('automation.scenario_step_ref_message', [apiCases.length]) + '?', + () => { + this.$emit('save', apiCases, 'CASE', reference); + this.$refs.baseRelevance.close(); + }, + () => { + this.buttonIsWorking = false; + } + ); } else { this.$emit('save', apiCases, 'CASE', reference); this.$refs.baseRelevance.close(); } - }, - (error) => { - this.buttonIsWorking = false; } - ); + }); } }, close() { diff --git a/api-test/frontend/src/business/automation/scenario/api/ScenarioRelevance.vue b/api-test/frontend/src/business/automation/scenario/api/ScenarioRelevance.vue index c5e8629ca7..7d8537ac5a 100644 --- a/api-test/frontend/src/business/automation/scenario/api/ScenarioRelevance.vue +++ b/api-test/frontend/src/business/automation/scenario/api/ScenarioRelevance.vue @@ -43,19 +43,18 @@