Subversion Repositories SmartDukaan

Rev

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

Rev 36654 Rev 36680
Line 2857... Line 2857...
2857
        // Batch fetch all tagListings using pre-fetched items to avoid duplicate item fetch
2857
        // Batch fetch all tagListings using pre-fetched items to avoid duplicate item fetch
2858
        Map<Integer, TagListing> tagListingByCatalogIdMap = tagListingRepository
2858
        Map<Integer, TagListing> tagListingByCatalogIdMap = tagListingRepository
2859
                .selectAllByItems(allItemsByCatalogId);
2859
                .selectAllByItems(allItemsByCatalogId);
2860
        LOGGER.info("Fetched {} tagListings", tagListingByCatalogIdMap.size());
2860
        LOGGER.info("Fetched {} tagListings", tagListingByCatalogIdMap.size());
2861
 
2861
 
-
 
2862
        // Collect all distinct brands from focused models
-
 
2863
        Set<String> allFocusedBrands = new HashSet<>();
-
 
2864
        for (List<Item> itemList : itemsByCatalogIdMap.values()) {
-
 
2865
            if (itemList != null && !itemList.isEmpty() && allFocusedCatalogIds.contains(itemList.get(0).getCatalogItemId())) {
-
 
2866
                allFocusedBrands.add(itemList.get(0).getBrand());
-
 
2867
            }
-
 
2868
        }
-
 
2869
        LOGGER.info("Focused model brands: {}", allFocusedBrands);
-
 
2870
 
-
 
2871
        // Batch fetch: which focused brands each partner had in stock in the past 30 days
-
 
2872
        LocalDateTime monthStart = LocalDateTime.now().minusDays(30).withHour(0).withMinute(0).withSecond(0).withNano(0);
-
 
2873
 
-
 
2874
        Map<Integer, Set<String>> partnerBrandsFromInventory = !allFocusedBrands.isEmpty()
-
 
2875
                ? inventoryItemRepository.selectDistinctBrandsByFofoIds(allPartnerIds, allFocusedBrands, monthStart)
-
 
2876
                : new HashMap<>();
-
 
2877
 
-
 
2878
        Map<Integer, Set<String>> partnerBrandsFromScans = !allFocusedBrands.isEmpty()
-
 
2879
                ? scanRecordRepository.selectDistinctBrandsByFofoIds(allPartnerIds, allFocusedBrands, monthStart)
-
 
2880
                : new HashMap<>();
-
 
2881
 
-
 
2882
        // Merge both sources into a single map
-
 
2883
        Map<Integer, Set<String>> partnerBrandsMap = new HashMap<>(partnerBrandsFromInventory);
-
 
2884
        for (Map.Entry<Integer, Set<String>> entry : partnerBrandsFromScans.entrySet()) {
-
 
2885
            partnerBrandsMap.computeIfAbsent(entry.getKey(), k -> new HashSet<>()).addAll(entry.getValue());
-
 
2886
        }
-
 
2887
        LOGGER.info("Built partnerBrandsMap for {} partners", partnerBrandsMap.size());
-
 
2888
 
2862
        // Collect all item IDs from inventory, GRN orders, and processing orders for batch item lookup
2889
        // Collect all item IDs from inventory, GRN orders, and processing orders for batch item lookup
2863
        Set<Integer> allItemIds = new HashSet<>();
2890
        Set<Integer> allItemIds = new HashSet<>();
2864
        allInventorySnapshotsMap.values().forEach(list ->
2891
        allInventorySnapshotsMap.values().forEach(list ->
2865
                list.forEach(cis -> allItemIds.add(cis.getItemId())));
2892
                list.forEach(cis -> allItemIds.add(cis.getItemId())));
2866
        allGrnPendingOrdersMap.values().forEach(orders ->
2893
        allGrnPendingOrdersMap.values().forEach(orders ->
Line 2984... Line 3011...
2984
 
3011
 
2985
                    // Use pre-fetched tagListing
3012
                    // Use pre-fetched tagListing
2986
                    TagListing tagListing = tagListingByCatalogIdMap.get(catalogId);
3013
                    TagListing tagListing = tagListingByCatalogIdMap.get(catalogId);
2987
                    if (tagListing == null) continue;
3014
                    if (tagListing == null) continue;
2988
 
3015
 
-
 
3016
                    // Skip if partner didn't carry this brand at any point this month
-
 
3017
                    String brand = items.get(0).getBrand();
-
 
3018
                    if (!partnerBrandsMap.getOrDefault(partnerId, Collections.emptySet()).contains(brand)) continue;
-
 
3019
 
2989
                    int allColorNetAvailability = 0;
3020
                    int allColorNetAvailability = 0;
2990
                    int allColorPoAvailability = 0;
3021
                    int allColorPoAvailability = 0;
2991
 
3022
 
2992
                    for (Item item : items) {
3023
                    for (Item item : items) {
2993
                        if (itemAvailabilityMap != null) {
3024
                        if (itemAvailabilityMap != null) {