From 5f769d7f3e3cab2f22ca56a9409e4939db1f0da0 Mon Sep 17 00:00:00 2001 From: guoyuqi Date: Mon, 3 Jun 2024 15:33:05 +0800 Subject: [PATCH] =?UTF-8?q?reactor(=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B):?= =?UTF-8?q?=20=E8=B0=83=E6=95=B4=E7=94=A8=E4=BE=8B=E4=BF=9D=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FunctionalCaseMinderEditRequest.java | 7 ++++- .../service/FunctionalCaseMinderService.java | 28 ++++++++++++++----- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/request/FunctionalCaseMinderEditRequest.java b/backend/services/case-management/src/main/java/io/metersphere/functional/request/FunctionalCaseMinderEditRequest.java index f4c5ae9149..4f9d9329e0 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/request/FunctionalCaseMinderEditRequest.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/request/FunctionalCaseMinderEditRequest.java @@ -5,13 +5,18 @@ import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotBlank; import lombok.Data; +import java.io.Serial; +import java.io.Serializable; import java.util.List; /** * @author guoyuqi */ @Data -public class FunctionalCaseMinderEditRequest{ +public class FunctionalCaseMinderEditRequest implements Serializable { + + @Serial + private static final long serialVersionUID = 1L; @Schema(description = "项目id", requiredMode = Schema.RequiredMode.REQUIRED) @NotBlank(message = "{functional_case.project_id.not_blank}") diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseMinderService.java b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseMinderService.java index 9ddfee22cf..090519005b 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseMinderService.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseMinderService.java @@ -401,6 +401,9 @@ public class FunctionalCaseMinderService { private static void checkModules(FunctionalCaseModuleEditRequest functionalCaseModuleEditRequest, Map> parentModuleMap) { List functionalCaseModules = parentModuleMap.get(functionalCaseModuleEditRequest.getParentId()); + if (CollectionUtils.isEmpty(functionalCaseModules)) { + return; + } List sameNameList = functionalCaseModules.stream().filter(t -> StringUtils.equalsIgnoreCase(t.getName(), functionalCaseModuleEditRequest.getName())).toList(); if (CollectionUtils.isNotEmpty(sameNameList)) { throw new MSException(Translator.get("node.name.repeat")); @@ -499,14 +502,20 @@ public class FunctionalCaseMinderService { @NotNull private Map> getParentModuleMap(List addList) { - List targetIds = addList.stream().map(FunctionalCaseModuleEditRequest::getTargetId).distinct().toList(); + List targetIds = addList.stream().filter(t->!StringUtils.equalsIgnoreCase(t.getMoveMode(), MoveTypeEnum.APPEND.name())).map(FunctionalCaseModuleEditRequest::getTargetId).distinct().toList(); + List parentIds = new ArrayList<>(); + if (CollectionUtils.isNotEmpty(targetIds)) { + FunctionalCaseModuleExample functionalCaseModuleExample = new FunctionalCaseModuleExample(); + functionalCaseModuleExample.createCriteria().andIdIn(targetIds); + List functionalCaseModules = functionalCaseModuleMapper.selectByExample(functionalCaseModuleExample); + parentIds = functionalCaseModules.stream().map(FunctionalCaseModule::getParentId).distinct().toList(); + } + if (CollectionUtils.isEmpty(parentIds)) { + parentIds = addList.stream().map(FunctionalCaseModuleEditRequest::getParentId).distinct().toList(); + } FunctionalCaseModuleExample functionalCaseModuleExample = new FunctionalCaseModuleExample(); - functionalCaseModuleExample.createCriteria().andIdIn(targetIds); - List functionalCaseModules = functionalCaseModuleMapper.selectByExample(functionalCaseModuleExample); - List parentIds = functionalCaseModules.stream().map(FunctionalCaseModule::getParentId).distinct().toList(); - functionalCaseModuleExample = new FunctionalCaseModuleExample(); functionalCaseModuleExample.createCriteria().andParentIdIn(parentIds); - functionalCaseModules = functionalCaseModuleMapper.selectByExample(functionalCaseModuleExample); + List functionalCaseModules = functionalCaseModuleMapper.selectByExample(functionalCaseModuleExample); return functionalCaseModules.stream().collect(Collectors.groupingBy(FunctionalCaseModule::getParentId)); } @@ -581,6 +590,9 @@ public class FunctionalCaseMinderService { @NotNull private Map> getModuleCaseMap(List addList) { List list = addList.stream().map(FunctionalCaseChangeRequest::getTargetId).distinct().toList(); + if (CollectionUtils.isEmpty(list)) { + return new HashMap<>(); + } FunctionalCaseExample functionalCaseExample = new FunctionalCaseExample(); functionalCaseExample.createCriteria().andIdIn(list); List functionalCases = functionalCaseMapper.selectByExample(functionalCaseExample); @@ -619,6 +631,9 @@ public class FunctionalCaseMinderService { private List updateCustomFields(FunctionalCaseChangeRequest functionalCaseChangeRequest, Map> caseCustomFieldMap, String caseId, FunctionalCaseCustomFieldMapper caseCustomFieldMapper) { List total = new ArrayList<>(); List functionalCaseCustomFields = caseCustomFieldMap.get(caseId); + if (CollectionUtils.isEmpty(functionalCaseCustomFields)) { + functionalCaseCustomFields = new ArrayList<>(); + } List customFields = functionalCaseChangeRequest.getCustomFields(); if (CollectionUtils.isNotEmpty(customFields)) { customFields = customFields.stream().distinct().collect(Collectors.toList()); @@ -637,7 +652,6 @@ public class FunctionalCaseMinderService { List functionalCaseCustomFields1 = saveCustomField(caseId, caseCustomFieldMapper, addFields); total.addAll(functionalCaseCustomFields1); } - ; if (CollectionUtils.isNotEmpty(updateFields)) { List functionalCaseCustomFields1 = updateField(updateFields, caseId, caseCustomFieldMapper); total.addAll(functionalCaseCustomFields1);