Commit 7347c1c9d6addcf1ddd2abd97e1e4b721e79c835

Authored by YunaiV
1 parent 26237ee8

fix:【pay】pay_wallet 表,部分用户出现两条钱包记录问题,对应 https://gitee.com/zhijiantianya/ruoyi-vue-pro/pulls/1475

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 58 private PayRefundService refundService;
59 59  
60 60 @Override
  61 + @SneakyThrows
61 62 public PayWalletDO getOrCreateWallet(Long userId, Integer userType) {
62 63 PayWalletDO wallet = walletMapper.selectByUserIdAndType(userId, userType);
63 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 78 return wallet;
70 79 }
... ...