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());