Subversion Repositories SmartDukaan

Rev

Rev 23942 | Rev 23957 | 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
 
23300 amit.gupta 3
import java.time.LocalDateTime;
23060 ashik.ali 4
import java.util.ArrayList;
22980 ashik.ali 5
import java.util.HashMap;
23781 ashik.ali 6
import java.util.HashSet;
22980 ashik.ali 7
import java.util.List;
8
import java.util.Map;
9
import java.util.Set;
10
import java.util.function.Function;
11
import java.util.stream.Collectors;
12
 
23781 ashik.ali 13
import org.apache.logging.log4j.LogManager;
23568 govind 14
import org.apache.logging.log4j.Logger;
22980 ashik.ali 15
import org.springframework.beans.factory.annotation.Autowired;
23043 ashik.ali 16
import org.springframework.beans.factory.annotation.Qualifier;
22980 ashik.ali 17
import org.springframework.stereotype.Component;
18
 
23378 ashik.ali 19
import com.spice.profitmandi.common.ResponseCodeHolder;
23955 govind 20
import com.spice.profitmandi.common.enumuration.CounterSize;
22980 ashik.ali 21
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
23025 ashik.ali 22
import com.spice.profitmandi.common.model.CustomAddress;
23509 amit.gupta 23
import com.spice.profitmandi.common.model.CustomRetailer;
23025 ashik.ali 24
import com.spice.profitmandi.common.model.CustomShop;
23781 ashik.ali 25
import com.spice.profitmandi.common.model.MapWrapper;
23329 ashik.ali 26
import com.spice.profitmandi.common.model.ProfitMandiConstants;
23025 ashik.ali 27
import com.spice.profitmandi.common.model.UpdateRetailerRequest;
23329 ashik.ali 28
import com.spice.profitmandi.common.util.StringUtils;
29
import com.spice.profitmandi.common.util.Utils;
30
import com.spice.profitmandi.dao.entity.dtr.DistrictMaster;
22980 ashik.ali 31
import com.spice.profitmandi.dao.entity.dtr.Retailer;
23043 ashik.ali 32
import com.spice.profitmandi.dao.entity.dtr.RetailerRegisteredAddress;
23781 ashik.ali 33
import com.spice.profitmandi.dao.entity.dtr.Role;
22980 ashik.ali 34
import com.spice.profitmandi.dao.entity.dtr.Shop;
35
import com.spice.profitmandi.dao.entity.dtr.ShopAddress;
36
import com.spice.profitmandi.dao.entity.dtr.User;
23269 ashik.ali 37
import com.spice.profitmandi.dao.entity.dtr.UserAccount;
22980 ashik.ali 38
import com.spice.profitmandi.dao.entity.dtr.UserRole;
23365 ashik.ali 39
import com.spice.profitmandi.dao.entity.fofo.FofoPartnerPaymentOption;
23329 ashik.ali 40
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
23365 ashik.ali 41
import com.spice.profitmandi.dao.entity.fofo.PaymentOption;
22980 ashik.ali 42
import com.spice.profitmandi.dao.entity.user.Address;
23043 ashik.ali 43
import com.spice.profitmandi.dao.entity.user.Cart;
23329 ashik.ali 44
import com.spice.profitmandi.dao.entity.user.Counter;
45
import com.spice.profitmandi.dao.entity.user.PrivateDealUser;
46
import com.spice.profitmandi.dao.entity.user.PrivateDealUserAddressMapping;
23063 ashik.ali 47
import com.spice.profitmandi.dao.enumuration.dtr.AccountType;
23106 ashik.ali 48
import com.spice.profitmandi.dao.enumuration.dtr.RetailerType;
23136 ashik.ali 49
import com.spice.profitmandi.dao.enumuration.dtr.RoleType;
23365 ashik.ali 50
import com.spice.profitmandi.dao.enumuration.fofo.PaymentOptionType;
23329 ashik.ali 51
import com.spice.profitmandi.dao.repository.dtr.DistrictMasterRepository;
22980 ashik.ali 52
import com.spice.profitmandi.dao.repository.dtr.DocumentRepository;
23329 ashik.ali 53
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
22980 ashik.ali 54
import com.spice.profitmandi.dao.repository.dtr.RetailerRegisteredAddressRepository;
55
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
23781 ashik.ali 56
import com.spice.profitmandi.dao.repository.dtr.RoleRepository;
23955 govind 57
import com.spice.profitmandi.dao.repository.dtr.RoleRepositoryImpl;
22980 ashik.ali 58
import com.spice.profitmandi.dao.repository.dtr.ShopAddressRepository;
59
import com.spice.profitmandi.dao.repository.dtr.ShopRepository;
60
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
61
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
62
import com.spice.profitmandi.dao.repository.dtr.UserRoleRepository;
23365 ashik.ali 63
import com.spice.profitmandi.dao.repository.fofo.FofoPartnerPaymentOptionRepository;
64
import com.spice.profitmandi.dao.repository.fofo.PaymentOptionRepository;
22980 ashik.ali 65
import com.spice.profitmandi.dao.repository.user.AddressRepository;
23043 ashik.ali 66
import com.spice.profitmandi.dao.repository.user.CartRepository;
23329 ashik.ali 67
import com.spice.profitmandi.dao.repository.user.CounterRepository;
68
import com.spice.profitmandi.dao.repository.user.PrivateDealUserAddressMappingRepository;
69
import com.spice.profitmandi.dao.repository.user.PrivateDealUserRepository;
22980 ashik.ali 70
 
23329 ashik.ali 71
import in.shop2020.model.v1.inventory.StateInfo;
23043 ashik.ali 72
import in.shop2020.model.v1.user.CartStatus;
73
 
