Subversion Repositories SmartDukaan

Rev

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