Subversion Repositories SmartDukaan

Rev

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

Rev 35443 Rev 35454
Line 501... Line 501...
501
        }
501
        }
502
    }
502
    }
503
 
503
 
504
    @Override
504
    @Override
505
    public Map<Integer, AuthUser> getAuthUserIdAndAuthUserMap(List<TicketAssigned> ticketAssigneds) {
505
    public Map<Integer, AuthUser> getAuthUserIdAndAuthUserMap(List<TicketAssigned> ticketAssigneds) {
-
 
506
        if (ticketAssigneds == null || ticketAssigneds.isEmpty()) {
-
 
507
            return new HashMap<>();
-
 
508
        }
-
 
509
        // OPTIMIZED: Batch fetch all AuthUsers instead of N+1 queries
-
 
510
        List<Integer> assigneeIds = ticketAssigneds.stream()
-
 
511
                .map(TicketAssigned::getAssineeId)
-
 
512
                .distinct()
-
 
513
                .collect(Collectors.toList());
506
        Map<Integer, AuthUser> authUserIdAndAuthUserMap = new HashMap<>();
514
        Map<Integer, AuthUser> authUserById = authRepository.selectByIds(assigneeIds).stream()
-
 
515
                .collect(Collectors.toMap(AuthUser::getId, au -> au, (a, b) -> a));
507
 
516
 
-
 
517
        Map<Integer, AuthUser> authUserIdAndAuthUserMap = new HashMap<>();
508
        for (TicketAssigned ticketAssigned : ticketAssigneds) {
518
        for (TicketAssigned ticketAssigned : ticketAssigneds) {
509
            AuthUser authUser = authRepository.selectById(ticketAssigned.getAssineeId());
-
 
510
            authUserIdAndAuthUserMap.put(ticketAssigned.getTicketId(), authUser);
519
            authUserIdAndAuthUserMap.put(ticketAssigned.getTicketId(), authUserById.get(ticketAssigned.getAssineeId()));
511
        }
520
        }
512
        return authUserIdAndAuthUserMap;
521
        return authUserIdAndAuthUserMap;
513
    }
522
    }
514
 
523
 
515
    @Override
524
    @Override
516
    public Map<Integer, AuthUser> getTicketIdAndAuthUserMapUsingTickets(List<Ticket> tickets) {
525
    public Map<Integer, AuthUser> getTicketIdAndAuthUserMapUsingTickets(List<Ticket> tickets) {
-
 
526
        if (tickets == null || tickets.isEmpty()) {
-
 
527
            return new HashMap<>();
-
 
528
        }
-
 
529
        // OPTIMIZED: Batch fetch all AuthUsers instead of N+1 queries
-
 
530
        List<Integer> authUserIds = tickets.stream()
-
 
531
                .map(Ticket::getL1AuthUser)
-
 
532
                .filter(id -> id != null && id > 0)
-
 
533
                .distinct()
-
 
534
                .collect(Collectors.toList());
517
        Map<Integer, AuthUser> authUserIdAndAuthUserMap = new HashMap<>();
535
        Map<Integer, AuthUser> authUserById = authRepository.selectByIds(authUserIds).stream()
-
 
536
                .collect(Collectors.toMap(AuthUser::getId, au -> au, (a, b) -> a));
518
 
537
 
-
 
538
        Map<Integer, AuthUser> authUserIdAndAuthUserMap = new HashMap<>();
519
        for (Ticket ticket : tickets) {
539
        for (Ticket ticket : tickets) {
520
            AuthUser authUser = authRepository.selectById(ticket.getL1AuthUser());
-
 
521
            authUserIdAndAuthUserMap.put(ticket.getId(), authUser);
540
            authUserIdAndAuthUserMap.put(ticket.getId(), authUserById.get(ticket.getL1AuthUser()));
522
        }
541
        }
523
        return authUserIdAndAuthUserMap;
542
        return authUserIdAndAuthUserMap;
524
    }
543
    }
525
 
544
 
526
    @Override
545
    @Override
Line 554... Line 573...
554
        return new ArrayList<>(ticketSubCategories.stream().map(x -> x.getTicketCategory()).collect(Collectors.toSet()));
573
        return new ArrayList<>(ticketSubCategories.stream().map(x -> x.getTicketCategory()).collect(Collectors.toSet()));
555
    }
574
    }
556
 
575
 
557
    @Override
576
    @Override
