| Line 1974... |
Line 1974... |
| 1974 |
}
|
1974 |
}
|
| 1975 |
}
|
1975 |
}
|
| 1976 |
|
1976 |
|
| 1977 |
private FofoOrder createAndGetFofoOrder(int customerId, String customerGstNumber, int fofoId, String
|
1977 |
private FofoOrder createAndGetFofoOrder(int customerId, String customerGstNumber, int fofoId, String
|
| 1978 |
documentNumber, float totalAmount, int customerAddressId, int poId) {
|
1978 |
documentNumber, float totalAmount, int customerAddressId, int poId) {
|
| - |
|
1979 |
// Idempotency: concurrent duplicate requests (double-click, upstream retries) used
|
| - |
|
1980 |
// to deadlock on idx_invoice_number. Fast path — if the row already exists for
|
| - |
|
1981 |
// this (fofo, invoice) return it instead of attempting a duplicate insert.
|
| - |
|
1982 |
FofoOrder existing = findExistingFofoOrder(fofoId, documentNumber);
|
| - |
|
1983 |
if (existing != null) return existing;
|
| - |
|
1984 |
|
| 1979 |
FofoOrder fofoOrder = new FofoOrder();
|
1985 |
FofoOrder fofoOrder = new FofoOrder();
|
| 1980 |
fofoOrder.setCustomerGstNumber(customerGstNumber);
|
1986 |
fofoOrder.setCustomerGstNumber(customerGstNumber);
|
| 1981 |
fofoOrder.setCustomerId(customerId);
|
1987 |
fofoOrder.setCustomerId(customerId);
|
| 1982 |
fofoOrder.setFofoId(fofoId);
|
1988 |
fofoOrder.setFofoId(fofoId);
|
| 1983 |
fofoOrder.setPendingOrderId(poId);
|
1989 |
fofoOrder.setPendingOrderId(poId);
|
| 1984 |
fofoOrder.setInvoiceNumber(documentNumber);
|
1990 |
fofoOrder.setInvoiceNumber(documentNumber);
|
| 1985 |
fofoOrder.setTotalAmount(totalAmount);
|
1991 |
fofoOrder.setTotalAmount(totalAmount);
|
| 1986 |
fofoOrder.setCustomerAddressId(customerAddressId);
|
1992 |
fofoOrder.setCustomerAddressId(customerAddressId);
|
| - |
|
1993 |
try {
|
| 1987 |
fofoOrderRepository.persist(fofoOrder);
|
1994 |
fofoOrderRepository.persist(fofoOrder);
|
| - |
|
1995 |
} catch (org.springframework.dao.DataIntegrityViolationException dup) {
|
| - |
|
1996 |
// Narrow race: another concurrent request won the insert after our select.
|
| - |
|
1997 |
// Re-fetch and return the winner's row. Requires the uk_fofo_order_fofo_invoice
|
| - |
|
1998 |
// unique key on fofo_order to surface the duplicate as this exception.
|
| - |
|
1999 |
FofoOrder winner = findExistingFofoOrder(fofoId, documentNumber);
|
| - |
|
2000 |
if (winner != null) return winner;
|
| - |
|
2001 |
throw dup;
|
| - |
|
2002 |
}
|
| 1988 |
return fofoOrder;
|
2003 |
return fofoOrder;
|
| 1989 |
}
|
2004 |
}
|
| 1990 |
|
2005 |
|
| - |
|
2006 |
private FofoOrder findExistingFofoOrder(int fofoId, String invoiceNumber) {
|
| - |
|
2007 |
try {
|
| - |
|
2008 |
return fofoOrderRepository.selectByFofoIdAndInvoiceNumber(fofoId, invoiceNumber);
|
| - |
|
2009 |
} catch (ProfitMandiBusinessException ignored) {
|
| - |
|
2010 |
return null;
|
| - |
|
2011 |
}
|
| - |
|
2012 |
}
|
| - |
|
2013 |
|
| 1991 |
private void validateItemsSerializedNonSerialized
|
2014 |
private void validateItemsSerializedNonSerialized
|
| 1992 |
(List<Item> items, Map<Integer, CustomFofoOrderItem> customFofoOrderItemMap) throws
|
2015 |
(List<Item> items, Map<Integer, CustomFofoOrderItem> customFofoOrderItemMap) throws
|
| 1993 |
ProfitMandiBusinessException {
|
2016 |
ProfitMandiBusinessException {
|
| 1994 |
List<Integer> invalidItemIdSerialNumbers = new ArrayList<Integer>();
|
2017 |
List<Integer> invalidItemIdSerialNumbers = new ArrayList<Integer>();
|
| 1995 |
List<Integer> itemIdNonSerializedSerialNumbers = new ArrayList<Integer>();
|
2018 |
List<Integer> itemIdNonSerializedSerialNumbers = new ArrayList<Integer>();
|