diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/controller/scenario/ApiScenarioController.java b/backend/services/api-test/src/main/java/io/metersphere/api/controller/scenario/ApiScenarioController.java index a16b349e52..ef90d25f79 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/controller/scenario/ApiScenarioController.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/controller/scenario/ApiScenarioController.java @@ -317,7 +317,7 @@ public class ApiScenarioController { @PostMapping(value = "/export/{type}") @Operation(summary = "接口测试-接口场景管理-场景-导出场景") @RequiresPermissions(PermissionConstants.PROJECT_API_SCENARIO_EXPORT) - @CheckOwner(resourceId = "#request.getResourceId()", resourceType = "api_scenario") + @CheckOwner(resourceId = "#request.getProjectId()", resourceType = "project") public String export(@RequestBody ApiScenarioBatchExportRequest request, @PathVariable String type) { return apiScenarioDataTransferService.exportScenario(request, type, SessionUtils.getUserId()); } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiDefinitionMapper.java b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiDefinitionMapper.java index 0bde5944a6..41bf2f2d5d 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiDefinitionMapper.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiDefinitionMapper.java @@ -105,4 +105,6 @@ public interface ExtApiDefinitionMapper { List getIdsByShareParam(@Param("projectId") String projectId, @Param("condition") String condition); long countByProjectAndId(@Param("projectId") String projectId, @Param("id") String id); + + Long selectNumById(String id); } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiDefinitionMapper.xml b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiDefinitionMapper.xml index aa21d21ea0..a509e70776 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiDefinitionMapper.xml +++ b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiDefinitionMapper.xml @@ -766,4 +766,9 @@ AND id = #{id} AND deleted = false + diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiScenarioDataTransferService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiScenarioDataTransferService.java index 4d79cbd9d6..5e60f85704 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiScenarioDataTransferService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiScenarioDataTransferService.java @@ -218,6 +218,7 @@ public class ApiScenarioDataTransferService { sqlSession.flushStatements(); }); } + Map insertApiDefinitionNumMap = new HashMap<>(); // 接口定义 if (CollectionUtils.isNotEmpty(preImportAnalysisResult.getInsertApiDefinitions())) { Map> projectMap = preImportAnalysisResult.getInsertApiDefinitions().stream().collect(Collectors.groupingBy(ApiDefinitionDetail::getProjectId)); @@ -231,6 +232,7 @@ public class ApiScenarioDataTransferService { BeanUtils.copyBean(apiDefinition, t); apiDefinition.setPos(getImportNextOrder(apiDefinitionImportService::getNextOrder, currentApiOrder, targetProjectId)); apiDefinition.setLatest(true); + apiDefinition.setNum(NumGenerator.nextNum(targetProjectId, ApplicationNumScope.API_DEFINITION)); apiDefinition.setStatus(ApiDefinitionStatus.PROCESSING.name()); apiDefinition.setRefId(apiDefinition.getId()); apiDefinition.setVersionId(versionId); @@ -245,6 +247,8 @@ public class ApiScenarioDataTransferService { apiDefinitionBlob.setRequest(ApiDataUtils.toJSONString(t.getRequest()).getBytes(StandardCharsets.UTF_8)); apiDefinitionBlob.setResponse(ApiDataUtils.toJSONString(t.getResponse()).getBytes(StandardCharsets.UTF_8)); batchApiBlobMapper.insertSelective(apiDefinitionBlob); + + insertApiDefinitionNumMap.put(apiDefinition.getId(), apiDefinition.getNum()); } sqlSession.flushStatements(); }); @@ -266,7 +270,15 @@ public class ApiScenarioDataTransferService { BeanUtils.copyBean(apiTestCase, t); apiTestCase.setProjectId(targetProjectId); apiTestCase.setPos(getImportNextOrder(apiTestCaseService::getNextOrder, currentApiTestCaseOrder, targetProjectId)); - apiTestCase.setNum(NumGenerator.nextNum(targetProjectId, ApplicationNumScope.API_DEFINITION)); + long apiDefinitionNum; + if (insertApiDefinitionNumMap.containsKey(apiTestCase.getApiDefinitionId())) { + apiDefinitionNum = insertApiDefinitionNumMap.get(apiTestCase.getApiDefinitionId()); + } else { + apiDefinitionNum = extApiDefinitionMapper.selectNumById(apiTestCase.getApiDefinitionId()); + insertApiDefinitionNumMap.put(apiTestCase.getApiDefinitionId(), apiDefinitionNum); + } + + apiTestCase.setNum(NumGenerator.nextNum(targetProjectId + "_" + apiDefinitionNum, ApplicationNumScope.API_TEST_CASE)); apiTestCase.setStatus(ApiDefinitionStatus.PROCESSING.name()); apiTestCase.setVersionId(versionId); apiTestCase.setCreateUser(operator);