feat: 实现手机号校验

This commit is contained in:
wangyu 2021-09-28 17:40:13 +08:00
parent a2aaec96e5
commit 9100c2214a
6 changed files with 113 additions and 2 deletions

View File

@ -0,0 +1,43 @@
package com.flyfish.framework.annotations;
import com.flyfish.framework.annotations.ConditionOn.List;
import java.lang.annotation.*;
import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
/**
* 条件处理
* 可以通过条件处理动态的显隐字段
* 包括表达式校验支持repeat
*/
@Target({ANNOTATION_TYPE, FIELD, TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Repeatable(List.class)
public @interface ConditionOn {
/**
* @return 判定的字段
*/
String field() default "";
/**
* @return 判定的值
*/
String value() default "";
/**
* @return js表达式
*/
String expression() default "";
@Target({FIELD, TYPE, ANNOTATION_TYPE})
@Retention(RUNTIME)
@Documented
@interface List {
ConditionOn[] value() default {};
}
}

View File

@ -0,0 +1,42 @@
package com.flyfish.framework.annotations;
import java.lang.annotation.*;
/**
* 值生成策略
* 值生成只发生在表单初始化阶段
* 对于父类使用的场景如果子类进行了属性覆盖但未指定生成策略父类策略会被忽略
*
* @author wangyu
*/
@Target({ElementType.ANNOTATION_TYPE, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Generation {
/**
* 生成策略
*
* @return 结果
*/
Strategy value() default Strategy.NONE;
/**
* 来自某个字段
*
* @return 结果
*/
String[] from() default {};
/**
* 模板支持生成模板
*
* @return 结果
*/
String template() default "";
enum Strategy {
NONE, NAME, CODE, TIMESTAMP, TRANSACTION
}
}

View File

@ -86,4 +86,9 @@ public @interface Property {
* @return 映射的注解仅用于构造器
*/
MappedTo[] mapping() default {};
/**
* 自动生成的值
*/
Generation[] generated() default {};
}

View File

@ -1,6 +1,7 @@
package com.flyfish.framework.domain.base;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.flyfish.framework.annotations.Generation;
import com.flyfish.framework.annotations.Property;
import com.flyfish.framework.domain.po.User;
import lombok.Getter;
@ -32,6 +33,7 @@ public abstract class Domain implements Po, Serializable {
*/
@Property(title = "编码", inherited = true)
@NotBlank(message = "编码不可为空")
@Generation(Generation.Strategy.CODE)
protected String code;
/**
@ -40,6 +42,7 @@ public abstract class Domain implements Po, Serializable {
@Indexed
@Property(title = "名称", inherited = true)
@NotBlank(message = "名称不可为空")
@Generation(Generation.Strategy.NAME)
protected String name;
/**

View File

@ -134,6 +134,12 @@ public class BeanProperty {
} else {
property.setOrder(props.order());
}
// 追加生成属性
MergedAnnotation<Generation> generation = annotations.get(Generation.class);
if (generation.isPresent()) {
property.extra.put(BeanProps.GENERATED, generation.asMap());
property.extra.put(BeanProps.COMPONENT, "input-hidden");
}
// 优雅的设置额外的属性
MergedAnnotation<FormItem> item = annotations.get(FormItem.class);
if (item.isPresent()) {
@ -185,7 +191,7 @@ public class BeanProperty {
case NUMBER:
if (null != field) {
if (annotations.isPresent(Money.class) && !property.extra.containsKey("component")) {
property.extra.put("component", "money-input");
property.extra.put(BeanProps.COMPONENT, "money-input");
}
}
break;
@ -324,6 +330,12 @@ public class BeanProperty {
if (ArrayUtils.isNotEmpty(prop.mapping())) {
property.extra.put("mapping", MergedAnnotations.from(prop.mapping()).get(MappedTo.class).asMap());
}
// 处理值生成策略此处可清除原策略
if (ArrayUtils.isNotEmpty(prop.generated())) {
property.extra.put(BeanProps.GENERATED, MergedAnnotations.from(prop.mapping()).get(MappedTo.class).asMap());
} else {
property.extra.remove(BeanProps.GENERATED);
}
// 设置标题
property.title = prop.title();
} else {
@ -374,7 +386,9 @@ public class BeanProperty {
*/
private static void applyFormItem(BeanProperty property, FormItem item) {
// 设置额外属性
property.extra.put("component", item.component());
if (StringUtils.isNotBlank(item.component())) {
property.extra.put(BeanProps.COMPONENT, item.component());
}
property.layout = item.layout();
if (ArrayUtils.isNotEmpty(item.props())) {
for (FormItem.Prop prop : item.props()) {

View File

@ -17,4 +17,8 @@ public interface BeanProps {
String LAYOUT_HALF = "half";
String LAYOUT_TABLE = "table";
String COMPONENT = "component";
String GENERATED = "generated";
}