Subversion Repositories SmartDukaan

Rev

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

Rev 36229 Rev 36234
Line 609... Line 609...
609
    @Autowired
609
    @Autowired
610
    com.spice.profitmandi.dao.repository.cs.PartnerPositionRepository partnerPositionRepository;
610
    com.spice.profitmandi.dao.repository.cs.PartnerPositionRepository partnerPositionRepository;
611
 
611
 
612
    @Override
612
    @Override
613
    public List<RbmCallTargetModel> getRbmCallTargetModels() throws Exception {
613
    public List<RbmCallTargetModel> getRbmCallTargetModels() throws Exception {
-
 
614
        return getRbmCallTargetModels(LocalDate.now());
-
 
615
    }
-
 
616
 
-
 
617
    public List<RbmCallTargetModel> getRbmCallTargetModels(LocalDate queryDate) throws Exception {
614
        long methodStart = System.currentTimeMillis();
618
        long methodStart = System.currentTimeMillis();
615
        List<RbmCallTargetModel> rbmCallTargetModels = new ArrayList<>();
619
        List<RbmCallTargetModel> rbmCallTargetModels = new ArrayList<>();
616
 
620
 
617
        // Get all RBM positions (L1 and L2)
621
        // Get all RBM positions (L1 and L2)
618
        long start = System.currentTimeMillis();
622
        long start = System.currentTimeMillis();
Line 639... Line 643...
639
 
643
 
640
        start = System.currentTimeMillis();
644
        start = System.currentTimeMillis();
641
        Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
645
        Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
642
        LOGGER.info("RBM Call Target - StoreGuyMap fetch: {}ms", System.currentTimeMillis() - start);
646
        LOGGER.info("RBM Call Target - StoreGuyMap fetch: {}ms", System.currentTimeMillis() - start);
643
 
647
 
644
        LocalDateTime startDate = LocalDate.now().atStartOfDay();
648
        LocalDateTime startDate = queryDate.atStartOfDay();
645
        LocalDate firstOfMonth = LocalDate.now().withDayOfMonth(1);
649
        LocalDate firstOfMonth = queryDate.withDayOfMonth(1);
646
        LocalDate endOfMonth = LocalDate.now().withDayOfMonth(LocalDate.now().lengthOfMonth()).plusDays(1);
650
        LocalDate endOfMonth = queryDate.withDayOfMonth(queryDate.lengthOfMonth()).plusDays(1);
647
 
651
 
648
        // Get auth user map
652
        // Get auth user map
649
        start = System.currentTimeMillis();
653
        start = System.currentTimeMillis();
650
        Map<Integer, AuthUser> authUserMap = authRepository.selectByIds(rbmPositionsAuthIds).stream()
654
        Map<Integer, AuthUser> authUserMap = authRepository.selectByIds(rbmPositionsAuthIds).stream()
651
                .collect(Collectors.toMap(AuthUser::getId, au -> au));
655
                .collect(Collectors.toMap(AuthUser::getId, au -> au));
Line 940... Line 944...
940
            todayTargetPartners.addAll(carryForwardPartners);
944
            todayTargetPartners.addAll(carryForwardPartners);
941
            todayTargetPartners.addAll(zeroBillingPartners);
945
            todayTargetPartners.addAll(zeroBillingPartners);
942
            todayTargetPartners.addAll(untouchedPartners);
946
            todayTargetPartners.addAll(untouchedPartners);
943
 
947
 
944
            // Value Achieved = All distinct partners called today (from call logs)
948
            // Value Achieved = All distinct partners called today (from call logs)
945
            long valueAchieved = getCalledCountFromCallLogs(rbmAuthId);
949
            long valueAchieved = getCalledCountFromCallLogs(rbmAuthId, queryDate);
946
            targetModel.setValueTargetAchieved(valueAchieved);
950
            targetModel.setValueTargetAchieved(valueAchieved);
947
 
951
 
948
            // Keep todayRemarks for movedToFuture calculation
952
            // Keep todayRemarks for movedToFuture calculation
949
            List<PartnerCollectionRemark> todayRemarks = remarksByAuthId.getOrDefault(rbmAuthId, Collections.emptyList());
953
            List<PartnerCollectionRemark> todayRemarks = remarksByAuthId.getOrDefault(rbmAuthId, Collections.emptyList());
950
 
954
 
Line 1093... Line 1097...
1093
                // Pure L2 (not also L1) — target is only L2 escalation
1097
                // Pure L2 (not also L1) — target is only L2 escalation
1094
                l2Model.setTodayTargetOfCall(l2TargetFofoIds.size());
1098
                l2Model.setTodayTargetOfCall(l2TargetFofoIds.size());
1095
            }
1099
            }
