mirror of
https://gitee.com/zhijiantianya/ruoyi-vue-pro.git
synced 2026-03-22 05:07:17 +08:00
fix:【pay】pay_wallet 表,部分用户出现两条钱包记录问题,对应 https://gitee.com/zhijiantianya/ruoyi-vue-pro/pulls/1475
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user