Subversion Repositories SmartDukaan

Rev

Rev 33367 | Rev 34149 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
22980 ashik.ali 1
package com.spice.profitmandi.service.user;
2
 
26528 amit.gupta 3
import com.google.common.hash.Hashing;
30097 tejbeer 4
import com.spice.profitmandi.common.enumuration.ActivationType;
5
import com.spice.profitmandi.common.enumuration.FofoType;
22980 ashik.ali 6
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
30017 amit.gupta 7
import com.spice.profitmandi.common.model.*;
23329 ashik.ali 8
import com.spice.profitmandi.common.util.StringUtils;
9
import com.spice.profitmandi.common.util.Utils;
22980 ashik.ali 10
import com.spice.profitmandi.dao.entity.dtr.User;
30017 amit.gupta 11
import com.spice.profitmandi.dao.entity.dtr.*;
12
import com.spice.profitmandi.dao.entity.fofo.*;
24349 amit.gupta 13
import com.spice.profitmandi.dao.entity.inventory.State;
33124 ranu 14
import com.spice.profitmandi.dao.entity.logistics.AST;
15
import com.spice.profitmandi.dao.entity.logistics.ASTRepository;
30017 amit.gupta 16
import com.spice.profitmandi.dao.entity.user.*;
23063 ashik.ali 17
import com.spice.profitmandi.dao.enumuration.dtr.AccountType;
23106 ashik.ali 18
import com.spice.profitmandi.dao.enumuration.dtr.RetailerType;
23136 ashik.ali 19
import com.spice.profitmandi.dao.enumuration.dtr.RoleType;
23365 ashik.ali 20
import com.spice.profitmandi.dao.enumuration.fofo.PaymentOptionType;
29042 tejbeer 21
import com.spice.profitmandi.dao.enumuration.transaction.PartnerVerificationApprovalStatus;
22980 ashik.ali 22
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
30017 amit.gupta 23
import com.spice.profitmandi.dao.repository.dtr.*;
23365 ashik.ali 24
import com.spice.profitmandi.dao.repository.fofo.FofoPartnerPaymentOptionRepository;
25
import com.spice.profitmandi.dao.repository.fofo.PaymentOptionRepository;
30719 tejbeer 26
import com.spice.profitmandi.dao.repository.fofo.PincodePartnerRepository;
24349 amit.gupta 27
import com.spice.profitmandi.dao.repository.inventory.StateRepository;
30017 amit.gupta 28
import com.spice.profitmandi.dao.repository.user.*;
33124 ranu 29
import com.spice.profitmandi.service.PostOfficeService;
23043 ashik.ali 30
import in.shop2020.model.v1.user.CartStatus;
30017 amit.gupta 31
import org.apache.logging.log4j.LogManager;
32
import org.apache.logging.log4j.Logger;
33
import org.springframework.beans.factory.annotation.Autowired;
34
import org.springframework.beans.factory.annotation.Qualifier;
35
import org.springframework.cache.annotation.Cacheable;
36
import org.springframework.stereotype.Component;
23043 ashik.ali 37
 
30017 amit.gupta 38
import java.nio.charset.StandardCharsets;
39
import java.time.LocalDateTime;
40
import java.util.*;
41
import java.util.function.Function;
42
import java.util.stream.Collectors;
43
import java.util.stream.Stream;
44
 
22980 ashik.ali 45
@Component
46
public class RetailerServiceImpl implements RetailerService {
23955 govind 47
 
31734 tejbeer 48
    private static final Logger LOGGER = LogManager.getLogger(RetailerServiceImpl.class);
23955 govind 49
 
31734 tejbeer 50
    @Autowired
51
    private RetailerRepository retailerRepository;
23955 govind 52
 
31734 tejbeer 53
    @Autowired
54
    private RetailerBlockBrandsRepository retailerBlockBrandsRepository;
28024 tejbeer 55
 
31734 tejbeer 56
    @Autowired
57
    private UserAccountRepository userAccountRepository;
23955 govind 58
 
31734 tejbeer 59
    @Autowired
60
    private Mongo mongoClient;
28024 tejbeer 61
 
31734 tejbeer 62
    @Autowired
63
    private UserRepository userRepository;
23955 govind 64
 
31734 tejbeer 65
    @Autowired
66
    private CartRepository cartRepository;
23955 govind 67
 
31734 tejbeer 68
    @Autowired
69
    private RetailerRegisteredAddressRepository retailerRegisteredAddressRepository;
23955 govind 70
 
31734 tejbeer 71
    @Autowired
72
    private AddressRepository addressRepository;
23955 govind 73
 
31734 tejbeer 74
    @Autowired
75
    private ShopRepository shopRepository;
23955 govind 76
 
31734 tejbeer 77
    @Autowired
78
    private ShopAddressRepository shopAddressRepository;
23955 govind 79
 
31734 tejbeer 80
    @Autowired
81
    private UserRoleRepository userRoleRepository;
23955 govind 82
 
31734 tejbeer 83
    @Autowired
84
    private DocumentRepository documentRepository;
23955 govind 85
 
31734 tejbeer 86
    @Autowired
87
    private PrivateDealUserRepository privateDealUserRepository;
23955 govind 88
 
31734 tejbeer 89
    @Autowired
32737 amit.gupta 90
    private RetailerContactRepository retailerContactRepository;
91
 
92
    @Autowired
31734 tejbeer 93
    private PrivateDealUserAddressMappingRepository privateDealUserAddressMappingRepository;
23955 govind 94
 
31734 tejbeer 95
    @Autowired
96
    private CounterRepository counterRepository;
25295 amit.gupta 97
 
31734 tejbeer 98
    @Autowired
99
    private StateRepository stateRepository;
23955 govind 100
 
31734 tejbeer 101
    @Autowired
102
    @Qualifier("userUserRepository")
103
    private com.spice.profitmandi.dao.repository.user.UserRepository userUserRepository;
23955 govind 104
 
31734 tejbeer 105
    @Autowired
106
    private DistrictMasterRepository districtMasterRepository;
23955 govind 107
 
31734 tejbeer 108
    @Autowired
109
    private FofoStoreRepository fofoStoreRepository;
23955 govind 110
 
31734 tejbeer 111
    @Autowired
33124 ranu 112
    private ASTRepository aSTRepository;
113
 
114
    @Autowired
115
    private PostOfficeService postOfficeService;
116
 
117
    @Autowired
31734 tejbeer 118
    private PaymentOptionRepository paymentOptionRepository;
23955 govind 119
 
31734 tejbeer 120
    @Autowired
121
    private FofoPartnerPaymentOptionRepository fofoPartnerPaymentOptionRepository;
23955 govind 122
 
31734 tejbeer 123
    @Autowired
124
    private RoleRepository roleRepository;
23955 govind 125
 
31734 tejbeer 126
    @Autowired
127
    private StoreTimelineTatService storeTimelineTatService;
28908 tejbeer 128
 
31734 tejbeer 129
    @Autowired
130
    private PartnerOnBoardingPanelRepository partnerOnBoardingPanelRepository;
28908 tejbeer 131
 
31734 tejbeer 132
    @Autowired
133
    private PartnerOnboardingVerificationRepository partnerOnboardingVerificationRepository;
29042 tejbeer 134
 
31734 tejbeer 135
    @Autowired
136
    private PincodePartnerRepository pincodePartnerRepository;
30719 tejbeer 137
 
31734 tejbeer 138
    @Override
139
    public Map<String, Object> getByEmailIdOrMobileNumber(String emailIdOrMobileNumber) throws ProfitMandiBusinessException {
140
        User user = null;
141
        int fofoId = Utils.SYSTEM_PARTNER_ID;
28024 tejbeer 142
 
31734 tejbeer 143
        try {
144
            user = userRepository.selectByEmailIdOrMobileNumber(emailIdOrMobileNumber);
145
        } catch (ProfitMandiBusinessException profitMandiBusinessException) {
23955 govind 146
 
31734 tejbeer 147
        }
148
        if (user == null) {
149
            try {
150
                user = userRepository.selectBySecondryEmailId(emailIdOrMobileNumber);
151
            } catch (ProfitMandiBusinessException profitMandiBusinessException) {
23955 govind 152
 
31734 tejbeer 153
            }
154
        }
155
        Map<String, Object> map = new HashMap<>();
156
        map.put("stateNames", stateRepository.selectAll().stream().map(x -> x.getName()).collect(Collectors.toList()));
23955 govind 157
 
31734 tejbeer 158
        if (user != null) {
23955 govind 159
 
31734 tejbeer 160
            List<UserRole> userRoles = userRoleRepository.selectByUserId(user.getId());
23955 govind 161
 
31734 tejbeer 162
            Role role = roleRepository.selectByName(RoleType.FOFO.toString());
23955 govind 163
 
31734 tejbeer 164
            map.put("userRoles", userRoles);
165
            map.put("user", user);
166
            // map.put("retailer", retailer);
167
            map.put("fofoRole", this.containsRoleType(userRoles, role.getId()));
23955 govind 168
 
31734 tejbeer 169
            map.put("userRoleNames", this.toString(userRoles));
170
            try {
171
                int retailerId = userAccountRepository.selectRetailerIdByUserId(user.getId());
172
                Retailer retailer = retailerRepository.selectById(retailerId);
23955 govind 173
 
31734 tejbeer 174
                map.put("retailer", retailer);
23955 govind 175
 
31734 tejbeer 176
                List<String> retailerBlockBrands = null;
177
                Set<String> brands = null;
178
                if (retailer.getId() != fofoId) {
179
                    brands = mongoClient.getMongoBrands(retailer.getId(), null, 3).stream().map(x -> (String) x.get("name")).collect(Collectors.toSet());
180
                    retailerBlockBrands = retailerBlockBrandsRepository.selectAllByRetailer(retailer.getId()).stream().map(x -> x.getBlockBrands()).collect(Collectors.toList());
28189 tejbeer 181
 
31734 tejbeer 182
                    LOGGER.info("loginDetailsFofoId" + retailer.getId());
183
                } else {
184
                    LOGGER.info("fofoId" + fofoId);
185
                    brands = mongoClient.getMongoBrands(fofoId, null, 3).stream().map(x -> (String) x.get("name")).collect(Collectors.toSet());
186
                }
187
                map.put("brands", brands);
188
                map.put("retailerBlockBrands", retailerBlockBrands);
23955 govind 189
 
31734 tejbeer 190
                try {
191
                    PrivateDealUser privateDealUser = privateDealUserRepository.selectById(retailer.getId());
192
                    if (privateDealUser.getCounterId() != null) {
193
                        Counter counter = counterRepository.selectById(privateDealUser.getCounterId());
194
                        map.put("gstNumber", counter.getGstin());
195
                        // LOGGER.info("gstNumber" + counter.getGstin());
196
                    }
197
                } catch (ProfitMandiBusinessException profitMandiBusinessException) {
198
                    LOGGER.error("PrivateDealUser not found");
199
                }
200
                try {
201
                    int retailerAddressId = retailerRegisteredAddressRepository.selectAddressIdByRetailerId(retailer.getId());
202
                    Address retailerAddress = addressRepository.selectById(retailerAddressId);
203
                    map.put("retailerAddress", retailerAddress);
204
                    State state = stateRepository.selectByName(retailerAddress.getState());
205
                    // LOGGER.info("retailerAddress.." + retailerAddress);
206
                    List<DistrictMaster> districtMasters = districtMasterRepository.selectByStateShortName(state.getShortName());
207
                    map.put("districtMasters", districtMasters);
208
                    // LOGGER.info("districtMasters" + districtMasters);
209
                    List<Shop> shops = shopRepository.selectByRetailerId(retailer.getId());
210
                    map.put("shops", shops);
211
                    this.addAddress(shops);
33128 amit.gupta 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
                    }
31734 tejbeer 228
                    // LOGGER.info("shops" + shops);
229
                } catch (ProfitMandiBusinessException profitMandiBusinessException) {
230
                    LOGGER.error("Retailer Registered Address not found");
231
                }
232
            } catch (ProfitMandiBusinessException profitMandiBusinessException) {
233
                LOGGER.error("Retailer not found in user_account");
234
            }
235
        }
23955 govind 236
 
31734 tejbeer 237
        return map;
238
    }
23955 govind 239
 
31734 tejbeer 240
    private boolean containsRoleType(List<UserRole> userRoles, int roleId) {
241
        for (UserRole userRole : userRoles) {
242
            if (userRole.getRoleId() == roleId) {
243
                return true;
244
            }
245
        }
246
        return false;
247
    }
23955 govind 248
 
31734 tejbeer 249
    private List<UserRole> addRole(List<UserRole> userRoles, int userId, int roleId) {
250
        if (userRoles == null) {
251
            userRoles = new ArrayList<>();
252
        }
253
        if (!this.containsRoleType(userRoles, roleId)) {
254
            UserRole userRole = new UserRole();
255
            userRole.setUserId(userId);
256
            userRole.setRoleId(roleId);
257
            try {
258
                userRoleRepository.persist(userRole);
259
            } catch (ProfitMandiBusinessException e) {
260
                LOGGER.error("UserRole is already exist");
261
            }
262
            userRoles.add(userRole);
263
        }
264
        return userRoles;
23955 govind 265
 
31734 tejbeer 266
    }
23955 govind 267
 
31734 tejbeer 268
    private List<UserRole> removeRole(List<UserRole> userRoles, int userId, int roleId) {
269
        if (userRoles == null) {
270
            userRoles = new ArrayList<>();
271
            return userRoles;
272
        }
273
        try {
274
            userRoles.remove(userRoleRepository.deleteByRoleUserId(userId, roleId));
275
        } catch (Exception e) {
25295 amit.gupta 276
 
31734 tejbeer 277
        }
278
        return userRoles;
25295 amit.gupta 279
 
31734 tejbeer 280
    }
25295 amit.gupta 281
 
31734 tejbeer 282
    @SuppressWarnings("unchecked")
283
    @Override
33128 amit.gupta 284
    public Map<String, Object> updateRetailerDetails(UpdateRetailerRequest updateRetailerRequest) throws
285
            ProfitMandiBusinessException {
31734 tejbeer 286
        Map<String, Object> map = this.getByEmailIdOrMobileNumber(updateRetailerRequest.getEmailIdOrMobileNumber());
32953 amit.gupta 287
        User dtrUser = (User) map.get("user");
28024 tejbeer 288
 
32953 amit.gupta 289
        dtrUser = this.createUser(dtrUser, updateRetailerRequest);
28024 tejbeer 290
 
32953 amit.gupta 291
        map.put("user", dtrUser);
31734 tejbeer 292
        List<UserRole> userRoles = (List<UserRole>) map.get("userRoles");
293
        Role roleUser = roleRepository.selectByName(RoleType.USER.toString());
32953 amit.gupta 294
        userRoles = this.addRole(userRoles, dtrUser.getId(), roleUser.getId());
31734 tejbeer 295
        Retailer retailer = (Retailer) map.get("retailer");
32953 amit.gupta 296
        retailer = this.updateRetailer(dtrUser, retailer, updateRetailerRequest);
28024 tejbeer 297
 
31734 tejbeer 298
        map.put("retailer", retailer);
23955 govind 299
 
31734 tejbeer 300
        List<String> retailerBlockBrands = retailerBlockBrandsRepository.selectAllByRetailer(retailer.getId()).stream().map(x -> x.getBlockBrands()).collect(Collectors.toList());
28024 tejbeer 301
 
31734 tejbeer 302
        LOGGER.info("retailerBlockBrands" + retailerBlockBrands);
28189 tejbeer 303
 
31734 tejbeer 304
        if (!retailerBlockBrands.isEmpty()) {
305
            retailerBlockBrandsRepository.deleteBrands(retailer.getId());
306
        }
28024 tejbeer 307
 
31734 tejbeer 308
        for (String blockBrand : updateRetailerRequest.getBlocksBrands()) {
309
            RetailerBlockBrands retailerBlockBrand = new RetailerBlockBrands();
28024 tejbeer 310
 
31734 tejbeer 311
            retailerBlockBrand.setFofoId(retailer.getId());
312
            retailerBlockBrand.setBlockBrands(blockBrand);
313
            retailerBlockBrandsRepository.persist(retailerBlockBrand);
28024 tejbeer 314
 
31734 tejbeer 315
        }
316
        map.put("retailerBlockBrands", retailerBlockBrands);
28024 tejbeer 317
 
31734 tejbeer 318
        Role roleRetailer = roleRepository.selectByName(RoleType.RETAILER.toString());
23955 govind 319
 
32953 amit.gupta 320
        userRoles = this.addRole(userRoles, dtrUser.getId(), roleRetailer.getId());
23955 govind 321
 
31734 tejbeer 322
        Role roleFofo = roleRepository.selectByName(RoleType.FOFO.toString());
23955 govind 323
 
31734 tejbeer 324
        if (updateRetailerRequest.isFofo()) {
32953 amit.gupta 325
            userRoles = this.addRole(userRoles, dtrUser.getId(), roleFofo.getId());
31734 tejbeer 326
        } else {
32953 amit.gupta 327
            userRoles = this.removeRole(userRoles, dtrUser.getId(), roleFofo.getId());
31734 tejbeer 328
        }
329
        map.put("fofoRole", this.containsRoleType(userRoles, roleFofo.getId()));
23955 govind 330
 
31734 tejbeer 331
        if (this.containsRoleType(userRoles, roleFofo.getId())) {
332
            this.createDefaultPaymentOption(retailer.getId());
333
        }
23955 govind 334
 
31734 tejbeer 335
        map.put("userRoles", userRoles);
336
        map.put("userRoleNames", this.toString(userRoles));
23955 govind 337
 
31734 tejbeer 338
        Address retailerAddress = (Address) map.get("retailerAddress");
339
        retailerAddress = this.updateRetailerAddress(retailerAddress, updateRetailerRequest.getAddress(), retailer.getId());
340
        map.put("retailerAddress", retailerAddress);
23955 govind 341
 
31734 tejbeer 342
        if (updateRetailerRequest.isFofo()) {
343
            FofoStore fofoStore = this.createFofoStoreCodeByRetailerId(retailer.getId(), updateRetailerRequest.getDistrictName(), retailerAddress.getState(), updateRetailerRequest);
344
            map.put("fofoStore", fofoStore);
345
            fofoStore.setActive(updateRetailerRequest.isActive());
33131 ranu 346
            List<AST> astDetail = postOfficeService.getAreasAndTerritoriesByStateName(retailerAddress.getState());
347
            map.put("astDetail", astDetail);
31734 tejbeer 348
        }
23955 govind 349
 
32953 amit.gupta 350
        this.createPrivateDealUser(dtrUser, updateRetailerRequest.isFofo(), updateRetailerRequest.getGstNumber(), retailer, retailerAddress.getId());
31734 tejbeer 351
        map.put("gstNumber", updateRetailerRequest.getGstNumber());
352
        this.updateSaholicUser(retailer.getId(), retailerAddress.getId());
23955 govind 353
 
31734 tejbeer 354
        List<Shop> shops = (List<Shop>) map.get("shops");
355
        if (shops == null) {
356
            shops = new ArrayList<>();
357
            map.put("shops", shops);
358
        }
359
        this.updateRetailerShops(shops, updateRetailerRequest.getShops(), retailer.getId(), retailerAddress);
23955 govind 360
 
31734 tejbeer 361
        return map;
23955 govind 362
 
31734 tejbeer 363
    }
23955 govind 364
 
31734 tejbeer 365
    private void createDefaultPaymentOption(int fofoId) {
366
        List<Integer> paymentOptionIds = fofoPartnerPaymentOptionRepository.selectPaymentOptionIdsByFofoId(fofoId);
367
        if (paymentOptionIds.isEmpty()) {
368
            PaymentOption paymentOption = null;
369
            try {
370
                paymentOption = paymentOptionRepository.selectByName(PaymentOptionType.CASH.toString());
371
            } catch (ProfitMandiBusinessException profitMandiBusinessException) {
372
                paymentOption = new PaymentOption();
373
                paymentOption.setName(PaymentOptionType.CASH.toString());
374
                paymentOptionRepository.persist(paymentOption);
375
            }
376
            FofoPartnerPaymentOption fofoPartnerPaymentOption = new FofoPartnerPaymentOption();
377
            fofoPartnerPaymentOption.setFofoId(fofoId);
378
            fofoPartnerPaymentOption.setPaymentOptionId(paymentOption.getId());
379
            fofoPartnerPaymentOptionRepository.persist(fofoPartnerPaymentOption);
380
        }
23955 govind 381
 
31734 tejbeer 382
    }
23955 govind 383
 
33128 amit.gupta 384
    private User createUser(User user, UpdateRetailerRequest updateRetailerRequest) throws
385
            ProfitMandiBusinessException {
32965 amit.gupta 386
 
387
        User dtrUser = null;
388
        try {
389
            dtrUser = userRepository.selectByMobileNumber(updateRetailerRequest.getUserMobileNumber());
390
        } catch (ProfitMandiBusinessException e) {
391
            //Ignore the exception
392
        }
33140 ranu 393
        if (dtrUser != null && (user == null || user.getId() != dtrUser.getId()))
394
            throw new ProfitMandiBusinessException("Mobile already exist", updateRetailerRequest.getUserMobileNumber(), dtrUser.getEmailId());
32966 amit.gupta 395
 
396
        User dtrUserByEmail = null;
397
        try {
398
            dtrUserByEmail = userRepository.selectByEmailId(updateRetailerRequest.getUserEmailId());
399
        } catch (ProfitMandiBusinessException e) {
400
            //ignore the exception
401
        }
33025 amit.gupta 402
        if (user != null && dtrUserByEmail != null && user.getId() != dtrUserByEmail.getId())
32965 amit.gupta 403
            throw new ProfitMandiBusinessException("Email already exist", updateRetailerRequest.getUserEmailId(), "");
32953 amit.gupta 404
 
405
 
31734 tejbeer 406
        if (user == null) {
407
            user = new User();
408
            user.setCity("");
409
            user.setPinCode(0);
410
            user.setState("");
411
            user.setPassword("");
412
            user.setMobile_verified(false);
413
            user.setReferral_url("");
414
            user.setGroup_id(1);
415
            user.setStatus(1);
416
            user.setActivated(true);
417
            user.setCreateTimestamp(LocalDateTime.now());
418
        }
419
        user.setActivated(updateRetailerRequest.isActive());
420
        user.setFirstName(updateRetailerRequest.getUserFirstName());
421
        user.setLastName(updateRetailerRequest.getUserLastName());
422
        user.setMobileNumber(updateRetailerRequest.getUserMobileNumber());
423
        user.setEmailId(updateRetailerRequest.getUserEmailId());
424
        user.setUsername(updateRetailerRequest.getUserEmailId());
425
        user.setUpdateTimestamp(LocalDateTime.now());
426
        userRepository.persist(user);
427
        return user;
23955 govind 428
 
31734 tejbeer 429
    }
23955 govind 430
 
31734 tejbeer 431
    private int createSaholicUser(User user, String retailerName) {
432
        com.spice.profitmandi.dao.entity.user.User saholicUser = null;
433
        try {
434
            saholicUser = userUserRepository.selectByEmailId(user.getEmailId());
435
        } catch (ProfitMandiBusinessException e) {
436
            LOGGER.info("User doesnt exist in old system");
437
        }
438
        if (saholicUser == null) {
439
            Cart cart = new Cart();
440
            cart.setCartStatus(CartStatus.ACTIVE);
441
            cartRepository.persist(cart);
442
            saholicUser = new com.spice.profitmandi.dao.entity.user.User();
443
            saholicUser.setEmailId(user.getEmailId());
444
            saholicUser.setName(retailerName);
445
            saholicUser.setActiveCartId(cart.getId());
446
            saholicUser.setCreateTimestamp(LocalDateTime.now());
447
            userUserRepository.persist(saholicUser);
23955 govind 448
 
31734 tejbeer 449
            UserAccount ua = new UserAccount();
450
            ua.setAccountKey(saholicUser.getId());
451
            ua.setUserId(user.getId());
452
            ua.setType(AccountType.saholic);
453
            userAccountRepository.persist(ua);
23063 ashik.ali 454
 
31734 tejbeer 455
            UserAccount ua2 = new UserAccount();
456
            ua2.setAccountKey(saholicUser.getActiveCartId());
457
            ua2.setUserId(user.getId());
458
            ua2.setType(AccountType.cartId);
459
            userAccountRepository.persist(ua2);
460
            LOGGER.info("created....");
461
        }
462
        return saholicUser.getId();
463
    }
23955 govind 464
 
31734 tejbeer 465
    private com.spice.profitmandi.dao.entity.user.User createSaholicUser(
32953 amit.gupta 466
            LoginRequestResponseModel loginRequestResponseModel) {
31734 tejbeer 467
        com.spice.profitmandi.dao.entity.user.User saholicUser = null;
468
        try {
469
            saholicUser = userUserRepository.selectByEmailId(loginRequestResponseModel.getEmail());
470
            saholicUser.setCreateTimestamp(LocalDateTime.now());
471
        } catch (ProfitMandiBusinessException e) {
472
            LOGGER.info("User doesnt exist in old system");
473
        }
474
        if (saholicUser == null) {
475
            Cart cart = new Cart();
476
            cart.setCartStatus(CartStatus.ACTIVE);
477
            cartRepository.persist(cart);
478
            saholicUser = new com.spice.profitmandi.dao.entity.user.User();
479
            saholicUser.setPassword(getHash256(loginRequestResponseModel.getPassword()));
480
            saholicUser.setEmailId(loginRequestResponseModel.getEmail());
481
            saholicUser.setName(loginRequestResponseModel.getCustomerName());
482
            saholicUser.setActiveCartId(cart.getId());
483
            saholicUser.setCreateTimestamp(LocalDateTime.now());
484
            loginRequestResponseModel.setPassword(null);
485
            userUserRepository.persist(saholicUser);
486
        }
487
        return saholicUser;
488
    }
26522 amit.gupta 489
 
33128 amit.gupta 490
    private Retailer updateRetailer(User user, Retailer retailer, UpdateRetailerRequest updateRetailerRequest) throws
491
            ProfitMandiBusinessException {
31734 tejbeer 492
        if (retailer == null) {
493
            LOGGER.info("createSaholicUser.....");
494
            int saholicUserId = this.createSaholicUser(user, updateRetailerRequest.getName());
495
            retailer = new Retailer();
496
            retailer.setId(saholicUserId);
497
        }
498
        retailer.setActive(updateRetailerRequest.isActive());
499
        user.setActivated(updateRetailerRequest.isActive());//
500
        // this.createRole(user.getId(), RoleType.RETAILER);
501
        retailer.setName(updateRetailerRequest.getName());
502
        retailer.setNumber(updateRetailerRequest.getNumber());
503
        if (updateRetailerRequest.getNumber() == null || updateRetailerRequest.getNumber().isEmpty()) {
504
            retailer.setType(RetailerType.UNREGISTERED_SHOP);
505
        } else {
506
            retailer.setType(RetailerType.GSTIN);
507
        }
508
        if (updateRetailerRequest.getDocumentId() > 0) {
509
            if (retailer.getDocumentId() != null && retailer.getDocumentId() != updateRetailerRequest.getDocumentId()) {
510
                try {
511
                    documentRepository.deleteById(retailer.getDocumentId());
512
                } catch (Exception e) {
513
                    e.printStackTrace();
514
                }
515
            }
516
            retailer.setDocumentId(updateRetailerRequest.getDocumentId());
517
            documentRepository.markDocumentAsPersisted(updateRetailerRequest.getDocumentId());
518
        }
519
        retailerRepository.persist(retailer);
520
        return retailer;
521
    }
23955 govind 522
 
31734 tejbeer 523
    private void updateSaholicUser(int retailerId, int retailerAddressId) {
524
        try {
525
            com.spice.profitmandi.dao.entity.user.User user = userUserRepository.selectById(retailerId);
526
            user.setAddressId(retailerAddressId);
32555 amit.gupta 527
            Cart cart = cartRepository.selectById(user.getActiveCartId());
528
            cart.setAddressId(retailerAddressId);
31734 tejbeer 529
        } catch (ProfitMandiBusinessException e) {
23955 govind 530
 
31734 tejbeer 531
        }
532
    }
23955 govind 533
 
33128 amit.gupta 534
    private void createPrivateDealUser(User user, boolean fofo, String gstNumber, Retailer retailer,
535
                                       int retailerAddressId) {
31734 tejbeer 536
        PrivateDealUser privateDealUser = null;
537
        try {
538
            privateDealUser = privateDealUserRepository.selectById(retailer.getId());
539
        } catch (ProfitMandiBusinessException profitMandiBusinessException) {
540
            LOGGER.error("PrivateDealUser not found");
541
        }
23955 govind 542
 
31734 tejbeer 543
        // = privateDealUserRepository.selectById(saholicUser.getId());
544
        if (privateDealUser == null) {
545
            Integer counterId = this.createCounter(user.getEmailId(), gstNumber, user.getMobileNumber(), retailer.getName(), retailerAddressId);
546
            try {
547
                this.createPrivateDealUser(retailer.getId(), counterId, fofo);
548
            } catch (Exception e) {
549
                LOGGER.error("ERROR : ", e);
550
            }
551
        } else {
552
            if (privateDealUser.getCounterId() == null) {
553
                Integer counterId = this.createCounter(user.getEmailId(), gstNumber, user.getMobileNumber(), retailer.getName(), retailerAddressId);
554
                privateDealUser.setCounterId(counterId);
555
                privateDealUser.setFofo(fofo);
556
                privateDealUserRepository.persist(privateDealUser);
557
            } else {
558
                Counter counter = null;
559
                try {
560
                    counter = counterRepository.selectById(privateDealUser.getCounterId());
561
                } catch (ProfitMandiBusinessException profitMandiBusinessException) {
562
                    LOGGER.error("Counter not found with id [{}]", privateDealUser.getCounterId());
563
                }
564
                if (counter == null) {
565
                    this.createCounter(user.getEmailId(), gstNumber, user.getMobileNumber(), retailer.getName(), retailerAddressId);
566
                } else {
567
                    counter.setGstin(gstNumber);
568
                    counterRepository.persist(counter);
569
                }
570
                privateDealUser.setFofo(fofo);
571
                privateDealUserRepository.persist(privateDealUser);
572
            }
573
        }
23955 govind 574
 
31734 tejbeer 575
        PrivateDealUserAddressMapping privateDealUserAddressMapping = new PrivateDealUserAddressMapping();
576
        privateDealUserAddressMapping.setUserId(retailer.getId());
577
        privateDealUserAddressMapping.setAddressId(retailerAddressId);
578
        privateDealUserAddressMappingRepository.persist(privateDealUserAddressMapping);
579
    }
23955 govind 580
 
31734 tejbeer 581
    // Specifically set isFofo to true that has to be used by old system
582
    private void createPrivateDealUser(int retailerId, int counterId, boolean fofo) {
583
        PrivateDealUser privateDealUser = new PrivateDealUser();
584
        privateDealUser.setActive(true);
585
        privateDealUser.setBulkShipmentAmountLimit(fofo ? 1000000 : 50000);
586
        privateDealUser.setId(retailerId);
587
        privateDealUser.setCounterId(counterId);
588
        privateDealUser.setFofo(fofo);
589
        privateDealUserRepository.persist(privateDealUser);
590
    }
23955 govind 591
 
31734 tejbeer 592
    private Integer createCounter(String emailId, String gstNumber, String mobileNumber, String name, int addressId) {
593
        if (gstNumber != null && !gstNumber.isEmpty()) {
594
            Counter counter = new Counter();
595
            counter.setEmailId(emailId);
596
            counter.setGstin(gstNumber);
597
            counter.setMobileNumber(mobileNumber);
598
            counter.setName(name);
599
            counter.setAddressId(addressId);
600
            counterRepository.persist(counter);
601
            return counter.getId();
602
        } else {
603
            return null;
604
        }
605
    }
23955 govind 606
 
33128 amit.gupta 607
    private Address updateRetailerAddress(Address address, CustomAddress customAddress, int retailerId) throws
608
            ProfitMandiBusinessException {
31734 tejbeer 609
        if (address == null) {
610
            address = new Address();
611
            address.setRetaierId(retailerId);
612
            this.updateAddress(address, customAddress);
613
            // addressRepository.persist(addressRetailer);
23955 govind 614
 
31734 tejbeer 615
            final RetailerRegisteredAddress retailerRegisteredAddress = new RetailerRegisteredAddress();
616
            retailerRegisteredAddress.setRetailerId(retailerId);
617
            retailerRegisteredAddress.setAddressId(address.getId());
618
            retailerRegisteredAddressRepository.persist(retailerRegisteredAddress);
619
        } else {
620
            this.updateAddress(address, customAddress);
621
            RetailerRegisteredAddress retailerRegisteredAddress = retailerRegisteredAddressRepository.selectByRetailerId(retailerId);
622
            retailerRegisteredAddress.setAddressId(address.getId());
623
            retailerRegisteredAddressRepository.persist(retailerRegisteredAddress);
624
        }
625
        return address;
626
    }
23955 govind 627
 
31734 tejbeer 628
    private void updateAddress(Address address, CustomAddress customAddress) throws ProfitMandiBusinessException {
629
        address.setName(customAddress.getName());
630
        address.setPhoneNumber(customAddress.getPhoneNumber());
631
        address.setLine1(customAddress.getLine1());
632
        address.setLine2(customAddress.getLine2());
633
        address.setCity(customAddress.getCity());
634
        address.setPinCode(customAddress.getPinCode());
635
        State state = stateRepository.selectByName(customAddress.getState());
636
        if (state == null) {
637
            throw new ProfitMandiBusinessException("State name", "Invalid State - Pls Contact Technology", "Invalid State - Pls Contact Technology");
638
        }
639
        address.setState(state.getName());
640
        addressRepository.persist(address);
641
        LOGGER.info("Address Updated" + address);
642
    }
23955 govind 643
 
33128 amit.gupta 644
    private void updateRetailerShops(List<Shop> shops, Set<CustomShop> customShops, int retailerId, Address
645
            sameAsRetailerAddressValue) throws ProfitMandiBusinessException {
31734 tejbeer 646
        if (shops.isEmpty()) {
647
            for (CustomShop customShop : customShops) {
648
                Shop shop = new Shop();
649
                this.createOrUpdateShop(shop, customShop, retailerId, sameAsRetailerAddressValue);
650
                shops.add(shop);
651
            }
652
        } else {
653
            for (Shop shop : shops) {
654
                for (CustomShop customShop : customShops) {
655
                    if (shop.getId() == customShop.getShopId()) {
656
                        this.createOrUpdateShop(shop, customShop, retailerId, sameAsRetailerAddressValue);
657
                    }
658
                }
659
            }
660
            for (CustomShop customShop : customShops) {
661
                if (customShop.getShopId() == 0) {
662
                    Shop shop = new Shop();
663
                    this.createOrUpdateShop(shop, customShop, retailerId, sameAsRetailerAddressValue);
664
                    shops.add(shop);
665
                }
666
            }
667
        }
668
    }
23955 govind 669
 
33128 amit.gupta 670
    private void createOrUpdateShop(Shop shop, CustomShop customShop, int retailerId, Address
671
            sameAsRetailerAddressValue) throws ProfitMandiBusinessException {
31734 tejbeer 672
        shop.setRetailerId(retailerId);
673
        shop.setName(customShop.getName());
674
        if (customShop.getDocumentId() > 0) {
675
            if (shop.getDocumentId() != null && shop.getDocumentId() != customShop.getDocumentId()) {
676
                try {
677
                    documentRepository.deleteById(shop.getDocumentId());
678
                } catch (Exception e) {
679
                    e.printStackTrace();
680
                }
681
            }
682
            shop.setDocumentId(customShop.getDocumentId());
683
            documentRepository.markDocumentAsPersisted(customShop.getDocumentId());
684
        }
685
        if (shop.getAddressId() == null) {
686
            Address address = null;
687
            if (customShop.isSameAsRetailerAddress()) {
688
                address = sameAsRetailerAddressValue;
689
            } else {
690
                // shop.setDocumentId(customShop.getDocumentId());
691
                address = new Address();
692
                this.updateAddress(address, customShop.getAddress());
693
            }
694
            shop.setAddressId(address.getId());
695
            shop.setAddress(address);
696
            shopRepository.persist(shop);
697
            ShopAddress shopAddress = null;
698
            try {
699
                shopAddress = shopAddressRepository.selectByShopId(shop.getId());
700
                shopAddress.setAddressId(address.getId());
701
            } catch (ProfitMandiBusinessException profitMandiBusinessException) {
702
                shopAddress = new ShopAddress();
703
                shopAddress.setAddressId(address.getId());
704
                shopAddress.setShopId(shop.getId());
705
            }
706
            shopAddressRepository.persist(shopAddress);
707
        } else {
708
            Address address = null;
709
            try {
710
                address = addressRepository.selectById(shop.getAddressId());
711
                CustomAddress customAddress = customShop.getAddress();
712
                if (!(address.getName().equals(customAddress.getName()) && address.getLine1().equals(customAddress.getLine1()) && address.getLine2().equals(customAddress.getLine2()) && address.getCity().equals(customAddress.getCity()) && address.getPinCode().equals(customAddress.getPinCode()) && address.getState().equals(customAddress.getState()))) {
713
                    address = new Address();
714
                    ShopAddress shopAddress = shopAddressRepository.selectByShopId(shop.getId());
715
                    this.updateAddress(address, customAddress);
716
                    shopAddress.setAddressId(address.getId());
717
                    shopAddressRepository.persist(shopAddress);
718
                    shop.setAddress(address);
719
                    shopRepository.persist(shop);
720
                }
721
            } catch (Exception e) {
722
                if (customShop.isSameAsRetailerAddress()) {
723
                    address = sameAsRetailerAddressValue;
724
                } else {
725
                    // shop.setDocumentId(customShop.getDocumentId());
726
                    address = new Address();
727
                    this.updateAddress(address, customShop.getAddress());
728
                }
729
                shop.setAddressId(address.getId());
730
                shop.setAddress(address);
731
                shopRepository.persist(shop);
732
                ShopAddress shopAddress = null;
733
                try {
734
                    shopAddress = shopAddressRepository.selectByShopId(shop.getId());
735
                    shopAddress.setAddressId(address.getId());
736
                } catch (ProfitMandiBusinessException profitMandiBusinessException) {
737
                    shopAddress = new ShopAddress();
738
                    shopAddress.setAddressId(address.getId());
739
                    shopAddress.setShopId(shop.getId());
740
                }
741
                shopAddressRepository.persist(shopAddress);
742
            }
23955 govind 743
 
31734 tejbeer 744
        }
23955 govind 745
 
31734 tejbeer 746
    }
23955 govind 747
 
33247 ranu 748
    private void addAddress(List<Shop> shops) throws ProfitMandiBusinessException {
31734 tejbeer 749
        Set<Integer> shopIds = this.toShopIds(shops);
750
        if (shopIds.isEmpty()) {
751
            return;
752
        }
753
        List<ShopAddress> shopAddresses = shopAddressRepository.selectByShopIds(shopIds);
754
        Map<Integer, Address> addressIdAddressMap = this.toAddressIdAddressMap(shopAddresses);
23955 govind 755
 
31734 tejbeer 756
        for (Shop shop : shops) {
757
            shop.setAddress(addressIdAddressMap.get(shop.getAddressId()));
758
        }
759
    }
22980 ashik.ali 760
 
33247 ranu 761
    private Map<Integer, Address> toAddressIdAddressMap(List<ShopAddress> shopAddresses) throws ProfitMandiBusinessException {
31734 tejbeer 762
        Map<Integer, Address> addressIdAddressMap = new HashMap<>();
763
        List<Integer> addressIds = this.toAddressIds(shopAddresses);
764
        List<Address> addresses = addressRepository.selectByIds(addressIds);
765
        for (Address address : addresses) {
766
            addressIdAddressMap.put(address.getId(), address);
767
        }
768
        return addressIdAddressMap;
769
    }
23955 govind 770
 
31734 tejbeer 771
    private List<Integer> toAddressIds(List<ShopAddress> shopAddresses) {
772
        Function<ShopAddress, Integer> shopAddressToAddressIdFunction = new Function<ShopAddress, Integer>() {
773
            @Override
774
            public Integer apply(ShopAddress shopAddress) {
775
                return shopAddress.getAddressId();
776
            }
777
        };
778
        return shopAddresses.stream().map(shopAddressToAddressIdFunction).collect(Collectors.toList());
779
    }
23955 govind 780
 
31734 tejbeer 781
    private Set<Integer> toShopIds(List<Shop> shops) {
782
        Function<Shop, Integer> shopToAddressIdFunction = new Function<Shop, Integer>() {
783
            @Override
784
            public Integer apply(Shop shop) {
785
                return shop.getId();
786
            }
787
        };
788
        return shops.stream().map(shopToAddressIdFunction).collect(Collectors.toSet());
789
    }
23955 govind 790
 
33247 ranu 791
    private String toString(List<UserRole> userRoles) throws ProfitMandiBusinessException {
31734 tejbeer 792
        Set<Integer> roleIds = new HashSet<>();
793
        for (UserRole userRole : userRoles) {
794
            roleIds.add(userRole.getRoleId());
795
        }
796
        List<Role> roles = roleRepository.selectByIds(roleIds);
31735 amit.gupta 797
        Function<Role, String> roleToNameFunction = role -> String.valueOf(role.getName());
31734 tejbeer 798
        Set<String> userRoleStrings = roles.stream().map(roleToNameFunction).collect(Collectors.toSet());
799
        return String.join(", ", userRoleStrings);
800
    }
23955 govind 801
 
33128 amit.gupta 802
    private FofoStore createFofoStoreCodeByRetailerId(int retailerId, String districtName, String
803
            stateName, UpdateRetailerRequest updateRetailerRequest) throws ProfitMandiBusinessException {
31734 tejbeer 804
        FofoStore fofoStore = null;
805
        try {
806
            fofoStore = fofoStoreRepository.selectByRetailerId(retailerId);
807
            fofoStore.setActivationType(ActivationType.ACTIVE);
30097 tejbeer 808
 
31734 tejbeer 809
        } catch (ProfitMandiBusinessException profitMandiBusinessException) {
23955 govind 810
 
31734 tejbeer 811
        }
23955 govind 812
 
31734 tejbeer 813
        if (fofoStore != null) {
814
            fofoStore.setCounterSize(updateRetailerRequest.getCountersize());
33124 ranu 815
            fofoStore.setAstId(updateRetailerRequest.getAstId());
31734 tejbeer 816
            fofoStore.setMinimumInvestment(updateRetailerRequest.getMinInvestment());
817
            fofoStore.setWarehouseId(updateRetailerRequest.getWarehouseId());
818
            fofoStore.setCounterPotential(updateRetailerRequest.getCounterPotential());
819
            fofoStore.setFofoType(updateRetailerRequest.getFofoType());
820
        } else {
821
            int retailerAddressId = retailerRegisteredAddressRepository.selectAddressIdByRetailerId(retailerId);
822
            Address retailerAddress = addressRepository.selectById(retailerAddressId);
23955 govind 823
 
31734 tejbeer 824
            // StateInfo stateInfo = null;
825
            State stateInfo = null;
826
            try {
30527 tejbeer 827
 
31734 tejbeer 828
                stateInfo = stateRepository.selectByName(retailerAddress.getState());
829
                // stateInfo = Utils.getStateInfo(retailerAddress.getState());
830
            } catch (Exception e) {
831
                // TODO Auto-generated catch block
832
                e.printStackTrace();
833
                // throw new ProfitMandiBusinessException();
834
            }
835
            DistrictMaster districtMaster = districtMasterRepository.selectByNameAndStateShortName(districtName, stateInfo.getShortName());
23955 govind 836
 
31734 tejbeer 837
            fofoStore = new FofoStore();
838
            fofoStore.setId(retailerId);
839
            fofoStore.setCounterSize(updateRetailerRequest.getCountersize());
840
            fofoStore.setMinimumInvestment(updateRetailerRequest.getMinInvestment());
31730 tejbeer 841
 
31734 tejbeer 842
            fofoStore.setCounterPotential(updateRetailerRequest.getCounterPotential());
843
            fofoStore.setWarehouseId(updateRetailerRequest.getWarehouseId());
32615 raveendra. 844
            int nextStoreCodeInt = fofoStoreRepository.selectLatestStore().getCodeInt() + 1;
845
 
31734 tejbeer 846
            String fofoStoreCode = StringUtils.generateFofoStoreSequence(
32615 raveendra. 847
                    districtMaster.getStateShortName() + districtMaster.getShortName(), nextStoreCodeInt);
31734 tejbeer 848
            fofoStore.setCode(fofoStoreCode);
32615 raveendra. 849
            fofoStore.setCodeInt(nextStoreCodeInt);
31734 tejbeer 850
            fofoStore.setBagsLastCredited(LocalDateTime.now());
851
            fofoStore.setFofoType(updateRetailerRequest.getFofoType());
852
            fofoStore.setActivationType(ActivationType.ACTIVE);
853
            fofoStoreRepository.persist(fofoStore);
28908 tejbeer 854
 
31734 tejbeer 855
            // Auto fill in onboarding Panel
856
            PartnerOnBoardingPanel pobp = partnerOnBoardingPanelRepository.selectByPhoneNumber(Long.parseLong(retailerAddress.getPhoneNumber()));
857
            if (pobp != null) {
28908 tejbeer 858
 
31734 tejbeer 859
                PartnerVerificationpanel partnerVerificationpanel = partnerOnboardingVerificationRepository.selectByOnboardingId(pobp.getId());
29042 tejbeer 860
 
31734 tejbeer 861
                if (partnerVerificationpanel != null) {
862
                    if (partnerVerificationpanel.getApproval().equals(PartnerVerificationApprovalStatus.YES)) {
863
                        pobp.setCode(fofoStore.getCode());
29042 tejbeer 864
 
31734 tejbeer 865
                        storeTimelineTatService.onCodeCreated(pobp.getId());
29042 tejbeer 866
 
31734 tejbeer 867
                    }
29042 tejbeer 868
 
31734 tejbeer 869
                }
29042 tejbeer 870
 
31734 tejbeer 871
            }
30719 tejbeer 872
 
31734 tejbeer 873
            PincodePartner pincodePartner = pincodePartnerRepository.selectPartnerByPincode(retailerAddress.getPinCode(), fofoStore.getId());
874
            if (pincodePartner == null) {
875
                PincodePartner pinPartner = new PincodePartner();
876
                pinPartner.setFofoId(fofoStore.getId());
877
                pinPartner.setPincode(retailerAddress.getPinCode());
878
                pincodePartnerRepository.perist(pinPartner);
879
            }
880
        }
23955 govind 881
 
31734 tejbeer 882
        return fofoStore;
883
    }
23955 govind 884
 
31734 tejbeer 885
    @Override
33128 amit.gupta 886
    public FofoStore createFofoStoreCodeByUserId(int userId, String districtName, String
887
            stateName, UpdateRetailerRequest updateRetailerRequest) throws ProfitMandiBusinessException {
31734 tejbeer 888
        User user = userRepository.selectById(userId);
889
        // = userAccountRepository.selectRetailerIdByUserId(user.getId());
890
        UserAccount userAccounts = userAccountRepository.selectSaholicByUserId(user.getId());
891
        Retailer retailer = retailerRepository.selectById(userAccounts.getAccountKey());
892
        Role roleFofo = roleRepository.selectByName(RoleType.FOFO.toString());
893
        try {
894
            userRoleRepository.selectByUserIdAndRoleId(user.getId(), roleFofo.getId());
895
        } catch (ProfitMandiBusinessException profitMandiBusinessException) {
896
            throw new ProfitMandiBusinessException(ProfitMandiConstants.USER_ID, user.getId(), "USR_1013");
897
        }
898
        return this.createFofoStoreCodeByRetailerId(retailer.getId(), districtName, stateName, updateRetailerRequest);
23955 govind 899
 
31734 tejbeer 900
    }
23955 govind 901
 
31734 tejbeer 902
    @Override
903
    public List<DistrictMaster> getAllDistrictMaster(String stateName) {
904
        // StateInfo stateInfo = null;
905
        State stateInfo = null;
906
        try {
907
            // stateInfo = Utils.getStateInfo(stateName);
30525 tejbeer 908
 
31734 tejbeer 909
            stateInfo = stateRepository.selectByName(stateName);
910
        } catch (Exception e) {
911
            e.printStackTrace();
912
            // throw new ProfitMandiBusinessException();
913
        }
914
        return districtMasterRepository.selectByStateShortName(stateInfo.getShortName());
915
    }
22980 ashik.ali 916
 
31734 tejbeer 917
    @Override
33247 ranu 918
    public Map<Integer, CustomRetailer> getFofoRetailers(List<Integer> fofoIds) throws ProfitMandiBusinessException {
31734 tejbeer 919
        List<com.spice.profitmandi.dao.entity.user.User> saholicUsers = userUserRepository.selectByIds(fofoIds);
920
        Map<Integer, com.spice.profitmandi.dao.entity.user.User> userAddressMap = saholicUsers.stream().filter(x -> x.getAddressId() != null).collect(Collectors.toMap(x -> x.getAddressId(), x -> x));
921
        List<Address> addresses = addressRepository.selectByIds(new ArrayList<>(userAddressMap.keySet()));
922
        Map<Integer, CustomRetailer> customRetailersMap = new HashMap<>();
923
        for (Address address : addresses) {
924
            com.spice.profitmandi.dao.entity.user.User user = userAddressMap.get(address.getId());
925
            CustomRetailer customRetailer = new CustomRetailer();
926
            customRetailer.setEmail(user.getEmailId());
927
            customRetailer.setBusinessName(address.getName());
928
            customRetailer.setMobileNumber(address.getPhoneNumber());
929
            try {
930
                FofoStore fs = fofoStoreRepository.selectByRetailerId(address.getRetaierId());
931
                customRetailer.setCode(fs.getCode());
33553 ranu 932
                customRetailer.setAstId(fs.getAstId());
31734 tejbeer 933
                customRetailer.setActivationType(fs.getActivationType());
934
                customRetailer.setCounterSize(fs.getCounterSize());
31180 tejbeer 935
 
31743 tejbeer 936
 
937
                customRetailer.setCounterPotential(fs.getCounterPotential());
938
 
31734 tejbeer 939
                customRetailer.setWarehouseId(fs.getWarehouseId());
940
                customRetailer.setPartnerId(fs.getId());
941
                customRetailer.setFofoType(fs.getFofoType());
942
            } catch (Exception e) {
943
                continue;
944
            }
945
            try {
946
                customRetailer.setCartId(user.getActiveCartId());
947
                PrivateDealUser pdu = privateDealUserRepository.selectById(address.getRetaierId());
948
                Counter counter = counterRepository.selectById(pdu.getCounterId());
949
                customRetailer.setGstNumber(counter.getGstin());
950
            } catch (Exception e) {
951
                customRetailer.setGstNumber(null);
952
            }
953
            CustomAddress address1 = new CustomAddress();
954
            address1.setCity(address.getCity());
955
            address1.setState(address.getState());
956
            address1.setLine1(address.getLine1());
957
            address1.setLine2(address.getLine2());
958
            address1.setPinCode(address.getPinCode());
959
            address1.setName(address.getName());
960
            customRetailer.setAddress(address1);
961
            customRetailer.setDisplayName(
962
                    customRetailer.getBusinessName() + "-" + customRetailer.getCode() + "- " + address1.getCity());
963
            customRetailersMap.put(customRetailer.getPartnerId(), customRetailer);
964
        }
965
        return customRetailersMap;
966
    }
25295 amit.gupta 967
 
31734 tejbeer 968
    @Override
969
    @Cacheable(value = "getFofoRetailer", cacheManager = "thirtyMinsTimeOutCacheManager")
970
    public CustomRetailer getFofoRetailer(int fofoId) throws ProfitMandiBusinessException {
971
        com.spice.profitmandi.dao.entity.user.User saholicUser = userUserRepository.selectById(fofoId);
31862 tejbeer 972
 
973
        User dtrUser = userRepository.selectByEmailId(saholicUser.getEmailId());
31734 tejbeer 974
        FofoStore store = fofoStoreRepository.selectByRetailerId(fofoId);
975
        Address address = null;
976
        try {
977
            address = addressRepository.selectById(saholicUser.getAddressId());
978
        } catch (ProfitMandiBusinessException e1) {
979
            // TODO Auto-generated catch block
980
            e1.printStackTrace();
981
        }
982
        Map<Integer, CustomRetailer> customRetailersMap = new HashMap<>();
983
        CustomRetailer customRetailer = new CustomRetailer();
984
        customRetailer.setEmail(saholicUser.getEmailId());
985
        customRetailer.setBusinessName(address.getName());
986
        customRetailer.setMobileNumber(address.getPhoneNumber());
31862 tejbeer 987
        customRetailer.setFirstName(dtrUser.getFirstName());
988
        customRetailer.setLastName(dtrUser.getLastName());
31734 tejbeer 989
        try {
990
            customRetailer.setCartId(saholicUser.getActiveCartId());
991
            PrivateDealUser pdu = privateDealUserRepository.selectById(address.getRetaierId());
992
            Counter counter = counterRepository.selectById(pdu.getCounterId());
993
            customRetailer.setGstNumber(counter.getGstin());
994
        } catch (Exception e) {
995
            customRetailer.setGstNumber(null);
996
        }
997
        CustomAddress address1 = new CustomAddress();
998
        address1.setCity(address.getCity());
999
        address1.setState(address.getState());
1000
        address1.setLine1(address.getLine1());
1001
        address1.setLine2(address.getLine2());
1002
        address1.setPinCode(address.getPinCode());
1003
        address1.setPhoneNumber(address.getPhoneNumber());
1004
        address1.setName(address.getName());
1005
        customRetailer.setDisplayName(address.getName() + " - " + address.getCity());
1006
        customRetailer.setAddress(address1);
1007
        customRetailer.setPartnerId(address.getRetaierId());
1008
        customRetailer.setCode(store.getCode());
33553 ranu 1009
        customRetailer.setAstId(store.getAstId());
31734 tejbeer 1010
        customRetailer.setActivationType(store.getActivationType());
1011
        customRetailer.setWarehouseId(store.getWarehouseId());
1012
        customRetailersMap.put(address.getRetaierId(), customRetailer);
1013
        return customRetailer;
25295 amit.gupta 1014
 
31734 tejbeer 1015
    }
26125 amit.gupta 1016
 
31734 tejbeer 1017
    @Override
33247 ranu 1018
    public Map<Integer, CustomRetailer> getFofoRetailerUserId(List<Integer> fofoIds) throws ProfitMandiBusinessException {
31734 tejbeer 1019
        List<com.spice.profitmandi.dao.entity.user.User> saholicUsers = userUserRepository.selectByIds(fofoIds);
1020
        Map<Integer, com.spice.profitmandi.dao.entity.user.User> userAddressMap = saholicUsers.stream().filter(x -> x.getAddressId() != null).collect(Collectors.toMap(x -> x.getAddressId(), x -> x));
1021
        List<Address> addresses = addressRepository.selectByIds(new ArrayList<>(userAddressMap.keySet()));
1022
        Map<Integer, CustomRetailer> customRetailersMap = new HashMap<>();
1023
        for (Address address : addresses) {
1024
            com.spice.profitmandi.dao.entity.user.User user = userAddressMap.get(address.getId());
1025
            CustomRetailer customRetailer = new CustomRetailer();
1026
            customRetailer.setEmail(user.getEmailId());
1027
            customRetailer.setBusinessName(address.getName());
1028
            customRetailer.setMobileNumber(address.getPhoneNumber());
1029
            int userId = 0;
1030
            try {
1031
                userId = userAccountRepository.selectUserIdByRetailerId(user.getId());
1032
            } catch (ProfitMandiBusinessException e) {
1033
                continue;
1034
            }
1035
            try {
1036
                customRetailer.setCartId(user.getActiveCartId());
1037
                PrivateDealUser pdu = privateDealUserRepository.selectById(address.getRetaierId());
1038
                Counter counter = counterRepository.selectById(pdu.getCounterId());
1039
                customRetailer.setGstNumber(counter.getGstin());
1040
            } catch (Exception e) {
1041
                customRetailer.setGstNumber(null);
1042
            }
1043
            CustomAddress address1 = new CustomAddress();
1044
            address1.setCity(address.getCity());
1045
            address1.setState(address.getState());
1046
            address1.setLine1(address.getLine1());
1047
            address1.setLine2(address.getLine2());
1048
            address1.setPinCode(address.getPinCode());
1049
            address1.setName(address.getName());
1050
            customRetailer.setAddress(address1);
1051
            customRetailer.setPartnerId(address.getRetaierId());
1052
            customRetailer.setDisplayName(customRetailer.getBusinessName() + "-" + address1.getCity());
1053
            customRetailersMap.put(userId, customRetailer);
1054
        }
1055
        return customRetailersMap;
1056
    }
25295 amit.gupta 1057
 
31734 tejbeer 1058
    @Override
33247 ranu 1059
    public Map<Integer, String> getAllFofoRetailerIdEmailIdMap() throws ProfitMandiBusinessException {
31734 tejbeer 1060
        Role roleFofo = null;
1061
        try {
1062
            roleFofo = roleRepository.selectByName(RoleType.FOFO.toString());
1063
        } catch (ProfitMandiBusinessException e) {
1064
            // TODO Auto-generated catch block
1065
            e.printStackTrace();
1066
        }
1067
        Role roleRetailer = null;
1068
        try {
1069
            roleRetailer = roleRepository.selectByName(RoleType.RETAILER.toString());
1070
        } catch (ProfitMandiBusinessException e) {
1071
            // TODO Auto-generated catch block
1072
            e.printStackTrace();
1073
        }
1074
        Set<Integer> roleIds = new HashSet<>();
1075
        roleIds.add(roleFofo.getId());
1076
        roleIds.add(roleRetailer.getId());
1077
        List<Integer> userIds = userRoleRepository.selectUserIdsByRoleIds(roleIds);
1078
        List<User> users = userRepository.selectAllByIds(new HashSet<>(userIds));
1079
        Map<Integer, Integer> userIdRetailerIdMap = this.getUserIdRetailerIdMap(userIds);
1080
        Map<Integer, String> retailerIdEmailIdMap = new HashMap<>();
1081
        for (User user : users) {
1082
            retailerIdEmailIdMap.put(userIdRetailerIdMap.get(user.getId()), user.getEmailId());
1083
        }
1084
        return retailerIdEmailIdMap;
1085
    }
23955 govind 1086
 
31734 tejbeer 1087
    private Map<Integer, Integer> getUserIdRetailerIdMap(List<Integer> userIds) {
1088
        List<UserAccount> userAccounts = userAccountRepository.selectAllSaholicByUserIds(new HashSet<>(userIds));
1089
        Map<Integer, Integer> userIdRetailerIdMap = new HashMap<>();
1090
        for (UserAccount userAccount : userAccounts) {
1091
            userIdRetailerIdMap.put(userAccount.getUserId(), userAccount.getAccountKey());
1092
        }
1093
        return userIdRetailerIdMap;
1094
    }
25295 amit.gupta 1095
 
33247 ranu 1096
    private Map<Integer, String> getUserIdEmailIdMap(Set<Integer> userIds) throws ProfitMandiBusinessException {
31734 tejbeer 1097
        List<User> users = userRepository.selectAllByIds(userIds);
1098
        Map<Integer, String> userIdEmailIdMap = new HashMap<>();
1099
        for (User user : users) {
1100
            userIdEmailIdMap.put(user.getId(), user.getEmailId());
1101
        }
1102
        return userIdEmailIdMap;
1103
    }
23509 amit.gupta 1104
 
31734 tejbeer 1105
    @Override
33247 ranu 1106
    public Map<Integer, String> getAllFofoRetailerIdEmailIdMap(Set<Integer> retailerIds) throws ProfitMandiBusinessException {
31734 tejbeer 1107
        List<UserAccount> userAccounts = userAccountRepository.selectAllSaholicByRetailerIds(retailerIds);
1108
        Set<Integer> userIds = new HashSet<>();
1109
        for (UserAccount userAccount : userAccounts) {
1110
            userIds.add(userAccount.getUserId());
1111
        }
1112
        Map<Integer, String> retailerIdEmailIdMap = new HashMap<>();
1113
        Map<Integer, String> userIdEmailIdMap = this.getUserIdEmailIdMap(userIds);
1114
        for (UserAccount userAccount : userAccounts) {
1115
            retailerIdEmailIdMap.put(userAccount.getAccountKey(), userIdEmailIdMap.get(userAccount.getUserId()));
1116
        }
1117
        return retailerIdEmailIdMap;
1118
    }
25295 amit.gupta 1119
 
31734 tejbeer 1120
    @Override
33247 ranu 1121
    public Map<Integer, String> getAllFofoRetailerIdNameMap(List<Integer> storeIds) throws ProfitMandiBusinessException {
31734 tejbeer 1122
        Map<Integer, CustomRetailer> retailersMap = this.getFofoRetailers(storeIds);
1123
        Map<Integer, String> retailerIdNameMap = new HashMap<>();
1124
        for (Map.Entry<Integer, CustomRetailer> entry : retailersMap.entrySet()) {
1125
            retailerIdNameMap.put(entry.getKey(), entry.getValue().getBusinessName() + "-" + entry.getValue().getAddress().getCity());
1126
        }
1127
        return retailerIdNameMap;
1128
    }
24168 amit.gupta 1129
 
31734 tejbeer 1130
    @Override
1131
    @Cacheable(value = "FofoRetailerIdNameMap", cacheManager = "thirtyMinsTimeOutCacheManager")
33247 ranu 1132
    public Map<Integer, String> getAllFofoRetailerIdNameMap() throws ProfitMandiBusinessException {
31734 tejbeer 1133
        List<FofoStore> stores = fofoStoreRepository.selectAll();
1134
        List<Integer> storeIds = stores.stream().map(x -> x.getId()).collect(Collectors.toList());
1135
        return this.getAllFofoRetailerIdNameMap(storeIds);
1136
    }
24349 amit.gupta 1137
 
31734 tejbeer 1138
    @Override
33247 ranu 1139
    public List<MapWrapper<Integer, String>> getAllFofoRetailerIdNameList() throws ProfitMandiBusinessException {
31734 tejbeer 1140
        List<MapWrapper<Integer, String>> mapWrappers = new ArrayList<>();
1141
        // TODO Auto-generated method stub
1142
        Map<Integer, String> fofoIdNameMap = this.getAllFofoRetailerIdNameMap();
1143
        fofoIdNameMap.forEach((fofoId, name) -> {
1144
            MapWrapper<Integer, String> idWrapper = new MapWrapper<>();
1145
            idWrapper.setKey(fofoId);
1146
            idWrapper.setValue(name);
1147
            mapWrappers.add(idWrapper);
1148
        });
1149
        return mapWrappers;
1150
    }
24349 amit.gupta 1151
 
31734 tejbeer 1152
    @Override
1153
    @Cacheable(value = "retailerNames", cacheManager = "thirtyMinsTimeOutCacheManager")
33247 ranu 1154
    public Map<Integer, CustomRetailer> getFofoRetailers(boolean activeOnly) throws ProfitMandiBusinessException {
31734 tejbeer 1155
        // TODO Auto-generated method stub
1156
        Stream<FofoStore> storeStream = fofoStoreRepository.selectAll().stream().filter(x -> !x.isInternal());
1157
        if (activeOnly) {
1158
            storeStream = storeStream.filter(x -> x.isActive());
1159
        }
1160
        List<Integer> storeIds = storeStream.map(x -> x.getId()).collect(Collectors.toList());
1161
        return this.getFofoRetailers(storeIds);
1162
    }
25295 amit.gupta 1163
 
31734 tejbeer 1164
    @Override
33367 ranu 1165
    @Cacheable(value = "retailerNames", cacheManager = "thirtyMinsTimeOutCacheManager")
1166
    public Map<Integer, CustomRetailer> getFofoRetailers(boolean activeOnly, String pinCode) throws ProfitMandiBusinessException {
1167
        List<PincodePartner> pincodePartners = pincodePartnerRepository.selectPartnersByPincode(pinCode);
1168
        List<Integer> storeIds = new ArrayList<>();
1169
        if (pincodePartners.size() > 0) {
1170
            List<Integer> fofoIds = pincodePartners.stream().map(x -> x.getFofoId()).collect(Collectors.toList());
1171
            List<FofoStore> fofoStores = fofoStoreRepository.selectActivePartnersByRetailerIds(fofoIds);
1172
            storeIds = fofoStores.stream().map(x -> x.getId()).collect(Collectors.toList());
1173
        }
1174
        return this.getFofoRetailers(storeIds);
1175
    }
1176
 
1177
    @Override
31734 tejbeer 1178
    @Cacheable(value = "allFofoRetailers", cacheManager = "thirtyMinsTimeOutCacheManager")
