| Line 202... |
Line 202... |
| 202 |
Map<String, JsonNode> map = new HashMap<>();
|
202 |
Map<String, JsonNode> map = new HashMap<>();
|
| 203 |
|
203 |
|
| 204 |
for (JsonNode edge : edges) {
|
204 |
for (JsonNode edge : edges) {
|
| 205 |
JsonNode node = edge.path("node");
|
205 |
JsonNode node = edge.path("node");
|
| 206 |
|
206 |
|
| 207 |
String color = "", ram = "", storage = "";
|
207 |
String color = "", variant = "", insurance = "";
|
| 208 |
|
208 |
|
| 209 |
for (JsonNode opt : node.path("selectedOptions")) {
|
209 |
for (JsonNode opt : node.path("selectedOptions")) {
|
| 210 |
String name = opt.path("name").asText();
|
210 |
String name = opt.path("name").asText();
|
| 211 |
String value = opt.path("value").asText();
|
211 |
String value = opt.path("value").asText();
|
| 212 |
if ("Color".equalsIgnoreCase(name)) color = value;
|
212 |
if ("Color".equalsIgnoreCase(name)) color = value;
|
| 213 |
if ("RAM".equalsIgnoreCase(name)) ram = value;
|
213 |
if ("Variant".equalsIgnoreCase(name)) variant = value;
|
| 214 |
if ("Storage".equalsIgnoreCase(name)) storage = value;
|
214 |
if ("Insurance".equalsIgnoreCase(name)) insurance = value;
|
| 215 |
}
|
215 |
}
|
| 216 |
|
216 |
|
| 217 |
String key = color + "|" + ram + "|" + storage;
|
217 |
String key = color + "|" + variant + "|" + insurance;
|
| 218 |
map.put(key.trim(), node);
|
218 |
map.put(key.trim(), node);
|
| 219 |
}
|
219 |
}
|
| 220 |
|
220 |
|
| 221 |
return map;
|
221 |
return map;
|
| 222 |
}
|
222 |
}
|
| Line 272... |
Line 272... |
| 272 |
|
272 |
|
| 273 |
return getCatalogResponse(docs, fofoStore.getId());
|
273 |
return getCatalogResponse(docs, fofoStore.getId());
|
| 274 |
|
274 |
|
| 275 |
}
|
275 |
}
|
| 276 |
|
276 |
|
| - |
|
277 |
public List<FofoCatalogResponse> getAllDocsPaginated(FofoStore fofoStore, int batchSize) throws Exception {
|
| - |
|
278 |
List<FofoCatalogResponse> allProducts = new ArrayList<>();
|
| - |
|
279 |
int start = 0;
|
| - |
|
280 |
|
| - |
|
281 |
while (true) {
|
| - |
|
282 |
Map<String, String> params = new HashMap<>();
|
| - |
|
283 |
params.put("q", "+active_b:true AND show_default_b:true");
|
| - |
|
284 |
params.put("fl", "*, [child parentFilter=id:catalog* childFilter=active_b:true ]");
|
| - |
|
285 |
params.put("wt", "json");
|
| - |
|
286 |
params.put("rows", String.valueOf(batchSize));
|
| - |
|
287 |
params.put("start", String.valueOf(start));
|
| - |
|
288 |
|
| - |
|
289 |
String response = restClient.get(SchemeType.HTTP, solrUrl, 8984, "solr/demo/select", params);
|
| - |
|
290 |
JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
|
| - |
|
291 |
int numFound = solrResponseJSONObj.getInt("numFound");
|
| - |
|
292 |
JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
|
| - |
|
293 |
|
| - |
|
294 |
if (docs.length() == 0) break;
|
| - |
|
295 |
|
| - |
|
296 |
List<FofoCatalogResponse> batch = getCatalogResponse(docs, fofoStore.getId());
|
| - |
|
297 |
allProducts.addAll(batch);
|
| - |
|
298 |
|
| - |
|
299 |
start += batchSize;
|
| - |
|
300 |
if (start >= numFound) break;
|
| - |
|
301 |
|
| - |
|
302 |
logger.info("Fetched {} / {} products from Solr", Math.min(start, numFound), numFound);
|
| - |
|
303 |
}
|
| - |
|
304 |
|
| - |
|
305 |
logger.info("Total products fetched from Solr: {}", allProducts.size());
|
| - |
|
306 |
return allProducts;
|
| - |
|
307 |
}
|
| - |
|
308 |
|
| - |
|
309 |
public List<FofoCatalogResponse> getAllDocsPaginatedForWarehouse(int batchSize) throws Exception {
|
| - |
|
310 |
List<FofoCatalogResponse> allProducts = new ArrayList<>();
|
| - |
|
311 |
int start = 0;
|
| - |
|
312 |
|
| - |
|
313 |
while (true) {
|
| - |
|
314 |
Map<String, String> params = new HashMap<>();
|
| - |
|
315 |
params.put("q", "+active_b:true AND show_default_b:true");
|
| - |
|
316 |
params.put("fl", "*, [child parentFilter=id:catalog* childFilter=active_b:true ]");
|
| - |
|
317 |
params.put("wt", "json");
|
| - |
|
318 |
params.put("rows", String.valueOf(batchSize));
|
| - |
|
319 |
params.put("start", String.valueOf(start));
|
| - |
|
320 |
|
| - |
|
321 |
String response = restClient.get(SchemeType.HTTP, solrUrl, 8984, "solr/demo/select", params);
|
| - |
|
322 |
JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
|
| - |
|
323 |
int numFound = solrResponseJSONObj.getInt("numFound");
|
| - |
|
324 |
JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
|
| - |
|
325 |
|
| - |
|
326 |
if (docs.length() == 0) break;
|
| - |
|
327 |
|
| - |
|
328 |
List<FofoCatalogResponse> batch = getCatalogResponse(docs, 0);
|
| - |
|
329 |
allProducts.addAll(batch);
|
| - |
|
330 |
|
| - |
|
331 |
start += batchSize;
|
| - |
|
332 |
if (start >= numFound) break;
|
| - |
|
333 |
|
| - |
|
334 |
logger.info("Fetched {} / {} products from Solr (warehouse)", Math.min(start, numFound), numFound);
|
| - |
|
335 |
}
|
| - |
|
336 |
|
| - |
|
337 |
logger.info("Total products fetched from Solr (warehouse): {}", allProducts.size());
|
| - |
|
338 |
return allProducts;
|
| - |
|
339 |
}
|
| - |
|
340 |
|
| 277 |
private List<FofoCatalogResponse> getCatalogResponse(JSONArray docs, int fofoId) throws ProfitMandiBusinessException {
|
341 |
private List<FofoCatalogResponse> getCatalogResponse(JSONArray docs, int fofoId) throws ProfitMandiBusinessException {
|
| 278 |
Map<Integer, Integer> ourItemAvailabilityMap = null;
|
342 |
Map<Integer, Integer> ourItemAvailabilityMap = null;
|
| 279 |
Map<Integer, Integer> partnerStockAvailabilityMap = null;
|
343 |
Map<Integer, Integer> partnerStockAvailabilityMap = new HashMap<>();
|
| 280 |
List<FofoCatalogResponse> dealResponse = new ArrayList<>();
|
344 |
List<FofoCatalogResponse> dealResponse = new ArrayList<>();
|
| 281 |
if (docs.length() > 0) {
|
345 |
if (docs.length() > 0) {
|
| 282 |
HashSet<Integer> itemsSet = new HashSet<>();
|
346 |
HashSet<Integer> itemsSet = new HashSet<>();
|
| 283 |
for (int i = 0; i < docs.length(); i++) {
|
347 |
for (int i = 0; i < docs.length(); i++) {
|
| 284 |
JSONObject doc = docs.getJSONObject(i);
|
348 |
JSONObject doc = docs.getJSONObject(i);
|
| Line 320... |
Line 384... |
| 320 |
}
|
384 |
}
|
| 321 |
ffdr.setBrand(doc.getJSONArray("brand_ss").getString(0));
|
385 |
ffdr.setBrand(doc.getJSONArray("brand_ss").getString(0));
|
| 322 |
|
386 |
|
| 323 |
if (doc.has("_childDocuments_")) {
|
387 |
if (doc.has("_childDocuments_")) {
|
| 324 |
for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
|
388 |
for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
|
| - |
|
389 |
try {
|
| 325 |
JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
|
390 |
JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
|
| 326 |
int itemId = childItem.getInt("itemId_i");
|
391 |
int itemId = childItem.getInt("itemId_i");
|
| 327 |
ffdr.setIsSmartPhone(itemRepository.selectById(itemId).isSmartPhone());
|
392 |
ffdr.setIsSmartPhone(itemRepository.selectById(itemId).isSmartPhone());
|
| 328 |
float sellingPrice = (float) childItem.getDouble("sellingPrice_f");
|
393 |
float sellingPrice = (float) childItem.getDouble("sellingPrice_f");
|
| 329 |
if (fofoAvailabilityInfoMap.containsKey(itemId)) {
|
394 |
if (fofoAvailabilityInfoMap.containsKey(itemId)) {
|
| 330 |
if (fofoAvailabilityInfoMap.get(itemId).getSellingPrice() > sellingPrice) {
|
395 |
if (fofoAvailabilityInfoMap.get(itemId).getSellingPrice() > sellingPrice) {
|
| 331 |
fofoAvailabilityInfoMap.get(itemId).setSellingPrice(sellingPrice);
|
396 |
fofoAvailabilityInfoMap.get(itemId).setSellingPrice(sellingPrice);
|
| 332 |
fofoAvailabilityInfoMap.get(itemId).setMop((float) childItem.getDouble("mop_f"));
|
397 |
fofoAvailabilityInfoMap.get(itemId).setMop((float) childItem.getDouble("mop_f"));
|
| - |
|
398 |
}
|
| - |
|
399 |
} else {
|
| - |
|
400 |
FofoAvailabilityInfo fdi = new FofoAvailabilityInfo();
|
| - |
|
401 |
fdi.setSellingPrice(sellingPrice);
|
| - |
|
402 |
fdi.setMrp(childItem.getDouble("mrp_f"));
|
| - |
|
403 |
fdi.setMop((float) childItem.getDouble("mop_f"));
|
| - |
|
404 |
fdi.setColor(childItem.has("color_s") ? childItem.getString("color_s") : "");
|
| - |
|
405 |
fdi.setTagId(childItem.getInt("tagId_i"));
|
| - |
|
406 |
fdi.setItem_id(itemId);
|
| - |
|
407 |
fdi.setCatalog_id(doc.getInt("catalogId_i"));
|
| - |
|
408 |
fdi.setCashback(0);
|
| - |
|
409 |
fdi.setMinBuyQuantity(1);
|
| - |
|
410 |
int partnerAvailability = partnerStockAvailabilityMap.get(itemId) == null ? 0 : partnerStockAvailabilityMap.get(itemId);
|
| - |
|
411 |
int ourStockAvailability = ourItemAvailabilityMap.get(itemId) == null ? 0 : Math.max(0, ourItemAvailabilityMap.get(itemId));
|
| - |
|
412 |
fdi.setActive(partnerAvailability > 0);
|
| - |
|
413 |
fdi.setPartnerAvailability(partnerAvailability);
|
| - |
|
414 |
fdi.setAvailability(Math.min(5, ourStockAvailability + partnerAvailability));
|
| - |
|
415 |
fdi.setQuantityStep(1);
|
| - |
|
416 |
fdi.setMaxQuantity(fdi.getAvailability());
|
| - |
|
417 |
fofoAvailabilityInfoMap.put(itemId, fdi);
|
| 333 |
}
|
418 |
}
|
| 334 |
} else {
|
419 |
} catch (Exception e) {
|
| 335 |
FofoAvailabilityInfo fdi = new FofoAvailabilityInfo();
|
- |
|
| 336 |
fdi.setSellingPrice(sellingPrice);
|
- |
|
| 337 |
fdi.setMrp(childItem.getDouble("mrp_f"));
|
- |
|
| 338 |
fdi.setMop((float) childItem.getDouble("mop_f"));
|
- |
|
| 339 |
fdi.setColor(childItem.has("color_s") ? childItem.getString("color_s") : "");
|
- |
|
| 340 |
fdi.setTagId(childItem.getInt("tagId_i"));
|
- |
|
| 341 |
fdi.setItem_id(itemId);
|
- |
|
| 342 |
fdi.setCatalog_id(doc.getInt("catalogId_i"));
|
420 |
logger.warn("Skipping stale item in Solr doc catalogId={}: {}", doc.getInt("catalogId_i"), e.getMessage());
|
| 343 |
fdi.setCashback(0);
|
- |
|
| 344 |
fdi.setMinBuyQuantity(1);
|
- |
|
| 345 |
int partnerAvailability = partnerStockAvailabilityMap.get(itemId) == null ? 0 : partnerStockAvailabilityMap.get(itemId);
|
- |
|
| 346 |
int ourStockAvailability = ourItemAvailabilityMap.get(itemId) == null ? 0 : Math.max(0, ourItemAvailabilityMap.get(itemId));
|
- |
|
| 347 |
fdi.setActive(partnerAvailability > 0);
|
- |
|
| 348 |
fdi.setPartnerAvailability(partnerAvailability);
|
- |
|
| 349 |
fdi.setAvailability(Math.min(5, ourStockAvailability + partnerAvailability));
|
- |
|
| 350 |
fdi.setQuantityStep(1);
|
- |
|
| 351 |
fdi.setMaxQuantity(fdi.getAvailability());
|
- |
|
| 352 |
fofoAvailabilityInfoMap.put(itemId, fdi);
|
- |
|
| 353 |
}
|
421 |
}
|
| 354 |
}
|
422 |
}
|
| 355 |
}
|
423 |
}
|
| 356 |
if (fofoAvailabilityInfoMap.values().size() > 0) {
|
424 |
if (fofoAvailabilityInfoMap.values().size() > 0) {
|
| 357 |
ffdr.setItems(fofoAvailabilityInfoMap.values().stream().sorted(Comparator.comparing(FofoAvailabilityInfo::isActive, Comparator.reverseOrder()).thenComparingInt(y -> -y.getAvailability())).collect(Collectors.toList()));
|
425 |
ffdr.setItems(fofoAvailabilityInfoMap.values().stream().sorted(Comparator.comparing(FofoAvailabilityInfo::isActive, Comparator.reverseOrder()).thenComparingInt(y -> -y.getAvailability())).collect(Collectors.toList()));
|
| Line 364... |
Line 432... |
| 364 |
private List<Map<String, String>> buildSelectedOptions(String color, String storage) {
|
432 |
private List<Map<String, String>> buildSelectedOptions(String color, String storage) {
|
| 365 |
|
433 |
|
| 366 |
List<Map<String, String>> selectedOptions = new ArrayList<>();
|
434 |
List<Map<String, String>> selectedOptions = new ArrayList<>();
|
| 367 |
|
435 |
|
| 368 |
Map<String, String> c = new HashMap<>();
|
436 |
Map<String, String> c = new HashMap<>();
|
| 369 |
c.put("name", "Color");
|
437 |
c.put("name", "Colour");
|
| 370 |
c.put("value", color);
|
438 |
c.put("value", color);
|
| 371 |
selectedOptions.add(c);
|
439 |
selectedOptions.add(c);
|
| 372 |
|
440 |
|
| 373 |
Map<String, String> s = new HashMap<>();
|
441 |
Map<String, String> s = new HashMap<>();
|
| 374 |
s.put("name", "Storage");
|
442 |
s.put("name", "Storage");
|