Subversion Repositories SmartDukaan

Rev

Rev 37168 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 37168 Rev 37648
Line 99... Line 99...
99
 
99
 
100
    @Autowired
100
    @Autowired
101
    private DocumentRepository documentRepository;
101
    private DocumentRepository documentRepository;
102
 
102
 
103
    @Autowired
103
    @Autowired
104
    private PrivateDealUserRepository privateDealUserRepository;
-
 
105
 
-
 
106
    @Autowired
-
 
107
    private RetailerContactRepository retailerContactRepository;
104
    private RetailerContactRepository retailerContactRepository;
108
 
105
 
109
    @Autowired
106
    @Autowired
110
    private PrivateDealUserAddressMappingRepository privateDealUserAddressMappingRepository;
-
 
111
 
-
 
112
    @Autowired
-
 
113
    private CounterRepository counterRepository;
-
 
114
 
-
 
115
    @Autowired
-
 
116
    private StateRepository stateRepository;
107
    private StateRepository stateRepository;
117
    @Autowired
108
    @Autowired
118
    private TrialFormRepository trialFormRepository;
109
    private TrialFormRepository trialFormRepository;
119
 
110
 
120
    @Autowired
111
    @Autowired
Line 407... Line 398...
407
            fofoStore.setActive(updateRetailerRequest.isActive());
398
            fofoStore.setActive(updateRetailerRequest.isActive());
408
            List<AST> astDetail = postOfficeService.getAreasAndTerritoriesByStateName(retailerAddress.getState());
399
            List<AST> astDetail = postOfficeService.getAreasAndTerritoriesByStateName(retailerAddress.getState());
409
            map.put("astDetail", astDetail);
400
            map.put("astDetail", astDetail);
410
        }
401
        }
411
 
402
 
412
        this.createPrivateDealUser(dtrUser, updateRetailerRequest.getGstNumber(), retailer, retailerAddress.getId());
-
 
413
        map.put("gstNumber", updateRetailerRequest.getGstNumber());
403
        map.put("gstNumber", updateRetailerRequest.getGstNumber());
414
        this.updateSaholicUser(retailer.getId(), retailerAddress.getId());
404
        this.updateSaholicUser(retailer.getId(), retailerAddress.getId());
415
 
405
 
416
        List<Shop> shops = (List<Shop>) map.get("shops");
406
        List<Shop> shops = (List<Shop>) map.get("shops");
417
        if (shops == null) {
407
        if (shops == null) {
Line 652... Line 642...
652
        } catch (ProfitMandiBusinessException e) {
642
        } catch (ProfitMandiBusinessException e) {
653
 
643
 
654
        }
644
        }
655
    }
645
    }
656
 
646
 
657
    private void createPrivateDealUser(User user, String gstNumber, Retailer retailer,
-
 
658
                                       int retailerAddressId) {
-
 
659
        PrivateDealUser privateDealUser = null;
-
 
660
        try {
-
 
661
            privateDealUser = privateDealUserRepository.selectById(retailer.getId());
-
 
662
        } catch (ProfitMandiBusinessException profitMandiBusinessException) {
-
 
663
            LOGGER.error("PrivateDealUser not found");
-
 
664
        }
-
 
665
 
-
 
666
        // = privateDealUserRepository.selectById(saholicUser.getId());
-
 
667
        if (privateDealUser == null) {
-
 
668
            Integer counterId = this.createCounter(user.getEmailId(), gstNumber, user.getMobileNumber(), retailer.getName(), retailerAddressId);
-
 
669
            try {
-
 
670
                this.createPrivateDealUser(retailer.getId(), counterId);
-
 
671
            } catch (Exception e) {
-
 
672
                LOGGER.error("ERROR : ", e);
-
 
673
            }
-
 
674
        } else {
-
 
675
            if (privateDealUser.getCounterId() == null) {
-
 
676
                Integer counterId = this.createCounter(user.getEmailId(), gstNumber, user.getMobileNumber(), retailer.getName(), retailerAddressId);
-
 
677
                privateDealUser.setCounterId(counterId);
-
 
678
                privateDealUserRepository.persist(privateDealUser);
-
 
679
            } else {
-
 
680
                Counter counter = null;
-
 
681
                try {
-
 
682
                    counter = counterRepository.selectById(privateDealUser.getCounterId());
-
 
683
                } catch (ProfitMandiBusinessException profitMandiBusinessException) {
-
 
684
                    LOGGER.error("Counter not found with id [{}]", privateDealUser.getCounterId());
-
 
685
                }
-
 
686
                if (counter == null) {
-
 
687
                    this.createCounter(user.getEmailId(), gstNumber, user.getMobileNumber(), retailer.getName(), retailerAddressId);
-
 
688
                } else {
-
 
689
                    counter.setGstin(gstNumber);
-
 
690
                    counterRepository.persist(counter);
-
 
691
                }
-
 
692
                privateDealUserRepository.persist(privateDealUser);
-
 
693
            }
-
 
694
        }
-
 
695
 
-
 
696
        PrivateDealUserAddressMapping privateDealUserAddressMapping = new PrivateDealUserAddressMapping();
-
 
697
        privateDealUserAddressMapping.setUserId(retailer.getId());
-
 
698
        privateDealUserAddressMapping.setAddressId(retailerAddressId);
-
 
699
        privateDealUserAddressMappingRepository.persist(privateDealUserAddressMapping);
-
 
700
    }
-
 
701
 
-
 
702
    private void createPrivateDealUser(int retailerId, int counterId) {
-
 
703
        PrivateDealUser privateDealUser = new PrivateDealUser();
-
 
704
        privateDealUser.setActive(true);
-
 
705
        privateDealUser.setId(retailerId);
-
 
706
        privateDealUser.setCounterId(counterId);
-
 
707
        privateDealUserRepository.persist(privateDealUser);
-
 
708
    }
-
 
709
 
-
 
710
    private Integer createCounter(String emailId, String gstNumber, String mobileNumber, String name, int addressId) {
-
 
711
        if (gstNumber != null && !gstNumber.isEmpty()) {
-
 
712
            Counter counter = new Counter();
-
 
713
            counter.setEmailId(emailId);
-
 
714
            counter.setGstin(gstNumber);
-
 
715
            counter.setMobileNumber(mobileNumber);
-
 
716
            counter.setName(name);
-
 
717
            counter.setAddressId(addressId);
-
 
718
            counterRepository.persist(counter);
-
 
719
            return counter.getId();
-
 
720
        } else {
-
 
721
            return null;
-
 
722
        }
-
 
723
    }
-
 
724
 
-
 
725
    private Address updateRetailerAddress(Address address, CustomAddress customAddress, int retailerId) throws
647
    private Address updateRetailerAddress(Address address, CustomAddress customAddress, int retailerId) throws
726
            ProfitMandiBusinessException {
648
            ProfitMandiBusinessException {
727
        if (address == null) {
649
        if (address == null) {
728
            // Try to find existing address via RetailerRegisteredAddress (handles case where
650
            // Try to find existing address via RetailerRegisteredAddress (handles case where
729
            // dtr.user was deleted but retailer/address still exist in database)
651
            // dtr.user was deleted but retailer/address still exist in database)
Line 1430... Line 1352...
1430
        com.spice.profitmandi.dao.entity.user.User saholicUser = this.createSaholicUser(loginRequestModel);
1352
        com.spice.profitmandi.dao.entity.user.User saholicUser = this.createSaholicUser(loginRequestModel);
1431
        loginRequestModel.setUserId(saholicUser.getId());
1353
        loginRequestModel.setUserId(saholicUser.getId());
1432
 
1354
 
1433
        this.createRetailerAddress(loginRequestModel);
1355
        this.createRetailerAddress(loginRequestModel);
1434
 
1356
 
1435
        this.createPrivateDealUser(loginRequestModel);
-
 
1436
        this.updateSaholicUser(saholicUser.getId(), loginRequestModel.getBusinessAddress().getId());
1357
        this.updateSaholicUser(saholicUser.getId(), loginRequestModel.getBusinessAddress().getId());
1437
 
1358
 
1438
        return loginRequestModel;
1359
        return loginRequestModel;
1439
 
1360
 
1440
    }
1361
    }
1441
 
1362
 
1442
    private void createPrivateDealUser(LoginRequestResponseModel loginRequestModel) {
-
 
1443
 
-
 
1444
        Integer counterId = this.createCounter(loginRequestModel.getEmail(), loginRequestModel.getGstNumber(), loginRequestModel.getBusinessAddress().getPhoneNumber(), loginRequestModel.getBusinessAddress().getName(), loginRequestModel.getBusinessAddress().getId());
-
 
1445
        try {
-
 
1446
            this.createPrivateDealUser(loginRequestModel.getUserId(), counterId);
-
 
1447
        } catch (Exception e) {
-
 
1448
            LOGGER.error("ERROR : ", e);
-
 
1449
        }
-
 
1450
 
-
 
1451
        PrivateDealUserAddressMapping privateDealUserAddressMapping = new PrivateDealUserAddressMapping();
-
 
1452
        privateDealUserAddressMapping.setUserId(loginRequestModel.getUserId());
-
 
1453
        privateDealUserAddressMapping.setAddressId(loginRequestModel.getBusinessAddress().getId());
-
 
1454
        privateDealUserAddressMappingRepository.persist(privateDealUserAddressMapping);
-
 
1455
 
-
 
1456
    }
-
 
1457
 
-
 
1458
    private void createRetailerAddress(LoginRequestResponseModel loginRequestResponseModel) throws
1363
    private void createRetailerAddress(LoginRequestResponseModel loginRequestResponseModel) throws
1459
            ProfitMandiBusinessException {
1364
            ProfitMandiBusinessException {
1460
        Address businessAddress = loginRequestResponseModel.getBusinessAddress();
1365
        Address businessAddress = loginRequestResponseModel.getBusinessAddress();
1461
        businessAddress.setRetaierId(loginRequestResponseModel.getUserId());
1366
        businessAddress.setRetaierId(loginRequestResponseModel.getUserId());
1462
        addressRepository.persist(businessAddress);
1367
        addressRepository.persist(businessAddress);