feat: 实现空缺补充
This commit is contained in:
parent
db9496943f
commit
8a5459c9be
@ -311,64 +311,17 @@ public class BeanProperty {
|
||||
* @return 结果
|
||||
*/
|
||||
private static List<BeanProperty> parseExtras(Class<?> clazz, List<BeanProperty> origin) {
|
||||
List<BeanProperty> result = new ArrayList<>();
|
||||
// 包含properties
|
||||
if (clazz.isAnnotationPresent(Properties.class)) {
|
||||
List<BeanProperty> result = new ArrayList<>();
|
||||
Properties properties = clazz.getAnnotation(Properties.class);
|
||||
for (Property prop : properties.value()) {
|
||||
String key = prop.key();
|
||||
// 如果基础元数据已经包含了这部分,相当于重载属性,此时不会调整其他属性,而是替换名称(将来可能扩展更多)
|
||||
Optional<BeanProperty> found = origin.stream().filter(property -> property.name.equals(key))
|
||||
.findFirst();
|
||||
if (found.isPresent()) {
|
||||
BeanProperty property = found.get();
|
||||
if (prop.order() != 0) {
|
||||
property.order = prop.order();
|
||||
}
|
||||
if (StringUtils.isNotBlank(prop.group())) {
|
||||
property.group = prop.group();
|
||||
}
|
||||
// 只读状态不显示
|
||||
if (prop.readonly()) {
|
||||
origin.remove(property);
|
||||
}
|
||||
// 存在校验,替换名称文案(仅inherit)
|
||||
if (property.inherited && CollectionUtils.isNotEmpty(property.validation)) {
|
||||
property.validation.forEach(validation -> validation.setMessage(validation.getMessage()
|
||||
.replace(property.oldTitle, prop.title())));
|
||||
}
|
||||
// 处理额外的表单属性
|
||||
if (ArrayUtils.isNotEmpty(prop.form())) {
|
||||
applyFormItem(property, prop.form()[0]);
|
||||
}
|
||||
// 处理额外的映射
|
||||
if (ArrayUtils.isNotEmpty(prop.mapping())) {
|
||||
property.extra.put(BeanProps.MAPPING, MergedAnnotations.from(prop.mapping()).get(MappedTo.class).asMap());
|
||||
}
|
||||
// 处理值生成策略,此处可清除原策略
|
||||
if (ArrayUtils.isNotEmpty(prop.generated())) {
|
||||
property.extra.put(BeanProps.GENERATED, MergedAnnotations.from(prop.mapping()).get(MappedTo.class).asMap());
|
||||
} else {
|
||||
property.extra.remove(BeanProps.GENERATED);
|
||||
if ("input-hidden".equals(property.extra.get(BeanProps.COMPONENT))) {
|
||||
property.extra.remove(BeanProps.COMPONENT);
|
||||
}
|
||||
}
|
||||
// 设置标题
|
||||
property.title = prop.title();
|
||||
} else {
|
||||
BeanProperty property = new BeanProperty();
|
||||
property.setType(BeanPropertyType.STRING);
|
||||
property.setName(key);
|
||||
property.setTitle(prop.title());
|
||||
if (!prop.readonly()) {
|
||||
result.add(property);
|
||||
}
|
||||
}
|
||||
applyExtraProperty(result, origin, prop);
|
||||
}
|
||||
return result;
|
||||
} else if (clazz.isAnnotationPresent(Property.class)) {
|
||||
applyExtraProperty(result, origin, clazz.getAnnotation(Property.class));
|
||||
}
|
||||
return Collections.emptyList();
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -415,6 +368,65 @@ public class BeanProperty {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 使的额外的属性生效
|
||||
*
|
||||
* @param result 结果集
|
||||
* @param origin 原属性集
|
||||
* @param prop 当前注解
|
||||
*/
|
||||
private static void applyExtraProperty(List<BeanProperty> result, List<BeanProperty> origin, Property prop) {
|
||||
String key = prop.key();
|
||||
// 如果基础元数据已经包含了这部分,相当于重载属性,此时不会调整其他属性,而是替换名称(将来可能扩展更多)
|
||||
Optional<BeanProperty> found = origin.stream().filter(property -> property.name.equals(key))
|
||||
.findFirst();
|
||||
if (found.isPresent()) {
|
||||
BeanProperty property = found.get();
|
||||
if (prop.order() != 0) {
|
||||
property.order = prop.order();
|
||||
}
|
||||
if (StringUtils.isNotBlank(prop.group())) {
|
||||
property.group = prop.group();
|
||||
}
|
||||
// 只读状态不显示
|
||||
if (prop.readonly()) {
|
||||
origin.remove(property);
|
||||
}
|
||||
// 存在校验,替换名称文案(仅inherit)
|
||||
if (property.inherited && CollectionUtils.isNotEmpty(property.validation)) {
|
||||
property.validation.forEach(validation -> validation.setMessage(validation.getMessage()
|
||||
.replace(property.oldTitle, prop.title())));
|
||||
}
|
||||
// 处理额外的表单属性
|
||||
if (ArrayUtils.isNotEmpty(prop.form())) {
|
||||
applyFormItem(property, prop.form()[0]);
|
||||
}
|
||||
// 处理额外的映射
|
||||
if (ArrayUtils.isNotEmpty(prop.mapping())) {
|
||||
property.extra.put(BeanProps.MAPPING, MergedAnnotations.from(prop.mapping()).get(MappedTo.class).asMap());
|
||||
}
|
||||
// 处理值生成策略,此处可清除原策略
|
||||
if (ArrayUtils.isNotEmpty(prop.generated())) {
|
||||
property.extra.put(BeanProps.GENERATED, MergedAnnotations.from(prop.mapping()).get(MappedTo.class).asMap());
|
||||
} else {
|
||||
property.extra.remove(BeanProps.GENERATED);
|
||||
if ("input-hidden".equals(property.extra.get(BeanProps.COMPONENT))) {
|
||||
property.extra.remove(BeanProps.COMPONENT);
|
||||
}
|
||||
}
|
||||
// 设置标题
|
||||
property.title = prop.title();
|
||||
} else {
|
||||
BeanProperty property = new BeanProperty();
|
||||
property.setType(BeanPropertyType.STRING);
|
||||
property.setName(key);
|
||||
property.setTitle(prop.title());
|
||||
if (!prop.readonly()) {
|
||||
result.add(property);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置当前对象的键值属性
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user