From dbd7ab5f231c60bac29ee4346263057fb32c879c Mon Sep 17 00:00:00 2001 From: jason <2667446@qq.com> Date: Thu, 21 Sep 2023 17:31:58 +0800 Subject: [PATCH] =?UTF-8?q?code=20review=20=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/mysql/pay_wallet.sql | 8 ++++---- .../AppPayWalletRechargeCreateReqVO.java | 7 ++++--- .../wallet/PayWalletRechargeConvert.java | 11 +++-------- .../dataobject/wallet/PayWalletRechargeDO.java | 17 +++++++++-------- .../pay/dal/mysql/wallet/PayWalletMapper.java | 13 ++++++------- .../wallet/PayWalletRechargeServiceImpl.java | 8 +++++--- .../service/wallet/PayWalletServiceImpl.java | 6 +++--- 7 files changed, 34 insertions(+), 36 deletions(-) diff --git a/sql/mysql/pay_wallet.sql b/sql/mysql/pay_wallet.sql index e9cc6a288e..e3d92239c0 100644 --- a/sql/mysql/pay_wallet.sql +++ b/sql/mysql/pay_wallet.sql @@ -50,17 +50,17 @@ CREATE TABLE `pay_wallet_recharge` ( `id` bigint NOT NULL AUTO_INCREMENT COMMENT '编号', `wallet_id` bigint NOT NULL COMMENT '会员钱包 id', - `price` int NOT NULL COMMENT '用户实际到账余额,例如充 100 送 20,则该值是 120', + `total_price` int NOT NULL COMMENT '用户实际到账余额,例如充 100 送 20,则该值是 120', `pay_price` int NOT NULL COMMENT '实际支付金额', - `wallet_bonus` int NOT NULL COMMENT '钱包赠送金额', + `bonus_price` int NOT NULL COMMENT '钱包赠送金额', `pay_status` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否已支付:[0:未支付 1:已经支付过]', `pay_order_id` bigint NULL COMMENT '支付订单编号', `pay_channel_code` varchar(16) NULL COMMENT '支付成功的支付渠道', `pay_time` datetime NULL COMMENT '订单支付时间', `pay_refund_id` bigint NULL COMMENT '支付退款单编号', - `refund_price` int NOT NULL DEFAULT 0 COMMENT '退款金额,包含赠送金额', + `refund_total_price` int NOT NULL DEFAULT 0 COMMENT '退款金额,包含赠送金额', `refund_pay_price` int NOT NULL DEFAULT 0 COMMENT '退款支付金额', - `refund_wallet_bonus` int NOT NULL DEFAULT 0 COMMENT '退款钱包赠送金额', + `refund_bonus_price` int NOT NULL DEFAULT 0 COMMENT '退款钱包赠送金额', `refund_time` datetime NULL COMMENT '退款时间', `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '创建者', `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/vo/recharge/AppPayWalletRechargeCreateReqVO.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/vo/recharge/AppPayWalletRechargeCreateReqVO.java index 45125e8c07..44af54c350 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/vo/recharge/AppPayWalletRechargeCreateReqVO.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/vo/recharge/AppPayWalletRechargeCreateReqVO.java @@ -4,6 +4,7 @@ import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import javax.validation.constraints.DecimalMin; +import javax.validation.constraints.Min; import javax.validation.constraints.NotNull; @Schema(description = "用户 APP - 创建钱包充值 Request VO") @@ -12,14 +13,14 @@ public class AppPayWalletRechargeCreateReqVO { @Schema(description = "支付金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000") @NotNull(message = "支付金额不能为空") - // TODO @jason999:是不是 @Min 哈? - @DecimalMin(value = "0", inclusive = false, message = "支付金额必须大于零") + @Min(value = 1, message = "支付金额必须大于零") private Integer payPrice; // TODO @jason:这个是不是后端计算出来呀?不然前端可以直接搞了。。。 + // TOTO 那是不是搞一个充值模板 @Schema(description = "钱包赠送金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000") @NotNull(message = "钱包赠送金额不能为空") @DecimalMin(value = "0", message = "钱包赠送金额必须大于等于零") - private Integer walletBonus; + private Integer bonusPrice; } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/convert/wallet/PayWalletRechargeConvert.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/convert/wallet/PayWalletRechargeConvert.java index 584144734a..4e53db3a63 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/convert/wallet/PayWalletRechargeConvert.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/convert/wallet/PayWalletRechargeConvert.java @@ -4,6 +4,7 @@ import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.recharge.AppPayWalle import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.recharge.AppPayWalletRechargeCreateRespVO; import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletRechargeDO; import org.mapstruct.Mapper; +import org.mapstruct.Mapping; import org.mapstruct.factory.Mappers; /** @@ -14,14 +15,8 @@ public interface PayWalletRechargeConvert { PayWalletRechargeConvert INSTANCE = Mappers.getMapper(PayWalletRechargeConvert.class); - PayWalletRechargeDO convert(AppPayWalletRechargeCreateReqVO vo); - - // TODO @jason:好像 price 相加,可以写个表达式的,通过 @Mapping - default PayWalletRechargeDO convert(Long walletId, AppPayWalletRechargeCreateReqVO vo) { - PayWalletRechargeDO walletRecharge = convert(vo); - return walletRecharge.setWalletId(walletId) - .setPrice(walletRecharge.getPayPrice() + walletRecharge.getWalletBonus()); - } + @Mapping(target = "totalPrice", expression = "java(vo.getPayPrice() + vo.getBonusPrice() )") + PayWalletRechargeDO convert(Long walletId, AppPayWalletRechargeCreateReqVO vo); AppPayWalletRechargeCreateRespVO convert(PayWalletRechargeDO bean); diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/dataobject/wallet/PayWalletRechargeDO.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/dataobject/wallet/PayWalletRechargeDO.java index 939b9b4a14..dc56e56140 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/dataobject/wallet/PayWalletRechargeDO.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/dataobject/wallet/PayWalletRechargeDO.java @@ -31,22 +31,21 @@ public class PayWalletRechargeDO extends BaseDO { */ private Long walletId; - // TODO @jason:要不改成 totalPrice? /** * 用户实际到账余额 * * 例如充 100 送 20,则该值是 120 */ - private Integer price; + private Integer totalPrice; /** * 实际支付金额 */ private Integer payPrice; - // TODO @jason:bonusPrice 哈,更统一一点; + /** * 钱包赠送金额 */ - private Integer walletBonus; + private Integer bonusPrice; /** * 是否已支付 @@ -62,6 +61,7 @@ public class PayWalletRechargeDO extends BaseDO { * 关联 {@link PayOrderDO#getId()} */ private Long payOrderId; + /** * 支付成功的支付渠道 * @@ -79,20 +79,21 @@ public class PayWalletRechargeDO extends BaseDO { * 关联 {@link PayRefundDO#getId()} */ private Long payRefundId; - // TODO @jason:要不改成 refundTotalPrice? + /** * 退款金额,包含赠送金额 */ - private Integer refundPrice; + private Integer refundTotalPrice; /** * 退款支付金额 */ private Integer refundPayPrice; - // TODO @jason:要不改成 refundBonusPrice? + /** * 退款钱包赠送金额 */ - private Integer refundWalletBonus; + private Integer refundBonusPrice; + /** * 退款时间 */ diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletMapper.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletMapper.java index 57f9250d6e..47c4c2009a 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletMapper.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletMapper.java @@ -14,15 +14,13 @@ public interface PayWalletMapper extends BaseMapperX { PayWalletDO::getUserType, userType); } - // TODO @jason:下面几个更新方法,把 id 放前面哈。一般来说,重要参数放前面; - /** * 当消费退款时候, 更新钱包 * - * @param price 消费金额 * @param id 钱包 id + * @param price 消费金额 */ - default int updateWhenConsumptionRefund(Integer price, Long id){ + default int updateWhenConsumptionRefund(Long id, Integer price){ LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() .setSql(" balance = balance + " + price + ", total_expense = total_expense - " + price) @@ -36,7 +34,7 @@ public interface PayWalletMapper extends BaseMapperX { * @param price 消费金额 * @param id 钱包 id */ - default int updateWhenConsumption(Integer price, Long id){ + default int updateWhenConsumption(Long id, Integer price){ LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() .setSql(" balance = balance - " + price + ", total_expense = total_expense + " + price) @@ -47,10 +45,11 @@ public interface PayWalletMapper extends BaseMapperX { /** * 当充值的时候,更新钱包 - * @param price 钱包金额 + * * @param id 钱包 id + * @param price 钱包金额 */ - default int updateWhenRecharge(Integer price, Long id){ + default int updateWhenRecharge(Long id, Integer price){ LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() .setSql(" balance = balance + " + price + ", total_recharge = total_recharge + " + price) diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletRechargeServiceImpl.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletRechargeServiceImpl.java index 771dfd3838..0259627c72 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletRechargeServiceImpl.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletRechargeServiceImpl.java @@ -66,8 +66,9 @@ public class PayWalletRechargeServiceImpl implements PayWalletRechargeService { // 2.2 更新钱包充值记录中支付订单 walletRechargeMapper.updateById(new PayWalletRechargeDO().setPayOrderId(payOrderId) .setId(walletRecharge.getId())); - // TODO @jason:是不是你直接返回就好啦;然后 payOrderId 设置下; - return walletRechargeMapper.selectById(walletRecharge.getId()); + + walletRecharge.setPayOrderId(payOrderId); + return walletRecharge; } @Override @@ -92,8 +93,9 @@ public class PayWalletRechargeServiceImpl implements PayWalletRechargeService { // 3. 更新钱包余额 // TODO @jason:这样的话,未来提现会不会把充值的,也提现走哈。类似先充 100,送 110;然后提现 110; + // TODO 需要钱包中加个可提现余额 payWalletService.addWalletBalance(walletRecharge.getWalletId(), String.valueOf(id), - PayWalletBizTypeEnum.RECHARGE, walletRecharge.getPrice()); + PayWalletBizTypeEnum.RECHARGE, walletRecharge.getTotalPrice()); } private PayOrderDO validateWalletRechargerCanPaid(PayWalletRechargeDO walletRecharge, Long payOrderId) { diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java index 346e8523e4..542e567edd 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java @@ -125,7 +125,7 @@ public class PayWalletServiceImpl implements PayWalletService { int updateCounts = 0 ; switch (bizType) { case PAYMENT: { - updateCounts = walletMapper.updateWhenConsumption(price, payWallet.getId()); + updateCounts = walletMapper.updateWhenConsumption(payWallet.getId(), price); break; } case RECHARGE_REFUND: { @@ -156,11 +156,11 @@ public class PayWalletServiceImpl implements PayWalletService { // 1.2 更新钱包金额 switch (bizType) { case PAYMENT_REFUND: { // 退款更新 - walletMapper.updateWhenConsumptionRefund(price, payWallet.getId()); + walletMapper.updateWhenConsumptionRefund(payWallet.getId(), price); break; } case RECHARGE: { // 充值更新 - walletMapper.updateWhenRecharge(price, payWallet.getId()); + walletMapper.updateWhenRecharge(payWallet.getId(), price); break; } // TODO 其它类型;这里可以先跑异常;避免有业务搞错;