adjust logic, avoide race condition
Some checks failed
Build and Push Backend / docker (push) Failing after 6s

This commit is contained in:
irving
2025-10-18 20:56:55 -04:00
parent 584780a812
commit 385ceeecb6

View File

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