Subversion Repositories SmartDukaan

Rev

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

Rev 36996 Rev 36997
Line 1765... Line 1765...
1765
 
1765
 
1766
        // Get auth user map
1766
        // Get auth user map
1767
        Map<Integer, AuthUser> authUserMap = authRepository.selectByIds(l1AuthIds).stream()
1767
        Map<Integer, AuthUser> authUserMap = authRepository.selectByIds(l1AuthIds).stream()
1768
                .collect(Collectors.toMap(AuthUser::getId, au -> au));
1768
                .collect(Collectors.toMap(AuthUser::getId, au -> au));
1769
 
1769
 
-
 
1770
        // Positions per auth user (needed early to build L1 partner assignments below)
-
 
1771
        Map<Integer, List<Position>> positionsByAuthId = positionRepository.selectPositionByAuthIds(l1AuthIds).stream()
-
 
1772
                .collect(Collectors.groupingBy(Position::getAuthUserId));
-
 
1773
 
-
 
1774
        // Build L1 partner assignments from partner_position — SAME source the UI summary uses for
-
 
1775
        // Calling Target. storeGuyMap (email-based CS mapping) was returning smaller/different lists
-
 
1776
        // for users who are also L2, causing summary=43 but download=3 for Ebadullah.
-
 
1777
        Map<Integer, Integer> l1PositionIdToAuthId = new HashMap<>();
1770
        // Get partner assignments
1778
        for (int rbmAuthId : l1AuthIds) {
1771
        Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
1779
            List<Position> positions = positionsByAuthId.getOrDefault(rbmAuthId, Collections.emptyList());
-
 
1780
            for (Position p : positions) {
-
 
1781
                if (ProfitMandiConstants.TICKET_CATEGORY_RBM == p.getCategoryId()
-
 
1782
                        && EscalationType.L1.equals(p.getEscalationType())) {
-
 
1783
                    l1PositionIdToAuthId.put(p.getId(), rbmAuthId);
-
 
1784
                }
-
 
1785
            }
-
 
1786
        }
1772
 
1787
 
1773
        Map<Integer, List<Integer>> rbmToFofoIdsMap = new HashMap<>();
1788
        Map<Integer, List<Integer>> rbmToFofoIdsMap = new HashMap<>();
1774
        Set<Integer> allFofoIds = new HashSet<>();
1789
        Set<Integer> allFofoIds = new HashSet<>();
1775
        for (int rbmAuthId : l1AuthIds) {
1790
        if (!l1PositionIdToAuthId.isEmpty()) {
-
 
1791
            List<com.spice.profitmandi.dao.entity.cs.PartnerPosition> allL1PPs =
-
 
1792
                    partnerPositionRepository.selectByPositionIds(new ArrayList<>(l1PositionIdToAuthId.keySet()));
-
 
1793
            // Group by owning RBM; keep partners distinct within each RBM.
1776
            AuthUser au = authUserMap.get(rbmAuthId);
1794
            Map<Integer, Set<Integer>> perRbmSets = new HashMap<>();
1777
            if (au != null && storeGuyMap.containsKey(au.getEmailId())) {
1795
            for (com.spice.profitmandi.dao.entity.cs.PartnerPosition pp : allL1PPs) {
1778
                List<Integer> fofoIds = new ArrayList<>(storeGuyMap.get(au.getEmailId()));
1796
                Integer ownerAuthId = l1PositionIdToAuthId.get(pp.getPositionId());
-
 
1797
                if (ownerAuthId == null) continue;
-
 
1798
                perRbmSets.computeIfAbsent(ownerAuthId, k -> new HashSet<>()).add(pp.getFofoId());
1779
                allFofoIds.addAll(fofoIds);
1799
                allFofoIds.add(pp.getFofoId());
-
 
1800
            }
-
 
1801
            for (Map.Entry<Integer, Set<Integer>> e : perRbmSets.entrySet()) {
1780
                rbmToFofoIdsMap.put(rbmAuthId, fofoIds);
1802
                rbmToFofoIdsMap.put(e.getKey(), new ArrayList<>(e.getValue()));
1781
            }
1803
            }
1782
        }
1804
        }
