| Line 561... |
Line 561... |
| 561 |
|
561 |
|
| 562 |
LOGGER.info("chartMap" + gson.toJson(cm));
|
562 |
LOGGER.info("chartMap" + gson.toJson(cm));
|
| 563 |
model.addAttribute("chartMap", gson.toJson(cm));
|
563 |
model.addAttribute("chartMap", gson.toJson(cm));
|
| 564 |
|
564 |
|
| 565 |
List<CreateOfferRequest> createOffers = offerService.getPublishedOffers(loginDetails.getFofoId(), YearMonth.from(LocalDateTime.now()));
|
565 |
List<CreateOfferRequest> createOffers = offerService.getPublishedOffers(loginDetails.getFofoId(), YearMonth.from(LocalDateTime.now()));
|
| 566 |
List<CreateOfferRequest> publishedOffers = null;
|
- |
|
| 567 |
|
566 |
|
| - |
|
567 |
// Batch fetch all catalog IDs to avoid N+1 queries
|
| 568 |
publishedOffers = createOffers.stream().filter(createOffer -> createOffer.getTargetSlabs().stream()
|
568 |
Set<Integer> allCatalogIds = createOffers.stream()
|
| 569 |
.map(x -> x.getItemCriteriaPayouts())
|
569 |
.flatMap(offer -> offer.getTargetSlabs().stream())
|
| 570 |
.flatMap(List::stream)
|
570 |
.flatMap(slab -> slab.getItemCriteriaPayouts().stream())
|
| 571 |
.map(ItemCriteriaPayout::getItemCriteria)
|
571 |
.map(ItemCriteriaPayout::getItemCriteria)
|
| 572 |
.map(ItemCriteria::getCatalogIds)
|
572 |
.flatMap(criteria -> criteria.getCatalogIds().stream())
|
| 573 |
.flatMap(List::stream)
|
573 |
.collect(Collectors.toSet());
|
| - |
|
574 |
|
| - |
|
575 |
final Map<Integer, String> catalogBrandMap = new HashMap<>();
|
| - |
|
576 |
if (!allCatalogIds.isEmpty()) {
|
| - |
|
577 |
try {
|
| 574 |
.noneMatch(catalogId -> catalogRepository.selectCatalogById(catalogId).getBrand().equals("Live Demo"))).collect(Collectors.toList());
|
578 |
catalogBrandMap.putAll(catalogRepository.selectAllByIds(new ArrayList<>(allCatalogIds)).stream()
|
| - |
|
579 |
.collect(Collectors.toMap(c -> c.getId(), c -> c.getBrand())));
|
| - |
|
580 |
} catch (ProfitMandiBusinessException e) {
|
| - |
|
581 |
LOGGER.error("Error fetching catalogs by IDs", e);
|
| - |
|
582 |
}
|
| - |
|
583 |
}
|
| - |
|
584 |
|
| - |
|
585 |
List<CreateOfferRequest> publishedOffers = createOffers.stream()
|
| - |
|
586 |
.filter(createOffer -> createOffer.getTargetSlabs().stream()
|
| - |
|
587 |
.flatMap(slab -> slab.getItemCriteriaPayouts().stream())
|
| - |
|
588 |
.map(ItemCriteriaPayout::getItemCriteria)
|
| - |
|
589 |
.flatMap(criteria -> criteria.getCatalogIds().stream())
|
| - |
|
590 |
.noneMatch(catalogId -> "Live Demo".equals(catalogBrandMap.get(catalogId))))
|
| - |
|
591 |
.collect(Collectors.toList());
|
| 575 |
|
592 |
|
| 576 |
model.addAttribute("publishedOffers", publishedOffers);
|
593 |
model.addAttribute("publishedOffers", publishedOffers);
|
| 577 |
model.addAttribute("investments", fofoUser.getInvestments(loginDetails.getFofoId()));
|
594 |
model.addAttribute("investments", fofoUser.getInvestments(loginDetails.getFofoId()));
|
| 578 |
model.addAttribute("isInvestmentOk", partnerInvestmentService.isInvestmentOk(loginDetails.getFofoId(), ProfitMandiConstants.MIN_INVESTMENT_PERCENTAGE, ProfitMandiConstants.CUTOFF_INVESTMENT));
|
595 |
model.addAttribute("isInvestmentOk", partnerInvestmentService.isInvestmentOk(loginDetails.getFofoId(), ProfitMandiConstants.MIN_INVESTMENT_PERCENTAGE, ProfitMandiConstants.CUTOFF_INVESTMENT));
|
| 579 |
|
596 |
|
| Line 1141... |
Line 1158... |
| 1141 |
|
1158 |
|
| 1142 |
LOGGER.info("params" + fofoId + brand + yearMonth);
|
1159 |
LOGGER.info("params" + fofoId + brand + yearMonth);
|
| 1143 |
|
1160 |
|
| 1144 |
List<ActivationItemDetailModel> activationItemDetails = schemeInOutRepository.selectBrandPendingActivationItemDetails(fofoId, brand, yearMonth);
|
1161 |
List<ActivationItemDetailModel> activationItemDetails = schemeInOutRepository.selectBrandPendingActivationItemDetails(fofoId, brand, yearMonth);
|
| 1145 |
|
1162 |
|
| - |
|
1163 |
if (!activationItemDetails.isEmpty()) {
|
| - |
|
1164 |
// Batch fetch to avoid N+1 queries
|
| 1146 |
for (ActivationItemDetailModel activationItemDetail : activationItemDetails) {
|
1165 |
List<Integer> inventoryItemIds = activationItemDetails.stream()
|
| 1147 |
|
- |
|
| 1148 |
List<FofoLineItem> flis = fofoLineItemRepository.selectByInventoryItemId(activationItemDetail.getInventoryItemId());
|
1166 |
.map(ActivationItemDetailModel::getInventoryItemId)
|
| 1149 |
|
- |
|
| 1150 |
LOGGER.info("flis" + flis);
|
1167 |
.collect(Collectors.toList());
|
| 1151 |
|
1168 |
|
| - |
|
1169 |
Map<Integer, List<FofoLineItem>> lineItemsByInventoryId;
|
| - |
|
1170 |
try {
|
| - |
|
1171 |
lineItemsByInventoryId = fofoLineItemRepository
|
| - |
|
1172 |
.selectByInventoryItemIds(inventoryItemIds).stream()
|
| 1152 |
int maxFofoOrderItemId = flis.stream().mapToInt(x -> x.getFofoOrderItemId()).max().orElseThrow(NoSuchElementException::new);
|
1173 |
.collect(Collectors.groupingBy(FofoLineItem::getInventoryItemId));
|
| - |
|
1174 |
} catch (ProfitMandiBusinessException e) {
|
| 1153 |
LOGGER.info("maxFofoOrderItemId" + maxFofoOrderItemId);
|
1175 |
LOGGER.error("Error fetching FofoLineItems by inventory IDs", e);
|
| 1154 |
|
- |
|
| 1155 |
FofoOrderItem foi = fofoOrderItemRepository.selectById(maxFofoOrderItemId);
|
1176 |
lineItemsByInventoryId = new HashMap<>();
|
| - |
|
1177 |
}
|
| 1156 |
|
1178 |
|
| - |
|
1179 |
// Get max FofoOrderItemId for each inventory item
|
| 1157 |
FofoOrder fo = fofoOrderRepository.selectByOrderId(foi.getOrderId());
|
1180 |
Set<Integer> fofoOrderItemIds = lineItemsByInventoryId.values().stream()
|
| - |
|
1181 |
.map(list -> list.stream().mapToInt(FofoLineItem::getFofoOrderItemId).max().orElse(-1))
|
| - |
|
1182 |
.filter(id -> id > 0)
|
| - |
|
1183 |
.collect(Collectors.toSet());
|
| - |
|
1184 |
|
| - |
|
1185 |
Map<Integer, FofoOrderItem> fofoOrderItemMap;
|
| - |
|
1186 |
try {
|
| - |
|
1187 |
fofoOrderItemMap = fofoOrderItemRepository
|
| - |
|
1188 |
.selectByIds(new ArrayList<>(fofoOrderItemIds)).stream()
|
| - |
|
1189 |
.collect(Collectors.toMap(FofoOrderItem::getId, foi -> foi));
|
| - |
|
1190 |
} catch (ProfitMandiBusinessException e) {
|
| - |
|
1191 |
LOGGER.error("Error fetching FofoOrderItems by IDs", e);
|
| - |
|
1192 |
fofoOrderItemMap = new HashMap<>();
|
| - |
|
1193 |
}
|
| 1158 |
|
1194 |
|
| - |
|
1195 |
Set<Integer> orderIds = fofoOrderItemMap.values().stream()
|
| - |
|
1196 |
.map(FofoOrderItem::getOrderId)
|
| - |
|
1197 |
.collect(Collectors.toSet());
|
| - |
|
1198 |
|
| - |
|
1199 |
Map<Integer, FofoOrder> fofoOrderMap = new HashMap<>();
|
| - |
|
1200 |
try {
|
| - |
|
1201 |
fofoOrderMap = fofoOrderRepository
|
| - |
|
1202 |
.selectAllByOrderIds(new ArrayList<>(orderIds)).stream()
|
| 1159 |
activationItemDetail.setInvoiceNumber(fo.getInvoiceNumber());
|
1203 |
.collect(Collectors.toMap(FofoOrder::getId, fo -> fo));
|
| - |
|
1204 |
} catch (ProfitMandiBusinessException e) {
|
| - |
|
1205 |
LOGGER.error("Error fetching FofoOrders by order IDs", e);
|
| - |
|
1206 |
}
|
| 1160 |
|
1207 |
|
| - |
|
1208 |
for (ActivationItemDetailModel activationItemDetail : activationItemDetails) {
|
| - |
|
1209 |
List<FofoLineItem> flis = lineItemsByInventoryId.get(activationItemDetail.getInventoryItemId());
|
| - |
|
1210 |
if (flis != null && !flis.isEmpty()) {
|
| - |
|
1211 |
int maxFofoOrderItemId = flis.stream().mapToInt(FofoLineItem::getFofoOrderItemId).max().orElse(-1);
|
| - |
|
1212 |
FofoOrderItem foi = fofoOrderItemMap.get(maxFofoOrderItemId);
|
| - |
|
1213 |
if (foi != null) {
|
| - |
|
1214 |
FofoOrder fo = fofoOrderMap.get(foi.getOrderId());
|
| - |
|
1215 |
if (fo != null) {
|
| - |
|
1216 |
activationItemDetail.setInvoiceNumber(fo.getInvoiceNumber());
|
| - |
|
1217 |
}
|
| - |
|
1218 |
}
|
| - |
|
1219 |
}
|
| - |
|
1220 |
}
|
| 1161 |
}
|
1221 |
}
|
| 1162 |
LOGGER.info("activationItemDetails" + activationItemDetails);
|
1222 |
LOGGER.info("activationItemDetails" + activationItemDetails);
|
| 1163 |
|
1223 |
|
| 1164 |
model.addAttribute("activationItemDetails", activationItemDetails);
|
1224 |
model.addAttribute("activationItemDetails", activationItemDetails);
|
| 1165 |
|
1225 |
|
| Line 1174... |
Line 1234... |
| 1174 |
|
1234 |
|
| 1175 |
LocalDateTime startOfMonth = curDate.withDayOfMonth(1).minusMonths(6);
|
1235 |
LocalDateTime startOfMonth = curDate.withDayOfMonth(1).minusMonths(6);
|
| 1176 |
|
1236 |
|
| 1177 |
List<ActivationItemDetailModel> activationItemDetails = schemeInOutRepository.selectBrandPendingActivationItemDetailByYearMonth(fofoId, brand, startOfMonth);
|
1237 |
List<ActivationItemDetailModel> activationItemDetails = schemeInOutRepository.selectBrandPendingActivationItemDetailByYearMonth(fofoId, brand, startOfMonth);
|
| 1178 |
|
1238 |
|
| - |
|
1239 |
if (!activationItemDetails.isEmpty()) {
|
| - |
|
1240 |
// Batch fetch to avoid N+1 queries
|
| 1179 |
for (ActivationItemDetailModel activationItemDetail : activationItemDetails) {
|
1241 |
List<Integer> inventoryItemIds = activationItemDetails.stream()
|
| 1180 |
|
- |
|
| 1181 |
List<FofoLineItem> flis = fofoLineItemRepository.selectByInventoryItemId(activationItemDetail.getInventoryItemId());
|
1242 |
.map(ActivationItemDetailModel::getInventoryItemId)
|
| 1182 |
LOGGER.info("flis" + flis);
|
1243 |
.collect(Collectors.toList());
|
| 1183 |
|
1244 |
|
| - |
|
1245 |
Map<Integer, List<FofoLineItem>> lineItemsByInventoryId;
|
| - |
|
1246 |
try {
|
| - |
|
1247 |
lineItemsByInventoryId = fofoLineItemRepository
|
| - |
|
1248 |
.selectByInventoryItemIds(inventoryItemIds).stream()
|
| 1184 |
int maxFofoOrderItemId = flis.stream().mapToInt(x -> x.getFofoOrderItemId()).max().orElseThrow(NoSuchElementException::new);
|
1249 |
.collect(Collectors.groupingBy(FofoLineItem::getInventoryItemId));
|
| - |
|
1250 |
} catch (ProfitMandiBusinessException e) {
|
| 1185 |
LOGGER.info("maxFofoOrderItemId" + maxFofoOrderItemId);
|
1251 |
LOGGER.error("Error fetching FofoLineItems by inventory IDs", e);
|
| 1186 |
|
- |
|
| 1187 |
FofoOrderItem foi = fofoOrderItemRepository.selectById(maxFofoOrderItemId);
|
1252 |
lineItemsByInventoryId = new HashMap<>();
|
| - |
|
1253 |
}
|
| 1188 |
|
1254 |
|
| 1189 |
FofoOrder fo = fofoOrderRepository.selectByOrderId(foi.getOrderId());
|
1255 |
Set<Integer> fofoOrderItemIds = lineItemsByInventoryId.values().stream()
|
| - |
|
1256 |
.map(list -> list.stream().mapToInt(FofoLineItem::getFofoOrderItemId).max().orElse(-1))
|
| - |
|
1257 |
.filter(id -> id > 0)
|
| - |
|
1258 |
.collect(Collectors.toSet());
|
| - |
|
1259 |
|
| - |
|
1260 |
Map<Integer, FofoOrderItem> fofoOrderItemMap;
|
| - |
|
1261 |
try {
|
| - |
|
1262 |
fofoOrderItemMap = fofoOrderItemRepository
|
| - |
|
1263 |
.selectByIds(new ArrayList<>(fofoOrderItemIds)).stream()
|
| - |
|
1264 |
.collect(Collectors.toMap(FofoOrderItem::getId, foi -> foi));
|
| - |
|
1265 |
} catch (ProfitMandiBusinessException e) {
|
| - |
|
1266 |
LOGGER.error("Error fetching FofoOrderItems by IDs", e);
|
| - |
|
1267 |
fofoOrderItemMap = new HashMap<>();
|
| - |
|
1268 |
}
|
| 1190 |
|
1269 |
|
| - |
|
1270 |
Set<Integer> orderIds = fofoOrderItemMap.values().stream()
|
| - |
|
1271 |
.map(FofoOrderItem::getOrderId)
|
| - |
|
1272 |
.collect(Collectors.toSet());
|
| - |
|
1273 |
|
| - |
|
1274 |
Map<Integer, FofoOrder> fofoOrderMap = new HashMap<>();
|
| - |
|
1275 |
try {
|
| - |
|
1276 |
fofoOrderMap = fofoOrderRepository
|
| - |
|
1277 |
.selectAllByOrderIds(new ArrayList<>(orderIds)).stream()
|
| 1191 |
activationItemDetail.setInvoiceNumber(fo.getInvoiceNumber());
|
1278 |
.collect(Collectors.toMap(FofoOrder::getId, fo -> fo));
|
| - |
|
1279 |
} catch (ProfitMandiBusinessException e) {
|
| - |
|
1280 |
LOGGER.error("Error fetching FofoOrders by order IDs", e);
|
| - |
|
1281 |
}
|
| 1192 |
|
1282 |
|
| - |
|
1283 |
for (ActivationItemDetailModel activationItemDetail : activationItemDetails) {
|
| - |
|
1284 |
List<FofoLineItem> flis = lineItemsByInventoryId.get(activationItemDetail.getInventoryItemId());
|
| - |
|
1285 |
if (flis != null && !flis.isEmpty()) {
|
| - |
|
1286 |
int maxFofoOrderItemId = flis.stream().mapToInt(FofoLineItem::getFofoOrderItemId).max().orElse(-1);
|
| - |
|
1287 |
FofoOrderItem foi = fofoOrderItemMap.get(maxFofoOrderItemId);
|
| - |
|
1288 |
if (foi != null) {
|
| - |
|
1289 |
FofoOrder fo = fofoOrderMap.get(foi.getOrderId());
|
| - |
|
1290 |
if (fo != null) {
|
| - |
|
1291 |
activationItemDetail.setInvoiceNumber(fo.getInvoiceNumber());
|
| - |
|
1292 |
}
|
| - |
|
1293 |
}
|
| - |
|
1294 |
}
|
| - |
|
1295 |
}
|
| 1193 |
}
|
1296 |
}
|
| 1194 |
LOGGER.info("activationItemDetails" + activationItemDetails);
|
1297 |
LOGGER.info("activationItemDetails" + activationItemDetails);
|
| 1195 |
|
1298 |
|
| 1196 |
model.addAttribute("activationItemDetails", activationItemDetails);
|
1299 |
model.addAttribute("activationItemDetails", activationItemDetails);
|
| 1197 |
|
1300 |
|
| Line 1490... |
Line 1593... |
| 1490 |
Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
|
1593 |
Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
|
| 1491 |
Set<Integer> authfofoIds = storeGuyMap.get(email);
|
1594 |
Set<Integer> authfofoIds = storeGuyMap.get(email);
|
| 1492 |
|
1595 |
|
| 1493 |
AuthUser authUser = authRepository.selectByEmailOrMobile(email);
|
1596 |
AuthUser authUser = authRepository.selectByEmailOrMobile(email);
|
| 1494 |
if (authfofoIds == null) {
|
1597 |
if (authfofoIds == null) {
|
| 1495 |
List<Position> positions1 = positionRepository.selectAll(authUser.getId());
|
1598 |
List<Position> positions1 = positionRepository.selectAllByAuthUserId(authUser.getId());
|
| 1496 |
if (positions1.stream().filter(x -> x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_MASTER).count() > 0) {
|
1599 |
if (positions1.stream().filter(x -> x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_MASTER).count() > 0) {
|
| 1497 |
authfofoIds = csService.getPositionCustomRetailerMap(positions1).values().stream().flatMap(x -> x.stream()).map(x -> x.getPartnerId()).collect(Collectors.toSet());
|
1600 |
authfofoIds = csService.getPositionCustomRetailerMap(positions1).values().stream().flatMap(x -> x.stream()).map(x -> x.getPartnerId()).collect(Collectors.toSet());
|
| 1498 |
}
|
1601 |
}
|
| 1499 |
}
|
1602 |
}
|
| 1500 |
List<WarehouseWiseBrandSaleModel> warehouseWiseBrandPartnerSales = fofoStoreRepository.selectGroupByWarehouseAccesoriesBrandWisePartnerSale(brand, new ArrayList<>(authfofoIds));
|
1603 |
List<WarehouseWiseBrandSaleModel> warehouseWiseBrandPartnerSales = fofoStoreRepository.selectGroupByWarehouseAccesoriesBrandWisePartnerSale(brand, new ArrayList<>(authfofoIds));
|
| Line 1814... |
Line 1917... |
| 1814 |
Map<Integer, AuthUser> ticketIdAuthUser = new HashMap<>();
|
1917 |
Map<Integer, AuthUser> ticketIdAuthUser = new HashMap<>();
|
| 1815 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
|
1918 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
|
| 1816 |
List<Integer> ticketIds = ticketRepository.selectAllOpenTicketByRetailer(fofoId).stream().map(x -> x.getId()).collect(Collectors.toList());
|
1919 |
List<Integer> ticketIds = ticketRepository.selectAllOpenTicketByRetailer(fofoId).stream().map(x -> x.getId()).collect(Collectors.toList());
|
| 1817 |
List<TicketAssigned> ticketAssigns = ticketAssignedRepository.selectByTicketIds(ticketIds);
|
1920 |
List<TicketAssigned> ticketAssigns = ticketAssignedRepository.selectByTicketIds(ticketIds);
|
| 1818 |
|
1921 |
|
| - |
|
1922 |
if (!ticketAssigns.isEmpty()) {
|
| - |
|
1923 |
// Batch fetch AuthUsers to avoid N+1 queries
|
| - |
|
1924 |
Set<Integer> assigneeIds = ticketAssigns.stream()
|
| - |
|
1925 |
.map(TicketAssigned::getAssineeId)
|
| - |
|
1926 |
.collect(Collectors.toSet());
|
| - |
|
1927 |
|
| - |
|
1928 |
Map<Integer, AuthUser> authUserMap = authRepository.selectByIds(new ArrayList<>(assigneeIds)).stream()
|
| - |
|
1929 |
.collect(Collectors.toMap(AuthUser::getId, au -> au));
|
| - |
|
1930 |
|
| 1819 |
for (TicketAssigned ticketAssign : ticketAssigns) {
|
1931 |
for (TicketAssigned ticketAssign : ticketAssigns) {
|
| 1820 |
AuthUser authUser = authRepository.selectById(ticketAssign.getAssineeId());
|
1932 |
AuthUser authUser = authUserMap.get(ticketAssign.getAssineeId());
|
| - |
|
1933 |
if (authUser != null) {
|
| 1821 |
ticketIdAuthUser.put(ticketAssign.getTicketId(), authUser);
|
1934 |
ticketIdAuthUser.put(ticketAssign.getTicketId(), authUser);
|
| - |
|
1935 |
}
|
| - |
|
1936 |
}
|
| 1822 |
}
|
1937 |
}
|
| 1823 |
model.addAttribute("ticketIdAuthUser", ticketIdAuthUser);
|
1938 |
model.addAttribute("ticketIdAuthUser", ticketIdAuthUser);
|
| 1824 |
model.addAttribute("ticketAssigns", ticketAssigns);
|
1939 |
model.addAttribute("ticketAssigns", ticketAssigns);
|
| 1825 |
model.addAttribute("customRetailer", customRetailer);
|
1940 |
model.addAttribute("customRetailer", customRetailer);
|
| 1826 |
return "open-ticket";
|
1941 |
return "open-ticket";
|
| Line 2240... |
Line 2355... |
| 2240 |
fofoIds = storeGuyMap.get("tarun.verma@smartdukaan.com");
|
2355 |
fofoIds = storeGuyMap.get("tarun.verma@smartdukaan.com");
|
| 2241 |
LOGGER.info("fofoIds" + fofoIds);
|
2356 |
LOGGER.info("fofoIds" + fofoIds);
|
| 2242 |
}
|
2357 |
}
|
| 2243 |
|
2358 |
|
| 2244 |
if (fofoIds == null) {
|
2359 |
if (fofoIds == null) {
|
| 2245 |
List<Position> positions1 = positionRepository.selectAll(authUser.getId());
|
2360 |
List<Position> positions1 = positionRepository.selectAllByAuthUserId(authUser.getId());
|
| 2246 |
if (positions1.stream().filter(x -> x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_MASTER).count() > 0) {
|
2361 |
if (positions1.stream().filter(x -> x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_MASTER).count() > 0) {
|
| 2247 |
fofoIds = csService.getPositionCustomRetailerMap(positions1).values().stream().flatMap(x -> x.stream()).map(x -> x.getPartnerId()).collect(Collectors.toSet());
|
2362 |
fofoIds = csService.getPositionCustomRetailerMap(positions1).values().stream().flatMap(x -> x.stream()).map(x -> x.getPartnerId()).collect(Collectors.toSet());
|
| 2248 |
}
|
2363 |
}
|
| 2249 |
}
|
2364 |
}
|
| 2250 |
return new ArrayList<>(fofoIds);
|
2365 |
return new ArrayList<>(fofoIds);
|