| 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;
|
|
|
14 |
import in.shop2020.model.v1.order.OrderStatus;
|
|
|
15 |
import org.apache.logging.log4j.LogManager;
|
|
|
16 |
import org.apache.logging.log4j.Logger;
|
|
|
17 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
18 |
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
19 |
import org.springframework.stereotype.Component;
|
|
|
20 |
|
|
|
21 |
import java.time.LocalDate;
|
|
|
22 |
import java.time.LocalDateTime;
|
|
|
23 |
import java.util.*;
|
|
|
24 |
import java.util.stream.Collectors;
|
|
|
25 |
|
|
|
26 |
@Component
|
|
|
27 |
public class Listing {
|
|
|
28 |
@Autowired
|
|
|
29 |
private WebListingRepository webListingRepository;
|
|
|
30 |
|
|
|
31 |
@Autowired
|
|
|
32 |
private FofoSolr fofoSolr;
|
|
|
33 |
|
|
|
34 |
@Autowired
|
|
|
35 |
OrderRepository orderRepository;
|
|
|
36 |
|
|
|
37 |
@Autowired
|
|
|
38 |
ItemRepository itemRepository;
|
|
|
39 |
|
|
|
40 |
@Autowired
|
|
|
41 |
PriceDropRepository priceDropRepository;
|
|
|
42 |
|
|
|
43 |
@Autowired
|
|
|
44 |
CustomerOfferRepository customerOfferRepository;
|
|
|
45 |
|
|
|
46 |
@Autowired
|
|
|
47 |
CustomerOfferItemRepository customerOfferItemRepository;
|
|
|
48 |
|
|
|
49 |
@Autowired
|
|
|
50 |
SchemeRepository schemeRepository;
|
|
|
51 |
|
|
|
52 |
@Autowired
|
|
|
53 |
TagListingRepository tagListingRepository;
|
|
|
54 |
|
|
|
55 |
|
|
|
56 |
private static final Logger LOGGER = LogManager.getLogger(Listing.class);
|
|
|
57 |
|
|
|
58 |
@Autowired
|
|
|
59 |
private WebProductListingRepository webProductListingRepository;
|
|
|
60 |
|
|
|
61 |
|
|
|
62 |
public void pushDataToSolr() throws Exception {
|
|
|
63 |
fofoSolr.pushData();
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
public void getBestSeller() throws ProfitMandiBusinessException {
|
|
|
67 |
WebListing webListing = webListingRepository.selectByUrl("partner-best-sellers");
|
|
|
68 |
|
|
|
69 |
List<WebProductListing> webProductListings = webProductListingRepository
|
|
|
70 |
.selectAllByWebListingId(webListing.getId());
|
|
|
71 |
|
|
|
72 |
List<Integer> catalogItemIds = orderRepository.selectAllOrderWeight(LocalDateTime.now().minusDays(30),
|
|
|
73 |
LocalDateTime.now(), OrderStatus.DELIVERY_SUCCESS);
|
|
|
74 |
|
|
|
75 |
LOGGER.info("catalogItemIds {}", catalogItemIds);
|
|
|
76 |
if (!catalogItemIds.isEmpty()) {
|
|
|
77 |
webProductListingRepository.deleteByEqual(webListing.getId());
|
|
|
78 |
int count = 0;
|
|
|
79 |
for (Integer catalogItemId : catalogItemIds) {
|
|
|
80 |
|
|
|
81 |
WebProductListing webProductListing = new WebProductListing();
|
|
|
82 |
webProductListing.setEntityId(catalogItemId);
|
|
|
83 |
webProductListing.setWebListingId(webListing.getId());
|
|
|
84 |
count = count + 1;
|
|
|
85 |
|
|
|
86 |
webProductListing.setRank(count + 1);
|
|
|
87 |
webProductListingRepository.persist(webProductListing);
|
|
|
88 |
|
|
|
89 |
}
|
|
|
90 |
|
|
|
91 |
}
|
|
|
92 |
}
|
|
|
93 |
|
|
|
94 |
public void getPriceDrop() throws ProfitMandiBusinessException {
|
|
|
95 |
WebListing webListing = webListingRepository.selectByUrl("partner-price-drop");
|
|
|
96 |
|
|
|
97 |
List<WebProductListing> webProductListings = webProductListingRepository
|
|
|
98 |
.selectAllByWebListingId(webListing.getId());
|
|
|
99 |
|
|
|
100 |
Set<Integer> catalogItemIds = priceDropRepository
|
|
|
101 |
.selectAllByDatesBetweenSortByDate(LocalDateTime.now().minusDays(30), LocalDateTime.now()).stream()
|
|
|
102 |
.filter(x->x.getAmount()>0).map(x -> x.getCatalogItemId()).collect(Collectors.toSet());
|
|
|
103 |
|
|
|
104 |
LOGGER.info("catalogItemIds {}", catalogItemIds);
|
|
|
105 |
if (!catalogItemIds.isEmpty()) {
|
|
|
106 |
webProductListingRepository.deleteByEqual(webListing.getId());
|
|
|
107 |
int count = 0;
|
|
|
108 |
for (Integer catalogItemId : catalogItemIds) {
|
|
|
109 |
|
|
|
110 |
WebProductListing webProductListing = new WebProductListing();
|
|
|
111 |
webProductListing.setEntityId(catalogItemId);
|
|
|
112 |
webProductListing.setWebListingId(webListing.getId());
|
|
|
113 |
count = count + 1;
|
|
|
114 |
webProductListing.setRank(count);
|
|
|
115 |
webProductListingRepository.persist(webProductListing);
|
|
|
116 |
|
|
|
117 |
}
|
|
|
118 |
|
|
|
119 |
}
|
|
|
120 |
}
|
|
|
121 |
|
|
|
122 |
public void getNewLaunches() throws ProfitMandiBusinessException {
|
|
|
123 |
WebListing webListing = webListingRepository.selectByUrl("new-launches");
|
|
|
124 |
|
|
|
125 |
List<Integer> catalogItemIds = tagListingRepository.getRecentLanuch(LocalDate.now().minusDays(30),
|
|
|
126 |
LocalDate.now().plusDays(1));
|
|
|
127 |
|
|
|
128 |
if (!catalogItemIds.isEmpty()) {
|
|
|
129 |
webProductListingRepository.deleteByEqual(webListing.getId());
|
|
|
130 |
int count = 0;
|
|
|
131 |
for (Integer catalogItemId : catalogItemIds) {
|
|
|
132 |
|
|
|
133 |
WebProductListing webProductListing = new WebProductListing();
|
|
|
134 |
webProductListing.setEntityId(catalogItemId);
|
|
|
135 |
webProductListing.setWebListingId(webListing.getId());
|
|
|
136 |
count = count + 1;
|
|
|
137 |
webProductListing.setRank(count);
|
|
|
138 |
webProductListingRepository.persist(webProductListing);
|
|
|
139 |
|
|
|
140 |
}
|
|
|
141 |
|
|
|
142 |
}
|
|
|
143 |
}
|
|
|
144 |
|
|
|
145 |
public void getSpecialSupport() throws ProfitMandiBusinessException {
|
|
|
146 |
WebListing webListing = webListingRepository.selectByUrl("special-support");
|
|
|
147 |
|
|
|
148 |
List<Integer> catalogItemIds = schemeRepository.getActiveScheme(SchemeType.SPECIAL_SUPPORT,
|
|
|
149 |
LocalDate.now().plusDays(1));
|
|
|
150 |
|
|
|
151 |
LOGGER.info("catalogItemIds {}", catalogItemIds);
|
|
|
152 |
if (!catalogItemIds.isEmpty()) {
|
|
|
153 |
webProductListingRepository.deleteByEqual(webListing.getId());
|
|
|
154 |
int count = 0;
|
|
|
155 |
for (Integer catalogItemId : catalogItemIds) {
|
|
|
156 |
|
|
|
157 |
WebProductListing webProductListing = new WebProductListing();
|
|
|
158 |
webProductListing.setEntityId(catalogItemId);
|
|
|
159 |
webProductListing.setWebListingId(webListing.getId());
|
|
|
160 |
count = count + 1;
|
|
|
161 |
webProductListing.setRank(count);
|
|
|
162 |
webProductListingRepository.persist(webProductListing);
|
|
|
163 |
|
|
|
164 |
}
|
|
|
165 |
|
|
|
166 |
}
|
|
|
167 |
}
|
|
|
168 |
|
|
|
169 |
public void getUpgradeOffer() throws ProfitMandiBusinessException {
|
|
|
170 |
WebListing webListing = webListingRepository.selectByUrl("upgrade-offer");
|
|
|
171 |
webProductListingRepository.deleteByEqual(webListing.getId());
|
|
|
172 |
|
|
|
173 |
List<Integer> customerOfferIds = customerOfferRepository.selectOffers(LocalDate.now()).stream()
|
|
|
174 |
.map(x -> x.getId()).collect(Collectors.toList());
|
|
|
175 |
|
|
|
176 |
List<Integer> catalogItemIds = customerOfferItemRepository
|
|
|
177 |
.selectByOfferIdsRange(customerOfferIds, LocalDate.now()).stream().map(x -> x.getCatalogId()).distinct()
|
|
|
178 |
.collect(Collectors.toList());
|
|
|
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 |
|
|
|
197 |
@Scheduled(cron = "0 */30 * * * *")
|
|
|
198 |
public void scheduledPushDataToSolr() throws Throwable {
|
|
|
199 |
this.pushDataToSolr();
|
|
|
200 |
}
|
|
|
201 |
|
|
|
202 |
@Scheduled(cron = "0 0 8 * * *")
|
|
|
203 |
public void scheduledGetBestSeller() throws Throwable {
|
|
|
204 |
this.getBestSeller();
|
|
|
205 |
}
|
|
|
206 |
|
|
|
207 |
@Scheduled(cron = "0 0 8 * * *")
|
|
|
208 |
public void scheduledGetPriceDrop() throws Throwable {
|
|
|
209 |
this.getPriceDrop();
|
|
|
210 |
}
|
|
|
211 |
|
|
|
212 |
@Scheduled(cron = "0 0 8 * * *")
|
|
|
213 |
public void scheduledGetNewLaunches() throws Throwable {
|
|
|
214 |
this.getNewLaunches();
|
|
|
215 |
}
|
|
|
216 |
|
|
|
217 |
@Scheduled(cron = "0 0 8 * * *")
|
|
|
218 |
public void scheduledGetSpecialSupport() throws Throwable {
|
|
|
219 |
this.getSpecialSupport();
|
|
|
220 |
}
|
|
|
221 |
|
|
|
222 |
@Scheduled(cron = "0 0 8 * * *")
|
|
|
223 |
public void scheduledGetUpgradeOffer() throws Throwable {
|
|
|
224 |
this.getUpgradeOffer();
|
|
|
225 |
}
|
|
|
226 |
}
|
|
|
227 |
|
|
|
228 |
|