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; }