From 787aa736150163d2e2a354695c062d7b01c56a79 Mon Sep 17 00:00:00 2001 From: wangyu <727842003@qq.com> Date: Sun, 12 Dec 2021 11:13:11 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E5=AE=9E=E7=8E=B0=E7=9B=B8?= =?UTF-8?q?=E5=BD=93=E7=89=9B=E9=80=BC=E7=9A=84=E9=93=BE=E5=BC=8F=E5=8F=8D?= =?UTF-8?q?=E5=BA=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../framework/beans/meta/BeanProperty.java | 398 +++++++++++------- .../parser/BeanPropertyAnnotationParser.java | 10 + .../meta/parser/BeanPropertyAnnotations.java | 87 ++++ .../parser/SimpleBeanPropertyAnnotations.java | 150 +++++++ .../parser/chain/AnnotationChainSupport.java | 30 ++ .../BeanPropertyAnnotationBatchChain.java | 75 ++++ .../chain/BeanPropertyAnnotationChain.java | 73 ++++ .../impl/BasicAnnotationChainSupport.java | 45 ++ .../chain/impl/EmptyAnnotationBatchChain.java | 106 +++++ .../chain/impl/EmptyAnnotationChain.java | 104 +++++ .../impl/SimpleAnnotationBatchChain.java | 134 ++++++ .../chain/impl/SimpleAnnotationChain.java | 124 ++++++ .../configuration/WebfluxConfig.java | 19 +- .../service/impl/BaseReactiveServiceImpl.java | 2 +- 14 files changed, 1197 insertions(+), 160 deletions(-) create mode 100644 flyfish-web/src/main/java/com/flyfish/framework/beans/meta/parser/BeanPropertyAnnotationParser.java create mode 100644 flyfish-web/src/main/java/com/flyfish/framework/beans/meta/parser/BeanPropertyAnnotations.java create mode 100644 flyfish-web/src/main/java/com/flyfish/framework/beans/meta/parser/SimpleBeanPropertyAnnotations.java create mode 100644 flyfish-web/src/main/java/com/flyfish/framework/beans/meta/parser/chain/AnnotationChainSupport.java create mode 100644 flyfish-web/src/main/java/com/flyfish/framework/beans/meta/parser/chain/BeanPropertyAnnotationBatchChain.java create mode 100644 flyfish-web/src/main/java/com/flyfish/framework/beans/meta/parser/chain/BeanPropertyAnnotationChain.java create mode 100644 flyfish-web/src/main/java/com/flyfish/framework/beans/meta/parser/chain/impl/BasicAnnotationChainSupport.java create mode 100644 flyfish-web/src/main/java/com/flyfish/framework/beans/meta/parser/chain/impl/EmptyAnnotationBatchChain.java create mode 100644 flyfish-web/src/main/java/com/flyfish/framework/beans/meta/parser/chain/impl/EmptyAnnotationChain.java create mode 100644 flyfish-web/src/main/java/com/flyfish/framework/beans/meta/parser/chain/impl/SimpleAnnotationBatchChain.java create mode 100644 flyfish-web/src/main/java/com/flyfish/framework/beans/meta/parser/chain/impl/SimpleAnnotationChain.java diff --git a/flyfish-web/src/main/java/com/flyfish/framework/beans/meta/BeanProperty.java b/flyfish-web/src/main/java/com/flyfish/framework/beans/meta/BeanProperty.java index dd70a64..dee2833 100644 --- a/flyfish-web/src/main/java/com/flyfish/framework/beans/meta/BeanProperty.java +++ b/flyfish-web/src/main/java/com/flyfish/framework/beans/meta/BeanProperty.java @@ -5,6 +5,8 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.flyfish.framework.annotations.Properties; import com.flyfish.framework.annotations.*; import com.flyfish.framework.beans.enums.ValidationCandidate; +import com.flyfish.framework.beans.meta.parser.BeanPropertyAnnotations; +import com.flyfish.framework.beans.meta.parser.SimpleBeanPropertyAnnotations; import com.flyfish.framework.domain.base.Qo; import com.flyfish.framework.domain.base.Vo; import com.flyfish.framework.utils.ReflectionUtils; @@ -110,116 +112,174 @@ public class BeanProperty { boolean strict = Qo.class.isAssignableFrom(beanClass) || Vo.class.isAssignableFrom(beanClass); // 尝试获取field Field field = FieldUtils.getField(beanClass, descriptor.getName(), true); - MergedAnnotations annotations = null == field ? MergedAnnotations.from() : MergedAnnotations.from(field); - // 存在field,可以干一些坏事 - if (null != field) { - // 开始解析关键注解 - if (annotations.isPresent(Property.class)) { - Property props = annotations.get(Property.class).synthesize(); - // 只有存在关键注解,才会进行初始化 - String parentName = Optional.ofNullable(beanClass.getAnnotation(RestBean.class)) - .map(RestBean::name).orElse(""); - property.setDescription(props.description()); - property.setReadonly(props.readonly()); - property.setInherited(props.inherited()); - property.setGroup(props.group()); - // 继承模式,继承名称 - if (property.inherited) { - property.setOldTitle(props.title()); - property.setTitle(parentName + property.oldTitle); - } else { - property.setTitle(props.title()); - } - // 优雅地设置排序 - MergedAnnotation order = annotations.get(Order.class); - if (order.isPresent()) { - property.setOrder(order.synthesize().value()); - } else { - property.setOrder(props.order()); - } - // 追加生成属性 - MergedAnnotation generation = annotations.get(Generation.class); - if (generation.isPresent()) { - property.extra.put(BeanProps.GENERATED, generation.asMap()); - property.extra.put(BeanProps.COMPONENT, "input-hidden"); - } - // 追加属性映射 - MergedAnnotation 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 single = annotations.get(ComputedProps.class); - if (single.isPresent()) { - property.extra.put(BeanProps.LINKED, Collections.singletonList(single.asMap())); - } - } - // 优雅的设置额外的属性 - MergedAnnotation item = annotations.get(FormItem.class); - if (item.isPresent()) { - applyFormItem(property, item.synthesize()); - } - // 优雅的设置联动映射 - MergedAnnotation mapping = annotations.get(MappedTo.class); - if (mapping.isPresent()) { - property.extra.put(BeanProps.MAPPING, mapping.asMap()); - } - // 处理联动 - MergedAnnotation 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 single = annotations.get(ConditionOn.class); - if (single.isPresent()) { - property.extra.put(BeanProps.CONDITION, Collections.singletonList(single.asMap())); - } - } - // 优雅的处理校验 - property.setValidation(ValidationCandidate.produce(annotations, property.getType())); - } else if (strict) { - property.setReadonly(true); - return property; - } - } else if (strict) { + BeanPropertyAnnotations annotations = new SimpleBeanPropertyAnnotations(field); + // 判断是否需要跳过,启用严格模式并未标记的属性,将直接跳过 + boolean skip = null == field || !annotations.isPresent(Property.class); + if (skip && strict) { property.setReadonly(true); return property; } + // 开始解析关键注解, 存在field,可以干一些坏事 + Property props = annotations.as(Property.class).synthesize(); + if (null != props) { + // 只有存在关键注解,才会进行初始化 + String parentName = Optional.ofNullable(beanClass.getAnnotation(RestBean.class)) + .map(RestBean::name).orElse(""); + property.setDescription(props.description()); + property.setReadonly(props.readonly()); + property.setInherited(props.inherited()); + property.setGroup(props.group()); + // 继承模式,继承名称 + if (property.inherited) { + property.setOldTitle(props.title()); + property.setTitle(parentName + property.oldTitle); + } else { + property.setTitle(props.title()); + } + // 开始优雅地操作 + annotations + // 优雅地设置排序 + .as(Order.class) + .map(item -> item.synthesize().value()) + .then(property::setOrder) + .empty(() -> property.setOrder(props.order())) + .and() + // 追加生成属性 + .as(Generation.class) + .map(MergedAnnotation::asMap) + .then(map -> { + property.extra.put(BeanProps.GENERATED, map); + property.extra.put(BeanProps.COMPONENT, "input-hidden"); + }) + .and() + // 追加属性映射 + .as(ComputedProps.class, ComputedProps.List.class) + .map(MergedAnnotation::asMap) + .then(list -> property.extra.put(BeanProps.LINKED, list)) + .and() + // 优雅地设置额外的属性 + .as(FormItem.class) + .map(MergedAnnotation::synthesize) + .then(item -> applyFormItem(property, item)) + .and() + // 优雅地设置联动映射 + .as(MappedTo.class) + .map(MergedAnnotation::asMap) + .then(map -> property.extra.put(BeanProps.MAPPING, map)) + .and() + // 处理联动 + .as(ConditionOn.class, ConditionOn.List.class) + .map(MergedAnnotation::asMap) + .then(list -> property.extra.put(BeanProps.CONDITION, list)) + .end(); + // 优雅地处理校验 + property.setValidation(ValidationCandidate.produce(annotations.annotations(), property.getType())); + } + // 优雅地设置排序 +// MergedAnnotation order = annotations.get(Order.class); +// if (order.isPresent()) { +// property.setOrder(order.synthesize().value()); +// } else { +// property.setOrder(props.order()); +// } + // 追加生成属性 +// MergedAnnotation generation = annotations.get(Generation.class); +// if (generation.isPresent()) { +// +// } + // 追加属性映射 +// MergedAnnotation 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 single = annotations.get(ComputedProps.class); +// if (single.isPresent()) { +// property.extra.put(BeanProps.LINKED, Collections.singletonList(single.asMap())); +// } +// } + // 优雅的设置额外的属性 +// MergedAnnotation item = annotations.get(FormItem.class); +// if (item.isPresent()) { +// applyFormItem(property, item.synthesize()); +// } + // 优雅的设置联动映射 +// MergedAnnotation mapping = annotations.get(MappedTo.class); +// if (mapping.isPresent()) { +// property.extra.put(BeanProps.MAPPING, mapping.asMap()); +// } + // 处理联动 +// MergedAnnotation 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 single = annotations.get(ConditionOn.class); +// if (single.isPresent()) { +// property.extra.put(BeanProps.CONDITION, Collections.singletonList(single.asMap())); +// } +// } + Class clazz = descriptor.getPropertyType(); switch (property.getType()) { case STRING: // 如果字段使用DictValue注解,尝试使用字典值仓库 - if (null != field) { - // 添加了字典枚举,自动添加code,从字典表取得 - 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 optional = processDbRef(dbRefValue.value()); - if (optional.isPresent()) { - property.setType(BeanPropertyType.DB_REF); - property.prop("uri", optional.get()); - } else { - property.setType(BeanPropertyType.STRING); - } - } - } + // 添加了字典枚举,自动添加code,从字典表取得 + annotations.as(DictValue.class) + .map(item -> item.synthesize().value()) + .then(value -> property.prop("code", value)) + .or() + .as(EnumValue.class) + .map(item -> item.synthesize().value()) + .then(value -> { + // 添加了枚举注解,自动注入类型,给前端使用 + property.setType(BeanPropertyType.ENUM); + String name = StringFormats.camel2Line(ClassUtils.getShortClassName(value)); + property.prop("code", name); + }) + .or() + .as(DBRefValue.class) + .map(item -> item.synthesize().value()) + .then(value -> { + Optional optional = processDbRef(value); + if (optional.isPresent()) { + property.setType(BeanPropertyType.DB_REF); + property.prop("uri", optional.get()); + } else { + property.setType(BeanPropertyType.STRING); + } + }) + .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 optional = processDbRef(dbRefValue.value()); +// if (optional.isPresent()) { +// property.setType(BeanPropertyType.DB_REF); +// property.prop("uri", optional.get()); +// } else { +// property.setType(BeanPropertyType.STRING); +// } +// } break; case NUMBER: if (null != field) { - if (annotations.isPresent(Money.class) && !property.extra.containsKey(BeanProps.COMPONENT)) { - property.extra.put(BeanProps.COMPONENT, "money-input"); - } + annotations.as(Money.class) + .filter(() -> !property.extra.containsKey(BeanProps.COMPONENT)) + .exists(() -> property.extra.put(BeanProps.COMPONENT, "money-input")) + .end(); } break; case LIST: @@ -228,33 +288,68 @@ public class BeanProperty { ReflectionUtils.getGenericType(field) .filter(property::isAttachment) .ifPresent(item -> property.prop("attachment", true)); - 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"); - }); - } + annotations + .as(SubBean.class) + .map(MergedAnnotation::synthesize) + .then(item -> { + // 尝试获取泛型参数,存在时,赋值子表单 + parseSubClass(field).ifPresent(subClazz -> property.setChildren(from(subClazz))); + // 处理替换 + applyReplacement(property, item); + }) + .or() + .as(DateRange.class) + .exists(() -> { + property.setType(BeanPropertyType.DATE); + property + .prop("type", "range") + .prop("placeholder", Arrays.asList("开始时间", "结束时间")); + }) + .or() + .as(DBRefValue.class) + .map(item -> item.synthesize().value()) + // 添加了数据库引用注解,自动注入类型给前端使用 + .then(value -> processDbRef(value).ifPresent(ref -> { + property.setType(BeanPropertyType.DB_REF); + property.prop("uri", ref).prop("mode", "multiple"); + })) + .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; case OBJECT: // 有子bean注解才处理 - if (null != field && annotations.isPresent(SubBean.class)) { - property.setChildren(from(clazz)); - // 处理替换 - applyReplacement(property, annotations); - } + annotations.as(SubBean.class) + .map(MergedAnnotation::synthesize) + .then(value -> { + property.setChildren(from(clazz)); + // 处理替换 + applyReplacement(property, value); + }) + .end(); + // 有子bean注解才处理 +// if (null != field && annotations.isPresent(SubBean.class)) { +// property.setChildren(from(clazz)); +// // 处理替换 +// applyReplacement(property, annotations); +// } break; case DB_REF: // 当存在db-ref时,解析为动态数据源 @@ -276,28 +371,34 @@ public class BeanProperty { break; case DATE: // 为日期,自动放入类型和长度 - if (null != field) { - if (annotations.isPresent(JsonFormat.class)) { - String pattern = annotations.get(JsonFormat.class).synthesize().pattern(); - // yyyy-MM-dd HH:mm:ss - if (StringUtils.isNotBlank(pattern)) { - int length = pattern.length(); - if (length == 7) { - property.prop("type", "month"); - } else if (length == 10) { - property.prop("type", "date"); - } else if (length == 11) { - property.prop("type", "date") - .prop("format", "YYYY年MM月DD日"); - } else if (length == 16) { - property.prop("type", "datetime"); - property.prop("format", "YYYY-MM-DD HH:mm"); - } else if (length > 16) { - property.prop("format", "YYYY-MM-DD HH:mm:ss"); + annotations.as(JsonFormat.class) + .map(item -> item.synthesize().pattern()) + .then(pattern -> { + // yyyy-MM-dd HH:mm:ss + if (StringUtils.isNotBlank(pattern)) { + int length = pattern.length(); + if (length == 7) { + property.prop("type", "month"); + } else if (length == 10) { + property.prop("type", "date"); + } else if (length == 11) { + property.prop("type", "date") + .prop("format", "YYYY年MM月DD日"); + } else if (length == 16) { + property.prop("type", "datetime"); + property.prop("format", "YYYY-MM-DD HH:mm"); + } else if (length > 16) { + property.prop("format", "YYYY-MM-DD HH:mm:ss"); + } } - } - } - } + }) + .end(); +// if (null != field) { +// if (annotations.isPresent(JsonFormat.class)) { +// String pattern = annotations.get(JsonFormat.class).synthesize().pattern(); +// +// } +// } } // 写入默认值 Object value = ReflectionUtils.getFieldValue(instance, property.name); @@ -472,13 +573,12 @@ public class BeanProperty { } /** - * 替换文案的生效 + * 替换子表单文案的生效 * - * @param property 属性 - * @param annotations 注解 + * @param property 属性 + * @param subBean 注解 */ - private static void applyReplacement(BeanProperty property, MergedAnnotations annotations) { - SubBean subBean = annotations.get(SubBean.class).synthesize(); + private static void applyReplacement(BeanProperty property, SubBean subBean) { if (CollectionUtils.isNotEmpty(property.getChildren()) && StringUtils.isNotBlank(subBean.search()) && StringUtils.isNotBlank(subBean.replacement())) { property.getChildren().forEach(child -> child.setTitle(child.getTitle() diff --git a/flyfish-web/src/main/java/com/flyfish/framework/beans/meta/parser/BeanPropertyAnnotationParser.java b/flyfish-web/src/main/java/com/flyfish/framework/beans/meta/parser/BeanPropertyAnnotationParser.java new file mode 100644 index 0000000..217054c --- /dev/null +++ b/flyfish-web/src/main/java/com/flyfish/framework/beans/meta/parser/BeanPropertyAnnotationParser.java @@ -0,0 +1,10 @@ +package com.flyfish.framework.beans.meta.parser; + +/** + * bean属性注解解析器 + * @author wangyu + */ +public class BeanPropertyAnnotationParser { + + +} diff --git a/flyfish-web/src/main/java/com/flyfish/framework/beans/meta/parser/BeanPropertyAnnotations.java b/flyfish-web/src/main/java/com/flyfish/framework/beans/meta/parser/BeanPropertyAnnotations.java new file mode 100644 index 0000000..9ac9ac1 --- /dev/null +++ b/flyfish-web/src/main/java/com/flyfish/framework/beans/meta/parser/BeanPropertyAnnotations.java @@ -0,0 +1,87 @@ +package com.flyfish.framework.beans.meta.parser; + +import com.flyfish.framework.beans.meta.parser.chain.BeanPropertyAnnotationBatchChain; +import com.flyfish.framework.beans.meta.parser.chain.BeanPropertyAnnotationChain; +import org.springframework.core.annotation.MergedAnnotation; +import org.springframework.core.annotation.MergedAnnotations; + +import java.lang.annotation.Annotation; + +/** + * 基于spring annotations最高级封装 + * 1. 全optional机制 + * 2. 完整链式调用 + * 3. 支持或、与操作 + * + * @author wangyu + */ +public interface BeanPropertyAnnotations { + + /** + * 判断是否有某个注解 + * + * @param annotationType 注解类型 + * @param 泛型 + * @return 结果 + */ + boolean isPresent(Class annotationType); + + /** + * 获取纯粹的spring注解属性表 + * + * @return 结果 + */ + MergedAnnotations annotations(); + + /** + * 判断某个注解是否存在,存在则交给consumer进行处理,仅取得找到的第一个注解 + * + * @param annotationType 注解类型 + * @param 泛型 + * @return 结果 + */ + BeanPropertyAnnotationChain> as(Class annotationType); + + /** + * 判断某个注解是否存在,存在则交给consumer进行处理,取得所有注解并自动判断复数形式 + * + * @param annotationType 注解类型 + * @param listType 列表类型 + * @param 泛型 + * @param 列表泛型 + * @return 结果 + */ + BeanPropertyAnnotationBatchChain> as( + Class annotationType, Class listType); + + /** + * 设置上一步结果 + * + * @param success 是否成功 + * @return 结果 + */ + BeanPropertyAnnotations last(boolean success); + + /** + * 返回上一步成功结果 + * + * @return 结果 + */ + boolean last(); + + /** + * 返回空的运行链 + * + * @param 注解泛型 + * @return 结果 + */ + BeanPropertyAnnotationChain empty(); + + /** + * 返回空的运行链 + * + * @param 注解泛型 + * @return 结果 + */ + BeanPropertyAnnotationBatchChain batchEmpty(); +} diff --git a/flyfish-web/src/main/java/com/flyfish/framework/beans/meta/parser/SimpleBeanPropertyAnnotations.java b/flyfish-web/src/main/java/com/flyfish/framework/beans/meta/parser/SimpleBeanPropertyAnnotations.java new file mode 100644 index 0000000..2fc78de --- /dev/null +++ b/flyfish-web/src/main/java/com/flyfish/framework/beans/meta/parser/SimpleBeanPropertyAnnotations.java @@ -0,0 +1,150 @@ +package com.flyfish.framework.beans.meta.parser; + +import com.flyfish.framework.beans.meta.parser.chain.BeanPropertyAnnotationBatchChain; +import com.flyfish.framework.beans.meta.parser.chain.BeanPropertyAnnotationChain; +import com.flyfish.framework.beans.meta.parser.chain.impl.EmptyAnnotationBatchChain; +import com.flyfish.framework.beans.meta.parser.chain.impl.EmptyAnnotationChain; +import com.flyfish.framework.beans.meta.parser.chain.impl.SimpleAnnotationBatchChain; +import com.flyfish.framework.beans.meta.parser.chain.impl.SimpleAnnotationChain; +import org.apache.commons.collections4.CollectionUtils; +import org.springframework.core.annotation.MergedAnnotation; +import org.springframework.core.annotation.MergedAnnotations; +import org.springframework.data.util.CastUtils; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Field; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +/** + * bean属性注解容器 + * + * @author wangyu + */ +public class SimpleBeanPropertyAnnotations implements BeanPropertyAnnotations { + + private final Field field; + + private final MergedAnnotations annotations; + private final EmptyAnnotationChain emptyChain = new EmptyAnnotationChain<>(this); + private final EmptyAnnotationBatchChain emptyBatchChain = new EmptyAnnotationBatchChain<>(this); + private boolean last; + + public SimpleBeanPropertyAnnotations(Field field) { + this.field = field; + this.annotations = null == field ? MergedAnnotations.from() : MergedAnnotations.from(field); + } + + /** + * 判断是否有某个注解 + * + * @param annotationType 注解类型 + * @return 结果 + */ + @Override + public boolean isPresent(Class annotationType) { + if (null == field) { + return false; + } + return annotations.isPresent(annotationType); + } + + /** + * 获取纯粹的spring注解属性表 + * + * @return 结果 + */ + @Override + public MergedAnnotations annotations() { + return annotations; + } + + /** + * 判断某个注解是否存在,存在则交给consumer进行处理,仅取得找到的第一个注解 + * + * @param annotationType 注解类型 + * @return 结果 + */ + @Override + public BeanPropertyAnnotationChain> as(Class annotationType) { + if (null != field && !this.last) { + MergedAnnotation annotation = this.annotations.get(annotationType); + if (annotation.isPresent()) { + return new SimpleAnnotationChain<>(this.last(true), annotation); + } + } + return empty(); + } + + /** + * 判断某个注解是否存在,存在则交给consumer进行处理,取得所有注解并自动判断复数形式 + * + * @param annotationType 注解类型 + * @param listType 列表类型 + * @param 泛型 + * @param 列表泛型 + * @return 结果 + */ + @Override + public BeanPropertyAnnotationBatchChain> as( + Class annotationType, Class listType) { + if (null != field && !this.last) { + MergedAnnotation annotation = this.annotations.get(listType); + if (annotation.isPresent()) { + return new SimpleAnnotationBatchChain<>(this.last(true), + Arrays.asList(annotation.getAnnotationArray("value", annotationType))); + } else { + List> values = this.annotations.stream(annotationType) + .filter(MergedAnnotation::isPresent) + .collect(Collectors.toList()); + if (CollectionUtils.isNotEmpty(values)) { + return new SimpleAnnotationBatchChain<>(this.last(true), values); + } + } + } + return batchEmpty(); + } + + /** + * 设置上一步结果 + * + * @param success 是否成功 + * @return 结果 + */ + @Override + public SimpleBeanPropertyAnnotations last(boolean success) { + this.last = success; + return this; + } + + /** + * 返回上一步成功结果 + * + * @return 结果 + */ + @Override + public boolean last() { + return this.last; + } + + /** + * 返回空的运行链 + * + * @return 结果 + */ + @Override + public BeanPropertyAnnotationChain empty() { + return CastUtils.cast(emptyChain); + } + + /** + * 返回空的运行链 + * + * @return 结果 + */ + @Override + public BeanPropertyAnnotationBatchChain batchEmpty() { + return CastUtils.cast(emptyBatchChain); + } +} diff --git a/flyfish-web/src/main/java/com/flyfish/framework/beans/meta/parser/chain/AnnotationChainSupport.java b/flyfish-web/src/main/java/com/flyfish/framework/beans/meta/parser/chain/AnnotationChainSupport.java new file mode 100644 index 0000000..750380c --- /dev/null +++ b/flyfish-web/src/main/java/com/flyfish/framework/beans/meta/parser/chain/AnnotationChainSupport.java @@ -0,0 +1,30 @@ +package com.flyfish.framework.beans.meta.parser.chain; + +import com.flyfish.framework.beans.meta.parser.BeanPropertyAnnotations; + +/** + * 链式支持 + * + * @author wangyu + */ +public interface AnnotationChainSupport { + + /** + * 下一步要做什么 + * + * @return 结果 + */ + BeanPropertyAnnotations and(); + + /** + * 下一步要做什么,如果这一步成立,下一步不执行;反之,这一步不成立,下一步才执行 + * + * @return 结果 + */ + BeanPropertyAnnotations or(); + + /** + * 主动停止操作,会清空前面的状态 + */ + void end(); +} diff --git a/flyfish-web/src/main/java/com/flyfish/framework/beans/meta/parser/chain/BeanPropertyAnnotationBatchChain.java b/flyfish-web/src/main/java/com/flyfish/framework/beans/meta/parser/chain/BeanPropertyAnnotationBatchChain.java new file mode 100644 index 0000000..c1e60f4 --- /dev/null +++ b/flyfish-web/src/main/java/com/flyfish/framework/beans/meta/parser/chain/BeanPropertyAnnotationBatchChain.java @@ -0,0 +1,75 @@ +package com.flyfish.framework.beans.meta.parser.chain; + +import java.lang.annotation.Annotation; +import java.util.List; +import java.util.function.Consumer; +import java.util.function.Function; +import java.util.function.Predicate; +import java.util.function.Supplier; + +/** + * 抽象的链式操作,作为批量支持 + * + * @param 注解泛型 + * @param 入参类型 + */ +public interface BeanPropertyAnnotationBatchChain extends AnnotationChainSupport { + + /** + * 映射转换,将转换每一条 + * + * @param mapper 映射器 + * @param 泛型 + * @return 结果 + */ + BeanPropertyAnnotationBatchChain map(Function mapper); + + /** + * 过滤,不满足的将过滤,如果为空,将empty + * + * @param filter 过滤器 + * @return 结果 + */ + BeanPropertyAnnotationBatchChain filter(Predicate filter); + + /** + * 过滤,不满足的将过滤,如果为空,将empty + * + * @param filter 过滤器 + * @return 结果 + */ + BeanPropertyAnnotationBatchChain filter(Supplier filter); + + /** + * 如果存在,则做 + * + * @param consumer 消费者 + * @return 结果 + */ + BeanPropertyAnnotationBatchChain then(Consumer> consumer); + + /** + * 存在时执行逻辑,不需要结果 + * + * @param handler 处理器 + * @return 结果 + */ + BeanPropertyAnnotationBatchChain exists(Runnable handler); + + /** + * 不存在做的事情 + * + * @param fallback 补偿逻辑 + * @return 结果 + */ + BeanPropertyAnnotationBatchChain empty(Runnable fallback); + + /** + * 获取所有结果为list + * + * @return 结果 + */ + List synthesize(); + + +} diff --git a/flyfish-web/src/main/java/com/flyfish/framework/beans/meta/parser/chain/BeanPropertyAnnotationChain.java b/flyfish-web/src/main/java/com/flyfish/framework/beans/meta/parser/chain/BeanPropertyAnnotationChain.java new file mode 100644 index 0000000..0eda8b4 --- /dev/null +++ b/flyfish-web/src/main/java/com/flyfish/framework/beans/meta/parser/chain/BeanPropertyAnnotationChain.java @@ -0,0 +1,73 @@ +package com.flyfish.framework.beans.meta.parser.chain; + +import java.lang.annotation.Annotation; +import java.util.function.Consumer; +import java.util.function.Function; +import java.util.function.Predicate; +import java.util.function.Supplier; + +/** + * 抽象的链式操作 + * + * @param 注解泛型 + * @param 入参类型 + */ +public interface BeanPropertyAnnotationChain extends AnnotationChainSupport { + + /** + * 映射转换 + * + * @param mapper 映射器 + * @param 泛型 + * @return 结果 + */ + BeanPropertyAnnotationChain map(Function mapper); + + /** + * 过滤,不满足的将直接empty + * + * @param filter 过滤器 + * @return 结果 + */ + BeanPropertyAnnotationChain filter(Predicate filter); + + /** + * 过滤,不满足的将直接empty + * + * @param filter 过滤器 + * @return 结果 + */ + BeanPropertyAnnotationChain filter(Supplier filter); + + /** + * 如果存在,则做 + * + * @param consumer 消费者 + * @return 结果 + */ + BeanPropertyAnnotationChain then(Consumer consumer); + + /** + * 存在时执行逻辑,不需要结果 + * + * @param handler 处理器 + * @return 结果 + */ + BeanPropertyAnnotationChain exists(Runnable handler); + + /** + * 不存在做的事情 + * + * @param fallback 补偿逻辑 + * @return 结果 + */ + BeanPropertyAnnotationChain empty(Runnable fallback); + + /** + * 直接获取结果 + * + * @return 结果 + */ + A synthesize(); + +} diff --git a/flyfish-web/src/main/java/com/flyfish/framework/beans/meta/parser/chain/impl/BasicAnnotationChainSupport.java b/flyfish-web/src/main/java/com/flyfish/framework/beans/meta/parser/chain/impl/BasicAnnotationChainSupport.java new file mode 100644 index 0000000..4dc6cc4 --- /dev/null +++ b/flyfish-web/src/main/java/com/flyfish/framework/beans/meta/parser/chain/impl/BasicAnnotationChainSupport.java @@ -0,0 +1,45 @@ +package com.flyfish.framework.beans.meta.parser.chain.impl; + +import com.flyfish.framework.beans.meta.parser.BeanPropertyAnnotations; +import com.flyfish.framework.beans.meta.parser.chain.AnnotationChainSupport; +import lombok.RequiredArgsConstructor; + +/** + * 基本的链式支持 + * + * @author wangyu + */ +@RequiredArgsConstructor +public class BasicAnnotationChainSupport implements AnnotationChainSupport { + + // 父级 + protected final BeanPropertyAnnotations parent; + + /** + * 下一步要做什么 + * + * @return 结果 + */ + @Override + public BeanPropertyAnnotations and() { + return parent.last(false); + } + + /** + * 下一步要做什么,如果这一步不成立,才执行 + * + * @return 结果 + */ + @Override + public BeanPropertyAnnotations or() { + return parent; + } + + /** + * 主动停止操作,会清空前面的状态 + */ + @Override + public void end() { + parent.last(false); + } +} diff --git a/flyfish-web/src/main/java/com/flyfish/framework/beans/meta/parser/chain/impl/EmptyAnnotationBatchChain.java b/flyfish-web/src/main/java/com/flyfish/framework/beans/meta/parser/chain/impl/EmptyAnnotationBatchChain.java new file mode 100644 index 0000000..a113f1d --- /dev/null +++ b/flyfish-web/src/main/java/com/flyfish/framework/beans/meta/parser/chain/impl/EmptyAnnotationBatchChain.java @@ -0,0 +1,106 @@ +package com.flyfish.framework.beans.meta.parser.chain.impl; + +import com.flyfish.framework.beans.meta.parser.BeanPropertyAnnotations; +import com.flyfish.framework.beans.meta.parser.chain.BeanPropertyAnnotationBatchChain; +import org.springframework.data.util.CastUtils; + +import java.lang.annotation.Annotation; +import java.util.Collections; +import java.util.List; +import java.util.function.Consumer; +import java.util.function.Function; +import java.util.function.Predicate; +import java.util.function.Supplier; + +/** + * 单例的,空实现 + * + * @param 注解泛型 + * @param 实际泛型 + */ +public class EmptyAnnotationBatchChain extends BasicAnnotationChainSupport implements BeanPropertyAnnotationBatchChain { + + public EmptyAnnotationBatchChain(BeanPropertyAnnotations parent) { + super(parent); + } + + /** + * 映射转换,将转换每一条 + * + * @param mapper 映射器 + * @return 结果 + */ + @Override + public BeanPropertyAnnotationBatchChain map(Function mapper) { + return CastUtils.cast(this); + } + + /** + * 过滤,不满足的将过滤,如果为空,将empty + * + * @param filter 过滤器 + * @return 结果 + */ + @Override + public BeanPropertyAnnotationBatchChain filter(Predicate filter) { + return this; + } + + /** + * 过滤,不满足的将过滤,如果为空,将empty + * + * @param filter 过滤器 + * @return 结果 + */ + @Override + public BeanPropertyAnnotationBatchChain filter(Supplier filter) { + return this; + } + + /** + * 如果存在,则做 + * + * @param consumer 消费者 + * @return 结果 + */ + @Override + public BeanPropertyAnnotationBatchChain then(Consumer> consumer) { + return this; + } + + /** + * 存在时执行逻辑,不需要结果 + * + * @param handler 处理器 + * @return 结果 + */ + @Override + public BeanPropertyAnnotationBatchChain exists(Runnable handler) { + return this; + } + + /** + * 不存在做的事情 + * + * @param fallback 补偿逻辑 + * @return 结果 + */ + @Override + public BeanPropertyAnnotationBatchChain empty(Runnable fallback) { + if (!parent.last()) { + fallback.run(); + } + return this; + } + + /** + * 获取所有结果为list + * + * @return 结果 + */ + @Override + public List synthesize() { + parent.last(false); + return Collections.emptyList(); + } +} diff --git a/flyfish-web/src/main/java/com/flyfish/framework/beans/meta/parser/chain/impl/EmptyAnnotationChain.java b/flyfish-web/src/main/java/com/flyfish/framework/beans/meta/parser/chain/impl/EmptyAnnotationChain.java new file mode 100644 index 0000000..ed19f8d --- /dev/null +++ b/flyfish-web/src/main/java/com/flyfish/framework/beans/meta/parser/chain/impl/EmptyAnnotationChain.java @@ -0,0 +1,104 @@ +package com.flyfish.framework.beans.meta.parser.chain.impl; + +import com.flyfish.framework.beans.meta.parser.BeanPropertyAnnotations; +import com.flyfish.framework.beans.meta.parser.chain.BeanPropertyAnnotationChain; +import org.springframework.data.util.CastUtils; + +import java.lang.annotation.Annotation; +import java.util.function.Consumer; +import java.util.function.Function; +import java.util.function.Predicate; +import java.util.function.Supplier; + +/** + * 单例的,空实现 + * + * @param 注解泛型 + * @param 实际泛型 + */ +public class EmptyAnnotationChain extends BasicAnnotationChainSupport + implements BeanPropertyAnnotationChain { + + public EmptyAnnotationChain(BeanPropertyAnnotations parent) { + super(parent); + } + + /** + * 映射转换 + * + * @param mapper 映射器 + * @return 结果 + */ + @Override + public BeanPropertyAnnotationChain map(Function mapper) { + return CastUtils.cast(this); + } + + /** + * 过滤,不满足的将直接empty + * + * @param filter 过滤器 + * @return 结果 + */ + @Override + public BeanPropertyAnnotationChain filter(Predicate filter) { + return this; + } + + /** + * 过滤,不满足的将直接empty + * + * @param filter 过滤器 + * @return 结果 + */ + @Override + public BeanPropertyAnnotationChain filter(Supplier filter) { + return this; + } + + /** + * 如果存在,则做 + * + * @param consumer 消费者 + * @return 结果 + */ + @Override + public BeanPropertyAnnotationChain then(Consumer consumer) { + return this; + } + + /** + * 存在时执行逻辑,不需要结果 + * + * @param handler 处理器 + * @return 结果 + */ + @Override + public BeanPropertyAnnotationChain exists(Runnable handler) { + return this; + } + + /** + * 不存在做的事情 + * + * @param fallback 补偿逻辑 + * @return 结果 + */ + @Override + public BeanPropertyAnnotationChain empty(Runnable fallback) { + if (!parent.last()) { + fallback.run(); + } + return this; + } + + /** + * 直接获取结果 + * + * @return 结果 + */ + @Override + public A synthesize() { + return null; + } +} diff --git a/flyfish-web/src/main/java/com/flyfish/framework/beans/meta/parser/chain/impl/SimpleAnnotationBatchChain.java b/flyfish-web/src/main/java/com/flyfish/framework/beans/meta/parser/chain/impl/SimpleAnnotationBatchChain.java new file mode 100644 index 0000000..4e3f89c --- /dev/null +++ b/flyfish-web/src/main/java/com/flyfish/framework/beans/meta/parser/chain/impl/SimpleAnnotationBatchChain.java @@ -0,0 +1,134 @@ +package com.flyfish.framework.beans.meta.parser.chain.impl; + +import com.flyfish.framework.beans.meta.parser.BeanPropertyAnnotations; +import com.flyfish.framework.beans.meta.parser.chain.BeanPropertyAnnotationBatchChain; +import org.apache.commons.collections4.CollectionUtils; +import org.springframework.core.annotation.MergedAnnotation; +import org.springframework.data.util.CastUtils; + +import java.lang.annotation.Annotation; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.function.Consumer; +import java.util.function.Function; +import java.util.function.Predicate; +import java.util.function.Supplier; +import java.util.stream.Collectors; + +/** + * 简单的批量注解链式实现 + * + * @param 注解类型 + * @param 实际类型 + */ +public class SimpleAnnotationBatchChain extends BasicAnnotationChainSupport + implements BeanPropertyAnnotationBatchChain { + + // 内置值 + private List values; + + // 是否map过 + private boolean mapped = false; + + public SimpleAnnotationBatchChain(BeanPropertyAnnotations parent, List annotations) { + super(parent); + this.values = annotations; + } + + /** + * 映射转换,将转换每一条 + * + * @param mapper 映射器 + * @return 结果 + */ + @Override + public BeanPropertyAnnotationBatchChain map(Function mapper) { + List list = values.stream().map(mapper).filter(Objects::nonNull) + .collect(Collectors.toList()); + if (CollectionUtils.isEmpty(list)) { + return parent.batchEmpty(); + } + this.mapped = true; + this.values = CastUtils.cast(list); + return CastUtils.cast(this); + } + + /** + * 过滤,不满足的将过滤,如果为空,将empty + * + * @param filter 过滤器 + * @return 结果 + */ + @Override + public BeanPropertyAnnotationBatchChain filter(Predicate filter) { + this.values = values.stream().filter(filter).collect(Collectors.toList()); + if (CollectionUtils.isEmpty(values)) { + return parent.batchEmpty(); + } + return this; + } + + /** + * 过滤,不满足的将过滤,如果为空,将empty + * + * @param filter 过滤器 + * @return 结果 + */ + @Override + public BeanPropertyAnnotationBatchChain filter(Supplier filter) { + if (!filter.get()) { + return parent.batchEmpty(); + } + return this; + } + + /** + * 如果存在,则做 + * + * @param consumer 消费者 + * @return 结果 + */ + @Override + public BeanPropertyAnnotationBatchChain then(Consumer> consumer) { + this.parent.last(true); + consumer.accept(this.values); + return this; + } + + /** + * 存在时执行逻辑,不需要结果 + * + * @param handler 处理器 + * @return 结果 + */ + @Override + public BeanPropertyAnnotationBatchChain exists(Runnable handler) { + this.parent.last(true); + handler.run(); + return this; + } + + /** + * 不存在做的事情 + * + * @param fallback 补偿逻辑 + * @return 结果 + */ + @Override + public BeanPropertyAnnotationBatchChain empty(Runnable fallback) { + return this; + } + + /** + * 获取所有结果为list + * + * @return 结果 + */ + @Override + @SuppressWarnings("unchecked") + public List synthesize() { + return mapped ? Collections.emptyList() : this.values.stream().map(item -> (MergedAnnotation) item) + .map(MergedAnnotation::synthesize).collect(Collectors.toList()); + } +} diff --git a/flyfish-web/src/main/java/com/flyfish/framework/beans/meta/parser/chain/impl/SimpleAnnotationChain.java b/flyfish-web/src/main/java/com/flyfish/framework/beans/meta/parser/chain/impl/SimpleAnnotationChain.java new file mode 100644 index 0000000..f4991ec --- /dev/null +++ b/flyfish-web/src/main/java/com/flyfish/framework/beans/meta/parser/chain/impl/SimpleAnnotationChain.java @@ -0,0 +1,124 @@ +package com.flyfish.framework.beans.meta.parser.chain.impl; + +import com.flyfish.framework.beans.meta.parser.BeanPropertyAnnotations; +import com.flyfish.framework.beans.meta.parser.chain.BeanPropertyAnnotationChain; +import org.springframework.core.annotation.MergedAnnotation; +import org.springframework.data.util.CastUtils; + +import java.lang.annotation.Annotation; +import java.util.function.Consumer; +import java.util.function.Function; +import java.util.function.Predicate; +import java.util.function.Supplier; + +/** + * 简单的注解链 + * + * @param 注解类型 + * @param 泛型 + */ +public class SimpleAnnotationChain extends BasicAnnotationChainSupport + implements BeanPropertyAnnotationChain { + + // 内置值 + private T value; + + public SimpleAnnotationChain(BeanPropertyAnnotations parent, T value) { + super(parent); + this.value = value; + } + + /** + * 映射转换 + * + * @param mapper 映射器 + * @return 结果 + */ + @Override + public BeanPropertyAnnotationChain map(Function mapper) { + R value = mapper.apply(this.value); + if (null == value) { + return parent.empty(); + } + this.value = CastUtils.cast(value); + return CastUtils.cast(this); + } + + /** + * 过滤,不满足的将直接empty + * + * @param filter 过滤器 + * @return 结果 + */ + @Override + public BeanPropertyAnnotationChain filter(Predicate filter) { + // 测试不通过,直接返回空,释放内存 + if (!filter.test(this.value)) { + return parent.empty(); + } + return this; + } + + /** + * 过滤,不满足的将直接empty + * + * @param filter 过滤器 + * @return 结果 + */ + @Override + public BeanPropertyAnnotationChain filter(Supplier filter) { + if (!filter.get()) { + return parent.empty(); + } + return this; + } + + /** + * 如果存在,则做 + * + * @param consumer 消费者 + * @return 结果 + */ + @Override + public BeanPropertyAnnotationChain then(Consumer consumer) { + parent.last(true); + consumer.accept(value); + return this; + } + + /** + * 存在时执行逻辑,不需要结果 + * + * @param handler 处理器 + * @return 结果 + */ + @Override + public BeanPropertyAnnotationChain exists(Runnable handler) { + parent.last(true); + handler.run(); + return this; + } + + /** + * 不存在做的事情 + * + * @param fallback 补偿逻辑 + * @return 结果 + */ + @Override + public BeanPropertyAnnotationChain empty(Runnable fallback) { + return this; + } + + /** + * 直接获取结果 + * + * @return 结果 + */ + @Override + @SuppressWarnings("unchecked") + public A synthesize() { + parent.last(false); + return value instanceof MergedAnnotation ? ((MergedAnnotation) value).synthesize() : null; + } +} diff --git a/flyfish-web/src/main/java/com/flyfish/framework/configuration/WebfluxConfig.java b/flyfish-web/src/main/java/com/flyfish/framework/configuration/WebfluxConfig.java index 4452e8d..84e52ab 100644 --- a/flyfish-web/src/main/java/com/flyfish/framework/configuration/WebfluxConfig.java +++ b/flyfish-web/src/main/java/com/flyfish/framework/configuration/WebfluxConfig.java @@ -7,7 +7,7 @@ import com.flyfish.framework.configuration.resolver.RequestContextBodyArgumentRe import com.flyfish.framework.configuration.resolver.UserArgumentResolver; import com.flyfish.framework.configuration.resolver.ValidRequestBodyMethodArgumentResolver; import com.flyfish.framework.context.SpringContext; -import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.jackson.JacksonProperties; import org.springframework.context.annotation.Configuration; import org.springframework.core.Ordered; import org.springframework.core.ReactiveAdapterRegistry; @@ -20,9 +20,9 @@ import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; import org.springframework.web.reactive.config.EnableWebFlux; import org.springframework.web.reactive.config.WebFluxConfigurer; import org.springframework.web.reactive.result.method.annotation.ArgumentResolverConfigurer; -import org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerAdapter; import javax.annotation.Resource; +import java.util.Optional; import java.util.TimeZone; /** @@ -35,8 +35,8 @@ import java.util.TimeZone; @Order(Ordered.HIGHEST_PRECEDENCE) public class WebfluxConfig implements WebFluxConfigurer { - @Value("${spring.jackson.date-format}") - private String dateFormat = "yyyy-MM-dd HH:mm:ss"; + @Resource + private JacksonProperties jacksonProperties; /** * Configure resolvers for custom {@code @RequestMapping} method arguments. @@ -64,13 +64,12 @@ public class WebfluxConfig implements WebFluxConfigurer { TimeZone.setDefault(TimeZone.getTimeZone("GMT+8")); CodecConfigurer.DefaultCodecs defaults = configurer.defaultCodecs(); ObjectMapper mapper = Jackson2ObjectMapperBuilder.json() - .simpleDateFormat(dateFormat) + .simpleDateFormat(Optional.ofNullable(jacksonProperties.getDateFormat()).orElse("yyyy-MM-dd HH:mm:ss")) .timeZone("GMT+8") - .serializationInclusion(JsonInclude.Include.NON_NULL) + .serializationInclusion(Optional.ofNullable(jacksonProperties.getDefaultPropertyInclusion()) + .orElse(JsonInclude.Include.NON_NULL)) .build(); - defaults.jackson2JsonDecoder( - new Jackson2JsonDecoder(mapper)); - defaults.jackson2JsonEncoder( - new Jackson2JsonEncoder(mapper)); + defaults.jackson2JsonDecoder(new Jackson2JsonDecoder(mapper)); + defaults.jackson2JsonEncoder(new Jackson2JsonEncoder(mapper)); } } diff --git a/flyfish-web/src/main/java/com/flyfish/framework/service/impl/BaseReactiveServiceImpl.java b/flyfish-web/src/main/java/com/flyfish/framework/service/impl/BaseReactiveServiceImpl.java index 06954c3..b91a0ae 100644 --- a/flyfish-web/src/main/java/com/flyfish/framework/service/impl/BaseReactiveServiceImpl.java +++ b/flyfish-web/src/main/java/com/flyfish/framework/service/impl/BaseReactiveServiceImpl.java @@ -290,7 +290,7 @@ public class BaseReactiveServiceImpl implements BaseReactiveSe public Mono deleteBatchByIds(List ids) { return Flux.fromIterable(ids) .flatMap(t -> repository.deleteById(t)) - .single(); + .then(Mono.empty()); } /**