From bcfb412c8b6146619961c2937992a94145721eb2 Mon Sep 17 00:00:00 2001 From: wangyu <727842003@qq.com> Date: Thu, 1 Apr 2021 23:44:00 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0db=E5=BC=95=E7=94=A8?= =?UTF-8?q?=E6=B3=A8=E8=A7=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../framework/annotations/DateRange.java | 14 +++++++++ .../framework/beans/meta/BeanProperty.java | 31 +++++++++++++++++-- 2 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 flyfish-data/src/main/java/com/flyfish/framework/annotations/DateRange.java diff --git a/flyfish-data/src/main/java/com/flyfish/framework/annotations/DateRange.java b/flyfish-data/src/main/java/com/flyfish/framework/annotations/DateRange.java new file mode 100644 index 0000000..cf38867 --- /dev/null +++ b/flyfish-data/src/main/java/com/flyfish/framework/annotations/DateRange.java @@ -0,0 +1,14 @@ +package com.flyfish.framework.annotations; + +import java.lang.annotation.*; + +/** + * 日期范围标记 + * + * @author wangyu + */ +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.FIELD}) +@Documented +public @interface DateRange { +} 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 ba57d14..742b98b 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 @@ -1,5 +1,6 @@ package com.flyfish.framework.beans.meta; +import com.fasterxml.jackson.annotation.JsonFormat; import com.flyfish.framework.annotations.Properties; import com.flyfish.framework.annotations.*; import com.flyfish.framework.domain.base.Qo; @@ -10,6 +11,7 @@ import lombok.Data; import lombok.val; import org.apache.commons.collections4.ListUtils; import org.apache.commons.lang3.ClassUtils; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.reflect.FieldUtils; import org.apache.commons.lang3.reflect.TypeUtils; import org.springframework.beans.BeanUtils; @@ -119,9 +121,15 @@ public class BeanProperty { } break; case LIST: - // 尝试获取泛型参数,存在时,赋值子表单 - if (null != field && field.isAnnotationPresent(SubBean.class)) { - parseSubClass(field).ifPresent(subClazz -> property.setChildren(from(subClazz))); + if (null != field) { + if (field.isAnnotationPresent(SubBean.class)) { + // 尝试获取泛型参数,存在时,赋值子表单 + parseSubClass(field).ifPresent(subClazz -> property.setChildren(from(subClazz))); + } else if (field.isAnnotationPresent(DateRange.class)) { + property.setType(BeanPropertyType.DATE); + property.prop("type", "range"); + property.prop("placeholder", Arrays.asList("开始时间", "结束时间")); + } } break; case OBJECT: @@ -144,6 +152,23 @@ public class BeanProperty { String name = StringFormats.camel2Line(ClassUtils.getShortClassName(clazz)); property.prop("code", name); break; + case DATE: + // 为日期,自动放入类型和长度 + if (null != field) { + if (field.isAnnotationPresent(JsonFormat.class)) { + String pattern = field.getAnnotation(JsonFormat.class).pattern(); + // yyyy-MM-dd HH:mm:ss + if (StringUtils.isNotBlank(pattern)) { + if (pattern.length() == 7) { + property.prop("type", "month"); + } else if (pattern.length() == 10) { + property.prop("type", "date"); + } else if (pattern.length() > 16) { + property.prop("format", "YYYY-MM-DD HH:mm:ss"); + } + } + } + } } return property; }