| Line 944... |
Line 944... |
| 944 |
todayTargetPartners.addAll(carryForwardPartners);
|
944 |
todayTargetPartners.addAll(carryForwardPartners);
|
| 945 |
todayTargetPartners.addAll(zeroBillingPartners);
|
945 |
todayTargetPartners.addAll(zeroBillingPartners);
|
| 946 |
todayTargetPartners.addAll(untouchedPartners);
|
946 |
todayTargetPartners.addAll(untouchedPartners);
|
| 947 |
|
947 |
|
| 948 |
// Value Achieved = All distinct partners called today (from call logs)
|
948 |
// Value Achieved = All distinct partners called today (from call logs)
|
| 949 |
long valueAchieved = getCalledCountFromCallLogs(rbmAuthId, queryDate);
|
949 |
long[] callStats = getCallStats(rbmAuthId, queryDate);
|
| 950 |
targetModel.setValueTargetAchieved(valueAchieved);
|
950 |
targetModel.setValueTargetAchieved(callStats[0]);
|
| - |
|
951 |
targetModel.setTotalRecordingCalls(callStats[1]);
|
| - |
|
952 |
targetModel.setUniqueRecordingCalls(callStats[2]);
|
| 951 |
|
953 |
|
| 952 |
// Keep todayRemarks for movedToFuture calculation
|
954 |
// Keep todayRemarks for movedToFuture calculation
|
| 953 |
List<PartnerCollectionRemark> todayRemarks = remarksByAuthId.getOrDefault(rbmAuthId, Collections.emptyList());
|
955 |
List<PartnerCollectionRemark> todayRemarks = remarksByAuthId.getOrDefault(rbmAuthId, Collections.emptyList());
|
| 954 |
|
956 |
|
| 955 |
// Moved to Future = Partners in Future Plan category who have a remark today
|
957 |
// Moved to Future = Partners in Future Plan category who have a remark today
|
| Line 1097... |
Line 1099... |
| 1097 |
// Pure L2 (not also L1) — target is only L2 escalation
|
1099 |
// Pure L2 (not also L1) — target is only L2 escalation
|
| 1098 |
l2Model.setTodayTargetOfCall(l2TargetFofoIds.size());
|
1100 |
l2Model.setTodayTargetOfCall(l2TargetFofoIds.size());
|
| 1099 |
}
|
1101 |
}
|
| 1100 |
|
1102 |
|
| 1101 |
// Value Achieved = All distinct partners called today (from call logs)
|
1103 |
// Value Achieved = All distinct partners called today (from call logs)
|
| 1102 |
long l2ValueAchieved = getCalledCountFromCallLogs(l2AuthId, queryDate);
|
1104 |
long[] l2CallStats = getCallStats(l2AuthId, queryDate);
|
| 1103 |
l2Model.setValueTargetAchieved(l2ValueAchieved);
|
1105 |
l2Model.setValueTargetAchieved(l2CallStats[0]);
|
| - |
|
1106 |
l2Model.setTotalRecordingCalls(l2CallStats[1]);
|
| - |
|
1107 |
l2Model.setUniqueRecordingCalls(l2CallStats[2]);
|
| 1104 |
|
1108 |
|
| 1105 |
l2Model.setOutOfSequenceCount(outOfSequenceCountByAuthId.getOrDefault(l2AuthId, 0L));
|
1109 |
l2Model.setOutOfSequenceCount(outOfSequenceCountByAuthId.getOrDefault(l2AuthId, 0L));
|
| 1106 |
rbmCallTargetModels.add(l2Model);
|
1110 |
rbmCallTargetModels.add(l2Model);
|
| 1107 |
}
|
1111 |
}
|
| 1108 |
|
1112 |
|
| Line 1129... |
Line 1133... |
| 1129 |
|
1133 |
|
| 1130 |
// L3 Target = partners with RBM_L3_ESCALATION as latest remark
|
1134 |
// L3 Target = partners with RBM_L3_ESCALATION as latest remark
|
| 1131 |
l3Model.setTodayTargetOfCall(l3TargetFofoIds.size());
|
1135 |
l3Model.setTodayTargetOfCall(l3TargetFofoIds.size());
|
| 1132 |
|
1136 |
|
| 1133 |
// Value Achieved = All distinct partners called today (from call logs)
|
1137 |
// Value Achieved = All distinct partners called today (from call logs)
|
| 1134 |
long l3ValueAchieved = getCalledCountFromCallLogs(l3AuthId, queryDate);
|
1138 |
long[] l3CallStats = getCallStats(l3AuthId, queryDate);
|
| 1135 |
l3Model.setValueTargetAchieved(l3ValueAchieved);
|
1139 |
l3Model.setValueTargetAchieved(l3CallStats[0]);
|
| - |
|
1140 |
l3Model.setTotalRecordingCalls(l3CallStats[1]);
|
| - |
|
1141 |
l3Model.setUniqueRecordingCalls(l3CallStats[2]);
|
| 1136 |
|
1142 |
|
| 1137 |
l3Model.setOutOfSequenceCount(outOfSequenceCountByAuthId.getOrDefault(l3AuthId, 0L));
|
1143 |
l3Model.setOutOfSequenceCount(outOfSequenceCountByAuthId.getOrDefault(l3AuthId, 0L));
|
| 1138 |
rbmCallTargetModels.add(l3Model);
|
1144 |
rbmCallTargetModels.add(l3Model);
|
| 1139 |
}
|
1145 |
}
|
| 1140 |
|
1146 |
|
| Line 1711... |
Line 1717... |
| 1711 |
public long getCalledCountFromCallLogs(long authId) {
|
1717 |
public long getCalledCountFromCallLogs(long authId) {
|
| 1712 |
return getCalledCountFromCallLogs(authId, LocalDate.now());
|
1718 |
return getCalledCountFromCallLogs(authId, LocalDate.now());
|
| 1713 |
}
|
1719 |
}
|
| 1714 |
|
1720 |
|
| 1715 |
public long getCalledCountFromCallLogs(long authId, LocalDate date) {
|
1721 |
public long getCalledCountFromCallLogs(long authId, LocalDate date) {
|
| - |
|
1722 |
return getCallStats(authId, date)[0];
|
| - |
|
1723 |
}
|
| - |
|
1724 |
|
| - |
|
1725 |
/**
|
| - |
|
1726 |
* Returns call stats: [0] = called count, [1] = total recording calls, [2] = unique recording calls
|
| - |
|
1727 |
*/
|
| - |
|
1728 |
public long[] getCallStats(long authId, LocalDate date) {
|
| 1716 |
List<AgentCallLog> callLogs = agentCallLogRepository.findByAuthIdAndDate(authId, date);
|
1729 |
List<AgentCallLog> callLogs = agentCallLogRepository.findByAuthIdAndDate(authId, date);
|
| 1717 |
|
1730 |
|
| 1718 |
if (callLogs == null || callLogs.isEmpty()) {
|
1731 |
if (callLogs == null || callLogs.isEmpty()) {
|
| 1719 |
return 0;
|
1732 |
return new long[]{0, 0, 0};
|
| 1720 |
}
|
1733 |
}
|
| 1721 |
|
1734 |
|
| 1722 |
Set<Integer> calledFofoIds = new HashSet<>();
|
1735 |
Set<Integer> calledFofoIds = new HashSet<>();
|
| 1723 |
Set<String> calledNumbersWithoutFofoId = new HashSet<>();
|
1736 |
Set<String> calledNumbersWithoutFofoId = new HashSet<>();
|
| - |
|
1737 |
long totalRecordingCalls = 0;
|
| - |
|
1738 |
Set<String> uniqueRecordingNumbers = new HashSet<>();
|
| 1724 |
|
1739 |
|
| 1725 |
for (AgentCallLog callLog : callLogs) {
|
1740 |
for (AgentCallLog callLog : callLogs) {
|
| 1726 |
String customerNumber = callLog.getCustomerNumber();
|
1741 |
String customerNumber = callLog.getCustomerNumber();
|
| 1727 |
if (customerNumber != null) {
|
1742 |
if (customerNumber != null) {
|
| 1728 |
// Normalize the phone number (remove +91 prefix if present)
|
1743 |
// Normalize the phone number (remove +91 prefix if present)
|
| Line 1734... |
Line 1749... |
| 1734 |
calledFofoIds.add(fofoId);
|
1749 |
calledFofoIds.add(fofoId);
|
| 1735 |
} else {
|
1750 |
} else {
|
| 1736 |
// Number not found in retailer_contact or address, count by distinct number
|
1751 |
// Number not found in retailer_contact or address, count by distinct number
|
| 1737 |
calledNumbersWithoutFofoId.add(normalized);
|
1752 |
calledNumbersWithoutFofoId.add(normalized);
|
| 1738 |
}
|
1753 |
}
|
| - |
|
1754 |
|
| - |
|
1755 |
// Count calls with recordings
|
| - |
|
1756 |
if (callLog.getRecordingUrl() != null && !callLog.getRecordingUrl().isEmpty()
|
| - |
|
1757 |
&& !"None".equalsIgnoreCase(callLog.getRecordingUrl())) {
|
| - |
|
1758 |
totalRecordingCalls++;
|
| - |
|
1759 |
uniqueRecordingNumbers.add(normalized);
|
| - |
|
1760 |
}
|
| 1739 |
}
|
1761 |
}
|
| 1740 |
}
|
1762 |
}
|
| 1741 |
|
1763 |
|
| 1742 |
// Total called = distinct fofoIds + distinct numbers without fofoId mapping
|
1764 |
// Total called = distinct fofoIds + distinct numbers without fofoId mapping
|
| 1743 |
return calledFofoIds.size() + calledNumbersWithoutFofoId.size();
|
1765 |
long calledCount = calledFofoIds.size() + calledNumbersWithoutFofoId.size();
|
| - |
|
1766 |
return new long[]{calledCount, totalRecordingCalls, uniqueRecordingNumbers.size()};
|
| 1744 |
}
|
1767 |
}
|
| 1745 |
|
1768 |
|
| 1746 |
@Override
|
1769 |
@Override
|
| 1747 |
public List<List<String>> getAllCallDataByDate(LocalDate date) throws Exception {
|
1770 |
public List<List<String>> getAllCallDataByDate(LocalDate date) throws Exception {
|
| 1748 |
List<List<String>> rows = new ArrayList<>();
|
1771 |
List<List<String>> rows = new ArrayList<>();
|