Subversion Repositories SmartDukaan

Rev

Rev 37247 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 37247 Rev 37250
Line 79... Line 79...
79
 
79
 
80
import javax.servlet.http.HttpServletRequest;
80
import javax.servlet.http.HttpServletRequest;
81
import java.time.LocalDate;
81
import java.time.LocalDate;
82
import java.time.LocalDateTime;
82
import java.time.LocalDateTime;
83
import java.util.*;
83
import java.util.*;
-
 
84
import java.util.concurrent.CompletableFuture;
-
 
85
import java.util.concurrent.CompletionException;
-
 
86
import java.util.concurrent.ExecutorService;
-
 
87
import java.util.concurrent.Executors;
84
import java.util.concurrent.atomic.AtomicInteger;
88
import java.util.concurrent.atomic.AtomicInteger;
85
import java.util.stream.Collectors;
89
import java.util.stream.Collectors;
86
 
90
 
87
@Controller
91
@Controller
88
@Transactional(rollbackFor = Throwable.class)
92
@Transactional(rollbackFor = Throwable.class)
Line 820... Line 824...
820
            }
824
            }
821
        }
825
        }
822
        return responseSender.ok(responseObject);
826
        return responseSender.ok(responseObject);
823
    }
827
    }
824
 
828
 
-
 
829
    // Fans out the per-listing Solr HTTP calls only; every DB access stays on the request
-
 
830
    // thread because the Hibernate session is thread-bound. Pool size matches the
-
 
831
    // RestClient per-route connection limit.
-
 
832
    private static final ExecutorService SOLR_EXECUTOR = Executors.newFixedThreadPool(8, r -> {
-
 
833
        Thread t = new Thread(r, "partner-listing-solr");
-
 
834
        t.setDaemon(true);
-
 
835
        return t;
-
 
836
    });
-
 
837
 
