| Line 790... |
Line 790... |
| 790 |
Map<Integer, Long> twoMonthAgoRtoRefundOrderMap = orderRepository.selectAllRefundOrderDatesBetween(twoMonthsAgoStartDate, twoMonthsAgoEndDate)
|
790 |
Map<Integer, Long> twoMonthAgoRtoRefundOrderMap = orderRepository.selectAllRefundOrderDatesBetween(twoMonthsAgoStartDate, twoMonthsAgoEndDate)
|
| 791 |
.stream().collect(Collectors.groupingBy(Order::getRetailerId, Collectors.summingLong(x -> Math.round(x.getTotalAmount()))));
|
791 |
.stream().collect(Collectors.groupingBy(Order::getRetailerId, Collectors.summingLong(x -> Math.round(x.getTotalAmount()))));
|
| 792 |
|
792 |
|
| 793 |
// ---- Batch pre-fetch everything else that was previously per-fofo ----
|
793 |
// ---- Batch pre-fetch everything else that was previously per-fofo ----
|
| 794 |
|
794 |
|
| - |
|
795 |
// Auth hierarchy:
|
| - |
|
796 |
// RBM = TICKET_CATEGORY_RBM → L1, fallback L2
|
| - |
|
797 |
// BM = TICKET_CATEGORY_SALES → L4 (was L2)
|
| 795 |
// Auth hierarchy (BM / SalesManager / RBM L1+L2 fallback / ABM L1+L2+L3 fallback)
|
798 |
// Sales Manager = TICKET_CATEGORY_SALES → L1, fallback L2, then L3
|
| - |
|
799 |
// ABM = removed from report
|
| 796 |
Map<Integer, Integer> rbmL1Map = csService.getAuthUserIdsWithoutTicketAssigneeByFofoIds(ProfitMandiConstants.TICKET_CATEGORY_RBM, EscalationType.L1, retailerIdSet);
|
800 |
Map<Integer, Integer> rbmL1Map = csService.getAuthUserIdsWithoutTicketAssigneeByFofoIds(ProfitMandiConstants.TICKET_CATEGORY_RBM, EscalationType.L1, retailerIdSet);
|
| 797 |
Map<Integer, Integer> rbmL2Map = csService.getAuthUserIdsWithoutTicketAssigneeByFofoIds(ProfitMandiConstants.TICKET_CATEGORY_RBM, EscalationType.L2, retailerIdSet);
|
801 |
Map<Integer, Integer> rbmL2Map = csService.getAuthUserIdsWithoutTicketAssigneeByFofoIds(ProfitMandiConstants.TICKET_CATEGORY_RBM, EscalationType.L2, retailerIdSet);
|
| 798 |
Map<Integer, Integer> bmMap = csService.getAuthUserIdsWithoutTicketAssigneeByFofoIds(ProfitMandiConstants.TICKET_CATEGORY_SALES, EscalationType.L2, retailerIdSet);
|
802 |
Map<Integer, Integer> bmMap = csService.getAuthUserIdsWithoutTicketAssigneeByFofoIds(ProfitMandiConstants.TICKET_CATEGORY_SALES, EscalationType.L4, retailerIdSet);
|
| 799 |
Map<Integer, Integer> salesManagerMap = csService.getAuthUserIdsWithoutTicketAssigneeByFofoIds(ProfitMandiConstants.TICKET_CATEGORY_SALES, EscalationType.L1, retailerIdSet);
|
803 |
Map<Integer, Integer> salesManagerL1Map = csService.getAuthUserIdsWithoutTicketAssigneeByFofoIds(ProfitMandiConstants.TICKET_CATEGORY_SALES, EscalationType.L1, retailerIdSet);
|
| 800 |
Map<Integer, Integer> abmL1Map = csService.getAuthUserIdsWithoutTicketAssigneeByFofoIds(ProfitMandiConstants.TICKET_CATEGORY_ABM, EscalationType.L1, retailerIdSet);
|
- |
|
| 801 |
Map<Integer, Integer> abmL2Map = csService.getAuthUserIdsWithoutTicketAssigneeByFofoIds(ProfitMandiConstants.TICKET_CATEGORY_ABM, EscalationType.L2, retailerIdSet);
|
804 |
Map<Integer, Integer> salesManagerL2Map = csService.getAuthUserIdsWithoutTicketAssigneeByFofoIds(ProfitMandiConstants.TICKET_CATEGORY_SALES, EscalationType.L2, retailerIdSet);
|
| 802 |
Map<Integer, Integer> abmL3Map = csService.getAuthUserIdsWithoutTicketAssigneeByFofoIds(ProfitMandiConstants.TICKET_CATEGORY_ABM, EscalationType.L3, retailerIdSet);
|
805 |
Map<Integer, Integer> salesManagerL3Map = csService.getAuthUserIdsWithoutTicketAssigneeByFofoIds(ProfitMandiConstants.TICKET_CATEGORY_SALES, EscalationType.L3, retailerIdSet);
|
| 803 |
|
806 |
|
| 804 |
Set<Integer> allAuthUserIds = new HashSet<>();
|
807 |
Set<Integer> allAuthUserIds = new HashSet<>();
|
| 805 |
for (Map<Integer, Integer> m : Arrays.asList(rbmL1Map, rbmL2Map, bmMap, salesManagerMap, abmL1Map, abmL2Map, abmL3Map)) {
|
808 |
for (Map<Integer, Integer> m : Arrays.asList(rbmL1Map, rbmL2Map, bmMap, salesManagerL1Map, salesManagerL2Map, salesManagerL3Map)) {
|
| 806 |
m.values().stream().filter(v -> v != null && v != 0).forEach(allAuthUserIds::add);
|
809 |
m.values().stream().filter(v -> v != null && v != 0).forEach(allAuthUserIds::add);
|
| 807 |
}
|
810 |
}
|
| 808 |
Map<Integer, AuthUser> authUserMap = allAuthUserIds.isEmpty() ? new HashMap<>()
|
811 |
Map<Integer, AuthUser> authUserMap = allAuthUserIds.isEmpty() ? new HashMap<>()
|
| 809 |
: authRepository.selectByIds(new ArrayList<>(allAuthUserIds)).stream()
|
812 |
: authRepository.selectByIds(new ArrayList<>(allAuthUserIds)).stream()
|
| 810 |
.collect(Collectors.toMap(AuthUser::getId, u -> u, (a, b) -> a));
|
813 |
.collect(Collectors.toMap(AuthUser::getId, u -> u, (a, b) -> a));
|
| Line 950... |
Line 953... |
| 950 |
String bmName = "";
|
953 |
String bmName = "";
|
| 951 |
int bmId = bmMap.getOrDefault(fofoId, 0);
|
954 |
int bmId = bmMap.getOrDefault(fofoId, 0);
|
| 952 |
if (bmId != 0 && authUserMap.get(bmId) != null) {
|
955 |
if (bmId != 0 && authUserMap.get(bmId) != null) {
|
| 953 |
bmName = authUserMap.get(bmId).getFullName();
|
956 |
bmName = authUserMap.get(bmId).getFullName();
|
| 954 |
}
|
957 |
}
|
| 955 |
int managerId = salesManagerMap.getOrDefault(fofoId, 0);
|
- |
|
| 956 |
String managerName;
|
- |
|
| 957 |
if (managerId != 0 && authUserMap.get(managerId) != null) {
|
958 |
// Sales Manager: L1 → L2 → L3 fallback in SALES category
|
| 958 |
managerName = authUserMap.get(managerId).getFullName();
|
- |
|
| 959 |
} else {
|
- |
|
| 960 |
managerName = bmName;
|
- |
|
| 961 |
}
|
- |
|
| 962 |
String abmName = "";
|
959 |
String managerName = "";
|
| 963 |
int abmId = abmL1Map.getOrDefault(fofoId, 0);
|
960 |
int managerL1 = salesManagerL1Map.getOrDefault(fofoId, 0);
|
| 964 |
int abmL2Id = abmL2Map.getOrDefault(fofoId, 0);
|
961 |
int managerL2 = salesManagerL2Map.getOrDefault(fofoId, 0);
|
| 965 |
int abmL3Id = abmL3Map.getOrDefault(fofoId, 0);
|
962 |
int managerL3 = salesManagerL3Map.getOrDefault(fofoId, 0);
|
| 966 |
if (abmId != 0 && authUserMap.get(abmId) != null) {
|
963 |
if (managerL1 != 0 && authUserMap.get(managerL1) != null) {
|
| 967 |
abmName = authUserMap.get(abmId).getFullName();
|
964 |
managerName = authUserMap.get(managerL1).getFullName();
|
| 968 |
} else if (abmL2Id != 0 && authUserMap.get(abmL2Id) != null) {
|
965 |
} else if (managerL2 != 0 && authUserMap.get(managerL2) != null) {
|
| 969 |
abmName = authUserMap.get(abmL2Id).getFullName();
|
966 |
managerName = authUserMap.get(managerL2).getFullName();
|
| 970 |
} else if (abmL3Id != 0 && authUserMap.get(abmL3Id) != null) {
|
967 |
} else if (managerL3 != 0 && authUserMap.get(managerL3) != null) {
|
| 971 |
abmName = authUserMap.get(abmL3Id).getFullName();
|
968 |
managerName = authUserMap.get(managerL3).getFullName();
|
| 972 |
}
|
969 |
}
|
| 973 |
|
970 |
|
| 974 |
AST ast = astMap.get(customRetailers.get(fofoId).getAstId());
|
971 |
AST ast = astMap.get(customRetailers.get(fofoId).getAstId());
|
| 975 |
PartnerType partnerTypeThisMonth = partnerTypeMap.get(fofoId);
|
972 |
PartnerType partnerTypeThisMonth = partnerTypeMap.get(fofoId);
|
| 976 |
|
973 |
|
| Line 992... |
Line 989... |
| 992 |
biRetailerModel.setStoreName(customRetailers.get(fofoId).getBusinessName());
|
989 |
biRetailerModel.setStoreName(customRetailers.get(fofoId).getBusinessName());
|
| 993 |
biRetailerModel.setStatus(retailerStatus);
|
990 |
biRetailerModel.setStatus(retailerStatus);
|
| 994 |
biRetailerModel.setCategory(String.valueOf(partnerTypeThisMonth));
|
991 |
biRetailerModel.setCategory(String.valueOf(partnerTypeThisMonth));
|
| 995 |
biRetailerModel.setSalesManager(managerName);
|
992 |
biRetailerModel.setSalesManager(managerName);
|
| 996 |
biRetailerModel.setRbm(rbmName);
|
993 |
biRetailerModel.setRbm(rbmName);
|
| 997 |
biRetailerModel.setAbm(abmName);
|
- |
|
| 998 |
biRetailerModelMap.put(fofoId, biRetailerModel);
|
994 |
biRetailerModelMap.put(fofoId, biRetailerModel);
|
| 999 |
|
995 |
|
| 1000 |
Map<YearMonth, PartnerWiseActivatedNotBilledTotal> partnerWiseActivatedNotBilledTotalMap =
|
996 |
Map<YearMonth, PartnerWiseActivatedNotBilledTotal> partnerWiseActivatedNotBilledTotalMap =
|
| 1001 |
activatedNotBilledByFofo.getOrDefault(fofoId, new HashMap<>());
|
997 |
activatedNotBilledByFofo.getOrDefault(fofoId, new HashMap<>());
|
| 1002 |
|
998 |
|
| Line 1187... |
Line 1183... |
| 1187 |
|
1183 |
|
| 1188 |
);
|
1184 |
);
|
| 1189 |
|
1185 |
|
| 1190 |
List<String> headers2 = Arrays.asList(
|
1186 |
List<String> headers2 = Arrays.asList(
|
| 1191 |
"Assessment","Zero billing","Billing needed","Counta",
|
1187 |
"Assessment","Zero billing","Billing needed","Counta",
|
| 1192 |
"BM","Partner Id","Link","Wallet Date","Creation Date","Code","Area", "City", "Store Name", "Status","Category","Sales Manager", "RBM","ABM",
|
1188 |
"BM","Partner Id","Link","Wallet Date","Creation Date","Code","Area", "City", "Store Name", "Status","Category","Sales Manager", "RBM",
|
| 1193 |
"Secondary Target", "Secondary Achieved", "Returns", "Net Secondary", "Secondary %",
|
1189 |
"Secondary Target", "Secondary Achieved", "Returns", "Net Secondary", "Secondary %",
|
| 1194 |
"Tertiary Sale", "Unbilled",
|
1190 |
"Tertiary Sale", "Unbilled",
|
| 1195 |
"Secondary Target", "Secondary Achieved", "Returns", "Net Secondary", "Secondary %",
|
1191 |
"Secondary Target", "Secondary Achieved", "Returns", "Net Secondary", "Secondary %",
|
| 1196 |
"Tertiary Sale", "Unbilled",
|
1192 |
"Tertiary Sale", "Unbilled",
|
| 1197 |
"Secondary Target", "Secondary Achieved", "Returns", "Net Secondary", "Secondary %",
|
1193 |
"Secondary Target", "Secondary Achieved", "Returns", "Net Secondary", "Secondary %",
|
| Line 1244... |
Line 1240... |
| 1244 |
retailer.getCity(),
|
1240 |
retailer.getCity(),
|
| 1245 |
retailer.getStoreName(),
|
1241 |
retailer.getStoreName(),
|
| 1246 |
retailer.getStatus(),
|
1242 |
retailer.getStatus(),
|
| 1247 |
retailer.getCategory(),
|
1243 |
retailer.getCategory(),
|
| 1248 |
retailer.getSalesManager(),
|
1244 |
retailer.getSalesManager(),
|
| 1249 |
retailer.getRbm(),
|
1245 |
retailer.getRbm()
|
| 1250 |
retailer.getAbm()
|
- |
|
| 1251 |
|
1246 |
|
| 1252 |
));
|
1247 |
));
|
| 1253 |
|
1248 |
|
| 1254 |
|
1249 |
|
| 1255 |
// Two Months Ago
|
1250 |
// Two Months Ago
|