一、自定义分组完成微信支付,申请退款参数二选一
@GroupSequenceProvider(value = NativeRefundSequenceProvider.class)
@Data
public class NativeRefundDTO {
/**
* 微信支付基本配置
*/
@Valid
@NotNull(message = "微信支付基本配置必传")
private WxPayBase wxPayBase;
@NotBlank(message = "微信支付订单号必传",groups = WhenOutTradeNoIsNull.class)
@Length(min = 1, max = 32, message = "微信支付订单号长度需要在1和32之间",groups = WhenOutTradeNoIsNull.class)
private String transaction_id;
@NotBlank(message = "商户订单号必传",groups = WhenTransactionIdIsNull.class)
@Length(min = 6, max = 32, message = "商户订单号长度需要在6和32之间",groups = WhenTransactionIdIsNull.class)
private String out_trade_no;
@NotBlank(message = "商户退款单号必传")
@Length(min = 1, max = 64, message = "商户退款单号长度需要在1和64之间")
private String out_refund_no;
/**
* 退款原因
*/
@Length(min = 1, max = 80, message = "退款原因长度需要在1和80之间")
private String reason;
/**
* 退款结果回调url
*/
@Length(min = 8, max = 256, message = "退款结果回调url长度需要在8和256之间")
private String notify_url;
/**
* 退款资金来源
*/
@Length(min = 1, max = 32, message = "退款资金来源长度需要在1和32之间")
private String funds_account;
/**
* -金额信息
*/
@Valid
private NativeRefundAmount amount;
/**
* 退款商品
*/
@Valid
private List<NativeRefundGoodsDetail> goods_detail;
/**
* 微信支付订单没传
*/
public interface WhenTransactionIdIsNull {}
/**
* 商户订单号没传
*/
public interface WhenOutTradeNoIsNull {}
}
public class NativeRefundSequenceProvider implements DefaultGroupSequenceProvider<NativeRefundDTO> {
@Override
public List<Class<?>> getValidationGroups(NativeRefundDTO dto) {
List<Class<?>> defaultGroupSequence = new ArrayList<>();
defaultGroupSequence.add(NativeRefundDTO.class);
if(Objects.nonNull(dto)){
//微信支付订单号为null,group =WhenTransactionIdIsNull 的校验注解生效
if(Objects.isNull(dto.getTransaction_id()) ){
defaultGroupSequence.add(NativeRefundDTO.WhenTransactionIdIsNull.class);
}
//商户订单号为null,group = WhenOutTradeNoIsNull 的校验注解生效
if(Objects.isNull(dto.getOut_trade_no())){
defaultGroupSequence.add(NativeRefundDTO.WhenOutTradeNoIsNull.class);
}
}
return defaultGroupSequence;
}
}