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 2da22b3bd1..6f498b1bed 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 @@ -930,21 +930,19 @@ public class FunctionalCaseMinderService { private List addCustomFields(FunctionalCaseChangeRequest functionalCaseChangeRequest, String caseId, FunctionalCaseCustomFieldMapper caseCustomFieldMapper, Map defaultValueMap) { List customFields = functionalCaseChangeRequest.getCustomFields(); - List caseCustomFields; - if (CollectionUtils.isNotEmpty(customFields)) { - customFields = customFields.stream().distinct().collect(Collectors.toList()); - caseCustomFields = saveCustomField(caseId, caseCustomFieldMapper, customFields); - } else { - List customFieldDTOs = new ArrayList<>(); - defaultValueMap.forEach((k,v)->{ + List list = customFields.stream().map(CaseCustomFieldDTO::getFieldId).toList(); + List customFieldDTOs = new ArrayList<>(); + defaultValueMap.forEach((k, v) -> { + if (!list.contains(k)) { CaseCustomFieldDTO customFieldDTO = new CaseCustomFieldDTO(); customFieldDTO.setFieldId(k); customFieldDTO.setValue(v.toString()); customFieldDTOs.add(customFieldDTO); - }); - caseCustomFields = saveCustomField(caseId, caseCustomFieldMapper, customFieldDTOs); - } - return caseCustomFields; + } + }); + customFields.addAll(customFieldDTOs); + customFields = customFields.stream().distinct().collect(Collectors.toList()); + return saveCustomField(caseId, caseCustomFieldMapper, customFields); } private List saveCustomField(String caseId, FunctionalCaseCustomFieldMapper caseCustomFieldMapper, List customFields) {