| Line 989... |
Line 989... |
| 989 |
} else {
|
989 |
} else {
|
| 990 |
List<Integer> l2AssignedFofoIds = rbmToFofoIdsMap.getOrDefault(l2AuthId, Collections.emptyList());
|
990 |
List<Integer> l2AssignedFofoIds = rbmToFofoIdsMap.getOrDefault(l2AuthId, Collections.emptyList());
|
| 991 |
l2Model.setPartnerCount(l2AssignedFofoIds.size());
|
991 |
l2Model.setPartnerCount(l2AssignedFofoIds.size());
|
| 992 |
}
|
992 |
}
|
| 993 |
|
993 |
|
| 994 |
// Calculate L1 own target if user is also L1
|
994 |
// If user is also L1, calculate full L1 breakdown and merge into L2 model
|
| 995 |
long l1OwnTarget = 0;
|
- |
|
| 996 |
if (l1AuthIds.contains(l2AuthId) && storeGuyMap.containsKey(authUser.getEmailId())) {
|
995 |
if (l1AuthIds.contains(l2AuthId) && storeGuyMap.containsKey(authUser.getEmailId())) {
|
| 997 |
List<Integer> fofoIdList = rbmToFofoIdsMap.getOrDefault(l2AuthId, Collections.emptyList());
|
996 |
// Get only L1 RBM position partners (not L2 partners) from partner_position
|
| 998 |
List<Position> positions = positionsByAuthId.getOrDefault(l2AuthId, Collections.emptyList());
|
997 |
List<Position> positions = positionsByAuthId.getOrDefault(l2AuthId, Collections.emptyList());
|
| 999 |
boolean isRBMAndL1 = positions.stream()
|
998 |
Set<Integer> l1RbmPositionIds = positions.stream()
|
| - |
|
999 |
.filter(p -> ProfitMandiConstants.TICKET_CATEGORY_RBM == p.getCategoryId()
|
| - |
|
1000 |
&& EscalationType.L1.equals(p.getEscalationType()))
|
| 1000 |
.anyMatch(position ->
|
1001 |
.map(Position::getId)
|
| - |
|
1002 |
.collect(Collectors.toSet());
|
| 1001 |
ProfitMandiConstants.TICKET_CATEGORY_RBM == position.getCategoryId()
|
1003 |
// Fetch partner_position for only L1 RBM positions of this user
|
| - |
|
1004 |
List<Integer> fofoIdList = partnerPositionRepository
|
| 1002 |
&& EscalationType.L1.equals(position.getEscalationType()));
|
1005 |
.selectByPositionIds(new ArrayList<>(l1RbmPositionIds)).stream()
|
| - |
|
1006 |
.map(pp -> pp.getFofoId())
|
| - |
|
1007 |
.distinct()
|
| - |
|
1008 |
.collect(Collectors.toList());
|
| - |
|
1009 |
boolean isRBMAndL1 = !l1RbmPositionIds.isEmpty();
|
| 1003 |
List<Integer> l1FofoIds = new ArrayList<>(fofoIdList);
|
1010 |
List<Integer> l1FofoIds = new ArrayList<>(fofoIdList);
|
| 1004 |
if (isRBMAndL1) {
|
1011 |
if (isRBMAndL1) {
|
| 1005 |
Map<Integer, PartnerCollectionRemark> partnerCollectionRemarks = new HashMap<>();
|
1012 |
Map<Integer, PartnerCollectionRemark> partnerCollectionRemarks = new HashMap<>();
|
| 1006 |
for (Integer fofoId : fofoIdList) {
|
1013 |
for (Integer fofoId : fofoIdList) {
|
| 1007 |
if (allPartnerCollectionRemarks.containsKey(fofoId)) {
|
1014 |
if (allPartnerCollectionRemarks.containsKey(fofoId)) {
|
| Line 1025... |
Line 1032... |
| 1025 |
return ActivationType.ACTIVE.equals(store.getActivationType())
|
1032 |
return ActivationType.ACTIVE.equals(store.getActivationType())
|
| 1026 |
|| ActivationType.REVIVAL.equals(store.getActivationType());
|
1033 |
|| ActivationType.REVIVAL.equals(store.getActivationType());
|
| 1027 |
})
|
1034 |
})
|
| 1028 |
.collect(Collectors.toList());
|
1035 |
.collect(Collectors.toList());
|
| 1029 |
|
1036 |
|
| - |
|
1037 |
// Categorize L1 partners — same logic as L1 processing
|
| - |
|
1038 |
Set<Integer> planTodayPartners = new HashSet<>();
|
| 1030 |
// Count L1 own target (PlanToday + CarryForward + ZeroBilling + Untouched)
|
1039 |
Set<Integer> carryForwardPartners = new HashSet<>();
|
| - |
|
1040 |
Set<Integer> untouchedPartners = new HashSet<>();
|
| - |
|
1041 |
Set<Integer> zeroBillingPartners = new HashSet<>();
|
| - |
|
1042 |
Set<Integer> futurePlanPartners = new HashSet<>();
|
| - |
|
1043 |
Set<Integer> normalPartners = new HashSet<>();
|
| - |
|
1044 |
Set<Integer> revivalPartners = new HashSet<>();
|
| - |
|
1045 |
|
| 1031 |
for (Integer fofoId : validL1FofoIds) {
|
1046 |
for (Integer fofoId : validL1FofoIds) {
|
| 1032 |
int rank = allCollectionRankMap.getOrDefault(fofoId, 5);
|
1047 |
int rank = allCollectionRankMap.getOrDefault(fofoId, 5);
|
| 1033 |
boolean hasZeroBilling = !allMtdBilledFofoIds.contains(fofoId);
|
1048 |
boolean hasZeroBilling = !allMtdBilledFofoIds.contains(fofoId);
|
| - |
|
1049 |
FofoStore store = finalFofoStoresMap2.get(fofoId);
|
| - |
|
1050 |
if (store != null && ActivationType.REVIVAL.equals(store.getActivationType())) {
|
| - |
|
1051 |
revivalPartners.add(fofoId);
|
| - |
|
1052 |
}
|
| - |
|
1053 |
if (rank == 1) {
|
| - |
|
1054 |
planTodayPartners.add(fofoId);
|
| - |
|
1055 |
} else if (rank == 2) {
|
| - |
|
1056 |
carryForwardPartners.add(fofoId);
|
| 1034 |
if (rank == 1 || rank == 2 || hasZeroBilling || rank == 3) {
|
1057 |
} else if (hasZeroBilling) {
|
| - |
|
1058 |
zeroBillingPartners.add(fofoId);
|
| - |
|
1059 |
} else if (rank == 3) {
|
| - |
|
1060 |
untouchedPartners.add(fofoId);
|
| - |
|
1061 |
} else if (rank == 4) {
|
| - |
|
1062 |
futurePlanPartners.add(fofoId);
|
| 1035 |
l1OwnTarget++;
|
1063 |
} else {
|
| - |
|
1064 |
normalPartners.add(fofoId);
|
| 1036 |
}
|
1065 |
}
|
| 1037 |
}
|
1066 |
}
|
| 1038 |
}
|
- |
|
| 1039 |
|
1067 |
|
| - |
|
1068 |
// Set L1 breakdown fields on L2 model
|
| - |
|
1069 |
l2Model.setPlanToday(planTodayPartners.size());
|
| - |
|
1070 |
l2Model.setCarryForward(carryForwardPartners.size());
|
| - |
|
1071 |
l2Model.setZeroBilling(zeroBillingPartners.size());
|
| - |
|
1072 |
l2Model.setUntouched(untouchedPartners.size());
|
| - |
|
1073 |
l2Model.setFuturePlan(futurePlanPartners.size());
|
| - |
|
1074 |
l2Model.setNormal(normalPartners.size());
|
| - |
|
1075 |
l2Model.setRevival(revivalPartners.size());
|
| - |
|
1076 |
|
| - |
|
1077 |
long l1OwnTarget = planTodayPartners.size() + carryForwardPartners.size()
|
| - |
|
1078 |
+ zeroBillingPartners.size() + untouchedPartners.size();
|
| - |
|
1079 |
|
| 1040 |
// L2 Target = L2 escalation partners + own L1 target (if also L1)
|
1080 |
// Today Target = own L1 target + L2 escalation
|
| 1041 |
l2Model.setTodayTargetOfCall(l2TargetFofoIds.size() + l1OwnTarget);
|
1081 |
l2Model.setTodayTargetOfCall(l2TargetFofoIds.size() + l1OwnTarget);
|
| - |
|
1082 |
|
| - |
|
1083 |
// Moved to Future from L1 partners
|
| - |
|
1084 |
List<PartnerCollectionRemark> todayRemarks = remarksByAuthId.getOrDefault(l2AuthId, Collections.emptyList());
|
| - |
|
1085 |
Set<Integer> todayRemarkedFofoIds = todayRemarks.stream()
|
| - |
|
1086 |
.map(PartnerCollectionRemark::getFofoId)
|
| - |
|
1087 |
.collect(Collectors.toSet());
|
| - |
|
1088 |
long movedToFuture = futurePlanPartners.stream()
|
| - |
|
1089 |
.filter(todayRemarkedFofoIds::contains)
|
| - |
|
1090 |
.count();
|
| - |
|
1091 |
l2Model.setMovedToFuture(movedToFuture);
|
| - |
|
1092 |
} else {
|
| - |
|
1093 |
// Pure L2 (not also L1) — target is only L2 escalation
|
| - |
|
1094 |
l2Model.setTodayTargetOfCall(l2TargetFofoIds.size());
|
| - |
|
1095 |
}
|
| 1042 |
|
1096 |
|
| 1043 |
// Value Achieved = All distinct partners called today (from call logs)
|
1097 |
// Value Achieved = All distinct partners called today (from call logs)
|
| 1044 |
long l2ValueAchieved = getCalledCountFromCallLogs(l2AuthId);
|
1098 |
long l2ValueAchieved = getCalledCountFromCallLogs(l2AuthId);
|
| 1045 |
l2Model.setValueTargetAchieved(l2ValueAchieved);
|
1099 |
l2Model.setValueTargetAchieved(l2ValueAchieved);
|
| 1046 |
|
1100 |
|