Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
24383 amit.gupta 1
package com.spice.profitmandi.dao.repository.cs;
24500 govind 2
 
24383 amit.gupta 3
import java.time.LocalDateTime;
24417 govind 4
import java.util.ArrayList;
5
import java.util.HashMap;
24439 govind 6
import java.util.HashSet;
24417 govind 7
import java.util.List;
8
import java.util.Map;
25570 tejbeer 9
import java.util.Set;
10
import java.util.stream.Collectors;
24500 govind 11
 
25570 tejbeer 12
import org.apache.commons.collections4.map.HashedMap;
24439 govind 13
import org.apache.commons.lang.RandomStringUtils;
14
import org.apache.logging.log4j.LogManager;
15
import org.apache.logging.log4j.Logger;
24383 amit.gupta 16
import org.springframework.beans.factory.annotation.Autowired;
24439 govind 17
import org.springframework.mail.javamail.JavaMailSender;
24383 amit.gupta 18
import org.springframework.stereotype.Component;
24701 govind 19
 
24383 amit.gupta 20
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
24417 govind 21
import com.spice.profitmandi.common.model.CustomRetailer;
24439 govind 22
import com.spice.profitmandi.common.model.ProfitMandiConstants;
23
import com.spice.profitmandi.common.util.Utils;
24417 govind 24
import com.spice.profitmandi.dao.entity.auth.AuthUser;
24383 amit.gupta 25
import com.spice.profitmandi.dao.entity.cs.Activity;
24417 govind 26
import com.spice.profitmandi.dao.entity.cs.PartnerRegion;
27
import com.spice.profitmandi.dao.entity.cs.Position;
24471 govind 28
import com.spice.profitmandi.dao.entity.cs.Region;
24383 amit.gupta 29
import com.spice.profitmandi.dao.entity.cs.Ticket;
24500 govind 30
import com.spice.profitmandi.dao.entity.cs.TicketAssigned;
24439 govind 31
import com.spice.profitmandi.dao.entity.cs.TicketCategory;
24417 govind 32
import com.spice.profitmandi.dao.entity.cs.TicketSubCategory;
24383 amit.gupta 33
import com.spice.profitmandi.dao.entity.fofo.ActivityType;
25570 tejbeer 34
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
24417 govind 35
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
36
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
25570 tejbeer 37
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
38
import com.spice.profitmandi.service.slab.TargetSlabService;
24417 govind 39
import com.spice.profitmandi.service.user.RetailerService;
24383 amit.gupta 40
 
