| Line 1687... |
Line 1687... |
| 1687 |
List<AgentCallLog> l1Logs = callLogsByAuthId.get((long) rbmAuthId);
|
1687 |
List<AgentCallLog> l1Logs = callLogsByAuthId.get((long) rbmAuthId);
|
| 1688 |
long[] callStats = getCallStatsFromLogs(l1Logs, mobileToFofoIdMap);
|
1688 |
long[] callStats = getCallStatsFromLogs(l1Logs, mobileToFofoIdMap);
|
| 1689 |
targetModel.setValueTargetAchieved(callStats[0]);
|
1689 |
targetModel.setValueTargetAchieved(callStats[0]);
|
| 1690 |
targetModel.setTotalRecordingCalls(callStats[1]);
|
1690 |
targetModel.setTotalRecordingCalls(callStats[1]);
|
| 1691 |
targetModel.setUniqueRecordingCalls(callStats[2]);
|
1691 |
targetModel.setUniqueRecordingCalls(callStats[2]);
|
| 1692 |
targetModel.setTriedUniqueCalls(computeUniqueTriedCount(l1Logs));
|
- |
|
| 1693 |
|
1692 |
|
| 1694 |
// Keep todayRemarks for movedToFuture calculation
|
1693 |
// Keep todayRemarks for movedToFuture calculation AND for Tried calculation
|
| 1695 |
List<PartnerCollectionRemark> todayRemarks = remarksByAuthId.getOrDefault(rbmAuthId, Collections.emptyList());
|
1694 |
List<PartnerCollectionRemark> todayRemarks = remarksByAuthId.getOrDefault(rbmAuthId, Collections.emptyList());
|
| - |
|
1695 |
targetModel.setTriedUniqueCalls(computeUniqueTriedCount(l1Logs, mobileToFofoIdMap, todayRemarks));
|
| 1696 |
|
1696 |
|
| 1697 |
// Moved to Future = Partners in Future Plan category who have a remark today
|
1697 |
// Moved to Future = Partners in Future Plan category who have a remark today
|
| 1698 |
// These are partners who were contacted today but moved to a future date
|
1698 |
// These are partners who were contacted today but moved to a future date
|
| 1699 |
Set<Integer> todayRemarkedFofoIds = todayRemarks.stream()
|
1699 |
Set<Integer> todayRemarkedFofoIds = todayRemarks.stream()
|
| 1700 |
.map(PartnerCollectionRemark::getFofoId)
|
1700 |
.map(PartnerCollectionRemark::getFofoId)
|
| Line 1844... |
Line 1844... |
| 1844 |
List<AgentCallLog> l2Logs = callLogsByAuthId.get((long) l2AuthId);
|
1844 |
List<AgentCallLog> l2Logs = callLogsByAuthId.get((long) l2AuthId);
|
| 1845 |
long[] l2CallStats = getCallStatsFromLogs(l2Logs, mobileToFofoIdMap);
|
1845 |
long[] l2CallStats = getCallStatsFromLogs(l2Logs, mobileToFofoIdMap);
|
| 1846 |
l2Model.setValueTargetAchieved(l2CallStats[0]);
|
1846 |
l2Model.setValueTargetAchieved(l2CallStats[0]);
|
| 1847 |
l2Model.setTotalRecordingCalls(l2CallStats[1]);
|
1847 |
l2Model.setTotalRecordingCalls(l2CallStats[1]);
|
| 1848 |
l2Model.setUniqueRecordingCalls(l2CallStats[2]);
|
1848 |
l2Model.setUniqueRecordingCalls(l2CallStats[2]);
|
| 1849 |
l2Model.setTriedUniqueCalls(computeUniqueTriedCount(l2Logs));
|
1849 |
l2Model.setTriedUniqueCalls(computeUniqueTriedCount(l2Logs, mobileToFofoIdMap,
|
| - |
|
1850 |
remarksByAuthId.getOrDefault(l2AuthId, Collections.emptyList())));
|
| 1850 |
|
1851 |
|
| 1851 |
l2Model.setOutOfSequenceCount(outOfSequenceCountByAuthId.getOrDefault(l2AuthId, 0L));
|
1852 |
l2Model.setOutOfSequenceCount(outOfSequenceCountByAuthId.getOrDefault(l2AuthId, 0L));
|
| 1852 |
rbmCallTargetModels.add(l2Model);
|
1853 |
rbmCallTargetModels.add(l2Model);
|
| 1853 |
}
|
1854 |
}
|
| 1854 |
|
1855 |
|
| Line 1887... |
Line 1888... |
| 1887 |
List<AgentCallLog> l3Logs = callLogsByAuthId.get((long) l3AuthId);
|
1888 |
List<AgentCallLog> l3Logs = callLogsByAuthId.get((long) l3AuthId);
|
| 1888 |
long[] l3CallStats = getCallStatsFromLogs(l3Logs, mobileToFofoIdMap);
|
1889 |
long[] l3CallStats = getCallStatsFromLogs(l3Logs, mobileToFofoIdMap);
|
| 1889 |
l3Model.setValueTargetAchieved(l3CallStats[0]);
|
1890 |
l3Model.setValueTargetAchieved(l3CallStats[0]);
|
| 1890 |
l3Model.setTotalRecordingCalls(l3CallStats[1]);
|
1891 |
l3Model.setTotalRecordingCalls(l3CallStats[1]);
|
| 1891 |
l3Model.setUniqueRecordingCalls(l3CallStats[2]);
|
1892 |
l3Model.setUniqueRecordingCalls(l3CallStats[2]);
|
| 1892 |
l3Model.setTriedUniqueCalls(computeUniqueTriedCount(l3Logs));
|
1893 |
l3Model.setTriedUniqueCalls(computeUniqueTriedCount(l3Logs, mobileToFofoIdMap,
|
| - |
|
1894 |
remarksByAuthId.getOrDefault(l3AuthId, Collections.emptyList())));
|
| 1893 |
|
1895 |
|
| 1894 |
l3Model.setOutOfSequenceCount(outOfSequenceCountByAuthId.getOrDefault(l3AuthId, 0L));
|
1896 |
l3Model.setOutOfSequenceCount(outOfSequenceCountByAuthId.getOrDefault(l3AuthId, 0L));
|
| 1895 |
rbmCallTargetModels.add(l3Model);
|
1897 |
rbmCallTargetModels.add(l3Model);
|
| 1896 |
}
|
1898 |
}
|
| 1897 |
|
1899 |
|
| Line 2073... |
Line 2075... |
| 2073 |
LOGGER.info("RBM Call Target - TOTAL TIME: {}ms, RBM count: {}", System.currentTimeMillis() - methodStart, sortedModels.size());
|
2075 |
LOGGER.info("RBM Call Target - TOTAL TIME: {}ms, RBM count: {}", System.currentTimeMillis() - methodStart, sortedModels.size());
|
| 2074 |
return sortedModels;
|
2076 |
return sortedModels;
|
| 2075 |
}
|
2077 |
}
|
| 2076 |
|
2078 |
|
| 2077 |
/**
|
2079 |
/**
|
| 2078 |
* Rule: count each distinct customer number this RBM attempted today, EXCEPT
|
2080 |
* Rule: count each distinct customer number this RBM attempted today, based on
|
| - |
|
2081 |
* post-call REMARKS (PartnerCollectionRemark), not the vendor callStatus:
|
| 2079 |
* numbers whose every log entry has callStatus "No Answer" — those count only
|
2082 |
* - If the RBM logged ANY remark other than NO_ANSWER for this partner today
|
| 2080 |
* if there were 3 or more attempts (persistence credit). Recording presence is
|
2083 |
* → count as 1 (customer was reached / tagged with a real outcome).
|
| - |
|
2084 |
* - Else if the RBM has NO remark row at all for this partner today → count
|
| 2081 |
* not required. null/empty callStatus is treated as "not no-answer" (favours
|
2085 |
* as 1 (treat missing remark as "not tagged no-answer" — matches the "-"
|
| 2082 |
* counting when the vendor didn't classify the outcome).
|
2086 |
* rows shown in the Called Partners modal which count as tried).
|
| - |
|
2087 |
* - Else (every remark is NO_ANSWER) → count only if attempts >= 3
|
| - |
|
2088 |
* (persistence credit).
|
| - |
|
2089 |
* Unknown numbers (no fofoId mapping) always count as 1 — no remark to check.
|
| 2083 |
*/
|
2090 |
*/
|
| 2084 |
private long computeUniqueTriedCount(List<AgentCallLog> callLogs) {
|
2091 |
private long computeUniqueTriedCount(List<AgentCallLog> callLogs,
|
| - |
|
2092 |
Map<String, Integer> mobileToFofoIdMap,
|
| - |
|
2093 |
List<PartnerCollectionRemark> rbmRemarksToday) {
|
| 2085 |
if (callLogs == null || callLogs.isEmpty()) return 0L;
|
2094 |
if (callLogs == null || callLogs.isEmpty()) return 0L;
|
| - |
|
2095 |
|
| - |
|
2096 |
// Build fofoId -> remarks (only the current RBM's remarks today are in scope).
|
| - |
|
2097 |
Map<Integer, List<PartnerCollectionRemark>> remarksByFofoId = new HashMap<>();
|
| - |
|
2098 |
if (rbmRemarksToday != null) {
|
| - |
|
2099 |
for (PartnerCollectionRemark r : rbmRemarksToday) {
|
| - |
|
2100 |
remarksByFofoId.computeIfAbsent(r.getFofoId(), k -> new ArrayList<>()).add(r);
|
| - |
|
2101 |
}
|
| - |
|
2102 |
}
|
| - |
|
2103 |
|
| - |
|
2104 |
// Attempts (call count) per fofoId, or per raw number if unresolved.
|
| 2086 |
Map<String, List<AgentCallLog>> byNumber = new HashMap<>();
|
2105 |
Map<Integer, Integer> attemptsByFofo = new HashMap<>();
|
| - |
|
2106 |
Set<String> unresolvedNumbers = new HashSet<>();
|
| 2087 |
for (AgentCallLog log : callLogs) {
|
2107 |
for (AgentCallLog log : callLogs) {
|
| 2088 |
String num = log.getCustomerNumber();
|
2108 |
String num = log.getCustomerNumber();
|
| 2089 |
if (num == null) continue;
|
2109 |
if (num == null) continue;
|
| 2090 |
String normalized = num.startsWith("+91") ? num.substring(3) : num;
|
2110 |
String normalized = num.startsWith("+91") ? num.substring(3) : num;
|
| 2091 |
byNumber.computeIfAbsent(normalized, k -> new ArrayList<>()).add(log);
|
2111 |
Integer fofoId = mobileToFofoIdMap != null ? mobileToFofoIdMap.get(normalized) : null;
|
| - |
|
2112 |
if (fofoId != null) {
|
| - |
|
2113 |
attemptsByFofo.merge(fofoId, 1, Integer::sum);
|
| - |
|
2114 |
} else {
|
| - |
|
2115 |
unresolvedNumbers.add(normalized);
|
| - |
|
2116 |
}
|
| 2092 |
}
|
2117 |
}
|
| - |
|
2118 |
|
| 2093 |
long count = 0L;
|
2119 |
long count = 0L;
|
| 2094 |
for (List<AgentCallLog> logs : byNumber.values()) {
|
2120 |
for (Map.Entry<Integer, Integer> e : attemptsByFofo.entrySet()) {
|
| - |
|
2121 |
int fofoId = e.getKey();
|
| - |
|
2122 |
int attempts = e.getValue();
|
| - |
|
2123 |
List<PartnerCollectionRemark> remarks = remarksByFofoId.getOrDefault(fofoId, Collections.emptyList());
|
| - |
|
2124 |
if (remarks.isEmpty()) {
|
| - |
|
2125 |
// No remark logged today for this fofoId — counts.
|
| - |
|
2126 |
count++;
|
| - |
|
2127 |
continue;
|
| - |
|
2128 |
}
|
| 2095 |
boolean hasNonNoAnswer = false;
|
2129 |
boolean hasNonNoAnswer = false;
|
| 2096 |
for (AgentCallLog l : logs) {
|
2130 |
for (PartnerCollectionRemark r : remarks) {
|
| 2097 |
if (!isNoAnswerStatus(l.getCallStatus())) {
|
2131 |
if (r.getRemark() != CollectionRemark.NO_ANSWER) {
|
| 2098 |
hasNonNoAnswer = true;
|
2132 |
hasNonNoAnswer = true;
|
| 2099 |
break;
|
2133 |
break;
|
| 2100 |
}
|
2134 |
}
|
| 2101 |
}
|
2135 |
}
|
| 2102 |
if (hasNonNoAnswer) count++;
|
2136 |
if (hasNonNoAnswer) count++;
|
| 2103 |
else if (logs.size() >= 3) count++;
|
2137 |
else if (attempts >= 3) count++;
|
| 2104 |
}
|
2138 |
}
|
| - |
|
2139 |
// Unresolved numbers — count each as 1.
|
| - |
|
2140 |
count += unresolvedNumbers.size();
|
| 2105 |
return count;
|
2141 |
return count;
|
| 2106 |
}
|
2142 |
}
|
| 2107 |
|
2143 |
|
| 2108 |
/**
|
2144 |
/**
|
| 2109 |
* Returns call stats: [0] = called count, [1] = total recording calls, [2] = unique recording calls
|
2145 |
* Returns call stats: [0] = called count, [1] = total recording calls, [2] = unique recording calls
|