558
    public Map<Integer, AuthUser> getAuthUserIdAndAuthUserMapUsingPositions(List<Position> positions) {
577
    public Map<Integer, AuthUser> getAuthUserIdAndAuthUserMapUsingPositions(List<Position> positions) {
559
        Map<Integer, AuthUser> authUserIdAndAuthUserMap = new HashMap<>();
-
 
560
        for (Position position : positions) {
578
        if (positions == null || positions.isEmpty()) {
561
            AuthUser authUser = authRepository.selectById(position.getAuthUserId());
-
 
562
            authUserIdAndAuthUserMap.put(position.getAuthUserId(), authUser);
579
            return new HashMap<>();
563
        }
580
        }
-
 
581
        // OPTIMIZED: Batch fetch all AuthUsers instead of N+1 queries
564
        return authUserIdAndAuthUserMap;
582
        List<Integer> authUserIds = positions.stream()
-
 
583
                .map(Position::getAuthUserId)
-
 
584
                .filter(id -> id != null && id > 0)
-
 
585
                .distinct()
-
 
586
                .collect(Collectors.toList());
-
 
587
        return authRepository.selectByIds(authUserIds).stream()
-
 
588
                .collect(Collectors.toMap(AuthUser::getId, au -> au, (a, b) -> a));
565
    }
589
    }
566
 
590
 
567
    @Override
591
    @Override
568
    public Map<Integer, TicketCategory> getCategoryIdAndCategoryUsingPositions(List<Position> positions) {
592
    public Map<Integer, TicketCategory> getCategoryIdAndCategoryUsingPositions(List<Position> positions) {
569
        Map<Integer, TicketCategory> categoryIdAndCategoryMap = new HashMap<>();
-
 
570
        for (Position position : positions) {
593
        if (positions == null || positions.isEmpty()) {
571
            TicketCategory ticketCategory = ticketCategoryRepository.selectById(position.getCategoryId());
-
 
572
            categoryIdAndCategoryMap.put(position.getCategoryId(), ticketCategory);
594
            return new HashMap<>();
573
        }
595
        }
-
 
596
        // OPTIMIZED: Batch fetch all categories instead of N+1 queries
-
 
597
        List<Integer> categoryIds = positions.stream()
574
        return categoryIdAndCategoryMap;
598
                .map(Position::getCategoryId)
-
 
599
                .filter(id -> id != null && id > 0)
-
 
600
                .distinct()
-
 
601
                .collect(Collectors.toList());
-
 
602
        return ticketCategoryRepository.selectAll(categoryIds).stream()
-
 
603
                .collect(Collectors.toMap(TicketCategory::getId, tc -> tc, (a, b) -> a));
575
    }
604
    }
576
 
605
 
577
    @Override
606
    @Override
578
    public Map<Integer, Region> getRegionIdAndRegionMap(List<Position> positions) {
607
    public Map<Integer, Region> getRegionIdAndRegionMap(List<Position> positions) {
579
        Map<Integer, Region> regionIdAndRegionMap = new HashMap<>();
-
 
580
        for (Position position : positions) {
608
        if (positions == null || positions.isEmpty()) {
581
            Region region = regionRepository.selectById(position.getRegionId());
-
 
582
            regionIdAndRegionMap.put(position.getRegionId(), region);
609
            return new HashMap<>();
583
        }
610
        }
-
 
611
        // OPTIMIZED: Batch fetch all regions instead of N+1 queries
584
        return regionIdAndRegionMap;
612
        Set<Integer> regionIds = positions.stream()
-
 
613
                .map(Position::getRegionId)
-
 
614
                .filter(id -> id != null && id > 0)
-
 
615
                .collect(Collectors.toSet());
-
 
616
        return regionRepository.selectAll().stream()
-
 
617
                .filter(r -> regionIds.contains(r.getId()))
-
 
618
                .collect(Collectors.toMap(Region::getId, r -> r, (a, b) -> a));
585
    }
619
    }
586
 
620
 
