diff --git a/backend/src/main/java/io/metersphere/api/dto/automation/parse/ApiScenarioImportUtil.java b/backend/src/main/java/io/metersphere/api/dto/automation/parse/ApiScenarioImportUtil.java index bbb0cefb93..a0d4085805 100644 --- a/backend/src/main/java/io/metersphere/api/dto/automation/parse/ApiScenarioImportUtil.java +++ b/backend/src/main/java/io/metersphere/api/dto/automation/parse/ApiScenarioImportUtil.java @@ -116,9 +116,7 @@ public class ApiScenarioImportUtil { } } - private static ApiDefinition getApiDefinitionResult(JSONObject object, ApiDefinitionService apiDefinitionService,MapdefinitionMap) { - CheckPermissionService checkPermissionService = CommonBeanFactory.getBean(CheckPermissionService.class); - Set userRelatedProjectIds = checkPermissionService.getUserRelatedProjectIds(); + private static ApiDefinition getApiDefinitionResult(JSONObject object, ApiDefinitionService apiDefinitionService,MapdefinitionMap,Set userRelatedProjectIds) { List projectIds = new ArrayList<>(userRelatedProjectIds); ApiDefinitionExample apiDefinitionExample = new ApiDefinitionExample(); apiDefinitionExample.createCriteria() @@ -147,8 +145,10 @@ public class ApiScenarioImportUtil { ApiTestCaseService testCaseService = CommonBeanFactory.getBean(ApiTestCaseService.class); ApiDefinitionService apiDefinitionService = CommonBeanFactory.getBean(ApiDefinitionService.class); ApiTestCaseWithBLOBs bloBs = testCaseService.get(object.getString("id")); - if (bloBs == null) { - ApiDefinition apiDefinition = getApiDefinitionResult(object,apiDefinitionService,definitionMap); + CheckPermissionService checkPermissionService = CommonBeanFactory.getBean(CheckPermissionService.class); + Set userRelatedProjectIds = checkPermissionService.getUserRelatedProjectIds(); + if (bloBs == null||!userRelatedProjectIds.contains(bloBs.getProjectId())) { + ApiDefinition apiDefinition = getApiDefinitionResult(object,apiDefinitionService,definitionMap,userRelatedProjectIds); if(apiDefinition!=null){ if(MapUtils.isNotEmpty(definitionMap)||definitionMap.size()==0){ structureCaseByJson(i,object,testCaseService, apiDefinition,apiTestCaseMapper); 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 8d9712671c..ed113f18e5 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java @@ -1299,6 +1299,9 @@ public class ApiAutomationService { if (StringUtils.isBlank(item.getId())) { item.setId(UUID.randomUUID().toString()); } + item.setCreateUser(SessionUtils.getUserId()); + item.setUserId(SessionUtils.getUserId()); + item.setPrincipal(SessionUtils.getUserId()); // 导入之后刷新latest importCreate(item, batchMapper, extApiScenarioMapper, request,apiTestCaseMapper,apiDefinitionMapper); if (i % 300 == 0) {