Subversion Repositories SmartDukaan

Rev

Rev 36883 | Rev 36996 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 36883 Rev 36994
Line 1832... Line 1832...
1832
 
1832
 
1833
        // Get positions for L1 check
1833
        // Get positions for L1 check
1834
        Map<Integer, List<Position>> positionsByAuthId = positionRepository.selectPositionByAuthIds(l1AuthIds).stream()
1834
        Map<Integer, List<Position>> positionsByAuthId = positionRepository.selectPositionByAuthIds(l1AuthIds).stream()
1835
                .collect(Collectors.groupingBy(Position::getAuthUserId));
1835
                .collect(Collectors.groupingBy(Position::getAuthUserId));
1836
 
1836
 
1837
        // Batch-fetch today's call logs for all L1 RBMs, and build a (authId, fofoId) -> latest AgentCallLog map
1837
        // Batch-fetch today's call logs across all L1 RBMs and build a fofoId -> latest AgentCallLog map.
-
 
1838
        // "Latest Call Status" reflects whether the PARTNER was tried at all today, regardless of which
1838
        // so each row can carry the latest call status for that RBM-partner pair.
1839
        // RBM placed the call — so a partner shared across RBMs shows a real status if any caller reached them.
1839
        Map<Long, Map<Integer, AgentCallLog>> latestCallByAuthFofo = new HashMap<>();
1840
        Map<Integer, AgentCallLog> latestCallByFofo = new HashMap<>();
1840
        try {
1841
        try {
1841
            List<AgentCallLog> todayCallLogs = agentCallLogRepository.findByAuthIdsAndDate(l1AuthIds, LocalDate.now());
1842
            List<AgentCallLog> todayCallLogs = agentCallLogRepository.findByAuthIdsAndDate(l1AuthIds, LocalDate.now());
1842
            Set<String> normalizedMobiles = new HashSet<>();
1843
            Set<String> normalizedMobiles = new HashSet<>();
1843
            for (AgentCallLog log : todayCallLogs) {
1844
            for (AgentCallLog log : todayCallLogs) {
1844
                if (log.getCustomerNumber() != null) {
1845
                if (log.getCustomerNumber() != null) {
Line 1851... Line 1852...
1851
                if (log.getCustomerNumber() == null) continue;
1852
                if (log.getCustomerNumber() == null) continue;
1852
                String n = log.getCustomerNumber();
1853
                String n = log.getCustomerNumber();
1853
                String normalized = n.startsWith("+91") ? n.substring(3) : n;
1854
                String normalized = n.startsWith("+91") ? n.substring(3) : n;
1854
                Integer fofoId = mobileToFofoIdMap.get(normalized);
1855
                Integer fofoId = mobileToFofoIdMap.get(normalized);
1855
                if (fofoId == null) continue;
1856
                if (fofoId == null) continue;
1856
                Map<Integer, AgentCallLog> inner = latestCallByAuthFofo
-
 
1857
                        .computeIfAbsent(log.getAuthId(), k -> new HashMap<>());
-
 
1858
                AgentCallLog existing = inner.get(fofoId);
1857
                AgentCallLog existing = latestCallByFofo.get(fofoId);
1859
                if (existing == null || (log.getId() != null && existing.getId() != null && log.getId() > existing.getId())) {
1858
                if (existing == null || (log.getId() != null && existing.getId() != null && log.getId() > existing.getId())) {
1860
                    inner.put(fofoId, log);
1859
                    latestCallByFofo.put(fofoId, log);
1861
                }
1860
                }
1862
            }
1861
            }
1863
        } catch (Exception e) {
1862
        } catch (Exception e) {
1864
            LOGGER.error("Error building latest call status map for all raw data", e);
1863
            LOGGER.error("Error building latest call status map for all raw data", e);
1865
        }
1864
        }
Line 1942... Line 1941...
1942
 
1941
 
1943
                CustomRetailer retailer = retailerMap.get(fofoId);
1942
                CustomRetailer retailer = retailerMap.get(fofoId);
1944
                String partnerName = retailer != null ? retailer.getBusinessName() : "Unknown (" + fofoId + ")";
1943
                String partnerName = retailer != null ? retailer.getBusinessName() : "Unknown (" + fofoId + ")";
1945
                String partnerCode = retailer != null ? retailer.getCode() : "-";
1944
                String partnerCode = retailer != null ? retailer.getCode() : "-";
1946
 
1945
 
-
 
1946
                // "Did Not Try" means the PARTNER has no call log today from anyone — not tied to this RBM.
-
 
1947
                // If any caller reached this partner, show the actual status.
1947
                String latestCallStatus = "Did Not Try";
1948
                String latestCallStatus = "Did Not Try";
1948
                Map<Integer, AgentCallLog> rbmCalls = latestCallByAuthFofo.get((long) rbmAuthId);
-
 
1949
                if (rbmCalls != null) {
-
 
1950
                    AgentCallLog latestLog = rbmCalls.get(fofoId);
1949
                AgentCallLog latestLog = latestCallByFofo.get(fofoId);
1951
                    if (latestLog != null && latestLog.getCallStatus() != null && !latestLog.getCallStatus().isEmpty()) {
1950
                if (latestLog != null && latestLog.getCallStatus() != null && !latestLog.getCallStatus().isEmpty()) {
1952
                        latestCallStatus = latestLog.getCallStatus();
1951
                    latestCallStatus = latestLog.getCallStatus();
1953
                    }
-
 
1954
                }
1952
                }
1955
 
1953
 
1956
                rows.add(Arrays.asList(partnerName, partnerCode, status, rbmName, latestCallStatus));
1954
                rows.add(Arrays.asList(partnerName, partnerCode, status, rbmName, latestCallStatus));
1957
            }
1955
            }
1958
        }
1956
        }