feat:() 增加了支付渠道枚举和支付渠道进行校验
parent
4f74a63c83
commit
48ed9f1809
|
@ -0,0 +1,58 @@
|
||||||
|
package com.muyu.common.core.enums;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName SysPayType
|
||||||
|
* @Description 支付系统枚举
|
||||||
|
* @Author Chen
|
||||||
|
* @Date 2024/8/8 9:41
|
||||||
|
*/
|
||||||
|
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 传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
|
||||||
|
* @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,29 @@
|
||||||
|
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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName IsSystemPayType
|
||||||
|
* @Description validation自定支付渠道校验
|
||||||
|
* @Author Chen
|
||||||
|
* @Date 2024/8/8 9:52
|
||||||
|
*/
|
||||||
|
@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,18 @@
|
||||||
|
package com.muyu.common.core.validation.custom;
|
||||||
|
|
||||||
|
import com.muyu.common.core.enums.SysPayType;
|
||||||
|
import jakarta.validation.ConstraintValidator;
|
||||||
|
import jakarta.validation.ConstraintValidatorContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName SystemYesNoValidator
|
||||||
|
* @Description 描述
|
||||||
|
* @Author Chen
|
||||||
|
* @Date 2024/8/6 21:01
|
||||||
|
*/
|
||||||
|
public class SystemPayTypeValidator implements ConstraintValidator<IsSystemYesNo,String> {
|
||||||
|
@Override
|
||||||
|
public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) {
|
||||||
|
return SysPayType.isCode(value);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue