| Line 295... |
Line 295... |
| 295 |
}
|
295 |
}
|
| 296 |
|
296 |
|
| 297 |
if (ticket.getSubCategoryId() != ticketSubCategory.getId()) {
|
297 |
if (ticket.getSubCategoryId() != ticketSubCategory.getId()) {
|
| 298 |
ticket.setSubCategoryId(ticketSubCategory.getId());
|
298 |
ticket.setSubCategoryId(ticketSubCategory.getId());
|
| 299 |
List<Integer> oldAssignedAuthUserIds = oldTicketAssignedList.stream().map(x -> x.getAssineeId()).collect(Collectors.toList());
|
299 |
List<Integer> oldAssignedAuthUserIds = oldTicketAssignedList.stream().map(x -> x.getAssineeId()).collect(Collectors.toList());
|
| 300 |
List<String> oldAssignedEmailIds = authRepository.selectAllAuthUserByIds(oldAssignedAuthUserIds).stream().map(x -> x.getEmailId()).collect(Collectors.toList());
|
300 |
List<String> oldAssignedEmailIds = authRepository.selectByIds(oldAssignedAuthUserIds).stream().map(x -> x.getEmailId()).collect(Collectors.toList());
|
| 301 |
String mailTo = oldAssignedEmailIds.remove(0);
|
301 |
String mailTo = oldAssignedEmailIds.remove(0);
|
| 302 |
String message = String.format(CATEGORY_CHANGED_TICKET, ticket.getId(), storeName, ticketSubCategory.getTicketCategory().getName() + " - " + ticketSubCategory.getName());
|
302 |
String message = String.format(CATEGORY_CHANGED_TICKET, ticket.getId(), storeName, ticketSubCategory.getTicketCategory().getName() + " - " + ticketSubCategory.getName());
|
| 303 |
try {
|
303 |
try {
|
| 304 |
Utils.sendMailWithAttachments(mailSender, mailTo, oldAssignedEmailIds.toArray(new String[0]), "Ticket Category/Subcategory Changed", message, null);
|
304 |
Utils.sendMailWithAttachments(mailSender, mailTo, oldAssignedEmailIds.toArray(new String[0]), "Ticket Category/Subcategory Changed", message, null);
|
| 305 |
} catch (Exception e) {
|
305 |
} catch (Exception e) {
|
| Line 425... |
Line 425... |
| 425 |
List<Position> positionAssignee = positions.stream().filter(x -> x.isTicketAssignee() && partnerPositionsIds.contains(x.getId())).collect(Collectors.toList());
|
425 |
List<Position> positionAssignee = positions.stream().filter(x -> x.isTicketAssignee() && partnerPositionsIds.contains(x.getId())).collect(Collectors.toList());
|
| 426 |
LOGGER.info("User List List {}", positions.stream().map(x -> x.getAuthUserId()).collect(Collectors.toList()));
|
426 |
LOGGER.info("User List List {}", positions.stream().map(x -> x.getAuthUserId()).collect(Collectors.toList()));
|
| 427 |
LOGGER.info("positionAssignee List {}", positionAssignee);
|
427 |
LOGGER.info("positionAssignee List {}", positionAssignee);
|
| 428 |
if (positionAssignee.size() > 0) {
|
428 |
if (positionAssignee.size() > 0) {
|
| 429 |
|
429 |
|
| 430 |
List<AuthUser> authUsers = authRepository.selectAllAuthUserByIds(
|
430 |
List<AuthUser> authUsers = authRepository.selectByIds(
|
| 431 |
positionAssignee.stream().map(x -> x.getAuthUserId()).collect(Collectors.toList()));
|
431 |
positionAssignee.stream().map(x -> x.getAuthUserId()).collect(Collectors.toList()));
|
| 432 |
authUsers = authUsers.stream().filter(x -> x.isActive()).collect(Collectors.toList());
|
432 |
authUsers = authUsers.stream().filter(x -> x.isActive()).collect(Collectors.toList());
|
| 433 |
LOGGER.info("Auth User List {}", authUsers);
|
433 |
LOGGER.info("Auth User List {}", authUsers);
|
| 434 |
if (authUsers.size() > 0) {
|
434 |
if (authUsers.size() > 0) {
|
| 435 |
authUserId = authUsers.get(0).getId();
|
435 |
authUserId = authUsers.get(0).getId();
|
| Line 456... |
Line 456... |
| 456 |
List<Position> positionAssignee = positions.stream().filter(x -> partnerPositionsIds.contains(x.getId())).collect(Collectors.toList());
|
456 |
List<Position> positionAssignee = positions.stream().filter(x -> partnerPositionsIds.contains(x.getId())).collect(Collectors.toList());
|
| 457 |
LOGGER.info("User List List {}", positions.stream().map(x -> x.getAuthUserId()).collect(Collectors.toList()));
|
457 |
LOGGER.info("User List List {}", positions.stream().map(x -> x.getAuthUserId()).collect(Collectors.toList()));
|
| 458 |
LOGGER.info("positionAssignee List {}", positionAssignee);
|
458 |
LOGGER.info("positionAssignee List {}", positionAssignee);
|
| 459 |
if (positionAssignee.size() > 0) {
|
459 |
if (positionAssignee.size() > 0) {
|
| 460 |
|
460 |
|
| 461 |
List<AuthUser> authUsers = authRepository.selectAllAuthUserByIds(
|
461 |
List<AuthUser> authUsers = authRepository.selectByIds(
|
| 462 |
positionAssignee.stream().map(x -> x.getAuthUserId()).collect(Collectors.toList()));
|
462 |
positionAssignee.stream().map(x -> x.getAuthUserId()).collect(Collectors.toList()));
|
| 463 |
authUsers = authUsers.stream().filter(x -> x.isActive()).collect(Collectors.toList());
|
463 |
authUsers = authUsers.stream().filter(x -> x.isActive()).collect(Collectors.toList());
|
| 464 |
LOGGER.info("Auth User List {}", authUsers);
|
464 |
LOGGER.info("Auth User List {}", authUsers);
|
| 465 |
if (authUsers.size() > 0) {
|
465 |
if (authUsers.size() > 0) {
|
| 466 |
authUserId = authUsers.get(0).getId();
|
466 |
authUserId = authUsers.get(0).getId();
|
| Line 786... |
Line 786... |
| 786 |
|
786 |
|
| 787 |
List<Integer> partnerPositionIds = partnerPositionRepository.selectByRegionIdAndPartnerId(regionIds, Arrays.asList(fofoId, 0)).stream().map(x -> x.getPositionId()).collect(Collectors.toList());
|
787 |
List<Integer> partnerPositionIds = partnerPositionRepository.selectByRegionIdAndPartnerId(regionIds, Arrays.asList(fofoId, 0)).stream().map(x -> x.getPositionId()).collect(Collectors.toList());
|
| 788 |
|
788 |
|
| 789 |
LOGGER.info("partnerPositionIds" + partnerPositionIds);
|
789 |
LOGGER.info("partnerPositionIds" + partnerPositionIds);
|
| 790 |
|
790 |
|
| 791 |
List<Position> positions = positionRepository.selectAll(partnerPositionIds);
|
791 |
List<Position> positions = positionRepository.selectByIds(partnerPositionIds);
|
| 792 |
|
792 |
|
| 793 |
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());
|
793 |
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());
|
| 794 |
|
794 |
|
| 795 |
if (!positions.isEmpty()) {
|
795 |
if (!positions.isEmpty()) {
|
| 796 |
for (Position partnerPostionId : positions) {
|
796 |
for (Position partnerPostionId : positions) {
|
| Line 910... |
Line 910... |
| 910 |
if (tickets.size() == 0) {
|
910 |
if (tickets.size() == 0) {
|
| 911 |
return new HashMap<>();
|
911 |
return new HashMap<>();
|
| 912 |
}
|
912 |
}
|
| 913 |
List<TicketAssigned> ticketAssignedList = ticketAssignedRepository.selectByTicketIds(tickets.stream().map(x -> x.getId()).collect(Collectors.toList()));
|
913 |
List<TicketAssigned> ticketAssignedList = ticketAssignedRepository.selectByTicketIds(tickets.stream().map(x -> x.getId()).collect(Collectors.toList()));
|
| 914 |
List<Integer> authUserIds = ticketAssignedList.stream().map(x -> x.getAssineeId()).distinct().collect(Collectors.toList());
|
914 |
List<Integer> authUserIds = ticketAssignedList.stream().map(x -> x.getAssineeId()).distinct().collect(Collectors.toList());
|
| 915 |
Map<Integer, AuthUser> authUserMap = authRepository.selectAllAuthUserByIds(authUserIds).stream().collect(Collectors.toMap(x -> x.getId(), x -> x));
|
915 |
Map<Integer, AuthUser> authUserMap = authRepository.selectByIds(authUserIds).stream().collect(Collectors.toMap(x -> x.getId(), x -> x));
|
| 916 |
return ticketAssignedList.stream().collect(Collectors.groupingBy(x -> x.getTicketId(), Collectors.mapping(x -> authUserMap.get(x.getAssineeId()), Collectors.toList())));
|
916 |
return ticketAssignedList.stream().collect(Collectors.groupingBy(x -> x.getTicketId(), Collectors.mapping(x -> authUserMap.get(x.getAssineeId()), Collectors.toList())));
|
| 917 |
}
|
917 |
}
|
| 918 |
|
918 |
|
| 919 |
@Override
|
919 |
@Override
|
| 920 |
public Map<EscalationType, AuthUser> getAuthUserAndEsclationByPartnerId(int fofoId) throws ProfitMandiBusinessException {
|
920 |
public Map<EscalationType, AuthUser> getAuthUserAndEsclationByPartnerId(int fofoId) throws ProfitMandiBusinessException {
|
| Line 947... |
Line 947... |
| 947 |
|
947 |
|
| 948 |
return authuserEsclationTypeMap;
|
948 |
return authuserEsclationTypeMap;
|
| 949 |
}
|
949 |
}
|
| 950 |
|
950 |
|
| 951 |
@Override
|
951 |
@Override
|
| - |
|
952 |
public Map<Integer, Map<EscalationType, AuthUser>> getAuthUserAndEsclationByPartnerIds(Set<Integer> fofoIds) throws ProfitMandiBusinessException {
|
| - |
|
953 |
Map<Integer, Map<EscalationType, AuthUser>> result = new HashMap<>();
|
| - |
|
954 |
|
| - |
|
955 |
if (fofoIds == null || fofoIds.isEmpty()) {
|
| - |
|
956 |
return result;
|
| - |
|
957 |
}
|
| - |
|
958 |
|
| - |
|
959 |
// Initialize result map
|
| - |
|
960 |
for (Integer fofoId : fofoIds) {
|
| - |
|
961 |
result.put(fofoId, new HashMap<>());
|
| - |
|
962 |
}
|
| - |
|
963 |
|
| - |
|
964 |
// Batch fetch all partner regions
|
| - |
|
965 |
List<Integer> fofoIdListWithZero = new ArrayList<>(fofoIds);
|
| - |
|
966 |
fofoIdListWithZero.add(0);
|
| - |
|
967 |
List<PartnerRegion> allPartnerRegions = partnerRegionRepository.selectByfofoIds(fofoIdListWithZero);
|
| - |
|
968 |
|
| - |
|
969 |
// Build fofoId -> regionIds map
|
| - |
|
970 |
Map<Integer, Set<Integer>> fofoRegionMap = new HashMap<>();
|
| - |
|
971 |
for (Integer fofoId : fofoIds) {
|
| - |
|
972 |
fofoRegionMap.put(fofoId, new HashSet<>());
|
| - |
|
973 |
fofoRegionMap.get(fofoId).add(ALL_PARTNERS_REGION);
|
| - |
|
974 |
}
|
| - |
|
975 |
for (PartnerRegion pr : allPartnerRegions) {
|
| - |
|
976 |
int prFofoId = pr.getFofoId();
|
| - |
|
977 |
if (prFofoId == 0) {
|
| - |
|
978 |
for (Integer fid : fofoIds) {
|
| - |
|
979 |
fofoRegionMap.get(fid).add(pr.getRegionId());
|
| - |
|
980 |
}
|
| - |
|
981 |
} else if (fofoIds.contains(prFofoId)) {
|
| - |
|
982 |
fofoRegionMap.get(prFofoId).add(pr.getRegionId());
|
| - |
|
983 |
}
|
| - |
|
984 |
}
|
| - |
|
985 |
|
| - |
|
986 |
// Collect all region IDs
|
| - |
|
987 |
Set<Integer> allRegionIds = fofoRegionMap.values().stream()
|
| - |
|
988 |
.flatMap(Set::stream).collect(Collectors.toSet());
|
| - |
|
989 |
|
| - |
|
990 |
// Batch fetch all partner positions
|
| - |
|
991 |
List<PartnerPosition> allPartnerPositions = partnerPositionRepository.selectByRegionIdAndPartnerId(
|
| - |
|
992 |
new ArrayList<>(allRegionIds), fofoIdListWithZero);
|
| - |
|
993 |
|
| - |
|
994 |
// Collect all position IDs
|
| - |
|
995 |
Set<Integer> allPositionIds = allPartnerPositions.stream()
|
| - |
|
996 |
.map(PartnerPosition::getPositionId).collect(Collectors.toSet());
|
| - |
|
997 |
|
| - |
|
998 |
// Batch fetch all positions for SALES category
|
| - |
|
999 |
List<Position> salesPositions = positionRepository.selectPositionbyCategoryIdAndEscalationType(
|
| - |
|
1000 |
ProfitMandiConstants.TICKET_CATEGORY_SALES, null);
|
| - |
|
1001 |
Map<Integer, Position> positionMap = salesPositions.stream()
|
| - |
|
1002 |
.filter(p -> allPositionIds.contains(p.getId()))
|
| - |
|
1003 |
.collect(Collectors.toMap(Position::getId, p -> p, (a, b) -> a));
|
| - |
|
1004 |
|
| - |
|
1005 |
// Collect all auth user IDs and batch fetch
|
| - |
|
1006 |
Set<Integer> authUserIds = positionMap.values().stream()
|
| - |
|
1007 |
.map(Position::getAuthUserId).collect(Collectors.toSet());
|
| - |
|
1008 |
Map<Integer, AuthUser> authUserMap = authRepository.selectByIds(new ArrayList<>(authUserIds))
|
| - |
|
1009 |
.stream().collect(Collectors.toMap(AuthUser::getId, au -> au, (a, b) -> a));
|
| - |
|
1010 |
|
| - |
|
1011 |
// For each fofoId, find matching positions and build result
|
| - |
|
1012 |
for (Integer fofoId : fofoIds) {
|
| - |
|
1013 |
Set<Integer> regionIds = fofoRegionMap.get(fofoId);
|
| - |
|
1014 |
Map<EscalationType, AuthUser> escalationMap = result.get(fofoId);
|
| - |
|
1015 |
|
| - |
|
1016 |
for (PartnerPosition pp : allPartnerPositions) {
|
| - |
|
1017 |
if (regionIds.contains(pp.getRegionId()) &&
|
| - |
|
1018 |
(pp.getFofoId() == 0 || pp.getFofoId() == fofoId)) {
|
| - |
|
1019 |
Position position = positionMap.get(pp.getPositionId());
|
| - |
|
1020 |
if (position != null) {
|
| - |
|
1021 |
AuthUser authUser = authUserMap.get(position.getAuthUserId());
|
| - |
|
1022 |
if (authUser != null) {
|
| - |
|
1023 |
escalationMap.put(position.getEscalationType(), authUser);
|
| - |
|
1024 |
}
|
| - |
|
1025 |
}
|
| - |
|
1026 |
}
|
| - |
|
1027 |
}
|
| - |
|
1028 |
}
|
| - |
|
1029 |
|
| - |
|
1030 |
return result;
|
| - |
|
1031 |
}
|
| - |
|
1032 |
|
| - |
|
1033 |
@Override
|
| 952 |
public List<AuthUser> getAuthUserIdByPartnerId(int fofoId) throws ProfitMandiBusinessException {
|
1034 |
public List<AuthUser> getAuthUserIdByPartnerId(int fofoId) throws ProfitMandiBusinessException {
|
| 953 |
return this.getAuthUserIdByPartnerId(fofoId, EscalationType.escalations.toArray(new EscalationType[0]));
|
1035 |
return this.getAuthUserIdByPartnerId(fofoId, EscalationType.escalations.toArray(new EscalationType[0]));
|
| 954 |
}
|
1036 |
}
|
| 955 |
|
1037 |
|
| 956 |
@Override
|
1038 |
@Override
|
| Line 968... |
Line 1050... |
| 968 |
|
1050 |
|
| 969 |
//LOGGER.info("partnerPositionIds" + partnerPositionIds);
|
1051 |
//LOGGER.info("partnerPositionIds" + partnerPositionIds);
|
| 970 |
List<Integer> allowedTicketCategoryIds = Arrays.asList(ProfitMandiConstants.TICKET_CATEGORY_SALES, ProfitMandiConstants.TICKET_CATEGORY_RBM,ProfitMandiConstants.TICKET_CATEGORY_ABM);
|
1052 |
List<Integer> allowedTicketCategoryIds = Arrays.asList(ProfitMandiConstants.TICKET_CATEGORY_SALES, ProfitMandiConstants.TICKET_CATEGORY_RBM,ProfitMandiConstants.TICKET_CATEGORY_ABM);
|
| 971 |
|
1053 |
|
| 972 |
|
1054 |
|
| 973 |
List<Position> escalationBasedPositions = positionRepository.selectAll(partnerPositionIds).stream().filter(x -> allowedTicketCategoryIds.contains(x.getCategoryId()) &&
|
1055 |
List<Position> escalationBasedPositions = positionRepository.selectByIds(partnerPositionIds).stream().filter(x -> allowedTicketCategoryIds.contains(x.getCategoryId()) &&
|
| 974 |
Arrays.stream(escalationTypes)
|
1056 |
Arrays.stream(escalationTypes)
|
| 975 |
.anyMatch(y -> y.equals(x.getEscalationType()))).collect(Collectors.toList());
|
1057 |
.anyMatch(y -> y.equals(x.getEscalationType()))).collect(Collectors.toList());
|
| 976 |
|
1058 |
|
| 977 |
List<Integer> authUserIds = escalationBasedPositions.stream().map(x -> x.getAuthUserId()).collect(Collectors.toList());
|
1059 |
List<Integer> authUserIds = escalationBasedPositions.stream().map(x -> x.getAuthUserId()).collect(Collectors.toList());
|
| 978 |
|
1060 |
|
| 979 |
return authRepository.selectAllAuthUserByIds(authUserIds);
|
1061 |
return authRepository.selectByIds(authUserIds);
|
| 980 |
|
1062 |
|
| 981 |
}
|
1063 |
}
|
| 982 |
|
1064 |
|
| 983 |
@Override
|
1065 |
@Override
|
| 984 |
public List<AuthUser> getAuthUserIds(int categoryId, List<EscalationType> escalationType) {
|
1066 |
public List<AuthUser> getAuthUserIds(int categoryId, List<EscalationType> escalationType) {
|
| Line 987... |
Line 1069... |
| 987 |
List<Integer> authIds = positions.stream().map(x -> x.getAuthUserId()).distinct().collect(Collectors.toList());
|
1069 |
List<Integer> authIds = positions.stream().map(x -> x.getAuthUserId()).distinct().collect(Collectors.toList());
|
| 988 |
|
1070 |
|
| 989 |
//LOGGER.info("authIds" + authIds);
|
1071 |
//LOGGER.info("authIds" + authIds);
|
| 990 |
List<AuthUser> authUsers = null;
|
1072 |
List<AuthUser> authUsers = null;
|
| 991 |
if (authIds.size() > 0) {
|
1073 |
if (authIds.size() > 0) {
|
| 992 |
authUsers = authRepository.selectAllAuthUserByIds(authIds);
|
1074 |
authUsers = authRepository.selectByIds(authIds);
|
| 993 |
} else {
|
1075 |
} else {
|
| 994 |
authUsers = new ArrayList<>();
|
1076 |
authUsers = new ArrayList<>();
|
| 995 |
}
|
1077 |
}
|
| 996 |
|
1078 |
|
| 997 |
LOGGER.info("authUsers" + authUsers);
|
1079 |
LOGGER.info("authUsers" + authUsers);
|
| Line 1005... |
Line 1087... |
| 1005 |
List<Integer> authIds = positions.stream().map(x -> x.getAuthUserId()).distinct().collect(Collectors.toList());
|
1087 |
List<Integer> authIds = positions.stream().map(x -> x.getAuthUserId()).distinct().collect(Collectors.toList());
|
| 1006 |
|
1088 |
|
| 1007 |
LOGGER.info("authIds" + authIds);
|
1089 |
LOGGER.info("authIds" + authIds);
|
| 1008 |
List<AuthUser> authUsers = new ArrayList<>();
|
1090 |
List<AuthUser> authUsers = new ArrayList<>();
|
| 1009 |
if (!authIds.isEmpty()) {
|
1091 |
if (!authIds.isEmpty()) {
|
| 1010 |
authUsers = authRepository.selectAllAuthUserByIds(authIds);
|
1092 |
authUsers = authRepository.selectByIds(authIds);
|
| 1011 |
}
|
1093 |
}
|
| 1012 |
|
1094 |
|
| 1013 |
LOGGER.info("authUsers" + authUsers);
|
1095 |
LOGGER.info("authUsers" + authUsers);
|
| 1014 |
return authUsers;
|
1096 |
return authUsers;
|
| 1015 |
}
|
1097 |
}
|
| Line 1020... |
Line 1102... |
| 1020 |
List<Position> positions = positionRepository.selectPositionByCategoryId(categoryId);
|
1102 |
List<Position> positions = positionRepository.selectPositionByCategoryId(categoryId);
|
| 1021 |
List<Integer> authIds = positions.stream().map(x -> x.getAuthUserId()).distinct().collect(Collectors.toList());
|
1103 |
List<Integer> authIds = positions.stream().map(x -> x.getAuthUserId()).distinct().collect(Collectors.toList());
|
| 1022 |
|
1104 |
|
| 1023 |
LOGGER.info("authIds" + authIds);
|
1105 |
LOGGER.info("authIds" + authIds);
|
| 1024 |
|
1106 |
|
| 1025 |
List<AuthUser> authUsers = authRepository.selectAllAuthUserByIds(authIds).stream().filter(x -> x.getActive()).collect(Collectors.toList());
|
1107 |
List<AuthUser> authUsers = authRepository.selectByIds(authIds).stream().filter(x -> x.getActive()).collect(Collectors.toList());
|
| 1026 |
|
1108 |
|
| 1027 |
LOGGER.info("authUsers" + authUsers);
|
1109 |
LOGGER.info("authUsers" + authUsers);
|
| 1028 |
return authUsers;
|
1110 |
return authUsers;
|
| 1029 |
}
|
1111 |
}
|
| 1030 |
|
1112 |
|
| Line 1364... |
Line 1446... |
| 1364 |
|
1446 |
|
| 1365 |
}
|
1447 |
}
|
| 1366 |
return subCategoryIdAndCategoryMap;
|
1448 |
return subCategoryIdAndCategoryMap;
|
| 1367 |
}
|
1449 |
}
|
| 1368 |
|
1450 |
|
| - |
|
1451 |
@Override
|
| - |
|
1452 |
public Map<Integer, Map<String, Integer>> getBmAsmRbmAuthUserIdsByFofoIds(Set<Integer> fofoIds) throws ProfitMandiBusinessException {
|
| - |
|
1453 |
Map<Integer, Map<String, Integer>> result = new HashMap<>();
|
| - |
|
1454 |
|
| - |
|
1455 |
if (fofoIds == null || fofoIds.isEmpty()) {
|
| - |
|
1456 |
return result;
|
| - |
|
1457 |
}
|
| - |
|
1458 |
|
| - |
|
1459 |
// Initialize result map with empty values for each fofoId
|
| - |
|
1460 |
for (Integer fofoId : fofoIds) {
|
| - |
|
1461 |
Map<String, Integer> roleMap = new HashMap<>();
|
| - |
|
1462 |
roleMap.put("BM", 0);
|
| - |
|
1463 |
roleMap.put("ASM", 0);
|
| - |
|
1464 |
roleMap.put("RBM", 0);
|
| - |
|
1465 |
result.put(fofoId, roleMap);
|
| - |
|
1466 |
}
|
| - |
|
1467 |
|
| - |
|
1468 |
// Fetch positions by category + escalation type (same for all fofoIds)
|
| - |
|
1469 |
List<Position> bmPositions = positionRepository.selectPositionbyCategoryIdAndEscalationType(
|
| - |
|
1470 |
ProfitMandiConstants.TICKET_CATEGORY_SALES, EscalationType.L2);
|
| - |
|
1471 |
List<Position> asmPositions = positionRepository.selectPositionbyCategoryIdAndEscalationType(
|
| - |
|
1472 |
ProfitMandiConstants.TICKET_CATEGORY_SALES, EscalationType.L1);
|
| - |
|
1473 |
List<Position> rbmPositions = positionRepository.selectPositionbyCategoryIdAndEscalationType(
|
| - |
|
1474 |
ProfitMandiConstants.TICKET_CATEGORY_RBM, EscalationType.L1);
|
| - |
|
1475 |
|
| - |
|
1476 |
// Batch fetch all partner regions for all fofoIds
|
| - |
|
1477 |
List<Integer> fofoIdList = new ArrayList<>(fofoIds);
|
| - |
|
1478 |
fofoIdList.add(0); // Include global entries
|
| - |
|
1479 |
List<PartnerRegion> allPartnerRegions = partnerRegionRepository.selectByfofoIds(fofoIdList);
|
| - |
|
1480 |
|
| - |
|
1481 |
// Build fofoId -> regionIds map
|
| - |
|
1482 |
Map<Integer, Set<Integer>> fofoRegionMap = new HashMap<>();
|
| - |
|
1483 |
for (Integer fofoId : fofoIds) {
|
| - |
|
1484 |
fofoRegionMap.put(fofoId, new HashSet<>());
|
| - |
|
1485 |
fofoRegionMap.get(fofoId).add(ALL_PARTNERS_REGION); // Add all partners region
|
| - |
|
1486 |
}
|
| - |
|
1487 |
for (PartnerRegion pr : allPartnerRegions) {
|
| - |
|
1488 |
int fofoId = pr.getFofoId();
|
| - |
|
1489 |
if (fofoId == 0) {
|
| - |
|
1490 |
// Global entry applies to all fofoIds
|
| - |
|
1491 |
for (Integer fid : fofoIds) {
|
| - |
|
1492 |
fofoRegionMap.get(fid).add(pr.getRegionId());
|
| - |
|
1493 |
}
|
| - |
|
1494 |
} else if (fofoIds.contains(fofoId)) {
|
| - |
|
1495 |
fofoRegionMap.get(fofoId).add(pr.getRegionId());
|
| - |
|
1496 |
}
|
| - |
|
1497 |
}
|
| - |
|
1498 |
|
| - |
|
1499 |
// Collect all unique region IDs and position IDs for batch query
|
| - |
|
1500 |
Set<Integer> allRegionIds = fofoRegionMap.values().stream()
|
| - |
|
1501 |
.flatMap(Set::stream).collect(Collectors.toSet());
|
| - |
|
1502 |
Set<Integer> allPositionIds = new HashSet<>();
|
| - |
|
1503 |
bmPositions.forEach(p -> allPositionIds.add(p.getId()));
|
| - |
|
1504 |
asmPositions.forEach(p -> allPositionIds.add(p.getId()));
|
| - |
|
1505 |
rbmPositions.forEach(p -> allPositionIds.add(p.getId()));
|
| - |
|
1506 |
|
| - |
|
1507 |
// Batch fetch all partner positions
|
| - |
|
1508 |
List<PartnerPosition> allPartnerPositions = partnerPositionRepository.selectByRegionIdAndPostionId(
|
| - |
|
1509 |
new ArrayList<>(allRegionIds), new ArrayList<>(allPositionIds));
|
| - |
|
1510 |
|
| - |
|
1511 |
// Build positionId -> set of (regionId, partnerId) for matching
|
| - |
|
1512 |
Map<Integer, List<PartnerPosition>> positionIdToPartnerPositions = allPartnerPositions.stream()
|
| - |
|
1513 |
.collect(Collectors.groupingBy(PartnerPosition::getPositionId));
|
| - |
|
1514 |
|
| - |
|
1515 |
// Collect all auth user IDs we need
|
| - |
|
1516 |
Set<Integer> allAuthUserIds = new HashSet<>();
|
| - |
|
1517 |
bmPositions.forEach(p -> allAuthUserIds.add(p.getAuthUserId()));
|
| - |
|
1518 |
asmPositions.forEach(p -> allAuthUserIds.add(p.getAuthUserId()));
|
| - |
|
1519 |
rbmPositions.forEach(p -> allAuthUserIds.add(p.getAuthUserId()));
|
| - |
|
1520 |
|
| - |
|
1521 |
// Batch fetch all auth users
|
| - |
|
1522 |
Map<Integer, AuthUser> authUserMap = authRepository.selectByIds(new ArrayList<>(allAuthUserIds))
|
| - |
|
1523 |
.stream().filter(AuthUser::isActive)
|
| - |
|
1524 |
.collect(Collectors.toMap(AuthUser::getId, au -> au, (a, b) -> a));
|
| - |
|
1525 |
|
| - |
|
1526 |
// Build position ID sets for fast lookup
|
| - |
|
1527 |
Set<Integer> bmPositionIds = bmPositions.stream().map(Position::getId).collect(Collectors.toSet());
|
| - |
|
1528 |
Set<Integer> asmPositionIds = asmPositions.stream().map(Position::getId).collect(Collectors.toSet());
|
| - |
|
1529 |
Set<Integer> rbmPositionIds = rbmPositions.stream().map(Position::getId).collect(Collectors.toSet());
|
| - |
|
1530 |
|
| - |
|
1531 |
// Map position ID to auth user ID
|
| - |
|
1532 |
Map<Integer, Integer> positionToAuthUser = new HashMap<>();
|
| - |
|
1533 |
bmPositions.forEach(p -> positionToAuthUser.put(p.getId(), p.getAuthUserId()));
|
| - |
|
1534 |
asmPositions.forEach(p -> positionToAuthUser.put(p.getId(), p.getAuthUserId()));
|
| - |
|
1535 |
rbmPositions.forEach(p -> positionToAuthUser.put(p.getId(), p.getAuthUserId()));
|
| - |
|
1536 |
|
| - |
|
1537 |
// For each fofoId, find matching positions
|
| - |
|
1538 |
for (Integer fofoId : fofoIds) {
|
| - |
|
1539 |
Set<Integer> regionIds = fofoRegionMap.get(fofoId);
|
| - |
|
1540 |
|
| - |
|
1541 |
// Find position IDs that match this fofoId's regions (partnerId = 0 or fofoId)
|
| - |
|
1542 |
Set<Integer> matchingPositionIds = new HashSet<>();
|
| - |
|
1543 |
for (PartnerPosition pp : allPartnerPositions) {
|
| - |
|
1544 |
if (regionIds.contains(pp.getRegionId()) &&
|
| - |
|
1545 |
(pp.getFofoId() == 0 || pp.getFofoId() == fofoId)) {
|
| - |
|
1546 |
matchingPositionIds.add(pp.getPositionId());
|
| - |
|
1547 |
}
|
| - |
|
1548 |
}
|
| - |
|
1549 |
|
| - |
|
1550 |
// Find first active auth user for each role
|
| - |
|
1551 |
Map<String, Integer> roleMap = result.get(fofoId);
|
| - |
|
1552 |
|
| - |
|
1553 |
for (Integer positionId : matchingPositionIds) {
|
| - |
|
1554 |
Integer authUserId = positionToAuthUser.get(positionId);
|
| - |
|
1555 |
if (authUserId != null && authUserMap.containsKey(authUserId)) {
|
| - |
|
1556 |
if (bmPositionIds.contains(positionId) && roleMap.get("BM") == 0) {
|
| - |
|
1557 |
roleMap.put("BM", authUserId);
|
| - |
|
1558 |
} else if (asmPositionIds.contains(positionId) && roleMap.get("ASM") == 0) {
|
| - |
|
1559 |
roleMap.put("ASM", authUserId);
|
| - |
|
1560 |
} else if (rbmPositionIds.contains(positionId) && roleMap.get("RBM") == 0) {
|
| - |
|
1561 |
roleMap.put("RBM", authUserId);
|
| - |
|
1562 |
}
|
| - |
|
1563 |
}
|
| - |
|
1564 |
}
|
| - |
|
1565 |
}
|
| - |
|
1566 |
|
| - |
|
1567 |
return result;
|
| - |
|
1568 |
}
|
| - |
|
1569 |
|
| 1369 |
}
|
1570 |
}
|