825
    @RequestMapping(value = "/partner/listing", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
838
    @RequestMapping(value = "/partner/listing", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
826
    public ResponseEntity<?> getPartnersListing(HttpServletRequest request) throws Exception {
839
    public ResponseEntity<?> getPartnersListing(HttpServletRequest request) throws Exception {
827
        List<WebListing> webListings = webListingRepository.selectAllWebListingByType(Optional.of(true), WebListingSource.partner);
840
        List<WebListing> webListings = webListingRepository.selectAllWebListingByType(Optional.of(true), WebListingSource.partner);
828
        UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
841
        UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
-
 
842
        int fofoId = userInfo.getRetailerId();
-
 
843
        FofoStore fs = fofoStoreRepository.selectByRetailerId(fofoId);
829
 
844
 
-
 
845
        // Build every listing's Solr query on the request thread; the brand exclusion is
830
        // Pre-fetch FofoStore once (instead of N times inside getDealResponses)
846
        // partner-scoped, so resolve it once instead of per listing.
831
        FofoStore fs = fofoStoreRepository.selectByRetailerId(userInfo.getRetailerId());
847
        String exclusionFq = SolrService.brandExclusionFq(brandsService.restrictedBrands(fofoId));
832
 
-
 
-
 
848
        List<ListingQuery> queries = new ArrayList<>();
833
        for (WebListing webListing : webListings) {
849
        for (WebListing webListing : webListings) {
-
 
850
            ListingQuery query = buildListingQuery(webListing, fs.getWarehouseId(), 0, 20);
-
 
851
            if (query.params != null && exclusionFq != null) {
-
 
852
                query.params.put("fq", exclusionFq);
-
 
853
            }
-
 
854
            queries.add(query);
-
 
855
        }
-
 
856
 
-
 
857
        Map<Integer, CompletableFuture<JSONArray>> futures = new HashMap<>();
-
 
858
        for (int i = 0; i < queries.size(); i++) {
-
 
859
            Map<String, String> params = queries.get(i).params;
-
 
860
            if (params != null) {
-
 
861
                futures.put(i, CompletableFuture.supplyAsync(() -> {
-
 
862
                    try {
-
 
863
                        return partnerSolrClient.selectDocsRaw(params);
-
 
864
                    } catch (ProfitMandiBusinessException e) {
-
 
865
                        throw new CompletionException(e);
-
 
866
                    }
-
 
867
                }, SOLR_EXECUTOR));
-
 
868
            }
-
 
869
        }
-
 
870
 
-
 
871
        Map<Integer, JSONArray> docsByListing = new HashMap<>();
-
 
872
        Set<Integer> allCatalogIds = new LinkedHashSet<>();
-
 
873
        Set<Integer> allItemIds = new LinkedHashSet<>();
-
 
874
        for (Map.Entry<Integer, CompletableFuture<JSONArray>> entry : futures.entrySet()) {
-
 
875
            JSONArray docs;
-
 
876
            try {
-
 
877
                docs = entry.getValue().join();
-
 
878
            } catch (CompletionException e) {
-
 
879
                throw e.getCause() instanceof Exception ? (Exception) e.getCause() : e;
-
 
880
            }
-
 
881
            docsByListing.put(entry.getKey(), docs);
-
 
882
            allCatalogIds.addAll(extractCatalogIds(docs));
-
 
883
            allItemIds.addAll(extractItemIds(docs));
-
 
884
        }
-
 
885
 
-
 
886
        CatalogBatchData batch = allItemIds.isEmpty() ? null
-
 
887
                : buildCatalogBatchData(fofoId, fs.getWarehouseId(), new ArrayList<>(allCatalogIds), new ArrayList<>(allItemIds));
-
 
888
 
-
 
889
        for (int i = 0; i < queries.size(); i++) {
-
 
890
            ListingQuery query = queries.get(i);
-
 
891
            JSONArray docs = docsByListing.get(i);
-
 
892
            List<FofoCatalogResponse> dealResponse;
-
 
893
            if (docs == null || batch == null) {
-
 
894
                dealResponse = new ArrayList<>();
-
 
895
            } else {
-
 
896
                dealResponse = buildCatalogResponses(docs, false, fofoId, batch);
-
 
897
                if (query.webProducts != null && query.webListing.getUrl().equals("new-launches")) {
-
 
898
                    List<Integer> webProductsFinal = query.webProducts;
-
 
899
                    dealResponse = dealResponse.stream().sorted(Comparator.comparing(x -> webProductsFinal.indexOf(x.getCatalogId()))).collect(Collectors.toList());
-
 
900
                }
-
 
901
            }
834
            webListing.setFofoCatalogResponses(getDealResponses(userInfo, fs, webListing, 0, 20));
902
            query.webListing.setFofoCatalogResponses(dealResponse);
835
        }
903
        }
836
        return responseSender.ok(webListings);
904
        return responseSender.ok(webListings);
837
    }
905
    }
838
 
906
 
839
    private List<FofoCatalogResponse> getDealResponses(UserInfo userInfo, FofoStore fs, WebListing webListing, int offset, int limit) throws Exception {
907
    private List<FofoCatalogResponse> getDealResponses(UserInfo userInfo, FofoStore fs, WebListing webListing, int offset, int limit) throws Exception {
-
 
908
        ListingQuery query = buildListingQuery(webListing, fs.getWarehouseId(), offset, limit);
-
 
909
        if (query.params == null) {
-
 
910
            return new ArrayList<>();
-
 
911
        }
-
 
912
        JSONArray docs = partnerSolrClient.selectDocs(query.params, userInfo.getRetailerId());
-
 
913
        List<FofoCatalogResponse> dealResponse = getCatalogResponse(docs, false, userInfo.getRetailerId());
-
 
914
 
-
 
915
        if (query.webProducts != null && webListing.getUrl().equals("new-launches")) {
-
 
916
            List<Integer> webProductsFinal = query.webProducts;
-
 
917
            dealResponse = dealResponse.stream().sorted(Comparator.comparing(x -> webProductsFinal.indexOf(x.getCatalogId()))).collect(Collectors.toList());
-
 
918
        }
-
 
919
 
-
 
920
        return dealResponse;
-
 
921
    }
-
 
922
 
-
 
923
    /** Solr query for one web listing; params is null when a curated listing has no ranked products. */
-
 
924
    private static class ListingQuery {
-
 
925
        WebListing webListing;
-
 
926
        Map<String, String> params;
-
 
927
        List<Integer> webProducts;
-
 
928
    }
-
 
929
 
-
 
930
    private ListingQuery buildListingQuery(WebListing webListing, int warehouseId, int offset, int limit) {
-
 
931
        ListingQuery query = new ListingQuery();
-
 
932
        query.webListing = webListing;
840
 
933
 
841
        Map<String, String> params = new HashMap<>();
934
        Map<String, String> params = new HashMap<>();
842
        List<String> mandatoryQ = new ArrayList<>();
935
        List<String> mandatoryQ = new ArrayList<>();
-
 
936
        params.put("sort", "w" + warehouseId + "_i desc");
843
 
937
 
844
        params.put("sort", "w" + fs.getWarehouseId() + "_i desc");
-
 
845
 
-
 
846
        List<Integer> webProducts = null;
-
 
847
        if (webListing.getType().equals(WebListingType.solr)) {
938
        if (webListing.getType().equals(WebListingType.solr)) {
848
            logger.info("solrtype {}", webListing.getSolrQuery());
-
 
849
            mandatoryQ.add(String.format("+{!parent which=\"" + webListing.getSolrQuery() + "\"} AND active_b:true AND show_default_b:true"));
939
            mandatoryQ.add(String.format("+{!parent which=\"" + webListing.getSolrQuery() + "\"} AND active_b:true AND show_default_b:true"));
850
        } else {
940
        } else {
851
            logger.info("solrtype2 {}", webListing.getSolrQuery());
941
            query.webProducts = webProductListingRepository.selectAllByWebListingId(webListing.getId(), offset, limit).stream().filter(x -> x.getRank() > 0).map(x -> x.getEntityId()).collect(Collectors.toList());
852
 
942
 
853
            webProducts = webProductListingRepository.selectAllByWebListingId(webListing.getId(), offset, limit).stream().filter(x -> x.getRank() > 0).map(x -> x.getEntityId()).collect(Collectors.toList());
-
 
854
 
-
 
855
            if (webProducts.size() == 0) {
943
            if (query.webProducts.size() == 0) {
856
                return new ArrayList<>();
944
                return query;
857
            }
945
            }
858
 
946
 
859
            mandatoryQ.add(String.format(
947
            mandatoryQ.add(String.format(
860
                    "+{!parent which=\"catalogId_i:(" + StringUtils.join(webProducts, " ") + ")\"} AND active_b:true AND show_default_b:true"));
948
                    "+{!parent which=\"catalogId_i:(" + StringUtils.join(query.webProducts, " ") + ")\"} AND active_b:true AND show_default_b:true"));
861
 
-
 
862
        }
949
        }
863
        params.put("q", StringUtils.join(mandatoryQ, " "));
950
        params.put("q", StringUtils.join(mandatoryQ, " "));
864
        params.put("fl", "*, [child parentFilter=id:catalog* childFilter=active_b:true ]");
951
        params.put("fl", "*, [child parentFilter=id:catalog* childFilter=active_b:true ]");
865
 
952
 
866
        params.put("start", String.valueOf(offset));
953
        params.put("start", String.valueOf(offset));
867
        params.put("rows", String.valueOf(limit));
954
        params.put("rows", String.valueOf(limit));
868
        params.put("wt", "json");
955
        params.put("wt", "json");
869
        JSONArray docs = partnerSolrClient.selectDocs(params, userInfo.getRetailerId());
-
 
870
        List<FofoCatalogResponse> dealResponse = getCatalogResponse(docs, false, userInfo.getRetailerId());
-
 
871
 
-
 
872
        if (webProducts != null && webListing.getUrl().equals("new-launches")) {
-
 
873
            List<Integer> webProductsFinal = webProducts;
956
        query.params = params;
874
            dealResponse = dealResponse.stream().sorted(Comparator.comparing(x -> webProductsFinal.indexOf(x.getCatalogId()))).collect(Collectors.toList());
-
 
875
 
-
 
876
        }
-
 
877
 
-
 
878
        return dealResponse;
957
        return query;
879
    }
958
    }
880
 
959
 
881
    @Autowired
960
    @Autowired
882
    private SaholicCISTableRepository saholicCISTableRepository;
961
    private SaholicCISTableRepository saholicCISTableRepository;
883
 
962
 
884
    private List<FofoCatalogResponse> getCatalogResponse(JSONArray docs, boolean hotDeal, int fofoId) throws Exception {
963
    private List<FofoCatalogResponse> getCatalogResponse(JSONArray docs, boolean hotDeal, int fofoId) throws Exception {
-
 
964
        List<Integer> itemIds = extractItemIds(docs);
-
 
965
        if (itemIds.isEmpty()) {
-
 
966
            return new ArrayList<>();
-
 
967
        }
-
 
968
        int warehouseId = fofoStoreRepository.selectByRetailerId(fofoId).getWarehouseId();
-
 
969
        CatalogBatchData batch = buildCatalogBatchData(fofoId, warehouseId, extractCatalogIds(docs), itemIds);
885
        List<FofoCatalogResponse> dealResponse = new ArrayList<>();
970
        return buildCatalogResponses(docs, hotDeal, fofoId, batch);
-
 
971
    }
-
 
972
 
886
        List<Integer> tagIds = Arrays.asList(4);
973
    private List<Integer> extractItemIds(JSONArray docs) {
887
        List<Integer> itemIds = new ArrayList<>();
974
        List<Integer> itemIds = new ArrayList<>();
888
        Map<Integer, Integer> partnerStockAvailabilityMap = null;
-
 
889
        if (docs.length() > 0) {
-
 
890
            for (int i = 0; i < docs.length(); i++) {
975
        for (int i = 0; i < docs.length(); i++) {
891
                JSONObject doc = docs.getJSONObject(i);
976
            JSONObject doc = docs.getJSONObject(i);
892
                if (doc.has("_childDocuments_")) {
977
            if (doc.has("_childDocuments_")) {
893
                    for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
978
                for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
894
                        JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
979
                    itemIds.add(doc.getJSONArray("_childDocuments_").getJSONObject(j).getInt("itemId_i"));
895
                        int itemId = childItem.getInt("itemId_i");
-
 
896
                        itemIds.add(itemId);
-
 
897
                    }
-
 
898
                }
980
                }
899
            }
981
            }
900
        }
982
        }
901
        if (itemIds.isEmpty()) {
-
 
902
            return dealResponse;
983
        return itemIds;
903
        }
984
    }
904
        // get warehouse Id
-
 
-
 
985
 
905
        int warehouseId = fofoStoreRepository.selectByRetailerId(fofoId).getWarehouseId();
986
    private List<Integer> extractCatalogIds(JSONArray docs) {
906
        Map<Integer, List<SaholicPOItem>> poItemAvailabilityMap = saholicInventoryService.getSaholicPOItems().get(warehouseId);
-
 
907
        List<Integer> catalogIds = new ArrayList<>();
987
        List<Integer> catalogIds = new ArrayList<>();
908
        for (int i = 0; i < docs.length(); i++) {
988
        for (int i = 0; i < docs.length(); i++) {
909
            JSONObject doc = docs.getJSONObject(i);
-
 
910
            catalogIds.add(doc.getInt("catalogId_i"));
989
            catalogIds.add(docs.getJSONObject(i).getInt("catalogId_i"));
911
        }
990
        }
-
 
991
        return catalogIds;
-
 
992
    }
-
 
993
 
-
 
994
    /** Partner-level data shared by every catalog response built in one request. */
-
 
995
    private static class CatalogBatchData {
-
 
996
        int warehouseId;
-
 
997
        Map<Integer, List<SaholicPOItem>> poItemAvailabilityMap;
-
 
998
        Map<Integer, Integer> partnerStockAvailabilityMap;
-
 
999
        Set<Integer> favouriteCatalogIds;
912
        List<CreateOfferRequest> allSchemOffers = null;
1000
        Map<Integer, List<WebOffer>> webOffersMap;
-
 
1001
        Map<Integer, List<ComboModel>> comboModelsByCatalogId;
913
        Map<Integer, PriceCircularItemModelNew> priceCircularItemModelMap = new HashMap<>();
1002
        Map<Integer, PriceCircularItemModelNew> priceCircularItemModelMap;
-
 
1003
        Map<Integer, List<CreateOfferRequest>> schemeOffersByCatalogId;
-
 
1004
        Map<Integer, List<SaholicCISTable>> cisDataByItemId;
-
 
1005
        Map<Integer, Item> itemMap;
-
 
1006
        Map<Integer, Float> cashbackMap;
-
 
1007
    }
-
 
1008
 
-
 
1009
    private CatalogBatchData buildCatalogBatchData(int fofoId, int warehouseId, List<Integer> catalogIds, List<Integer> itemIds) throws Exception {
-
 
1010
        CatalogBatchData batch = new CatalogBatchData();
-
 
1011
        batch.warehouseId = warehouseId;
-
 
1012
        batch.poItemAvailabilityMap = saholicInventoryService.getSaholicPOItems().get(warehouseId);
-
 
1013
 
-
 
1014
        batch.priceCircularItemModelMap = new HashMap<>();
-
 
1015
        batch.schemeOffersByCatalogId = new HashMap<>();
914
        if (catalogIds.size() > 0) {
1016
        if (catalogIds.size() > 0) {
915
            PriceCircularModel priceCircularModel = priceCircularService.getPriceCircularByOffer(fofoId, catalogIds, LocalDate.now());
1017
            PriceCircularModel priceCircularModel = priceCircularService.getPriceCircularByOffer(fofoId, catalogIds, LocalDate.now());
916
            allSchemOffers = priceCircularModel.getOffers();
1018
            List<CreateOfferRequest> allSchemOffers = priceCircularModel.getOffers();
917
 
1019
 
918
            List<PriceCircularItemModelNew> priceCircularItemModelNews = priceCircularModel.getPriceCircularItemModelNews();
1020
            List<PriceCircularItemModelNew> priceCircularItemModelNews = priceCircularModel.getPriceCircularItemModelNews();
919
            if (priceCircularItemModelNews != null) {
1021
            if (priceCircularItemModelNews != null) {
920
                priceCircularItemModelMap = priceCircularItemModelNews.stream().collect(Collectors.toMap(x -> x.getCatalogId(), x -> x));
1022
                batch.priceCircularItemModelMap = priceCircularItemModelNews.stream().collect(Collectors.toMap(x -> x.getCatalogId(), x -> x));
-
 
1023
            }
-
 
1024
            // Filter null slab payouts and align the surviving ones with the offer list exactly
-
 
1025
            // once per catalog. The models are shared when a catalog appears in more than one
-
 
1026
            // listing, and the iterator.remove() below breaks the index alignment on a second pass.
-
 
1027
            for (PriceCircularItemModelNew model : batch.priceCircularItemModelMap.values()) {
-
 
1028
                if (model.getSlabPayouts() == null) {
-
 
1029
                    continue;
-
 
1030
                }
-
 
1031
                List<CreateOfferRequest> schemeOffers = new ArrayList<>();
-
 
1032
                Iterator<Map<Integer, AmountModel>> iterator = model.getSlabPayouts().iterator();
-
 
1033
                int iteratorCount = 0;
-
 
1034
                while (iterator.hasNext()) {
-
 
1035
                    Map<Integer, AmountModel> slabPayoutMap = iterator.next();
-
 
1036
                    if (slabPayoutMap != null) {
-
 
1037
                        schemeOffers.add(allSchemOffers.get(iteratorCount));
-
 
1038
                    } else {
-
 
1039
                        iterator.remove();
-
 
1040
                    }
-
 
1041
                    iteratorCount++;
-
 
1042
                }
-
 
1043
                batch.schemeOffersByCatalogId.put(model.getCatalogId(), schemeOffers);
921
            }
1044
            }
922
        }
1045
        }
923
 
1046
 
924
        /*List<CatalogFavourite> catalogFavourites = catalogFavouriteRepository.selectBypartnerId(fofoId);
-
 
925
        List<Integer> catalogFavouriteIds = new ArrayList<>();
-
 
926
        if (!catalogFavourites.isEmpty()) {
-
 
927
            catalogFavouriteIds = catalogFavourites.stream().map(x -> x.getCatalogId()).collect(Collectors.toList());
-
 
928
        }
-
 
929
 
-
 
930
        if (!catalogFavourites.isEmpty()) {
-
 
931
            catalogFavourites.stream().collect(Collectors.toMap(x -> x.getCatalogId(), x -> x));
-
 
932
        }*/
-
 
933
 
-
 
934
        if (fofoId > 0) {
1047
        if (fofoId > 0) {
935
            partnerStockAvailabilityMap = currentInventorySnapshotRepository.selectItemsStock(fofoId).stream().collect(Collectors.toMap(x -> x.getItemId(), x -> x.getAvailability()));
1048
            batch.partnerStockAvailabilityMap = currentInventorySnapshotRepository.selectItemsStock(fofoId).stream().collect(Collectors.toMap(x -> x.getItemId(), x -> x.getAvailability()));
936
            logger.info("partnerStockAvailabilityMap: {}",partnerStockAvailabilityMap);
-
 
937
        }
1049
        }
938
        List<CatalogFavourite> catalogFavouriteList = catalogFavouriteRepository.selectBypartnerId(fofoId);
1050
        batch.favouriteCatalogIds = catalogFavouriteRepository.selectBypartnerId(fofoId).stream()
939
        Set<Integer> favouriteCatalogIds = catalogFavouriteList.stream()
-
 
940
                .map(CatalogFavourite::getCatalogId)
1051
                .map(CatalogFavourite::getCatalogId)
941
                .collect(Collectors.toSet());
1052
                .collect(Collectors.toSet());
942
 
1053
 
943
        // Pre-fetch CIS data for all items (batch query instead of N+1)
-
 
944
        Map<Integer, List<SaholicCISTable>> cisDataByItemId = saholicCISTableRepository
1054
        batch.cisDataByItemId = saholicCISTableRepository
945
                .selectByItemWarehouse(itemIds, warehouseId).stream()
1055
                .selectByItemWarehouse(itemIds, warehouseId).stream()
946
                .collect(Collectors.groupingBy(SaholicCISTable::getItemId));
1056
                .collect(Collectors.groupingBy(SaholicCISTable::getItemId));
947
 
1057
 
948
        // Pre-fetch all Items (batch query instead of N+1)
-
 
949
        Map<Integer, Item> itemMap = itemRepository.selectByIds(new HashSet<>(itemIds)).stream()
1058
        batch.itemMap = itemRepository.selectByIds(new HashSet<>(itemIds)).stream()
950
                .collect(Collectors.toMap(Item::getId, x -> x));
1059
                .collect(Collectors.toMap(Item::getId, x -> x));
951
 
1060
 
952
        // Pre-fetch cashback data for all catalogs (batch query instead of N+1)
-
 
953
        Map<Integer, Float> cashbackMap = schemeService.getCatalogSchemeCashBack(fofoId, catalogIds);
1061
        batch.cashbackMap = schemeService.getCatalogSchemeCashBack(fofoId, catalogIds);
954
 
1062
 
955
        // Pre-fetch web offers (call once instead of inside loop)
-
 
956
        Map<Integer, List<WebOffer>> webOffersMap = webOfferRepository.selectAllActiveOffers();
1063
        batch.webOffersMap = webOfferRepository.selectAllActiveOffers();
957
 
1064
 
958
        // Pre-fetch combo models (call once instead of inside loop)
-
 
959
        Map<Integer, List<ComboModel>> comboModelsByCatalogId = comboModelRepository.selectByWarehouseId(warehouseId)
1065
        batch.comboModelsByCatalogId = comboModelRepository.selectByWarehouseId(warehouseId)
960
                .stream().collect(Collectors.groupingBy(ComboModel::getCatalogId));
1066
                .stream().collect(Collectors.groupingBy(ComboModel::getCatalogId));
-
 
1067
        return batch;
-
 
1068
    }
-
 
1069
 
-
 
1070
    private List<FofoCatalogResponse> buildCatalogResponses(JSONArray docs, boolean hotDeal, int fofoId, CatalogBatchData batch) throws Exception {
-
 
1071
        List<FofoCatalogResponse> dealResponse = new ArrayList<>();
-
 
1072
        int warehouseId = batch.warehouseId;
-
 
1073
        Map<Integer, List<SaholicPOItem>> poItemAvailabilityMap = batch.poItemAvailabilityMap;
-
 
1074
        Map<Integer, Integer> partnerStockAvailabilityMap = batch.partnerStockAvailabilityMap;
-
 
1075
        Set<Integer> favouriteCatalogIds = batch.favouriteCatalogIds;
-
 
1076
        Map<Integer, List<WebOffer>> webOffersMap = batch.webOffersMap;
-
 
1077
        Map<Integer, List<ComboModel>> comboModelsByCatalogId = batch.comboModelsByCatalogId;
-
 
1078
        Map<Integer, PriceCircularItemModelNew> priceCircularItemModelMap = batch.priceCircularItemModelMap;
-
 
1079
        Map<Integer, List<SaholicCISTable>> cisDataByItemId = batch.cisDataByItemId;
-
 
1080
        Map<Integer, Item> itemMap = batch.itemMap;
-
 
1081
        Map<Integer, Float> cashbackMap = batch.cashbackMap;
961
 
1082
 
962
        for (int i = 0; i < docs.length(); i++) {
1083
        for (int i = 0; i < docs.length(); i++) {
963
            Map<Integer, FofoAvailabilityInfo> fofoAvailabilityInfoMap = new HashMap<>();
1084
            Map<Integer, FofoAvailabilityInfo> fofoAvailabilityInfoMap = new HashMap<>();
964
            JSONObject doc = docs.getJSONObject(i);
1085
            JSONObject doc = docs.getJSONObject(i);
965
            FofoCatalogResponse fofoCatalogResponse = new FofoCatalogResponse();
1086
            FofoCatalogResponse fofoCatalogResponse = new FofoCatalogResponse();
Line 999... Line 1120...
999
                fofoCatalogResponse.setFeature(null);
1120
                fofoCatalogResponse.setFeature(null);
1000
                logger.info("Could not find Feature_s for {}", fofoCatalogResponse.getCatalogId());
1121
                logger.info("Could not find Feature_s for {}", fofoCatalogResponse.getCatalogId());
1001
            }
1122
            }
1002
 
1123
 
1003
            fofoCatalogResponse.setBrand(doc.getJSONArray("brand_ss").getString(0));
1124
            fofoCatalogResponse.setBrand(doc.getJSONArray("brand_ss").getString(0));
1004
            logger.info("labelss {}", doc.has("label_ss"));
-
 
1005
 
1125
 
1006
            if (doc.has("label_ss")) {
1126
            if (doc.has("label_ss")) {
1007
                logger.info("label {}", doc.getJSONArray("label_ss"));
-
 
1008
 
-
 
1009
                JSONArray arr = doc.getJSONArray("label_ss");
1127
                JSONArray arr = doc.getJSONArray("label_ss");
1010
                Set<String> labels = new HashSet<String>();
1128
                Set<String> labels = new HashSet<String>();
1011
                for (int j = 0; j < arr.length(); j++) {
1129
                for (int j = 0; j < arr.length(); j++) {
1012
                    labels.add(arr.getString(j));
1130
                    labels.add(arr.getString(j));
1013
                }
1131
                }
Line 1135... Line 1253...
1135
            if (fofoAvailabilityInfoMap.values().size() > 0) {
1253
            if (fofoAvailabilityInfoMap.values().size() > 0) {
1136
                List<FofoAvailabilityInfo> availabilityList = fofoAvailabilityInfoMap.values().stream().sorted(Comparator.comparing(FofoAvailabilityInfo::getAvailability).reversed()).collect(Collectors.toList());
1254
                List<FofoAvailabilityInfo> availabilityList = fofoAvailabilityInfoMap.values().stream().sorted(Comparator.comparing(FofoAvailabilityInfo::getAvailability).reversed()).collect(Collectors.toList());
1137
                fofoCatalogResponse.setItems(availabilityList);
1255
                fofoCatalogResponse.setItems(availabilityList);
1138
                if (priceCircularItemModelMap.containsKey(fofoCatalogResponse.getCatalogId())) {
1256
                if (priceCircularItemModelMap.containsKey(fofoCatalogResponse.getCatalogId())) {
1139
                    PriceCircularItemModelNew priceCircularItemModel = priceCircularItemModelMap.get(fofoCatalogResponse.getCatalogId());
1257
                    PriceCircularItemModelNew priceCircularItemModel = priceCircularItemModelMap.get(fofoCatalogResponse.getCatalogId());
1140
                    if (priceCircularItemModel.getSlabPayouts() != null) {
-
 
1141
                        List<CreateOfferRequest> schemeOffers = new ArrayList<>();
1258
                    List<CreateOfferRequest> schemeOffers = batch.schemeOffersByCatalogId.get(fofoCatalogResponse.getCatalogId());
1142
                        List<Map<Integer, AmountModel>> slabPayouts = priceCircularItemModel.getSlabPayouts();
-
 
1143
                        Iterator<Map<Integer, AmountModel>> iterator = slabPayouts.iterator();
-
 
1144
                        int iteratorCount = 0;
-
 
1145
                        while (iterator.hasNext()) {
-
 
1146
                            Map<Integer, AmountModel> slabPayoutMap = iterator.next();
-
 
1147
                            if (slabPayoutMap != null) {
1259
                    if (schemeOffers != null) {
1148
                                schemeOffers.add(allSchemOffers.get(iteratorCount));
-
 
1149
                            } else {
-
 
1150
                                iterator.remove();
-
 
1151
                            }
-
 
1152
                            iteratorCount++;
-
 
1153
                        }
-
 
1154
                        fofoCatalogResponse.setSchemeOffers(schemeOffers);
1260
                        fofoCatalogResponse.setSchemeOffers(schemeOffers);
1155
                    }
1261
                    }
1156
                    fofoCatalogResponse.setPriceCircularItemModel(priceCircularItemModel);
1262
                    fofoCatalogResponse.setPriceCircularItemModel(priceCircularItemModel);
1157
                }
1263
                }
1158
                dealResponse.add(fofoCatalogResponse);
1264
                dealResponse.add(fofoCatalogResponse);