adjust logic, avoide race condition

This commit is contained in:
irving
2025-10-18 20:56:55 -04:00
parent b9779e7436
commit d681635394

View File

@@ -57,13 +57,12 @@ public class WithdrawalServiceImpl extends ServiceImpl<WithdrawalRequestMapper,
throw new CustomException("收款码确认已过期,请重新确认");
}
BigDecimal available = earningsService.getAvailableAmount(clerkId, now);
if (available.compareTo(amount) < 0) {
throw new CustomException("可提现余额不足");
}
// pick and reserve lines
List<EarningsLineEntity> lines = earningsService.findWithdrawable(clerkId, amount, now);
if (lines.isEmpty()) throw new CustomException("可提现余额不足");
if (lines.isEmpty()) {
BigDecimal latestAvailable = earningsService.getAvailableAmount(clerkId, now);
throw new CustomException("可提现余额不足或已被锁定,当前可用:" + latestAvailable);
}
// Reserve lines FIRST with temp ID (fail fast before creating request)
String tempWithdrawalId = "TEMP_" + IdUtils.getUuid();