| Line 1124... |
Line 1124... |
| 1124 |
// Batch-fetch EVERY call log for today (across all callers, not just RBMs) and build a
|
1124 |
// Batch-fetch EVERY call log for today (across all callers, not just RBMs) and build a
|
| 1125 |
// fofoId -> latest AgentCallLog map. We use findAllByDate here so that calls placed by
|
1125 |
// fofoId -> latest AgentCallLog map. We use findAllByDate here so that calls placed by
|
| 1126 |
// admins, escalation agents, or anyone whose authId isn't in the RBM position table are
|
1126 |
// admins, escalation agents, or anyone whose authId isn't in the RBM position table are
|
| 1127 |
// still surfaced. Downstream we only read this map for fofoIds we actually emit, so
|
1127 |
// still surfaced. Downstream we only read this map for fofoIds we actually emit, so
|
| 1128 |
// extra entries are harmless.
|
1128 |
// extra entries are harmless.
|
| - |
|
1129 |
// Group ALL today's call logs by fofoId so we can apply the Tried rule per partner
|
| - |
|
1130 |
// (uses customerStatus + persistence, same as the summary's Tried metric).
|
| 1129 |
Map<Integer, AgentCallLog> latestCallByFofo = new HashMap<>();
|
1131 |
Map<Integer, List<AgentCallLog>> callsByFofoId = new HashMap<>();
|
| 1130 |
try {
|
1132 |
try {
|
| 1131 |
List<AgentCallLog> todayCallLogs = agentCallLogRepository.findAllByDate(LocalDate.now());
|
1133 |
List<AgentCallLog> todayCallLogs = agentCallLogRepository.findAllByDate(LocalDate.now());
|
| 1132 |
Set<String> normalizedMobiles = new HashSet<>();
|
1134 |
Set<String> normalizedMobiles = new HashSet<>();
|
| 1133 |
for (AgentCallLog log : todayCallLogs) {
|
1135 |
for (AgentCallLog log : todayCallLogs) {
|
| 1134 |
if (log.getCustomerNumber() != null) {
|
1136 |
if (log.getCustomerNumber() != null) {
|
| Line 1141... |
Line 1143... |
| 1141 |
if (log.getCustomerNumber() == null) continue;
|
1143 |
if (log.getCustomerNumber() == null) continue;
|
| 1142 |
String n = log.getCustomerNumber();
|
1144 |
String n = log.getCustomerNumber();
|
| 1143 |
String normalized = n.startsWith("+91") ? n.substring(3) : n;
|
1145 |
String normalized = n.startsWith("+91") ? n.substring(3) : n;
|
| 1144 |
Integer fofoId = mobileToFofoIdMap.get(normalized);
|
1146 |
Integer fofoId = mobileToFofoIdMap.get(normalized);
|
| 1145 |
if (fofoId == null) continue;
|
1147 |
if (fofoId == null) continue;
|
| 1146 |
AgentCallLog existing = latestCallByFofo.get(fofoId);
|
- |
|
| 1147 |
if (existing == null || (log.getId() != null && existing.getId() != null && log.getId() > existing.getId())) {
|
- |
|
| 1148 |
latestCallByFofo.put(fofoId, log);
|
1148 |
callsByFofoId.computeIfAbsent(fofoId, k -> new ArrayList<>()).add(log);
|
| 1149 |
}
|
- |
|
| 1150 |
}
|
1149 |
}
|
| 1151 |
} catch (Exception e) {
|
1150 |
} catch (Exception e) {
|
| 1152 |
LOGGER.error("Error building latest call status map for all raw data", e);
|
1151 |
LOGGER.error("Error building call logs map for all raw data", e);
|
| 1153 |
}
|
1152 |
}
|
| 1154 |
|
1153 |
|
| 1155 |
// Process each L1 RBM
|
1154 |
// Process each L1 RBM
|
| 1156 |
// Note: no cross-RBM dedup — a partner assigned to multiple RBMs appears once per RBM,
|
1155 |
// Note: no cross-RBM dedup — a partner assigned to multiple RBMs appears once per RBM,
|
| 1157 |
// matching the UI summary counts so row totals per RBM equal that RBM's "Calling Target".
|
1156 |
// matching the UI summary counts so row totals per RBM equal that RBM's "Calling Target".
|
| Line 1225... |
Line 1224... |
| 1225 |
|
1224 |
|
| 1226 |
CustomRetailer retailer = retailerMap.get(fofoId);
|
1225 |
CustomRetailer retailer = retailerMap.get(fofoId);
|
| 1227 |
String partnerName = retailer != null ? retailer.getBusinessName() : "Unknown (" + fofoId + ")";
|
1226 |
String partnerName = retailer != null ? retailer.getBusinessName() : "Unknown (" + fofoId + ")";
|
| 1228 |
String partnerCode = retailer != null ? retailer.getCode() : "-";
|
1227 |
String partnerCode = retailer != null ? retailer.getCode() : "-";
|
| 1229 |
|
1228 |
|
| 1230 |
// "Did Not Try" means the PARTNER has no call log today from anyone — not tied to this RBM.
|
1229 |
// Show the latest customerStatus from today's call logs for this partner.
|
| 1231 |
// If any caller reached this partner, show the actual status.
|
1230 |
// "Did Not Try" only when there is no call log at all today.
|
| - |
|
1231 |
List<AgentCallLog> partnerCalls = callsByFofoId.getOrDefault(fofoId, Collections.emptyList());
|
| 1232 |
String latestCallStatus = "Did Not Try";
|
1232 |
String latestCallStatus = "Did Not Try";
|
| - |
|
1233 |
if (!partnerCalls.isEmpty()) {
|
| 1233 |
AgentCallLog latestLog = latestCallByFofo.get(fofoId);
|
1234 |
AgentCallLog latest = null;
|
| - |
|
1235 |
for (AgentCallLog l : partnerCalls) {
|
| - |
|
1236 |
if (latest == null || (l.getId() != null && latest.getId() != null && l.getId() > latest.getId())) {
|
| - |
|
1237 |
latest = l;
|
| - |
|
1238 |
}
|
| - |
|
1239 |
}
|
| 1234 |
if (latestLog != null && latestLog.getCallStatus() != null && !latestLog.getCallStatus().isEmpty()) {
|
1240 |
if (latest != null && latest.getCustomerStatus() != null && !latest.getCustomerStatus().isEmpty()) {
|
| 1235 |
latestCallStatus = latestLog.getCallStatus();
|
1241 |
latestCallStatus = latest.getCustomerStatus();
|
| - |
|
1242 |
}
|
| 1236 |
}
|
1243 |
}
|
| 1237 |
|
1244 |
|
| 1238 |
rows.add(Arrays.asList(partnerName, partnerCode, status, rbmName, latestCallStatus));
|
1245 |
rows.add(Arrays.asList(partnerName, partnerCode, status, rbmName, latestCallStatus));
|
| 1239 |
}
|
1246 |
}
|
| 1240 |
}
|
1247 |
}
|
| Line 1334... |
Line 1341... |
| 1334 |
if (status == null) return false;
|
1341 |
if (status == null) return false;
|
| 1335 |
String s = status.trim().toLowerCase().replace('_', ' ').replace('-', ' ').replaceAll("\\s+", " ");
|
1342 |
String s = status.trim().toLowerCase().replace('_', ' ').replace('-', ' ').replaceAll("\\s+", " ");
|
| 1336 |
return s.equals("missed") || s.equals("no answer") || s.equals("noanswer");
|
1343 |
return s.equals("missed") || s.equals("no answer") || s.equals("noanswer");
|
| 1337 |
}
|
1344 |
}
|
| 1338 |
|
1345 |
|
| - |
|
1346 |
|
| 1339 |
public List<RbmCallTargetModel> getRbmCallTargetModels(LocalDate queryDate) throws Exception {
|
1347 |
public List<RbmCallTargetModel> getRbmCallTargetModels(LocalDate queryDate) throws Exception {
|
| 1340 |
long methodStart = System.currentTimeMillis();
|
1348 |
long methodStart = System.currentTimeMillis();
|
| 1341 |
List<RbmCallTargetModel> rbmCallTargetModels = new ArrayList<>();
|
1349 |
List<RbmCallTargetModel> rbmCallTargetModels = new ArrayList<>();
|
| 1342 |
|
1350 |
|
| 1343 |
// Get all RBM positions (L1 and L2)
|
1351 |
// Get all RBM positions (L1 and L2)
|