Subversion Repositories SmartDukaan

Rev

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

Rev 26111 Rev 26298
Line 1... Line 1...
1
package com.spice.profitmandi.dao.repository.cs;
1
package com.spice.profitmandi.dao.repository.cs;
2
 
2
 
3
import java.time.LocalDateTime;
3
import java.time.LocalDateTime;
4
import java.util.ArrayList;
4
import java.util.ArrayList;
5
import java.util.Arrays;
5
import java.util.Arrays;
-
 
6
import java.util.Collection;
6
import java.util.HashMap;
7
import java.util.HashMap;
7
import java.util.HashSet;
8
import java.util.HashSet;
8
import java.util.List;
9
import java.util.List;
9
import java.util.Map;
10
import java.util.Map;
-
 
11
import java.util.Map.Entry;
10
import java.util.Set;
12
import java.util.Set;
11
import java.util.stream.Collectors;
13
import java.util.stream.Collectors;
12
 
14
 
13
import org.apache.commons.collections4.map.HashedMap;
15
import org.apache.commons.collections4.map.HashedMap;
14
import org.apache.commons.lang.RandomStringUtils;
16
import org.apache.commons.lang.RandomStringUtils;
Line 17... Line 19...
17
import org.springframework.beans.factory.annotation.Autowired;
19
import org.springframework.beans.factory.annotation.Autowired;
18
import org.springframework.cache.annotation.Cacheable;
20
import org.springframework.cache.annotation.Cacheable;
19
import org.springframework.mail.javamail.JavaMailSender;
21
import org.springframework.mail.javamail.JavaMailSender;
20
import org.springframework.stereotype.Component;
22
import org.springframework.stereotype.Component;
21
 
23
 
-
 
24
import com.google.common.collect.HashMultimap;
-
 
25
import com.google.common.collect.Multimap;
22
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
26
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
23
import com.spice.profitmandi.common.model.CustomRetailer;
27
import com.spice.profitmandi.common.model.CustomRetailer;
24
import com.spice.profitmandi.common.model.ProfitMandiConstants;
28
import com.spice.profitmandi.common.model.ProfitMandiConstants;
25
import com.spice.profitmandi.common.util.Utils;
29
import com.spice.profitmandi.common.util.Utils;
26
import com.spice.profitmandi.dao.entity.auth.AuthUser;
30
import com.spice.profitmandi.dao.entity.auth.AuthUser;
Line 498... Line 502...
498
			Set<String> partnerEmails = positionPartnerEntry.getValue().stream()
502
			Set<String> partnerEmails = positionPartnerEntry.getValue().stream()
499
					.filter(x -> activeFofoIds.contains(x.getPartnerId())).map(x -> x.getEmail())
503
					.filter(x -> activeFofoIds.contains(x.getPartnerId())).map(x -> x.getEmail())
500
					.collect(Collectors.toSet());
504
					.collect(Collectors.toSet());
501
			AuthUser authUser = authRepository.selectById(authUserId);
505
			AuthUser authUser = authRepository.selectById(authUserId);
502
			if (authUser.isActive()) {
506
			if (authUser.isActive()) {
503
				if(!storeGuyMap.containsKey(authUser.getEmailId())) {
507
				if (!storeGuyMap.containsKey(authUser.getEmailId())) {
504
					storeGuyMap.put(authUser.getEmailId(), partnerEmails);
508
					storeGuyMap.put(authUser.getEmailId(), partnerEmails);
505
				} else {
509
				} else {
506
					storeGuyMap.get(authUser.getEmailId()).addAll(partnerEmails);
510
					storeGuyMap.get(authUser.getEmailId()).addAll(partnerEmails);
507
				}
511
				}
508
			}
512
			}
Line 527... Line 531...
527
			Set<Integer> partnerEmails = positionPartnerEntry.getValue().stream()
531
			Set<Integer> partnerEmails = positionPartnerEntry.getValue().stream()
528
					.filter(x -> activeFofoIds.contains(x.getPartnerId())).map(x -> x.getPartnerId())
532
					.filter(x -> activeFofoIds.contains(x.getPartnerId())).map(x -> x.getPartnerId())
529
					.collect(Collectors.toSet());
533
					.collect(Collectors.toSet());
530
			AuthUser authUser = authRepository.selectById(authUserId);
534
			AuthUser authUser = authRepository.selectById(authUserId);
531
			if (authUser.isActive()) {
535
			if (authUser.isActive()) {
532
				if(!storeGuyMap.containsKey(authUser.getEmailId())) {
536
				if (!storeGuyMap.containsKey(authUser.getEmailId())) {
533
					storeGuyMap.put(authUser.getEmailId(), partnerEmails);
537
					storeGuyMap.put(authUser.getEmailId(), partnerEmails);
534
				} else {
538
				} else {
535
					storeGuyMap.get(authUser.getEmailId()).addAll(partnerEmails);
539
					storeGuyMap.get(authUser.getEmailId()).addAll(partnerEmails);
536
				}
540
				}
537
			}
541
			}
Line 569... Line 573...
569
			}
573
			}
