feat:实现相当牛逼的链式反应

This commit is contained in:
wangyu 2021-12-12 12:40:15 +08:00
parent 787aa73615
commit 7deb4fc580

View File

@ -175,53 +175,6 @@ public class BeanProperty {
// 优雅地处理校验 // 优雅地处理校验
property.setValidation(ValidationCandidate.produce(annotations.annotations(), property.getType())); property.setValidation(ValidationCandidate.produce(annotations.annotations(), property.getType()));
} }
// 优雅地设置排序
// MergedAnnotation<Order> order = annotations.get(Order.class);
// if (order.isPresent()) {
// property.setOrder(order.synthesize().value());
// } else {
// property.setOrder(props.order());
// }
// 追加生成属性
// MergedAnnotation<Generation> generation = annotations.get(Generation.class);
// if (generation.isPresent()) {
//
// }
// 追加属性映射
// MergedAnnotation<ComputedProps.List> links = annotations.get(ComputedProps.List.class);
// if (links.isPresent()) {
// property.extra.put(BeanProps.LINKED, Arrays.stream(
// links.getAnnotationArray("value", ComputedProps.class)
// ).map(MergedAnnotation::asMap).collect(Collectors.toList()));
// } else {
// MergedAnnotation<ComputedProps> single = annotations.get(ComputedProps.class);
// if (single.isPresent()) {
// property.extra.put(BeanProps.LINKED, Collections.singletonList(single.asMap()));
// }
// }
// 优雅的设置额外的属性
// MergedAnnotation<FormItem> item = annotations.get(FormItem.class);
// if (item.isPresent()) {
// applyFormItem(property, item.synthesize());
// }
// 优雅的设置联动映射
// MergedAnnotation<MappedTo> mapping = annotations.get(MappedTo.class);
// if (mapping.isPresent()) {
// property.extra.put(BeanProps.MAPPING, mapping.asMap());
// }
// 处理联动
// MergedAnnotation<ConditionOn.List> condition = annotations.get(ConditionOn.List.class);
// if (condition.isPresent()) {
// property.extra.put(BeanProps.CONDITION, Arrays.stream(
// condition.getAnnotationArray("value", ConditionOn.class)
// ).map(MergedAnnotation::asMap).collect(Collectors.toList()));
// } else {
// MergedAnnotation<ConditionOn> single = annotations.get(ConditionOn.class);
// if (single.isPresent()) {
// property.extra.put(BeanProps.CONDITION, Collections.singletonList(single.asMap()));
// }
// }
Class<?> clazz = descriptor.getPropertyType(); Class<?> clazz = descriptor.getPropertyType();
switch (property.getType()) { switch (property.getType()) {
case STRING: case STRING:
@ -252,27 +205,6 @@ public class BeanProperty {
} }
}) })
.end(); .end();
// if (annotations.isPresent(DictValue.class)) {
// DictValue dictValue = annotations.get(DictValue.class).synthesize();
// property.prop("code", dictValue.value());
// } else if (annotations.isPresent(EnumValue.class)) {
// // 添加了枚举注解自动注入类型给前端使用
// property.setType(BeanPropertyType.ENUM);
// EnumValue enumValue = annotations.get(EnumValue.class).synthesize();
// String name = StringFormats.camel2Line(ClassUtils.getShortClassName(enumValue.value()));
// property.prop("code", name);
// } else if (annotations.isPresent(DBRefValue.class)) {
// 添加了数据库引用注解自动注入类型给前端使用
// DBRefValue dbRefValue = annotations.get(DBRefValue.class).synthesize();
// Optional<String> optional = processDbRef(dbRefValue.value());
// if (optional.isPresent()) {
// property.setType(BeanPropertyType.DB_REF);
// property.prop("uri", optional.get());
// } else {
// property.setType(BeanPropertyType.STRING);
// }
// }
break; break;
case NUMBER: case NUMBER:
if (null != field) { if (null != field) {
@ -314,24 +246,6 @@ public class BeanProperty {
property.prop("uri", ref).prop("mode", "multiple"); property.prop("uri", ref).prop("mode", "multiple");
})) }))
.end(); .end();
// if (annotations.isPresent(SubBean.class)) {
// // 尝试获取泛型参数存在时赋值子表单
// parseSubClass(field).ifPresent(subClazz -> property.setChildren(from(subClazz)));
// // 处理替换
// applyReplacement(property, annotations);
// } else if (annotations.isPresent(DateRange.class)) {
// property.setType(BeanPropertyType.DATE);
// property
// .prop("type", "range")
// .prop("placeholder", Arrays.asList("开始时间", "结束时间"));
// } else if (annotations.isPresent(DBRefValue.class)) {
// // 添加了数据库引用注解自动注入类型给前端使用
// DBRefValue dbRefValue = annotations.get(DBRefValue.class).synthesize();
// processDbRef(dbRefValue.value()).ifPresent(ref -> {
// property.setType(BeanPropertyType.DB_REF);
// property.prop("uri", ref).prop("mode", "multiple");
// });
// }
} }
break; break;
case OBJECT: case OBJECT:
@ -344,12 +258,6 @@ public class BeanProperty {
applyReplacement(property, value); applyReplacement(property, value);
}) })
.end(); .end();
// 有子bean注解才处理
// if (null != field && annotations.isPresent(SubBean.class)) {
// property.setChildren(from(clazz));
// // 处理替换
// applyReplacement(property, annotations);
// }
break; break;
case DB_REF: case DB_REF:
// 当存在db-ref时解析为动态数据源 // 当存在db-ref时解析为动态数据源
@ -393,12 +301,6 @@ public class BeanProperty {
} }
}) })
.end(); .end();
// if (null != field) {
// if (annotations.isPresent(JsonFormat.class)) {
// String pattern = annotations.get(JsonFormat.class).synthesize().pattern();
//
// }
// }
} }
// 写入默认值 // 写入默认值
Object value = ReflectionUtils.getFieldValue(instance, property.name); Object value = ReflectionUtils.getFieldValue(instance, property.name);