增加校验的代码
parent
0a29a3be63
commit
649708b019
14
pom.xml
14
pom.xml
|
@ -10,8 +10,7 @@
|
|||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>cloud-common-core</artifactId>
|
||||
<version>1.0.0</version>
|
||||
|
||||
<version>3.6.3</version>
|
||||
<description>
|
||||
cloud-common-core核心模块
|
||||
</description>
|
||||
|
@ -165,6 +164,17 @@
|
|||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- forestHttp调用框架依赖 -->
|
||||
<dependency>
|
||||
<groupId>com.dtflys.forest</groupId>
|
||||
<artifactId>forest-spring-boot3-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.swagger.core.v3</groupId>
|
||||
<artifactId>swagger-annotations-jakarta</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
package com.muyu.common.core.enums;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
|
||||
/**
|
||||
* @author Lenovo
|
||||
*/
|
||||
public enum SysPayType {
|
||||
ALI_PAY("aliPay","支付宝"),
|
||||
WECHAT_PAY("wechatPay","微信支付"),
|
||||
JD_PAY("jdPay","京东支付");
|
||||
|
||||
private final String code;
|
||||
|
||||
private final String info;
|
||||
|
||||
SysPayType(String code, String info) {
|
||||
this.code = code;
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public String getCode(){
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getInfo(){
|
||||
return info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 鉴别code是否合法
|
||||
* @param code
|
||||
* @return 如果存在code则返回true,不存在则返回false
|
||||
*/
|
||||
public static boolean isCode(String code){
|
||||
return Arrays.stream(values())
|
||||
.map(SysPayType::getCode)
|
||||
.anyMatch(s -> s.equals(code));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过code获取支付渠道
|
||||
* @param code code编码
|
||||
* @return 支付渠道
|
||||
*/
|
||||
public static String getInfoByCode(String code){
|
||||
return Arrays.stream(values())
|
||||
.filter(s -> s.getCode().equals(code))
|
||||
.findFirst()
|
||||
.map(SysPayType::getInfo)
|
||||
.orElseGet(() -> "-");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
package com.muyu.common.core.enums;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* @author Lenovo
|
||||
*/
|
||||
|
||||
public enum SystemYesNo {
|
||||
|
||||
YES("Y","是"),
|
||||
NO("N","否"),
|
||||
;
|
||||
|
||||
private final String code;
|
||||
|
||||
private final String info;
|
||||
|
||||
SystemYesNo(String code, String info) {
|
||||
this.code = code;
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public String getCode(){
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getInfo(){
|
||||
return info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 鉴别code是否合法
|
||||
* @param code
|
||||
* @return 如果存在code则返回true,不存在则返回false
|
||||
*/
|
||||
public static boolean isCode(String code){
|
||||
return Arrays.stream(values())
|
||||
.map(SystemYesNo::getCode)
|
||||
.anyMatch(s -> s.equals(code));
|
||||
}
|
||||
}
|
|
@ -5,6 +5,9 @@ import jakarta.validation.Validator;
|
|||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @author Lenovo
|
||||
*/
|
||||
@Configuration
|
||||
public class ValidationConfig {
|
||||
@Bean
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
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 Lenovo
|
||||
*/
|
||||
@Target({ElementType.FIELD})
|
||||
@Retention(RUNTIME)
|
||||
@Documented
|
||||
@Constraint(validatedBy = {SystemPayTypeValidator.class})
|
||||
public @interface IsSystemPayType {
|
||||
String message() default "[支付渠道] - 参数不合法";
|
||||
Class<?>[] groups() default {};
|
||||
Class<? extends Payload>[] payload() default { };
|
||||
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package com.muyu.common.core.validation.custom;
|
||||
|
||||
import jakarta.validation.Constraint;
|
||||
import jakarta.validation.Payload;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
/**
|
||||
* @author Lenovo
|
||||
*/
|
||||
@Target({ElementType.FIELD})
|
||||
@Retention(RUNTIME)
|
||||
@Documented
|
||||
@Constraint(validatedBy = {SystemYesNoValidator.class})
|
||||
public @interface IsSystemYesNo {
|
||||
String message() default "数据字典:[系统是否] - 参数不合法";
|
||||
Class<?>[] groups() default {};
|
||||
Class<? extends Payload>[] payload() default { };
|
||||
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package com.muyu.common.core.validation.custom;
|
||||
|
||||
import com.muyu.common.core.enums.SysPayType;
|
||||
import jakarta.validation.ConstraintValidator;
|
||||
import jakarta.validation.ConstraintValidatorContext;
|
||||
|
||||
/**
|
||||
* @author Lenovo
|
||||
*/
|
||||
public class SystemPayTypeValidator implements ConstraintValidator<IsSystemPayType,String> {
|
||||
|
||||
@Override
|
||||
public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) {
|
||||
return SysPayType.isCode(value);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package com.muyu.common.core.validation.custom;
|
||||
|
||||
import com.muyu.common.core.enums.SystemYesNo;
|
||||
import jakarta.validation.ConstraintValidator;
|
||||
import jakarta.validation.ConstraintValidatorContext;
|
||||
|
||||
/**
|
||||
* @author Lenovo
|
||||
*/
|
||||
public class SystemYesNoValidator implements ConstraintValidator<IsSystemYesNo,String> {
|
||||
|
||||
@Override
|
||||
public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) {
|
||||
return SystemYesNo.isCode(value);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue