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

@@ -292,8 +292,15 @@ public class LeaseOrderInfoServiceImpl extends ServiceImpl<LeaseOrderInfoMapper,
.stripTrailingZeros();
throw new OrderException("下单失败,买家"+chainAndCoinKey+"钱包余额不足,缺少" + lackAmount + "满足支付需求");
}
// 使用乐观锁防止并发修改
BigDecimal initBlockedBalance = leaseUserWalletData.getBlockedBalance();
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("下单失败,钱包余额已被修改,请重试");
}
});
}