22980 ashik.ali 74
@Component
75
public class RetailerServiceImpl implements RetailerService {
23955 govind 76
 
23568 govind 77
	private static final Logger LOGGER = LogManager.getLogger(RetailerServiceImpl.class);
23955 govind 78
 
22980 ashik.ali 79
	@Autowired
80
	private RetailerRepository retailerRepository;
23955 govind 81
 
22980 ashik.ali 82
	@Autowired
83
	private UserAccountRepository userAccountRepository;
23955 govind 84
 
22980 ashik.ali 85
	@Autowired
86
	private UserRepository userRepository;
23955 govind 87
 
22980 ashik.ali 88
	@Autowired
23043 ashik.ali 89
	private CartRepository cartRepository;
23955 govind 90
 
23043 ashik.ali 91
	@Autowired
22980 ashik.ali 92
	private RetailerRegisteredAddressRepository retailerRegisteredAddressRepository;
23955 govind 93
 
22980 ashik.ali 94
	@Autowired
95
	private AddressRepository addressRepository;
23955 govind 96
 
22980 ashik.ali 97
	@Autowired
98
	private ShopRepository shopRepository;
23955 govind 99
 
22980 ashik.ali 100
	@Autowired
101
	private ShopAddressRepository shopAddressRepository;
23955 govind 102
 
22980 ashik.ali 103
	@Autowired
104
	private UserRoleRepository userRoleRepository;
23955 govind 105
 
22980 ashik.ali 106
	@Autowired
107
	private DocumentRepository documentRepository;
23955 govind 108
 
23043 ashik.ali 109
	@Autowired
23329 ashik.ali 110
	private PrivateDealUserRepository privateDealUserRepository;
23955 govind 111
 
23329 ashik.ali 112
	@Autowired
113
	private PrivateDealUserAddressMappingRepository privateDealUserAddressMappingRepository;
23955 govind 114
 
23329 ashik.ali 115
	@Autowired
116
	private CounterRepository counterRepository;
23955 govind 117
 
23329 ashik.ali 118
	@Autowired
23043 ashik.ali 119
	@Qualifier("userUserRepository")
120
	private com.spice.profitmandi.dao.repository.user.UserRepository userUserRepository;
23955 govind 121
 
23329 ashik.ali 122
	@Autowired
123
	private DistrictMasterRepository districtMasterRepository;
23955 govind 124
 
23329 ashik.ali 125
	@Autowired
126
	private FofoStoreRepository fofoStoreRepository;
23955 govind 127
 
23329 ashik.ali 128
	@Autowired
23365 ashik.ali 129
	private PaymentOptionRepository paymentOptionRepository;
23955 govind 130
 
23365 ashik.ali 131
	@Autowired
132
	private FofoPartnerPaymentOptionRepository fofoPartnerPaymentOptionRepository;
23955 govind 133
 
23842 ashik.ali 134
	@Autowired
135
	private RoleRepository roleRepository;
23955 govind 136
 
22980 ashik.ali 137
	@Override
138
	public Map<String, Object> getByEmailIdOrMobileNumber(String emailIdOrMobileNumber)
139
			throws ProfitMandiBusinessException {
23202 ashik.ali 140
		User user = null;
23955 govind 141
		try {
23202 ashik.ali 142
			user = userRepository.selectByEmailIdOrMobileNumber(emailIdOrMobileNumber);
23955 govind 143
		} catch (ProfitMandiBusinessException profitMandiBusinessException) {
144
 
23202 ashik.ali 145
		}
23955 govind 146
		if (user == null) {
147
			try {
23329 ashik.ali 148
				user = userRepository.selectBySecondryEmailId(emailIdOrMobileNumber);
23955 govind 149
			} catch (ProfitMandiBusinessException profitMandiBusinessException) {
150
 
23329 ashik.ali 151
			}
23202 ashik.ali 152
		}
22980 ashik.ali 153
		Map<String, Object> map = new HashMap<>();
23329 ashik.ali 154
		map.put("stateNames", Utils.getAllStateNames());
23955 govind 155
 
156
		if (user != null) {
157
 
23329 ashik.ali 158
			List<UserRole> userRoles = userRoleRepository.selectByUserId(user.getId());
23955 govind 159
 
23781 ashik.ali 160
			Role role = roleRepository.selectByName(RoleType.FOFO.toString());
23955 govind 161
 
23329 ashik.ali 162
			map.put("userRoles", userRoles);
163
			map.put("user", user);
23955 govind 164
			// map.put("retailer", retailer);
23781 ashik.ali 165
			map.put("fofoRole", this.containsRoleType(userRoles, role.getId()));
23955 govind 166
 
23329 ashik.ali 167
			map.put("userRoleNames", this.toString(userRoles));
23955 govind 168
			try {
23329 ashik.ali 169
				int retailerId = userAccountRepository.selectRetailerIdByUserId(user.getId());
170
				Retailer retailer = retailerRepository.selectById(retailerId);
23955 govind 171
 
23329 ashik.ali 172
				map.put("retailer", retailer);
23955 govind 173
 
174
				if (this.containsRoleType(userRoles, role.getId())) {
175
					try {
23329 ashik.ali 176
						FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(retailerId);
177
						map.put("fofoStore", fofoStore);
23955 govind 178
						// map.put("counterSize", fofoStore.getCounterSize().toString());
179
						// LOGGER.info("fofoStore" + fofoStore);
180
					} catch (ProfitMandiBusinessException profitMandiBusinessException) {
23329 ashik.ali 181
						LOGGER.error("FofoStore code not found");
182
					}
183
				}
23955 govind 184
 
185
				try {
23329 ashik.ali 186
					PrivateDealUser privateDealUser = privateDealUserRepository.selectById(retailer.getId());
23955 govind 187
					if (privateDealUser.getCounterId() != null) {
23329 ashik.ali 188
						Counter counter = counterRepository.selectById(privateDealUser.getCounterId());
189
						map.put("gstNumber", counter.getGstin());
23955 govind 190
						// LOGGER.info("gstNumber" + counter.getGstin());
23329 ashik.ali 191
					}
23955 govind 192
				} catch (ProfitMandiBusinessException profitMandiBusinessException) {
23329 ashik.ali 193
					LOGGER.error("PrivateDealUser not found");
194
				}
23955 govind 195
				try {
196
					int retailerAddressId = retailerRegisteredAddressRepository
197
							.selectAddressIdByRetailerId(retailer.getId());
23329 ashik.ali 198
					Address retailerAddress = addressRepository.selectById(retailerAddressId);
199
					map.put("retailerAddress", retailerAddress);
23955 govind 200
					// LOGGER.info("retailerAddress.." + retailerAddress);
23329 ashik.ali 201
					StateInfo stateInfo = null;
202
					try {
203
						stateInfo = Utils.getStateInfo(retailerAddress.getState());
23955 govind 204
						// LOGGER.info("stateInfo" + stateInfo);
23329 ashik.ali 205
					} catch (Exception e) {
206
						e.printStackTrace();
23955 govind 207
						// throw new ProfitMandiBusinessException();
23329 ashik.ali 208
					}
23955 govind 209
					List<DistrictMaster> districtMasters = districtMasterRepository
210
							.selectByStateShortName(stateInfo.getShortName());
23329 ashik.ali 211
					map.put("districtMasters", districtMasters);
23955 govind 212
					// LOGGER.info("districtMasters" + districtMasters);
23329 ashik.ali 213
					List<Shop> shops = shopRepository.selectByRetailerId(retailer.getId());
23955 govind 214
					map.put("shops", shops);
23329 ashik.ali 215
					this.addAddress(shops);
23955 govind 216
					// LOGGER.info("shops" + shops);
217
				} catch (ProfitMandiBusinessException profitMandiBusinessException) {
23329 ashik.ali 218
					LOGGER.error("Retailer Registered Address not found");
219
				}
23955 govind 220
			} catch (ProfitMandiBusinessException profitMandiBusinessException) {
23329 ashik.ali 221
				LOGGER.error("Retailer not found in user_account");
23043 ashik.ali 222
			}
223
		}
23955 govind 224
 
22980 ashik.ali 225
		return map;
226
	}
23955 govind 227
 
228
	private boolean containsRoleType(List<UserRole> userRoles, int roleId) {
229
		for (UserRole userRole : userRoles) {
230
			if (userRole.getRoleId() == roleId) {
23329 ashik.ali 231
				return true;
232
			}
233
		}
234
		return false;
235
	}
23955 govind 236
 
237
	private List<UserRole> addRole(List<UserRole> userRoles, int userId, int roleId) {
238
		if (userRoles == null) {
23329 ashik.ali 239
			userRoles = new ArrayList<>();
240
		}
23955 govind 241
		if (!this.containsRoleType(userRoles, roleId)) {
23329 ashik.ali 242
			UserRole userRole = new UserRole();
243
			userRole.setUserId(userId);
23781 ashik.ali 244
			userRole.setRoleId(roleId);
23329 ashik.ali 245
			try {
246
				userRoleRepository.persist(userRole);
247
			} catch (ProfitMandiBusinessException e) {
248
				LOGGER.error("UserRole is already exist");
249
			}
250
			userRoles.add(userRole);
251
		}
252
		return userRoles;
23955 govind 253
 
23329 ashik.ali 254
	}
23955 govind 255
 
22980 ashik.ali 256
	@SuppressWarnings("unchecked")
257
	@Override
23025 ashik.ali 258
	public Map<String, Object> updateRetailerDetails(UpdateRetailerRequest updateRetailerRequest)
259
			throws ProfitMandiBusinessException {
260
		Map<String, Object> map = this.getByEmailIdOrMobileNumber(updateRetailerRequest.getEmailIdOrMobileNumber());
23955 govind 261
		User user = (User) map.get("user");
23329 ashik.ali 262
		user = this.createUser(user, updateRetailerRequest);
263
		map.put("user", user);
23955 govind 264
		List<UserRole> userRoles = (List<UserRole>) map.get("userRoles");
23781 ashik.ali 265
		Role roleUser = roleRepository.selectByName(RoleType.USER.toString());
266
		userRoles = this.addRole(userRoles, user.getId(), roleUser.getId());
23955 govind 267
		Retailer retailer = (Retailer) map.get("retailer");
23329 ashik.ali 268
		retailer = this.updateRetailer(user, retailer, updateRetailerRequest);
269
		map.put("retailer", retailer);
23955 govind 270
 
23781 ashik.ali 271
		Role roleRetailer = roleRepository.selectByName(RoleType.RETAILER.toString());
23955 govind 272
 
23781 ashik.ali 273
		userRoles = this.addRole(userRoles, user.getId(), roleRetailer.getId());
23955 govind 274
 
23781 ashik.ali 275
		Role roleFofo = roleRepository.selectByName(RoleType.FOFO.toString());
23955 govind 276
 
277
		if (updateRetailerRequest.isFofo()) {
278
 
23781 ashik.ali 279
			userRoles = this.addRole(userRoles, user.getId(), roleFofo.getId());
280
			map.put("fofoRole", this.containsRoleType(userRoles, roleFofo.getId()));
23061 ashik.ali 281
		}
23955 govind 282
 
283
		if (this.containsRoleType(userRoles, roleFofo.getId())) {
23365 ashik.ali 284
			this.createDefaultPaymentOption(retailer.getId());
23329 ashik.ali 285
		}
23955 govind 286
 
23329 ashik.ali 287
		map.put("userRoles", userRoles);
288
		map.put("userRoleNames", this.toString(userRoles));
23955 govind 289
 
290
		Address retailerAddress = (Address) map.get("retailerAddress");
291
		retailerAddress = this.updateRetailerAddress(retailerAddress, updateRetailerRequest.getAddress(),
292
				retailer.getId());
23329 ashik.ali 293
		map.put("retailerAddress", retailerAddress);
23955 govind 294
 
295
		if (updateRetailerRequest.isFofo()) {
296
			FofoStore fofoStore = this.createFofoStoreCodeByRetailerId(retailer.getId(),
297
					updateRetailerRequest.getDistrictName(), retailerAddress.getState(), updateRetailerRequest);
23378 ashik.ali 298
			map.put("fofoStore", fofoStore);
23061 ashik.ali 299
		}
23955 govind 300
 
301
		this.createPrivateDealUser(user, updateRetailerRequest.isFofo(), updateRetailerRequest.getGstNumber(), retailer,
302
				retailerAddress.getId());
23329 ashik.ali 303
		map.put("gstNumber", updateRetailerRequest.getGstNumber());
304
		this.updateSaholicUser(retailer.getId(), retailerAddress.getId());
23955 govind 305
 
306
		List<Shop> shops = (List<Shop>) map.get("shops");
307
		if (shops == null) {
23060 ashik.ali 308
			shops = new ArrayList<>();
23061 ashik.ali 309
			map.put("shops", shops);
23060 ashik.ali 310
		}
23079 ashik.ali 311
		this.updateRetailerShops(shops, updateRetailerRequest.getShops(), retailer.getId(), retailerAddress);
23955 govind 312
 
23025 ashik.ali 313
		return map;
23955 govind 314
 
23025 ashik.ali 315
	}
23955 govind 316
 
317
	private void createDefaultPaymentOption(int fofoId) {
23365 ashik.ali 318
		List<Integer> paymentOptionIds = fofoPartnerPaymentOptionRepository.selectPaymentOptionIdsByFofoId(fofoId);
23955 govind 319
		if (paymentOptionIds.isEmpty()) {
23365 ashik.ali 320
			PaymentOption paymentOption = null;
23955 govind 321
			try {
23365 ashik.ali 322
				paymentOption = paymentOptionRepository.selectByName(PaymentOptionType.CASH.toString());
23955 govind 323
			} catch (ProfitMandiBusinessException profitMandiBusinessException) {
23365 ashik.ali 324
				paymentOption = new PaymentOption();
325
				paymentOption.setName(PaymentOptionType.CASH.toString());
326
				paymentOptionRepository.persist(paymentOption);
327
			}
328
			FofoPartnerPaymentOption fofoPartnerPaymentOption = new FofoPartnerPaymentOption();
329
			fofoPartnerPaymentOption.setFofoId(fofoId);
330
			fofoPartnerPaymentOption.setPaymentOptionId(paymentOption.getId());
331
			fofoPartnerPaymentOptionRepository.persist(fofoPartnerPaymentOption);
332
		}
23955 govind 333
 
23365 ashik.ali 334
	}
23955 govind 335
 
336
	private User createUser(User user, UpdateRetailerRequest updateRetailerRequest) {
337
		if (user == null) {
23329 ashik.ali 338
			user = new User();
339
			user.setCity("");
340
			user.setPinCode(0);
341
			user.setState("");
342
			user.setPassword("");
343
			user.setMobile_verified(false);
344
			user.setReferral_url("");
345
			user.setGroup_id(1);
346
			user.setStatus(1);
347
			user.setActivated(true);
348
			user.setCreateTimestamp(LocalDateTime.now());
349
		}
350
		user.setFirstName(updateRetailerRequest.getUserFirstName());
351
		user.setLastName(updateRetailerRequest.getUserLastName());
352
		user.setMobileNumber(updateRetailerRequest.getUserMobileNumber());
353
		user.setEmailId(updateRetailerRequest.getUserEmailId());
354
		user.setUsername(updateRetailerRequest.getUserEmailId());
23509 amit.gupta 355
		user.setUpdateTimestamp(LocalDateTime.now());
356
		userRepository.persist(user);
23329 ashik.ali 357
		return user;
23955 govind 358
 
23329 ashik.ali 359
	}
23955 govind 360
 
361
	private int createSaholicUser(User user, String retailerName) {
23043 ashik.ali 362
		com.spice.profitmandi.dao.entity.user.User saholicUser = null;
363
		try {
23063 ashik.ali 364
			saholicUser = userUserRepository.selectByEmailId(user.getEmailId());
23955 govind 365
		} catch (ProfitMandiBusinessException e) {
23043 ashik.ali 366
			LOGGER.info("User doesnt exist in old system");
367
		}
23955 govind 368
		if (saholicUser == null) {
23043 ashik.ali 369
			Cart cart = new Cart();
370
			cart.setCartStatus(CartStatus.ACTIVE);
371
			cartRepository.persist(cart);
372
			saholicUser = new com.spice.profitmandi.dao.entity.user.User();
23063 ashik.ali 373
			saholicUser.setEmailId(user.getEmailId());
23043 ashik.ali 374
			saholicUser.setName(retailerName);
375
			saholicUser.setActiveCartId(cart.getId());
23300 amit.gupta 376
			saholicUser.setCreateTimestamp(LocalDateTime.now());
23043 ashik.ali 377
			userUserRepository.persist(saholicUser);
23955 govind 378
 
23269 ashik.ali 379
			UserAccount ua = new UserAccount();
380
			ua.setAccountKey(saholicUser.getId());
381
			ua.setUserId(user.getId());
382
			ua.setType(AccountType.saholic);
23063 ashik.ali 383
			userAccountRepository.persist(ua);
384
 
23269 ashik.ali 385
			UserAccount ua2 = new UserAccount();
386
			ua2.setAccountKey(saholicUser.getActiveCartId());
387
			ua2.setUserId(user.getId());
388
			ua2.setType(AccountType.cartId);
23063 ashik.ali 389
			userAccountRepository.persist(ua2);
23955 govind 390
			LOGGER.info("created....");
23043 ashik.ali 391
		}
392
		return saholicUser.getId();
393
	}
23955 govind 394
 
395
	private Retailer updateRetailer(User user, Retailer retailer, UpdateRetailerRequest updateRetailerRequest)
396
			throws ProfitMandiBusinessException {
397
		if (retailer == null) {
398
			LOGGER.info("createSaholicUser.....");
23063 ashik.ali 399
			int saholicUserId = this.createSaholicUser(user, updateRetailerRequest.getName());
23043 ashik.ali 400
			retailer = new Retailer();
401
			retailer.setId(saholicUserId);
402
		}
23329 ashik.ali 403
		retailer.setActive(updateRetailerRequest.isActive());
23955 govind 404
		// this.createRole(user.getId(), RoleType.RETAILER);
23025 ashik.ali 405
		retailer.setName(updateRetailerRequest.getName());
406
		retailer.setNumber(updateRetailerRequest.getNumber());
23955 govind 407
		if (updateRetailerRequest.getNumber() == null || updateRetailerRequest.getNumber().isEmpty()) {
23107 ashik.ali 408
			retailer.setType(RetailerType.UNREGISTERED_SHOP);
23955 govind 409
		} else {
23107 ashik.ali 410
			retailer.setType(RetailerType.GSTIN);
411
		}
23955 govind 412
		if (updateRetailerRequest.getDocumentId() > 0) {
413
			if (retailer.getDocumentId() != null && retailer.getDocumentId() != updateRetailerRequest.getDocumentId()) {
23489 ashik.ali 414
				documentRepository.deleteById(retailer.getDocumentId());
415
			}
23497 ashik.ali 416
			retailer.setDocumentId(updateRetailerRequest.getDocumentId());
417
			documentRepository.markDocumentAsPersisted(updateRetailerRequest.getDocumentId());
23025 ashik.ali 418
		}
419
		retailerRepository.persist(retailer);
23059 ashik.ali 420
		return retailer;
23025 ashik.ali 421
	}
23955 govind 422
 
423
	private void updateSaholicUser(int retailerId, int retailerAddressId) {
23329 ashik.ali 424
		try {
425
			com.spice.profitmandi.dao.entity.user.User user = userUserRepository.selectById(retailerId);
426
			user.setAddressId(retailerAddressId);
427
			userUserRepository.persist(user);
428
		} catch (ProfitMandiBusinessException e) {
23955 govind 429
 
23329 ashik.ali 430
		}
431
	}
23955 govind 432
 
433
	private void createPrivateDealUser(User user, boolean fofo, String gstNumber, Retailer retailer,
434
			int retailerAddressId) {
23329 ashik.ali 435
		PrivateDealUser privateDealUser = null;
23955 govind 436
		try {
23329 ashik.ali 437
			privateDealUser = privateDealUserRepository.selectById(retailer.getId());
23955 govind 438
		} catch (ProfitMandiBusinessException profitMandiBusinessException) {
23329 ashik.ali 439
			LOGGER.error("PrivateDealUser not found");
440
		}
23955 govind 441
 
442
		// = privateDealUserRepository.selectById(saholicUser.getId());
443
		if (privateDealUser == null) {
444
			Integer counterId = this.createCounter(user.getEmailId(), gstNumber, user.getMobileNumber(),
445
					retailer.getName(), retailerAddressId);
23473 ashik.ali 446
			try {
447
				this.createPrivateDealUser(retailer.getId(), counterId, fofo);
23955 govind 448
			} catch (Exception e) {
23473 ashik.ali 449
				LOGGER.error("ERROR : ", e);
450
			}
23955 govind 451
		} else {
452
			if (privateDealUser.getCounterId() == null) {
453
				Integer counterId = this.createCounter(user.getEmailId(), gstNumber, user.getMobileNumber(),
454
						retailer.getName(), retailerAddressId);
23329 ashik.ali 455
				privateDealUser.setCounterId(counterId);
456
				privateDealUser.setFofo(fofo);
457
				privateDealUserRepository.persist(privateDealUser);
23955 govind 458
			} else {
23329 ashik.ali 459
				Counter counter = null;
23955 govind 460
				try {
23329 ashik.ali 461
					counter = counterRepository.selectById(privateDealUser.getCounterId());
23955 govind 462
				} catch (ProfitMandiBusinessException profitMandiBusinessException) {
23329 ashik.ali 463
					LOGGER.error("Counter not found with id [{}]", privateDealUser.getCounterId());
464
				}
23955 govind 465
				if (counter == null) {
466
					this.createCounter(user.getEmailId(), gstNumber, user.getMobileNumber(), retailer.getName(),
467
							retailerAddressId);
468
				} else {
23329 ashik.ali 469
					counter.setGstin(gstNumber);
470
					counterRepository.persist(counter);
471
				}
472
				privateDealUser.setFofo(fofo);
473
				privateDealUserRepository.persist(privateDealUser);
474
			}
475
		}
23955 govind 476
 
23329 ashik.ali 477
		PrivateDealUserAddressMapping privateDealUserAddressMapping = new PrivateDealUserAddressMapping();
478
		privateDealUserAddressMapping.setUserId(retailer.getId());
479
		privateDealUserAddressMapping.setAddressId(retailerAddressId);
480
		privateDealUserAddressMappingRepository.persist(privateDealUserAddressMapping);
481
	}
23955 govind 482
 
483
	// Specifically set isFofo to true that has to be used by old system
484
	private void createPrivateDealUser(int retailerId, int counterId, boolean fofo) {
23329 ashik.ali 485
		PrivateDealUser privateDealUser = new PrivateDealUser();
486
		privateDealUser.setActive(true);
487
		privateDealUser.setBulkShipmentAmountLimit(fofo ? 1000000 : 50000);
488
		privateDealUser.setId(retailerId);
489
		privateDealUser.setCounterId(counterId);
490
		privateDealUser.setFofo(fofo);
491
		privateDealUserRepository.persist(privateDealUser);
492
	}
23955 govind 493
 
494
	private Integer createCounter(String emailId, String gstNumber, String mobileNumber, String name, int addressId) {
495
		if (gstNumber != null && !gstNumber.isEmpty()) {
23329 ashik.ali 496
			Counter counter = new Counter();
497
			counter.setEmailId(emailId);
498
			counter.setGstin(gstNumber);
499
			counter.setMobileNumber(mobileNumber);
500
			counter.setName(name);
501
			counter.setAddressId(addressId);
502
			counterRepository.persist(counter);
503
			return counter.getId();
23955 govind 504
		} else {
23329 ashik.ali 505
			return null;
506
		}
507
	}
23955 govind 508
 
509
	private Address updateRetailerAddress(Address address, CustomAddress customAddress, int retailerId)
510
			throws ProfitMandiBusinessException {
511
		if (address == null) {
23043 ashik.ali 512
			address = new Address();
513
			address.setRetaierId(retailerId);
514
			this.updateAddress(address, customAddress);
23955 govind 515
			// addressRepository.persist(addressRetailer);
516
 
23043 ashik.ali 517
			final RetailerRegisteredAddress retailerRegisteredAddress = new RetailerRegisteredAddress();
518
			retailerRegisteredAddress.setRetailerId(retailerId);
519
			retailerRegisteredAddress.setAddressId(address.getId());
520
			retailerRegisteredAddressRepository.persist(retailerRegisteredAddress);
23955 govind 521
		} else {
522
			this.updateAddress(address, customAddress);
523
			RetailerRegisteredAddress retailerRegisteredAddress = retailerRegisteredAddressRepository
524
					.selectByRetailerId(retailerId);
525
			retailerRegisteredAddress.setAddressId(address.getId());
526
			retailerRegisteredAddressRepository.persist(retailerRegisteredAddress);
23043 ashik.ali 527
		}
23059 ashik.ali 528
		return address;
23043 ashik.ali 529
	}
23955 govind 530
 
531
	private void updateAddress(Address address, CustomAddress customAddress) {
23025 ashik.ali 532
		address.setName(customAddress.getName());
23829 amit.gupta 533
		address.setPhoneNumber(customAddress.getPhoneNumber());
23025 ashik.ali 534
		address.setLine1(customAddress.getLine1());
535
		address.setLine2(customAddress.getLine2());
536
		address.setCity(customAddress.getCity());
537
		address.setPinCode(customAddress.getPinCode());
538
		address.setState(customAddress.getState());
539
		addressRepository.persist(address);
23955 govind 540
		LOGGER.info("Address Updated" + address);
23025 ashik.ali 541
	}
23955 govind 542
 
543
	private void updateRetailerShops(List<Shop> shops, Set<CustomShop> customShops, int retailerId,
544
			Address sameAsRetailerAddressValue) throws ProfitMandiBusinessException {
545
		if (shops.isEmpty()) {
546
			for (CustomShop customShop : customShops) {
23043 ashik.ali 547
				Shop shop = new Shop();
23079 ashik.ali 548
				this.createOrUpdateShop(shop, customShop, retailerId, sameAsRetailerAddressValue);
23043 ashik.ali 549
				shops.add(shop);
550
			}
23955 govind 551
		} else {
552
			for (Shop shop : shops) {
553
				for (CustomShop customShop : customShops) {
554
					if (shop.getId() == customShop.getShopId()) {
23079 ashik.ali 555
						this.createOrUpdateShop(shop, customShop, retailerId, sameAsRetailerAddressValue);
23025 ashik.ali 556
					}
557
				}
558
			}
23955 govind 559
			for (CustomShop customShop : customShops) {
560
				if (customShop.getShopId() == 0) {
23043 ashik.ali 561
					Shop shop = new Shop();
23079 ashik.ali 562
					this.createOrUpdateShop(shop, customShop, retailerId, sameAsRetailerAddressValue);
23043 ashik.ali 563
					shops.add(shop);
564
				}
565
			}
23025 ashik.ali 566
		}
567
	}
23955 govind 568
 
569
	private void createOrUpdateShop(Shop shop, CustomShop customShop, int retailerId,
570
			Address sameAsRetailerAddressValue) throws ProfitMandiBusinessException {
23043 ashik.ali 571
		shop.setRetailerId(retailerId);
572
		shop.setName(customShop.getName());
23955 govind 573
		if (customShop.getDocumentId() > 0) {
574
			if (shop.getDocumentId() != null && shop.getDocumentId() != customShop.getDocumentId()) {
23489 ashik.ali 575
				documentRepository.deleteById(shop.getDocumentId());
576
			}
23497 ashik.ali 577
			shop.setDocumentId(customShop.getDocumentId());
578
			documentRepository.markDocumentAsPersisted(customShop.getDocumentId());
23043 ashik.ali 579
		}
23955 govind 580
		if (shop.getAddressId() == null) {
23079 ashik.ali 581
			Address address = null;
23955 govind 582
			if (customShop.isSameAsRetailerAddress()) {
23079 ashik.ali 583
				address = sameAsRetailerAddressValue;
23955 govind 584
			} else {
585
				// shop.setDocumentId(customShop.getDocumentId());
23079 ashik.ali 586
				address = new Address();
587
				this.updateAddress(address, customShop.getAddress());
588
			}
23043 ashik.ali 589
			shop.setAddressId(address.getId());
590
			shop.setAddress(address);
591
			shopRepository.persist(shop);
23131 ashik.ali 592
			ShopAddress shopAddress = null;
23955 govind 593
			try {
23131 ashik.ali 594
				shopAddress = shopAddressRepository.selectByShopId(shop.getId());
595
				shopAddress.setAddressId(address.getId());
23955 govind 596
			} catch (ProfitMandiBusinessException profitMandiBusinessException) {
23131 ashik.ali 597
				shopAddress = new ShopAddress();
598
				shopAddress.setAddressId(address.getId());
599
				shopAddress.setShopId(shop.getId());
600
			}
23043 ashik.ali 601
			shopAddressRepository.persist(shopAddress);
23955 govind 602
		} else {
23043 ashik.ali 603
			Address address = addressRepository.selectById(shop.getAddressId());
23329 ashik.ali 604
			LOGGER.info("found address : {}", address);
23079 ashik.ali 605
			CustomAddress customAddress = customShop.getAddress();
23329 ashik.ali 606
			LOGGER.info("requested address : {}", customAddress);
23955 govind 607
			if (!(address.getName().equals(customAddress.getName())
608
					&& address.getLine1().equals(customAddress.getLine1())
609
					&& address.getLine2().equals(customAddress.getLine2())
610
					&& address.getCity().equals(customAddress.getCity())
611
					&& address.getPinCode().equals(customAddress.getPinCode())
612
					&& address.getState().equals(customAddress.getState()))) {
23079 ashik.ali 613
				address = new Address();
614
				ShopAddress shopAddress = shopAddressRepository.selectByShopId(shop.getId());
615
				this.updateAddress(address, customAddress);
616
				shopAddress.setAddressId(address.getId());
617
				shopAddressRepository.persist(shopAddress);
618
			}
23955 govind 619
 
23043 ashik.ali 620
			shop.setAddress(address);
621
			shopRepository.persist(shop);
622
		}
23955 govind 623
 
23043 ashik.ali 624
	}
23955 govind 625
 
626
	private void addAddress(List<Shop> shops) {
22980 ashik.ali 627
		Set<Integer> shopIds = this.toShopIds(shops);
23955 govind 628
		if (shopIds.isEmpty()) {
22980 ashik.ali 629
			return;
630
		}
631
		List<ShopAddress> shopAddresses = shopAddressRepository.selectByShopIds(shopIds);
632
		Map<Integer, Address> addressIdAddressMap = this.toAddressIdAddressMap(shopAddresses);
23955 govind 633
 
634
		for (Shop shop : shops) {
22980 ashik.ali 635
			shop.setAddress(addressIdAddressMap.get(shop.getAddressId()));
636
		}
637
	}
638
 
23955 govind 639
	private Map<Integer, Address> toAddressIdAddressMap(List<ShopAddress> shopAddresses) {
22980 ashik.ali 640
		Map<Integer, Address> addressIdAddressMap = new HashMap<>();
641
		List<Integer> addressIds = this.toAddressIds(shopAddresses);
642
		List<Address> addresses = addressRepository.selectByIds(addressIds);
23955 govind 643
		for (Address address : addresses) {
22980 ashik.ali 644
			addressIdAddressMap.put(address.getId(), address);
645
		}
646
		return addressIdAddressMap;
647
	}
23955 govind 648
 
649
	private List<Integer> toAddressIds(List<ShopAddress> shopAddresses) {
650
		Function<ShopAddress, Integer> shopAddressToAddressIdFunction = new Function<ShopAddress, Integer>() {
22980 ashik.ali 651
			@Override
652
			public Integer apply(ShopAddress shopAddress) {
653
				return shopAddress.getAddressId();
654
			}
655
		};
656
		return shopAddresses.stream().map(shopAddressToAddressIdFunction).collect(Collectors.toList());
657
	}
23955 govind 658
 
659
	private Set<Integer> toShopIds(List<Shop> shops) {
660
		Function<Shop, Integer> shopToAddressIdFunction = new Function<Shop, Integer>() {
22980 ashik.ali 661
			@Override
662
			public Integer apply(Shop shop) {
663
				return shop.getId();
664
			}
665
		};
666
		return shops.stream().map(shopToAddressIdFunction).collect(Collectors.toSet());
667
	}
23955 govind 668
 
669
	private String toString(List<UserRole> userRoles) {
23781 ashik.ali 670
		Set<Integer> roleIds = new HashSet<>();
23955 govind 671
		for (UserRole userRole : userRoles) {
23781 ashik.ali 672
			roleIds.add(userRole.getRoleId());
673
		}
674
		List<Role> roles = roleRepository.selectByIds(roleIds);
23955 govind 675
		Function<Role, String> roleToNameFunction = new Function<Role, String>() {
23781 ashik.ali 676
			public String apply(Role role) {
677
				return String.valueOf(role.getName());
22980 ashik.ali 678
			};
679
		};
23781 ashik.ali 680
		Set<String> userRoleStrings = roles.stream().map(roleToNameFunction).collect(Collectors.toSet());
22980 ashik.ali 681
		return String.join(", ", userRoleStrings);
682
	}
23955 govind 683
 
684
	private FofoStore createFofoStoreCodeByRetailerId(int retailerId, String districtName, String stateName,
685
			UpdateRetailerRequest updateRetailerRequest) throws ProfitMandiBusinessException {
23378 ashik.ali 686
		FofoStore fofoStore = null;
23955 govind 687
		try {
23378 ashik.ali 688
			fofoStore = fofoStoreRepository.selectByRetailerId(retailerId);
23955 govind 689
		} catch (ProfitMandiBusinessException profitMandiBusinessException) {
690
 
23378 ashik.ali 691
		}
23955 govind 692
 
693
		if (fofoStore != null) {
694
			fofoStore.setCounterSize(updateRetailerRequest.getCountersize());
695
			fofoStore.setMinimumInvestment(updateRetailerRequest.getMinInvestment());
696
			fofoStoreRepository.persist(fofoStore);
697
 
698
		} else {
23378 ashik.ali 699
			int retailerAddressId = retailerRegisteredAddressRepository.selectAddressIdByRetailerId(retailerId);
700
			Address retailerAddress = addressRepository.selectById(retailerAddressId);
23955 govind 701
 
23378 ashik.ali 702
			StateInfo stateInfo = null;
703
			try {
704
				stateInfo = Utils.getStateInfo(retailerAddress.getState());
705
			} catch (Exception e) {
706
				// TODO Auto-generated catch block
707
				e.printStackTrace();
23955 govind 708
				// throw new ProfitMandiBusinessException();
23378 ashik.ali 709
			}
23955 govind 710
			DistrictMaster districtMaster = districtMasterRepository.selectByNameAndStateShortName(districtName,
711
					stateInfo.getShortName());
712
 
23378 ashik.ali 713
			fofoStore = new FofoStore();
714
			fofoStore.setId(retailerId);
23786 amit.gupta 715
			String latestStoreCode = fofoStoreRepository.selectLatestStore().getCode();
716
			int latestCodeCounter = Integer.parseInt(latestStoreCode.replaceAll("[A-Z]", ""));
23955 govind 717
			String fofoStoreCode = StringUtils.generateFofoStoreSequence(
718
					districtMaster.getStateShortName() + districtMaster.getShortName(), latestCodeCounter + 1);
23378 ashik.ali 719
			fofoStore.setCode(fofoStoreCode);
720
			fofoStoreRepository.persist(fofoStore);
721
		}
23955 govind 722
 
23378 ashik.ali 723
		return fofoStore;
724
	}
23955 govind 725
 
23329 ashik.ali 726
	@Override
23955 govind 727
	public FofoStore createFofoStoreCodeByUserId(int userId, String districtName, String stateName,
728
			UpdateRetailerRequest updateRetailerRequest) throws ProfitMandiBusinessException {
23329 ashik.ali 729
		User user = userRepository.selectById(userId);
730
		// = userAccountRepository.selectRetailerIdByUserId(user.getId());
731
		UserAccount userAccounts = userAccountRepository.selectSaholicByUserId(user.getId());
732
		Retailer retailer = retailerRepository.selectById(userAccounts.getAccountKey());
23781 ashik.ali 733
		Role roleFofo = roleRepository.selectByName(RoleType.FOFO.toString());
23955 govind 734
		try {
23781 ashik.ali 735
			userRoleRepository.selectByUserIdAndRoleId(user.getId(), roleFofo.getId());
23955 govind 736
		} catch (ProfitMandiBusinessException profitMandiBusinessException) {
23329 ashik.ali 737
			throw new ProfitMandiBusinessException(ProfitMandiConstants.USER_ID, user.getId(), "USR_1013");
738
		}
23955 govind 739
		return this.createFofoStoreCodeByRetailerId(retailer.getId(), districtName, stateName, updateRetailerRequest);
740
 
23329 ashik.ali 741
	}
23955 govind 742
 
23329 ashik.ali 743
	@Override
744
	public List<DistrictMaster> getAllDistrictMaster(String stateName) {
745
		StateInfo stateInfo = null;
746
		try {
747
			stateInfo = Utils.getStateInfo(stateName);
748
		} catch (Exception e) {
749
			e.printStackTrace();
23955 govind 750
			// throw new ProfitMandiBusinessException();
23329 ashik.ali 751
		}
752
		return districtMasterRepository.selectByStateShortName(stateInfo.getShortName());
753
	}
22980 ashik.ali 754
 
23509 amit.gupta 755
	@Override
756
	public Map<Integer, CustomRetailer> getFofoRetailers(List<Integer> fofoIds) {
757
		List<com.spice.profitmandi.dao.entity.user.User> saholicUsers = userUserRepository.selectByIds(fofoIds);
23955 govind 758
		Map<Integer, com.spice.profitmandi.dao.entity.user.User> userAddressMap = saholicUsers.stream()
759
				.filter(x -> x.getAddressId() != null).collect(Collectors.toMap(x -> x.getAddressId(), x -> x));
23903 amit.gupta 760
		List<Address> addresses = addressRepository.selectByIds(new ArrayList<>(userAddressMap.keySet()));
23509 amit.gupta 761
		Map<Integer, CustomRetailer> customRetailersMap = new HashMap<>();
23955 govind 762
		for (Address address : addresses) {
23903 amit.gupta 763
			com.spice.profitmandi.dao.entity.user.User user = userAddressMap.get(address.getId());
23509 amit.gupta 764
			CustomRetailer customRetailer = new CustomRetailer();
23903 amit.gupta 765
			customRetailer.setEmail(user.getEmailId());
23509 amit.gupta 766
			customRetailer.setBusinessName(address.getName());
767
			customRetailer.setMobileNumber(address.getPhoneNumber());
23532 amit.gupta 768
			try {
23796 amit.gupta 769
				customRetailer.setCartId(user.getActiveCartId());
23532 amit.gupta 770
				PrivateDealUser pdu = privateDealUserRepository.selectById(address.getRetaierId());
771
				Counter counter = counterRepository.selectById(pdu.getCounterId());
772
				customRetailer.setGstNumber(counter.getGstin());
23955 govind 773
			} catch (Exception e) {
23532 amit.gupta 774
				customRetailer.setGstNumber(null);
775
			}
776
			CustomAddress address1 = new CustomAddress();
777
			address1.setCity(address.getCity());
778
			address1.setState(address.getState());
779
			address1.setLine1(address.getLine1());
780
			address1.setLine2(address.getLine2());
781
			address1.setPinCode(address.getPinCode());
782
			address1.setName(address.getName());
783
			customRetailer.setAddress(address1);
23786 amit.gupta 784
			customRetailer.setPartnerId(address.getRetaierId());
23509 amit.gupta 785
			customRetailersMap.put(address.getRetaierId(), customRetailer);
786
		}
787
		return customRetailersMap;
788
	}
23955 govind 789
 
23781 ashik.ali 790
	@Override
791
	public Map<Integer, String> getAllFofoRetailerIdEmailIdMap() {
792
		Role roleFofo = null;
793
		try {
794
			roleFofo = roleRepository.selectByName(RoleType.FOFO.toString());
795
		} catch (ProfitMandiBusinessException e) {
796
			// TODO Auto-generated catch block
797
			e.printStackTrace();
798
		}
799
		Role roleRetailer = null;
800
		try {
801
			roleRetailer = roleRepository.selectByName(RoleType.RETAILER.toString());
802
		} catch (ProfitMandiBusinessException e) {
803
			// TODO Auto-generated catch block
804
			e.printStackTrace();
805
		}
806
		Set<Integer> roleIds = new HashSet<>();
807
		roleIds.add(roleFofo.getId());
808
		roleIds.add(roleRetailer.getId());
809
		List<Integer> userIds = userRoleRepository.selectUserIdsByRoleIds(roleIds);
810
		List<User> users = userRepository.selectAllByIds(new HashSet<>(userIds));
811
		Map<Integer, Integer> userIdRetailerIdMap = this.getUserIdRetailerIdMap(userIds);
812
		Map<Integer, String> retailerIdEmailIdMap = new HashMap<>();
23955 govind 813
		for (User user : users) {
23781 ashik.ali 814
			retailerIdEmailIdMap.put(userIdRetailerIdMap.get(user.getId()), user.getEmailId());
815
		}
816
		return retailerIdEmailIdMap;
817
	}
23955 govind 818
 
23781 ashik.ali 819
	@Override
820
	public List<MapWrapper<Integer, String>> getFofoRetailerIdEmailIdMap() {
821
		List<MapWrapper<Integer, String>> mapWrappers = new ArrayList<>();
23955 govind 822
		for (Map.Entry<Integer, String> retailerIdEmailIdEntry : this.getAllFofoRetailerIdEmailIdMap().entrySet()) {
23781 ashik.ali 823
			MapWrapper<Integer, String> mapWrapper = new MapWrapper<>();
824
			mapWrapper.setKey(retailerIdEmailIdEntry.getKey());
825
			mapWrapper.setValue(retailerIdEmailIdEntry.getValue());
826
			mapWrappers.add(mapWrapper);
827
		}
828
		return mapWrappers;
829
	}
23955 govind 830
 
831
	private Map<Integer, Integer> getUserIdRetailerIdMap(List<Integer> userIds) {
23781 ashik.ali 832
		List<UserAccount> userAccounts = userAccountRepository.selectAllSaholicByUserIds(new HashSet<>(userIds));
833
		Map<Integer, Integer> userIdRetailerIdMap = new HashMap<>();
23955 govind 834
		for (UserAccount userAccount : userAccounts) {
23781 ashik.ali 835
			userIdRetailerIdMap.put(userAccount.getUserId(), userAccount.getAccountKey());
836
		}
837
		return userIdRetailerIdMap;
838
	}
23955 govind 839
 
840
	private Map<Integer, String> getUserIdEmailIdMap(Set<Integer> userIds) {
23880 ashik.ali 841
		List<User> users = userRepository.selectAllByIds(userIds);
842
		Map<Integer, String> userIdEmailIdMap = new HashMap<>();
23955 govind 843
		for (User user : users) {
23880 ashik.ali 844
			userIdEmailIdMap.put(user.getId(), user.getEmailId());
845
		}
846
		return userIdEmailIdMap;
847
	}
23509 amit.gupta 848
 
23880 ashik.ali 849
	@Override
850
	public Map<Integer, String> getAllFofoRetailerIdEmailIdMap(Set<Integer> retailerIds) {
851
		List<UserAccount> userAccounts = userAccountRepository.selectAllSaholicByRetailerIds(retailerIds);
852
		Set<Integer> userIds = new HashSet<>();
23955 govind 853
		for (UserAccount userAccount : userAccounts) {
23880 ashik.ali 854
			userIds.add(userAccount.getUserId());
855
		}
856
		Map<Integer, String> retailerIdEmailIdMap = new HashMap<>();
857
		Map<Integer, String> userIdEmailIdMap = this.getUserIdEmailIdMap(userIds);
23955 govind 858
		for (UserAccount userAccount : userAccounts) {
23880 ashik.ali 859
			retailerIdEmailIdMap.put(userAccount.getAccountKey(), userIdEmailIdMap.get(userAccount.getUserId()));
860
		}
861
		return retailerIdEmailIdMap;
862
	}
863
 
22980 ashik.ali 864
}