| Line 571... |
Line 571... |
| 571 |
|
571 |
|
| 572 |
public void pushData() throws Exception {
|
572 |
public void pushData() throws Exception {
|
| 573 |
this.populateTagItems();
|
573 |
this.populateTagItems();
|
| 574 |
}
|
574 |
}
|
| 575 |
|
575 |
|
| - |
|
576 |
/**
|
| - |
|
577 |
* Updates a single catalog in Solr based on catalogId.
|
| - |
|
578 |
* Used for real-time updates when TagListing changes.
|
| - |
|
579 |
*
|
| - |
|
580 |
* @param catalogId The catalog ID to update
|
| - |
|
581 |
*/
|
| - |
|
582 |
public void updateSingleCatalog(int catalogId) throws Exception {
|
| - |
|
583 |
logger.info("Updating single catalog in Solr: catalogId={}", catalogId);
|
| - |
|
584 |
|
| - |
|
585 |
List<status> statuses = Arrays.asList(status.ACTIVE, status.PAUSED_BY_RISK, status.PARTIALLY_ACTIVE);
|
| - |
|
586 |
|
| - |
|
587 |
// Get all TagListings for this catalog
|
| - |
|
588 |
List<ItemTagModel> itemTagModels = tagListingRepository.getItemTagByCatalogIdAndStatus(catalogId, statuses);
|
| - |
|
589 |
|
| - |
|
590 |
if (itemTagModels.isEmpty()) {
|
| - |
|
591 |
logger.warn("No active TagListings found for catalogId={}, removing from Solr", catalogId);
|
| - |
|
592 |
String solrPath = "http://" + solrUrl + ":8984/solr/demo";
|
| - |
|
593 |
SolrClient solr = new HttpSolrClient.Builder(solrPath).build();
|
| - |
|
594 |
solr.deleteById("catalog" + catalogId);
|
| - |
|
595 |
solr.commit();
|
| - |
|
596 |
return;
|
| - |
|
597 |
}
|
| - |
|
598 |
|
| - |
|
599 |
// Get availability for items in this catalog
|
| - |
|
600 |
Map<String, Map<String, Map<String, Integer>>> availabilityItemMap = getItemMap();
|
| - |
|
601 |
|
| - |
|
602 |
// Get ranking info
|
| - |
|
603 |
List<TagRanking> tagRankingList = tagRankingRepository.getAllTagRanking();
|
| - |
|
604 |
List<Integer> rankingList = new ArrayList<>();
|
| - |
|
605 |
Map<Integer, String> featureMap = new HashMap<>();
|
| - |
|
606 |
for (TagRanking tagRanking : tagRankingList) {
|
| - |
|
607 |
rankingList.add(tagRanking.getCatalogItemId());
|
| - |
|
608 |
featureMap.put(tagRanking.getCatalogItemId(), tagRanking.getFeature());
|
| - |
|
609 |
}
|
| - |
|
610 |
|
| - |
|
611 |
// Get labels
|
| - |
|
612 |
Map<Integer, List<String>> catalogLabelMap = this.getLabels();
|
| - |
|
613 |
|
| - |
|
614 |
// Get EOL info
|
| - |
|
615 |
List<Integer> eolWithOutStock = catalogRepository.findAllWithEOLWithOutStock();
|
| - |
|
616 |
List<Integer> eolWithBadQty = catalogRepository.findAllWithNoGoodStock();
|
| - |
|
617 |
Set<Integer> eolSet = new HashSet<>(eolWithOutStock);
|
| - |
|
618 |
eolSet.addAll(eolWithBadQty);
|
| - |
|
619 |
|
| - |
|
620 |
// Build catalog document
|
| - |
|
621 |
com.spice.profitmandi.dao.entity.catalog.Item firstItem = itemTagModels.get(0).getItem();
|
| - |
|
622 |
TagListing firstTagListing = itemTagModels.get(0).getTagListing();
|
| - |
|
623 |
|
| - |
|
624 |
Map<Integer, Integer> avColorMap = new HashMap<>();
|
| - |
|
625 |
List<SolrInputDocument> itemObjs = new ArrayList<>();
|
| - |
|
626 |
boolean active = false;
|
| - |
|
627 |
float mop = 0;
|
| - |
|
628 |
float dp = 0;
|
| - |
|
629 |
int stockColor = 0;
|
| - |
|
630 |
|
| - |
|
631 |
for (ItemTagModel itemTagModel : itemTagModels) {
|
| - |
|
632 |
TagListing tagListing = itemTagModel.getTagListing();
|
| - |
|
633 |
com.spice.profitmandi.dao.entity.catalog.Item item = itemTagModel.getItem();
|
| - |
|
634 |
|
| - |
|
635 |
active = active || tagListing.isActive();
|
| - |
|
636 |
|
| - |
|
637 |
// Build item document
|
| - |
|
638 |
SolrInputDocument itemObj = new SolrInputDocument();
|
| - |
|
639 |
itemObj.setField("id", "itemtag-" + item.getId() + "-" + tagListing.getTagId());
|
| - |
|
640 |
itemObj.setField("color_s", item.getColor().replace("f_", ""));
|
| - |
|
641 |
itemObj.setField("itemId_i", item.getId());
|
| - |
|
642 |
itemObj.setField("tagId_i", tagListing.getTagId());
|
| - |
|
643 |
itemObj.setField("mrp_f", tagListing.getMrp());
|
| - |
|
644 |
itemObj.setField("mop_f", tagListing.getMop());
|
| - |
|
645 |
itemObj.setField("sellingPrice_f", tagListing.getSellingPrice());
|
| - |
|
646 |
itemObj.setField("active_b", tagListing.isActive());
|
| - |
|
647 |
itemObj.setField("hot_deal_b", tagListing.isHotDeals());
|
| - |
|
648 |
mop = tagListing.getMop();
|
| - |
|
649 |
dp = tagListing.getSellingPrice();
|
| - |
|
650 |
itemObjs.add(itemObj);
|
| - |
|
651 |
|
| - |
|
652 |
// Calculate availability color
|
| - |
|
653 |
if (availabilityItemMap.containsKey(String.valueOf(item.getId()))) {
|
| - |
|
654 |
int itemStockColor = 0;
|
| - |
|
655 |
for (Map.Entry<String, Map<String, Integer>> entry : availabilityItemMap
|
| - |
|
656 |
.get(String.valueOf(item.getId())).entrySet()) {
|
| - |
|
657 |
String warehouseId = entry.getKey();
|
| - |
|
658 |
Map<String, Integer> avMap = entry.getValue();
|
| - |
|
659 |
if (!avColorMap.containsKey(Integer.parseInt(warehouseId))) {
|
| - |
|
660 |
avColorMap.put(Integer.parseInt(warehouseId), 0);
|
| - |
|
661 |
}
|
| - |
|
662 |
int color = avColorMap.get(Integer.parseInt(warehouseId));
|
| - |
|
663 |
|
| - |
|
664 |
if (avMap.get("netAvailability") > 0) {
|
| - |
|
665 |
color = 2;
|
| - |
|
666 |
} else if (avMap.get("netPo") > 0) {
|
| - |
|
667 |
color = Math.max(color, 1);
|
| - |
|
668 |
} else {
|
| - |
|
669 |
color = Math.max(color, 0);
|
| - |
|
670 |
}
|
| - |
|
671 |
avColorMap.put(Integer.parseInt(warehouseId), color);
|
| - |
|
672 |
|
| - |
|
673 |
if (color > itemStockColor) {
|
| - |
|
674 |
itemStockColor = color;
|
| - |
|
675 |
}
|
| - |
|
676 |
}
|
| - |
|
677 |
if (itemStockColor > stockColor) {
|
| - |
|
678 |
stockColor = itemStockColor;
|
| - |
|
679 |
}
|
| - |
|
680 |
}
|
| - |
|
681 |
}
|
| - |
|
682 |
|
| - |
|
683 |
// Build catalog Solr document
|
| - |
|
684 |
SolrInputDocument catalogSolrObj = new SolrInputDocument();
|
| - |
|
685 |
catalogSolrObj.setField("id", "catalog" + catalogId);
|
| - |
|
686 |
catalogSolrObj.setField("rank_i", rankingList.indexOf(catalogId));
|
| - |
|
687 |
catalogSolrObj.setField("title_s", String.join(" ", Arrays.asList(
|
| - |
|
688 |
firstItem.getBrand(), firstItem.getModelName(), firstItem.getModelNumber())
|
| - |
|
689 |
.stream().filter(s -> s != null && !s.isEmpty()).collect(Collectors.toList())));
|
| - |
|
690 |
catalogSolrObj.addChildDocuments(itemObjs);
|
| - |
|
691 |
catalogSolrObj.setField("child_b", itemObjs.size() > 0);
|
| - |
|
692 |
catalogSolrObj.setField("catalogId_i", catalogId);
|
| - |
|
693 |
|
| - |
|
694 |
// Super catalog mapping
|
| - |
|
695 |
List<SuperCatalogModel> superCatalogMappingList = superCatalogMappingRepository.selectJoinedData();
|
| - |
|
696 |
List<SuperCatalogMapping> superCatalogs = superCatalogMappingRepository.selectAll();
|
| - |
|
697 |
Optional<SuperCatalogModel> superCatalogMapping = findMappingByCatalogId(superCatalogMappingList, catalogId, itemTagModels);
|
| - |
|
698 |
|
| - |
|
699 |
if (superCatalogMapping.isPresent()) {
|
| - |
|
700 |
int superCatalogId = superCatalogMapping.get().getSuperCatalogId();
|
| - |
|
701 |
String superCatalogMappingVariants = findMappingVariantsByCatalogId(superCatalogs, superCatalogId, itemTagModels);
|
| - |
|
702 |
catalogSolrObj.setField("superCatalog_i", superCatalogId);
|
| - |
|
703 |
catalogSolrObj.setField("superCatalog_s", superCatalogMapping.get().getSuperCatalogName());
|
| - |
|
704 |
catalogSolrObj.setField("superCatalogVariants_s", superCatalogMappingVariants);
|
| - |
|
705 |
} else {
|
| - |
|
706 |
catalogSolrObj.setField("superCatalog_i", 0);
|
| - |
|
707 |
catalogSolrObj.setField("superCatalog_s", catalogSolrObj.getFieldValue("title_s"));
|
| - |
|
708 |
catalogSolrObj.setField("superCatalogVariants_s", "[]");
|
| - |
|
709 |
}
|
| - |
|
710 |
|
| - |
|
711 |
// Image URL
|
| - |
|
712 |
try {
|
| - |
|
713 |
String imageUrl = contentMongoClient.getEntityById(catalogId).getDefaultImageUrl();
|
| - |
|
714 |
if (imageUrl != null) {
|
| - |
|
715 |
catalogSolrObj.setField("imageUrl_s", imageUrl.replace("saholic", "smartdukaan"));
|
| - |
|
716 |
} else {
|
| - |
|
717 |
catalogSolrObj.setField("imageUrl_s",
|
| - |
|
718 |
"https://images.smartdukaan.com/uploads/campaigns/" + catalogId + ".jpg");
|
| - |
|
719 |
}
|
| - |
|
720 |
} catch (Exception e) {
|
| - |
|
721 |
catalogSolrObj.setField("imageUrl_s",
|
| - |
|
722 |
"https://images.smartdukaan.com/uploads/campaigns/" + catalogId + ".jpg");
|
| - |
|
723 |
}
|
| - |
|
724 |
|
| - |
|
725 |
// Feature
|
| - |
|
726 |
if (featureMap.containsKey(catalogId) && featureMap.get(catalogId) != null) {
|
| - |
|
727 |
catalogSolrObj.setField("feature_s", featureMap.get(catalogId));
|
| - |
|
728 |
} else {
|
| - |
|
729 |
catalogSolrObj.setField("feature_s", "");
|
| - |
|
730 |
}
|
| - |
|
731 |
|
| - |
|
732 |
// Brand
|
| - |
|
733 |
String[] brands = new String[]{firstItem.getBrand()};
|
| - |
|
734 |
if (firstItem.getBrand().equals("Huawei") || firstItem.getBrand().equals("Honor")) {
|
| - |
|
735 |
brands = new String[]{"Huawei", "Honor"};
|
| - |
|
736 |
}
|
| - |
|
737 |
if (firstItem.getBrand().equals("Mi") || firstItem.getBrand().equals("Xiaomi")
|
| - |
|
738 |
|| firstItem.getBrand().equals("Redmi")) {
|
| - |
|
739 |
brands = new String[]{"Mi", "Xiaomi", "Redmi"};
|
| - |
|
740 |
}
|
| - |
|
741 |
catalogSolrObj.setField("brand_ss", brands);
|
| - |
|
742 |
|
| - |
|
743 |
// Category
|
| - |
|
744 |
catalogSolrObj.setField("categoryId_i", CATEGORY_MASTER.contains(firstItem.getCategoryId())
|
| - |
|
745 |
? (firstItem.getCategoryId() == 10006 ? 3 : firstItem.getCategoryId()) : 6);
|
| - |
|
746 |
catalogSolrObj.setField("subCategoryId_i", firstItem.getCategoryId());
|
| - |
|
747 |
|
| - |
|
748 |
// Timestamps and labels
|
| - |
|
749 |
catalogSolrObj.setField("create_s", firstTagListing.getCreatedTimestamp()
|
| - |
|
750 |
.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli());
|
| - |
|
751 |
if (catalogLabelMap.containsKey(catalogId) && catalogLabelMap.get(catalogId) != null) {
|
| - |
|
752 |
catalogSolrObj.setField("label_ss", catalogLabelMap.get(catalogId));
|
| - |
|
753 |
}
|
| - |
|
754 |
|
| - |
|
755 |
catalogSolrObj.setField("mop_f", mop);
|
| - |
|
756 |
catalogSolrObj.setField("dp_f", dp);
|
| - |
|
757 |
catalogSolrObj.setField("hsncode_s", firstItem.getHsnCode());
|
| - |
|
758 |
catalogSolrObj.setField("show_default_b", true);
|
| - |
|
759 |
|
| - |
|
760 |
for (String brand : brands) {
|
| - |
|
761 |
if (brand.equals("FOC") || brand.equals("Live Demo")) {
|
| - |
|
762 |
catalogSolrObj.setField("show_default_b", false);
|
| - |
|
763 |
}
|
| - |
|
764 |
}
|
| - |
|
765 |
|
| - |
|
766 |
// Warehouse availability
|
| - |
|
767 |
for (Integer warehouseId : ProfitMandiConstants.WAREHOUSE_MAP.keySet()) {
|
| - |
|
768 |
catalogSolrObj.setField("w" + warehouseId + "_i", 0);
|
| - |
|
769 |
}
|
| - |
|
770 |
for (Entry<Integer, Integer> avColorEntry : avColorMap.entrySet()) {
|
| - |
|
771 |
int whId = avColorEntry.getKey();
|
| - |
|
772 |
int color = avColorEntry.getValue();
|
| - |
|
773 |
catalogSolrObj.setField("w" + whId + "_i", color);
|
| - |
|
774 |
}
|
| - |
|
775 |
|
| - |
|
776 |
// Similar models - simplified for single update
|
| - |
|
777 |
catalogSolrObj.setField("similarModels_ii", Collections.EMPTY_LIST);
|
| - |
|
778 |
|
| - |
|
779 |
catalogSolrObj.setField("active_b", active);
|
| - |
|
780 |
catalogSolrObj.setField("eol_no_stock_b", eolSet.contains(catalogId));
|
| - |
|
781 |
|
| - |
|
782 |
// Push to Solr
|
| - |
|
783 |
String solrPath = "http://" + solrUrl + ":8984/solr/demo";
|
| - |
|
784 |
SolrClient solr = new HttpSolrClient.Builder(solrPath).build();
|
| - |
|
785 |
|
| - |
|
786 |
// Delete existing and add updated document
|
| - |
|
787 |
solr.deleteById("catalog" + catalogId);
|
| - |
|
788 |
solr.add(catalogSolrObj);
|
| - |
|
789 |
solr.commit();
|
| - |
|
790 |
|
| - |
|
791 |
logger.info("Successfully updated catalogId={} in Solr", catalogId);
|
| - |
|
792 |
}
|
| - |
|
793 |
|
| 576 |
public Optional<SuperCatalogModel> findMappingByCatalogId(List<SuperCatalogModel> superCatalogMappingList, int id, List<ItemTagModel> itemTagModels) {
|
794 |
public Optional<SuperCatalogModel> findMappingByCatalogId(List<SuperCatalogModel> superCatalogMappingList, int id, List<ItemTagModel> itemTagModels) {
|
| 577 |
if (itemTagModels.stream().anyMatch(tag -> tag.getItem().getCatalogItemId() == id && tag.getTagListing().isActive())) {
|
795 |
if (itemTagModels.stream().anyMatch(tag -> tag.getItem().getCatalogItemId() == id && tag.getTagListing().isActive())) {
|
| 578 |
return superCatalogMappingList.stream().filter(mapping -> mapping.getCatalogId() == id).findFirst();
|
796 |
return superCatalogMappingList.stream().filter(mapping -> mapping.getCatalogId() == id).findFirst();
|
| 579 |
}
|
797 |
}
|
| 580 |
return Optional.empty();
|
798 |
return Optional.empty();
|