| Line 18... |
Line 18... |
| 18 |
import org.apache.logging.log4j.LogManager;
|
18 |
import org.apache.logging.log4j.LogManager;
|
| 19 |
import org.apache.logging.log4j.Logger;
|
19 |
import org.apache.logging.log4j.Logger;
|
| 20 |
import org.apache.solr.client.solrj.SolrClient;
|
20 |
import org.apache.solr.client.solrj.SolrClient;
|
| 21 |
import org.apache.solr.client.solrj.impl.HttpSolrClient;
|
21 |
import org.apache.solr.client.solrj.impl.HttpSolrClient;
|
| 22 |
import org.apache.solr.common.SolrInputDocument;
|
22 |
import org.apache.solr.common.SolrInputDocument;
|
| - |
|
23 |
import org.apache.solr.common.SolrInputField;
|
| 23 |
import org.json.JSONArray;
|
24 |
import org.json.JSONArray;
|
| 24 |
import org.json.JSONException;
|
25 |
import org.json.JSONException;
|
| 25 |
import org.json.JSONObject;
|
26 |
import org.json.JSONObject;
|
| 26 |
import org.springframework.beans.factory.annotation.Autowired;
|
27 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 27 |
import org.springframework.beans.factory.annotation.Value;
|
28 |
import org.springframework.beans.factory.annotation.Value;
|
| Line 257... |
Line 258... |
| 257 |
for (TagRanking tagRanking : tagRankingList) {
|
258 |
for (TagRanking tagRanking : tagRankingList) {
|
| 258 |
rankingList.add(tagRanking.getCatalogItemId());
|
259 |
rankingList.add(tagRanking.getCatalogItemId());
|
| 259 |
featureMap.put(tagRanking.getCatalogItemId(), tagRanking.getFeature());
|
260 |
featureMap.put(tagRanking.getCatalogItemId(), tagRanking.getFeature());
|
| 260 |
}
|
261 |
}
|
| 261 |
//Get Similar Models
|
262 |
//Get Similar Models
|
| 262 |
List<SimilarModel> similarModels = similarModelRepository.selectAll();
|
263 |
/*List<SimilarModel> similarModels = similarModelRepository.selectAll();
|
| 263 |
|
264 |
|
| 264 |
Map<Integer, List<Integer>> similarModelsMap = similarModels.stream().collect(Collectors.groupingBy(SimilarModel::getCatalogId, Collectors.mapping(x -> x.getSimilarCatalogId(), Collectors.toList())));
|
265 |
Map<Integer, List<Integer>> similarModelsMap = similarModels.stream().collect(Collectors.groupingBy(SimilarModel::getCatalogId, Collectors.mapping(x -> x.getSimilarCatalogId(), Collectors.toList())));*/
|
| 265 |
|
266 |
|
| 266 |
Map<Integer, Map<String, Object>> catalogMap = new HashMap<>();
|
267 |
Map<Integer, Map<String, Object>> catalogMap = new HashMap<>();
|
| 267 |
|
268 |
|
| 268 |
List<status> statuses = Arrays.asList(status.ACTIVE, status.PAUSED_BY_RISK, status.PARTIALLY_ACTIVE);
|
269 |
List<status> statuses = Arrays.asList(status.ACTIVE, status.PAUSED_BY_RISK, status.PARTIALLY_ACTIVE);
|
| 269 |
|
270 |
|
| 270 |
Map<Integer, List<String>> catalogLabelMap = this.getLabels();
|
271 |
Map<Integer, List<String>> catalogLabelMap = this.getLabels();
|
| 271 |
|
272 |
|
| 272 |
logger.info("catalogLabelMap {}", catalogLabelMap);
|
273 |
logger.info("catalogLabelMap {}", catalogLabelMap);
|
| 273 |
|
274 |
|
| 274 |
/*
|
- |
|
| 275 |
* List<ItemTagModel> tuples =
|
- |
|
| 276 |
* tagListingRepository.getAllItemTagByStatus(statuses).stream() .filter(x ->
|
- |
|
| 277 |
* x.getItem().getCatalogItemId() == 1023747).collect(Collectors.toList());
|
- |
|
| 278 |
*/
|
- |
|
| 279 |
|
- |
|
| 280 |
List<ItemTagModel> itemTagModels = tagListingRepository.getAllItemTagByStatus(statuses);
|
275 |
List<ItemTagModel> itemTagModels = tagListingRepository.getAllItemTagByStatus(statuses);
|
| 281 |
|
276 |
|
| 282 |
Map<String, Object> projection = new HashMap<>();
|
277 |
Map<String, Object> projection = new HashMap<>();
|
| 283 |
projection.put("defaultImageUrl", 1);
|
278 |
projection.put("defaultImageUrl", 1);
|
| 284 |
|
279 |
|
| Line 291... |
Line 286... |
| 291 |
if (excludeBrands.contains(item.getBrand())) {
|
286 |
if (excludeBrands.contains(item.getBrand())) {
|
| 292 |
continue;
|
287 |
continue;
|
| 293 |
}
|
288 |
}
|
| 294 |
|
289 |
|
| 295 |
if (!catalogMap.containsKey(item.getCatalogItemId())) {
|
290 |
if (!catalogMap.containsKey(item.getCatalogItemId())) {
|
| 296 |
|
- |
|
| 297 |
if (!priceModelMap.containsKey(tagListing.getSellingPrice()) && item.getCategoryId() == 10006) {
|
291 |
if (!priceModelMap.containsKey(tagListing.getSellingPrice()) && item.getCategoryId() == 10006) {
|
| 298 |
priceModelMap.put(tagListing.getSellingPrice(), new ArrayList<>());
|
292 |
priceModelMap.put(tagListing.getSellingPrice(), new ArrayList<>());
|
| 299 |
}
|
293 |
}
|
| 300 |
if(item.getCategoryId()==10006) {
|
294 |
if (item.getCategoryId() == 10006) {
|
| 301 |
List<Integer> priceModels = priceModelMap.get(tagListing.getSellingPrice());
|
295 |
List<Integer> priceModels = priceModelMap.get(tagListing.getSellingPrice());
|
| 302 |
priceModels.add(item.getCatalogItemId());
|
296 |
priceModels.add(item.getCatalogItemId());
|
| 303 |
}
|
297 |
}
|
| 304 |
|
298 |
|
| 305 |
Map<String, Object> catalogObj = new HashMap<>();
|
299 |
Map<String, Object> catalogObj = new HashMap<>();
|
| 306 |
|
- |
|
| - |
|
300 |
catalogObj.put("stockColor", 0);
|
| 307 |
catalogObj.put("feature", "");
|
301 |
catalogObj.put("feature", "");
|
| 308 |
catalogObj.put("hsnCode", item.getHsnCode());
|
302 |
catalogObj.put("hsnCode", item.getHsnCode());
|
| 309 |
catalogObj.put("title",
|
303 |
catalogObj.put("title",
|
| 310 |
String.join(" ", Arrays.asList(item.getBrand(), item.getModelName(), item.getModelNumber())
|
304 |
String.join(" ", Arrays.asList(item.getBrand(), item.getModelName(), item.getModelNumber())
|
| 311 |
.stream().filter(s -> s != null && !s.isEmpty()).collect(Collectors.toList())));
|
305 |
.stream().filter(s -> s != null && !s.isEmpty()).collect(Collectors.toList())));
|
| Line 373... |
Line 367... |
| 373 |
|
367 |
|
| 374 |
Map<String, Object> catalogObj = catalogMap.get(item.getCatalogItemId());
|
368 |
Map<String, Object> catalogObj = catalogMap.get(item.getCatalogItemId());
|
| 375 |
Map<Integer, Integer> avColorMap = (Map<Integer, Integer>) catalogObj.get("avColor");
|
369 |
Map<Integer, Integer> avColorMap = (Map<Integer, Integer>) catalogObj.get("avColor");
|
| 376 |
|
370 |
|
| 377 |
if (availabilityItemMap.containsKey(String.valueOf(item.getId()))) {
|
371 |
if (availabilityItemMap.containsKey(String.valueOf(item.getId()))) {
|
| - |
|
372 |
int itemStockColor = 0;
|
| 378 |
for (Map.Entry<String, Map<String, Integer>> entry : availabilityItemMap
|
373 |
for (Map.Entry<String, Map<String, Integer>> entry : availabilityItemMap
|
| 379 |
.get(String.valueOf(item.getId())).entrySet()) {
|
374 |
.get(String.valueOf(item.getId())).entrySet()) {
|
| 380 |
String warehouseId = entry.getKey();
|
375 |
String warehouseId = entry.getKey();
|
| 381 |
Map<String, Integer> avMap = entry.getValue();
|
376 |
Map<String, Integer> avMap = entry.getValue();
|
| 382 |
if (!avColorMap.containsKey(Integer.parseInt(warehouseId))) {
|
377 |
if (!avColorMap.containsKey(Integer.parseInt(warehouseId))) {
|
| Line 392... |
Line 387... |
| 392 |
color = Math.max(color, 0);
|
387 |
color = Math.max(color, 0);
|
| 393 |
}
|
388 |
}
|
| 394 |
avColorMap.put(Integer.parseInt(warehouseId), color);
|
389 |
avColorMap.put(Integer.parseInt(warehouseId), color);
|
| 395 |
|
390 |
|
| 396 |
catalogObj.put("avColor", avColorMap);
|
391 |
catalogObj.put("avColor", avColorMap);
|
| - |
|
392 |
if (color > itemStockColor) {
|
| - |
|
393 |
itemStockColor = color;
|
| - |
|
394 |
}
|
| - |
|
395 |
}
|
| - |
|
396 |
if (itemStockColor > 0 && itemStockColor > (Integer) catalogObj.get("stockColor")) {
|
| - |
|
397 |
catalogObj.put("stockColor", itemStockColor);
|
| 397 |
|
- |
|
| 398 |
}
|
398 |
}
|
| 399 |
|
- |
|
| 400 |
}
|
399 |
}
|
| 401 |
|
400 |
|
| 402 |
Map<Integer, Object> itemColorMap = (Map<Integer, Object>) catalogObj.get("items");
|
401 |
Map<Integer, Object> itemColorMap = (Map<Integer, Object>) catalogObj.get("items");
|
| 403 |
|
402 |
|
| 404 |
if (!itemColorMap.containsKey(item.getId())) {
|
403 |
if (!itemColorMap.containsKey(item.getId())) {
|
| Line 424... |
Line 423... |
| 424 |
boolean active = false;
|
423 |
boolean active = false;
|
| 425 |
// Map<Integer, Object> itemsMap = (Map<String, Object>)
|
424 |
// Map<Integer, Object> itemsMap = (Map<String, Object>)
|
| 426 |
// catalogValMap.get("items");
|
425 |
// catalogValMap.get("items");
|
| 427 |
List<SolrInputDocument> itemObjs = new ArrayList<>();
|
426 |
List<SolrInputDocument> itemObjs = new ArrayList<>();
|
| 428 |
float mop = 0;
|
427 |
float mop = 0;
|
| 429 |
float dp = 0;
|
- |
|
| 430 |
|
428 |
|
| 431 |
for (Entry<Integer, Object> itemEntry : itemsMap.entrySet()) {
|
429 |
for (Entry<Integer, Object> itemEntry : itemsMap.entrySet()) {
|
| 432 |
int itemId = itemEntry.getKey();
|
430 |
int itemId = itemEntry.getKey();
|
| 433 |
Map<String, Object> itemMap = (Map<String, Object>) itemEntry.getValue();
|
431 |
Map<String, Object> itemMap = (Map<String, Object>) itemEntry.getValue();
|
| 434 |
List<TagListing> tags = (List<TagListing>) itemMap.get("tagPricing");
|
432 |
List<TagListing> tags = (List<TagListing>) itemMap.get("tagPricing");
|
| Line 444... |
Line 442... |
| 444 |
itemObj.setField("mop_f", taglist.getMop());
|
442 |
itemObj.setField("mop_f", taglist.getMop());
|
| 445 |
itemObj.setField("sellingPrice_f", taglist.getSellingPrice());
|
443 |
itemObj.setField("sellingPrice_f", taglist.getSellingPrice());
|
| 446 |
itemObj.setField("active_b", taglist.isActive());
|
444 |
itemObj.setField("active_b", taglist.isActive());
|
| 447 |
itemObj.setField("hot_deal_b", taglist.isHotDeals());
|
445 |
itemObj.setField("hot_deal_b", taglist.isHotDeals());
|
| 448 |
mop = taglist.getMop();
|
446 |
mop = taglist.getMop();
|
| 449 |
dp = taglist.getSellingPrice();
|
447 |
catalogValMap.put("dp", taglist.getSellingPrice());
|
| 450 |
|
448 |
|
| 451 |
}
|
449 |
}
|
| 452 |
itemObjs.add(itemObj);
|
450 |
itemObjs.add(itemObj);
|
| 453 |
}
|
451 |
}
|
| 454 |
|
- |
|
| 455 |
float starPrice = dp - 500f;
|
- |
|
| 456 |
float endPrice = dp + 1000f;
|
- |
|
| 457 |
List<Integer> similalarModels = null;
|
- |
|
| 458 |
if ((Integer) catalogValMap.get("categoryId") == 3) {
|
- |
|
| 459 |
similalarModels = new ArrayList<>();
|
- |
|
| 460 |
for (Entry<Float, List<Integer>> floatListEntry : priceModelMap.entrySet()) {
|
- |
|
| 461 |
float modelPrice = floatListEntry.getKey();
|
- |
|
| 462 |
if (modelPrice >= starPrice && modelPrice <= endPrice) {
|
- |
|
| 463 |
similalarModels.addAll(floatListEntry.getValue());
|
- |
|
| 464 |
}
|
- |
|
| 465 |
if (modelPrice > endPrice) break;
|
- |
|
| 466 |
}
|
- |
|
| 467 |
similalarModels.remove(Integer.valueOf(catalogId));
|
- |
|
| 468 |
}
|
- |
|
| 469 |
|
- |
|
| 470 |
|
- |
|
| 471 |
logger.info("catalogValMap {}", catalogValMap);
|
452 |
//logger.info("catalogValMap {}", catalogValMap);
|
| 472 |
|
- |
|
| 473 |
logger.info("rank {}", catalogValMap.get("rank"));
|
453 |
//logger.info("rank {}", catalogValMap.get("rank"));
|
| 474 |
|
454 |
|
| 475 |
SolrInputDocument catalogSolrObj = new SolrInputDocument();
|
455 |
SolrInputDocument catalogSolrObj = new SolrInputDocument();
|
| 476 |
|
- |
|
| 477 |
catalogSolrObj.setField("id", "catalog" + catalogId);
|
456 |
catalogSolrObj.setField("id", "catalog" + catalogId);
|
| 478 |
catalogSolrObj.setField("rank_i", catalogValMap.get("rank"));
|
457 |
catalogSolrObj.setField("rank_i", catalogValMap.get("rank"));
|
| 479 |
catalogSolrObj.setField("similarModels_ii", similalarModels == null ? Collections.EMPTY_LIST : similalarModels);
|
- |
|
| 480 |
catalogSolrObj.setField("title_s", catalogValMap.get("title"));
|
458 |
catalogSolrObj.setField("title_s", catalogValMap.get("title"));
|
| 481 |
// catalogSolrObj.setField("_childDocuments_", itemObjs);
|
459 |
// catalogSolrObj.setField("_childDocuments_", itemObjs);
|
| 482 |
catalogSolrObj.addChildDocuments(itemObjs);
|
460 |
catalogSolrObj.addChildDocuments(itemObjs);
|
| 483 |
catalogSolrObj.setField("child_b", itemObjs.size() > 0);
|
461 |
catalogSolrObj.setField("child_b", itemObjs.size() > 0);
|
| 484 |
catalogSolrObj.setField("catalogId_i", catalogId);
|
462 |
catalogSolrObj.setField("catalogId_i", catalogId);
|
| Line 488... |
Line 466... |
| 488 |
catalogSolrObj.setField("brand_ss", catalogValMap.get("brand"));
|
466 |
catalogSolrObj.setField("brand_ss", catalogValMap.get("brand"));
|
| 489 |
catalogSolrObj.setField("create_s", catalogValMap.get("create_timestamp"));
|
467 |
catalogSolrObj.setField("create_s", catalogValMap.get("create_timestamp"));
|
| 490 |
catalogSolrObj.setField("categoryId_i", catalogValMap.get("categoryId"));
|
468 |
catalogSolrObj.setField("categoryId_i", catalogValMap.get("categoryId"));
|
| 491 |
catalogSolrObj.setField("subCategoryId_i", catalogValMap.get("subCategoryId"));
|
469 |
catalogSolrObj.setField("subCategoryId_i", catalogValMap.get("subCategoryId"));
|
| 492 |
catalogSolrObj.setField("label_ss", catalogValMap.get("labels"));
|
470 |
catalogSolrObj.setField("label_ss", catalogValMap.get("labels"));
|
| 493 |
for (Integer warehouseId : ProfitMandiConstants.WAREHOUSE_MAP.keySet()) {
|
- |
|
| 494 |
catalogSolrObj.setField("w" + warehouseId + "_i", 0);
|
- |
|
| 495 |
}
|
- |
|
| 496 |
catalogSolrObj.setField("mop_f", mop);
|
471 |
catalogSolrObj.setField("mop_f", mop);
|
| 497 |
catalogSolrObj.setField("hsncode_s", catalogValMap.get("hsnCode"));
|
472 |
catalogSolrObj.setField("hsncode_s", catalogValMap.get("hsnCode"));
|
| 498 |
catalogSolrObj.setField("show_default_b", true);
|
473 |
catalogSolrObj.setField("show_default_b", true);
|
| 499 |
|
474 |
|
| 500 |
String[] brands = (String[]) catalogValMap.get("brand");
|
475 |
String[] brands = (String[]) catalogValMap.get("brand");
|
| Line 509... |
Line 484... |
| 509 |
|
484 |
|
| 510 |
}
|
485 |
}
|
| 511 |
}
|
486 |
}
|
| 512 |
Map<Integer, Integer> avColorMap = (Map<Integer, Integer>) catalogValMap.get("avColor");
|
487 |
Map<Integer, Integer> avColorMap = (Map<Integer, Integer>) catalogValMap.get("avColor");
|
| 513 |
|
488 |
|
| - |
|
489 |
|
| - |
|
490 |
for (Integer warehouseId : ProfitMandiConstants.WAREHOUSE_MAP.keySet()) {
|
| - |
|
491 |
catalogSolrObj.setField("w" + warehouseId + "_i", 0);
|
| - |
|
492 |
}
|
| 514 |
for (Entry<Integer, Integer> avColorEntry : avColorMap.entrySet()) {
|
493 |
for (Entry<Integer, Integer> avColorEntry : avColorMap.entrySet()) {
|
| 515 |
int whId = avColorEntry.getKey();
|
494 |
int whId = avColorEntry.getKey();
|
| 516 |
int color = avColorEntry.getValue();
|
495 |
int color = avColorEntry.getValue();
|
| 517 |
catalogSolrObj.setField("w" + whId + "_i", color);
|
496 |
catalogSolrObj.setField("w" + whId + "_i", color);
|
| 518 |
}
|
497 |
}
|
| - |
|
498 |
|
| - |
|
499 |
List<Integer> similalarModels = null;
|
| - |
|
500 |
if ((Integer) catalogValMap.get("categoryId") == 3) {
|
| - |
|
501 |
float dp = (Float) catalogValMap.get("dp");
|
| - |
|
502 |
float starPrice = dp - 500f;
|
| - |
|
503 |
float endPrice = dp + 1000f;
|
| - |
|
504 |
similalarModels = new ArrayList<>();
|
| - |
|
505 |
for (Entry<Float, List<Integer>> floatListEntry : priceModelMap.entrySet()) {
|
| - |
|
506 |
float modelPrice = floatListEntry.getKey();
|
| - |
|
507 |
if (modelPrice >= starPrice && modelPrice <= endPrice) {
|
| - |
|
508 |
List<Integer> instock = floatListEntry.getValue().stream().filter(x->catalogMap.get(x).get("stockColor") != null && (Integer) (catalogMap.get(x).get("stockColor"))>0).collect(Collectors.toList());
|
| - |
|
509 |
logger.info("/Entry before - {}, after - {}", floatListEntry.getValue().size(), instock.size());
|
| - |
|
510 |
similalarModels.addAll(instock);
|
| - |
|
511 |
}
|
| - |
|
512 |
if (modelPrice > endPrice) break;
|
| - |
|
513 |
}
|
| - |
|
514 |
similalarModels.remove(Integer.valueOf(catalogId));
|
| - |
|
515 |
}
|
| - |
|
516 |
catalogSolrObj.setField("similarModels_ii", similalarModels == null ? Collections.EMPTY_LIST : similalarModels);
|
| - |
|
517 |
|
| - |
|
518 |
|
| 519 |
catalogSolrObj.setField("active_b", active);
|
519 |
catalogSolrObj.setField("active_b", active);
|
| 520 |
logger.info("catalogSolrObj {}", catalogSolrObj.get("rank_i"));
|
520 |
logger.info("catalogSolrObj {}", catalogSolrObj.get("rank_i"));
|
| 521 |
catalogSolrObjs.add(catalogSolrObj);
|
521 |
catalogSolrObjs.add(catalogSolrObj);
|
| 522 |
|
- |
|
| 523 |
}
|
522 |
}
|
| 524 |
|
523 |
|
| - |
|
524 |
|
| 525 |
logger.info("catalogSolrObjs {}", catalogSolrObjs);
|
525 |
logger.info("catalogSolrObjs {}", catalogSolrObjs);
|
| 526 |
|
526 |
|
| 527 |
String solrPath = "http://" + solrUrl + ":8984/solr/demo";
|
527 |
String solrPath = "http://" + solrUrl + ":8984/solr/demo";
|
| 528 |
SolrClient solr = new HttpSolrClient.Builder(solrPath).build();
|
528 |
SolrClient solr = new HttpSolrClient.Builder(solrPath).build();
|
| 529 |
|
529 |
|