Subversion Repositories SmartDukaan

Rev

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

Rev 36212 Rev 36225
Line 604... Line 604...
604
    RetailerContactRepository retailerContactRepository;
604
    RetailerContactRepository retailerContactRepository;
605
 
605
 
606
    @Autowired
606
    @Autowired
607
    AddressRepository addressRepository;
607
    AddressRepository addressRepository;
608
 
608
 
-
 
609
    @Autowired
-
 
610
    com.spice.profitmandi.dao.repository.cs.PartnerPositionRepository partnerPositionRepository;
-
 
611
 
609
    @Override
612
    @Override
610
    public List<RbmCallTargetModel> getRbmCallTargetModels() throws Exception {
613
    public List<RbmCallTargetModel> getRbmCallTargetModels() throws Exception {
611
        long methodStart = System.currentTimeMillis();
614
        long methodStart = System.currentTimeMillis();
612
        List<RbmCallTargetModel> rbmCallTargetModels = new ArrayList<>();
615
        List<RbmCallTargetModel> rbmCallTargetModels = new ArrayList<>();
613
 
616
 
Line 806... Line 809...
806
        Map<Integer, Long> outOfSequenceCountByAuthId = outOfSequenceLogs.stream()
809
        Map<Integer, Long> outOfSequenceCountByAuthId = outOfSequenceLogs.stream()
807
                .collect(Collectors.groupingBy(RbmCallSequenceLog::getAuthId,
810
                .collect(Collectors.groupingBy(RbmCallSequenceLog::getAuthId,
808
                        Collectors.mapping(RbmCallSequenceLog::getFofoId, Collectors.collectingAndThen(Collectors.toSet(), s -> (long) s.size()))));
811
                        Collectors.mapping(RbmCallSequenceLog::getFofoId, Collectors.collectingAndThen(Collectors.toSet(), s -> (long) s.size()))));
809
        LOGGER.info("RBM Call Target - Out of Sequence fetch: {}ms", System.currentTimeMillis() - start);
812
        LOGGER.info("RBM Call Target - Out of Sequence fetch: {}ms", System.currentTimeMillis() - start);
810
 
813
 
-
 
814
        // Identify users who are both L1 and L2 — they will be shown only as L2
811
        // Process L1 RBMs (existing logic)
815
        Set<Integer> l2AuthIdSet = new HashSet<>(l2AuthIds);
-
 
816
 
-
 
817
        // Process L1 RBMs (skip users who are also L2 — their data will be merged into L2 model)
812
        for (int rbmAuthId : l1AuthIds) {
818
        for (int rbmAuthId : l1AuthIds) {
-
 
819
            if (l2AuthIdSet.contains(rbmAuthId)) {
-
 
820
                continue; // Will be handled in L2 processing with merged L1 data
-
 
821
            }
813
            AuthUser authUser = authUserMap.get(rbmAuthId);
822
            AuthUser authUser = authUserMap.get(rbmAuthId);
814
            if (authUser == null || !storeGuyMap.containsKey(authUser.getEmailId())) {
823
            if (authUser == null || !storeGuyMap.containsKey(authUser.getEmailId())) {
815
                continue;
824
                continue;
816
            }
825
            }
817
 
826
 
Line 954... Line 963...
954
 
963
 
955
            rbmCallTargetModels.add(targetModel);
964
            rbmCallTargetModels.add(targetModel);
956
        }
965
        }
957
 
966
 
958
        // Process L2 RBMs (escalated ticket logic with categorization)
967
        // Process L2 RBMs (escalated ticket logic with categorization)
-
 
968
        // For users who are both L1 and L2, merge their L1 calling target into L2 model
959
        for (int l2AuthId : l2AuthIds) {
969
        for (int l2AuthId : l2AuthIds) {
960
            AuthUser authUser = authUserMap.get(l2AuthId);
970
            AuthUser authUser = authUserMap.get(l2AuthId);
961
            if (authUser == null) {
971
            if (authUser == null) {
962
                continue;
972
                continue;
963
            }
973
            }
Line 974... Line 984...
974
            l2Model.setL2CallingList(l2TargetFofoIds.size());
984
            l2Model.setL2CallingList(l2TargetFofoIds.size());
975
            // Partner count = total assigned partners (same as L1 source)
985
            // Partner count = total assigned partners (same as L1 source)
976
            List<Integer> l2AssignedFofoIds = rbmToFofoIdsMap.getOrDefault(l2AuthId, Collections.emptyList());
986
            List<Integer> l2AssignedFofoIds = rbmToFofoIdsMap.getOrDefault(l2AuthId, Collections.emptyList());
977
            l2Model.setPartnerCount(l2AssignedFofoIds.size());
987
            l2Model.setPartnerCount(l2AssignedFofoIds.size());
978
 
988
 
-
 
989
            // Calculate L1 own target if user is also L1
-
 
990
            long l1OwnTarget = 0;
-
 
991
            if (l1AuthIds.contains(l2AuthId) && storeGuyMap.containsKey(authUser.getEmailId())) {
-
 
992
                List<Integer> fofoIdList = rbmToFofoIdsMap.getOrDefault(l2AuthId, Collections.emptyList());
-
 
993
                List<Position> positions = positionsByAuthId.getOrDefault(l2AuthId, Collections.emptyList());
-
 
994
                boolean isRBMAndL1 = positions.stream()
-
 
995
                        .anyMatch(position ->
-
 
996
                                ProfitMandiConstants.TICKET_CATEGORY_RBM == position.getCategoryId()
-
 
997
                                        && EscalationType.L1.equals(position.getEscalationType()));
-
 
998
                List<Integer> l1FofoIds = new ArrayList<>(fofoIdList);
-
 
999
                if (isRBMAndL1) {
-
 
1000
                    Map<Integer, PartnerCollectionRemark> partnerCollectionRemarks = new HashMap<>();
-
 
1001
                    for (Integer fofoId : fofoIdList) {
-
 
1002
                        if (allPartnerCollectionRemarks.containsKey(fofoId)) {
-
 
1003
                            partnerCollectionRemarks.put(fofoId, allPartnerCollectionRemarks.get(fofoId));
-
 
1004
                        }
-
 
1005
                    }
-
 
1006
                    l1FofoIds = partnerCollectionRemarks.entrySet().stream()
-
 
1007
                            .filter(entry -> {
-
 
1008
                                PartnerCollectionRemark pcrMap = entry.getValue();
-
 
1009
                                return !(CollectionRemark.RBM_L2_ESCALATION.equals(pcrMap.getRemark())
-
 
1010
                                        || CollectionRemark.SALES_ESCALATION.equals(pcrMap.getRemark()));
-
 
1011
                            })
-
 
1012
                            .map(Map.Entry::getKey)
-
 
1013
                            .collect(Collectors.toList());
-
 
1014
                }
-
 
1015
                Map<Integer, FofoStore> finalFofoStoresMap2 = fofoStoresMap;
-
 
1016
                List<Integer> validL1FofoIds = l1FofoIds.stream()
-
 
1017
                        .filter(fofoId -> {
-
 
1018
                            FofoStore store = finalFofoStoresMap2.get(fofoId);
-
 
1019
                            if (store == null || store.isInternal()) return false;
-
 
1020
                            return ActivationType.ACTIVE.equals(store.getActivationType())
-
 
1021
                                    || ActivationType.REVIVAL.equals(store.getActivationType());
-
 
1022
                        })
-
 
1023
                        .collect(Collectors.toList());
-
 
1024
 
-
 
1025
                // Count L1 own target (PlanToday + CarryForward + ZeroBilling + Untouched)
-
 
1026
                for (Integer fofoId : validL1FofoIds) {
-
 
1027
                    int rank = allCollectionRankMap.getOrDefault(fofoId, 5);
-
 
1028
                    boolean hasZeroBilling = !allMtdBilledFofoIds.contains(fofoId);
-
 
1029
                    if (rank == 1 || rank == 2 || hasZeroBilling || rank == 3) {
-
 
1030
                        l1OwnTarget++;
-
 
1031
                    }
-
 
1032
                }
-
 
1033
            }
-
 
1034
 
979
            // L2 Target = partners with RBM_L2_ESCALATION as latest remark
1035
            // L2 Target = L2 escalation partners + own L1 target (if also L1)
980
            l2Model.setTodayTargetOfCall(l2TargetFofoIds.size());
1036
            l2Model.setTodayTargetOfCall(l2TargetFofoIds.size() + l1OwnTarget);
981
 
1037
 
982
            // Value Achieved = All distinct partners called today (from call logs)
1038
            // Value Achieved = All distinct partners called today (from call logs)
983
            long l2ValueAchieved = getCalledCountFromCallLogs(l2AuthId);
1039
            long l2ValueAchieved = getCalledCountFromCallLogs(l2AuthId);
984
            l2Model.setValueTargetAchieved(l2ValueAchieved);
1040
            l2Model.setValueTargetAchieved(l2ValueAchieved);
985
 
1041
 
Line 1017... Line 1073...
1017
 
1073
 
1018
            l3Model.setOutOfSequenceCount(outOfSequenceCountByAuthId.getOrDefault(l3AuthId, 0L));
1074
            l3Model.setOutOfSequenceCount(outOfSequenceCountByAuthId.getOrDefault(l3AuthId, 0L));
1019
            rbmCallTargetModels.add(l3Model);
1075
            rbmCallTargetModels.add(l3Model);
1020
        }
1076
        }
1021
 
1077
 
1022
        // Group L1 under their L2 manager, and L2 under their L3 manager using authUser.managerId
1078
        // Group models by escalation level
1023
        Map<Integer, RbmCallTargetModel> l3ModelsByAuthId = new HashMap<>();
1079
        Map<Integer, RbmCallTargetModel> l3ModelsByAuthId = new HashMap<>();
1024
        Map<Integer, RbmCallTargetModel> l2ModelsByAuthId = new HashMap<>();
1080
        Map<Integer, RbmCallTargetModel> l2ModelsByAuthId = new HashMap<>();
1025
        Map<Integer, RbmCallTargetModel> l1ModelsByAuthId = new HashMap<>();
1081
        Map<Integer, RbmCallTargetModel> l1ModelsByAuthId = new HashMap<>();
1026
        for (RbmCallTargetModel m : rbmCallTargetModels) {
1082
        for (RbmCallTargetModel m : rbmCallTargetModels) {
1027
            if (m.isL3Position()) {
1083
            if (m.isL3Position()) {
Line 1031... Line 1087...
1031
            } else {
1087
            } else {
1032
                l1ModelsByAuthId.put(m.getAuthId(), m);
1088
                l1ModelsByAuthId.put(m.getAuthId(), m);
1033
            }
1089
            }
1034
        }
1090
        }
1035
 
1091
 
-
 
1092
        // Build partner-based hierarchy using partner_position table
-
 
1093
        // Map positionId -> Position for quick lookup
-
 
1094
        Map<Integer, Position> positionByIdMap = allRbmPositions.stream()
-
 
1095
                .collect(Collectors.toMap(Position::getId, p -> p, (a, b) -> a));
-
 
1096
 
-
 
1097
        // Get all RBM position IDs and fetch their partner assignments
-
 
1098
        List<Integer> allRbmPositionIds = allRbmPositions.stream()
-
 
1099
                .map(Position::getId).collect(Collectors.toList());
-
 
1100
        List<com.spice.profitmandi.dao.entity.cs.PartnerPosition> allPartnerPositions =
-
 
1101
                partnerPositionRepository.selectByPositionIds(allRbmPositionIds);
-
 
1102
 
-
 
1103
        // Build partnerId -> map of escalationType -> Set<authUserIds>
-
 
1104
        // This tells us for each partner, who is their L1, L2, L3
-
 
1105
        Map<Integer, Map<EscalationType, Set<Integer>>> partnerToAuthByLevel = new HashMap<>();
-
 
1106
        for (com.spice.profitmandi.dao.entity.cs.PartnerPosition pp : allPartnerPositions) {
-
 
1107
            Position pos = positionByIdMap.get(pp.getPositionId());
-
 
1108
            if (pos != null && pos.getEscalationType() != null) {
-
 
1109
                partnerToAuthByLevel
-
 
1110
                        .computeIfAbsent(pp.getFofoId(), k -> new HashMap<>())
-
 
1111
                        .computeIfAbsent(pos.getEscalationType(), k -> new HashSet<>())
-
 
1112
                        .add(pos.getAuthUserId());
-
 
1113
            }
-
 
1114
        }
-
 
1115
 
-
 
1116
        // Build L2 -> L1 team map based on shared partners
-
 
1117
        // If an L1 and L2 share partners (L1 at L1 level, L2 at L2 level), that L1 belongs under that L2
-
 
1118
        Map<Integer, List<RbmCallTargetModel>> l2TeamMap = new LinkedHashMap<>();
-
 
1119
        for (RbmCallTargetModel l2Model : l2ModelsByAuthId.values()) {
-
 
1120
            l2TeamMap.put(l2Model.getAuthId(), new ArrayList<>());
-
 
1121
        }
-
 
1122
 
1036
        // Build L3 -> L2 team map using managerId from AuthUser
1123
        // Build L3 -> L2 team map based on shared partners
1037
        Map<Integer, List<RbmCallTargetModel>> l3TeamMap = new LinkedHashMap<>();
1124
        Map<Integer, List<RbmCallTargetModel>> l3TeamMap = new LinkedHashMap<>();
1038
        for (RbmCallTargetModel l3Model : l3ModelsByAuthId.values()) {
1125
        for (RbmCallTargetModel l3Model : l3ModelsByAuthId.values()) {
1039
            l3TeamMap.put(l3Model.getAuthId(), new ArrayList<>());
1126
            l3TeamMap.put(l3Model.getAuthId(), new ArrayList<>());
1040
        }
1127
        }
1041
 
1128
 
-
 
1129
        // For each L1, find which L2 shares the most partners -> that's their L2
-
 
1130
        Set<Integer> addedL1AuthIds = new HashSet<>();
-
 
1131
        for (RbmCallTargetModel l1Model : l1ModelsByAuthId.values()) {
-
 
1132
            Map<Integer, Integer> l2SharedCount = new HashMap<>(); // l2AuthId -> shared partner count
-
 
1133
            for (Map.Entry<Integer, Map<EscalationType, Set<Integer>>> entry : partnerToAuthByLevel.entrySet()) {
-
 
1134
                Map<EscalationType, Set<Integer>> levelMap = entry.getValue();
-
 
1135
                Set<Integer> l1IdsForPartner = levelMap.getOrDefault(EscalationType.L1, Collections.emptySet());
-
 
1136
                Set<Integer> l2AuthIdsForPartner = levelMap.getOrDefault(EscalationType.L2, Collections.emptySet());
-
 
1137
                if (l1IdsForPartner.contains(l1Model.getAuthId())) {
-
 
1138
                    for (int l2Id : l2AuthIdsForPartner) {
-
 
1139
                        if (l2ModelsByAuthId.containsKey(l2Id) && l2Id != l1Model.getAuthId()) {
-
 
1140
                            l2SharedCount.merge(l2Id, 1, Integer::sum);
-
 
1141
                        }
-
 
1142
                    }
-
 
1143
                }
-
 
1144
            }
-
 
1145
            // Assign L1 to the L2 with most shared partners
-
 
1146
            if (!l2SharedCount.isEmpty()) {
-
 
1147
                int bestL2 = l2SharedCount.entrySet().stream()
-
 
1148
                        .max(Map.Entry.comparingByValue()).get().getKey();
-
 
1149
                l2TeamMap.get(bestL2).add(l1Model);
-
 
1150
                addedL1AuthIds.add(l1Model.getAuthId());
-
 
1151
            }
-
 
1152
        }
-
 
1153
 
-
 
1154
        // For each L2, find which L3 shares the most partners -> that's their L3
1042
        Set<Integer> addedL2AuthIds = new HashSet<>();
1155
        Set<Integer> addedL2AuthIds = new HashSet<>();
1043
        for (RbmCallTargetModel l2Model : l2ModelsByAuthId.values()) {
1156
        for (RbmCallTargetModel l2Model : l2ModelsByAuthId.values()) {
-
 
1157
            Map<Integer, Integer> l3SharedCount = new HashMap<>();
-
 
1158
            for (Map.Entry<Integer, Map<EscalationType, Set<Integer>>> entry : partnerToAuthByLevel.entrySet()) {
-
 
1159
                Map<EscalationType, Set<Integer>> levelMap = entry.getValue();
-
 
1160
                Set<Integer> l2AuthIdsForPartner = levelMap.getOrDefault(EscalationType.L2, Collections.emptySet());
-
 
1161
                Set<Integer> l3AuthIdsForPartner = levelMap.getOrDefault(EscalationType.L3, Collections.emptySet());
1044
            AuthUser l2User = authUserMap.get(l2Model.getAuthId());
1162
                if (l2AuthIdsForPartner.contains(l2Model.getAuthId())) {
-
 
1163
                    for (int l3Id : l3AuthIdsForPartner) {
1045
            if (l2User != null && l3TeamMap.containsKey(l2User.getManagerId())) {
1164
                        if (l3ModelsByAuthId.containsKey(l3Id)) {
-
 
1165
                            l3SharedCount.merge(l3Id, 1, Integer::sum);
-
 
1166
                        }
-
 
1167
                    }
-
 
1168
                }
-
 
1169
            }
-
 
1170
            if (!l3SharedCount.isEmpty()) {
-
 
1171
                int bestL3 = l3SharedCount.entrySet().stream()
-
 
1172
                        .max(Map.Entry.comparingByValue()).get().getKey();
1046
                l3TeamMap.get(l2User.getManagerId()).add(l2Model);
1173
                l3TeamMap.get(bestL3).add(l2Model);
1047
                addedL2AuthIds.add(l2Model.getAuthId());
1174
                addedL2AuthIds.add(l2Model.getAuthId());
1048
            }
1175
            }
1049
        }
1176
        }
1050
 
1177
 
1051
        // Build L2 -> L1 team map using managerId from AuthUser
1178
        // For L1s not mapped to any L2, check if they map directly to an L3 via shared partners
1052
        Map<Integer, List<RbmCallTargetModel>> l2TeamMap = new LinkedHashMap<>();
1179
        Map<Integer, List<RbmCallTargetModel>> l3DirectL1Map = new LinkedHashMap<>();
1053
        for (RbmCallTargetModel l2Model : l2ModelsByAuthId.values()) {
1180
        for (RbmCallTargetModel l3Model : l3ModelsByAuthId.values()) {
1054
            l2TeamMap.put(l2Model.getAuthId(), new ArrayList<>());
1181
            l3DirectL1Map.put(l3Model.getAuthId(), new ArrayList<>());
1055
        }
1182
        }
1056
 
-
 
1057
        Set<Integer> addedL1AuthIds = new HashSet<>();
-
 
1058
        for (RbmCallTargetModel l1Model : l1ModelsByAuthId.values()) {
1183
        for (RbmCallTargetModel l1Model : l1ModelsByAuthId.values()) {
1059
            AuthUser l1User = authUserMap.get(l1Model.getAuthId());
1184
            if (addedL1AuthIds.contains(l1Model.getAuthId())) continue;
-
 
1185
            Map<Integer, Integer> l3SharedCount = new HashMap<>();
-
 
1186
            for (Map.Entry<Integer, Map<EscalationType, Set<Integer>>> entry : partnerToAuthByLevel.entrySet()) {
-
 
1187
                Map<EscalationType, Set<Integer>> levelMap = entry.getValue();
-
 
1188
                Set<Integer> l1IdsForPartner = levelMap.getOrDefault(EscalationType.L1, Collections.emptySet());
-
 
1189
                Set<Integer> l3AuthIdsForPartner = levelMap.getOrDefault(EscalationType.L3, Collections.emptySet());
1060
            if (l1User != null && l2TeamMap.containsKey(l1User.getManagerId())) {
1190
                if (l1IdsForPartner.contains(l1Model.getAuthId())) {
-
 
1191
                    for (int l3Id : l3AuthIdsForPartner) {
-
 
1192
                        if (l3ModelsByAuthId.containsKey(l3Id)) {
-
 
1193
                            l3SharedCount.merge(l3Id, 1, Integer::sum);
-
 
1194
                        }
-
 
1195
                    }
-
 
1196
                }
-
 
1197
            }
-
 
1198
            if (!l3SharedCount.isEmpty()) {
-
 
1199
                int bestL3 = l3SharedCount.entrySet().stream()
-
 
1200
                        .max(Map.Entry.comparingByValue()).get().getKey();
1061
                l2TeamMap.get(l1User.getManagerId()).add(l1Model);
1201
                l3DirectL1Map.get(bestL3).add(l1Model);
1062
                addedL1AuthIds.add(l1Model.getAuthId());
1202
                addedL1AuthIds.add(l1Model.getAuthId());
1063
            }
1203
            }
1064
        }
1204
        }
1065
 
1205
 
1066
        // Build sorted result: L3 row, then its L2 team with their L1 teams (sorted by name)
1206
        // Build sorted result: L3 -> L2 -> L1 (with direct L1s under L3 if no L2)
1067
        List<RbmCallTargetModel> sortedModels = new ArrayList<>();
1207
        List<RbmCallTargetModel> sortedModels = new ArrayList<>();
1068
 
1208
 
1069
        // First add L3 with their L2 teams
-
 
1070
        List<RbmCallTargetModel> l3Sorted = new ArrayList<>(l3ModelsByAuthId.values());
1209
        List<RbmCallTargetModel> l3Sorted = new ArrayList<>(l3ModelsByAuthId.values());
1071
        l3Sorted.sort(Comparator.comparing(RbmCallTargetModel::getRbmName));
1210
        l3Sorted.sort(Comparator.comparing(RbmCallTargetModel::getRbmName));
1072
 
1211
 
1073
        for (RbmCallTargetModel l3Model : l3Sorted) {
1212
        for (RbmCallTargetModel l3Model : l3Sorted) {
1074
            sortedModels.add(l3Model);
1213
            sortedModels.add(l3Model);
Line 1078... Line 1217...
1078
                sortedModels.add(l2Model);
1217
                sortedModels.add(l2Model);
1079
                List<RbmCallTargetModel> l1Team = l2TeamMap.getOrDefault(l2Model.getAuthId(), Collections.emptyList());
1218
                List<RbmCallTargetModel> l1Team = l2TeamMap.getOrDefault(l2Model.getAuthId(), Collections.emptyList());
1080
                l1Team.sort(Comparator.comparing(RbmCallTargetModel::getRbmName));
1219
                l1Team.sort(Comparator.comparing(RbmCallTargetModel::getRbmName));
1081
                sortedModels.addAll(l1Team);
1220
                sortedModels.addAll(l1Team);
1082
            }
1221
            }
-
 
1222
            // Add L1s that report directly to this L3 (no L2 in between)
-
 
1223
            List<RbmCallTargetModel> directL1Team = l3DirectL1Map.getOrDefault(l3Model.getAuthId(), Collections.emptyList());
-
 
1224
            directL1Team.sort(Comparator.comparing(RbmCallTargetModel::getRbmName));
-
 
1225
            sortedModels.addAll(directL1Team);
1083
        }
1226
        }
