| Line 660... |
Line 660... |
| 660 |
List<Integer> fofoIds = new ArrayList<>(storeGuyMap.get(au.getEmailId()));
|
660 |
List<Integer> fofoIds = new ArrayList<>(storeGuyMap.get(au.getEmailId()));
|
| 661 |
allFofoIds.addAll(fofoIds);
|
661 |
allFofoIds.addAll(fofoIds);
|
| 662 |
rbmToFofoIdsMap.put(rbmAuthId, fofoIds);
|
662 |
rbmToFofoIdsMap.put(rbmAuthId, fofoIds);
|
| 663 |
}
|
663 |
}
|
| 664 |
}
|
664 |
}
|
| 665 |
// Fetch escalated tickets for L2 early so their fofoIds are included in batch fetches
|
665 |
// Initialize L2 calling list map - will be populated after fetching remarks
|
| 666 |
List<Ticket> escalatedTickets = Collections.emptyList();
|
- |
|
| 667 |
Map<Integer, List<Integer>> l2AuthIdToFofoIds = new HashMap<>();
|
666 |
Map<Integer, List<Integer>> l2AuthIdToFofoIds = new HashMap<>();
|
| 668 |
if (!l2AuthIds.isEmpty()) {
|
- |
|
| 669 |
start = System.currentTimeMillis();
|
- |
|
| 670 |
escalatedTickets = ticketRepository.selectOpenEscalatedTicketsByAuthIds(l2AuthIds);
|
- |
|
| 671 |
LOGGER.info("RBM Call Target - Escalated tickets fetch: {}ms, count: {}", System.currentTimeMillis() - start, escalatedTickets.size());
|
- |
|
| 672 |
|
- |
|
| 673 |
for (int l2AuthId : l2AuthIds) {
|
667 |
for (int l2AuthId : l2AuthIds) {
|
| 674 |
List<Integer> l2FofoIds = escalatedTickets.stream()
|
- |
|
| 675 |
.filter(t -> t.getL2AuthUser() == l2AuthId
|
- |
|
| 676 |
|| t.getL3AuthUser() == l2AuthId
|
- |
|
| 677 |
|| t.getL4AuthUser() == l2AuthId
|
- |
|
| 678 |
|| t.getL5AuthUser() == l2AuthId)
|
- |
|
| 679 |
.map(Ticket::getFofoId)
|
- |
|
| 680 |
.distinct()
|
- |
|
| 681 |
.collect(Collectors.toList());
|
- |
|
| 682 |
l2AuthIdToFofoIds.put(l2AuthId, l2FofoIds);
|
668 |
l2AuthIdToFofoIds.put(l2AuthId, new ArrayList<>());
|
| 683 |
allFofoIds.addAll(l2FofoIds);
|
- |
|
| 684 |
}
|
- |
|
| 685 |
}
|
669 |
}
|
| 686 |
LOGGER.info("RBM Call Target - Total fofo IDs to process: {}", allFofoIds.size());
|
670 |
LOGGER.info("RBM Call Target - Total fofo IDs to process: {}", allFofoIds.size());
|
| 687 |
|
671 |
|
| 688 |
// Get only needed fofo stores (OPTIMIZED - was fetching ALL stores before)
|
672 |
// Get only needed fofo stores (OPTIMIZED - was fetching ALL stores before)
|
| 689 |
start = System.currentTimeMillis();
|
673 |
start = System.currentTimeMillis();
|
| Line 708... |
Line 692... |
| 708 |
.collect(Collectors.toMap(PartnerCollectionRemark::getFofoId, x -> x, (a, b) -> a));
|
692 |
.collect(Collectors.toMap(PartnerCollectionRemark::getFofoId, x -> x, (a, b) -> a));
|
| 709 |
}
|
693 |
}
|
| 710 |
}
|
694 |
}
|
| 711 |
LOGGER.info("RBM Call Target - PartnerCollectionRemarks fetch: {}ms", System.currentTimeMillis() - start);
|
695 |
LOGGER.info("RBM Call Target - PartnerCollectionRemarks fetch: {}ms", System.currentTimeMillis() - start);
|
| 712 |
|
696 |
|
| - |
|
697 |
// Populate L2 calling list based on partners whose latest remark is RBM_L2_ESCALATION
|
| - |
|
698 |
// Find the L1 who has the partner and add to that L1's manager (L2) calling list
|
| - |
|
699 |
for (Map.Entry<Integer, PartnerCollectionRemark> entry : allPartnerCollectionRemarks.entrySet()) {
|
| - |
|
700 |
Integer fofoId = entry.getKey();
|
| - |
|
701 |
PartnerCollectionRemark remark = entry.getValue();
|
| - |
|
702 |
|
| - |
|
703 |
if (CollectionRemark.RBM_L2_ESCALATION.equals(remark.getRemark())) {
|
| - |
|
704 |
// Find which L1 RBM has this partner assigned
|
| - |
|
705 |
for (int l1AuthId : l1AuthIds) {
|
| - |
|
706 |
List<Integer> l1FofoIds = rbmToFofoIdsMap.getOrDefault(l1AuthId, Collections.emptyList());
|
| - |
|
707 |
if (l1FofoIds.contains(fofoId)) {
|
| - |
|
708 |
// Get L1's manager (L2)
|
| - |
|
709 |
AuthUser l1User = authUserMap.get(l1AuthId);
|
| - |
|
710 |
if (l1User != null && l2AuthIdToFofoIds.containsKey(l1User.getManagerId())) {
|
| - |
|
711 |
int l2ManagerId = l1User.getManagerId();
|
| - |
|
712 |
l2AuthIdToFofoIds.get(l2ManagerId).add(fofoId);
|
| - |
|
713 |
}
|
| - |
|
714 |
break; // Found the L1 for this fofoId
|
| - |
|
715 |
}
|
| - |
|
716 |
}
|
| - |
|
717 |
}
|
| - |
|
718 |
}
|
| - |
|
719 |
LOGGER.info("RBM Call Target - L2 calling lists populated from RBM_L2_ESCALATION remarks");
|
| - |
|
720 |
|
| 713 |
// Batch fetch collection RANK map for all fofoIds (OPTIMIZED - only fetches rank, not full model)
|
721 |
// Batch fetch collection RANK map for all fofoIds (OPTIMIZED - only fetches rank, not full model)
|
| 714 |
start = System.currentTimeMillis();
|
722 |
start = System.currentTimeMillis();
|
| 715 |
Map<Integer, Integer> allCollectionRankMap = new HashMap<>();
|
723 |
Map<Integer, Integer> allCollectionRankMap = new HashMap<>();
|
| 716 |
if (!allFofoIds.isEmpty()) {
|
724 |
if (!allFofoIds.isEmpty()) {
|
| 717 |
try {
|
725 |
try {
|
| Line 899... |
Line 907... |
| 899 |
continue;
|
907 |
continue;
|
| 900 |
}
|
908 |
}
|
| 901 |
|
909 |
|
| 902 |
List<Integer> l2FofoIdList = l2AuthIdToFofoIds.getOrDefault(l2AuthId, Collections.emptyList());
|
910 |
List<Integer> l2FofoIdList = l2AuthIdToFofoIds.getOrDefault(l2AuthId, Collections.emptyList());
|
| 903 |
|
911 |
|
| 904 |
// For L2, use all escalated ticket fofoIds as target (no collection plan filter)
|
912 |
// For L2, use unique fofoIds with RBM_L2_ESCALATION remark as target
|
| 905 |
Set<Integer> l2TargetFofoIds = new HashSet<>(l2FofoIdList);
|
913 |
Set<Integer> l2TargetFofoIds = new HashSet<>(l2FofoIdList);
|
| 906 |
|
914 |
|
| 907 |
RbmCallTargetModel l2Model = new RbmCallTargetModel();
|
915 |
RbmCallTargetModel l2Model = new RbmCallTargetModel();
|
| 908 |
l2Model.setAuthId(l2AuthId);
|
916 |
l2Model.setAuthId(l2AuthId);
|
| 909 |
l2Model.setRbmName(authUser.getFullName() + " (L2)");
|
917 |
l2Model.setRbmName(authUser.getFullName() + " (L2)");
|
| 910 |
l2Model.setL2Position(true);
|
918 |
l2Model.setL2Position(true);
|
| 911 |
l2Model.setL2CallingList(l2FofoIdList.size());
|
919 |
l2Model.setL2CallingList(l2TargetFofoIds.size());
|
| 912 |
// Partner count = total assigned partners (same as L1 source)
|
920 |
// Partner count = total assigned partners (same as L1 source)
|
| 913 |
List<Integer> l2AssignedFofoIds = rbmToFofoIdsMap.getOrDefault(l2AuthId, Collections.emptyList());
|
921 |
List<Integer> l2AssignedFofoIds = rbmToFofoIdsMap.getOrDefault(l2AuthId, Collections.emptyList());
|
| 914 |
l2Model.setPartnerCount(l2AssignedFofoIds.size());
|
922 |
l2Model.setPartnerCount(l2AssignedFofoIds.size());
|
| 915 |
|
923 |
|
| 916 |
// L2 Target = all escalated ticket fofoIds
|
924 |
// L2 Target = partners with RBM_L2_ESCALATION as latest remark
|
| 917 |
l2Model.setTodayTargetOfCall(l2TargetFofoIds.size());
|
925 |
l2Model.setTodayTargetOfCall(l2TargetFofoIds.size());
|
| 918 |
|
926 |
|
| 919 |
// Value Achieved = distinct fofoIds from today's remarks that are in escalated tickets
|
927 |
// Value Achieved = distinct fofoIds from today's remarks that are in L2's calling list
|
| 920 |
List<PartnerCollectionRemark> l2TodayRemarks = remarksByAuthId.getOrDefault(l2AuthId, Collections.emptyList());
|
928 |
List<PartnerCollectionRemark> l2TodayRemarks = remarksByAuthId.getOrDefault(l2AuthId, Collections.emptyList());
|
| 921 |
long l2ValueAchieved = l2TodayRemarks.stream()
|
929 |
long l2ValueAchieved = l2TodayRemarks.stream()
|
| 922 |
.map(PartnerCollectionRemark::getFofoId)
|
930 |
.map(PartnerCollectionRemark::getFofoId)
|
| 923 |
.filter(l2TargetFofoIds::contains)
|
931 |
.filter(l2TargetFofoIds::contains)
|
| 924 |
.distinct()
|
932 |
.distinct()
|