Rev 36058 | Blame | Compare with Previous | Last modification | View Log | RSS feed
package com.smartdukaan.cron.scheduled.b2b;import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;import com.spice.profitmandi.dao.entity.catalog.Item;import com.spice.profitmandi.dao.entity.dtr.WebListing;import com.spice.profitmandi.dao.entity.dtr.WebProductListing;import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;import com.spice.profitmandi.dao.repository.catalog.*;import com.spice.profitmandi.dao.repository.dtr.WebListingRepository;import com.spice.profitmandi.dao.repository.dtr.WebProductListingRepository;import com.spice.profitmandi.dao.repository.transaction.OrderRepository;import com.spice.profitmandi.dao.repository.transaction.PriceDropRepository;import com.spice.profitmandi.dao.service.solr.FofoSolr;import com.spice.profitmandi.service.catalog.CatalogDelistService;import in.shop2020.model.v1.order.OrderStatus;import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.beans.factory.annotation.Value;import org.springframework.scheduling.annotation.Scheduled;import org.springframework.stereotype.Component;import org.springframework.transaction.annotation.Transactional;import java.time.LocalDate;import java.time.LocalDateTime;import java.util.*;import java.util.stream.Collectors;@Component@Transactional(rollbackFor = Throwable.class)public class Listing {@Autowiredprivate WebListingRepository webListingRepository;@Autowiredprivate FofoSolr fofoSolr;@AutowiredOrderRepository orderRepository;@AutowiredItemRepository itemRepository;@AutowiredPriceDropRepository priceDropRepository;@AutowiredCustomerOfferRepository customerOfferRepository;@AutowiredCustomerOfferItemRepository customerOfferItemRepository;@AutowiredSchemeRepository schemeRepository;@AutowiredTagListingRepository tagListingRepository;@AutowiredCatalogDelistService catalogDelistService;// Inline default: env profiles have NO fallback between each other, so a key// missing from one profile's properties would otherwise stop the context booting.@Value("${catalog.autoDelist.enabled:true}")private boolean autoDelistEnabled;private static final Logger LOGGER = LogManager.getLogger(Listing.class);@Autowiredprivate WebProductListingRepository webProductListingRepository;public void pushDataToSolr() throws Exception {fofoSolr.pushData();}public void getBestSeller() throws ProfitMandiBusinessException {WebListing webListing = webListingRepository.selectByUrl("partner-best-sellers");List<WebProductListing> webProductListings = webProductListingRepository.selectAllByWebListingId(webListing.getId());List<Integer> catalogItemIds = orderRepository.selectAllOrderWeight(LocalDateTime.now().minusDays(30), LocalDateTime.now(), OrderStatus.DELIVERY_SUCCESS);LOGGER.info("catalogItemIds {}", catalogItemIds);if (!catalogItemIds.isEmpty()) {webProductListingRepository.deleteByEqual(webListing.getId());int count = 0;for (Integer catalogItemId : catalogItemIds) {WebProductListing webProductListing = new WebProductListing();webProductListing.setEntityId(catalogItemId);webProductListing.setWebListingId(webListing.getId());count = count + 1;webProductListing.setRank(count + 1);webProductListingRepository.persist(webProductListing);}}}public void getPriceDrop() throws ProfitMandiBusinessException {WebListing webListing = webListingRepository.selectByUrl("partner-price-drop");Set<Integer> catalogItemIds = priceDropRepository.selectAllByDatesBetweenSortByDate(LocalDateTime.now().minusDays(30), LocalDateTime.now()).stream().filter(x -> x.getAmount() > 0).map(x -> x.getCatalogItemId()).collect(Collectors.toSet());LOGGER.info("catalogItemIds {}", catalogItemIds);if (!catalogItemIds.isEmpty()) {webProductListingRepository.deleteByEqual(webListing.getId());int count = 0;for (Integer catalogItemId : catalogItemIds) {WebProductListing webProductListing = new WebProductListing();webProductListing.setEntityId(catalogItemId);webProductListing.setWebListingId(webListing.getId());count = count + 1;webProductListing.setRank(count);webProductListingRepository.persist(webProductListing);}}}public void getNewLaunches() throws ProfitMandiBusinessException {WebListing webListing = webListingRepository.selectByUrl("new-launches");List<Integer> catalogItemIds = tagListingRepository.getRecentLanuch(LocalDate.now().minusDays(30), LocalDate.now().plusDays(1));if (!catalogItemIds.isEmpty()) {webProductListingRepository.deleteByEqual(webListing.getId());int count = 0;for (Integer catalogItemId : catalogItemIds) {WebProductListing webProductListing = new WebProductListing();webProductListing.setEntityId(catalogItemId);webProductListing.setWebListingId(webListing.getId());count = count + 1;webProductListing.setRank(count);webProductListingRepository.persist(webProductListing);}}}public void getSpecialSupport() throws ProfitMandiBusinessException {WebListing webListing = webListingRepository.selectByUrl("special-support");List<Integer> catalogItemIds = schemeRepository.getActiveScheme(SchemeType.SPECIAL_SUPPORT, LocalDate.now().plusDays(1));LOGGER.info("catalogItemIds {}", catalogItemIds);if (!catalogItemIds.isEmpty()) {webProductListingRepository.deleteByEqual(webListing.getId());int count = 0;for (Integer catalogItemId : catalogItemIds) {WebProductListing webProductListing = new WebProductListing();webProductListing.setEntityId(catalogItemId);webProductListing.setWebListingId(webListing.getId());count = count + 1;webProductListing.setRank(count);webProductListingRepository.persist(webProductListing);}}}public void getUpgradeOffer() throws ProfitMandiBusinessException {WebListing webListing = webListingRepository.selectByUrl("upgrade-offer");webProductListingRepository.deleteByEqual(webListing.getId());List<Integer> customerOfferIds = customerOfferRepository.selectOffers(LocalDate.now()).stream().map(x -> x.getId()).collect(Collectors.toList());List<Integer> catalogItemIds = customerOfferItemRepository.selectByOfferIdsRange(customerOfferIds, LocalDate.now()).stream().map(x -> x.getCatalogId()).distinct().collect(Collectors.toList());LOGGER.info("catalogItemIds {}", catalogItemIds);if (!catalogItemIds.isEmpty()) {int count = 0;for (Integer catalogItemId : catalogItemIds) {WebProductListing webProductListing = new WebProductListing();webProductListing.setEntityId(catalogItemId);webProductListing.setWebListingId(webListing.getId());count = count + 1;webProductListing.setRank(count);webProductListingRepository.persist(webProductListing);}}}@Scheduled(cron = "0 0 6,18 * * *")public void scheduledPushDataToSolr() throws Throwable {this.pushDataToSolr();}/*** Retire dead catalogue, 30 minutes ahead of the 06:00 reindex above so the* same morning's Solr pass publishes it - a bulk UPDATE fires no* TagListingChangeListener event, so without that ordering the portal would* lag until 18:00.** <p>Steady state is small: the 2026-09-10 backfill cleared a 2.5-year* backlog, so a run now catches only listings newly crossing the 24-month* line plus items whose stock just went to zero.*/@Scheduled(cron = "0 30 5 * * *")public void scheduledDelistDeadListings() {if (!autoDelistEnabled) {LOGGER.info("catalog delist skipped: catalog.autoDelist.enabled=false");return;}LOGGER.info("catalog delist starting");LOGGER.info("catalog delist finished: {}", catalogDelistService.delistDeadListings());}@Scheduled(cron = "0 0 8 * * *")public void scheduledGetBestSeller() throws Throwable {this.getBestSeller();}@Scheduled(cron = "0 0 8 * * *")public void scheduledGetPriceDrop() throws Throwable {this.getPriceDrop();}@Scheduled(cron = "0 0 8 * * *")public void scheduledGetNewLaunches() throws Throwable {this.getNewLaunches();}@Scheduled(cron = "0 0 8 * * *")public void scheduledGetSpecialSupport() throws Throwable {this.getSpecialSupport();}@Scheduled(cron = "0 0 8 * * *")public void scheduledGetUpgradeOffer() throws Throwable {this.getUpgradeOffer();}}