Subversion Repositories SmartDukaan

Rev

Rev 36596 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 36596 Rev 36883
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
-
 
1838
        // so each row can carry the latest call status for that RBM-partner pair.
-
 
1839
        Map<Long, Map<Integer, AgentCallLog>> latestCallByAuthFofo = new HashMap<>();
-
 
1840
        try {
-
 
1841
            List<AgentCallLog> todayCallLogs = agentCallLogRepository.findByAuthIdsAndDate(l1AuthIds, LocalDate.now());
-
 
1842
            Set<String> normalizedMobiles = new HashSet<>();
-
 
1843
            for (AgentCallLog log : todayCallLogs) {
-
 
1844
                if (log.getCustomerNumber() != null) {
-
 
1845
                    String n = log.getCustomerNumber();
-
 
1846
                    normalizedMobiles.add(n.startsWith("+91") ? n.substring(3) : n);
-
 
1847
                }
-
 
1848
            }
-
 
1849
            Map<String, Integer> mobileToFofoIdMap = buildMobileToFofoIdMap(normalizedMobiles);
-
 
1850
            for (AgentCallLog log : todayCallLogs) {
-
 
1851
                if (log.getCustomerNumber() == null) continue;
-
 
1852
                String n = log.getCustomerNumber();
-
 
1853
                String normalized = n.startsWith("+91") ? n.substring(3) : n;
-
 
1854
                Integer fofoId = mobileToFofoIdMap.get(normalized);
-
 
1855
                if (fofoId == null) continue;
-
 
1856
                Map<Integer, AgentCallLog> inner = latestCallByAuthFofo
-
 
1857
                        .computeIfAbsent(log.getAuthId(), k -> new HashMap<>());
-
 
1858
                AgentCallLog existing = inner.get(fofoId);
-
 
1859
                if (existing == null || (log.getId() != null && existing.getId() != null && log.getId() > existing.getId())) {
-
 
1860
                    inner.put(fofoId, log);
-
 
1861
                }
-
 
1862
            }
-
 
1863
        } catch (Exception e) {
-
 
1864
            LOGGER.error("Error building latest call status map for all raw data", e);
-
 
1865
        }
-
 
1866
 
1837
        // Track processed fofoIds to avoid duplicates (a party assigned to L1 RBM
1867
        // Track processed fofoIds to avoid duplicates (a party assigned to L1 RBM
1838
        // should not appear again under another RBM who also has it via L2 position)
1868
        // should not appear again under another RBM who also has it via L2 position)
1839
        Set<Integer> processedFofoIds = new HashSet<>();
1869
        Set<Integer> processedFofoIds = new HashSet<>();
1840
 
1870
 
1841
        // Process each L1 RBM
1871
        // Process each L1 RBM
Line 1912... Line 1942...
1912
 
1942
 
1913
                CustomRetailer retailer = retailerMap.get(fofoId);
1943
                CustomRetailer retailer = retailerMap.get(fofoId);
1914
                String partnerName = retailer != null ? retailer.getBusinessName() : "Unknown (" + fofoId + ")";
1944
                String partnerName = retailer != null ? retailer.getBusinessName() : "Unknown (" + fofoId + ")";
1915
                String partnerCode = retailer != null ? retailer.getCode() : "-";
1945
                String partnerCode = retailer != null ? retailer.getCode() : "-";
1916
 
1946
 
-
 
1947
                String latestCallStatus = "Did Not Try";
-
 
1948
                Map<Integer, AgentCallLog> rbmCalls = latestCallByAuthFofo.get((long) rbmAuthId);
-
 
1949
                if (rbmCalls != null) {
-
 
1950
                    AgentCallLog latestLog = rbmCalls.get(fofoId);
-
 
1951
                    if (latestLog != null && latestLog.getCallStatus() != null && !latestLog.getCallStatus().isEmpty()) {
-
 
1952
                        latestCallStatus = latestLog.getCallStatus();
-
 
1953
                    }
-
 
1954
                }
-
 
1955
 
1917
                rows.add(Arrays.asList(partnerName, partnerCode, status, rbmName));
1956
                rows.add(Arrays.asList(partnerName, partnerCode, status, rbmName, latestCallStatus));
1918
            }
1957
            }
1919
        }
1958
        }
1920
 
1959
 
1921
        return rows;
1960
        return rows;
1922
    }
1961
    }