| Line 483... |
Line 483... |
| 483 |
}
|
483 |
}
|
| 484 |
}
|
484 |
}
|
| 485 |
}
|
485 |
}
|
| 486 |
|
486 |
|
| 487 |
private FofoOrder createAndGetFofoOrder(int customerId, String customerGstNumber, int fofoId, String documentNumber, float totalAmount, int customerAddressId) {
|
487 |
private FofoOrder createAndGetFofoOrder(int customerId, String customerGstNumber, int fofoId, String documentNumber, float totalAmount, int customerAddressId) {
|
| - |
|
488 |
// Idempotency: fast-path return if the row already exists for this (fofo, invoice).
|
| - |
|
489 |
// Protects against concurrent duplicate inserts (client retry / upstream webhook retry).
|
| - |
|
490 |
FofoOrder existing = findExistingFofoOrder(fofoId, documentNumber);
|
| - |
|
491 |
if (existing != null) return existing;
|
| - |
|
492 |
|
| 488 |
FofoOrder fofoOrder = new FofoOrder();
|
493 |
FofoOrder fofoOrder = new FofoOrder();
|
| 489 |
fofoOrder.setCustomerGstNumber(customerGstNumber);
|
494 |
fofoOrder.setCustomerGstNumber(customerGstNumber);
|
| 490 |
fofoOrder.setCustomerId(customerId);
|
495 |
fofoOrder.setCustomerId(customerId);
|
| 491 |
fofoOrder.setFofoId(fofoId);
|
496 |
fofoOrder.setFofoId(fofoId);
|
| 492 |
fofoOrder.setInvoiceNumber(documentNumber);
|
497 |
fofoOrder.setInvoiceNumber(documentNumber);
|
| 493 |
fofoOrder.setTotalAmount(totalAmount);
|
498 |
fofoOrder.setTotalAmount(totalAmount);
|
| 494 |
fofoOrder.setCustomerAddressId(customerAddressId);
|
499 |
fofoOrder.setCustomerAddressId(customerAddressId);
|
| - |
|
500 |
try {
|
| 495 |
fofoOrderRepository.persist(fofoOrder);
|
501 |
fofoOrderRepository.persist(fofoOrder);
|
| - |
|
502 |
} catch (org.springframework.dao.DataIntegrityViolationException dup) {
|
| - |
|
503 |
// Lost a narrow race between our select and insert — re-fetch the winner's row.
|
| - |
|
504 |
// Requires uk_fofo_order_fofo_invoice unique key to trigger this exception.
|
| - |
|
505 |
FofoOrder winner = findExistingFofoOrder(fofoId, documentNumber);
|
| - |
|
506 |
if (winner != null) return winner;
|
| - |
|
507 |
throw dup;
|
| - |
|
508 |
}
|
| 496 |
return fofoOrder;
|
509 |
return fofoOrder;
|
| 497 |
}
|
510 |
}
|
| 498 |
|
511 |
|
| - |
|
512 |
private FofoOrder findExistingFofoOrder(int fofoId, String invoiceNumber) {
|
| - |
|
513 |
try {
|
| - |
|
514 |
return fofoOrderRepository.selectByFofoIdAndInvoiceNumber(fofoId, invoiceNumber);
|
| - |
|
515 |
} catch (ProfitMandiBusinessException ignored) {
|
| - |
|
516 |
return null;
|
| - |
|
517 |
}
|
| - |
|
518 |
}
|
| - |
|
519 |
|
| 499 |
@RequestMapping(value = "/customer/addaddress", method = RequestMethod.POST)
|
520 |
@RequestMapping(value = "/customer/addaddress", method = RequestMethod.POST)
|
| 500 |
public ResponseEntity<?> addAddress(HttpServletRequest request, @RequestParam int customerId,
|
521 |
public ResponseEntity<?> addAddress(HttpServletRequest request, @RequestParam int customerId,
|
| 501 |
@RequestBody CustomAddress customAddress) {
|
522 |
@RequestBody CustomAddress customAddress) {
|
| 502 |
CustomerAddress customerAddress = this.toCustomerAddress(customerId, customAddress);
|
523 |
CustomerAddress customerAddress = this.toCustomerAddress(customerId, customAddress);
|
| 503 |
customerAddressRepository.persist(customerAddress);
|
524 |
customerAddressRepository.persist(customerAddress);
|