feat():添加规则作用域自定义注解
parent
96b2ef5b8d
commit
dab70ab8fa
|
@ -0,0 +1,37 @@
|
||||||
|
package com.muyu.common.core.enums;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:蓬叁
|
||||||
|
* @Package:com.muyu.common.core.enums
|
||||||
|
* @Project:cloud-common-core
|
||||||
|
* @name:SysRuleRegion
|
||||||
|
* @Date:2024/8/23 下午8:20
|
||||||
|
*/
|
||||||
|
public enum SysRuleRegion {
|
||||||
|
FIELD("F","数据字段"), RECORD("R","记录"), COLLECT("C","数据集");
|
||||||
|
|
||||||
|
private final String code;
|
||||||
|
private final String info;
|
||||||
|
|
||||||
|
SysRuleRegion(String code, String info) {
|
||||||
|
this.code = code;
|
||||||
|
this.info = info;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCode () {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getInfo () {
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isCode(String code){
|
||||||
|
return Arrays.stream(values())
|
||||||
|
.map(SysRuleRegion::getCode)
|
||||||
|
.anyMatch(s -> s.equals(code));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
package com.muyu.common.core.validation.custom;
|
||||||
|
|
||||||
|
import jakarta.validation.Constraint;
|
||||||
|
import jakarta.validation.Payload;
|
||||||
|
|
||||||
|
import java.lang.annotation.Documented;
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:蓬叁
|
||||||
|
* @Package:com.muyu.common.core.validation.custom
|
||||||
|
* @Project:cloud-common-core
|
||||||
|
* @name:IsSysRuleRegion
|
||||||
|
* @Date:2024/8/23 下午8:18
|
||||||
|
*/
|
||||||
|
@Target({ElementType.FIELD})
|
||||||
|
@Retention(RUNTIME)
|
||||||
|
@Documented
|
||||||
|
@Constraint(validatedBy = IsSysRuleRegionValidation.class)
|
||||||
|
public @interface IsSysRuleRegion {
|
||||||
|
|
||||||
|
String message() default "数据字典:[系统是否] - 参数不合法";
|
||||||
|
Class<?>[] groups() default { };
|
||||||
|
Class<? extends Payload>[] payload() default { };
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
package com.muyu.common.core.validation.custom;
|
||||||
|
|
||||||
|
import com.muyu.common.core.enums.SysRuleRegion;
|
||||||
|
import jakarta.validation.ConstraintValidator;
|
||||||
|
import jakarta.validation.ConstraintValidatorContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:蓬叁
|
||||||
|
* @Package:com.muyu.common.core.validation.custom
|
||||||
|
* @Project:cloud-common-core
|
||||||
|
* @name:IsSysRuleRegionValidation
|
||||||
|
* @Date:2024/8/23 下午8:19
|
||||||
|
*/
|
||||||
|
public class IsSysRuleRegionValidation implements ConstraintValidator<IsSysRuleRegion, String> {
|
||||||
|
@Override
|
||||||
|
public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) {
|
||||||
|
return SysRuleRegion.isCode(value);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue