Subversion Repositories SmartDukaan

Rev

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

Rev 33124 Rev 33128
Line 184... Line 184...
184
                    LOGGER.info("fofoId" + fofoId);
184
                    LOGGER.info("fofoId" + fofoId);
185
                    brands = mongoClient.getMongoBrands(fofoId, null, 3).stream().map(x -> (String) x.get("name")).collect(Collectors.toSet());
185
                    brands = mongoClient.getMongoBrands(fofoId, null, 3).stream().map(x -> (String) x.get("name")).collect(Collectors.toSet());
186
                }
186
                }
187
                map.put("brands", brands);
187
                map.put("brands", brands);
188
                map.put("retailerBlockBrands", retailerBlockBrands);
188
                map.put("retailerBlockBrands", retailerBlockBrands);
189
                if (this.containsRoleType(userRoles, role.getId())) {
-
 
190
                    try {
-
 
191
                        FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(retailerId);
-
 
192
                        map.put("fofoStore", fofoStore);
-
 
193
                        // map.put("counterSize", fofoStore.getCounterSize().toString());
-
 
194
                        // LOGGER.info("fofoStore" + fofoStore);
-
 
195
                    } catch (ProfitMandiBusinessException profitMandiBusinessException) {
-
 
196
                        LOGGER.error("FofoStore code not found");
-
 
197
                    }
-
 
198
                }
-
 
199
 
-
 
200
                if (this.containsRoleType(userRoles, role.getId())) {
-
 
201
                    try {
-
 
202
                        FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(retailerId);
-
 
203
                        AST ast = aSTRepository.selectById(fofoStore.getAstId()).get(0);
-
 
204
                        Map<String, Object> astDetail = postOfficeService.getAreasAndTerritoriesByAstId(ast.getId());
-
 
205
                        LOGGER.info("astDetail {}", astDetail);
-
 
206
                        map.put("astDetail", astDetail);
-
 
207
                    } catch (ProfitMandiBusinessException profitMandiBusinessException) {
-
 
208
                        LOGGER.error("AST Detail not found");
-
 
209
                    }
-
 
210
                }
-
 
211
 
189
 
212
                try {
190
                try {
213
                    PrivateDealUser privateDealUser = privateDealUserRepository.selectById(retailer.getId());
191
                    PrivateDealUser privateDealUser = privateDealUserRepository.selectById(retailer.getId());
214
                    if (privateDealUser.getCounterId() != null) {
192
                    if (privateDealUser.getCounterId() != null) {
215
                        Counter counter = counterRepository.selectById(privateDealUser.getCounterId());
193
                        Counter counter = counterRepository.selectById(privateDealUser.getCounterId());
Line 229... Line 207...
229
                    map.put("districtMasters", districtMasters);
207
                    map.put("districtMasters", districtMasters);
230
                    // LOGGER.info("districtMasters" + districtMasters);
208
                    // LOGGER.info("districtMasters" + districtMasters);
231
                    List<Shop> shops = shopRepository.selectByRetailerId(retailer.getId());
209
                    List<Shop> shops = shopRepository.selectByRetailerId(retailer.getId());
232
                    map.put("shops", shops);
210
                    map.put("shops", shops);
233
                    this.addAddress(shops);
211
                    this.addAddress(shops);
-
 
212
 
-
 
213
                    if (this.containsRoleType(userRoles, role.getId())) {
-
 
214
                        try {
-
 
215
                            FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(retailerId);
-
 
216
                            map.put("fofoStore", fofoStore);
-
 
217
                            List<AST> astDetail = postOfficeService.getAreasAndTerritoriesByStateName(retailerAddress.getState());
-
 
218
                            LOGGER.info("astDetail {}", astDetail);
-
 
219
                            map.put("astDetail", astDetail);
-
 
220
 
-
 
221
 
-
 
222
                            // map.put("counterSize", fofoStore.getCounterSize().toString());
-
 
223
                            // LOGGER.info("fofoStore" + fofoStore);
-
 
224
                        } catch (ProfitMandiBusinessException profitMandiBusinessException) {
-
 
225
                            LOGGER.error("FofoStore code not found");
-
 
226
                        }
-
 
227
                    }
234
                    // LOGGER.info("shops" + shops);
228
                    // LOGGER.info("shops" + shops);
235
                } catch (ProfitMandiBusinessException profitMandiBusinessException) {
229
                } catch (ProfitMandiBusinessException profitMandiBusinessException) {
236
                    LOGGER.error("Retailer Registered Address not found");
230
                    LOGGER.error("Retailer Registered Address not found");
237
                }
231
                }
238
            } catch (ProfitMandiBusinessException profitMandiBusinessException) {
232
            } catch (ProfitMandiBusinessException profitMandiBusinessException) {
Line 285... Line 279...
285
 
279
 
286
    }
280
    }
287
 
281
 
288
    @SuppressWarnings("unchecked")
282
    @SuppressWarnings("unchecked")
289
    @Override
283
    @Override
290
    public Map<String, Object> updateRetailerDetails(UpdateRetailerRequest updateRetailerRequest) throws ProfitMandiBusinessException {
284
    public Map<String, Object> updateRetailerDetails(UpdateRetailerRequest updateRetailerRequest) throws
-
 
285
            ProfitMandiBusinessException {
291
        Map<String, Object> map = this.getByEmailIdOrMobileNumber(updateRetailerRequest.getEmailIdOrMobileNumber());
286
        Map<String, Object> map = this.getByEmailIdOrMobileNumber(updateRetailerRequest.getEmailIdOrMobileNumber());
292
        User dtrUser = (User) map.get("user");
287
        User dtrUser = (User) map.get("user");
293
 
288
 
294
        dtrUser = this.createUser(dtrUser, updateRetailerRequest);
289
        dtrUser = this.createUser(dtrUser, updateRetailerRequest);
295
 
290
 
Line 382... Line 377...
382
            fofoPartnerPaymentOptionRepository.persist(fofoPartnerPaymentOption);
377
            fofoPartnerPaymentOptionRepository.persist(fofoPartnerPaymentOption);
383
        }
378
        }
384
 
379
 
385
    }
380
    }
386
 
381
 
387
    private User createUser(User user, UpdateRetailerRequest updateRetailerRequest) throws ProfitMandiBusinessException {
382
    private User createUser(User user, UpdateRetailerRequest updateRetailerRequest) throws
-
 
383
            ProfitMandiBusinessException {
388
 
384
 
389
        User dtrUser = null;
385
        User dtrUser = null;
390
        try {
386
        try {
391
            dtrUser = userRepository.selectByMobileNumber(updateRetailerRequest.getUserMobileNumber());
387
            dtrUser = userRepository.selectByMobileNumber(updateRetailerRequest.getUserMobileNumber());
392
        } catch (ProfitMandiBusinessException e) {
388
        } catch (ProfitMandiBusinessException e) {
Line 487... Line 483...
487
            userUserRepository.persist(saholicUser);
483
            userUserRepository.persist(saholicUser);
488
        }
484
        }
489
        return saholicUser;
485
        return saholicUser;
490
    }
486
    }
491
 
487
 
492
    private Retailer updateRetailer(User user, Retailer retailer, UpdateRetailerRequest updateRetailerRequest) throws ProfitMandiBusinessException {
488
    private Retailer updateRetailer(User user, Retailer retailer, UpdateRetailerRequest updateRetailerRequest) throws
-
 
489
            ProfitMandiBusinessException {
493
        if (retailer == null) {
490
        if (retailer == null) {
494
            LOGGER.info("createSaholicUser.....");
491
            LOGGER.info("createSaholicUser.....");
495
            int saholicUserId = this.createSaholicUser(user, updateRetailerRequest.getName());
492
            int saholicUserId = this.createSaholicUser(user, updateRetailerRequest.getName());
496
            retailer = new Retailer();
493
            retailer = new Retailer();
497
            retailer.setId(saholicUserId);
494
            retailer.setId(saholicUserId);
Line 530... Line 527...
530
        } catch (ProfitMandiBusinessException e) {
527
        } catch (ProfitMandiBusinessException e) {
531
 
528
 
532
        }
529
        }
533
    }
530
    }
534
 
531
 
535
    private void createPrivateDealUser(User user, boolean fofo, String gstNumber, Retailer retailer, int retailerAddressId) {
532
    private void createPrivateDealUser(User user, boolean fofo, String gstNumber, Retailer retailer,
-
 
533
                                       int retailerAddressId) {
536
        PrivateDealUser privateDealUser = null;
534
        PrivateDealUser privateDealUser = null;
537
        try {
535
        try {
538
            privateDealUser = privateDealUserRepository.selectById(retailer.getId());
536
            privateDealUser = privateDealUserRepository.selectById(retailer.getId());
539
        } catch (ProfitMandiBusinessException profitMandiBusinessException) {
537
        } catch (ProfitMandiBusinessException profitMandiBusinessException) {
540
            LOGGER.error("PrivateDealUser not found");
538
            LOGGER.error("PrivateDealUser not found");
Line 602... Line 600...
602
        } else {
600
        } else {
603
            return null;
601
            return null;
604
        }
602
        }
605
    }
603
    }
606
 
604
 
607
    private Address updateRetailerAddress(Address address, CustomAddress customAddress, int retailerId) throws ProfitMandiBusinessException {
605
    private Address updateRetailerAddress(Address address, CustomAddress customAddress, int retailerId) throws
-
 
606
            ProfitMandiBusinessException {
608
        if (address == null) {
607
        if (address == null) {
609
            address = new Address();
608
            address = new Address();
610
            address.setRetaierId(retailerId);
609
            address.setRetaierId(retailerId);
611
            this.updateAddress(address, customAddress);
610
            this.updateAddress(address, customAddress);
612
            // addressRepository.persist(addressRetailer);
611
            // addressRepository.persist(addressRetailer);
Line 638... Line 637...
638
        address.setState(state.getName());
637
        address.setState(state.getName());
639
        addressRepository.persist(address);
638
        addressRepository.persist(address);
640
        LOGGER.info("Address Updated" + address);
639
        LOGGER.info("Address Updated" + address);
641
    }
640
    }
642
 
641
 
643
    private void updateRetailerShops(List<Shop> shops, Set<CustomShop> customShops, int retailerId, Address sameAsRetailerAddressValue) throws ProfitMandiBusinessException {
642
    private void updateRetailerShops(List<Shop> shops, Set<CustomShop> customShops, int retailerId, Address
-
 
643
            sameAsRetailerAddressValue) throws ProfitMandiBusinessException {
644
        if (shops.isEmpty()) {
644
        if (shops.isEmpty()) {
645
            for (CustomShop customShop : customShops) {
645
            for (CustomShop customShop : customShops) {
646
                Shop shop = new Shop();
646
                Shop shop = new Shop();
647
                this.createOrUpdateShop(shop, customShop, retailerId, sameAsRetailerAddressValue);
647
                this.createOrUpdateShop(shop, customShop, retailerId, sameAsRetailerAddressValue);
648
                shops.add(shop);
648
                shops.add(shop);
Line 663... Line 663...
663
                }
663
                }
664
            }
664
            }
665
        }
665
        }
666
    }
666
    }
667
 
667
 
