feat:增加细化的domain超类接口

This commit is contained in:
wangyu 2021-10-05 23:05:32 +08:00
parent 25d00ec9bf
commit fa30ebb8c2
6 changed files with 22 additions and 14 deletions

View File

@ -1,7 +1,7 @@
package com.flyfish.framework.validation.annotations;
import com.flyfish.framework.validation.validators.IdCardValidator;
import com.flyfish.framework.validation.annotations.UniqueField.List;
import com.flyfish.framework.validation.validators.UniqueFieldValidator;
import javax.validation.Constraint;
import javax.validation.Payload;
@ -9,11 +9,8 @@ import java.lang.annotation.Documented;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import com.flyfish.framework.validation.annotations.UniqueField.List;
import com.flyfish.framework.validation.validators.UniqueFieldValidator;
import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER})

View File

@ -10,10 +10,10 @@ import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.beans.PropertyDescriptor;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import java.util.Collection;
import java.util.Map;
public class UniqueFieldValidator implements ConstraintValidator<UniqueField, List<Object>> {
public class UniqueFieldValidator implements ConstraintValidator<UniqueField, Collection> {
private String field;
@ -34,12 +34,12 @@ public class UniqueFieldValidator implements ConstraintValidator<UniqueField, Li
* @return {@code false} if {@code value} does not pass the constraint
*/
@Override
public boolean isValid(List<Object> value, ConstraintValidatorContext context) {
public boolean isValid(Collection value, ConstraintValidatorContext context) {
int size = CollectionUtils.size(value);
if (size < 2) {
return true;
}
long count = value.stream().map(item -> {
long count = ((Collection<?>) value).stream().map(item -> {
if (item instanceof String || ClassUtils.isPrimitiveOrWrapper(item.getClass())) {
return item;
}

View File

@ -17,7 +17,7 @@ import java.io.Serializable;
@Document
@Getter
@Setter
public abstract class Domain implements Po, Serializable {
public abstract class Domain implements Po, Named, Serializable {
private static final long serialVersionUID = -8288256526019424379L;

View File

@ -0,0 +1,11 @@
package com.flyfish.framework.domain.base;
/**
* 有名称的
*
* @author wangyu
*/
public interface Named {
String getName();
}

View File

@ -4,13 +4,13 @@ import com.flyfish.framework.annotations.ConditionOn;
import com.flyfish.framework.beans.meta.BeanPropertyType;
import com.flyfish.framework.beans.meta.BeanValidation;
import com.flyfish.framework.validation.annotations.IdCard;
import com.flyfish.framework.validation.annotations.Money;
import com.flyfish.framework.validation.annotations.Phone;
import com.flyfish.framework.validation.annotations.UniqueField;
import com.flyfish.framework.validation.enums.PhoneType;
import lombok.Getter;
import lombok.val;
import org.apache.commons.lang3.ArrayUtils;
import org.hibernate.validator.constraints.Currency;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.Range;
import org.hibernate.validator.constraints.URL;
@ -70,7 +70,7 @@ public enum ValidationCandidate {
.prop("type", annotation.getType().getSimpleName()),
Negative.class, NegativeOrZero.class, Positive.class, PositiveOrZero.class),
// 货币
CURRENCY((annotation, validation) -> validation.setValidator("currency"), Currency.class),
MONEY((annotation, validation) -> validation.setValidator("currency"), Money.class),
// 手机号
PHONE((annotation, validation) -> validation.setValidator("phone").prop("type",
annotation.getEnum("type", PhoneType.class).name().toLowerCase()), Phone.class),

View File

@ -21,9 +21,9 @@ import java.util.function.BiPredicate;
public enum BeanPropertyType {
STRING("String", "string", CharSequence.class),
NUMBER("Number", "string", Number.class),
NUMBER("Number", "any", Number.class),
BOOLEAN("Boolean", "boolean", Boolean.class),
DATE("Date", "date", Date.class),
DATE("Date", "any", Date.class),
ENUM("Enum", "any", Enum.class),
LIST("Array", "array", Collection.class),
DB_REF("Ref", "any", Po.class),