| Line 706... |
Line 706... |
| 706 |
LOGGER.error("Error fetching collection rank map for all fofoIds", e);
|
706 |
LOGGER.error("Error fetching collection rank map for all fofoIds", e);
|
| 707 |
}
|
707 |
}
|
| 708 |
}
|
708 |
}
|
| 709 |
LOGGER.info("RBM Call Target - CollectionRankMap fetch (OPTIMIZED): {}ms", System.currentTimeMillis() - start);
|
709 |
LOGGER.info("RBM Call Target - CollectionRankMap fetch (OPTIMIZED): {}ms", System.currentTimeMillis() - start);
|
| 710 |
|
710 |
|
| 711 |
// Get MTD billing data for zero billing calculation
|
711 |
// Get MTD billing data for zero billing calculation and partner counts
|
| 712 |
start = System.currentTimeMillis();
|
712 |
start = System.currentTimeMillis();
|
| 713 |
List<RbmWeeklyBillingModel> mtdBillingData = getWeeklyBillingDataForMonth(firstOfMonth, endOfMonth);
|
713 |
List<RbmWeeklyBillingModel> mtdBillingData = getWeeklyBillingDataForMonth(firstOfMonth, endOfMonth);
|
| 714 |
Set<Integer> allMtdBilledFofoIds = mtdBillingData.stream()
|
714 |
Set<Integer> allMtdBilledFofoIds = mtdBillingData.stream()
|
| 715 |
.filter(RbmWeeklyBillingModel::isMtdBilled)
|
715 |
.filter(RbmWeeklyBillingModel::isMtdBilled)
|
| 716 |
.map(RbmWeeklyBillingModel::getFofoId)
|
716 |
.map(RbmWeeklyBillingModel::getFofoId)
|
| 717 |
.collect(Collectors.toSet());
|
717 |
.collect(Collectors.toSet());
|
| - |
|
718 |
// Build partner count and fofoIds per RBM from mtdBillingData (same source as Today ARR page)
|
| - |
|
719 |
Map<Integer, Set<Integer>> mtdFofoIdsByAuthId = mtdBillingData.stream()
|
| - |
|
720 |
.filter(RbmWeeklyBillingModel::isTargetedPartner)
|
| - |
|
721 |
.collect(Collectors.groupingBy(RbmWeeklyBillingModel::getAuthId,
|
| - |
|
722 |
Collectors.mapping(RbmWeeklyBillingModel::getFofoId, Collectors.toSet())));
|
| 718 |
LOGGER.info("RBM Call Target - MTD Billing fetch: {}ms", System.currentTimeMillis() - start);
|
723 |
LOGGER.info("RBM Call Target - MTD Billing fetch: {}ms", System.currentTimeMillis() - start);
|
| 719 |
|
724 |
|
| 720 |
// Batch fetch today's remarks for all auth IDs (to calculate Value Achieved)
|
725 |
// Batch fetch today's remarks for all auth IDs (to calculate Value Achieved)
|
| 721 |
start = System.currentTimeMillis();
|
726 |
start = System.currentTimeMillis();
|
| 722 |
Map<Integer, List<PartnerCollectionRemark>> remarksByAuthId = partnerCollectionRemarkRepository
|
727 |
Map<Integer, List<PartnerCollectionRemark>> remarksByAuthId = partnerCollectionRemarkRepository
|
| Line 767... |
Line 772... |
| 767 |
})
|
772 |
})
|
| 768 |
.map(Map.Entry::getKey)
|
773 |
.map(Map.Entry::getKey)
|
| 769 |
.collect(Collectors.toList());
|
774 |
.collect(Collectors.toList());
|
| 770 |
}
|
775 |
}
|
| 771 |
|
776 |
|
| 772 |
// Filter to only external, ACTIVE stores with collection plan (like today_target Active section)
|
777 |
// Filter to only external, ACTIVE stores (collection plan not required)
|
| 773 |
Map<Integer, Integer> finalAllCollectionRankMap = allCollectionRankMap;
|
778 |
Map<Integer, Integer> finalAllCollectionRankMap = allCollectionRankMap;
|
| 774 |
Map<Integer, FofoStore> finalFofoStoresMap = fofoStoresMap;
|
779 |
Map<Integer, FofoStore> finalFofoStoresMap = fofoStoresMap;
|
| 775 |
List<Integer> validFofoIds = fofoIds.stream()
|
780 |
List<Integer> validFofoIds = fofoIds.stream()
|
| 776 |
.filter(fofoId -> {
|
781 |
.filter(fofoId -> {
|
| 777 |
FofoStore store = finalFofoStoresMap.get(fofoId);
|
782 |
FofoStore store = finalFofoStoresMap.get(fofoId);
|
| 778 |
if (store == null || store.isInternal()) {
|
783 |
if (store == null || store.isInternal()) {
|
| 779 |
return false;
|
784 |
return false;
|
| 780 |
}
|
785 |
}
|
| 781 |
// Only include ACTIVE partners (not Low Sale, not Disputed, not Billing Pending)
|
786 |
// Only include ACTIVE partners (not Low Sale, not Disputed, not Billing Pending)
|
| 782 |
if (!ActivationType.ACTIVE.equals(store.getActivationType())) {
|
787 |
return ActivationType.ACTIVE.equals(store.getActivationType());
|
| 783 |
return false;
|
- |
|
| 784 |
}
|
- |
|
| 785 |
// Only include partners who have a collection plan (to match today_target Active section)
|
- |
|
| 786 |
return finalAllCollectionRankMap.containsKey(fofoId);
|
- |
|
| 787 |
})
|
788 |
})
|
| 788 |
.collect(Collectors.toList());
|
789 |
.collect(Collectors.toList());
|
| 789 |
|
790 |
|
| 790 |
if (validFofoIds.isEmpty()) {
|
791 |
if (validFofoIds.isEmpty()) {
|
| 791 |
continue;
|
792 |
continue;
|
| 792 |
}
|
793 |
}
|
| 793 |
|
794 |
|
| 794 |
RbmCallTargetModel targetModel = new RbmCallTargetModel();
|
795 |
RbmCallTargetModel targetModel = new RbmCallTargetModel();
|
| 795 |
targetModel.setAuthId(rbmAuthId);
|
796 |
targetModel.setAuthId(rbmAuthId);
|
| 796 |
targetModel.setRbmName(authUser.getFullName());
|
797 |
targetModel.setRbmName(authUser.getFullName());
|
| - |
|
798 |
// Use partner count from mtdBillingData (same source as Today ARR page)
|
| - |
|
799 |
Set<Integer> mtdFofoIds = mtdFofoIdsByAuthId.getOrDefault(rbmAuthId, Collections.emptySet());
|
| 797 |
targetModel.setPartnerCount(validFofoIds.size());
|
800 |
targetModel.setPartnerCount(mtdFofoIds.size());
|
| 798 |
|
801 |
|
| 799 |
// Categorize each partner - each partner belongs to ONE category only
|
802 |
// Categorize each partner - each partner belongs to ONE category only
|
| 800 |
// Priority: PlanToday > CarryForward > ZeroBilling > Untouched > FuturePlan > Normal
|
803 |
// Priority: PlanToday > CarryForward > ZeroBilling > Untouched > FuturePlan > Normal
|
| 801 |
Set<Integer> planTodayPartners = new HashSet<>();
|
804 |
Set<Integer> planTodayPartners = new HashSet<>();
|
| 802 |
Set<Integer> carryForwardPartners = new HashSet<>();
|
805 |
Set<Integer> carryForwardPartners = new HashSet<>();
|