| Line 1315... |
Line 1315... |
| 1315 |
|
1315 |
|
| 1316 |
}
|
1316 |
}
|
| 1317 |
}
|
1317 |
}
|
| 1318 |
|
1318 |
|
| 1319 |
private void fixStuckLimitBlocks(int maxFixes) {
|
1319 |
private void fixStuckLimitBlocks(int maxFixes) {
|
| 1320 |
LocalDate fromDate = LocalDate.of(2026, 4, 27);
|
1320 |
int[] stuckIds = {100908, 100909, 102018, 104843, 105119, 105613, 105758, 105766, 105999};
|
| 1321 |
LocalDate toDate = LocalDate.of(2026, 4, 29);
|
- |
|
| 1322 |
|
1321 |
|
| 1323 |
List<Loan> allBlockedLoans = loanRepository.selectAllBlockedLoans();
|
1322 |
List<Loan> stuckLoans = new ArrayList<>();
|
| 1324 |
List<Loan> stuckLoans = allBlockedLoans.stream()
|
1323 |
for (int id : stuckIds) {
|
| 1325 |
.filter(l -> {
|
1324 |
Loan loan = loanRepository.selectByLoanId(id);
|
| 1326 |
LocalDate created = l.getCreatedOn().toLocalDate();
|
1325 |
if (loan != null && loan.isLimitBlock() && loan.getSettledOn() == null && loan.getPendingAmount().doubleValue() > 0) {
|
| 1327 |
return !created.isBefore(fromDate) && !created.isAfter(toDate);
|
1326 |
stuckLoans.add(loan);
|
| 1328 |
})
|
1327 |
}
|
| 1329 |
.collect(toList());
|
1328 |
}
|
| 1330 |
|
1329 |
|
| 1331 |
System.out.println("Found " + stuckLoans.size() + " stuck limit blocks between " + fromDate + " and " + toDate);
|
1330 |
System.out.println("Found " + stuckLoans.size() + " stuck limit blocks to fix");
|
| 1332 |
System.out.println("Max fixes this run: " + maxFixes);
|
1331 |
System.out.println("Max fixes this run: " + maxFixes);
|
| 1333 |
|
1332 |
|
| 1334 |
int fixed = 0, skipped = 0, failed = 0;
|
1333 |
int fixed = 0, skipped = 0, failed = 0;
|
| 1335 |
for (Loan blockedLoan : stuckLoans) {
|
1334 |
for (Loan blockedLoan : stuckLoans) {
|
| 1336 |
if (fixed >= maxFixes) {
|
1335 |
if (fixed >= maxFixes) {
|
| Line 1348... |
Line 1347... |
| 1348 |
int transactionId = loanTransaction.getTransactionId();
|
1347 |
int transactionId = loanTransaction.getTransactionId();
|
| 1349 |
List<Order> billedOrders = orderRepository.selectAllByTransactionId(transactionId).stream()
|
1348 |
List<Order> billedOrders = orderRepository.selectAllByTransactionId(transactionId).stream()
|
| 1350 |
.filter(o -> o.getBillingTimestamp() != null && o.getRefundTimestamp() == null)
|
1349 |
.filter(o -> o.getBillingTimestamp() != null && o.getRefundTimestamp() == null)
|
| 1351 |
.collect(toList());
|
1350 |
.collect(toList());
|
| 1352 |
|
1351 |
|
| 1353 |
if (billedOrders.isEmpty()) {
|
- |
|
| 1354 |
System.out.println("SKIP loan " + blockedLoan.getId() + " txn " + transactionId + " - no billed orders");
|
- |
|
| 1355 |
skipped++;
|
- |
|
| 1356 |
continue;
|
- |
|
| 1357 |
}
|
- |
|
| 1358 |
|
- |
|
| 1359 |
Map<String, List<Order>> byInvoice = billedOrders.stream()
|
1352 |
Map<String, List<Order>> byInvoice = billedOrders.stream()
|
| 1360 |
.filter(o -> o.getInvoiceNumber() != null)
|
1353 |
.filter(o -> o.getInvoiceNumber() != null)
|
| 1361 |
.collect(Collectors.groupingBy(Order::getInvoiceNumber));
|
1354 |
.collect(Collectors.groupingBy(Order::getInvoiceNumber));
|
| 1362 |
|
1355 |
|
| 1363 |
for (Map.Entry<String, List<Order>> entry : byInvoice.entrySet()) {
|
1356 |
for (Map.Entry<String, List<Order>> entry : byInvoice.entrySet()) {
|
| Line 1372... |
Line 1365... |
| 1372 |
|
1365 |
|
| 1373 |
System.out.println("FIX loan " + blockedLoan.getId() + " fofo " + blockedLoan.getFofoId() + " txn " + transactionId + " invoice " + invoiceNumber + " invoiceAmt " + invoiceAmount + " pending " + blockedLoan.getPendingAmount());
|
1366 |
System.out.println("FIX loan " + blockedLoan.getId() + " fofo " + blockedLoan.getFofoId() + " txn " + transactionId + " invoice " + invoiceNumber + " invoiceAmt " + invoiceAmount + " pending " + blockedLoan.getPendingAmount());
|
| 1374 |
sdCreditService.createLoanForBilling(transactionId, invoiceAmount, invoiceNumber);
|
1367 |
sdCreditService.createLoanForBilling(transactionId, invoiceAmount, invoiceNumber);
|
| 1375 |
fixed++;
|
1368 |
fixed++;
|
| 1376 |
}
|
1369 |
}
|
| - |
|
1370 |
|
| - |
|
1371 |
blockedLoan = loanRepository.selectByLoanId(blockedLoan.getId());
|
| - |
|
1372 |
if (blockedLoan.getPendingAmount().doubleValue() > 0) {
|
| - |
|
1373 |
System.out.println("RELEASE remaining limit " + blockedLoan.getId() + " fofo " + blockedLoan.getFofoId() + " pending " + blockedLoan.getPendingAmount());
|
| - |
|
1374 |
sdCreditService.releaseBlockedLimit(blockedLoan, blockedLoan.getPendingAmount().doubleValue());
|
| - |
|
1375 |
fixed++;
|
| - |
|
1376 |
}
|
| 1377 |
} catch (Exception e) {
|
1377 |
} catch (Exception e) {
|
| 1378 |
System.out.println("FAIL loan " + blockedLoan.getId() + " fofo " + blockedLoan.getFofoId() + " - " + e.getMessage());
|
1378 |
System.out.println("FAIL loan " + blockedLoan.getId() + " fofo " + blockedLoan.getFofoId() + " - " + e.getMessage());
|
| 1379 |
e.printStackTrace();
|
1379 |
e.printStackTrace();
|
| 1380 |
failed++;
|
1380 |
failed++;
|
| 1381 |
}
|
1381 |
}
|