From 7347c1c9d6addcf1ddd2abd97e1e4b721e79c835 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 13 Dec 2025 10:18:31 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E3=80=90pay=E3=80=91pay=5Fwallet?= =?UTF-8?q?=20=E8=A1=A8=EF=BC=8C=E9=83=A8=E5=88=86=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E5=87=BA=E7=8E=B0=E4=B8=A4=E6=9D=A1=E9=92=B1=E5=8C=85=E8=AE=B0?= =?UTF-8?q?=E5=BD=95=E9=97=AE=E9=A2=98=EF=BC=8C=E5=AF=B9=E5=BA=94=20https:?= =?UTF-8?q?//gitee.com/zhijiantianya/ruoyi-vue-pro/pulls/1475?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/wallet/PayWalletServiceImpl.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/yudao-module-pay/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java b/yudao-module-pay/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java index 0005acef63..58036eebc9 100644 --- a/yudao-module-pay/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java +++ b/yudao-module-pay/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java @@ -58,13 +58,22 @@ public class PayWalletServiceImpl implements PayWalletService { private PayRefundService refundService; @Override + @SneakyThrows public PayWalletDO getOrCreateWallet(Long userId, Integer userType) { PayWalletDO wallet = walletMapper.selectByUserIdAndType(userId, userType); if (wallet == null) { - wallet = new PayWalletDO().setUserId(userId).setUserType(userType) - .setBalance(0).setTotalExpense(0).setTotalRecharge(0); - wallet.setCreateTime(LocalDateTime.now()); - walletMapper.insert(wallet); + // 使用双重检查锁,保证钱包创建并发问题 + // https://gitee.com/zhijiantianya/ruoyi-vue-pro/pulls/1475/files + wallet = lockRedisDAO.lock(userId, UPDATE_TIMEOUT_MILLIS, () -> { + PayWalletDO newWallet = walletMapper.selectByUserIdAndType(userId, userType); + if (newWallet == null) { + newWallet = new PayWalletDO().setUserId(userId).setUserType(userType) + .setBalance(0).setTotalExpense(0).setTotalRecharge(0); + newWallet.setCreateTime(LocalDateTime.now()); + walletMapper.insert(newWallet); + } + return newWallet; + }); } return wallet; }