| Line 325... |
Line 325... |
| 325 |
Retailer retailer = (Retailer) map.get("retailer");
|
325 |
Retailer retailer = (Retailer) map.get("retailer");
|
| 326 |
retailer = this.updateRetailer(dtrUser, retailer, updateRetailerRequest);
|
326 |
retailer = this.updateRetailer(dtrUser, retailer, updateRetailerRequest);
|
| 327 |
|
327 |
|
| 328 |
map.put("retailer", retailer);
|
328 |
map.put("retailer", retailer);
|
| 329 |
|
329 |
|
| - |
|
330 |
// Ensure UserAccount links new dtr user to retailer (handles case where
|
| - |
|
331 |
// dtr.user was deleted and re-created with a new ID)
|
| - |
|
332 |
try {
|
| - |
|
333 |
userAccountRepository.selectSaholicByUserId(dtrUser.getId());
|
| - |
|
334 |
} catch (ProfitMandiBusinessException e) {
|
| - |
|
335 |
try {
|
| - |
|
336 |
UserAccount ua = new UserAccount();
|
| - |
|
337 |
ua.setAccountKey(retailer.getId());
|
| - |
|
338 |
ua.setUserId(dtrUser.getId());
|
| - |
|
339 |
ua.setType(AccountType.saholic);
|
| - |
|
340 |
userAccountRepository.persist(ua);
|
| - |
|
341 |
} catch (Exception ex) {
|
| - |
|
342 |
LOGGER.error("Error creating saholic UserAccount for userId: {}", dtrUser.getId(), ex);
|
| - |
|
343 |
}
|
| - |
|
344 |
}
|
| - |
|
345 |
|
| 330 |
List<String> retailerBlockBrands = retailerBlockBrandsRepository.selectAllByRetailer(retailer.getId()).stream().map(x -> x.getBlockBrands()).collect(Collectors.toList());
|
346 |
List<String> retailerBlockBrands = retailerBlockBrandsRepository.selectAllByRetailer(retailer.getId()).stream().map(x -> x.getBlockBrands()).collect(Collectors.toList());
|
| 331 |
|
347 |
|
| 332 |
LOGGER.info("retailerBlockBrands" + retailerBlockBrands);
|
348 |
LOGGER.info("retailerBlockBrands" + retailerBlockBrands);
|
| 333 |
|
349 |
|
| 334 |
if (!retailerBlockBrands.isEmpty()) {
|
350 |
if (!retailerBlockBrands.isEmpty()) {
|
| Line 639... |
Line 655... |
| 639 |
}
|
655 |
}
|
| 640 |
|
656 |
|
| 641 |
private Address updateRetailerAddress(Address address, CustomAddress customAddress, int retailerId) throws
|
657 |
private Address updateRetailerAddress(Address address, CustomAddress customAddress, int retailerId) throws
|
| 642 |
ProfitMandiBusinessException {
|
658 |
ProfitMandiBusinessException {
|
| 643 |
if (address == null) {
|
659 |
if (address == null) {
|
| - |
|
660 |
// Try to find existing address via RetailerRegisteredAddress (handles case where
|
| - |
|
661 |
// dtr.user was deleted but retailer/address still exist in database)
|
| 644 |
address = new Address();
|
662 |
try {
|
| - |
|
663 |
int existingAddressId = retailerRegisteredAddressRepository.selectAddressIdByRetailerId(retailerId);
|
| 645 |
address.setRetaierId(retailerId);
|
664 |
address = addressRepository.selectById(existingAddressId);
|
| 646 |
this.updateAddress(address, customAddress);
|
665 |
} catch (ProfitMandiBusinessException e) {
|
| 647 |
// addressRepository.persist(addressRetailer);
|
666 |
// No existing address found for this retailer
|
| - |
|
667 |
}
|
| 648 |
|
668 |
|
| - |
|
669 |
if (address != null) {
|
| - |
|
670 |
// Existing address found - update it
|
| - |
|
671 |
this.updateAddress(address, customAddress);
|
| - |
|
672 |
RetailerRegisteredAddress retailerRegisteredAddress = retailerRegisteredAddressRepository.selectByRetailerId(retailerId);
|
| - |
|
673 |
retailerRegisteredAddress.setAddressId(address.getId());
|
| - |
|
674 |
retailerRegisteredAddressRepository.persist(retailerRegisteredAddress);
|
| - |
|
675 |
} else {
|
| - |
|
676 |
// Truly new address
|
| - |
|
677 |
address = new Address();
|
| - |
|
678 |
address.setRetaierId(retailerId);
|
| - |
|
679 |
this.updateAddress(address, customAddress);
|
| - |
|
680 |
|
| 649 |
final RetailerRegisteredAddress retailerRegisteredAddress = new RetailerRegisteredAddress();
|
681 |
final RetailerRegisteredAddress retailerRegisteredAddress = new RetailerRegisteredAddress();
|
| 650 |
retailerRegisteredAddress.setRetailerId(retailerId);
|
682 |
retailerRegisteredAddress.setRetailerId(retailerId);
|
| 651 |
retailerRegisteredAddress.setAddressId(address.getId());
|
683 |
retailerRegisteredAddress.setAddressId(address.getId());
|
| 652 |
retailerRegisteredAddressRepository.persist(retailerRegisteredAddress);
|
684 |
retailerRegisteredAddressRepository.persist(retailerRegisteredAddress);
|
| - |
|
685 |
}
|
| 653 |
} else {
|
686 |
} else {
|
| 654 |
this.updateAddress(address, customAddress);
|
687 |
this.updateAddress(address, customAddress);
|
| 655 |
RetailerRegisteredAddress retailerRegisteredAddress = retailerRegisteredAddressRepository.selectByRetailerId(retailerId);
|
688 |
RetailerRegisteredAddress retailerRegisteredAddress = retailerRegisteredAddressRepository.selectByRetailerId(retailerId);
|
| 656 |
retailerRegisteredAddress.setAddressId(address.getId());
|
689 |
retailerRegisteredAddress.setAddressId(address.getId());
|
| 657 |
retailerRegisteredAddressRepository.persist(retailerRegisteredAddress);
|
690 |
retailerRegisteredAddressRepository.persist(retailerRegisteredAddress);
|
| Line 898... |
Line 931... |
| 898 |
fofoStore.setFofoType(updateRetailerRequest.getFofoType());
|
931 |
fofoStore.setFofoType(updateRetailerRequest.getFofoType());
|
| 899 |
fofoStore.setActivationType(ActivationType.ACTIVE);
|
932 |
fofoStore.setActivationType(ActivationType.ACTIVE);
|
| 900 |
fofoStore.setGstNumber(updateRetailerRequest.getGstNumber());
|
933 |
fofoStore.setGstNumber(updateRetailerRequest.getGstNumber());
|
| 901 |
fofoStoreRepository.persist(fofoStore);
|
934 |
fofoStoreRepository.persist(fofoStore);
|
| 902 |
|
935 |
|
| 903 |
// Auto fill in onboarding Panel
|
- |
|
| 904 |
PartnerOnBoardingPanel pobp = partnerOnBoardingPanelRepository.selectByPhoneNumber(Long.parseLong(retailerAddress.getPhoneNumber()));
|
- |
|
| 905 |
if (pobp != null) {
|
- |
|
| 906 |
|
- |
|
| 907 |
PartnerVerificationpanel partnerVerificationpanel = partnerOnboardingVerificationRepository.selectByOnboardingId(pobp.getId());
|
- |
|
| 908 |
|
- |
|
| 909 |
if (partnerVerificationpanel != null) {
|
- |
|
| 910 |
if (partnerVerificationpanel.getApproval().equals(PartnerVerificationApprovalStatus.YES)) {
|
- |
|
| 911 |
pobp.setCode(fofoStore.getCode());
|
- |
|
| 912 |
|
- |
|
| 913 |
storeTimelineTatService.onCodeCreated(pobp.getId());
|
- |
|
| 914 |
|
- |
|
| 915 |
}
|
- |
|
| 916 |
|
- |
|
| 917 |
}
|
- |
|
| 918 |
|
- |
|
| 919 |
}
|
- |
|
| 920 |
|
- |
|
| 921 |
PincodePartner pincodePartner = pincodePartnerRepository.selectPartnerByPincode(retailerAddress.getPinCode(), fofoStore.getId());
|
936 |
PincodePartner pincodePartner = pincodePartnerRepository.selectPartnerByPincode(retailerAddress.getPinCode(), fofoStore.getId());
|
| 922 |
if (pincodePartner == null) {
|
937 |
if (pincodePartner == null) {
|
| 923 |
PincodePartner pinPartner = new PincodePartner();
|
938 |
PincodePartner pinPartner = new PincodePartner();
|
| 924 |
pinPartner.setFofoId(fofoStore.getId());
|
939 |
pinPartner.setFofoId(fofoStore.getId());
|
| 925 |
pinPartner.setPincode(retailerAddress.getPinCode());
|
940 |
pinPartner.setPincode(retailerAddress.getPinCode());
|
| 926 |
pincodePartnerRepository.perist(pinPartner);
|
941 |
pincodePartnerRepository.perist(pinPartner);
|
| 927 |
}
|
942 |
}
|
| 928 |
}
|
943 |
}
|
| 929 |
|
944 |
|
| - |
|
945 |
// Link store code to onboarding panel and create STORE_CODE_CREATED timeline
|
| - |
|
946 |
// Runs for BOTH new and existing fofoStore to handle retry scenarios
|
| - |
|
947 |
if (fofoStore != null && fofoStore.getCode() != null && !fofoStore.getCode().isEmpty()) {
|
| - |
|
948 |
try {
|
| - |
|
949 |
int addressId = retailerRegisteredAddressRepository.selectAddressIdByRetailerId(retailerId);
|
| - |
|
950 |
Address addr = addressRepository.selectById(addressId);
|
| - |
|
951 |
PartnerOnBoardingPanel pobp = partnerOnBoardingPanelRepository.selectByPhoneNumber(Long.parseLong(addr.getPhoneNumber()));
|
| - |
|
952 |
if (pobp != null) {
|
| - |
|
953 |
PartnerVerificationpanel partnerVerificationpanel = partnerOnboardingVerificationRepository.selectByOnboardingId(pobp.getId());
|
| - |
|
954 |
if (partnerVerificationpanel != null
|
| - |
|
955 |
&& PartnerVerificationApprovalStatus.YES.equals(partnerVerificationpanel.getApproval())) {
|
| - |
|
956 |
pobp.setCode(fofoStore.getCode());
|
| - |
|
957 |
storeTimelineTatService.onCodeCreated(pobp.getId());
|
| - |
|
958 |
PartnerVerificationCheckboxes cb = partnerOnboardingVerificationRepository
|
| - |
|
959 |
.selectVerifiCheckboxByOnboardingId(pobp.getId());
|
| - |
|
960 |
if (cb == null) {
|
| - |
|
961 |
cb = new PartnerVerificationCheckboxes();
|
| - |
|
962 |
cb.setOnboardingId(pobp.getId());
|
| - |
|
963 |
partnerOnboardingVerificationRepository.persist(cb);
|
| - |
|
964 |
}
|
| - |
|
965 |
}
|
| - |
|
966 |
} else {
|
| - |
|
967 |
LOGGER.warn("No onboarding panel entry found for phone {}. Store code {} created for retailer {} " +
|
| - |
|
968 |
"but not linked to onboarding panel.",
|
| - |
|
969 |
addr.getPhoneNumber(), fofoStore.getCode(), retailerId);
|
| - |
|
970 |
}
|
| - |
|
971 |
} catch (Exception e) {
|
| - |
|
972 |
LOGGER.error("Failed to link store code to onboarding panel for retailerId: {}. " +
|
| - |
|
973 |
"Store code was created successfully but timeline/email may be incomplete.", retailerId, e);
|
| - |
|
974 |
}
|
| - |
|
975 |
}
|
| - |
|
976 |
|
| 930 |
if (fofoStore.isTrial()) {
|
977 |
if (fofoStore.isTrial()) {
|
| 931 |
|
978 |
|
| 932 |
storeTimelineTatService.sendTrialStoreCreationMail(fofoStore, updateRetailerRequest);
|
979 |
storeTimelineTatService.sendTrialStoreCreationMail(fofoStore, updateRetailerRequest);
|
| 933 |
storeTimelineTatService.sendTrialActivationMail(fofoStore, updateRetailerRequest);
|
980 |
storeTimelineTatService.sendTrialActivationMail(fofoStore, updateRetailerRequest);
|
| 934 |
|
981 |
|