587
    private void sendAssignedTicketMail(AuthUser authUserTo, List<AuthUser> authUsersCc, Ticket ticket, boolean isEscalated, List<Activity> activities) throws ProfitMandiBusinessException {
621
    private void sendAssignedTicketMail(AuthUser authUserTo, List<AuthUser> authUsersCc, Ticket ticket, boolean isEscalated, List<Activity> activities) throws ProfitMandiBusinessException {
588
        try {
622
        try {
589
            String[] ccTo = authUsersCc.stream().filter(x -> x != null).map(x -> x.getEmailId()).toArray(String[]::new);
623
            String[] ccTo = authUsersCc.stream().filter(x -> x != null).map(x -> x.getEmailId()).toArray(String[]::new);
Line 784... Line 818...
784
        }
818
        }
785
 
819
 
786
        List<Position> categoryPositions = positionRepository.selectPositionByCategoryIds(categoryIds);
820
        List<Position> categoryPositions = positionRepository.selectPositionByCategoryIds(categoryIds);
787
        Map<Integer, Position> positionsMap = categoryPositions.stream().collect(Collectors.toMap(x -> x.getId(), x -> x));
821
        Map<Integer, Position> positionsMap = categoryPositions.stream().collect(Collectors.toMap(x -> x.getId(), x -> x));
788
 
822
 
-
 
823
        // OPTIMIZED: Batch fetch all AuthUsers instead of N+1 queries
-
 
824
        List<Integer> authUserIds = categoryPositions.stream()
-
 
825
                .map(Position::getAuthUserId)
-
 
826
                .filter(id -> id != null && id > 0)
-
 
827
                .distinct()
-
 
828
                .collect(Collectors.toList());
-
 
829
        Map<Integer, AuthUser> authUserMap = authRepository.selectByIds(authUserIds).stream()
-
 
830
                .collect(Collectors.toMap(AuthUser::getId, au -> au, (a, b) -> a));
-
 
831
 
789
        Map<Integer, List<CustomRetailer>> positonPartnerMap = this.getPositionCustomRetailerMap(categoryPositions);
832
        Map<Integer, List<CustomRetailer>> positonPartnerMap = this.getPositionCustomRetailerMap(categoryPositions);
790
        for (Map.Entry<Integer, List<CustomRetailer>> positionPartnerEntry : positonPartnerMap.entrySet()) {
833
        for (Map.Entry<Integer, List<CustomRetailer>> positionPartnerEntry : positonPartnerMap.entrySet()) {
791
            int authUserId = positionsMap.get(positionPartnerEntry.getKey()).getAuthUserId();
834
            int authUserId = positionsMap.get(positionPartnerEntry.getKey()).getAuthUserId();
792
            Set<Integer> partnerIds = positionPartnerEntry.getValue().stream().filter(x -> activeFofoIds.contains(x.getPartnerId())).map(x -> x.getPartnerId()).collect(Collectors.toSet());
835
            Set<Integer> partnerIds = positionPartnerEntry.getValue().stream().filter(x -> activeFofoIds.contains(x.getPartnerId())).map(x -> x.getPartnerId()).collect(Collectors.toSet());
793
            AuthUser authUser = authRepository.selectById(authUserId);
836
            AuthUser authUser = authUserMap.get(authUserId);
794
            if (authUser.isActive()) {
837
            if (authUser != null && authUser.isActive()) {
795
                if (!authUserPartnerMap.containsKey(authUser.getEmailId())) {
838
                if (!authUserPartnerMap.containsKey(authUser.getEmailId())) {
796
                    authUserPartnerMap.put(authUser.getEmailId(), partnerIds);
839
                    authUserPartnerMap.put(authUser.getEmailId(), partnerIds);
797
                } else {
840
                } else {
798
                    authUserPartnerMap.get(authUser.getEmailId()).addAll(partnerIds);
841
                    authUserPartnerMap.get(authUser.getEmailId()).addAll(partnerIds);
799
                }
842
                }
Line 808... Line 851...
808
 
851
 
809
        Map<Integer, List<Integer>> authUserpartnerIdMap = new HashMap<>();
852
        Map<Integer, List<Integer>> authUserpartnerIdMap = new HashMap<>();
810
 
853
 
811
        List<Position> authPositions = positionRepository.selectPositionbyCategoryIdAndAuthId(categoryId, authId);
854
        List<Position> authPositions = positionRepository.selectPositionbyCategoryIdAndAuthId(categoryId, authId);
812
 
855
 
-
 
856
        // OPTIMIZED: Batch fetch all PartnerPositions instead of N+1 queries
813
        List<PartnerPosition> partnerPositions = authPositions.stream()
857
        List<Integer> positionIds = authPositions.stream()
814
                .flatMap(authPosition -> partnerPositionRepository.selectByPositionId(authPosition.getId()).stream())
858
                .map(Position::getId)
815
                .collect(Collectors.toList());
859
                .collect(Collectors.toList());
-
 
860
        List<PartnerPosition> partnerPositions = partnerPositionRepository.selectByPositionIds(positionIds);
816
 
861
 
817
        if (partnerPositions.stream().anyMatch(partnerPosition -> partnerPosition.getFofoId() == 0)) {
862
        if (partnerPositions.stream().anyMatch(partnerPosition -> partnerPosition.getFofoId() == 0)) {
818
            List<FofoStore> activeFofoStores = fofoStoreRepository.selectActiveStores();
863
            List<FofoStore> activeFofoStores = fofoStoreRepository.selectActiveStores();
819
 
864
 
820
            List<Integer> fofoStoreIds = activeFofoStores.stream()
865
            List<Integer> fofoStoreIds = activeFofoStores.stream()
Line 859... Line 904...
859
        List<Position> positions = positionRepository.selectByIds(partnerPositionIds);
904
        List<Position> positions = positionRepository.selectByIds(partnerPositionIds);
860
 
905
 
861
        positions = positions.stream().filter(x -> (x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_SALES || x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_RBM || x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_ABM)).collect(Collectors.toList());
906
        positions = positions.stream().filter(x -> (x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_SALES || x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_RBM || x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_ABM)).collect(Collectors.toList());
862
 
907
 
863
        if (!positions.isEmpty()) {
908
        if (!positions.isEmpty()) {
-
 
909
            // OPTIMIZED: Batch fetch all AuthUsers instead of N+1 queries
864
            for (Position partnerPostionId : positions) {
910
            List<Integer> authUserIds = positions.stream()
-
 
911
                    .map(Position::getAuthUserId)
-
 
912
                    .filter(id -> id != null && id > 0)
-
 
913
                    .distinct()
-
 
914
                    .collect(Collectors.toList());
-
 
915
            Map<Integer, AuthUser> authUserMap = authRepository.selectByIds(authUserIds).stream()
-
 
916
                    .collect(Collectors.toMap(AuthUser::getId, au -> au, (a, b) -> a));
865
 
917
 
-
 
918
            for (Position partnerPostionId : positions) {
866
                AuthUser authUser = authRepository.selectById(partnerPostionId.getAuthUserId());
919
                AuthUser authUser = authUserMap.get(partnerPostionId.getAuthUserId());
867
                LOGGER.info("authUser" + authUser);
920
                LOGGER.info("authUser" + authUser);
-
 
921
                if (authUser != null) {
868
                emails.add(authUser.getEmailId());
922
                    emails.add(authUser.getEmailId());
-
 
923
                }
869
            }
924
            }
870
        }
925
        }
871
 
926
 
872
        return emails;
927
        return emails;
873
    }
928
    }
Line 887... Line 942...
887
        //LOGGER.info("fofoIds" + fofoIds);
942
        //LOGGER.info("fofoIds" + fofoIds);
888
        List<Integer> partnerPositionIds = partnerPositionRepository.selectByRegionIdAndPartnerId(regionIds, fofoIds).stream().map(x -> x.getPositionId()).collect(Collectors.toList());
943
        List<Integer> partnerPositionIds = partnerPositionRepository.selectByRegionIdAndPartnerId(regionIds, fofoIds).stream().map(x -> x.getPositionId()).collect(Collectors.toList());
889
 
944
 
890
        //LOGGER.info("partnerPositionIds" + partnerPositionIds);
945
        //LOGGER.info("partnerPositionIds" + partnerPositionIds);
891
 
946
 
-
 
947
        // OPTIMIZED: Batch fetch all positions instead of N+1 queries
892
        for (Integer partnerPostionId : partnerPositionIds) {
948
        List<Position> positions = positionRepository.selectByIds(partnerPositionIds).stream()
893
            Position position = positionRepository.selectByIdAndCategoryId(partnerPostionId, ProfitMandiConstants.TICKET_CATEGORY_SALES);
949
                .filter(p -> p.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_SALES)
894
            //LOGGER.info("position" + position);
950
                .collect(Collectors.toList());
-
 
951
 
895
            if (position != null) {
952
        if (!positions.isEmpty()) {
-
 
953
            // OPTIMIZED: Batch fetch all AuthUsers instead of N+1 queries
-
 
954
            List<Integer> authUserIds = positions.stream()
-
 
955
                    .map(Position::getAuthUserId)
-
 
956
                    .filter(id -> id != null && id > 0)
-
 
957
                    .distinct()
-
 
958
                    .collect(Collectors.toList());
-
 
959
            Map<Integer, AuthUser> authUserMap = authRepository.selectByIds(authUserIds).stream()
-
 
960
                    .collect(Collectors.toMap(AuthUser::getId, au -> au, (a, b) -> a));
896
 
961
 
-
 
962
            for (Position position : positions) {
897
                AuthUser authUser = authRepository.selectById(position.getAuthUserId());
963
                AuthUser authUser = authUserMap.get(position.getAuthUserId());
898
                //LOGGER.info("authUser" + authUser);
964
                //LOGGER.info("authUser" + authUser);
899
 
-
 
-
 
965
                if (authUser != null) {
900
                emailEsclationTypeMap.put(position.getEscalationType(), authUser.getEmailId());
966
                    emailEsclationTypeMap.put(position.getEscalationType(), authUser.getEmailId());
-
 
967
                }
901
            }
968
            }
902
        }
969
        }
903
 
970
 
904
        //LOGGER.info("emailEsclationTypeMap" + emailEsclationTypeMap);
971
        //LOGGER.info("emailEsclationTypeMap" + emailEsclationTypeMap);
905
 
972
 
Line 914... Line 981...
914
 
981
 
915
        List<Position> categoryPositions = positionRepository.selectAllPosition();
982
        List<Position> categoryPositions = positionRepository.selectAllPosition();
916
 
983
 
917
        Map<Integer, Position> positionsMap = categoryPositions.stream().collect(Collectors.toMap(x -> x.getId(), x -> x));
984
        Map<Integer, Position> positionsMap = categoryPositions.stream().collect(Collectors.toMap(x -> x.getId(), x -> x));
918
 
985
 
-
 
986
        // OPTIMIZED: Batch fetch all AuthUsers instead of N+1 queries
-
 
987
        List<Integer> authUserIds = categoryPositions.stream()
-
 
988
                .map(Position::getAuthUserId)
-
 
989
                .filter(id -> id != null && id > 0)
-
 
990
                .distinct()
-
 
991
                .collect(Collectors.toList());
-
 
992
        Map<Integer, AuthUser> authUserMap = authRepository.selectByIds(authUserIds).stream()
-
 
993
                .collect(Collectors.toMap(AuthUser::getId, au -> au, (a, b) -> a));
-
 
994
 
919
        Map<Integer, List<CustomRetailer>> positonPartnerMap = this.getPositionCustomRetailerMap(categoryPositions);
995
        Map<Integer, List<CustomRetailer>> positonPartnerMap = this.getPositionCustomRetailerMap(categoryPositions);
920
        for (Map.Entry<Integer, List<CustomRetailer>> positionPartnerEntry : positonPartnerMap.entrySet()) {
996
        for (Map.Entry<Integer, List<CustomRetailer>> positionPartnerEntry : positonPartnerMap.entrySet()) {
921
            int authUserId = positionsMap.get(positionPartnerEntry.getKey()).getAuthUserId();
997
            int authUserId = positionsMap.get(positionPartnerEntry.getKey()).getAuthUserId();
922
            List<Integer> partnerIds = positionPartnerEntry.getValue().stream().filter(x -> activeFofoIds.contains(x.getPartnerId())).map(x -> x.getPartnerId()).collect(Collectors.toList());
998
            List<Integer> partnerIds = positionPartnerEntry.getValue().stream().filter(x -> activeFofoIds.contains(x.getPartnerId())).map(x -> x.getPartnerId()).collect(Collectors.toList());
923
            AuthUser authUser = authRepository.selectById(authUserId);
999
            AuthUser authUser = authUserMap.get(authUserId);
924
            if (authUser != null && authUser.isActive()) {
1000
            if (authUser != null && authUser.isActive()) {
925
                if (!storeGuyMap.containsKey(authUserId)) {
1001
                if (!storeGuyMap.containsKey(authUserId)) {
926
                    storeGuyMap.put(authUserId, partnerIds);
1002
                    storeGuyMap.put(authUserId, partnerIds);
927
                } else {
1003
                } else {
928
                    storeGuyMap.get(authUserId).addAll(partnerIds);
1004
                    storeGuyMap.get(authUserId).addAll(partnerIds);