| Line 873... |
Line 873... |
| 873 |
todayTargetPartners.addAll(planTodayPartners);
|
873 |
todayTargetPartners.addAll(planTodayPartners);
|
| 874 |
todayTargetPartners.addAll(carryForwardPartners);
|
874 |
todayTargetPartners.addAll(carryForwardPartners);
|
| 875 |
todayTargetPartners.addAll(zeroBillingPartners);
|
875 |
todayTargetPartners.addAll(zeroBillingPartners);
|
| 876 |
todayTargetPartners.addAll(untouchedPartners);
|
876 |
todayTargetPartners.addAll(untouchedPartners);
|
| 877 |
|
877 |
|
| 878 |
// Value Achieved = All distinct partners contacted today (all remarks made today by this RBM)
|
878 |
// Value Achieved = All distinct partners called today (from call logs)
|
| 879 |
List<PartnerCollectionRemark> todayRemarks = remarksByAuthId.getOrDefault(rbmAuthId, Collections.emptyList());
|
- |
|
| 880 |
long valueAchieved = todayRemarks.stream()
|
879 |
long valueAchieved = getCalledCountFromCallLogs(rbmAuthId);
|
| 881 |
.map(PartnerCollectionRemark::getFofoId)
|
- |
|
| 882 |
.distinct()
|
- |
|
| 883 |
.count();
|
- |
|
| 884 |
targetModel.setValueTargetAchieved(valueAchieved);
|
880 |
targetModel.setValueTargetAchieved(valueAchieved);
|
| 885 |
|
881 |
|
| - |
|
882 |
// Keep todayRemarks for movedToFuture calculation
|
| - |
|
883 |
List<PartnerCollectionRemark> todayRemarks = remarksByAuthId.getOrDefault(rbmAuthId, Collections.emptyList());
|
| - |
|
884 |
|
| 886 |
// Moved to Future = Partners in Future Plan category who have a remark today
|
885 |
// Moved to Future = Partners in Future Plan category who have a remark today
|
| 887 |
// These are partners who were contacted today but moved to a future date
|
886 |
// These are partners who were contacted today but moved to a future date
|
| 888 |
Set<Integer> todayRemarkedFofoIds = todayRemarks.stream()
|
887 |
Set<Integer> todayRemarkedFofoIds = todayRemarks.stream()
|
| 889 |
.map(PartnerCollectionRemark::getFofoId)
|
888 |
.map(PartnerCollectionRemark::getFofoId)
|
| 890 |
.collect(Collectors.toSet());
|
889 |
.collect(Collectors.toSet());
|
| Line 921... |
Line 920... |
| 921 |
l2Model.setPartnerCount(l2AssignedFofoIds.size());
|
920 |
l2Model.setPartnerCount(l2AssignedFofoIds.size());
|
| 922 |
|
921 |
|
| 923 |
// L2 Target = partners with RBM_L2_ESCALATION as latest remark
|
922 |
// L2 Target = partners with RBM_L2_ESCALATION as latest remark
|
| 924 |
l2Model.setTodayTargetOfCall(l2TargetFofoIds.size());
|
923 |
l2Model.setTodayTargetOfCall(l2TargetFofoIds.size());
|
| 925 |
|
924 |
|
| 926 |
// Value Achieved = All distinct partners contacted today (all remarks made today by this L2)
|
925 |
// Value Achieved = All distinct partners called today (from call logs)
|
| 927 |
List<PartnerCollectionRemark> l2TodayRemarks = remarksByAuthId.getOrDefault(l2AuthId, Collections.emptyList());
|
- |
|
| 928 |
long l2ValueAchieved = l2TodayRemarks.stream()
|
926 |
long l2ValueAchieved = getCalledCountFromCallLogs(l2AuthId);
|
| 929 |
.map(PartnerCollectionRemark::getFofoId)
|
- |
|
| 930 |
.distinct()
|
- |
|
| 931 |
.count();
|
- |
|
| 932 |
l2Model.setValueTargetAchieved(l2ValueAchieved);
|
927 |
l2Model.setValueTargetAchieved(l2ValueAchieved);
|
| 933 |
|
928 |
|
| 934 |
l2Model.setOutOfSequenceCount(outOfSequenceCountByAuthId.getOrDefault(l2AuthId, 0L));
|
929 |
l2Model.setOutOfSequenceCount(outOfSequenceCountByAuthId.getOrDefault(l2AuthId, 0L));
|
| 935 |
rbmCallTargetModels.add(l2Model);
|
930 |
rbmCallTargetModels.add(l2Model);
|
| 936 |
}
|
931 |
}
|
| Line 1368... |
Line 1363... |
| 1368 |
}
|
1363 |
}
|
| 1369 |
|
1364 |
|
| 1370 |
return rows;
|
1365 |
return rows;
|
| 1371 |
}
|
1366 |
}
|
| 1372 |
|
1367 |
|
| - |
|
1368 |
/**
|
| - |
|
1369 |
* Get count of distinct partners called today based on call logs.
|
| - |
|
1370 |
* Maps customerNumber from call log to fofoId using retailer_contact and address.
|
| - |
|
1371 |
* If same fofoId is called multiple times, counts only once.
|
| - |
|
1372 |
* Numbers without fofoId mapping are also counted (by distinct customer number).
|
| - |
|
1373 |
*
|
| - |
|
1374 |
* @param authId the RBM auth ID
|
| - |
|
1375 |
* @return count of distinct partners/numbers called today
|
| - |
|
1376 |
*/
|
| - |
|
1377 |
public long getCalledCountFromCallLogs(long authId) {
|
| - |
|
1378 |
List<AgentCallLog> callLogs = agentCallLogRepository.findByAuthIdAndDate(authId, LocalDate.now());
|
| - |
|
1379 |
|
| - |
|
1380 |
if (callLogs == null || callLogs.isEmpty()) {
|
| - |
|
1381 |
return 0;
|
| - |
|
1382 |
}
|
| - |
|
1383 |
|
| - |
|
1384 |
Set<Integer> calledFofoIds = new HashSet<>();
|
| - |
|
1385 |
Set<String> calledNumbersWithoutFofoId = new HashSet<>();
|
| - |
|
1386 |
|
| - |
|
1387 |
for (AgentCallLog callLog : callLogs) {
|
| - |
|
1388 |
String customerNumber = callLog.getCustomerNumber();
|
| - |
|
1389 |
if (customerNumber != null) {
|
| - |
|
1390 |
// Normalize the phone number (remove +91 prefix if present)
|
| - |
|
1391 |
String normalized = customerNumber.startsWith("+91") ? customerNumber.substring(3) : customerNumber;
|
| - |
|
1392 |
|
| - |
|
1393 |
// Find fofoId from retailer_contact or address
|
| - |
|
1394 |
Integer fofoId = findFofoIdByMobile(normalized);
|
| - |
|
1395 |
if (fofoId != null) {
|
| - |
|
1396 |
calledFofoIds.add(fofoId);
|
| - |
|
1397 |
} else {
|
| - |
|
1398 |
// Number not found in retailer_contact or address, count by distinct number
|
| - |
|
1399 |
calledNumbersWithoutFofoId.add(normalized);
|
| - |
|
1400 |
}
|
| - |
|
1401 |
}
|
| - |
|
1402 |
}
|
| - |
|
1403 |
|
| - |
|
1404 |
// Total called = distinct fofoIds + distinct numbers without fofoId mapping
|
| - |
|
1405 |
return calledFofoIds.size() + calledNumbersWithoutFofoId.size();
|
| - |
|
1406 |
}
|
| - |
|
1407 |
|
| 1373 |
}
|
1408 |
}
|