Subversion Repositories SmartDukaan

Rev

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

Rev 37055 Rev 37282
Line 528... Line 528...
528
        model.addAttribute("response1", response.toString());
528
        model.addAttribute("response1", response.toString());
529
        return "response";
529
        return "response";
530
 
530
 
531
    }
531
    }
532
 
532
 
533
    @RequestMapping(value = "/hotdealsitemsByCatalogId")
-
 
534
    public String getHotdealsitemsByCatalogId(HttpServletRequest request, Model model,
-
 
535
                                              @RequestParam(required = false) int catalogId, @RequestParam(required = false) int itemId)
-
 
536
            throws ProfitMandiBusinessException {
-
 
537
        if (catalogId == 0) {
-
 
538
            catalogId = itemRepository.selectById(itemId).getCatalogItemId();
-
 
539
        }
-
 
540
        List<Item> items = itemRepository.selectAllByCatalogItemId(catalogId);
-
 
541
        LOGGER.info("Items {}", items);
-
 
542
        Map<Integer, String> itemsColorMap = items.stream().filter(x -> x.getColorNatural().startsWith("f_"))
-
 
543
                .collect(Collectors.toMap(Item::getId, Item::getColor));
-
 
544
        Map<Integer, TagListing> tagsMap = tagListingRepository
-
 
545
                .selectByItemIdsAndTagIds(items.stream().map(x -> x.getId()).collect(Collectors.toSet()), defaultTags)
-
 
546
                .stream().collect(Collectors.toMap(TagListing::getItemId, x -> x));
-
 
547
        LOGGER.info("Items color map {}", itemsColorMap);
-
 
548
        JSONArray response = new JSONArray();
-
 
549
        itemsColorMap.keySet().stream().forEach(x -> {
-
 
550
            response.put(new JSONObject().put("color", itemsColorMap.get(x)).put("id", x).put("hotDeals",
-
 
551
                    tagsMap.get(x) == null ? false : tagsMap.get(x).isHotDeals()));
-
 
552
        });
-
 
553
        model.addAttribute("response1", response.toString());
-
 
554
        return "response";
-
 
555
 
-
 
556
    }
-
 
557
 
-
 
558
    private List<Order> filterValidOrders(List<Order> lastOrdersList) {
533
    private List<Order> filterValidOrders(List<Order> lastOrdersList) {
559
        int orderRemovedCount = 0;
534
        int orderRemovedCount = 0;
560
        Iterator<Order> orderIterator = lastOrdersList.iterator();
535
        Iterator<Order> orderIterator = lastOrdersList.iterator();
561
        while (orderIterator.hasNext()) {
536
        while (orderIterator.hasNext()) {
562
            Order o = orderIterator.next();
537
            Order o = orderIterator.next();
Line 596... Line 571...
596
                // Collect catalogIds for Solr updates
571
                // Collect catalogIds for Solr updates
597
                try {
572
                try {
598
                    Item item = itemRepository.selectById(itemId);
573
                    Item item = itemRepository.selectById(itemId);
599
                    updatedCatalogIds.add(item.getCatalogItemId());
574
                    updatedCatalogIds.add(item.getCatalogItemId());
600
                } catch (Exception e) {
575
                } catch (Exception e) {
601
                    LOGGER.error("Failed to get catalogId for itemId: {}", itemId, e);
-
 
602
                }
-
 
603
            }
-
 
604
        }
-
 
605
 
-
 
606
        // Publish events for all updated catalogs
-
 
607
        for (Integer catalogId : updatedCatalogIds) {
-
 
608
            try {
-
 
609
                tagListingEventPublisher.publishStatusChange(0, catalogId);
-
 
610
            } catch (Exception e) {
-
 
611
                LOGGER.error("Failed to publish status change event for catalogId: {}", catalogId, e);
-
 
612
            }
-
 
613
        }
-
 
614
 
-
 
615
        model.addAttribute("response1", true);
-
 
616
        return "response";
-
 
617
    }
-
 
618
 
-
 
619
    @RequestMapping(value = "/indent/confirm-hotdeals-pause", method = RequestMethod.POST)
-
 
620
    public String hotdealUpdate(HttpServletRequest request, Model model, @RequestBody String jsonArrayString)
-
 
621
            throws Exception {
-
 
622
        JSONArray jsonArray = new JSONArray(jsonArrayString);
-
 
623
        Set<Integer> updatedCatalogIds = new HashSet<>();
-
 
624
 
-
 
625
        for (int i = 0; i < jsonArray.length(); i++) {
-
 
626
            JSONObject obj = jsonArray.getJSONObject(i);
-
 
627
            int itemId = obj.getInt("id");
-
 
628
            TagListing tl = tagListingRepository.selectByItemId(itemId);
-
 
629
            if (tl == null) {
-
 
630
                continue;
-
 
631
            } else {
-
 
632
                tl.setHotDeals(obj.getBoolean("hotDeals"));
-
 
633
                tagListingRepository.persist(tl);
-
 
634
                // Collect catalogIds for Solr updates
-
 
635
                try {
-
 
636
                    Item item = itemRepository.selectById(itemId);
-
 
637
                    updatedCatalogIds.add(item.getCatalogItemId());
-
 
638
                } catch (Exception e) {
-
 
639
                    LOGGER.error("Failed to get catalogId for itemId: {}", itemId, e);
576
                    LOGGER.error("Failed to get catalogId for itemId: {}", itemId, e);
640
                }
577
                }
641
            }
578
            }
642
        }
579
        }
643
 
580