| 31732 |
amit.gupta |
1 |
package com.smartdukaan.cron.scheduled.b2b;
|
|
|
2 |
|
|
|
3 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
|
|
4 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
|
|
5 |
import com.spice.profitmandi.dao.entity.dtr.WebListing;
|
|
|
6 |
import com.spice.profitmandi.dao.entity.dtr.WebProductListing;
|
|
|
7 |
import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;
|
|
|
8 |
import com.spice.profitmandi.dao.repository.catalog.*;
|
|
|
9 |
import com.spice.profitmandi.dao.repository.dtr.WebListingRepository;
|
|
|
10 |
import com.spice.profitmandi.dao.repository.dtr.WebProductListingRepository;
|
|
|
11 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
|
|
12 |
import com.spice.profitmandi.dao.repository.transaction.PriceDropRepository;
|
|
|
13 |
import com.spice.profitmandi.dao.service.solr.FofoSolr;
|
| 37567 |
amit |
14 |
import com.spice.profitmandi.service.catalog.CatalogDelistService;
|
| 31732 |
amit.gupta |
15 |
import in.shop2020.model.v1.order.OrderStatus;
|
|
|
16 |
import org.apache.logging.log4j.LogManager;
|
|
|
17 |
import org.apache.logging.log4j.Logger;
|
|
|
18 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 37567 |
amit |
19 |
import org.springframework.beans.factory.annotation.Value;
|
| 31732 |
amit.gupta |
20 |
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
21 |
import org.springframework.stereotype.Component;
|
| 31754 |
tejbeer |
22 |
import org.springframework.transaction.annotation.Transactional;
|
| 31732 |
amit.gupta |
23 |
|
|
|
24 |
import java.time.LocalDate;
|
|
|
25 |
import java.time.LocalDateTime;
|
|
|
26 |
import java.util.*;
|
|
|
27 |
import java.util.stream.Collectors;
|
|
|
28 |
|
|
|
29 |
@Component
|
| 31754 |
tejbeer |
30 |
@Transactional(rollbackFor = Throwable.class)
|
| 31732 |
amit.gupta |
31 |
public class Listing {
|
|
|
32 |
@Autowired
|
|
|
33 |
private WebListingRepository webListingRepository;
|
|
|
34 |
|
|
|
35 |
@Autowired
|
|
|
36 |
private FofoSolr fofoSolr;
|
|
|
37 |
|
|
|
38 |
@Autowired
|
|
|
39 |
OrderRepository orderRepository;
|
|
|
40 |
|
|
|
41 |
@Autowired
|
|
|
42 |
ItemRepository itemRepository;
|
|
|
43 |
|
|
|
44 |
@Autowired
|
|
|
45 |
PriceDropRepository priceDropRepository;
|
|
|
46 |
|
|
|
47 |
@Autowired
|
|
|
48 |
CustomerOfferRepository customerOfferRepository;
|
|
|
49 |
|
|
|
50 |
@Autowired
|
|
|
51 |
CustomerOfferItemRepository customerOfferItemRepository;
|
|
|
52 |
|
|
|
53 |
@Autowired
|
|
|
54 |
SchemeRepository schemeRepository;
|
|
|
55 |
|
|
|
56 |
@Autowired
|
|
|
57 |
TagListingRepository tagListingRepository;
|
|
|
58 |
|
| 37567 |
amit |
59 |
@Autowired
|
|
|
60 |
CatalogDelistService catalogDelistService;
|
| 31732 |
amit.gupta |
61 |
|
| 37567 |
amit |
62 |
// Inline default: env profiles have NO fallback between each other, so a key
|
|
|
63 |
// missing from one profile's properties would otherwise stop the context booting.
|
|
|
64 |
@Value("${catalog.autoDelist.enabled:true}")
|
|
|
65 |
private boolean autoDelistEnabled;
|
|
|
66 |
|
|
|
67 |
|
| 31732 |
amit.gupta |
68 |
private static final Logger LOGGER = LogManager.getLogger(Listing.class);
|
|
|
69 |
|
|
|
70 |
@Autowired
|
|
|
71 |
private WebProductListingRepository webProductListingRepository;
|
|
|
72 |
|
|
|
73 |
|
|
|
74 |
public void pushDataToSolr() throws Exception {
|
|
|
75 |
fofoSolr.pushData();
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
public void getBestSeller() throws ProfitMandiBusinessException {
|
|
|
79 |
WebListing webListing = webListingRepository.selectByUrl("partner-best-sellers");
|
|
|
80 |
|
| 31754 |
tejbeer |
81 |
List<WebProductListing> webProductListings = webProductListingRepository.selectAllByWebListingId(webListing.getId());
|
| 31732 |
amit.gupta |
82 |
|
| 31754 |
tejbeer |
83 |
List<Integer> catalogItemIds = orderRepository.selectAllOrderWeight(LocalDateTime.now().minusDays(30), LocalDateTime.now(), OrderStatus.DELIVERY_SUCCESS);
|
| 31732 |
amit.gupta |
84 |
|
|
|
85 |
LOGGER.info("catalogItemIds {}", catalogItemIds);
|
|
|
86 |
if (!catalogItemIds.isEmpty()) {
|
|
|
87 |
webProductListingRepository.deleteByEqual(webListing.getId());
|
|
|
88 |
int count = 0;
|
|
|
89 |
for (Integer catalogItemId : catalogItemIds) {
|
|
|
90 |
|
|
|
91 |
WebProductListing webProductListing = new WebProductListing();
|
|
|
92 |
webProductListing.setEntityId(catalogItemId);
|
|
|
93 |
webProductListing.setWebListingId(webListing.getId());
|
|
|
94 |
count = count + 1;
|
|
|
95 |
|
|
|
96 |
webProductListing.setRank(count + 1);
|
|
|
97 |
webProductListingRepository.persist(webProductListing);
|
|
|
98 |
|
|
|
99 |
}
|
|
|
100 |
|
|
|
101 |
}
|
|
|
102 |
}
|
|
|
103 |
|
|
|
104 |
public void getPriceDrop() throws ProfitMandiBusinessException {
|
|
|
105 |
WebListing webListing = webListingRepository.selectByUrl("partner-price-drop");
|
|
|
106 |
|
| 31754 |
tejbeer |
107 |
Set<Integer> catalogItemIds = priceDropRepository.selectAllByDatesBetweenSortByDate(LocalDateTime.now().minusDays(30), LocalDateTime.now()).stream().filter(x -> x.getAmount() > 0).map(x -> x.getCatalogItemId()).collect(Collectors.toSet());
|
| 31732 |
amit.gupta |
108 |
|
|
|
109 |
LOGGER.info("catalogItemIds {}", catalogItemIds);
|
|
|
110 |
if (!catalogItemIds.isEmpty()) {
|
|
|
111 |
webProductListingRepository.deleteByEqual(webListing.getId());
|
|
|
112 |
int count = 0;
|
|
|
113 |
for (Integer catalogItemId : catalogItemIds) {
|
|
|
114 |
|
|
|
115 |
WebProductListing webProductListing = new WebProductListing();
|
|
|
116 |
webProductListing.setEntityId(catalogItemId);
|
|
|
117 |
webProductListing.setWebListingId(webListing.getId());
|
|
|
118 |
count = count + 1;
|
|
|
119 |
webProductListing.setRank(count);
|
|
|
120 |
webProductListingRepository.persist(webProductListing);
|
|
|
121 |
|
|
|
122 |
}
|
|
|
123 |
|
|
|
124 |
}
|
|
|
125 |
}
|
|
|
126 |
|
|
|
127 |
public void getNewLaunches() throws ProfitMandiBusinessException {
|
|
|
128 |
WebListing webListing = webListingRepository.selectByUrl("new-launches");
|
|
|
129 |
|
| 31754 |
tejbeer |
130 |
List<Integer> catalogItemIds = tagListingRepository.getRecentLanuch(LocalDate.now().minusDays(30), LocalDate.now().plusDays(1));
|
| 31732 |
amit.gupta |
131 |
|
|
|
132 |
if (!catalogItemIds.isEmpty()) {
|
|
|
133 |
webProductListingRepository.deleteByEqual(webListing.getId());
|
|
|
134 |
int count = 0;
|
|
|
135 |
for (Integer catalogItemId : catalogItemIds) {
|
|
|
136 |
|
|
|
137 |
WebProductListing webProductListing = new WebProductListing();
|
|
|
138 |
webProductListing.setEntityId(catalogItemId);
|
|
|
139 |
webProductListing.setWebListingId(webListing.getId());
|
|
|
140 |
count = count + 1;
|
|
|
141 |
webProductListing.setRank(count);
|
|
|
142 |
webProductListingRepository.persist(webProductListing);
|
|
|
143 |
|
|
|
144 |
}
|
|
|
145 |
|
|
|
146 |
}
|
|
|
147 |
}
|
|
|
148 |
|
|
|
149 |
public void getSpecialSupport() throws ProfitMandiBusinessException {
|
|
|
150 |
WebListing webListing = webListingRepository.selectByUrl("special-support");
|
|
|
151 |
|
| 31754 |
tejbeer |
152 |
List<Integer> catalogItemIds = schemeRepository.getActiveScheme(SchemeType.SPECIAL_SUPPORT, LocalDate.now().plusDays(1));
|
| 31732 |
amit.gupta |
153 |
|
|
|
154 |
LOGGER.info("catalogItemIds {}", catalogItemIds);
|
|
|
155 |
if (!catalogItemIds.isEmpty()) {
|
|
|
156 |
webProductListingRepository.deleteByEqual(webListing.getId());
|
|
|
157 |
int count = 0;
|
|
|
158 |
for (Integer catalogItemId : catalogItemIds) {
|
|
|
159 |
|
|
|
160 |
WebProductListing webProductListing = new WebProductListing();
|
|
|
161 |
webProductListing.setEntityId(catalogItemId);
|
|
|
162 |
webProductListing.setWebListingId(webListing.getId());
|
|
|
163 |
count = count + 1;
|
|
|
164 |
webProductListing.setRank(count);
|
|
|
165 |
webProductListingRepository.persist(webProductListing);
|
|
|
166 |
|
|
|
167 |
}
|
|
|
168 |
|
|
|
169 |
}
|
|
|
170 |
}
|
|
|
171 |
|
|
|
172 |
public void getUpgradeOffer() throws ProfitMandiBusinessException {
|
|
|
173 |
WebListing webListing = webListingRepository.selectByUrl("upgrade-offer");
|
|
|
174 |
webProductListingRepository.deleteByEqual(webListing.getId());
|
|
|
175 |
|
| 31754 |
tejbeer |
176 |
List<Integer> customerOfferIds = customerOfferRepository.selectOffers(LocalDate.now()).stream().map(x -> x.getId()).collect(Collectors.toList());
|
| 31732 |
amit.gupta |
177 |
|
| 31754 |
tejbeer |
178 |
List<Integer> catalogItemIds = customerOfferItemRepository.selectByOfferIdsRange(customerOfferIds, LocalDate.now()).stream().map(x -> x.getCatalogId()).distinct().collect(Collectors.toList());
|
| 31732 |
amit.gupta |
179 |
|
|
|
180 |
LOGGER.info("catalogItemIds {}", catalogItemIds);
|
|
|
181 |
if (!catalogItemIds.isEmpty()) {
|
|
|
182 |
int count = 0;
|
|
|
183 |
for (Integer catalogItemId : catalogItemIds) {
|
|
|
184 |
|
|
|
185 |
WebProductListing webProductListing = new WebProductListing();
|
|
|
186 |
webProductListing.setEntityId(catalogItemId);
|
|
|
187 |
webProductListing.setWebListingId(webListing.getId());
|
|
|
188 |
count = count + 1;
|
|
|
189 |
webProductListing.setRank(count);
|
|
|
190 |
webProductListingRepository.persist(webProductListing);
|
|
|
191 |
|
|
|
192 |
}
|
|
|
193 |
|
|
|
194 |
}
|
|
|
195 |
}
|
|
|
196 |
|
| 36058 |
ranu |
197 |
@Scheduled(cron = "0 0 6,18 * * *")
|
| 34555 |
tejus.loha |
198 |
public void scheduledPushDataToSolr() throws Throwable {
|
|
|
199 |
this.pushDataToSolr();
|
|
|
200 |
}
|
|
|
201 |
|
| 37567 |
amit |
202 |
/**
|
|
|
203 |
* Retire dead catalogue, 30 minutes ahead of the 06:00 reindex above so the
|
|
|
204 |
* same morning's Solr pass publishes it - a bulk UPDATE fires no
|
|
|
205 |
* TagListingChangeListener event, so without that ordering the portal would
|
|
|
206 |
* lag until 18:00.
|
|
|
207 |
*
|
|
|
208 |
* <p>Steady state is small: the 2026-09-10 backfill cleared a 2.5-year
|
|
|
209 |
* backlog, so a run now catches only listings newly crossing the 24-month
|
|
|
210 |
* line plus items whose stock just went to zero.
|
|
|
211 |
*/
|
|
|
212 |
@Scheduled(cron = "0 30 5 * * *")
|
|
|
213 |
public void scheduledDelistDeadListings() {
|
|
|
214 |
if (!autoDelistEnabled) {
|
|
|
215 |
LOGGER.info("catalog delist skipped: catalog.autoDelist.enabled=false");
|
|
|
216 |
return;
|
|
|
217 |
}
|
|
|
218 |
LOGGER.info("catalog delist starting");
|
|
|
219 |
LOGGER.info("catalog delist finished: {}", catalogDelistService.delistDeadListings());
|
|
|
220 |
}
|
|
|
221 |
|
| 34555 |
tejus.loha |
222 |
@Scheduled(cron = "0 0 8 * * *")
|
|
|
223 |
public void scheduledGetBestSeller() throws Throwable {
|
|
|
224 |
this.getBestSeller();
|
|
|
225 |
}
|
|
|
226 |
|
|
|
227 |
@Scheduled(cron = "0 0 8 * * *")
|
|
|
228 |
public void scheduledGetPriceDrop() throws Throwable {
|
|
|
229 |
this.getPriceDrop();
|
|
|
230 |
}
|
|
|
231 |
|
|
|
232 |
@Scheduled(cron = "0 0 8 * * *")
|
|
|
233 |
public void scheduledGetNewLaunches() throws Throwable {
|
|
|
234 |
this.getNewLaunches();
|
|
|
235 |
}
|
|
|
236 |
|
|
|
237 |
@Scheduled(cron = "0 0 8 * * *")
|
|
|
238 |
public void scheduledGetSpecialSupport() throws Throwable {
|
|
|
239 |
this.getSpecialSupport();
|
|
|
240 |
}
|
|
|
241 |
|
|
|
242 |
@Scheduled(cron = "0 0 8 * * *")
|
|
|
243 |
public void scheduledGetUpgradeOffer() throws Throwable {
|
|
|
244 |
this.getUpgradeOffer();
|
|
|
245 |
}
|
| 31732 |
amit.gupta |
246 |
}
|
|
|
247 |
|