41
@Component
42
public class CsServiceImpl implements CsService {
24417 govind 43
 
24439 govind 44
	private static final Logger LOGGER = LogManager.getLogger(CsServiceImpl.class);
45
 
24570 govind 46
	private static final String ASSIGNED_TICKET = "Dear %s,You have assigned a ticket by %s with ticketId#%s.Regards\nSmartdukaan";
24439 govind 47
	private static final String ASSINMENT_SUBJECT = "Assignment Ticket";
48
 
24383 amit.gupta 49
	@Autowired
50
	TicketRepository ticketRepository;
24417 govind 51
 
24383 amit.gupta 52
	@Autowired
24439 govind 53
	JavaMailSender mailSender;
54
 
55
	@Autowired
24383 amit.gupta 56
	TicketCategoryRepository ticketCategoryRepository;
24417 govind 57
 
24383 amit.gupta 58
	@Autowired
59
	TicketSubCategoryRepository ticketSubCategoryRepository;
24417 govind 60
 
61
	@Autowired
24388 amit.gupta 62
	ActivityRepository activityRepository;
24417 govind 63
 
64
	@Autowired
24439 govind 65
	PartnerRegionRepository partnerRegionRepository;
24417 govind 66
 
67
	@Autowired
68
	private PositionRepository positionRepository;
69
 
70
	@Autowired
71
	private AuthRepository authRepository;
72
 
73
	@Autowired
74
	private RetailerService retailerService;
24500 govind 75
 
24471 govind 76
	@Autowired
77
	private RegionRepository regionRepository;
24417 govind 78
 
24500 govind 79
	@Autowired
80
	private TicketAssignedRepository ticketAssignedRepository;
81
 
25570 tejbeer 82
	@Autowired
83
	private PartnersPositionRepository partnersPositionRepository;
84
 
85
	@Autowired
86
	private TargetSlabService targetSlabService;
87
 
88
	@Autowired
89
	private FofoStoreRepository fofoStoreRepository;
90
 
24383 amit.gupta 91
	@Override
24439 govind 92
	public void createTicket(int fofoId, int categoryId, int subcategoryId, String message)
93
			throws ProfitMandiBusinessException {
24417 govind 94
 
24383 amit.gupta 95
		ActivityType type = ActivityType.OPENED;
24439 govind 96
		EscalationType escalationTypeL1 = EscalationType.L1;
97
		EscalationType escalationTypeL2 = EscalationType.L2;
98
		EscalationType escalationTypeL3 = EscalationType.L3;
24383 amit.gupta 99
		Ticket ticket = new Ticket();
24500 govind 100
		TicketAssigned ticketAssigned = new TicketAssigned();
24383 amit.gupta 101
		ticket.setSubCategoryId(subcategoryId);
24417 govind 102
		ticket.setFofoId(fofoId);
24383 amit.gupta 103
		ticket.setCreateTimestamp(LocalDateTime.now());
24417 govind 104
		ticket.setUpdateTimestamp(LocalDateTime.now());
24467 govind 105
		ticket.setL2EscalationTimestamp(ticket.getUpdateTimestamp().plusDays(2));
106
		ticket.setL3EscalationTimestamp(ticket.getL2EscalationTimestamp().plusDays(2));
107
		ticket.setLastEscalationTimestamp(ticket.getL3EscalationTimestamp().plusDays(2));
24439 govind 108
		ticket.setHappyCode(getRandomString());
109
		int l1Auth = this.getAuthUserId(categoryId, escalationTypeL1, fofoId);
24699 govind 110
		LOGGER.info("l1Auth" + l1Auth);
24439 govind 111
		int l2Auth = this.getAuthUserId(categoryId, escalationTypeL2, fofoId);
24699 govind 112
		LOGGER.info("l2Auth" + l2Auth);
24557 govind 113
		int l3Auth = this.getAuthUserId(categoryId, escalationTypeL3, fofoId);
24699 govind 114
		LOGGER.info("l3Auth" + l3Auth);
24439 govind 115
		if (l1Auth == 0) {
116
			if (l2Auth == 0) {
24500 govind 117
				this.setAssignment(ticket, ticketAssigned);
24439 govind 118
			} else {
24500 govind 119
				ticketAssigned.setAssineeId(l2Auth);
24526 govind 120
				ticket.setL1AuthUser(l2Auth);
121
				ticket.setL2AuthUser(l2Auth);
24439 govind 122
			}
123
		} else {
24500 govind 124
			ticketAssigned.setAssineeId(l1Auth);
24439 govind 125
			ticket.setL1AuthUser(l1Auth);
126
			ticket.setL2AuthUser(l2Auth);
127
		}
24699 govind 128
		if (ticket.getL2AuthUser() == 0) {
24569 govind 129
			ticket.setL2AuthUser(l3Auth);
130
		}
24439 govind 131
		ticket.setL3AuthUser(l3Auth);
132
		ticketRepository.persist(ticket);
24500 govind 133
		ticketAssigned.setTicketId(ticket.getId());
134
		ticketAssignedRepository.persist(ticketAssigned);
135
		AuthUser authUser = authRepository.selectById(ticketAssigned.getAssineeId());
24569 govind 136
		this.sendAssignedTicketMail(authUser, ticket);
24383 amit.gupta 137
		Activity activity = this.createActivity(type, message, 0);
138
		this.addActivity(ticket.getId(), activity);
139
	}
140
 
141
	private Activity createActivity(ActivityType activityType, String message, int createdBy) {
142
		Activity activity = new Activity();
143
		activity.setMessage(message);
144
		activity.setCreatedBy(createdBy);
145
		activity.setType(activityType);
24417 govind 146
		activity.setCreateTimestamp(LocalDateTime.now());
24383 amit.gupta 147
		return activity;
148
	}
24417 govind 149
 
24439 govind 150
	private int getAuthUserId(int categoryId, EscalationType escalationType, int fofoId) {
24417 govind 151
 
24439 govind 152
		List<Position> positions = null;
153
		if (escalationType == EscalationType.L3) {
154
			positions = positionRepository.selectPositionbyCategoryIdAndEscalationType(0, escalationType, 0);
155
		} else {
156
			List<PartnerRegion> regions = partnerRegionRepository.selectByfofoId(fofoId);
157
			LOGGER.info("regions=" + regions);
24500 govind 158
			if (regions.size() == 0) {
159
				regions = partnerRegionRepository.selectByfofoId(0);
24452 govind 160
				LOGGER.info("regions=" + regions);
161
			}
24439 govind 162
			for (PartnerRegion region : regions) {
24699 govind 163
				LOGGER.info(categoryId + ":" + escalationType + ":" + region.getRegionId());
24439 govind 164
				positions = positionRepository.selectPositionbyCategoryIdAndEscalationType(categoryId, escalationType,
165
						region.getRegionId());
166
				LOGGER.info("positions:-" + positions);
24500 govind 167
				if (positions.size() > 0) {
24439 govind 168
					break;
169
				}
170
 
171
			}
172
			if (positions.size() == 0) {
24557 govind 173
				if (escalationType == EscalationType.L1) {
174
					regions = partnerRegionRepository.selectByfofoId(0);
175
					LOGGER.info("regions=" + regions);
176
					for (PartnerRegion region : regions) {
177
						positions = positionRepository.selectPositionbyCategoryIdAndEscalationType(categoryId,
178
								escalationType, region.getRegionId());
179
						LOGGER.info("positions:-" + positions);
180
						if (positions.size() > 0) {
181
							break;
182
						}
183
					}
184
				} else {
185
					regions = partnerRegionRepository.selectByfofoId(0);
186
					LOGGER.info("regions=" + regions);
187
					for (PartnerRegion region : regions) {
188
						positions = positionRepository.selectPositionbyCategoryIdAndEscalationType(categoryId,
189
								escalationType, region.getRegionId());
190
						LOGGER.info("positions:-" + positions);
191
						if (positions.size() > 0) {
192
							break;
193
						}
194
					}
195
				}
24439 govind 196
			}
24699 govind 197
 
24439 govind 198
		}
24699 govind 199
		if (positions.size() == 0) {
24557 govind 200
			return 0;
201
		}
202
		LOGGER.info(positions.get(0).getAuthUserId());
24439 govind 203
		return positions.get(0).getAuthUserId();
24417 govind 204
		/*
205
		 * if(ActivityType.escalationTypes.contains(escalationType)) {
206
		 * //escalationMatrix } else { throw new
207
		 * ProfitMandiBusinessException("SubCategory", subcategoryId,
208
		 * "Could not find Assignee for "); }
209
		 */
24439 govind 210
 
24383 amit.gupta 211
	}
212
 
213
	@Override
214
	public void addActivity(int ticketId, Activity activity) {
215
		activity.setTicketId(ticketId);
24417 govind 216
		activityRepository.persist(activity);
24383 amit.gupta 217
	}
218
 
24439 govind 219
	private String getRandomString() {
220
		int length = 4;
221
		boolean useLetters = false;
222
		boolean useNumbers = true;
223
		String generatedString = RandomStringUtils.random(length, useLetters, useNumbers);
224
		return generatedString;
225
	}
226
 
24417 govind 227
	@Override
228
	public void addPartnerToRegion(int regionId, List<Integer> fofoIds) {
229
 
24557 govind 230
		for (int fofoId : fofoIds) {
231
			PartnerRegion partnerRegion = new PartnerRegion();
232
			partnerRegion.setFofoId(fofoId);
233
			partnerRegion.setRegionId(regionId);
234
			partnerRegionRepository.persist(partnerRegion);
24417 govind 235
		}
236
	}
237
 
238
	@Override
24500 govind 239
	public Map<Integer, AuthUser> getAuthUserIdAndAuthUserMap(List<TicketAssigned> ticketAssigneds) {
24417 govind 240
		Map<Integer, AuthUser> authUserIdAndAuthUserMap = new HashMap<>();
24500 govind 241
 
242
		for (TicketAssigned ticketAssigned : ticketAssigneds) {
243
			AuthUser authUser = authRepository.selectById(ticketAssigned.getAssineeId());
244
			authUserIdAndAuthUserMap.put(ticketAssigned.getTicketId(), authUser);
245
		}
246
		return authUserIdAndAuthUserMap;
247
	}
248
 
249
	@Override
250
	public Map<Integer, AuthUser> getTicketIdAndAuthUserMapUsingTickets(List<Ticket> tickets) {
251
		Map<Integer, AuthUser> authUserIdAndAuthUserMap = new HashMap<>();
252
 
24417 govind 253
		for (Ticket ticket : tickets) {
24500 govind 254
			AuthUser authUser = authRepository.selectById(ticket.getL1AuthUser());
255
			authUserIdAndAuthUserMap.put(ticket.getId(), authUser);
24417 govind 256
		}
257
		return authUserIdAndAuthUserMap;
258
	}
259
 
260
	@Override
261
	public Map<Integer, TicketSubCategory> getSubCategoryIdAndSubCategoryMap(List<Ticket> tickets) {
262
		Map<Integer, TicketSubCategory> subCategoryIdAndSubCategoryMap = new HashMap<>();
24699 govind 263
		if (tickets != null) {
264
			for (Ticket ticket : tickets) {
265
				TicketSubCategory ticketSubCategory = ticketSubCategoryRepository.selectById(ticket.getSubCategoryId());
266
				subCategoryIdAndSubCategoryMap.put(ticket.getSubCategoryId(), ticketSubCategory);
267
			}
24417 govind 268
		}
269
		return subCategoryIdAndSubCategoryMap;
270
	}
271
 
272
	@Override
273
	public Map<Integer, CustomRetailer> getPartnerByFofoIds(List<Ticket> tickets) {
274
		List<Integer> fofoIds = new ArrayList<>();
24569 govind 275
		LOGGER.info(tickets);
24699 govind 276
		if (tickets == null) {
24569 govind 277
			return null;
278
		}
24417 govind 279
		for (Ticket ticket : tickets) {
280
			fofoIds.add(ticket.getFofoId());
281
		}
24699 govind 282
		Map<Integer, CustomRetailer> fofoIdsAndCustomRetailer = retailerService.getFofoRetailers(fofoIds);
24417 govind 283
		return fofoIdsAndCustomRetailer;
284
	}
285
 
24439 govind 286
	@Override
287
	public List<TicketCategory> getAllTicketCategotyFromSubCategory() {
288
 
289
		List<TicketSubCategory> ticketSubCategories = ticketSubCategoryRepository.selectAll();
290
		HashSet<Integer> categoryIds = new HashSet<>();
291
		for (TicketSubCategory ticketSubcategory : ticketSubCategories) {
292
			categoryIds.add(ticketSubcategory.getcategoryId());
293
		}
294
		List<TicketCategory> ticketcategories = ticketCategoryRepository.selectAll(new ArrayList<>(categoryIds));
295
		return ticketcategories;
296
	}
297
 
24500 govind 298
	private Ticket setAssignment(Ticket ticket, TicketAssigned ticketAssigned) {
24439 govind 299
		TicketCategory ticketCategory = ticketCategoryRepository.selectByName(ProfitMandiConstants.CRM);
300
		List<Position> positions = positionRepository.selectPositionByCategoryId(ticketCategory.getId());
301
		for (Position position : positions) {
302
			if (position.getEscalationType().equals(EscalationType.L1)) {
24500 govind 303
				ticketAssigned.setAssineeId(position.getAuthUserId());
24439 govind 304
				ticket.setL1AuthUser(position.getAuthUserId());
24557 govind 305
			} else if (position.getEscalationType().equals(EscalationType.L2)) {
24439 govind 306
				ticket.setL2AuthUser(position.getAuthUserId());
307
			}
308
		}
309
		return ticket;
310
	}
24500 govind 311
 
24471 govind 312
	@Override
313
	public Map<Integer, AuthUser> getAuthUserIdAndAuthUserMapUsingPositions(List<Position> positions) {
314
		Map<Integer, AuthUser> authUserIdAndAuthUserMap = new HashMap<>();
315
		for (Position position : positions) {
316
			AuthUser authUser = authRepository.selectById(position.getAuthUserId());
317
			authUserIdAndAuthUserMap.put(position.getAuthUserId(), authUser);
318
		}
319
		return authUserIdAndAuthUserMap;
320
	}
24500 govind 321
 
24471 govind 322
	@Override
323
	public Map<Integer, TicketCategory> getCategoryIdAndCategoryUsingPositions(List<Position> positions) {
324
		Map<Integer, TicketCategory> categoryIdAndCategoryMap = new HashMap<>();
325
		for (Position position : positions) {
24500 govind 326
			TicketCategory ticketCategory = ticketCategoryRepository.selectById(position.getCategoryId());
24471 govind 327
			categoryIdAndCategoryMap.put(position.getCategoryId(), ticketCategory);
328
		}
329
		return categoryIdAndCategoryMap;
330
	}
24439 govind 331
 
24471 govind 332
	@Override
333
	public Map<Integer, Region> getRegionIdAndRegionMap(List<Position> positions) {
334
		Map<Integer, Region> regionIdAndRegionMap = new HashMap<>();
335
		for (Position position : positions) {
24500 govind 336
			Region region = regionRepository.selectById(position.getRegionId());
24471 govind 337
			regionIdAndRegionMap.put(position.getRegionId(), region);
338
		}
339
		return regionIdAndRegionMap;
340
	}
24500 govind 341
 
342
	@Override
24699 govind 343
	public Map<Integer, List<AuthUser>> getAuthUserList(List<Ticket> tickets, AuthUser authUser) {
24500 govind 344
		Map<Integer, List<AuthUser>> authUserListMap = new HashMap<>();
345
		for (Ticket ticket : tickets) {
24570 govind 346
			if (ticket.getL2AuthUser() == authUser.getId()) {
24500 govind 347
				List<AuthUser> authUsers = new ArrayList<>();
348
				authUsers.add(authRepository.selectById(ticket.getL1AuthUser()));
349
				authUserListMap.put(ticket.getId(), authUsers);
350
 
24570 govind 351
			} else if (ticket.getL3AuthUser() == authUser.getId()) {
24500 govind 352
				TicketAssigned ticketAssigned = ticketAssignedRepository
353
						.selectByAssigneeIdAndTicketId(ticket.getL2AuthUser(), ticket.getId());
354
				if (ticketAssigned == null) {
355
					List<AuthUser> authUsers = new ArrayList<>();
356
					authUsers.add(authRepository.selectById(ticket.getL1AuthUser()));
357
					authUserListMap.put(ticket.getId(), authUsers);
358
				} else {
359
					List<AuthUser> authUsers = new ArrayList<>();
360
					authUsers.add(authRepository.selectById(ticket.getL1AuthUser()));
361
					authUsers.add(authRepository.selectById(ticket.getL2AuthUser()));
362
					authUserListMap.put(ticket.getId(), authUsers);
363
				}
364
			} else {
365
				TicketAssigned ticketAssigned = ticketAssignedRepository
366
						.selectByAssigneeIdAndTicketId(ticket.getL3AuthUser(), ticket.getId());
367
				if (ticketAssigned == null) {
368
					ticketAssigned = ticketAssignedRepository.selectByAssigneeIdAndTicketId(ticket.getL2AuthUser(),
369
							ticket.getId());
370
					if (ticketAssigned == null) {
371
						List<AuthUser> authUsers = new ArrayList<>();
372
						authUsers.add(authRepository.selectById(ticket.getL1AuthUser()));
373
						authUserListMap.put(ticket.getId(), authUsers);
374
					} else {
375
						List<AuthUser> authUsers = new ArrayList<>();
376
						authUsers.add(authRepository.selectById(ticket.getL1AuthUser()));
377
						authUsers.add(authRepository.selectById(ticket.getL2AuthUser()));
378
						authUserListMap.put(ticket.getId(), authUsers);
379
					}
380
				} else {
381
					List<AuthUser> authUsers = new ArrayList<>();
382
					authUsers.add(authRepository.selectById(ticket.getL1AuthUser()));
383
					authUsers.add(authRepository.selectById(ticket.getL2AuthUser()));
384
					authUsers.add(authRepository.selectById(ticket.getL3AuthUser()));
385
					authUserListMap.put(ticket.getId(), authUsers);
386
 
387
				}
388
			}
389
		}
390
		return authUserListMap;
391
	}
24557 govind 392
 
24500 govind 393
	@Override
24557 govind 394
	public void updateTicket(int categoryId, int subCategoryId, Ticket ticket) throws ProfitMandiBusinessException {
395
		TicketAssigned ticketAssigned = new TicketAssigned();
24500 govind 396
		ticket.setSubCategoryId(subCategoryId);
397
		ticket.setUpdateTimestamp(LocalDateTime.now());
398
		ticket.setL2EscalationTimestamp(ticket.getUpdateTimestamp().plusDays(2));
399
		ticket.setL3EscalationTimestamp(ticket.getL2EscalationTimestamp().plusDays(2));
400
		ticket.setLastEscalationTimestamp(ticket.getL3EscalationTimestamp().plusDays(2));
401
		int l3Auth = this.getAuthUserId(categoryId, EscalationType.L3, ticket.getFofoId());
25505 amit.gupta 402
		int l2Auth = this.getAuthUserId(categoryId, EscalationType.L2, ticket.getFofoId());
24500 govind 403
		int l1Auth = this.getAuthUserId(categoryId, EscalationType.L1, ticket.getFofoId());
404
		LOGGER.info(l1Auth + "-" + l2Auth + "-" + l3Auth);
405
		if (l1Auth == 0) {
406
			if (l2Auth == 0) {
407
				this.setAssignment(ticket, ticketAssigned);
408
			} else {
409
				ticketAssigned.setAssineeId(l2Auth);
24569 govind 410
				ticket.setL1AuthUser(0);
24536 govind 411
				ticket.setL2AuthUser(l2Auth);
24500 govind 412
			}
413
		} else {
414
			ticketAssigned.setAssineeId(l1Auth);
415
			ticket.setL1AuthUser(l1Auth);
416
			ticket.setL2AuthUser(l2Auth);
417
		}
418
		ticket.setL3AuthUser(l3Auth);
419
		ticketRepository.persist(ticket);
420
		ticketAssigned.setTicketId(ticket.getId());
421
		ticketAssignedRepository.persist(ticketAssigned);
422
		AuthUser authUser = authRepository.selectById(ticketAssigned.getAssineeId());
24569 govind 423
		this.sendAssignedTicketMail(authUser, ticket);
424
	}
425
 
426
	@Override
24699 govind 427
	public void sendAssignedTicketMail(AuthUser authUser, Ticket ticket) throws ProfitMandiBusinessException {
24500 govind 428
		try {
429
			Utils.sendMailWithAttachments(mailSender, authUser.getEmailId(), null, ASSINMENT_SUBJECT,
430
					String.format(ASSIGNED_TICKET, authUser.getFirstName(),
24699 govind 431
							retailerService.getFofoRetailer(ticket.getFofoId()).getBusinessName(), ticket.getId()),
24500 govind 432
					null);
433
		} catch (Exception e) {
434
			throw new ProfitMandiBusinessException("Ticket Assingment", authUser.getEmailId(),
435
					"Could not send ticket assignment mail");
436
		}
437
	}
25570 tejbeer 438
 
439
	@Override
440
	public Map<Integer, List<CustomRetailer>> getPositionCustomRetailerMap(List<Position> positions) {
441
		Map<Integer, List<CustomRetailer>> positionRetailerMap = new HashMap<>();
442
		for (Position position : positions) {
443
			List<Integer> fofoIds = partnersPositionRepository.selectByPositionId(position.getId()).stream()
444
					.map(x -> x.getFofoId()).collect(Collectors.toList());
445
 
446
			if (!fofoIds.isEmpty()) {
447
				if (fofoIds.contains(0)) {
448
					fofoIds = partnerRegionRepository.selectByRegionId(position.getRegionId()).stream()
449
							.map(x -> x.getFofoId()).collect(Collectors.toList());
450
					if (fofoIds.contains(0)) {
451
						fofoIds = fofoStoreRepository.selectAll().stream().map(x -> x.getId())
452
								.collect(Collectors.toList());
453
					}
454
 
455
				}
456
				positionRetailerMap.put(position.getId(),
457
						new ArrayList<CustomRetailer>(retailerService.getFofoRetailers(fofoIds).values()));
458
 
459
			}
460
		}
461
		return positionRetailerMap;
462
	}
463
 
464
	@Override
465
	public Map<Integer, List<CustomRetailer>> getpositionIdAndpartnerRegionMap(List<Position> positions) {
466
		Map<Integer, List<CustomRetailer>> positionIdAndpartnerRegionMap = new HashedMap<>();
467
		for (Position position : positions) {
468
			List<Integer> fofoIds = partnerRegionRepository.selectByRegionId(position.getRegionId()).stream()
469
					.map(x -> x.getFofoId()).collect(Collectors.toList());
470
 
471
			if (!fofoIds.isEmpty()) {
472
				if (fofoIds.contains(0)) {
473
					fofoIds = fofoStoreRepository.selectAll().stream().map(x -> x.getId()).collect(Collectors.toList());
474
 
475
				}
476
 
477
				Map<Integer, CustomRetailer> fofoRetailers = retailerService.getFofoRetailers(fofoIds);
478
				positionIdAndpartnerRegionMap.put(position.getRegionId(),
479
						new ArrayList<CustomRetailer>(fofoRetailers.values()));
480
			}
481
 
482
		}
483
 
484
		return positionIdAndpartnerRegionMap;
485
	}
24383 amit.gupta 486
}