Subversion Repositories SmartDukaan

Rev

Rev 30003 | Rev 30423 | 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
 
30003 tejbeer 3
import java.time.LocalDateTime;
4
import java.util.ArrayList;
5
import java.util.Arrays;
6
import java.util.HashMap;
7
import java.util.HashSet;
8
import java.util.LinkedHashSet;
9
import java.util.List;
10
import java.util.Map;
11
import java.util.Set;
12
import java.util.stream.Collectors;
13
 
14
import org.apache.commons.collections4.map.HashedMap;
15
import org.apache.commons.lang.RandomStringUtils;
16
import org.apache.commons.lang.StringUtils;
17
import org.apache.logging.log4j.LogManager;
18
import org.apache.logging.log4j.Logger;
19
import org.springframework.beans.factory.annotation.Autowired;
20
import org.springframework.cache.annotation.Cacheable;
21
import org.springframework.mail.javamail.JavaMailSender;
22
import org.springframework.stereotype.Component;
23
 
24383 amit.gupta 24
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
24417 govind 25
import com.spice.profitmandi.common.model.CustomRetailer;
24439 govind 26
import com.spice.profitmandi.common.model.ProfitMandiConstants;
27
import com.spice.profitmandi.common.util.Utils;
24417 govind 28
import com.spice.profitmandi.dao.entity.auth.AuthUser;
30003 tejbeer 29
import com.spice.profitmandi.dao.entity.cs.Activity;
30
import com.spice.profitmandi.dao.entity.cs.PartnerRegion;
31
import com.spice.profitmandi.dao.entity.cs.Position;
32
import com.spice.profitmandi.dao.entity.cs.Region;
33
import com.spice.profitmandi.dao.entity.cs.Ticket;
34
import com.spice.profitmandi.dao.entity.cs.TicketAssigned;
35
import com.spice.profitmandi.dao.entity.cs.TicketCategory;
36
import com.spice.profitmandi.dao.entity.cs.TicketSubCategory;
24383 amit.gupta 37
import com.spice.profitmandi.dao.entity.fofo.ActivityType;
30003 tejbeer 38
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
24417 govind 39
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
30003 tejbeer 40
import com.spice.profitmandi.dao.model.FofoReportingModel;
24417 govind 41
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
25570 tejbeer 42
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
24417 govind 43
import com.spice.profitmandi.service.user.RetailerService;
24383 amit.gupta 44
 
