feat():增加了支付渠道枚举和支付渠道校验
parent
97a05af72e
commit
e13b25577a
|
@ -0,0 +1,72 @@
|
||||||
|
package com.muyu.common.core.enums;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:zhangchengzhi
|
||||||
|
* @Package:com.muyu.common.core.enums
|
||||||
|
* @Project:cloud-common-core
|
||||||
|
* @name:SysPayType
|
||||||
|
* @Date:2024/8/4 14:09
|
||||||
|
*/
|
||||||
|
public enum SysPayType {
|
||||||
|
|
||||||
|
ALI_PAY("aliPay","支付宝"),
|
||||||
|
WECHAT_PAY("wechatPay","微信支付"),
|
||||||
|
JD_PAY("jdPay","京东支付")
|
||||||
|
;
|
||||||
|
|
||||||
|
private final String code;
|
||||||
|
private final String info;
|
||||||
|
|
||||||
|
public String getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getInfo() {
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
|
||||||
|
SysPayType(String code, String info) {
|
||||||
|
this.code = code;
|
||||||
|
this.info = info;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 鉴别Code是否合法
|
||||||
|
* @param code
|
||||||
|
* @return 如果存在code则返回true,不存在则返回
|
||||||
|
*/
|
||||||
|
|
||||||
|
public static boolean isCode(String code){
|
||||||
|
|
||||||
|
return Arrays.stream(values())
|
||||||
|
.map(SysPayType::getCode)
|
||||||
|
.anyMatch(s -> s.equals(code)); //传cou
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过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(() -> "-");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -43,8 +43,6 @@ public enum SystemYesNo {
|
||||||
.map(SystemYesNo::getCode)
|
.map(SystemYesNo::getCode)
|
||||||
.anyMatch(s -> s.equals(code)); //传cou
|
.anyMatch(s -> s.equals(code)); //传cou
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
package com.muyu.common.core.validation.custom;
|
||||||
|
|
||||||
|
import jakarta.validation.Constraint;
|
||||||
|
import jakarta.validation.Payload;
|
||||||
|
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:zhangchengzhi
|
||||||
|
* @Package:com.muyu.common.core.validation.custom
|
||||||
|
* @Project:cloud-common-core
|
||||||
|
* @name:IsSystemPayType
|
||||||
|
* @Date:2024/7/31 20:22
|
||||||
|
* @Decscription validation 自定义支付渠道校验
|
||||||
|
*/
|
||||||
|
@Target({ElementType.FIELD})
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Documented
|
||||||
|
@Constraint(validatedBy = {SystemYesNoValidator.class})
|
||||||
|
public @interface IsSystemPayType {
|
||||||
|
|
||||||
|
String message() default "[支付渠道] - 参数不合法";
|
||||||
|
Class<?>[] groups() default {};
|
||||||
|
Class<? extends Payload>[] payload() default {};
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
package com.muyu.common.core.validation.custom;
|
||||||
|
|
||||||
|
import com.muyu.common.core.enums.SysPayType;
|
||||||
|
import jakarta.validation.ConstraintValidator;
|
||||||
|
import jakarta.validation.ConstraintValidatorContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:zhangchengzhi
|
||||||
|
* @Package:com.muyu.common.core.validation.custom
|
||||||
|
* @Project:cloud-common-core
|
||||||
|
* @name:SystemYesNoValidator
|
||||||
|
* @Date:2024/7/31 20:22
|
||||||
|
*/
|
||||||
|
public class SystemPayTypeValidator implements ConstraintValidator<IsSystemPayType, String> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) {
|
||||||
|
return SysPayType.isCode(value);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue