update 修复部分修改金额的方法内未使用乐观锁

This commit is contained in:
yyb
2026-01-26 11:28:39 +08:00
parent 26e784e2d5
commit 8388ccb0c3
2 changed files with 16 additions and 2 deletions

View File

@@ -355,10 +355,17 @@ public class MessageReceiver {
.status(payWithdrawReturnMessage.getStatus()) .status(payWithdrawReturnMessage.getStatus())
.build(); .build();
if (payWithdrawReturnMessage.getStatus() == 1){ if (payWithdrawReturnMessage.getStatus() == 1){
// 使用乐观锁防止并发修改
BigDecimal initBalance = leaseShopConfig.getBalance();
leaseShopConfig.setBalance(leaseShopConfig.getBalance() leaseShopConfig.setBalance(leaseShopConfig.getBalance()
.subtract(payWithdrawReturnMessage.getAmount()) .subtract(payWithdrawReturnMessage.getAmount())
.subtract(payWithdrawReturnMessage.getFee())); .subtract(payWithdrawReturnMessage.getFee()));
leaseShopConfigMapper.updateById(leaseShopConfig); int update = leaseShopConfigMapper.update(leaseShopConfig, new LambdaUpdateWrapper<LeaseShopConfig>()
.eq(LeaseShopConfig::getId, leaseShopConfig.getId())
.eq(LeaseShopConfig::getBalance, initBalance));
if (update < 1){
throw new PayRechargeException("商家提现失败,余额已被修改,消息重试");
}
build.setTxHash(payWithdrawReturnMessage.getTx_hash()); build.setTxHash(payWithdrawReturnMessage.getTx_hash());
build.setBlockHeight(payWithdrawReturnMessage.getBlock_height()); build.setBlockHeight(payWithdrawReturnMessage.getBlock_height());
} }

View File

@@ -292,8 +292,15 @@ public class LeaseOrderInfoServiceImpl extends ServiceImpl<LeaseOrderInfoMapper,
.stripTrailingZeros(); .stripTrailingZeros();
throw new OrderException("下单失败,买家"+chainAndCoinKey+"钱包余额不足,缺少" + lackAmount + "满足支付需求"); throw new OrderException("下单失败,买家"+chainAndCoinKey+"钱包余额不足,缺少" + lackAmount + "满足支付需求");
} }
// 使用乐观锁防止并发修改
BigDecimal initBlockedBalance = leaseUserWalletData.getBlockedBalance();
leaseUserWalletData.setBlockedBalance(leaseUserWalletData.getBlockedBalance().add(totalAmount).add(totalFee)); leaseUserWalletData.setBlockedBalance(leaseUserWalletData.getBlockedBalance().add(totalAmount).add(totalFee));
leaseUserWalletDataMapper.updateById(leaseUserWalletData); int update = leaseUserWalletDataMapper.update(leaseUserWalletData, new LambdaUpdateWrapper<LeaseUserWalletData>()
.eq(LeaseUserWalletData::getId, leaseUserWalletData.getId())
.eq(LeaseUserWalletData::getBlockedBalance, initBlockedBalance));
if (update < 1){
throw new OrderException("下单失败,钱包余额已被修改,请重试");
}
}); });
} }