1096
 
1100
 
1097
            // Value Achieved = All distinct partners called today (from call logs)
1101
            // Value Achieved = All distinct partners called today (from call logs)
1098
            long l2ValueAchieved = getCalledCountFromCallLogs(l2AuthId);
1102
            long l2ValueAchieved = getCalledCountFromCallLogs(l2AuthId, queryDate);
1099
            l2Model.setValueTargetAchieved(l2ValueAchieved);
1103
            l2Model.setValueTargetAchieved(l2ValueAchieved);
1100
 
1104
 
1101
            l2Model.setOutOfSequenceCount(outOfSequenceCountByAuthId.getOrDefault(l2AuthId, 0L));
1105
            l2Model.setOutOfSequenceCount(outOfSequenceCountByAuthId.getOrDefault(l2AuthId, 0L));
1102
            rbmCallTargetModels.add(l2Model);
1106
            rbmCallTargetModels.add(l2Model);
1103
        }
1107
        }
Line 1125... Line 1129...
1125
 
1129
 
1126
            // L3 Target = partners with RBM_L3_ESCALATION as latest remark
1130
            // L3 Target = partners with RBM_L3_ESCALATION as latest remark
1127
            l3Model.setTodayTargetOfCall(l3TargetFofoIds.size());
1131
            l3Model.setTodayTargetOfCall(l3TargetFofoIds.size());
1128
 
1132
 
1129
            // Value Achieved = All distinct partners called today (from call logs)
1133
            // Value Achieved = All distinct partners called today (from call logs)
1130
            long l3ValueAchieved = getCalledCountFromCallLogs(l3AuthId);
1134
            long l3ValueAchieved = getCalledCountFromCallLogs(l3AuthId, queryDate);
1131
            l3Model.setValueTargetAchieved(l3ValueAchieved);
1135
            l3Model.setValueTargetAchieved(l3ValueAchieved);
1132
 
1136
 
1133
            l3Model.setOutOfSequenceCount(outOfSequenceCountByAuthId.getOrDefault(l3AuthId, 0L));
1137
            l3Model.setOutOfSequenceCount(outOfSequenceCountByAuthId.getOrDefault(l3AuthId, 0L));
1134
            rbmCallTargetModels.add(l3Model);
1138
            rbmCallTargetModels.add(l3Model);
1135
        }
1139
        }
Line 1703... Line 1707...
1703
     *
1707
     *
1704
     * @param authId the RBM auth ID
1708
     * @param authId the RBM auth ID
1705
     * @return count of distinct partners/numbers called today
1709
     * @return count of distinct partners/numbers called today
1706
     */
1710
     */
1707
    public long getCalledCountFromCallLogs(long authId) {
1711
    public long getCalledCountFromCallLogs(long authId) {
-
 
1712
        return getCalledCountFromCallLogs(authId, LocalDate.now());
-
 
1713
    }
-
 
1714
 
-
 
1715
    public long getCalledCountFromCallLogs(long authId, LocalDate date) {
1708
        List<AgentCallLog> callLogs = agentCallLogRepository.findByAuthIdAndDate(authId, LocalDate.now());
1716
        List<AgentCallLog> callLogs = agentCallLogRepository.findByAuthIdAndDate(authId, date);
1709
 
1717
 
1710
        if (callLogs == null || callLogs.isEmpty()) {
1718
        if (callLogs == null || callLogs.isEmpty()) {
1711
            return 0;
1719
            return 0;
1712
        }
1720
        }
1713
 
1721