From 7a018b2402cc44430f054cf3de1d3495c12c3a8a Mon Sep 17 00:00:00 2001 From: AgAngle <1323481023@qq.com> Date: Wed, 26 Jun 2024 15:01:22 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E7=B3=BB=E7=BB=9F=E8=AE=BE=E7=BD=AE):?= =?UTF-8?q?=20=E5=8A=9F=E8=83=BD=E7=94=A8=E4=BE=8B=E5=92=8C=E7=BC=BA?= =?UTF-8?q?=E9=99=B7=E8=8E=B7=E5=8F=96=E8=87=AA=E5=AE=9A=E4=B9=89=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E6=8E=A5=E5=8F=A3=EF=BC=8C=E6=B7=BB=E5=8A=A0=E5=86=85?= =?UTF-8?q?=E7=BD=AE=E5=AD=97=E6=AE=B5=E7=9A=84key?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../metersphere/project/dto/CustomFieldOptions.java | 3 +++ .../project/service/ProjectTemplateService.java | 1 + .../system/dto/sdk/TemplateCustomFieldDTO.java | 3 +++ .../system/service/BaseTemplateService.java | 12 ++++++------ 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/dto/CustomFieldOptions.java b/backend/services/project-management/src/main/java/io/metersphere/project/dto/CustomFieldOptions.java index e62d1dc4f0..6154654728 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/dto/CustomFieldOptions.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/dto/CustomFieldOptions.java @@ -27,6 +27,9 @@ public class CustomFieldOptions implements Serializable { @Schema(description = "是否内置字段") private Boolean internal; + @Schema(description = "内置字段的 key") + private String internalFieldKey; + @Schema(description = "自定义字段选项值") private List options; } diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectTemplateService.java b/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectTemplateService.java index 7fc7b4b637..e216cac076 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectTemplateService.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectTemplateService.java @@ -424,6 +424,7 @@ public class ProjectTemplateService extends BaseTemplateService { CustomFieldOptions optionDTO = new CustomFieldOptions(); optionDTO.setId(customField.getId()); if (customField.getInternal()) { + optionDTO.setInternalFieldKey(customField.getName()); optionDTO.setName(baseCustomFieldService.translateInternalField(customField.getName())); } else { optionDTO.setName(customField.getName()); diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/dto/sdk/TemplateCustomFieldDTO.java b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/sdk/TemplateCustomFieldDTO.java index 18276d042d..84a7fd824e 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/dto/sdk/TemplateCustomFieldDTO.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/sdk/TemplateCustomFieldDTO.java @@ -53,4 +53,7 @@ public class TemplateCustomFieldDTO { @Schema(description = "是否平台系统字段") private Boolean platformSystemField; + + @Schema(description = "内置字段的 key") + private String internalFieldKey; } diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseTemplateService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseTemplateService.java index 82df2f0973..52949d1b0e 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseTemplateService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseTemplateService.java @@ -27,6 +27,7 @@ import java.util.Arrays; import java.util.Comparator; import java.util.List; import java.util.Map; +import java.util.function.Function; import java.util.stream.Collectors; import static io.metersphere.system.controller.handler.result.CommonResultCode.*; @@ -105,12 +106,7 @@ public class BaseTemplateService { List customFields = baseCustomFieldService.getByIds(fieldIds); Map fieldMap = customFields .stream() - .collect(Collectors.toMap(CustomField::getId, customField -> { - if (customField.getInternal()) { - customField.setName(baseCustomFieldService.translateInternalField(customField.getName())); - } - return customField; - })); + .collect(Collectors.toMap(CustomField::getId, Function.identity())); // 封装自定义字段信息 List fieldDTOS = templateCustomFields.stream() @@ -121,6 +117,10 @@ public class BaseTemplateService { TemplateCustomFieldDTO templateCustomFieldDTO = new TemplateCustomFieldDTO(); BeanUtils.copyBean(templateCustomFieldDTO, i); templateCustomFieldDTO.setFieldName(customField.getName()); + if (BooleanUtils.isTrue(customField.getInternal())) { + templateCustomFieldDTO.setInternalFieldKey(customField.getName()); + templateCustomFieldDTO.setFieldName(baseCustomFieldService.translateInternalField(customField.getName())); + } templateCustomFieldDTO.setType(customField.getType()); templateCustomFieldDTO.setInternal(customField.getInternal()); AbstractCustomFieldResolver customFieldResolver = CustomFieldResolverFactory.getResolver(customField.getType());