| Line 2... |
Line 2... |
| 2 |
|
2 |
|
| 3 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
3 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 4 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
4 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
| 5 |
import com.spice.profitmandi.dao.entity.dtr.WebListing;
|
5 |
import com.spice.profitmandi.dao.entity.dtr.WebListing;
|
| 6 |
import com.spice.profitmandi.dao.entity.dtr.WebProductListing;
|
6 |
import com.spice.profitmandi.dao.entity.dtr.WebProductListing;
|
| - |
|
7 |
import com.spice.profitmandi.dao.entity.transaction.PriceDrop;
|
| 7 |
import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;
|
8 |
import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;
|
| 8 |
import com.spice.profitmandi.dao.repository.catalog.*;
|
9 |
import com.spice.profitmandi.dao.repository.catalog.*;
|
| 9 |
import com.spice.profitmandi.dao.repository.dtr.WebListingRepository;
|
10 |
import com.spice.profitmandi.dao.repository.dtr.WebListingRepository;
|
| 10 |
import com.spice.profitmandi.dao.repository.dtr.WebProductListingRepository;
|
11 |
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.OrderRepository;
|
| Line 81... |
Line 82... |
| 81 |
List<WebProductListing> webProductListings = webProductListingRepository.selectAllByWebListingId(webListing.getId());
|
82 |
List<WebProductListing> webProductListings = webProductListingRepository.selectAllByWebListingId(webListing.getId());
|
| 82 |
|
83 |
|
| 83 |
List<Integer> catalogItemIds = orderRepository.selectAllOrderWeight(LocalDateTime.now().minusDays(30), LocalDateTime.now(), OrderStatus.DELIVERY_SUCCESS);
|
84 |
List<Integer> catalogItemIds = orderRepository.selectAllOrderWeight(LocalDateTime.now().minusDays(30), LocalDateTime.now(), OrderStatus.DELIVERY_SUCCESS);
|
| 84 |
|
85 |
|
| 85 |
LOGGER.info("catalogItemIds {}", catalogItemIds);
|
86 |
LOGGER.info("catalogItemIds {}", catalogItemIds);
|
| 86 |
if (!catalogItemIds.isEmpty()) {
|
87 |
// Wipe first so a window that yields zero qualifying catalogs collapses
|
| - |
|
88 |
// the list to empty instead of leaving yesterday's stale entries in place.
|
| 87 |
webProductListingRepository.deleteByEqual(webListing.getId());
|
89 |
webProductListingRepository.deleteByEqual(webListing.getId());
|
| 88 |
int count = 0;
|
90 |
int count = 0;
|
| 89 |
for (Integer catalogItemId : catalogItemIds) {
|
91 |
for (Integer catalogItemId : catalogItemIds) {
|
| 90 |
|
92 |
|
| 91 |
WebProductListing webProductListing = new WebProductListing();
|
93 |
WebProductListing webProductListing = new WebProductListing();
|
| 92 |
webProductListing.setEntityId(catalogItemId);
|
94 |
webProductListing.setEntityId(catalogItemId);
|
| 93 |
webProductListing.setWebListingId(webListing.getId());
|
95 |
webProductListing.setWebListingId(webListing.getId());
|
| 94 |
count = count + 1;
|
96 |
count = count + 1;
|
| 95 |
|
97 |
|
| 96 |
webProductListing.setRank(count + 1);
|
98 |
webProductListing.setRank(count + 1);
|
| 97 |
webProductListingRepository.persist(webProductListing);
|
99 |
webProductListingRepository.persist(webProductListing);
|
| 98 |
|
- |
|
| 99 |
}
|
- |
|
| 100 |
|
100 |
|
| 101 |
}
|
101 |
}
|
| 102 |
}
|
102 |
}
|
| 103 |
|
103 |
|
| 104 |
public void getPriceDrop() throws ProfitMandiBusinessException {
|
104 |
public void getPriceDrop() throws ProfitMandiBusinessException {
|
| 105 |
WebListing webListing = webListingRepository.selectByUrl("partner-price-drop");
|
105 |
WebListing webListing = webListingRepository.selectByUrl("partner-price-drop");
|
| 106 |
|
106 |
|
| - |
|
107 |
// "Latest event wins" per catalog: group all price_drop rows in the
|
| - |
|
108 |
// 30-day window by catalogItemId, take the row with the latest
|
| - |
|
109 |
// affectedOn (tiebreak on id for determinism), and keep the catalog
|
| - |
|
110 |
// only if that row is a drop (amount > 0). A hike after an earlier
|
| - |
|
111 |
// drop removes the label immediately — previously the filter
|
| - |
|
112 |
// considered any drop row in the window, so a later hike was ignored
|
| - |
|
113 |
// and the catalog stayed labeled even when currently priced higher.
|
| 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());
|
114 |
Set<Integer> catalogItemIds = priceDropRepository.selectAllByDatesBetweenSortByDate(LocalDateTime.now().minusDays(30), LocalDateTime.now())
|
| - |
|
115 |
.stream()
|
| - |
|
116 |
.collect(Collectors.groupingBy(
|
| - |
|
117 |
PriceDrop::getCatalogItemId,
|
| - |
|
118 |
Collectors.maxBy(Comparator
|
| - |
|
119 |
.comparing(PriceDrop::getAffectedOn)
|
| - |
|
120 |
.thenComparingInt(PriceDrop::getId))))
|
| - |
|
121 |
.entrySet().stream()
|
| - |
|
122 |
.filter(e -> e.getValue().isPresent() && e.getValue().get().getAmount() > 0)
|
| - |
|
123 |
.map(Map.Entry::getKey)
|
| - |
|
124 |
.collect(Collectors.toSet());
|
| 108 |
|
125 |
|
| 109 |
LOGGER.info("catalogItemIds {}", catalogItemIds);
|
126 |
LOGGER.info("catalogItemIds {}", catalogItemIds);
|
| - |
|
127 |
// Wipe unconditionally: filter is on affectedOn (rolling 30 days), so
|
| 110 |
if (!catalogItemIds.isEmpty()) {
|
128 |
// catalogs whose most recent drop slides out of the window must be
|
| - |
|
129 |
// removed even when no new drops happened that day. Prior guard left
|
| - |
|
130 |
// stale entries in place (see catalog 1026477 case).
|
| 111 |
webProductListingRepository.deleteByEqual(webListing.getId());
|
131 |
webProductListingRepository.deleteByEqual(webListing.getId());
|
| 112 |
int count = 0;
|
132 |
int count = 0;
|
| 113 |
for (Integer catalogItemId : catalogItemIds) {
|
133 |
for (Integer catalogItemId : catalogItemIds) {
|
| 114 |
|
134 |
|
| 115 |
WebProductListing webProductListing = new WebProductListing();
|
135 |
WebProductListing webProductListing = new WebProductListing();
|
| 116 |
webProductListing.setEntityId(catalogItemId);
|
136 |
webProductListing.setEntityId(catalogItemId);
|
| 117 |
webProductListing.setWebListingId(webListing.getId());
|
137 |
webProductListing.setWebListingId(webListing.getId());
|
| 118 |
count = count + 1;
|
138 |
count = count + 1;
|
| 119 |
webProductListing.setRank(count);
|
139 |
webProductListing.setRank(count);
|
| 120 |
webProductListingRepository.persist(webProductListing);
|
140 |
webProductListingRepository.persist(webProductListing);
|
| 121 |
|
- |
|
| 122 |
}
|
- |
|
| 123 |
|
141 |
|
| 124 |
}
|
142 |
}
|
| 125 |
}
|
143 |
}
|
| 126 |
|
144 |
|
| 127 |
public void getNewLaunches() throws ProfitMandiBusinessException {
|
145 |
public void getNewLaunches() throws ProfitMandiBusinessException {
|
| 128 |
WebListing webListing = webListingRepository.selectByUrl("new-launches");
|
146 |
WebListing webListing = webListingRepository.selectByUrl("new-launches");
|
| 129 |
|
147 |
|
| 130 |
List<Integer> catalogItemIds = tagListingRepository.getRecentLanuch(LocalDate.now().minusDays(30), LocalDate.now().plusDays(1));
|
148 |
List<Integer> catalogItemIds = tagListingRepository.getRecentLanuch(LocalDate.now().minusDays(30), LocalDate.now().plusDays(1));
|
| 131 |
|
149 |
|
| - |
|
150 |
// Wipe first so items that fall out of the 30-day window get removed
|
| 132 |
if (!catalogItemIds.isEmpty()) {
|
151 |
// even when no fresh launches were tagged that day.
|
| 133 |
webProductListingRepository.deleteByEqual(webListing.getId());
|
152 |
webProductListingRepository.deleteByEqual(webListing.getId());
|
| 134 |
int count = 0;
|
153 |
int count = 0;
|
| 135 |
for (Integer catalogItemId : catalogItemIds) {
|
154 |
for (Integer catalogItemId : catalogItemIds) {
|
| 136 |
|
155 |
|
| 137 |
WebProductListing webProductListing = new WebProductListing();
|
156 |
WebProductListing webProductListing = new WebProductListing();
|
| 138 |
webProductListing.setEntityId(catalogItemId);
|
157 |
webProductListing.setEntityId(catalogItemId);
|
| 139 |
webProductListing.setWebListingId(webListing.getId());
|
158 |
webProductListing.setWebListingId(webListing.getId());
|
| 140 |
count = count + 1;
|
159 |
count = count + 1;
|
| 141 |
webProductListing.setRank(count);
|
160 |
webProductListing.setRank(count);
|
| 142 |
webProductListingRepository.persist(webProductListing);
|
161 |
webProductListingRepository.persist(webProductListing);
|
| 143 |
|
- |
|
| 144 |
}
|
- |
|
| 145 |
|
162 |
|
| 146 |
}
|
163 |
}
|
| 147 |
}
|
164 |
}
|
| 148 |
|
165 |
|
| 149 |
public void getSpecialSupport() throws ProfitMandiBusinessException {
|
166 |
public void getSpecialSupport() throws ProfitMandiBusinessException {
|
| 150 |
WebListing webListing = webListingRepository.selectByUrl("special-support");
|
167 |
WebListing webListing = webListingRepository.selectByUrl("special-support");
|
| 151 |
|
168 |
|
| 152 |
List<Integer> catalogItemIds = schemeRepository.getActiveScheme(SchemeType.SPECIAL_SUPPORT, LocalDate.now().plusDays(1));
|
169 |
List<Integer> catalogItemIds = schemeRepository.getActiveScheme(SchemeType.SPECIAL_SUPPORT, LocalDate.now().plusDays(1));
|
| 153 |
|
170 |
|
| 154 |
LOGGER.info("catalogItemIds {}", catalogItemIds);
|
171 |
LOGGER.info("catalogItemIds {}", catalogItemIds);
|
| - |
|
172 |
// Wipe first so items whose scheme ended get cleared even when no
|
| 155 |
if (!catalogItemIds.isEmpty()) {
|
173 |
// Special Support scheme is active on this day.
|
| 156 |
webProductListingRepository.deleteByEqual(webListing.getId());
|
174 |
webProductListingRepository.deleteByEqual(webListing.getId());
|
| 157 |
int count = 0;
|
175 |
int count = 0;
|
| 158 |
for (Integer catalogItemId : catalogItemIds) {
|
176 |
for (Integer catalogItemId : catalogItemIds) {
|
| 159 |
|
177 |
|
| 160 |
WebProductListing webProductListing = new WebProductListing();
|
178 |
WebProductListing webProductListing = new WebProductListing();
|
| 161 |
webProductListing.setEntityId(catalogItemId);
|
179 |
webProductListing.setEntityId(catalogItemId);
|
| 162 |
webProductListing.setWebListingId(webListing.getId());
|
180 |
webProductListing.setWebListingId(webListing.getId());
|
| 163 |
count = count + 1;
|
181 |
count = count + 1;
|
| 164 |
webProductListing.setRank(count);
|
182 |
webProductListing.setRank(count);
|
| 165 |
webProductListingRepository.persist(webProductListing);
|
183 |
webProductListingRepository.persist(webProductListing);
|
| 166 |
|
- |
|
| 167 |
}
|
- |
|
| 168 |
|
184 |
|
| 169 |
}
|
185 |
}
|
| 170 |
}
|
186 |
}
|
| 171 |
|
187 |
|
| 172 |
public void getUpgradeOffer() throws ProfitMandiBusinessException {
|
188 |
public void getUpgradeOffer() throws ProfitMandiBusinessException {
|