45
@Component
46
public class CsServiceImpl implements CsService {
24417 govind 47
 
27124 amit.gupta 48
	private static final int ALL_PARTNERS_REGION = 5;
49
 
24439 govind 50
	private static final Logger LOGGER = LogManager.getLogger(CsServiceImpl.class);
51
 
27124 amit.gupta 52
	private static final String ASSIGNED_TICKET = "Dear %s, New ticket #%s created by %s has been assigned to you. Regards\nSmartdukaan";
53
	private static final String ESCALATED_TICKET = "Dear %s, Ticket #%s created by %s has been escalated to you. Regards\nSmartdukaan";
54
	private static final String CATEGORY_CHANGED_TICKET = "Dear team, Category of Ticket #%s created by %s has been changed to %s. Regards\nSmartdukaan";
24439 govind 55
	private static final String ASSINMENT_SUBJECT = "Assignment Ticket";
56
 
24383 amit.gupta 57
	@Autowired
58
	TicketRepository ticketRepository;
24417 govind 59
 
24383 amit.gupta 60
	@Autowired
24439 govind 61
	JavaMailSender mailSender;
62
 
63
	@Autowired
24383 amit.gupta 64
	TicketCategoryRepository ticketCategoryRepository;
24417 govind 65
 
24383 amit.gupta 66
	@Autowired
67
	TicketSubCategoryRepository ticketSubCategoryRepository;
24417 govind 68
 
69
	@Autowired
24388 amit.gupta 70
	ActivityRepository activityRepository;
24417 govind 71
 
72
	@Autowired
24439 govind 73
	PartnerRegionRepository partnerRegionRepository;
24417 govind 74
 
75
	@Autowired
76
	private PositionRepository positionRepository;
77
 
78
	@Autowired
79
	private AuthRepository authRepository;
80
 
81
	@Autowired
82
	private RetailerService retailerService;
24500 govind 83
 
24471 govind 84
	@Autowired
85
	private RegionRepository regionRepository;
24417 govind 86
 
24500 govind 87
	@Autowired
88
	private TicketAssignedRepository ticketAssignedRepository;
89
 
25570 tejbeer 90
	@Autowired
91
	private PartnersPositionRepository partnersPositionRepository;
92
 
93
	@Autowired
94
	private FofoStoreRepository fofoStoreRepository;
95
 
24383 amit.gupta 96
	@Override
24439 govind 97
	public void createTicket(int fofoId, int categoryId, int subcategoryId, String message)
98
			throws ProfitMandiBusinessException {
24417 govind 99
 
24383 amit.gupta 100
		ActivityType type = ActivityType.OPENED;
101
		Ticket ticket = new Ticket();
102
		ticket.setSubCategoryId(subcategoryId);
24417 govind 103
		ticket.setFofoId(fofoId);
24383 amit.gupta 104
		ticket.setCreateTimestamp(LocalDateTime.now());
24417 govind 105
		ticket.setUpdateTimestamp(LocalDateTime.now());
24439 govind 106
		ticket.setHappyCode(getRandomString());
27124 amit.gupta 107
		ticketRepository.persist(ticket);
108
		this.addActivity(ticket, this.createActivity(type, message, 0));
109
		this.assignTicket(ticket);
110
 
111
	}
112
 
113
	@Override
114
	public void assignTicket(Ticket ticket) throws ProfitMandiBusinessException {
115
		TicketAssigned ticketAssigned = null;
116
		EscalationType newEscalationType = EscalationType.L1;
27545 tejbeer 117
		if (ticket.getAssignmentId() > 0) {
27124 amit.gupta 118
			ticketAssigned = ticketAssignedRepository.selectById(ticket.getAssignmentId());
119
			newEscalationType = ticketAssigned.getEscalationType().next();
27393 amit.gupta 120
			if (newEscalationType == null || newEscalationType.equals(EscalationType.Final)) {
27124 amit.gupta 121
				LOGGER.info("Cant escalate further");
122
				return;
24439 govind 123
			}
27393 amit.gupta 124
		} else {
125
			ticket.setL1AuthUser(0);
126
			ticket.setL2AuthUser(0);
127
			ticket.setL3AuthUser(0);
128
			ticket.setL4AuthUser(0);
129
			ticket.setL5AuthUser(0);
27124 amit.gupta 130
		}
131
		ticket.setUpdateTimestamp(LocalDateTime.now());
132
		TicketSubCategory ticketSubCategory = ticketSubCategoryRepository.selectById(ticket.getSubCategoryId());
133
		TicketCategory ticketCategory = ticketCategoryRepository.selectById(ticketSubCategory.getCategoryId());
134
		Map<Integer, EscalationType> escalationUserMap = new HashedMap<>();
135
		Set<Integer> assigneeUserIds = new LinkedHashSet<>();
136
		EscalationType escalationTypeNext = newEscalationType;
137
		do {
138
			int assigneeUserId = this.getAuthUserId(ticketCategory.getId(), escalationTypeNext, ticket.getFofoId());
139
			if (assigneeUserId == 0) {
140
				escalationTypeNext = escalationTypeNext.next();
141
				LOGGER.info("Escalation type next {}", escalationTypeNext);
142
				continue;
143
			}
144
			assigneeUserIds.add(assigneeUserId);
145
			escalationUserMap.put(assigneeUserId, escalationTypeNext);
146
			switch (escalationTypeNext) {
147
			case L1:
148
				ticket.setL1AuthUser(assigneeUserId);
149
				break;
150
			case L2:
151
				ticket.setL2AuthUser(assigneeUserId);
152
				break;
153
			case L3:
154
				ticket.setL3AuthUser(assigneeUserId);
155
				break;
156
			case L4:
157
				ticket.setL4AuthUser(assigneeUserId);
158
				break;
159
			case L5:
160
				ticket.setL5AuthUser(assigneeUserId);
161
				break;
162
 
163
			default:
164
				break;
165
			}
166
			escalationTypeNext = escalationTypeNext.next();
167
			// LOGGER.info("Escalation type next {}", escalationTypeNext);
168
		} while (!escalationTypeNext.equals(EscalationType.Final));
169
 
170
		int assigneeAuthId = assigneeUserIds.stream().findFirst().orElse(0);
27545 tejbeer 171
 
27124 amit.gupta 172
		int managerAuthId = 0;
173
		EscalationType assigneeEscalationType = null;
174
		if (assigneeAuthId == 0) {
175
			assigneeAuthId = ProfitMandiConstants.FINAL_AUTH_ID;
176
			assigneeEscalationType = EscalationType.Final;
27393 amit.gupta 177
			managerAuthId = ProfitMandiConstants.FINAL_AUTH_ID;
24439 govind 178
		} else {
27124 amit.gupta 179
			assigneeEscalationType = escalationUserMap.get(assigneeAuthId);
180
			managerAuthId = assigneeUserIds.stream().skip(1).findFirst().orElse(0);
181
			if (managerAuthId == 0) {
182
				managerAuthId = ProfitMandiConstants.FINAL_AUTH_ID;
183
			}
24439 govind 184
		}
27124 amit.gupta 185
 
186
		TicketAssigned ticketAssignedNew = new TicketAssigned();
187
		ticketAssignedNew.setTicketId(ticket.getId());
188
		ticketAssignedNew.setAssineeId(assigneeAuthId);
189
		ticketAssignedNew.setEscalationType(assigneeEscalationType);
27393 amit.gupta 190
		ticketAssignedNew.setManagerId(managerAuthId);
27124 amit.gupta 191
		ticketAssignedNew.setCreateTimestamp(LocalDateTime.now());
192
		ticketAssignedRepository.persist(ticketAssignedNew);
193
		LOGGER.info(ticketAssigned);
27545 tejbeer 194
 
27124 amit.gupta 195
		AuthUser authUser = authRepository.selectById(ticketAssignedNew.getAssineeId());
196
		AuthUser authUserManager = null;
27545 tejbeer 197
 
198
		// Dont send cc mail if both are same
199
		if (managerAuthId != assigneeAuthId) {
27124 amit.gupta 200
			authUserManager = authRepository.selectById(managerAuthId);
201
		}
202
		ticket.setAssignmentId(ticketAssignedNew.getId());
27545 tejbeer 203
		this.sendAssignedTicketMail(authUser, Arrays.asList(authUserManager), ticket, ticketAssigned != null);
27124 amit.gupta 204
		if (!ticketAssignedNew.getEscalationType().equals(EscalationType.L1)) {
205
			this.addActivity(ticket, this.createActivity(ActivityType.ESCALATED,
206
					"Ticket ecalated and assigned to " + authUser.getName(), 0));
207
		} else {
208
			this.addActivity(ticket,
209
					this.createActivity(ActivityType.ASSIGNED, "Ticket assigned to " + authUser.getName(), 0));
210
		}
24383 amit.gupta 211
	}
212
 
27124 amit.gupta 213
	@Override
214
	public void updateTicket(int categoryId, int subCategoryId, Ticket ticket) throws ProfitMandiBusinessException {
215
 
216
		TicketSubCategory ticketSubCategory = ticketSubCategoryRepository.getTicketSubCategoryMap().get(subCategoryId);
27545 tejbeer 217
		if (ticketSubCategory == null) {
218
			throw new ProfitMandiBusinessException("Could not find subCategoryId " + subCategoryId + "- " + categoryId,
219
					"Problem", "Problem");
27126 amit.gupta 220
		}
27861 tejbeer 221
		String storeName = retailerService.getAllFofoRetailers().get(ticket.getFofoId()).getBusinessName();
27545 tejbeer 222
		List<TicketAssigned> oldTicketAssignedList = ticketAssignedRepository
223
				.selectByTicketIds(Arrays.asList(ticket.getId()));
224
		for (TicketAssigned oldTicketAssigned : oldTicketAssignedList) {
27124 amit.gupta 225
			ticketAssignedRepository.delete(oldTicketAssigned);
226
		}
227
 
27153 amit.gupta 228
		if (ticket.getSubCategoryId() != ticketSubCategory.getId()) {
229
			ticket.setSubCategoryId(ticketSubCategory.getId());
27545 tejbeer 230
			List<Integer> oldAssignedAuthUserIds = oldTicketAssignedList.stream().map(x -> x.getAssineeId())
231
					.collect(Collectors.toList());
232
			List<String> oldAssignedEmailIds = authRepository.selectAllAuthUserByIds(oldAssignedAuthUserIds).stream()
233
					.map(x -> x.getEmailId()).collect(Collectors.toList());
27124 amit.gupta 234
			String mailTo = oldAssignedEmailIds.remove(0);
27545 tejbeer 235
			String message = String.format(CATEGORY_CHANGED_TICKET, ticket.getId(), storeName,
236
					ticketSubCategory.getTicketCategory().getName() + " - " + ticketSubCategory.getName());
27124 amit.gupta 237
			try {
27545 tejbeer 238
				Utils.sendMailWithAttachments(mailSender, mailTo, oldAssignedEmailIds.toArray(new String[0]),
239
						"Ticket Category/Subcategory Changed", message, null);
27124 amit.gupta 240
			} catch (Exception e) {
241
				LOGGER.info("Could not send mail for ticket {}", ticket.toString());
242
			}
243
		}
244
 
245
		Activity categoryChangedActivity = this.createActivity(ActivityType.CATEGORY_CHANGED, "Category changed to "
246
				+ ticketSubCategory.getTicketCategory().getName() + " - " + ticketSubCategory.getName(), 0);
247
		this.addActivity(ticket, categoryChangedActivity);
27393 amit.gupta 248
		ticket.setAssignmentId(0);
27124 amit.gupta 249
		this.assignTicket(ticket);
27545 tejbeer 250
 
27124 amit.gupta 251
	}
252
 
27393 amit.gupta 253
	@Override
254
	public Activity createActivity(ActivityType activityType, String message, int createdBy) {
24383 amit.gupta 255
		Activity activity = new Activity();
256
		activity.setMessage(message);
257
		activity.setCreatedBy(createdBy);
258
		activity.setType(activityType);
24417 govind 259
		activity.setCreateTimestamp(LocalDateTime.now());
27124 amit.gupta 260
		activityRepository.persist(activity);
24383 amit.gupta 261
		return activity;
262
	}
24417 govind 263
 
27078 amit.gupta 264
	@Override
265
	public int getAuthUserId(int categoryId, EscalationType escalationType, int fofoId) {
27124 amit.gupta 266
		int authUserId = 0;
267
		List<Position> positions = positionRepository.selectPositionbyCategoryIdAndEscalationType(categoryId,
268
				escalationType);
269
		List<Integer> regionIds = partnerRegionRepository.selectByfofoId(fofoId).stream().map(x -> x.getRegionId())
270
				.collect(Collectors.toList());
271
		// Add all Partner regions id
272
		regionIds.add(ALL_PARTNERS_REGION);
273
		LOGGER.info("Escalation Type {}, Region Ids {}", escalationType, regionIds);
274
		List<Integer> partnerPositionsIds = partnersPositionRepository
275
				.selectByRegionIdAndPartnerId(regionIds, Arrays.asList(0, fofoId)).stream().map(x -> x.getPositionId())
276
				.collect(Collectors.toList());
277
		positions = positions.stream().filter(x -> partnerPositionsIds.contains(x.getId()))
278
				.collect(Collectors.toList());
279
		LOGGER.info("User List List {}", positions.stream().map(x -> x.getAuthUserId()).collect(Collectors.toList()));
280
		if (positions.size() > 0) {
281
			List<AuthUser> authUsers = authRepository.selectAllAuthUserByIds(
282
					positions.stream().map(x -> x.getAuthUserId()).collect(Collectors.toList()));
283
			authUsers = authUsers.stream().filter(x -> x.isActive()).collect(Collectors.toList());
284
			if (authUsers.size() > 0) {
27260 amit.gupta 285
				authUserId = authUsers.get(0).getId();
27545 tejbeer 286
				/*
287
				 * Random rand = new Random(); authUserId =
288
				 * authUsers.get(rand.nextInt(authUsers.size())).getId();
289
				 */
24452 govind 290
			}
24439 govind 291
		}
27124 amit.gupta 292
		return authUserId;
24439 govind 293
 
24383 amit.gupta 294
	}
295
 
296
	@Override
27124 amit.gupta 297
	public void addActivity(Ticket ticket, Activity activity) {
298
		activity.setTicketId(ticket.getId());
299
		ticket.setLastActivity(activity.getType());
300
		ticket.setLastActivityId(activity.getId());
24383 amit.gupta 301
	}
302
 
24439 govind 303
	private String getRandomString() {
304
		int length = 4;
305
		boolean useLetters = false;
306
		boolean useNumbers = true;
307
		String generatedString = RandomStringUtils.random(length, useLetters, useNumbers);
308
		return generatedString;
309
	}
310
 
24417 govind 311
	@Override
312
	public void addPartnerToRegion(int regionId, List<Integer> fofoIds) {
313
 
24557 govind 314
		for (int fofoId : fofoIds) {
315
			PartnerRegion partnerRegion = new PartnerRegion();
316
			partnerRegion.setFofoId(fofoId);
317
			partnerRegion.setRegionId(regionId);
318
			partnerRegionRepository.persist(partnerRegion);
24417 govind 319
		}
320
	}
321
 
322
	@Override
24500 govind 323
	public Map<Integer, AuthUser> getAuthUserIdAndAuthUserMap(List<TicketAssigned> ticketAssigneds) {
24417 govind 324
		Map<Integer, AuthUser> authUserIdAndAuthUserMap = new HashMap<>();
24500 govind 325
 
326
		for (TicketAssigned ticketAssigned : ticketAssigneds) {
327
			AuthUser authUser = authRepository.selectById(ticketAssigned.getAssineeId());
328
			authUserIdAndAuthUserMap.put(ticketAssigned.getTicketId(), authUser);
329
		}
330
		return authUserIdAndAuthUserMap;
331
	}
332
 
333
	@Override
334
	public Map<Integer, AuthUser> getTicketIdAndAuthUserMapUsingTickets(List<Ticket> tickets) {
335
		Map<Integer, AuthUser> authUserIdAndAuthUserMap = new HashMap<>();
336
 
24417 govind 337
		for (Ticket ticket : tickets) {
24500 govind 338
			AuthUser authUser = authRepository.selectById(ticket.getL1AuthUser());
339
			authUserIdAndAuthUserMap.put(ticket.getId(), authUser);
24417 govind 340
		}
341
		return authUserIdAndAuthUserMap;
342
	}
343
 
344
	@Override
345
	public Map<Integer, TicketSubCategory> getSubCategoryIdAndSubCategoryMap(List<Ticket> tickets) {
346
		Map<Integer, TicketSubCategory> subCategoryIdAndSubCategoryMap = new HashMap<>();
24699 govind 347
		if (tickets != null) {
348
			for (Ticket ticket : tickets) {
349
				TicketSubCategory ticketSubCategory = ticketSubCategoryRepository.selectById(ticket.getSubCategoryId());
350
				subCategoryIdAndSubCategoryMap.put(ticket.getSubCategoryId(), ticketSubCategory);
351
			}
24417 govind 352
		}
353
		return subCategoryIdAndSubCategoryMap;
354
	}
355
 
356
	@Override
357
	public Map<Integer, CustomRetailer> getPartnerByFofoIds(List<Ticket> tickets) {
358
		List<Integer> fofoIds = new ArrayList<>();
24569 govind 359
		LOGGER.info(tickets);
24699 govind 360
		if (tickets == null) {
24569 govind 361
			return null;
362
		}
24417 govind 363
		for (Ticket ticket : tickets) {
364
			fofoIds.add(ticket.getFofoId());
365
		}
24699 govind 366
		Map<Integer, CustomRetailer> fofoIdsAndCustomRetailer = retailerService.getFofoRetailers(fofoIds);
24417 govind 367
		return fofoIdsAndCustomRetailer;
368
	}
369
 
24439 govind 370
	@Override
371
	public List<TicketCategory> getAllTicketCategotyFromSubCategory() {
372
 
373
		List<TicketSubCategory> ticketSubCategories = ticketSubCategoryRepository.selectAll();
374
		HashSet<Integer> categoryIds = new HashSet<>();
375
		for (TicketSubCategory ticketSubcategory : ticketSubCategories) {
27124 amit.gupta 376
			categoryIds.add(ticketSubcategory.getCategoryId());
24439 govind 377
		}
378
		List<TicketCategory> ticketcategories = ticketCategoryRepository.selectAll(new ArrayList<>(categoryIds));
379
		return ticketcategories;
380
	}
381
 
24471 govind 382
	@Override
383
	public Map<Integer, AuthUser> getAuthUserIdAndAuthUserMapUsingPositions(List<Position> positions) {
384
		Map<Integer, AuthUser> authUserIdAndAuthUserMap = new HashMap<>();
385
		for (Position position : positions) {
386
			AuthUser authUser = authRepository.selectById(position.getAuthUserId());
387
			authUserIdAndAuthUserMap.put(position.getAuthUserId(), authUser);
388
		}
389
		return authUserIdAndAuthUserMap;
390
	}
24500 govind 391
 
24471 govind 392
	@Override
393
	public Map<Integer, TicketCategory> getCategoryIdAndCategoryUsingPositions(List<Position> positions) {
394
		Map<Integer, TicketCategory> categoryIdAndCategoryMap = new HashMap<>();
395
		for (Position position : positions) {
24500 govind 396
			TicketCategory ticketCategory = ticketCategoryRepository.selectById(position.getCategoryId());
24471 govind 397
			categoryIdAndCategoryMap.put(position.getCategoryId(), ticketCategory);
398
		}
399
		return categoryIdAndCategoryMap;
400
	}
24439 govind 401
 
24471 govind 402
	@Override
403
	public Map<Integer, Region> getRegionIdAndRegionMap(List<Position> positions) {
404
		Map<Integer, Region> regionIdAndRegionMap = new HashMap<>();
405
		for (Position position : positions) {
24500 govind 406
			Region region = regionRepository.selectById(position.getRegionId());
24471 govind 407
			regionIdAndRegionMap.put(position.getRegionId(), region);
408
		}
409
		return regionIdAndRegionMap;
410
	}
24500 govind 411
 
27545 tejbeer 412
	private void sendAssignedTicketMail(AuthUser authUserTo, List<AuthUser> authUsersCc, Ticket ticket,
413
			boolean isEscalated) throws ProfitMandiBusinessException {
27124 amit.gupta 414
		try {
415
			String[] ccTo = authUsersCc.stream().filter(x -> x != null).map(x -> x.getEmailId()).toArray(String[]::new);
416
 
417
			String messageFormat = null;
27545 tejbeer 418
			if (isEscalated) {
27124 amit.gupta 419
				messageFormat = ESCALATED_TICKET;
24500 govind 420
			} else {
27124 amit.gupta 421
				messageFormat = ASSIGNED_TICKET;
24500 govind 422
			}
27124 amit.gupta 423
			String message = String.format(messageFormat, authUserTo.getName(), ticket.getId(),
424
					retailerService.getFofoRetailer(ticket.getFofoId()).getBusinessName());
27545 tejbeer 425
			Utils.sendMailWithAttachments(mailSender, authUserTo.getEmailId(), ccTo, ASSINMENT_SUBJECT, message, null);
24500 govind 426
		} catch (Exception e) {
27124 amit.gupta 427
			e.printStackTrace();
428
			throw new ProfitMandiBusinessException("Ticket Assingment", authUserTo.getEmailId(),
24500 govind 429
					"Could not send ticket assignment mail");
430
		}
431
	}
25570 tejbeer 432
 
433
	@Override
434
	public Map<Integer, List<CustomRetailer>> getPositionCustomRetailerMap(List<Position> positions) {
435
		Map<Integer, List<CustomRetailer>> positionRetailerMap = new HashMap<>();
436
		for (Position position : positions) {
437
			List<Integer> fofoIds = partnersPositionRepository.selectByPositionId(position.getId()).stream()
438
					.map(x -> x.getFofoId()).collect(Collectors.toList());
439
 
26992 amit.gupta 440
			LOGGER.info("fofoIds - {}", fofoIds);
25570 tejbeer 441
			if (!fofoIds.isEmpty()) {
442
				if (fofoIds.contains(0)) {
443
					fofoIds = partnerRegionRepository.selectByRegionId(position.getRegionId()).stream()
444
							.map(x -> x.getFofoId()).collect(Collectors.toList());
445
					if (fofoIds.contains(0)) {
446
						fofoIds = fofoStoreRepository.selectAll().stream().map(x -> x.getId())
447
								.collect(Collectors.toList());
448
					}
449
 
450
				}
26991 amit.gupta 451
				LOGGER.info("fofoIds - {}", fofoIds);
25570 tejbeer 452
				positionRetailerMap.put(position.getId(),
453
						new ArrayList<CustomRetailer>(retailerService.getFofoRetailers(fofoIds).values()));
454
 
455
			}
456
		}
457
		return positionRetailerMap;
458
	}
459
 
460
	@Override
27410 tejbeer 461
	public Map<Integer, List<CustomRetailer>> getRegionPartners(List<Position> positions) {
25570 tejbeer 462
		Map<Integer, List<CustomRetailer>> positionIdAndpartnerRegionMap = new HashedMap<>();
463
		for (Position position : positions) {
464
			List<Integer> fofoIds = partnerRegionRepository.selectByRegionId(position.getRegionId()).stream()
465
					.map(x -> x.getFofoId()).collect(Collectors.toList());
466
 
467
			if (!fofoIds.isEmpty()) {
468
				if (fofoIds.contains(0)) {
469
					fofoIds = fofoStoreRepository.selectAll().stream().map(x -> x.getId()).collect(Collectors.toList());
470
 
471
				}
472
 
473
				Map<Integer, CustomRetailer> fofoRetailers = retailerService.getFofoRetailers(fofoIds);
474
				positionIdAndpartnerRegionMap.put(position.getRegionId(),
475
						new ArrayList<CustomRetailer>(fofoRetailers.values()));
476
			}
477
 
478
		}
479
 
480
		return positionIdAndpartnerRegionMap;
481
	}
25597 amit.gupta 482
 
483
	@Override
25726 amit.gupta 484
	@Cacheable(value = "authUserEmailMapping", cacheManager = "thirtyMinsTimeOutCacheManager")
25597 amit.gupta 485
	public Map<String, Set<String>> getAuthUserPartnerEmailMapping() {
486
		Map<String, Set<String>> storeGuyMap = new HashMap<>();
487
		Set<Integer> activeFofoIds = fofoStoreRepository.selectActiveStores().stream().map(x -> x.getId())
488
				.collect(Collectors.toSet());
489
		List<Position> categoryPositions = positionRepository
490
				.selectPositionByCategoryId(ProfitMandiConstants.TICKET_CATEGORY_SALES);
28908 tejbeer 491
		categoryPositions
492
				.addAll(positionRepository.selectPositionByCategoryId(ProfitMandiConstants.TICKET_CATEGORY_RBM));
25597 amit.gupta 493
		Map<Integer, Position> positionsMap = categoryPositions.stream()
494
				.collect(Collectors.toMap(x -> x.getId(), x -> x));
495
 
25721 tejbeer 496
		Map<Integer, List<CustomRetailer>> positonPartnerMap = this.getPositionCustomRetailerMap(categoryPositions);
25597 amit.gupta 497
		for (Map.Entry<Integer, List<CustomRetailer>> positionPartnerEntry : positonPartnerMap.entrySet()) {
498
			int authUserId = positionsMap.get(positionPartnerEntry.getKey()).getAuthUserId();
499
			Set<String> partnerEmails = positionPartnerEntry.getValue().stream()
500
					.filter(x -> activeFofoIds.contains(x.getPartnerId())).map(x -> x.getEmail())
501
					.collect(Collectors.toSet());
502
			AuthUser authUser = authRepository.selectById(authUserId);
503
			if (authUser.isActive()) {
26298 tejbeer 504
				if (!storeGuyMap.containsKey(authUser.getEmailId())) {
26111 amit.gupta 505
					storeGuyMap.put(authUser.getEmailId(), partnerEmails);
506
				} else {
507
					storeGuyMap.get(authUser.getEmailId()).addAll(partnerEmails);
508
				}
25597 amit.gupta 509
			}
510
		}
511
		return storeGuyMap;
512
	}
25721 tejbeer 513
 
514
	@Override
25777 amit.gupta 515
	@Cacheable(value = "authUserEmailPartnerIdMapping", cacheManager = "thirtyMinsTimeOutCacheManager")
25721 tejbeer 516
	public Map<String, Set<Integer>> getAuthUserPartnerIdMapping() {
517
		Map<String, Set<Integer>> storeGuyMap = new HashMap<>();
25777 amit.gupta 518
		Set<Integer> activeFofoIds = fofoStoreRepository.selectActiveStores().stream().map(x -> x.getId())
519
				.collect(Collectors.toSet());
25721 tejbeer 520
		List<Position> categoryPositions = positionRepository
521
				.selectPositionByCategoryId(ProfitMandiConstants.TICKET_CATEGORY_SALES);
28908 tejbeer 522
		categoryPositions
523
				.addAll(positionRepository.selectPositionByCategoryId(ProfitMandiConstants.TICKET_CATEGORY_RBM));
25721 tejbeer 524
		Map<Integer, Position> positionsMap = categoryPositions.stream()
525
				.collect(Collectors.toMap(x -> x.getId(), x -> x));
526
 
527
		Map<Integer, List<CustomRetailer>> positonPartnerMap = this.getPositionCustomRetailerMap(categoryPositions);
528
		for (Map.Entry<Integer, List<CustomRetailer>> positionPartnerEntry : positonPartnerMap.entrySet()) {
529
			int authUserId = positionsMap.get(positionPartnerEntry.getKey()).getAuthUserId();
27044 amit.gupta 530
			Set<Integer> partnerIds = positionPartnerEntry.getValue().stream()
25777 amit.gupta 531
					.filter(x -> activeFofoIds.contains(x.getPartnerId())).map(x -> x.getPartnerId())
25721 tejbeer 532
					.collect(Collectors.toSet());
533
			AuthUser authUser = authRepository.selectById(authUserId);
534
			if (authUser.isActive()) {
26298 tejbeer 535
				if (!storeGuyMap.containsKey(authUser.getEmailId())) {
27044 amit.gupta 536
					storeGuyMap.put(authUser.getEmailId(), partnerIds);
26111 amit.gupta 537
				} else {
27044 amit.gupta 538
					storeGuyMap.get(authUser.getEmailId()).addAll(partnerIds);
26111 amit.gupta 539
				}
25721 tejbeer 540
			}
541
		}
542
		return storeGuyMap;
543
	}
544
 
545
	@Override
546
	public List<String> getAuthUserByPartnerId(int fofoId) {
547
 
548
		List<String> emails = new ArrayList<>();
549
		List<Integer> regionIds = partnerRegionRepository.selectByfofoId(fofoId).stream().map(x -> x.getRegionId())
550
				.collect(Collectors.toList());
551
 
552
		regionIds.add(5);// All partners Id;
25799 tejbeer 553
 
29318 tejbeer 554
		List<Integer> partnerPositionIds = partnersPositionRepository
555
				.selectByRegionIdAndPartnerId(regionIds, Arrays.asList(fofoId, 0)).stream().map(x -> x.getPositionId())
556
				.collect(Collectors.toList());
25721 tejbeer 557
 
25799 tejbeer 558
		LOGGER.info("partnerPositionIds" + partnerPositionIds);
559
 
29318 tejbeer 560
		List<Position> positions = positionRepository.selectAll(partnerPositionIds);
25721 tejbeer 561
 
29318 tejbeer 562
		positions = positions.stream().filter(x -> (x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_SALES
563
				|| x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_RBM)).collect(Collectors.toList());
564
 
565
		if (!positions.isEmpty()) {
566
			for (Position partnerPostionId : positions) {
567
 
568
				AuthUser authUser = authRepository.selectById(partnerPostionId.getAuthUserId());
25799 tejbeer 569
				LOGGER.info("authUser" + authUser);
570
				emails.add(authUser.getEmailId());
571
			}
25721 tejbeer 572
		}
573
 
574
		return emails;
575
	}
26298 tejbeer 576
 
577
	@Override
26978 tejbeer 578
	public Map<EscalationType, String> getAuthUserAndEsclationTypeByPartnerId(int fofoId) {
579
 
580
		List<String> emails = new ArrayList<>();
581
		Map<EscalationType, String> emailEsclationTypeMap = new HashMap<>();
582
		List<Integer> regionIds = partnerRegionRepository.selectByfofoId(fofoId).stream().map(x -> x.getRegionId())
583
				.collect(Collectors.toList());
584
 
585
		regionIds.add(5);// All partners Id;
586
		List<Integer> fofoIds = new ArrayList<>();
587
		fofoIds.add(fofoId);
588
		fofoIds.add(0);
589
 
590
		LOGGER.info("fofoIds" + fofoIds);
591
		List<Integer> partnerPositionIds = partnersPositionRepository.selectByRegionIdAndPartnerId(regionIds, fofoIds)
592
				.stream().map(x -> x.getPositionId()).collect(Collectors.toList());
593
 
594
		LOGGER.info("partnerPositionIds" + partnerPositionIds);
595
 
596
		for (Integer partnerPostionId : partnerPositionIds) {
597
			Position position = positionRepository.selectByIdAndCategoryId(partnerPostionId,
598
					ProfitMandiConstants.TICKET_CATEGORY_SALES);
599
			LOGGER.info("position" + position);
600
			if (position != null) {
601
 
602
				AuthUser authUser = authRepository.selectById(position.getAuthUserId());
603
				LOGGER.info("authUser" + authUser);
604
 
605
				emailEsclationTypeMap.put(position.getEscalationType(), authUser.getEmailId());
606
			}
607
		}
608
 
609
		LOGGER.info("emailEsclationTypeMap" + emailEsclationTypeMap);
610
 
611
		return emailEsclationTypeMap;
612
	}
613
 
614
	@Override
26298 tejbeer 615
	@Cacheable(value = "authUserIdPartnerIdMapping", cacheManager = "thirtyMinsTimeOutCacheManager")
616
	public Map<Integer, List<Integer>> getAuthUserIdPartnerIdMapping() {
617
		Map<Integer, List<Integer>> storeGuyMap = new HashMap<>();
618
		Set<Integer> activeFofoIds = fofoStoreRepository.selectActiveStores().stream().map(x -> x.getId())
619
				.collect(Collectors.toSet());
620
		List<Position> categoryPositions = positionRepository
621
				.selectPositionByCategoryId(ProfitMandiConstants.TICKET_CATEGORY_SALES);
28908 tejbeer 622
		categoryPositions
623
				.addAll(positionRepository.selectPositionByCategoryId(ProfitMandiConstants.TICKET_CATEGORY_RBM));
29229 tejbeer 624
 
625
		categoryPositions
626
				.addAll(positionRepository.selectPositionByCategoryId(ProfitMandiConstants.TICKET_CATEGORY_CRM));
627
 
26298 tejbeer 628
		Map<Integer, Position> positionsMap = categoryPositions.stream()
629
				.collect(Collectors.toMap(x -> x.getId(), x -> x));
630
 
631
		Map<Integer, List<CustomRetailer>> positonPartnerMap = this.getPositionCustomRetailerMap(categoryPositions);
632
		for (Map.Entry<Integer, List<CustomRetailer>> positionPartnerEntry : positonPartnerMap.entrySet()) {
633
			int authUserId = positionsMap.get(positionPartnerEntry.getKey()).getAuthUserId();
26991 amit.gupta 634
			List<Integer> partnerIds = positionPartnerEntry.getValue().stream()
26298 tejbeer 635
					.filter(x -> activeFofoIds.contains(x.getPartnerId())).map(x -> x.getPartnerId())
636
					.collect(Collectors.toList());
637
			AuthUser authUser = authRepository.selectById(authUserId);
27044 amit.gupta 638
			if (authUser != null && authUser.isActive()) {
26960 amit.gupta 639
				if (!storeGuyMap.containsKey(authUserId)) {
26991 amit.gupta 640
					storeGuyMap.put(authUserId, partnerIds);
26298 tejbeer 641
				} else {
26991 amit.gupta 642
					storeGuyMap.get(authUserId).addAll(partnerIds);
26298 tejbeer 643
				}
644
			}
645
		}
646
		return storeGuyMap;
647
	}
648
 
649
	@Override
650
	@Cacheable(value = "L1L2Mapping", cacheManager = "thirtyMinsTimeOutCacheManager")
26460 amit.gupta 651
	public Map<Integer, List<Integer>> getL2L1Mapping() {
26448 amit.gupta 652
		List<Position> l1SalesPositions = positionRepository.selectPositionbyCategoryIdAndEscalationType(
653
				ProfitMandiConstants.TICKET_CATEGORY_SALES, EscalationType.L1);
654
		List<Position> l2SalesPositions = positionRepository.selectPositionbyCategoryIdAndEscalationType(
655
				ProfitMandiConstants.TICKET_CATEGORY_SALES, EscalationType.L2);
26298 tejbeer 656
 
26448 amit.gupta 657
		LOGGER.info("position" + l1SalesPositions);
658
		Map<Integer, List<Integer>> authUserPartnerListMap = this.getAuthUserIdPartnerIdMapping();
659
		LOGGER.info("map" + authUserPartnerListMap);
26298 tejbeer 660
 
26448 amit.gupta 661
		Map<Integer, List<Integer>> l2l1ListMap = new HashMap<>();
26298 tejbeer 662
 
26448 amit.gupta 663
		for (Position l2SalePosition : l2SalesPositions) {
664
			int l2AuthUserId = l2SalePosition.getAuthUserId();
665
			if (authUserPartnerListMap.containsKey(l2SalePosition.getAuthUserId())) {
666
				List<Integer> mappedL1AuthUsers = new ArrayList<>();
667
				l2l1ListMap.put(l2AuthUserId, mappedL1AuthUsers);
668
				List<Integer> l2FofoIds = authUserPartnerListMap.get(l2AuthUserId);
669
				for (Position l1SalePosition : l1SalesPositions) {
670
					int l1AuthUserId = l1SalePosition.getAuthUserId();
671
					if (authUserPartnerListMap.containsKey(l1AuthUserId)) {
672
						List<Integer> l1FofoIds = authUserPartnerListMap.get(l1SalePosition.getAuthUserId());
673
						if (l2FofoIds.containsAll(l1FofoIds)) {
674
							mappedL1AuthUsers.add(l1AuthUserId);
675
						}
676
					}
26298 tejbeer 677
 
678
				}
679
			}
680
 
681
		}
682
 
26448 amit.gupta 683
		return l2l1ListMap;
26298 tejbeer 684
	}
26448 amit.gupta 685
 
27205 amit.gupta 686
	@Override
687
	public Map<Integer, List<AuthUser>> getAssignedAuthList(List<Ticket> tickets) {
27545 tejbeer 688
		if (tickets.size() == 0) {
27259 amit.gupta 689
			return new HashMap<>();
690
		}
27545 tejbeer 691
		List<TicketAssigned> ticketAssignedList = ticketAssignedRepository
692
				.selectByTicketIds(tickets.stream().map(x -> x.getId()).collect(Collectors.toList()));
693
		List<Integer> authUserIds = ticketAssignedList.stream().map(x -> x.getAssineeId()).distinct()
694
				.collect(Collectors.toList());
695
		Map<Integer, AuthUser> authUserMap = authRepository.selectAllAuthUserByIds(authUserIds).stream()
696
				.collect(Collectors.toMap(x -> x.getId(), x -> x));
697
		return ticketAssignedList.stream().collect(Collectors.groupingBy(x -> x.getTicketId(),
698
				Collectors.mapping(x -> authUserMap.get(x.getAssineeId()), Collectors.toList())));
27205 amit.gupta 699
	}
700
 
27548 tejbeer 701
	@Override
702
	public Map<EscalationType, AuthUser> getAuthUserAndEsclationByPartnerId(int fofoId) {
703
		Map<EscalationType, AuthUser> authuserEsclationTypeMap = new HashMap<>();
704
		List<Integer> regionIds = partnerRegionRepository.selectByfofoId(fofoId).stream().map(x -> x.getRegionId())
705
				.collect(Collectors.toList());
706
 
707
		regionIds.add(5);// All partners Id;
708
		List<Integer> fofoIds = new ArrayList<>();
709
		fofoIds.add(fofoId);
710
		fofoIds.add(0);
711
 
712
		LOGGER.info("fofoIds" + fofoIds);
713
		List<Integer> partnerPositionIds = partnersPositionRepository.selectByRegionIdAndPartnerId(regionIds, fofoIds)
714
				.stream().map(x -> x.getPositionId()).collect(Collectors.toList());
715
 
716
		LOGGER.info("partnerPositionIds" + partnerPositionIds);
717
 
718
		for (Integer partnerPostionId : partnerPositionIds) {
719
			Position position = positionRepository.selectByIdAndCategoryId(partnerPostionId,
720
					ProfitMandiConstants.TICKET_CATEGORY_SALES);
721
			LOGGER.info("position" + position);
722
			if (position != null) {
723
 
724
				AuthUser authUser = authRepository.selectById(position.getAuthUserId());
725
				LOGGER.info("authUser" + authUser);
726
 
727
				authuserEsclationTypeMap.put(position.getEscalationType(), authUser);
728
			}
729
		}
730
 
731
		LOGGER.info("emailEsclationTypeMap" + authuserEsclationTypeMap);
732
 
733
		return authuserEsclationTypeMap;
734
	}
735
 
28377 tejbeer 736
	@Override
737
	public List<AuthUser> getAuthUserIdByPartnerId(int fofoId) {
738
		List<AuthUser> authUsers = new ArrayList<>();
739
		List<Integer> regionIds = partnerRegionRepository.selectByfofoId(fofoId).stream().map(x -> x.getRegionId())
740
				.collect(Collectors.toList());
741
 
742
		regionIds.add(5);// All partners Id;
743
		List<Integer> fofoIds = new ArrayList<>();
744
		fofoIds.add(fofoId);
745
		fofoIds.add(0);
746
 
747
		LOGGER.info("fofoIds" + fofoIds);
748
		List<Integer> partnerPositionIds = partnersPositionRepository.selectByRegionIdAndPartnerId(regionIds, fofoIds)
749
				.stream().map(x -> x.getPositionId()).collect(Collectors.toList());
750
 
751
		LOGGER.info("partnerPositionIds" + partnerPositionIds);
752
 
753
		for (Integer partnerPostionId : partnerPositionIds) {
754
			Position position = positionRepository.selectByIdAndCategoryId(partnerPostionId,
755
					ProfitMandiConstants.TICKET_CATEGORY_SALES);
756
			LOGGER.info("position" + position);
757
			if (position != null) {
758
 
759
				AuthUser authUser = authRepository.selectById(position.getAuthUserId());
760
				LOGGER.info("authUser" + authUser);
761
				authUsers.add(authUser);
762
			}
763
		}
764
 
765
		return authUsers;
766
	}
767
 
28856 manish 768
	@Override
28977 manish 769
	public List<AuthUser> getAuthUserIds(int categoryId, List<EscalationType> escalationType) {
29229 tejbeer 770
 
28977 manish 771
		List<Position> positions = positionRepository.selectPositionbyCategoryIdAndEscalationTypes(categoryId,
28856 manish 772
				escalationType);
28908 tejbeer 773
		List<Integer> authIds = positions.stream().map(x -> x.getAuthUserId()).distinct().collect(Collectors.toList());
774
 
775
		LOGGER.info("authIds" + authIds);
776
 
777
		List<AuthUser> authUsers = authRepository.selectAllAuthUserByIds(authIds);
778
 
779
		LOGGER.info("authUsers" + authUsers);
28856 manish 780
		return authUsers;
781
	}
29318 tejbeer 782
 
29296 manish 783
	@Override
29927 amit.gupta 784
	public List<AuthUser> getAuthUserByCategoryId(int categoryId, EscalationType escalationType) {
28856 manish 785
 
29296 manish 786
		List<Position> positions = positionRepository.selectPositionbyCategoryIdAndEscalationType(categoryId,
787
				escalationType);
788
		List<Integer> authIds = positions.stream().map(x -> x.getAuthUserId()).distinct().collect(Collectors.toList());
789
 
790
		LOGGER.info("authIds" + authIds);
791
 
792
		List<AuthUser> authUsers = authRepository.selectAllAuthUserByIds(authIds);
793
 
794
		LOGGER.info("authUsers" + authUsers);
795
		return authUsers;
796
	}
797
 
28908 tejbeer 798
	@Override
29927 amit.gupta 799
	@Cacheable(value = "authUserByCategoryId", cacheManager = "thirtyMinsTimeOutCacheManager")
28908 tejbeer 800
	public List<AuthUser> getAuthUserByCategoryId(int categoryId) {
801
		List<Position> positions = positionRepository.selectPositionByCategoryId(categoryId);
802
		List<Integer> authIds = positions.stream().map(x -> x.getAuthUserId()).distinct().collect(Collectors.toList());
803
 
804
		LOGGER.info("authIds" + authIds);
805
 
30003 tejbeer 806
		List<AuthUser> authUsers = authRepository.selectAllAuthUserByIds(authIds).stream().filter(x -> x.getActive())
807
				.collect(Collectors.toList());
28908 tejbeer 808
 
809
		LOGGER.info("authUsers" + authUsers);
810
		return authUsers;
811
	}
812
 
30003 tejbeer 813
	private class SaleRoles {
814
 
815
		private List<String> l1;
816
		private List<String> l2;
30044 tejbeer 817
		private List<String> l3;
818
		private List<String> l4;
30003 tejbeer 819
 
820
		public SaleRoles() {
821
			l1 = new ArrayList<>();
822
			l2 = new ArrayList<>();
30044 tejbeer 823
			l3 = new ArrayList<>();
824
			l4 = new ArrayList<>();
30003 tejbeer 825
		}
826
 
827
		public List<String> getL1() {
828
			return l1;
829
		}
830
 
831
		public List<String> getL2() {
832
			return l2;
833
		}
834
 
30044 tejbeer 835
		public List<String> getL3() {
836
			return l3;
837
		}
838
 
839
		public List<String> getL4() {
840
			return l4;
841
		}
842
 
843
		@Override
844
		public String toString() {
845
			return "SaleRoles [l1=" + l1 + ", l2=" + l2 + ", l3=" + l3 + ", l4=" + l4 + "]";
846
		}
847
 
30003 tejbeer 848
	}
849
 
850
	@Override
851
	@Cacheable(value = "partnerSaleHeader", cacheManager = "oneDayCacheManager")
852
	public Map<Integer, FofoReportingModel> getPartnerIdSalesHeaders() {
853
		Map<String, SaleRoles> partnerEmailSalesMap = new HashMap<>();
854
 
855
		List<Position> positions = positionRepository
856
				.selectPositionByCategoryId(ProfitMandiConstants.TICKET_CATEGORY_SALES);
857
		Map<Integer, AuthUser> authUsersMap = authRepository.selectAllActiveUser().stream()
858
				.collect(Collectors.toMap(x -> x.getId(), x -> x));
859
		Map<Integer, List<CustomRetailer>> positionIdRetailerMap = this.getPositionCustomRetailerMap(positions);
860
		for (Position position : positions) {
861
			List<CustomRetailer> crList = positionIdRetailerMap.get(position.getId());
862
			if (crList == null)
863
				continue;
864
			for (CustomRetailer cr : crList) {
865
				if (!partnerEmailSalesMap.containsKey(cr.getEmail())) {
866
					partnerEmailSalesMap.put(cr.getEmail(), new SaleRoles());
867
				}
868
				SaleRoles saleRoles = partnerEmailSalesMap.get(cr.getEmail());
869
				AuthUser authUser = authUsersMap.get(position.getAuthUserId());
870
				if (authUser == null) {
871
					continue;
872
				}
873
				String name = authUser.getFirstName() + " " + authUser.getLastName();
874
				if (position.getEscalationType().equals(EscalationType.L1)) {
875
					saleRoles.getL1().add(name);
876
				} else if (position.getEscalationType().equals(EscalationType.L2)) {
877
					saleRoles.getL2().add(name);
878
				}
30044 tejbeer 879
 
30003 tejbeer 880
			}
881
		}
882
 
883
		Set<CustomRetailer> allCrList = new HashSet<>();
884
		for (List<CustomRetailer> cr : positionIdRetailerMap.values()) {
885
			allCrList.addAll(cr);
886
		}
887
 
888
		Map<Integer, FofoStore> fofoStoresMap = fofoStoreRepository.selectActiveStores().stream()
889
				.collect(Collectors.toMap(x -> x.getId(), x -> x));
890
 
891
		Map<Integer, FofoReportingModel> partnerIdSalesHeadersMap = new HashMap<>();
892
 
893
		for (CustomRetailer cr : allCrList) {
894
			FofoStore fofoStore = fofoStoresMap.get(cr.getPartnerId());
895
			if (fofoStore == null) {
896
				LOGGER.info("Could not find Store {} in active Store", cr.getBusinessName());
897
				continue;
898
			}
899
			String code = fofoStore.getCode();
900
			// String storeName = "SmartDukaan-" +
901
			// fofoStore.getCode().replaceAll("[a-zA-Z]", "");
902
			String businessName = cr.getBusinessName();
903
			try {
904
				String stateManager = StringUtils.join(partnerEmailSalesMap.get(cr.getEmail()).getL2(), ", ");
905
				String territoryManager = StringUtils.join(partnerEmailSalesMap.get(cr.getEmail()).getL1(), ", ");
30044 tejbeer 906
 
907
				if (StringUtils.isEmpty(territoryManager)) {
908
					territoryManager = StringUtils.join(partnerEmailSalesMap.get(cr.getEmail()).getL2(), ", ");
909
				}
910
 
30003 tejbeer 911
				FofoReportingModel reportingModel = new FofoReportingModel();
912
				reportingModel.setBusinessName(businessName);
913
				reportingModel.setCode(code);
914
				reportingModel.setFofoId(fofoStore.getId());
915
				reportingModel.setRegionalManager(stateManager);
916
				reportingModel.setTerritoryManager(territoryManager);
917
				partnerIdSalesHeadersMap.put(fofoStore.getId(), reportingModel);
918
			} catch (Exception e) {
919
				LOGGER.warn("Could not find partner with email - {}", cr.getEmail());
920
			}
921
		}
922
		return partnerIdSalesHeadersMap;
923
 
924
	}
925
 
24383 amit.gupta 926
}