feat():添加判断规则类型注解
parent
d4146f285e
commit
ff83833abb
3
pom.xml
3
pom.xml
|
@ -5,7 +5,7 @@
|
|||
<parent>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common</artifactId>
|
||||
<version>3.6.3</version>
|
||||
<version>3.6.4</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
@ -17,6 +17,7 @@
|
|||
|
||||
<dependencies>
|
||||
|
||||
|
||||
<!-- SpringCloud Openfeign -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
package com.muyu.common.core.enums;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* @Author:蓬叁
|
||||
* @Package:com.muyu.common.core.enums
|
||||
* @Project:cloud-common-core
|
||||
* @name:SysRuleType
|
||||
* @Date:2024/8/23 下午7:24
|
||||
*/
|
||||
public enum SysRuleType {
|
||||
Z("Z","自定义规则"), M("M","规则模板");
|
||||
|
||||
private final String code;
|
||||
private final String info;
|
||||
|
||||
SysRuleType(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(SysRuleType::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:IsSysRuleZM
|
||||
* @Date:2024/8/23 下午7:30
|
||||
*/
|
||||
@Target({ElementType.FIELD})
|
||||
@Retention(RUNTIME)
|
||||
@Documented
|
||||
@Constraint(validatedBy = IsSysRuleZMValidator.class)
|
||||
public @interface IsSysRuleZM {
|
||||
|
||||
String message() default "数据字典:[系统是否] - 参数不合法";
|
||||
Class<?>[] groups() default { };
|
||||
Class<? extends Payload>[] payload() default { };
|
||||
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package com.muyu.common.core.validation.custom;
|
||||
|
||||
import com.muyu.common.core.enums.SysRuleType;
|
||||
import jakarta.validation.ConstraintValidator;
|
||||
import jakarta.validation.ConstraintValidatorContext;
|
||||
|
||||
/**
|
||||
* @Author:蓬叁
|
||||
* @Package:com.muyu.common.core.validation.custom
|
||||
* @Project:cloud-common-core
|
||||
* @name:IsSysRuleZMValidator
|
||||
* @Date:2024/8/23 下午7:31
|
||||
*/
|
||||
public class IsSysRuleZMValidator implements ConstraintValidator<IsSysRuleZM, String> {
|
||||
|
||||
@Override
|
||||
public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) {
|
||||
return SysRuleType.isCode(value);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue