| Line 1065... |
Line 1065... |
| 1065 |
@RequestParam(value = "subCategoryId", required = false) int subCategoryId, @RequestParam(required = false) String queryTerm,
|
1065 |
@RequestParam(value = "subCategoryId", required = false) int subCategoryId, @RequestParam(required = false) String queryTerm,
|
| 1066 |
@RequestParam(required = false) String listing, @RequestParam(required = false, defaultValue = "true") boolean partnerStockOnly) throws Throwable {
|
1066 |
@RequestParam(required = false) String listing, @RequestParam(required = false, defaultValue = "true") boolean partnerStockOnly) throws Throwable {
|
| 1067 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
1067 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
| 1068 |
int dbCategoryId = mapFrontendCategoryToDb(categoryId);
|
1068 |
int dbCategoryId = mapFrontendCategoryToDb(categoryId);
|
| 1069 |
List<FofoCatalogResponse> dealResponse = getCatalogResponseFromDb(
|
1069 |
List<FofoCatalogResponse> dealResponse = getCatalogResponseFromDb(
|
| 1070 |
dbCategoryId, userInfo.getRetailerId(), offset, limit, brand, queryTerm, subCategoryId);
|
1070 |
dbCategoryId, userInfo.getRetailerId(), offset, limit, brand, queryTerm, subCategoryId, partnerStockOnly);
|
| 1071 |
return responseSender.ok(dealResponse);
|
1071 |
return responseSender.ok(dealResponse);
|
| 1072 |
}
|
1072 |
}
|
| 1073 |
|
1073 |
|
| 1074 |
private int mapFrontendCategoryToDb(String frontendCategoryId) {
|
1074 |
private int mapFrontendCategoryToDb(String frontendCategoryId) {
|
| 1075 |
if ("3".equals(frontendCategoryId)) return 10006;
|
1075 |
if ("3".equals(frontendCategoryId)) return 10006;
|
| Line 1079... |
Line 1079... |
| 1079 |
return 10006;
|
1079 |
return 10006;
|
| 1080 |
}
|
1080 |
}
|
| 1081 |
}
|
1081 |
}
|
| 1082 |
|
1082 |
|
| 1083 |
private List<FofoCatalogResponse> getCatalogResponseFromDb(int dbCategoryId, int fofoId, int offset, int limit,
|
1083 |
private List<FofoCatalogResponse> getCatalogResponseFromDb(int dbCategoryId, int fofoId, int offset, int limit,
|
| - |
|
1084 |
String brand, String queryTerm, int subCategoryId,
|
| 1084 |
String brand, String queryTerm, int subCategoryId) throws ProfitMandiBusinessException {
|
1085 |
boolean partnerStockOnly) throws ProfitMandiBusinessException {
|
| 1085 |
List<status> statuses = Arrays.asList(status.ACTIVE, status.PAUSED_BY_RISK, status.PARTIALLY_ACTIVE);
|
1086 |
List<status> statuses = Arrays.asList(status.ACTIVE, status.PAUSED_BY_RISK, status.PARTIALLY_ACTIVE);
|
| 1086 |
List<ItemTagModel> itemTagModels = tagListingRepository.getItemTagByCategoryAndStatus(dbCategoryId, statuses);
|
1087 |
List<ItemTagModel> itemTagModels = tagListingRepository.getItemTagByCategoryAndStatus(dbCategoryId, statuses);
|
| 1087 |
|
1088 |
|
| 1088 |
List<String> excludeBrands = Arrays.asList("Dummy", "FOC HANDSET", "FOC", "Live Demo");
|
1089 |
List<String> excludeBrands = Arrays.asList("Dummy", "FOC HANDSET", "FOC", "Live Demo");
|
| 1089 |
|
1090 |
|
| - |
|
1091 |
// Sell-mode (partnerStockOnly): fetch partner stock first so we can prune
|
| - |
|
1092 |
// catalogs to in-stock items only before any other lookups. This cuts the
|
| - |
|
1093 |
// work for warehouse/cashback/image batches and skips empty catalogs entirely.
|
| - |
|
1094 |
Map<Integer, Integer> partnerStockMap = Collections.emptyMap();
|
| - |
|
1095 |
if (fofoId > 0) {
|
| - |
|
1096 |
partnerStockMap = currentInventorySnapshotRepository.selectItemsStock(fofoId).stream()
|
| - |
|
1097 |
.collect(Collectors.toMap(x -> x.getItemId(), x -> x.getAvailability(), (a, b) -> a));
|
| - |
|
1098 |
}
|
| - |
|
1099 |
final Map<Integer, Integer> psMap = partnerStockMap;
|
| - |
|
1100 |
|
| 1090 |
Map<Integer, List<ItemTagModel>> catalogGrouped = itemTagModels.stream()
|
1101 |
Map<Integer, List<ItemTagModel>> catalogGrouped = itemTagModels.stream()
|
| 1091 |
.filter(itm -> !excludeBrands.contains(itm.getItem().getBrand()))
|
1102 |
.filter(itm -> !excludeBrands.contains(itm.getItem().getBrand()))
|
| 1092 |
.filter(itm -> brand == null || brand.isEmpty() || itm.getItem().getBrand().equalsIgnoreCase(brand))
|
1103 |
.filter(itm -> brand == null || brand.isEmpty() || itm.getItem().getBrand().equalsIgnoreCase(brand))
|
| 1093 |
.filter(itm -> queryTerm == null || queryTerm.isEmpty() || queryTerm.equals("null")
|
1104 |
.filter(itm -> queryTerm == null || queryTerm.isEmpty() || queryTerm.equals("null")
|
| 1094 |
|| matchesSearchQuery(itm.getItem(), queryTerm))
|
1105 |
|| matchesSearchQuery(itm.getItem(), queryTerm))
|
| 1095 |
.filter(itm -> subCategoryId == 0 || itm.getItem().getCategoryId() == subCategoryId)
|
1106 |
.filter(itm -> subCategoryId == 0 || itm.getItem().getCategoryId() == subCategoryId)
|
| - |
|
1107 |
// Drop items the partner has zero of when sell-mode demands in-stock only.
|
| - |
|
1108 |
.filter(itm -> !partnerStockOnly || psMap.getOrDefault(itm.getItem().getId(), 0) > 0)
|
| 1096 |
.collect(Collectors.groupingBy(itm -> itm.getItem().getCatalogItemId()));
|
1109 |
.collect(Collectors.groupingBy(itm -> itm.getItem().getCatalogItemId()));
|
| 1097 |
|
1110 |
|
| 1098 |
if (catalogGrouped.isEmpty()) {
|
1111 |
if (catalogGrouped.isEmpty()) {
|
| 1099 |
return new ArrayList<>();
|
1112 |
return new ArrayList<>();
|
| 1100 |
}
|
1113 |
}
|
| Line 1102... |
Line 1115... |
| 1102 |
Set<Integer> allItemIds = catalogGrouped.values().stream()
|
1115 |
Set<Integer> allItemIds = catalogGrouped.values().stream()
|
| 1103 |
.flatMap(List::stream)
|
1116 |
.flatMap(List::stream)
|
| 1104 |
.map(itm -> itm.getItem().getId())
|
1117 |
.map(itm -> itm.getItem().getId())
|
| 1105 |
.collect(Collectors.toSet());
|
1118 |
.collect(Collectors.toSet());
|
| 1106 |
|
1119 |
|
| 1107 |
Map<Integer, Integer> partnerStockMap = Collections.emptyMap();
|
- |
|
| 1108 |
if (fofoId > 0) {
|
- |
|
| 1109 |
partnerStockMap = currentInventorySnapshotRepository.selectItemsStock(fofoId).stream()
|
- |
|
| 1110 |
.collect(Collectors.toMap(x -> x.getItemId(), x -> x.getAvailability(), (a, b) -> a));
|
- |
|
| 1111 |
}
|
- |
|
| 1112 |
|
- |
|
| 1113 |
Map<Integer, Integer> warehouseStockMap = saholicInventoryService.getTotalAvailabilityByItemIds(new ArrayList<>(allItemIds));
|
1120 |
Map<Integer, Integer> warehouseStockMap = saholicInventoryService.getTotalAvailabilityByItemIds(new ArrayList<>(allItemIds));
|
| 1114 |
|
1121 |
|
| 1115 |
Map<Integer, List<WebOffer>> webOfferMap = webOfferRepository.selectAllActiveOffers();
|
1122 |
Map<Integer, List<WebOffer>> webOfferMap = webOfferRepository.selectAllActiveOffers();
|
| 1116 |
|
1123 |
|
| 1117 |
List<SuperCatalogModel> superCatalogModels = superCatalogMappingRepository.selectJoinedData();
|
1124 |
List<SuperCatalogModel> superCatalogModels = superCatalogMappingRepository.selectJoinedData();
|