trade: 分销业务完善校验

This commit is contained in:
owen 2023-09-08 22:33:44 +08:00
parent 0a0c3c0ede
commit b85d660a5c
4 changed files with 64 additions and 12 deletions

View File

@ -1,6 +1,9 @@
package cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.record;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.validation.InEnum;
import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum;
import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordStatusEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@ -8,12 +11,12 @@ import lombok.Data;
@Data
public class AppBrokerageRecordPageReqVO extends PageParam {
// TODO @疯狂要加下枚举校验
@Schema(description = "业务类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@InEnum(value = BrokerageRecordBizTypeEnum.class, message = "业务类型必须是 {value}")
private Integer bizType;
@Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@InEnum(value = BrokerageRecordStatusEnum.class, message = "状态必须是 {value}")
private Integer status;
}

View File

@ -1,29 +1,76 @@
package cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.withdraw;
import cn.iocoder.yudao.framework.common.util.validation.ValidationUtils;
import cn.iocoder.yudao.framework.common.validation.InEnum;
import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageWithdrawTypeEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.hibernate.validator.constraints.URL;
import javax.validation.Validator;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
@Schema(description = "用户 App - 分销提现创建 Request VO")
@Data
public class AppBrokerageWithdrawCreateReqVO {
// TODO @疯狂参数校验逻辑需要根据 type 进行不同的校验感觉可以通过分组
@Schema(description = "提现方式", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@InEnum(value = BrokerageWithdrawTypeEnum.class, message = "提现方式必须是 {value}")
private Integer type;
@Schema(description = "提现账号", requiredMode = Schema.RequiredMode.REQUIRED, example = "123456789") // 银行卡号/微信账号/支付宝账号
@Schema(description = "提现金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000")
@Min(value = 1, message = "提现金额不能小于 1")
private Integer price;
// ========== 银行卡微信支付宝 提现相关字段 ==========
@Schema(description = "提现账号", requiredMode = Schema.RequiredMode.REQUIRED, example = "123456789")
@NotBlank(message = "提现账号不能为空", groups = {Bank.class, Wechat.class, Alipay.class})
private String accountNo;
// ========== 微信支付宝 提现相关字段 ==========
@Schema(description = "收款码的图片", example = "https://www.iocoder.cn/1.png")
@URL(message = "收款码的图片,必须是一个 URL")
private String accountQrCodeUrl;
@Schema(description = "提现金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000")
@Min(value = 1, message = "提现金额必须大于 1")
private Integer price;
// ========== 银行卡 提现相关字段 ==========
@Schema(description = "持卡人姓名", example = "张三")
@NotBlank(message = "持卡人姓名不能为空", groups = {Bank.class})
private String name;
@Schema(description = "提现银行", example = "1")
@NotBlank(message = "提现银行不能为空", groups = {Bank.class})
private Integer bankName;
@Schema(description = "开户地址", example = "海淀支行")
private String bankAddress;
public interface Wallet {
}
public interface Bank {
}
public interface Wechat {
}
public interface Alipay {
}
public void validate(Validator validator) {
if (BrokerageWithdrawTypeEnum.WALLET.getType().equals(type)) {
ValidationUtils.validate(validator, this, Wallet.class);
} else if (BrokerageWithdrawTypeEnum.BANK.getType().equals(type)) {
ValidationUtils.validate(validator, this, Bank.class);
} else if (BrokerageWithdrawTypeEnum.WECHAT.getType().equals(type)) {
ValidationUtils.validate(validator, this, Wechat.class);
} else if (BrokerageWithdrawTypeEnum.ALIPAY.getType().equals(type)) {
ValidationUtils.validate(validator, this, Alipay.class);
}
}
}

View File

@ -4,6 +4,8 @@ import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.validation.constraints.NotBlank;
/**
* 佣金 增加 Request BO
*
@ -14,11 +16,10 @@ import lombok.NoArgsConstructor;
@AllArgsConstructor
public class BrokerageAddReqBO {
// TODO @疯狂bo 的话也可以考虑加下 @Validated 注解校验下参数防御性下哈虽然不一定用的到
/**
* 业务ID
* 业务编号
*/
@NotBlank(message = "业务编号不能为空")
private String bizId;
/**
* 佣金基数

View File

@ -7,6 +7,7 @@ import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum;
import cn.iocoder.yudao.module.trade.service.brokerage.bo.BrokerageAddReqBO;
import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserBrokerageSummaryBO;
import javax.validation.Valid;
import java.util.List;
/**
@ -39,7 +40,7 @@ public interface BrokerageRecordService {
* @param bizType 业务类型
* @param list 请求参数列表
*/
void addBrokerage(Long userId, BrokerageRecordBizTypeEnum bizType, List<BrokerageAddReqBO> list);
void addBrokerage(Long userId, BrokerageRecordBizTypeEnum bizType, @Valid List<BrokerageAddReqBO> list);
/**
* 取消佣金将佣金记录状态修改为已失效