Subversion Repositories SmartDukaan

Rev

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

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