refactor(系统设置): 功能用例和缺陷获取自定义字段接口,添加内置字段的key

This commit is contained in:
AgAngle 2024-06-26 15:01:22 +08:00 committed by jianxing
parent d7142366b4
commit 7a018b2402
4 changed files with 13 additions and 6 deletions

View File

@ -27,6 +27,9 @@ public class CustomFieldOptions implements Serializable {
@Schema(description = "是否内置字段") @Schema(description = "是否内置字段")
private Boolean internal; private Boolean internal;
@Schema(description = "内置字段的 key")
private String internalFieldKey;
@Schema(description = "自定义字段选项值") @Schema(description = "自定义字段选项值")
private List<CustomFieldOption> options; private List<CustomFieldOption> options;
} }

View File

@ -424,6 +424,7 @@ public class ProjectTemplateService extends BaseTemplateService {
CustomFieldOptions optionDTO = new CustomFieldOptions(); CustomFieldOptions optionDTO = new CustomFieldOptions();
optionDTO.setId(customField.getId()); optionDTO.setId(customField.getId());
if (customField.getInternal()) { if (customField.getInternal()) {
optionDTO.setInternalFieldKey(customField.getName());
optionDTO.setName(baseCustomFieldService.translateInternalField(customField.getName())); optionDTO.setName(baseCustomFieldService.translateInternalField(customField.getName()));
} else { } else {
optionDTO.setName(customField.getName()); optionDTO.setName(customField.getName());

View File

@ -53,4 +53,7 @@ public class TemplateCustomFieldDTO {
@Schema(description = "是否平台系统字段") @Schema(description = "是否平台系统字段")
private Boolean platformSystemField; private Boolean platformSystemField;
@Schema(description = "内置字段的 key")
private String internalFieldKey;
} }

View File

@ -27,6 +27,7 @@ import java.util.Arrays;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static io.metersphere.system.controller.handler.result.CommonResultCode.*; import static io.metersphere.system.controller.handler.result.CommonResultCode.*;
@ -105,12 +106,7 @@ public class BaseTemplateService {
List<CustomField> customFields = baseCustomFieldService.getByIds(fieldIds); List<CustomField> customFields = baseCustomFieldService.getByIds(fieldIds);
Map<String, CustomField> fieldMap = customFields Map<String, CustomField> fieldMap = customFields
.stream() .stream()
.collect(Collectors.toMap(CustomField::getId, customField -> { .collect(Collectors.toMap(CustomField::getId, Function.identity()));
if (customField.getInternal()) {
customField.setName(baseCustomFieldService.translateInternalField(customField.getName()));
}
return customField;
}));
// 封装自定义字段信息 // 封装自定义字段信息
List<TemplateCustomFieldDTO> fieldDTOS = templateCustomFields.stream() List<TemplateCustomFieldDTO> fieldDTOS = templateCustomFields.stream()
@ -121,6 +117,10 @@ public class BaseTemplateService {
TemplateCustomFieldDTO templateCustomFieldDTO = new TemplateCustomFieldDTO(); TemplateCustomFieldDTO templateCustomFieldDTO = new TemplateCustomFieldDTO();
BeanUtils.copyBean(templateCustomFieldDTO, i); BeanUtils.copyBean(templateCustomFieldDTO, i);
templateCustomFieldDTO.setFieldName(customField.getName()); templateCustomFieldDTO.setFieldName(customField.getName());
if (BooleanUtils.isTrue(customField.getInternal())) {
templateCustomFieldDTO.setInternalFieldKey(customField.getName());
templateCustomFieldDTO.setFieldName(baseCustomFieldService.translateInternalField(customField.getName()));
}
templateCustomFieldDTO.setType(customField.getType()); templateCustomFieldDTO.setType(customField.getType());
templateCustomFieldDTO.setInternal(customField.getInternal()); templateCustomFieldDTO.setInternal(customField.getInternal());
AbstractCustomFieldResolver customFieldResolver = CustomFieldResolverFactory.getResolver(customField.getType()); AbstractCustomFieldResolver customFieldResolver = CustomFieldResolverFactory.getResolver(customField.getType());