From 2dddab4f31c91ae07c155fdc14592f2891ec9816 Mon Sep 17 00:00:00 2001 From: wangyu <727842003@qq.com> Date: Mon, 27 Sep 2021 14:38:14 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E6=8F=90=E4=BE=9B=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C=E6=96=87=E6=A1=88=E5=85=B3=E9=94=AE=E5=AD=97=E6=9B=BF?= =?UTF-8?q?=E6=8D=A2=E8=83=BD=E5=8A=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../flyfish/framework/domain/base/Domain.java | 3 +++ .../framework/beans/meta/BeanProperty.java | 18 +++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/flyfish-data/src/main/java/com/flyfish/framework/domain/base/Domain.java b/flyfish-data/src/main/java/com/flyfish/framework/domain/base/Domain.java index 1e4b67e..b4622b9 100644 --- a/flyfish-data/src/main/java/com/flyfish/framework/domain/base/Domain.java +++ b/flyfish-data/src/main/java/com/flyfish/framework/domain/base/Domain.java @@ -9,6 +9,7 @@ import org.springframework.data.annotation.Transient; import org.springframework.data.mongodb.core.index.Indexed; import org.springframework.data.mongodb.core.mapping.Document; +import javax.validation.constraints.NotBlank; import java.io.Serializable; @Document @@ -29,6 +30,7 @@ public abstract class Domain implements Po, Serializable { * 编号 */ @Property(title = "编码", inherited = true) + @NotBlank(message = "编码不可为空") protected String code; /** @@ -36,6 +38,7 @@ public abstract class Domain implements Po, Serializable { */ @Indexed @Property(title = "名称", inherited = true) + @NotBlank(message = "名称不可为空") protected String name; /** 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 a028216..6403564 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,6 +1,9 @@ package com.flyfish.framework.beans.meta; +import com.alibaba.fastjson.annotation.JSONField; import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; import com.flyfish.framework.annotations.Properties; import com.flyfish.framework.annotations.*; import com.flyfish.framework.beans.enums.ValidationCandidate; @@ -10,6 +13,7 @@ import com.flyfish.framework.utils.ReflectionUtils; import com.flyfish.framework.utils.StringFormats; import lombok.Data; import lombok.val; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.ListUtils; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.ClassUtils; @@ -54,8 +58,13 @@ public class BeanProperty { private BeanPropertyType type; // 只读属性,不生成于表单 + @JsonIgnore private transient boolean readonly; + // 继承属性,不生成于表单 + @JsonIgnore + private transient boolean inherited; + // 属性 private Map props; @@ -106,6 +115,7 @@ public class BeanProperty { property.setTitle(props.inherited() ? parentName + props.title() : props.title()); property.setDescription(props.description()); property.setReadonly(props.readonly()); + property.setInherited(props.inherited()); property.setGroup(props.group()); // 优雅地设置排序 MergedAnnotation order = annotations.get(Order.class); @@ -277,7 +287,6 @@ public class BeanProperty { .findFirst(); if (found.isPresent()) { BeanProperty property = found.get(); - property.title = prop.title(); if (prop.order() != 0) { property.order = prop.order(); } @@ -288,6 +297,13 @@ public class BeanProperty { if (prop.readonly()) { origin.remove(property); } + // 存在校验,替换名称文案(仅inherit) + if (property.inherited && CollectionUtils.isNotEmpty(property.validation)) { + property.validation.forEach(validation -> validation.setMessage(validation.getMessage() + .replace(property.title, prop.title()))); + } + // 设置标题 + property.title = prop.title(); } else { BeanProperty property = new BeanProperty(); property.setType(BeanPropertyType.STRING);