Commit b85d660a5cc375bccb9c200fd0ac4a813c62c00d
1 parent
0a0c3c0e
trade: 分销业务完善校验
Showing
4 changed files
with
64 additions
and
12 deletions
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/record/AppBrokerageRecordPageReqVO.java
| 1 | 1 | package cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.record; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageParam; |
| 4 | +import cn.iocoder.yudao.framework.common.validation.InEnum; | |
| 5 | +import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum; | |
| 6 | +import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordStatusEnum; | |
| 4 | 7 | import io.swagger.v3.oas.annotations.media.Schema; |
| 5 | 8 | import lombok.Data; |
| 6 | 9 | |
| ... | ... | @@ -8,12 +11,12 @@ import lombok.Data; |
| 8 | 11 | @Data |
| 9 | 12 | public class AppBrokerageRecordPageReqVO extends PageParam { |
| 10 | 13 | |
| 11 | - // TODO @疯狂:要加下枚举校验 | |
| 12 | - | |
| 13 | 14 | @Schema(description = "业务类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") |
| 15 | + @InEnum(value = BrokerageRecordBizTypeEnum.class, message = "业务类型必须是 {value}") | |
| 14 | 16 | private Integer bizType; |
| 15 | 17 | |
| 16 | 18 | @Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") |
| 19 | + @InEnum(value = BrokerageRecordStatusEnum.class, message = "状态必须是 {value}") | |
| 17 | 20 | private Integer status; |
| 18 | 21 | |
| 19 | 22 | } | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/withdraw/AppBrokerageWithdrawCreateReqVO.java
| 1 | 1 | package cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.withdraw; |
| 2 | 2 | |
| 3 | +import cn.iocoder.yudao.framework.common.util.validation.ValidationUtils; | |
| 4 | +import cn.iocoder.yudao.framework.common.validation.InEnum; | |
| 5 | +import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageWithdrawTypeEnum; | |
| 3 | 6 | import io.swagger.v3.oas.annotations.media.Schema; |
| 4 | 7 | import lombok.Data; |
| 5 | 8 | import org.hibernate.validator.constraints.URL; |
| 6 | 9 | |
| 10 | +import javax.validation.Validator; | |
| 7 | 11 | import javax.validation.constraints.Min; |
| 12 | +import javax.validation.constraints.NotBlank; | |
| 8 | 13 | |
| 9 | 14 | @Schema(description = "用户 App - 分销提现创建 Request VO") |
| 10 | 15 | @Data |
| 11 | 16 | public class AppBrokerageWithdrawCreateReqVO { |
| 12 | 17 | |
| 13 | - // TODO @疯狂:参数校验逻辑,需要根据 type 进行不同的校验;感觉可以通过分组? | |
| 14 | - | |
| 15 | 18 | @Schema(description = "提现方式", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") |
| 19 | + @InEnum(value = BrokerageWithdrawTypeEnum.class, message = "提现方式必须是 {value}") | |
| 16 | 20 | private Integer type; |
| 17 | 21 | |
| 18 | - @Schema(description = "提现账号", requiredMode = Schema.RequiredMode.REQUIRED, example = "123456789") // 银行卡号/微信账号/支付宝账号 | |
| 22 | + @Schema(description = "提现金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000") | |
| 23 | + @Min(value = 1, message = "提现金额不能小于 1") | |
| 24 | + private Integer price; | |
| 25 | + | |
| 26 | + | |
| 27 | + // ========== 银行卡、微信、支付宝 提现相关字段 ========== | |
| 28 | + | |
| 29 | + @Schema(description = "提现账号", requiredMode = Schema.RequiredMode.REQUIRED, example = "123456789") | |
| 30 | + @NotBlank(message = "提现账号不能为空", groups = {Bank.class, Wechat.class, Alipay.class}) | |
| 19 | 31 | private String accountNo; |
| 20 | 32 | |
| 33 | + | |
| 34 | + // ========== 微信、支付宝 提现相关字段 ========== | |
| 35 | + | |
| 21 | 36 | @Schema(description = "收款码的图片", example = "https://www.iocoder.cn/1.png") |
| 22 | 37 | @URL(message = "收款码的图片,必须是一个 URL") |
| 23 | 38 | private String accountQrCodeUrl; |
| 24 | 39 | |
| 25 | - @Schema(description = "提现金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000") | |
| 26 | - @Min(value = 1, message = "提现金额必须大于 1") | |
| 27 | - private Integer price; | |
| 40 | + | |
| 41 | + // ========== 银行卡 提现相关字段 ========== | |
| 42 | + | |
| 43 | + @Schema(description = "持卡人姓名", example = "张三") | |
| 44 | + @NotBlank(message = "持卡人姓名不能为空", groups = {Bank.class}) | |
| 45 | + private String name; | |
| 46 | + @Schema(description = "提现银行", example = "1") | |
| 47 | + @NotBlank(message = "提现银行不能为空", groups = {Bank.class}) | |
| 48 | + private Integer bankName; | |
| 49 | + @Schema(description = "开户地址", example = "海淀支行") | |
| 50 | + private String bankAddress; | |
| 51 | + | |
| 52 | + public interface Wallet { | |
| 53 | + } | |
| 54 | + | |
| 55 | + public interface Bank { | |
| 56 | + } | |
| 57 | + | |
| 58 | + public interface Wechat { | |
| 59 | + } | |
| 60 | + | |
| 61 | + public interface Alipay { | |
| 62 | + } | |
| 63 | + | |
| 64 | + public void validate(Validator validator) { | |
| 65 | + if (BrokerageWithdrawTypeEnum.WALLET.getType().equals(type)) { | |
| 66 | + ValidationUtils.validate(validator, this, Wallet.class); | |
| 67 | + } else if (BrokerageWithdrawTypeEnum.BANK.getType().equals(type)) { | |
| 68 | + ValidationUtils.validate(validator, this, Bank.class); | |
| 69 | + } else if (BrokerageWithdrawTypeEnum.WECHAT.getType().equals(type)) { | |
| 70 | + ValidationUtils.validate(validator, this, Wechat.class); | |
| 71 | + } else if (BrokerageWithdrawTypeEnum.ALIPAY.getType().equals(type)) { | |
| 72 | + ValidationUtils.validate(validator, this, Alipay.class); | |
| 73 | + } | |
| 74 | + } | |
| 28 | 75 | |
| 29 | 76 | } | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/bo/BrokerageAddReqBO.java
| ... | ... | @@ -4,6 +4,8 @@ import lombok.AllArgsConstructor; |
| 4 | 4 | import lombok.Data; |
| 5 | 5 | import lombok.NoArgsConstructor; |
| 6 | 6 | |
| 7 | +import javax.validation.constraints.NotBlank; | |
| 8 | + | |
| 7 | 9 | /** |
| 8 | 10 | * 佣金 增加 Request BO |
| 9 | 11 | * |
| ... | ... | @@ -14,11 +16,10 @@ import lombok.NoArgsConstructor; |
| 14 | 16 | @AllArgsConstructor |
| 15 | 17 | public class BrokerageAddReqBO { |
| 16 | 18 | |
| 17 | - // TODO @疯狂:bo 的话,也可以考虑加下 @Validated 注解,校验下参数;防御性下哈,虽然不一定用的到 | |
| 18 | - | |
| 19 | 19 | /** |
| 20 | - * 业务ID | |
| 20 | + * 业务编号 | |
| 21 | 21 | */ |
| 22 | + @NotBlank(message = "业务编号不能为空") | |
| 22 | 23 | private String bizId; |
| 23 | 24 | /** |
| 24 | 25 | * 佣金基数 | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/BrokerageRecordService.java
| ... | ... | @@ -7,6 +7,7 @@ import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum; |
| 7 | 7 | import cn.iocoder.yudao.module.trade.service.brokerage.bo.BrokerageAddReqBO; |
| 8 | 8 | import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserBrokerageSummaryBO; |
| 9 | 9 | |
| 10 | +import javax.validation.Valid; | |
| 10 | 11 | import java.util.List; |
| 11 | 12 | |
| 12 | 13 | /** |
| ... | ... | @@ -39,7 +40,7 @@ public interface BrokerageRecordService { |
| 39 | 40 | * @param bizType 业务类型 |
| 40 | 41 | * @param list 请求参数列表 |
| 41 | 42 | */ |
| 42 | - void addBrokerage(Long userId, BrokerageRecordBizTypeEnum bizType, List<BrokerageAddReqBO> list); | |
| 43 | + void addBrokerage(Long userId, BrokerageRecordBizTypeEnum bizType, @Valid List<BrokerageAddReqBO> list); | |
| 43 | 44 | |
| 44 | 45 | /** |
| 45 | 46 | * 取消佣金:将佣金记录,状态修改为已失效 | ... | ... |