668
    private void createOrUpdateShop(Shop shop, CustomShop customShop, int retailerId, Address sameAsRetailerAddressValue) throws ProfitMandiBusinessException {
668
    private void createOrUpdateShop(Shop shop, CustomShop customShop, int retailerId, Address
-
 
669
            sameAsRetailerAddressValue) throws ProfitMandiBusinessException {
669
        shop.setRetailerId(retailerId);
670
        shop.setRetailerId(retailerId);
670
        shop.setName(customShop.getName());
671
        shop.setName(customShop.getName());
671
        if (customShop.getDocumentId() > 0) {
672
        if (customShop.getDocumentId() > 0) {
672
            if (shop.getDocumentId() != null && shop.getDocumentId() != customShop.getDocumentId()) {
673
            if (shop.getDocumentId() != null && shop.getDocumentId() != customShop.getDocumentId()) {
673
                try {
674
                try {
Line 794... Line 795...
794
        Function<Role, String> roleToNameFunction = role -> String.valueOf(role.getName());
795
        Function<Role, String> roleToNameFunction = role -> String.valueOf(role.getName());
795
        Set<String> userRoleStrings = roles.stream().map(roleToNameFunction).collect(Collectors.toSet());
796
        Set<String> userRoleStrings = roles.stream().map(roleToNameFunction).collect(Collectors.toSet());
796
        return String.join(", ", userRoleStrings);
797
        return String.join(", ", userRoleStrings);
797
    }
798
    }
798
 
799
 
-
 
800
    private FofoStore createFofoStoreCodeByRetailerId(int retailerId, String districtName, String
799
    private FofoStore createFofoStoreCodeByRetailerId(int retailerId, String districtName, String stateName, UpdateRetailerRequest updateRetailerRequest) throws ProfitMandiBusinessException {
801
            stateName, UpdateRetailerRequest updateRetailerRequest) throws ProfitMandiBusinessException {
800
        FofoStore fofoStore = null;
802
        FofoStore fofoStore = null;
801
        try {
803
        try {
802
            fofoStore = fofoStoreRepository.selectByRetailerId(retailerId);
804
            fofoStore = fofoStoreRepository.selectByRetailerId(retailerId);
803
            fofoStore.setActivationType(ActivationType.ACTIVE);
805
            fofoStore.setActivationType(ActivationType.ACTIVE);
804
 
806
 
Line 877... Line 879...
877
 
879
 
878
        return fofoStore;
880
        return fofoStore;
879
    }
881
    }
880
 
882
 
881
    @Override
883
    @Override
-
 
884
    public FofoStore createFofoStoreCodeByUserId(int userId, String districtName, String
882
    public FofoStore createFofoStoreCodeByUserId(int userId, String districtName, String stateName, UpdateRetailerRequest updateRetailerRequest) throws ProfitMandiBusinessException {
885
            stateName, UpdateRetailerRequest updateRetailerRequest) throws ProfitMandiBusinessException {
883
        User user = userRepository.selectById(userId);
886
        User user = userRepository.selectById(userId);
884
        // = userAccountRepository.selectRetailerIdByUserId(user.getId());
887
        // = userAccountRepository.selectRetailerIdByUserId(user.getId());
885
        UserAccount userAccounts = userAccountRepository.selectSaholicByUserId(user.getId());
888
        UserAccount userAccounts = userAccountRepository.selectSaholicByUserId(user.getId());
886
        Retailer retailer = retailerRepository.selectById(userAccounts.getAccountKey());
889
        Retailer retailer = retailerRepository.selectById(userAccounts.getAccountKey());
887
        Role roleFofo = roleRepository.selectByName(RoleType.FOFO.toString());
890
        Role roleFofo = roleRepository.selectByName(RoleType.FOFO.toString());
Line 1163... Line 1166...
1163
        List<Integer> storeIds = storeStream.map(x -> x.getId()).collect(Collectors.toList());
1166
        List<Integer> storeIds = storeStream.map(x -> x.getId()).collect(Collectors.toList());
1164
        return this.getFofoRetailers(storeIds);
1167
        return this.getFofoRetailers(storeIds);
1165
    }
1168
    }
1166
 
1169
 
1167
    @Override
1170
    @Override
1168
    public LoginRequestResponseModel registerWebUser(LoginRequestResponseModel loginRequestModel) throws ProfitMandiBusinessException {
1171
    public LoginRequestResponseModel registerWebUser(LoginRequestResponseModel loginRequestModel) throws
-
 
1172
            ProfitMandiBusinessException {
1169
 
1173
 
1170
        com.spice.profitmandi.dao.entity.user.User saholicUser = this.createSaholicUser(loginRequestModel);
1174
        com.spice.profitmandi.dao.entity.user.User saholicUser = this.createSaholicUser(loginRequestModel);
1171
        loginRequestModel.setUserId(saholicUser.getId());
1175
        loginRequestModel.setUserId(saholicUser.getId());
1172
 
1176
 
1173
        this.createRetailerAddress(loginRequestModel);
1177
        this.createRetailerAddress(loginRequestModel);
Line 1193... Line 1197...
1193
        privateDealUserAddressMapping.setAddressId(loginRequestModel.getBusinessAddress().getId());
1197
        privateDealUserAddressMapping.setAddressId(loginRequestModel.getBusinessAddress().getId());
1194
        privateDealUserAddressMappingRepository.persist(privateDealUserAddressMapping);
1198
        privateDealUserAddressMappingRepository.persist(privateDealUserAddressMapping);
1195
 
1199
 
1196
    }
1200
    }
1197
 
1201
 
1198
    private void createRetailerAddress(LoginRequestResponseModel loginRequestResponseModel) throws ProfitMandiBusinessException {
1202
    private void createRetailerAddress(LoginRequestResponseModel loginRequestResponseModel) throws
-
 
1203
            ProfitMandiBusinessException {
1199
        Address businessAddress = loginRequestResponseModel.getBusinessAddress();
1204
        Address businessAddress = loginRequestResponseModel.getBusinessAddress();
1200
        businessAddress.setRetaierId(loginRequestResponseModel.getUserId());
1205
        businessAddress.setRetaierId(loginRequestResponseModel.getUserId());
1201
        addressRepository.persist(businessAddress);
1206
        addressRepository.persist(businessAddress);
1202
    }
1207
    }
1203
 
1208
 
Line 1283... Line 1288...
1283
    }
1288
    }
1284
 
1289
 
1285
 
1290
 
1286
    //    @Override
1291
    //    @Override
1287
    @Cacheable(value = "getContactsByFofoId", cacheManager = "oneDayCacheManager")
1292
    @Cacheable(value = "getContactsByFofoId", cacheManager = "oneDayCacheManager")
1288
    public List<RetailerContact> getContactsByFofoId(int fofoId, boolean activeOnly) throws ProfitMandiBusinessException {
1293
    public List<RetailerContact> getContactsByFofoId(int fofoId, boolean activeOnly) throws
-
 
1294
            ProfitMandiBusinessException {
1289
        List<RetailerContact> retailerContacts = retailerContactRepository.selectAllByRetailerId(fofoId, activeOnly);
1295
        List<RetailerContact> retailerContacts = retailerContactRepository.selectAllByRetailerId(fofoId, activeOnly);
1290
        com.spice.profitmandi.dao.entity.user.User user = userUserRepository.selectById(fofoId);
1296
        com.spice.profitmandi.dao.entity.user.User user = userUserRepository.selectById(fofoId);
1291
        RetailerContact retailerContact = new RetailerContact();
1297
        RetailerContact retailerContact = new RetailerContact();
1292
        retailerContact.setMobile(user.getMobileNumber());
1298
        retailerContact.setMobile(user.getMobileNumber());
1293
        retailerContact.setName(user.getName());
1299
        retailerContact.setName(user.getName());
Line 1297... Line 1303...
1297
        return retailerContacts;
1303
        return retailerContacts;
1298
    }
1304
    }
1299
 
1305
 
1300
 
1306
 
1301
    @Override
1307
    @Override
1302
    public Map<Integer, CustomRetailer> getFofoRetailersPaginated(boolean activeOnly, int offset, int limit, FofoType fofoType) {
1308
    public Map<Integer, CustomRetailer> getFofoRetailersPaginated(boolean activeOnly, int offset,
-
 
1309
                                                                  int limit, FofoType fofoType) {
1303
 
1310
 
1304
        Stream<FofoStore> storeStream = fofoStoreRepository.selectByStatusFofoType(activeOnly, fofoType, offset, limit).stream();
1311
        Stream<FofoStore> storeStream = fofoStoreRepository.selectByStatusFofoType(activeOnly, fofoType, offset, limit).stream();
1305
 
1312
 
1306
        List<Integer> storeIds = storeStream.map(x -> x.getId()).collect(Collectors.toList());
1313
        List<Integer> storeIds = storeStream.map(x -> x.getId()).collect(Collectors.toList());
1307
        return this.getFofoRetailers(storeIds);
1314
        return this.getFofoRetailers(storeIds);