Commit 7347c1c9d6addcf1ddd2abd97e1e4b721e79c835
1 parent
26237ee8
fix:【pay】pay_wallet 表,部分用户出现两条钱包记录问题,对应 https://gitee.com/zhijiantianya/ruoyi-vue-pro/pulls/1475
Showing
1 changed file
with
13 additions
and
4 deletions
yudao-module-pay/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java
| @@ -58,13 +58,22 @@ public class PayWalletServiceImpl implements PayWalletService { | @@ -58,13 +58,22 @@ public class PayWalletServiceImpl implements PayWalletService { | ||
| 58 | private PayRefundService refundService; | 58 | private PayRefundService refundService; |
| 59 | 59 | ||
| 60 | @Override | 60 | @Override |
| 61 | + @SneakyThrows | ||
| 61 | public PayWalletDO getOrCreateWallet(Long userId, Integer userType) { | 62 | public PayWalletDO getOrCreateWallet(Long userId, Integer userType) { |
| 62 | PayWalletDO wallet = walletMapper.selectByUserIdAndType(userId, userType); | 63 | PayWalletDO wallet = walletMapper.selectByUserIdAndType(userId, userType); |
| 63 | if (wallet == null) { | 64 | if (wallet == null) { |
| 64 | - wallet = new PayWalletDO().setUserId(userId).setUserType(userType) | ||
| 65 | - .setBalance(0).setTotalExpense(0).setTotalRecharge(0); | ||
| 66 | - wallet.setCreateTime(LocalDateTime.now()); | ||
| 67 | - walletMapper.insert(wallet); | 65 | + // 使用双重检查锁,保证钱包创建并发问题 |
| 66 | + // https://gitee.com/zhijiantianya/ruoyi-vue-pro/pulls/1475/files | ||
| 67 | + wallet = lockRedisDAO.lock(userId, UPDATE_TIMEOUT_MILLIS, () -> { | ||
| 68 | + PayWalletDO newWallet = walletMapper.selectByUserIdAndType(userId, userType); | ||
| 69 | + if (newWallet == null) { | ||
| 70 | + newWallet = new PayWalletDO().setUserId(userId).setUserType(userType) | ||
| 71 | + .setBalance(0).setTotalExpense(0).setTotalRecharge(0); | ||
| 72 | + newWallet.setCreateTime(LocalDateTime.now()); | ||
| 73 | + walletMapper.insert(newWallet); | ||
| 74 | + } | ||
| 75 | + return newWallet; | ||
| 76 | + }); | ||
| 68 | } | 77 | } |
| 69 | return wallet; | 78 | return wallet; |
| 70 | } | 79 | } |