570
		}
574
		}
571
 
575
 
572
		return emails;
576
		return emails;
573
	}
577
	}
-
 
578
 
-
 
579
	@Override
-
 
580
	@Cacheable(value = "authUserIdPartnerIdMapping", cacheManager = "thirtyMinsTimeOutCacheManager")
-
 
581
	public Map<Integer, List<Integer>> getAuthUserIdPartnerIdMapping() {
-
 
582
		Map<Integer, List<Integer>> storeGuyMap = new HashMap<>();
-
 
583
		Set<Integer> activeFofoIds = fofoStoreRepository.selectActiveStores().stream().map(x -> x.getId())
-
 
584
				.collect(Collectors.toSet());
-
 
585
		List<Position> categoryPositions = positionRepository
-
 
586
				.selectPositionByCategoryId(ProfitMandiConstants.TICKET_CATEGORY_SALES);
-
 
587
		Map<Integer, Position> positionsMap = categoryPositions.stream()
-
 
588
				.collect(Collectors.toMap(x -> x.getId(), x -> x));
-
 
589
 
-
 
590
		Map<Integer, List<CustomRetailer>> positonPartnerMap = this.getPositionCustomRetailerMap(categoryPositions);
-
 
591
		for (Map.Entry<Integer, List<CustomRetailer>> positionPartnerEntry : positonPartnerMap.entrySet()) {
-
 
592
			int authUserId = positionsMap.get(positionPartnerEntry.getKey()).getAuthUserId();
-
 
593
			List<Integer> partnerEmails = positionPartnerEntry.getValue().stream()
-
 
594
					.filter(x -> activeFofoIds.contains(x.getPartnerId())).map(x -> x.getPartnerId())
-
 
595
					.collect(Collectors.toList());
-
 
596
			AuthUser authUser = authRepository.selectById(authUserId);
-
 
597
			if (authUser.isActive()) {
-
 
598
				if (!storeGuyMap.containsKey(authUser.getEmailId())) {
-
 
599
					storeGuyMap.put(authUser.getId(), partnerEmails);
-
 
600
				} else {
-
 
601
					storeGuyMap.get(authUser.getEmailId()).addAll(partnerEmails);
-
 
602
				}
-
 
603
			}
-
 
604
		}
-
 
605
		return storeGuyMap;
-
 
606
	}
-
 
607
 
-
 
608
	@Override
-
 
609
	@Cacheable(value = "L1L2Mapping", cacheManager = "thirtyMinsTimeOutCacheManager")
-
 
610
	public Map<Integer, List<Integer>> getL1L2Mapping() {
-
 
611
		List<Position> positions = positionRepository.selectPositionsByEscalationType(EscalationType.L1);
-
 
612
		LOGGER.info("position" + positions);
-
 
613
		Map<Integer, List<Integer>> map = this.getAuthUserIdPartnerIdMapping();
-
 
614
		LOGGER.info("map" + map);
-
 
615
 
-
 
616
		Map<Integer, Integer> l1andl2Map = new HashMap<>();
-
 
617
 
-
 
618
		for (Position position : positions) {
-
 
619
 
-
 
620
			if (map.containsKey(position.getAuthUserId())) {
-
 
621
				LOGGER.info("authId" + position.getAuthUserId());
-
 
622
				LOGGER.info("Vals" + map.get(position.getAuthUserId()));
-
 
623
				List<Integer> fofoIds = map.get(position.getAuthUserId());
-
 
624
				Integer fofoId = fofoIds.get(0);
-
 
625
				LOGGER.info("fofo" + fofoId);
-
 
626
				List<Position> l2position = new ArrayList<>();
-
 
627
 
-
 
628
				List<Position> finall2position = new ArrayList<>();
-
 
629
 
-
 
630
				for (Map.Entry<Integer, List<Integer>> bs : map.entrySet()) {
-
 
631
					if (!bs.getKey().equals(position.getAuthUserId())) {
-
 
632
 
-
 
633
						if (bs.getValue().contains(fofoId)) {
-
 
634
 
-
 
635
							LOGGER.info("key" + bs.getKey());
-
 
636
 
-
 
637
							l2position = positionRepository.selectPositionsByAuthUserAndEscalationType(bs.getKey(),
-
 
638
									EscalationType.L2);
-
 
639
 
-
 
640
							finall2position.addAll(l2position);
-
 
641
 
-
 
642
						}
-
 
643
					}
-
 
644
				}
-
 
645
				LOGGER.info("alll2position" + finall2position);
-
 
646
 
-
 
647
				l1andl2Map.put(position.getAuthUserId(), finall2position.get(0).getAuthUserId());
-
 
648
			}
-
 
649
 
-
 
650
		}
-
 
651
 
-
 
652
		Map<Integer, List<Integer>> l2andl1Map = l1andl2Map.entrySet().stream().collect(
-
 
653
				Collectors.groupingBy(Map.Entry::getValue, Collectors.mapping(Map.Entry::getKey, Collectors.toList())));
-
 
654
		return l2andl1Map;
-
 
655
	}
574
}
656
}