Subversion Repositories SmartDukaan

Rev

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

Rev 35645 Rev 35654
Line 728... Line 728...
728
        start = System.currentTimeMillis();
728
        start = System.currentTimeMillis();
729
        LocalDateTime todayStart = LocalDate.now().atStartOfDay();
729
        LocalDateTime todayStart = LocalDate.now().atStartOfDay();
730
        LocalDateTime todayEnd = LocalDate.now().plusDays(1).atStartOfDay();
730
        LocalDateTime todayEnd = LocalDate.now().plusDays(1).atStartOfDay();
731
        List<RbmCallSequenceLog> outOfSequenceLogs = rbmCallSequenceLogRepository.selectOutOfSequenceByDateRange(todayStart, todayEnd);
731
        List<RbmCallSequenceLog> outOfSequenceLogs = rbmCallSequenceLogRepository.selectOutOfSequenceByDateRange(todayStart, todayEnd);
732
        Map<Integer, Long> outOfSequenceCountByAuthId = outOfSequenceLogs.stream()
732
        Map<Integer, Long> outOfSequenceCountByAuthId = outOfSequenceLogs.stream()
733
                .collect(Collectors.groupingBy(RbmCallSequenceLog::getAuthId, Collectors.counting()));
733
                .collect(Collectors.groupingBy(RbmCallSequenceLog::getAuthId,
-
 
734
                        Collectors.mapping(RbmCallSequenceLog::getFofoId, Collectors.collectingAndThen(Collectors.toSet(), s -> (long) s.size()))));
734
        LOGGER.info("RBM Call Target - Out of Sequence fetch: {}ms", System.currentTimeMillis() - start);
735
        LOGGER.info("RBM Call Target - Out of Sequence fetch: {}ms", System.currentTimeMillis() - start);
735
 
736
 
736
        // Process L1 RBMs (existing logic)
737
        // Process L1 RBMs (existing logic)
737
        for (int rbmAuthId : l1AuthIds) {
738
        for (int rbmAuthId : l1AuthIds) {
738
            AuthUser authUser = authUserMap.get(rbmAuthId);
739
            AuthUser authUser = authUserMap.get(rbmAuthId);
Line 1037... Line 1038...
1037
        LocalDateTime end = today.plusDays(1).atStartOfDay();
1038
        LocalDateTime end = today.plusDays(1).atStartOfDay();
1038
 
1039
 
1039
        List<RbmCallSequenceLog> logs =
1040
        List<RbmCallSequenceLog> logs =
1040
                rbmCallSequenceLogRepository.selectByAuthIdAndDateRange(authId, start, end);
1041
                rbmCallSequenceLogRepository.selectByAuthIdAndDateRange(authId, start, end);
1041
 
1042
 
1042
        Set<Integer> fofoIds = new HashSet<>();
-
 
1043
        List<RbmCallSequenceLog> oosLogs = new ArrayList<>();
1043
        Map<Integer, RbmCallSequenceLog> uniqueOosLogsByFofoId = new LinkedHashMap<>();
1044
 
1044
 
1045
        for (RbmCallSequenceLog log : logs) {
1045
        for (RbmCallSequenceLog log : logs) {
1046
            if (log.isOutOfSequence()) {
1046
            if (log.isOutOfSequence()) {
1047
                oosLogs.add(log);
1047
                // Keep only the first occurrence per fofoId (latest entry since ordered by id DESC)
1048
                fofoIds.add(log.getFofoId());
1048
                uniqueOosLogsByFofoId.putIfAbsent(log.getFofoId(), log);
1049
            }
1049
            }
1050
        }
1050
        }
1051
 
1051
 
1052
        if (oosLogs.isEmpty()) {
1052
        if (uniqueOosLogsByFofoId.isEmpty()) {
1053
            return Collections.emptyList();
1053
            return Collections.emptyList();
1054
        }
1054
        }
1055
 
1055
 
-
 
1056
        Set<Integer> fofoIds = uniqueOosLogsByFofoId.keySet();
1056
        Map<Integer, CustomRetailer> retailerMap = Collections.emptyMap();
1057
        Map<Integer, CustomRetailer> retailerMap = Collections.emptyMap();
1057
        try {
1058
        try {
1058
            retailerMap = retailerService.getFofoRetailers(new ArrayList<>(fofoIds));
1059
            retailerMap = retailerService.getFofoRetailers(new ArrayList<>(fofoIds));
1059
        } catch (ProfitMandiBusinessException e) {
1060
        } catch (ProfitMandiBusinessException e) {
1060
            LOGGER.error("Error fetching fofo stores", e);
1061
            LOGGER.error("Error fetching fofo stores", e);
1061
        }
1062
        }
1062
 
1063
 
1063
        DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("hh:mm a");
1064
        DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("hh:mm a");
1064
        List<OutOfSequenceDetailModel> result = new ArrayList<>();
1065
        List<OutOfSequenceDetailModel> result = new ArrayList<>();
1065
 
1066
 
1066
        for (RbmCallSequenceLog log : oosLogs) {
1067
        for (RbmCallSequenceLog log : uniqueOosLogsByFofoId.values()) {
1067
            CustomRetailer retailer = retailerMap.get(log.getFofoId());
1068
            CustomRetailer retailer = retailerMap.get(log.getFofoId());
1068
            String partyName = retailer != null
1069
            String partyName = retailer != null
1069
                    ? retailer.getBusinessName()
1070
                    ? retailer.getBusinessName()
1070
                    : "Unknown (" + log.getFofoId() + ")";
1071
                    : "Unknown (" + log.getFofoId() + ")";
1071
            String code = retailer != null
1072
            String code = retailer != null