1783
 
1805
 
1784
        if (allFofoIds.isEmpty()) {
1806
        if (allFofoIds.isEmpty()) {
1785
            return rows;
1807
            return rows;
Line 1828... Line 1850...
1828
            retailerMap = retailerService.getFofoRetailers(new ArrayList<>(allFofoIds));
1850
            retailerMap = retailerService.getFofoRetailers(new ArrayList<>(allFofoIds));
1829
        } catch (ProfitMandiBusinessException e) {
1851
        } catch (ProfitMandiBusinessException e) {
1830
            LOGGER.error("Error fetching fofo retailers for all raw data", e);
1852
            LOGGER.error("Error fetching fofo retailers for all raw data", e);
1831
        }
1853
        }
1832
 
1854
 
1833
        // Get positions for L1 check
-
 
1834
        Map<Integer, List<Position>> positionsByAuthId = positionRepository.selectPositionByAuthIds(l1AuthIds).stream()
-
 
1835
                .collect(Collectors.groupingBy(Position::getAuthUserId));
-
 
1836
 
-
 
1837
        // Batch-fetch today's call logs across all L1 RBMs and build a fofoId -> latest AgentCallLog map.
1855
        // 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
1856
        // "Latest Call Status" reflects whether the PARTNER was tried at all today, regardless of which
1839
        // RBM placed the call — so a partner shared across RBMs shows a real status if any caller reached them.
1857
        // RBM placed the call — so a partner shared across RBMs shows a real status if any caller reached them.
1840
        Map<Integer, AgentCallLog> latestCallByFofo = new HashMap<>();
1858
        Map<Integer, AgentCallLog> latestCallByFofo = new HashMap<>();
1841
        try {
1859
        try {
Line 1866... Line 1884...
1866
        // Process each L1 RBM
1884
        // Process each L1 RBM
1867
        // Note: no cross-RBM dedup — a partner assigned to multiple RBMs appears once per RBM,
1885
        // Note: no cross-RBM dedup — a partner assigned to multiple RBMs appears once per RBM,
1868
        // matching the UI summary counts so row totals per RBM equal that RBM's "Calling Target".
1886
        // matching the UI summary counts so row totals per RBM equal that RBM's "Calling Target".
1869
        for (int rbmAuthId : l1AuthIds) {
1887
        for (int rbmAuthId : l1AuthIds) {
1870
            AuthUser authUser = authUserMap.get(rbmAuthId);
1888
            AuthUser authUser = authUserMap.get(rbmAuthId);
1871
            if (authUser == null || !storeGuyMap.containsKey(authUser.getEmailId())) {
1889
            if (authUser == null) {
1872
                continue;
1890
                continue;
1873
            }
1891
            }
1874
 
1892
 
1875
            List<Integer> fofoIdList = rbmToFofoIdsMap.getOrDefault(rbmAuthId, Collections.emptyList());
1893
            List<Integer> fofoIdList = rbmToFofoIdsMap.getOrDefault(rbmAuthId, Collections.emptyList());
-
 
1894
            if (fofoIdList.isEmpty()) {
-
 
1895
                continue; // No L1 partner assignments for this RBM
-
 
1896
            }
1876
 
1897
 
1877
            // Filter escalated partners for L1 RBMs
1898
            // Filter escalated partners for L1 RBMs
1878
            List<Position> positions = positionsByAuthId.getOrDefault(rbmAuthId, Collections.emptyList());
1899
            List<Position> positions = positionsByAuthId.getOrDefault(rbmAuthId, Collections.emptyList());
1879
            boolean isRBMAndL1 = positions.stream()
1900
            boolean isRBMAndL1 = positions.stream()
1880
                    .anyMatch(position ->
1901
                    .anyMatch(position ->