Subversion Repositories SmartDukaan

Rev

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

Rev 37731 Rev 37866
Line 837... Line 837...
837
            }
837
            }
838
        }
838
        }
839
        return storeGuyMap;
839
        return storeGuyMap;
840
    }
840
    }
841
 
841
 
-
 
842
    /**
-
 
843
     * Email mapping scoped to a caller-supplied category list. Mirrors
-
 
844
     * {@link #getAuthUserPartnerEmailMapping()}'s shape and filters, but doesn't
-
 
845
     * hard-code the Sales/RBM/ABM subset — v2 callers (React admin) pass the full
-
 
846
     * HO roster they want to serve. Uncached because the key would have to include
-
 
847
     * the category list and would miss cache for every call anyway.
-
 
848
     */
-
 
849
    @Override
-
 
850
    public Map<String, Set<String>> getAuthUserPartnerEmailMappingByCategoryIds(List<Integer> categoryIds) throws ProfitMandiBusinessException {
-
 
851
        Map<String, Set<String>> storeGuyMap = new HashMap<>();
-
 
852
        if (categoryIds == null || categoryIds.isEmpty()) {
-
 
853
            return storeGuyMap;
-
 
854
        }
-
 
855
        Set<Integer> activeFofoIds = fofoStoreRepository.selectActiveStores().stream().map(x -> x.getId()).collect(Collectors.toSet());
-
 
856
 
-
 
857
        List<Position> categoryPositions = positionRepository.selectPositionByCategoryIds(categoryIds);
-
 
858
        Map<Integer, Position> positionsMap = categoryPositions.stream().collect(Collectors.toMap(x -> x.getId(), x -> x));
-
 
859
 
-
 
860
        Set<Integer> authUserIds = categoryPositions.stream().map(Position::getAuthUserId).collect(Collectors.toSet());
-
 
861
        Map<Integer, AuthUser> authUserMap = authRepository.selectByIds(new ArrayList<>(authUserIds)).stream()
-
 
862
                .collect(Collectors.toMap(AuthUser::getId, x -> x));
-
 
863
 
-
 
864
        Map<Integer, List<CustomRetailer>> positonPartnerMap = this.getPositionCustomRetailerMap(categoryPositions);
-
 
865
        for (Map.Entry<Integer, List<CustomRetailer>> positionPartnerEntry : positonPartnerMap.entrySet()) {
-
 
866
            int authUserId = positionsMap.get(positionPartnerEntry.getKey()).getAuthUserId();
-
 
867
            Set<String> partnerEmails = positionPartnerEntry.getValue().stream().filter(x -> activeFofoIds.contains(x.getPartnerId())).map(x -> x.getEmail()).collect(Collectors.toSet());
-
 
868
            AuthUser authUser = authUserMap.get(authUserId);
-
 
869
            if (authUser != null && authUser.isActive()) {
-
 
870
                if (!storeGuyMap.containsKey(authUser.getEmailId())) {
-
 
871
                    storeGuyMap.put(authUser.getEmailId(), partnerEmails);
-
 
872
                } else {
-
 
873
                    storeGuyMap.get(authUser.getEmailId()).addAll(partnerEmails);
-
 
874
                }
-
 
875
            }
-
 
876
        }
-
 
877
        return storeGuyMap;
-
 
878
    }
-
 
879
 
842
    @Override
880
    @Override
843
    @Cacheable(value = "authUserEmailPartnerIdMapping", cacheManager = "thirtyMinsTimeOutCacheManager")
881
    @Cacheable(value = "authUserEmailPartnerIdMapping", cacheManager = "thirtyMinsTimeOutCacheManager")
844
    public Map<String, Set<Integer>> getAuthUserPartnerIdMapping() throws ProfitMandiBusinessException {
882
    public Map<String, Set<Integer>> getAuthUserPartnerIdMapping() throws ProfitMandiBusinessException {
845
        Map<String, Set<Integer>> storeGuyMap = new HashMap<>();
883
        Map<String, Set<Integer>> storeGuyMap = new HashMap<>();
846
        Set<Integer> activeFofoIds = fofoStoreRepository.selectActiveStores().stream().map(x -> x.getId()).collect(Collectors.toSet());
884
        Set<Integer> activeFofoIds = fofoStoreRepository.selectActiveStores().stream().map(x -> x.getId()).collect(Collectors.toSet());