33247 ranu 1179
    public Map<Integer, CustomRetailer> getAllFofoRetailers() throws ProfitMandiBusinessException {
31734 tejbeer 1180
        // TODO Auto-generated method stub
1181
        Stream<FofoStore> storeStream = fofoStoreRepository.selectAll().stream();
27861 tejbeer 1182
 
31734 tejbeer 1183
        List<Integer> storeIds = storeStream.map(x -> x.getId()).collect(Collectors.toList());
1184
        return this.getFofoRetailers(storeIds);
1185
    }
27861 tejbeer 1186
 
31734 tejbeer 1187
    @Override
33128 amit.gupta 1188
    public LoginRequestResponseModel registerWebUser(LoginRequestResponseModel loginRequestModel) throws
1189
            ProfitMandiBusinessException {
26522 amit.gupta 1190
 
31734 tejbeer 1191
        com.spice.profitmandi.dao.entity.user.User saholicUser = this.createSaholicUser(loginRequestModel);
1192
        loginRequestModel.setUserId(saholicUser.getId());
26522 amit.gupta 1193
 
31734 tejbeer 1194
        this.createRetailerAddress(loginRequestModel);
26522 amit.gupta 1195
 
31734 tejbeer 1196
        this.createPrivateDealUser(loginRequestModel);
1197
        this.updateSaholicUser(saholicUser.getId(), loginRequestModel.getBusinessAddress().getId());
26522 amit.gupta 1198
 
31734 tejbeer 1199
        return loginRequestModel;
26522 amit.gupta 1200
 
31734 tejbeer 1201
    }
26522 amit.gupta 1202
 
31734 tejbeer 1203
    private void createPrivateDealUser(LoginRequestResponseModel loginRequestModel) {
26522 amit.gupta 1204
 
31734 tejbeer 1205
        Integer counterId = this.createCounter(loginRequestModel.getEmail(), loginRequestModel.getGstNumber(), loginRequestModel.getBusinessAddress().getPhoneNumber(), loginRequestModel.getBusinessAddress().getName(), loginRequestModel.getBusinessAddress().getId());
1206
        try {
1207
            this.createPrivateDealUser(loginRequestModel.getUserId(), counterId, false);
1208
        } catch (Exception e) {
1209
            LOGGER.error("ERROR : ", e);
1210
        }
26522 amit.gupta 1211
 
31734 tejbeer 1212
        PrivateDealUserAddressMapping privateDealUserAddressMapping = new PrivateDealUserAddressMapping();
1213
        privateDealUserAddressMapping.setUserId(loginRequestModel.getUserId());
1214
        privateDealUserAddressMapping.setAddressId(loginRequestModel.getBusinessAddress().getId());
1215
        privateDealUserAddressMappingRepository.persist(privateDealUserAddressMapping);
26522 amit.gupta 1216
 
31734 tejbeer 1217
    }
26522 amit.gupta 1218
 
33128 amit.gupta 1219
    private void createRetailerAddress(LoginRequestResponseModel loginRequestResponseModel) throws
1220
            ProfitMandiBusinessException {
31734 tejbeer 1221
        Address businessAddress = loginRequestResponseModel.getBusinessAddress();
1222
        businessAddress.setRetaierId(loginRequestResponseModel.getUserId());
1223
        addressRepository.persist(businessAddress);
1224
    }
26536 amit.gupta 1225
 
31734 tejbeer 1226
    private String getHash256(String originalString) {
1227
        String hashString = Hashing.sha256().hashString(originalString, StandardCharsets.UTF_8).toString();
1228
        LOGGER.info("Hash String {}", hashString);
1229
        return hashString;
1230
    }
26533 amit.gupta 1231
 
31734 tejbeer 1232
    @Override
1233
    @Cacheable(value = "fofoIdUrl", cacheManager = "thirtyMinsTimeOutCacheManager")
1234
    public Map<Integer, String> getAllFofoRetailerIdUrlMap() {
1235
        Map<Integer, String> fofoRetailerUrlMap = new HashMap<>();
1236
        List<FofoStore> stores = fofoStoreRepository.selectAll().stream().filter(x -> x.isActive()).collect(Collectors.toList());
1237
        Map<Integer, com.spice.profitmandi.dao.entity.user.User> userMap = userUserRepository.selectByIds(stores.stream().map(x -> x.getId()).collect(Collectors.toList())).stream().collect(Collectors.toMap(x -> x.getId(), x -> x));
1238
        for (FofoStore store : stores) {
1239
            LOGGER.info("Store is {}", store);
1240
            String districtShortName = store.getCode().replaceAll("\\d+", "").substring(2);
1241
            String stateShortName = store.getCode().replaceAll("\\d+", "").substring(0, 2);
1242
            DistrictMaster districtMaster = null;
1243
            LOGGER.info("Store shortname is {}", districtShortName);
1244
            districtMaster = districtMasterRepository.selectByShortnameNameAndStateShortName(districtShortName, stateShortName);
1245
            if (districtMaster == null) {
1246
                districtMaster = districtMasterRepository.selectByShortnameNameAndStateShortName("FB", "HR");
1247
            }
1248
            LOGGER.info("Store id - {}", store.getId());
1249
            // com.spice.profitmandi.dao.entity.user.User user = userMap.get(store.getId());
1250
            String urlString = districtMaster.getStateShortName() + "/" + Utils.getHyphenatedString(districtMaster.getName()) + "/" + store.getCode();
1251
            fofoRetailerUrlMap.put(store.getId(), urlString.toLowerCase());
1252
            LOGGER.info("Store is {} end", store);
26536 amit.gupta 1253
 
31734 tejbeer 1254
        }
1255
        return fofoRetailerUrlMap;
1256
    }
26533 amit.gupta 1257
 
31734 tejbeer 1258
    @Override
1259
    @Cacheable(value = "storeCodeRetailerMap", cacheManager = "thirtyMinsTimeOutCacheManager")
1260
    public Map<String, Integer> getStoreCodeRetailerMap() {
1261
        Map<Integer, String> map = this.getAllFofoRetailerIdUrlMap();
1262
        Map<String, Integer> returnMap = map.entrySet().stream().collect(Collectors.toMap(x -> {
1263
            String[] splitString = x.getValue().split("/");
1264
            return splitString[splitString.length - 1];
1265
        }, x -> x.getKey()));
1266
        LOGGER.info("returnMap {}", returnMap);
1267
        return returnMap;
1268
    }
27877 amit.gupta 1269
 
1270
 
31734 tejbeer 1271
    @Override
32668 raveendra. 1272
    public User getEmail() {
1273
        return null;
1274
    }
1275
 
1276
    @Override
1277
    public void update(com.spice.profitmandi.dao.entity.user.User user) {
1278
    }
1279
 
1280
    @Override
1281
    public void updateRetailerEmail(int fofoId, String newEmail) throws ProfitMandiBusinessException {
1282
        User dtrUser = null;
1283
        com.spice.profitmandi.dao.entity.user.User user = null;
1284
 
1285
        try {
1286
            dtrUser = userRepository.selectByEmailId(newEmail);
1287
        } catch (Exception e) {
1288
        }
1289
 
1290
        try {
1291
            user = userUserRepository.selectByEmailId(newEmail);
1292
        } catch (Exception e) {
1293
        }
1294
 
1295
        if (user != null || dtrUser != null) {
1296
            throw new ProfitMandiBusinessException("Email", newEmail, "Email already exist");
1297
        }
1298
        com.spice.profitmandi.dao.entity.user.User fofoUser = userUserRepository.selectById(fofoId);
1299
        String oldEmail = fofoUser.getEmailId();
1300
        LOGGER.info("old email {}", oldEmail);
1301
        User thisDtrUser = userRepository.selectByEmailId(oldEmail);
1302
 
1303
        fofoUser.setEmailId(newEmail);
1304
        thisDtrUser.setEmailId(newEmail);
1305
    }
1306
 
1307
 
32953 amit.gupta 1308
    //    @Override
32737 amit.gupta 1309
    @Cacheable(value = "getContactsByFofoId", cacheManager = "oneDayCacheManager")
33128 amit.gupta 1310
    public List<RetailerContact> getContactsByFofoId(int fofoId, boolean activeOnly) throws
1311
            ProfitMandiBusinessException {
32737 amit.gupta 1312
        List<RetailerContact> retailerContacts = retailerContactRepository.selectAllByRetailerId(fofoId, activeOnly);
1313
        com.spice.profitmandi.dao.entity.user.User user = userUserRepository.selectById(fofoId);
1314
        RetailerContact retailerContact = new RetailerContact();
1315
        retailerContact.setMobile(user.getMobileNumber());
1316
        retailerContact.setName(user.getName());
1317
        retailerContact.setActive(true);
1318
        retailerContact.setFofoId(fofoId);
1319
        retailerContacts.add(retailerContact);
1320
        return retailerContacts;
1321
    }
1322
 
1323
 
1324
    @Override
33128 amit.gupta 1325
    public Map<Integer, CustomRetailer> getFofoRetailersPaginated(boolean activeOnly, int offset,
33247 ranu 1326
                                                                  int limit, FofoType fofoType) throws ProfitMandiBusinessException {
30097 tejbeer 1327
 
31734 tejbeer 1328
        Stream<FofoStore> storeStream = fofoStoreRepository.selectByStatusFofoType(activeOnly, fofoType, offset, limit).stream();
30219 tejbeer 1329
 
31734 tejbeer 1330
        List<Integer> storeIds = storeStream.map(x -> x.getId()).collect(Collectors.toList());
1331
        return this.getFofoRetailers(storeIds);
1332
    }
30219 tejbeer 1333
 
22980 ashik.ali 1334
}