From 0a92205f42c089be498887ee07cb169424971a3d Mon Sep 17 00:00:00 2001 From: Jianguo-Genius Date: Thu, 24 Oct 2024 17:50:41 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=A6=86=E7=9B=96=E5=AF=BC=E5=85=A5=E5=9C=BA?= =?UTF-8?q?=E6=99=AF=E6=97=B6=E6=95=B0=E6=8D=AE=E6=9B=B4=E6=96=B0=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1048012 --user=宋天阳 【场景导入】-覆盖方式导入,目标项目中有相同名称的场景,导入后场景的创建时间更新为场景文件中的创建时间 https://www.tapd.cn/55049933/s/1597631 --- .../api/service/ApiScenarioDataTransferService.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) 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 35e96e13cf..3832d52517 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 @@ -1,6 +1,7 @@ package io.metersphere.api.service; import io.metersphere.api.constants.ApiDefinitionStatus; +import io.metersphere.api.constants.ApiScenarioStatus; import io.metersphere.api.constants.ApiScenarioStepRefType; import io.metersphere.api.constants.ApiScenarioStepType; import io.metersphere.api.domain.*; @@ -357,7 +358,8 @@ public class ApiScenarioDataTransferService { //更新场景 list.forEach(request -> { // 更新基础信息 - ApiScenario scenario = BeanUtils.copyBean(new ApiScenario(), request); + ApiScenario scenario = new ApiScenario(); + scenario.setId(request.getId()); scenario.setUpdateUser(operator); scenario.setUpdateTime(System.currentTimeMillis()); scenario.setStepTotal(CollectionUtils.isNotEmpty(request.getSteps()) ? request.getSteps().size() : 0); @@ -503,6 +505,7 @@ public class ApiScenarioDataTransferService { scenario.setNum(apiScenarioService.getNextNum(targetProjectId)); scenario.setPos(getImportNextOrder(apiScenarioService::getNextOrder, currentApiScenarioOrder, targetProjectId)); scenario.setLatest(true); + scenario.setStatus(ApiScenarioStatus.UNDERWAY.name()); scenario.setCreateUser(operator); scenario.setUpdateUser(operator); scenario.setCreateTime(System.currentTimeMillis()); @@ -772,11 +775,15 @@ public class ApiScenarioDataTransferService { Map> projectScenarioMap = new HashMap<>(); // 对导入文件中的数据进行分组 { + Project project = projectMapper.selectByPrimaryKey(projectId); for (Map.Entry> entry : parseResult.getRelatedApiDefinitions().stream().collect(Collectors.groupingBy(ApiDefinitionDetail::getProjectId)).entrySet()) { String targetProjectId = entry.getKey(); List apiDefinitionDetails = entry.getValue(); // 如果没有权限,需要在当前项目进行校验 - if (projectMapper.selectByPrimaryKey(targetProjectId) == null) { + Project targetProject = projectMapper.selectByPrimaryKey(targetProjectId); + + // 项目不存在或者项目和当前项目不在统一组织下,需要在当前项目进行校验。场景不能跨项目关联 + if (targetProject == null || !StringUtils.equals(targetProject.getOrganizationId(), project.getOrganizationId())) { targetProjectId = projectId; } else if (!permissionCheckService.userHasProjectPermission(operator, targetProjectId, PermissionConstants.PROJECT_API_DEFINITION_ADD)) { targetProjectId = projectId;