feat: 实现空缺补充
This commit is contained in:
parent
db9496943f
commit
8a5459c9be
@ -311,11 +311,71 @@ public class BeanProperty {
|
|||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
private static List<BeanProperty> parseExtras(Class<?> clazz, List<BeanProperty> origin) {
|
private static List<BeanProperty> parseExtras(Class<?> clazz, List<BeanProperty> origin) {
|
||||||
|
List<BeanProperty> result = new ArrayList<>();
|
||||||
// 包含properties
|
// 包含properties
|
||||||
if (clazz.isAnnotationPresent(Properties.class)) {
|
if (clazz.isAnnotationPresent(Properties.class)) {
|
||||||
List<BeanProperty> result = new ArrayList<>();
|
|
||||||
Properties properties = clazz.getAnnotation(Properties.class);
|
Properties properties = clazz.getAnnotation(Properties.class);
|
||||||
for (Property prop : properties.value()) {
|
for (Property prop : properties.value()) {
|
||||||
|
applyExtraProperty(result, origin, prop);
|
||||||
|
}
|
||||||
|
} else if (clazz.isAnnotationPresent(Property.class)) {
|
||||||
|
applyExtraProperty(result, origin, clazz.getAnnotation(Property.class));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析子类型,用于表格组件
|
||||||
|
*
|
||||||
|
* @param field 反射域
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
private static Optional<Class<?>> parseSubClass(Field field) {
|
||||||
|
// 获取实际的泛型
|
||||||
|
Type type = field.getGenericType();
|
||||||
|
if (type instanceof ParameterizedType) {
|
||||||
|
val types = TypeUtils.getTypeArguments((ParameterizedType) type);
|
||||||
|
return types.entrySet().stream().findFirst().map(entry -> {
|
||||||
|
Type parsed = entry.getValue();
|
||||||
|
if (parsed instanceof Class) {
|
||||||
|
Class<?> clazz = (Class<?>) parsed;
|
||||||
|
if (!ClassUtils.isPrimitiveOrWrapper(clazz) && !CharSequence.class.isAssignableFrom(clazz)) {
|
||||||
|
return clazz;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将formItem注解赋值到目标属性上
|
||||||
|
*
|
||||||
|
* @param property 目标属性
|
||||||
|
* @param item 注解元
|
||||||
|
*/
|
||||||
|
private static void applyFormItem(BeanProperty property, FormItem item) {
|
||||||
|
// 设置额外属性
|
||||||
|
if (StringUtils.isNotBlank(item.component())) {
|
||||||
|
property.extra.put(BeanProps.COMPONENT, item.component());
|
||||||
|
}
|
||||||
|
property.layout = item.layout();
|
||||||
|
if (ArrayUtils.isNotEmpty(item.props())) {
|
||||||
|
for (FormItem.Prop prop : item.props()) {
|
||||||
|
property.prop(prop.key(), prop.value());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 使的额外的属性生效
|
||||||
|
*
|
||||||
|
* @param result 结果集
|
||||||
|
* @param origin 原属性集
|
||||||
|
* @param prop 当前注解
|
||||||
|
*/
|
||||||
|
private static void applyExtraProperty(List<BeanProperty> result, List<BeanProperty> origin, Property prop) {
|
||||||
String key = prop.key();
|
String key = prop.key();
|
||||||
// 如果基础元数据已经包含了这部分,相当于重载属性,此时不会调整其他属性,而是替换名称(将来可能扩展更多)
|
// 如果基础元数据已经包含了这部分,相当于重载属性,此时不会调整其他属性,而是替换名称(将来可能扩展更多)
|
||||||
Optional<BeanProperty> found = origin.stream().filter(property -> property.name.equals(key))
|
Optional<BeanProperty> found = origin.stream().filter(property -> property.name.equals(key))
|
||||||
@ -366,54 +426,6 @@ public class BeanProperty {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
|
||||||
}
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 解析子类型,用于表格组件
|
|
||||||
*
|
|
||||||
* @param field 反射域
|
|
||||||
* @return 结果
|
|
||||||
*/
|
|
||||||
private static Optional<Class<?>> parseSubClass(Field field) {
|
|
||||||
// 获取实际的泛型
|
|
||||||
Type type = field.getGenericType();
|
|
||||||
if (type instanceof ParameterizedType) {
|
|
||||||
val types = TypeUtils.getTypeArguments((ParameterizedType) type);
|
|
||||||
return types.entrySet().stream().findFirst().map(entry -> {
|
|
||||||
Type parsed = entry.getValue();
|
|
||||||
if (parsed instanceof Class) {
|
|
||||||
Class<?> clazz = (Class<?>) parsed;
|
|
||||||
if (!ClassUtils.isPrimitiveOrWrapper(clazz) && !CharSequence.class.isAssignableFrom(clazz)) {
|
|
||||||
return clazz;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return Optional.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 将formItem注解赋值到目标属性上
|
|
||||||
*
|
|
||||||
* @param property 目标属性
|
|
||||||
* @param item 注解元
|
|
||||||
*/
|
|
||||||
private static void applyFormItem(BeanProperty property, FormItem item) {
|
|
||||||
// 设置额外属性
|
|
||||||
if (StringUtils.isNotBlank(item.component())) {
|
|
||||||
property.extra.put(BeanProps.COMPONENT, item.component());
|
|
||||||
}
|
|
||||||
property.layout = item.layout();
|
|
||||||
if (ArrayUtils.isNotEmpty(item.props())) {
|
|
||||||
for (FormItem.Prop prop : item.props()) {
|
|
||||||
property.prop(prop.key(), prop.value());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置当前对象的键值属性
|
* 设置当前对象的键值属性
|
||||||
|
Loading…
x
Reference in New Issue
Block a user