1084
 
1227
 
1085
        // Add L2s not mapped to any L3 with their L1 teams
1228
        // Add L2s not mapped to any L3
1086
        List<RbmCallTargetModel> unmappedL2 = new ArrayList<>();
1229
        List<RbmCallTargetModel> unmappedL2 = new ArrayList<>();
1087
        for (RbmCallTargetModel l2Model : l2ModelsByAuthId.values()) {
1230
        for (RbmCallTargetModel l2Model : l2ModelsByAuthId.values()) {
1088
            if (!addedL2AuthIds.contains(l2Model.getAuthId())) {
1231
            if (!addedL2AuthIds.contains(l2Model.getAuthId())) {
1089
                unmappedL2.add(l2Model);
1232
                unmappedL2.add(l2Model);
1090
            }
1233
            }
1091
        }
1234
        }
1092
        unmappedL2.sort(Comparator.comparing(RbmCallTargetModel::getRbmName));
1235
        unmappedL2.sort(Comparator.comparing(RbmCallTargetModel::getRbmName));
1093
 
-
 
1094
        for (RbmCallTargetModel l2Model : unmappedL2) {
1236
        for (RbmCallTargetModel l2Model : unmappedL2) {
1095
            sortedModels.add(l2Model);
1237
            sortedModels.add(l2Model);
1096
            List<RbmCallTargetModel> team = l2TeamMap.getOrDefault(l2Model.getAuthId(), Collections.emptyList());
1238
            List<RbmCallTargetModel> team = l2TeamMap.getOrDefault(l2Model.getAuthId(), Collections.emptyList());
1097
            team.sort(Comparator.comparing(RbmCallTargetModel::getRbmName));
1239
            team.sort(Comparator.comparing(RbmCallTargetModel::getRbmName));
1098
            sortedModels.addAll(team);
1240
            sortedModels.addAll(team);
1099
        }
1241
        }
1100
 
1242
 
1101
        // Add any L1 RBMs not mapped to any L2 (sorted by name)
1243
        // Add any L1s not mapped to any L2 or L3
1102
        List<RbmCallTargetModel> unmappedL1 = new ArrayList<>();
1244
        List<RbmCallTargetModel> unmappedL1 = new ArrayList<>();
1103
        for (RbmCallTargetModel m : l1ModelsByAuthId.values()) {
1245
        for (RbmCallTargetModel m : l1ModelsByAuthId.values()) {
1104
            if (!addedL1AuthIds.contains(m.getAuthId())) {
1246
            if (!addedL1AuthIds.contains(m.getAuthId())) {
1105
                unmappedL1.add(m);
1247
                unmappedL1.add(m);
1106
            }
1248
            }