| 21285 |
kshitij.so |
1 |
package com.spice.profitmandi.web.services;
|
|
|
2 |
|
|
|
3 |
|
|
|
4 |
import java.io.IOException;
|
| 21744 |
ashik.ali |
5 |
|
| 21285 |
kshitij.so |
6 |
import java.io.InputStream;
|
|
|
7 |
import java.net.URISyntaxException;
|
|
|
8 |
import java.net.URL;
|
| 33873 |
ranu |
9 |
import java.time.LocalDate;
|
|
|
10 |
import java.util.*;
|
|
|
11 |
import java.util.stream.Collectors;
|
| 21285 |
kshitij.so |
12 |
|
| 33873 |
ranu |
13 |
import com.spice.profitmandi.common.enumuration.SchemeType;
|
|
|
14 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
|
|
15 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
|
|
16 |
import com.spice.profitmandi.common.web.client.RestClient;
|
|
|
17 |
import com.spice.profitmandi.dao.entity.catalog.ComboModel;
|
|
|
18 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
|
|
19 |
import com.spice.profitmandi.dao.entity.dtr.WebOffer;
|
|
|
20 |
import com.spice.profitmandi.dao.entity.inventory.SaholicCISTable;
|
|
|
21 |
import com.spice.profitmandi.dao.entity.inventory.SaholicPOItem;
|
|
|
22 |
import com.spice.profitmandi.dao.model.AmountModel;
|
|
|
23 |
import com.spice.profitmandi.dao.model.CreateOfferRequest;
|
|
|
24 |
import com.spice.profitmandi.dao.repository.catalog.ComboModelRepository;
|
|
|
25 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
|
|
26 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
|
|
27 |
import com.spice.profitmandi.dao.repository.dtr.WebOfferRepository;
|
|
|
28 |
import com.spice.profitmandi.dao.repository.inventory.SaholicCISTableRepository;
|
|
|
29 |
import com.spice.profitmandi.service.inventory.FofoAvailabilityInfo;
|
|
|
30 |
import com.spice.profitmandi.service.inventory.FofoCatalogResponse;
|
|
|
31 |
import com.spice.profitmandi.service.inventory.SaholicInventoryService;
|
|
|
32 |
import com.spice.profitmandi.service.pricecircular.PriceCircularItemModelNew;
|
|
|
33 |
import com.spice.profitmandi.service.pricecircular.PriceCircularModel;
|
|
|
34 |
import com.spice.profitmandi.service.pricecircular.PriceCircularService;
|
|
|
35 |
import com.spice.profitmandi.service.scheme.SchemeService;
|
| 21285 |
kshitij.so |
36 |
import org.apache.commons.io.IOUtils;
|
| 33873 |
ranu |
37 |
import org.apache.commons.lang3.StringUtils;
|
| 21285 |
kshitij.so |
38 |
import org.apache.http.client.utils.URIBuilder;
|
| 33873 |
ranu |
39 |
import org.apache.http.conn.HttpHostConnectException;
|
| 23568 |
govind |
40 |
import org.apache.logging.log4j.Logger;
|
|
|
41 |
import org.apache.logging.log4j.LogManager;
|
| 33873 |
ranu |
42 |
import org.json.JSONArray;
|
|
|
43 |
import org.json.JSONObject;
|
|
|
44 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 21339 |
kshitij.so |
45 |
import org.springframework.beans.factory.annotation.Value;
|
| 21287 |
kshitij.so |
46 |
import org.springframework.stereotype.Component;
|
| 21285 |
kshitij.so |
47 |
|
|
|
48 |
|
| 25387 |
amit.gupta |
49 |
@Component("solrService")
|
| 21285 |
kshitij.so |
50 |
public class SolrService{
|
|
|
51 |
|
| 23568 |
govind |
52 |
private static final Logger logger=LogManager.getLogger(SolrService.class);
|
| 21285 |
kshitij.so |
53 |
|
| 21339 |
kshitij.so |
54 |
@Value("${solr.url}")
|
|
|
55 |
private String SOLR_URL;
|
| 33873 |
ranu |
56 |
|
|
|
57 |
@Value("${new.solr.url}")
|
|
|
58 |
private String solrUrl;
|
|
|
59 |
|
|
|
60 |
@Autowired
|
|
|
61 |
private FofoStoreRepository fofoStoreRepository;
|
|
|
62 |
|
|
|
63 |
@Autowired
|
|
|
64 |
private PriceCircularService priceCircularService;
|
|
|
65 |
|
|
|
66 |
@Autowired
|
|
|
67 |
private SaholicInventoryService saholicInventoryService;
|
|
|
68 |
|
|
|
69 |
@Autowired
|
|
|
70 |
private WebOfferRepository webOfferRepository;
|
|
|
71 |
|
|
|
72 |
@Autowired
|
|
|
73 |
private ComboModelRepository comboModelRepository;
|
|
|
74 |
|
|
|
75 |
@Autowired
|
|
|
76 |
private SchemeService schemeService;
|
|
|
77 |
|
|
|
78 |
@Autowired
|
|
|
79 |
private ItemRepository itemRepository;
|
|
|
80 |
|
|
|
81 |
@Autowired
|
|
|
82 |
private SaholicCISTableRepository saholicCISTableRepository;
|
|
|
83 |
|
| 21285 |
kshitij.so |
84 |
private static final String limit ="20";
|
|
|
85 |
private static final String groupLimit = "10";
|
|
|
86 |
private static final String autoSuggestField = "title,subCategoryId,category_id,category,subCategory,score";
|
|
|
87 |
private static final String searchResultsField = "title,skuBundleId,id,thumbnail,ids";
|
|
|
88 |
private static final String outputFormat = "json";
|
|
|
89 |
|
|
|
90 |
|
|
|
91 |
|
|
|
92 |
public String getSuggestions(String search_text) throws URISyntaxException, IOException{
|
| 21517 |
kshitij.so |
93 |
|
| 21285 |
kshitij.so |
94 |
URIBuilder autoSuggestUrl = new URIBuilder(SOLR_URL);
|
|
|
95 |
autoSuggestUrl.addParameter("fl", autoSuggestField); //Fields to choose
|
|
|
96 |
autoSuggestUrl.addParameter("wt", outputFormat); //Output format
|
|
|
97 |
autoSuggestUrl.addParameter("group", "true"); //group data
|
|
|
98 |
autoSuggestUrl.addParameter("group.query", "category_id:3"); //group by category
|
|
|
99 |
autoSuggestUrl.addParameter("group.query", "category_id:5"); //group by category
|
|
|
100 |
autoSuggestUrl.addParameter("group.field", "subCategoryId"); //group by subCategory
|
|
|
101 |
autoSuggestUrl.addParameter("group.limit", groupLimit);
|
|
|
102 |
autoSuggestUrl.addParameter("q", "suggest:("+search_text+")");
|
|
|
103 |
URL url = autoSuggestUrl.build().toURL();
|
| 24995 |
amit.gupta |
104 |
logger.info("Auto Suggest Solr");
|
| 21285 |
kshitij.so |
105 |
InputStream is = url.openStream();
|
|
|
106 |
String jsonString;
|
|
|
107 |
try{
|
|
|
108 |
jsonString = IOUtils.toString(is, "UTF-8");
|
|
|
109 |
}
|
|
|
110 |
finally{
|
|
|
111 |
is.close();
|
|
|
112 |
}
|
|
|
113 |
return jsonString;
|
|
|
114 |
}
|
|
|
115 |
|
| 21287 |
kshitij.so |
116 |
public String getSearchResults(String search_text, int offset) throws URISyntaxException, IOException{
|
| 21517 |
kshitij.so |
117 |
|
| 21285 |
kshitij.so |
118 |
URIBuilder generalSearchUrl = new URIBuilder(SOLR_URL);
|
|
|
119 |
generalSearchUrl.addParameter("q", search_text);
|
|
|
120 |
generalSearchUrl.addParameter("fl", searchResultsField); //Fields to choose
|
|
|
121 |
generalSearchUrl.addParameter("wt", outputFormat); //Output format
|
|
|
122 |
generalSearchUrl.addParameter("rows", limit); //limit
|
| 21288 |
kshitij.so |
123 |
generalSearchUrl.setParameter("start", String.valueOf(offset));
|
| 21285 |
kshitij.so |
124 |
URL url = generalSearchUrl.build().toURL();
|
|
|
125 |
InputStream is = url.openStream();
|
|
|
126 |
String jsonString;
|
|
|
127 |
try{
|
|
|
128 |
jsonString = IOUtils.toString(is, "UTF-8");
|
|
|
129 |
}
|
|
|
130 |
finally{
|
|
|
131 |
is.close();
|
|
|
132 |
}
|
|
|
133 |
return jsonString;
|
|
|
134 |
}
|
|
|
135 |
|
| 33873 |
ranu |
136 |
public List<FofoCatalogResponse> dealResponse (Set<Integer> catalogIds, int fofoId) throws Exception {
|
|
|
137 |
List<FofoCatalogResponse> dealResponse = new ArrayList<>();
|
|
|
138 |
RestClient rc = new RestClient();
|
|
|
139 |
Map<String, String> params = new HashMap<>();
|
|
|
140 |
List<String> mandatoryQ = new ArrayList<>();
|
|
|
141 |
mandatoryQ.add(String.format("+catalogId_i:(%s) +{!parent which=\"id:catalog*\"}", StringUtils.join(catalogIds, " ")));
|
|
|
142 |
params.put("start", "0");
|
|
|
143 |
params.put("rows", "100");
|
|
|
144 |
params.put("q", StringUtils.join(mandatoryQ, " "));
|
|
|
145 |
params.put("fl", "*, [child parentFilter=id:catalog*]");
|
|
|
146 |
|
|
|
147 |
params.put("wt", "json");
|
|
|
148 |
String response = null;
|
|
|
149 |
try {
|
|
|
150 |
response = rc.get(SchemeType.HTTP, solrUrl, 8984, "solr/demo/select", params);
|
|
|
151 |
} catch (HttpHostConnectException e) {
|
|
|
152 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
|
|
153 |
}
|
|
|
154 |
JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
|
|
|
155 |
JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
|
|
|
156 |
dealResponse = getCatalogResponse(docs, false, fofoId);
|
|
|
157 |
|
|
|
158 |
return dealResponse;
|
|
|
159 |
|
|
|
160 |
}
|
|
|
161 |
|
|
|
162 |
|
|
|
163 |
private List<FofoCatalogResponse> getCatalogResponse(JSONArray docs, boolean hotDeal, int fofoId) throws
|
|
|
164 |
Exception {
|
|
|
165 |
List<FofoCatalogResponse> dealResponse = new ArrayList<>();
|
|
|
166 |
List<Integer> tagIds = Arrays.asList(4);
|
|
|
167 |
List<Integer> itemIds = new ArrayList<>();
|
|
|
168 |
if (docs.length() > 0) {
|
|
|
169 |
for (int i = 0; i < docs.length(); i++) {
|
|
|
170 |
JSONObject doc = docs.getJSONObject(i);
|
|
|
171 |
if (doc.has("_childDocuments_")) {
|
|
|
172 |
for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
|
|
|
173 |
JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
|
|
|
174 |
int itemId = childItem.getInt("itemId_i");
|
|
|
175 |
itemIds.add(itemId);
|
|
|
176 |
}
|
|
|
177 |
}
|
|
|
178 |
}
|
|
|
179 |
if (itemIds.size() == 0) {
|
|
|
180 |
return dealResponse;
|
|
|
181 |
}
|
|
|
182 |
}
|
|
|
183 |
// get warehouse Id
|
|
|
184 |
int warehouseId = fofoStoreRepository.selectByRetailerId(fofoId).getWarehouseId();
|
|
|
185 |
Map<Integer, List<SaholicPOItem>> poItemAvailabilityMap = saholicInventoryService.getSaholicPOItems().get(warehouseId);
|
|
|
186 |
List<Integer> catalogIds = new ArrayList<>();
|
|
|
187 |
for (int i = 0; i < docs.length(); i++) {
|
|
|
188 |
Map<Integer, FofoAvailabilityInfo> fofoAvailabilityInfoMap = new HashMap<>();
|
|
|
189 |
JSONObject doc = docs.getJSONObject(i);
|
|
|
190 |
catalogIds.add(doc.getInt("catalogId_i"));
|
|
|
191 |
}
|
|
|
192 |
List<CreateOfferRequest> allSchemOffers = null;
|
|
|
193 |
Map<Integer, PriceCircularItemModelNew> priceCircularItemModelMap = new HashMap<>();
|
|
|
194 |
if (catalogIds.size() > 0) {
|
|
|
195 |
PriceCircularModel priceCircularModel = priceCircularService.getPriceCircularByOffer(fofoId, catalogIds, LocalDate.now());
|
|
|
196 |
allSchemOffers = priceCircularModel.getOffers();
|
|
|
197 |
|
|
|
198 |
List<PriceCircularItemModelNew> priceCircularItemModelNews = priceCircularModel.getPriceCircularItemModelNews();
|
|
|
199 |
if (priceCircularItemModelNews != null) {
|
|
|
200 |
priceCircularItemModelMap = priceCircularItemModelNews.stream().collect(Collectors.toMap(x -> x.getCatalogId(), x -> x));
|
|
|
201 |
}
|
|
|
202 |
}
|
|
|
203 |
|
|
|
204 |
/*List<CatalogFavourite> catalogFavourites = catalogFavouriteRepository.selectBypartnerId(fofoId);
|
|
|
205 |
List<Integer> catalogFavouriteIds = new ArrayList<>();
|
|
|
206 |
if (!catalogFavourites.isEmpty()) {
|
|
|
207 |
catalogFavouriteIds = catalogFavourites.stream().map(x -> x.getCatalogId()).collect(Collectors.toList());
|
|
|
208 |
}
|
|
|
209 |
|
|
|
210 |
if (!catalogFavourites.isEmpty()) {
|
|
|
211 |
catalogFavourites.stream().collect(Collectors.toMap(x -> x.getCatalogId(), x -> x));
|
|
|
212 |
}*/
|
|
|
213 |
|
|
|
214 |
for (int i = 0; i < docs.length(); i++) {
|
|
|
215 |
Map<Integer, FofoAvailabilityInfo> fofoAvailabilityInfoMap = new HashMap<>();
|
|
|
216 |
JSONObject doc = docs.getJSONObject(i);
|
|
|
217 |
FofoCatalogResponse fofoCatalogResponse = new FofoCatalogResponse();
|
|
|
218 |
fofoCatalogResponse.setCatalogId(doc.getInt("catalogId_i"));
|
|
|
219 |
fofoCatalogResponse.setImageUrl(doc.getString("imageUrl_s"));
|
|
|
220 |
fofoCatalogResponse.setTitle(doc.getString("title_s"));
|
|
|
221 |
|
|
|
222 |
/*if (catalogFavouriteIds.contains(fofoCatalogResponse.getCatalogId())) {
|
|
|
223 |
fofoCatalogResponse.setFavourite(true);
|
|
|
224 |
}*/
|
|
|
225 |
|
|
|
226 |
List<WebOffer> webOffers = webOfferRepository.selectAllActiveOffers().get(fofoCatalogResponse.getCatalogId());
|
|
|
227 |
|
|
|
228 |
//logger.info("webOffers {}", webOffers);
|
|
|
229 |
if (webOffers != null && webOffers.size() > 0) {
|
|
|
230 |
fofoCatalogResponse.setWebOffers(webOffers);
|
|
|
231 |
fofoCatalogResponse.setOffers(webOffers.stream().map(x -> x.getTitle()).collect(Collectors.toList()));
|
|
|
232 |
|
|
|
233 |
}
|
|
|
234 |
|
|
|
235 |
List<ComboModel> comboModels = comboModelRepository.selectByWarehouseId(warehouseId).stream().filter(x -> x.getCatalogId() == fofoCatalogResponse.getCatalogId()).collect(Collectors.toList());
|
|
|
236 |
|
|
|
237 |
//logger.info("comboModels {}", comboModels);
|
|
|
238 |
|
|
|
239 |
if (comboModels != null && comboModels.size() > 0) {
|
|
|
240 |
fofoCatalogResponse.setComboModels(comboModels);
|
|
|
241 |
}
|
|
|
242 |
|
|
|
243 |
try {
|
|
|
244 |
fofoCatalogResponse.setFeature(doc.getString("feature_s"));
|
|
|
245 |
} catch (Exception e) {
|
|
|
246 |
fofoCatalogResponse.setFeature(null);
|
|
|
247 |
logger.info("Could not find Feature_s for {}", fofoCatalogResponse.getCatalogId());
|
|
|
248 |
}
|
|
|
249 |
|
|
|
250 |
fofoCatalogResponse.setBrand(doc.getJSONArray("brand_ss").getString(0));
|
|
|
251 |
logger.info("labelss {}", doc.has("label_ss"));
|
|
|
252 |
|
|
|
253 |
if (doc.has("label_ss")) {
|
|
|
254 |
logger.info("label {}", doc.getJSONArray("label_ss"));
|
|
|
255 |
|
|
|
256 |
JSONArray arr = doc.getJSONArray("label_ss");
|
|
|
257 |
Set<String> labels = new HashSet<String>();
|
|
|
258 |
for (int j = 0; j < arr.length(); j++) {
|
|
|
259 |
labels.add(arr.getString(j));
|
|
|
260 |
}
|
|
|
261 |
|
|
|
262 |
fofoCatalogResponse.setLabels(new ArrayList<>(labels));
|
|
|
263 |
|
|
|
264 |
}
|
|
|
265 |
if (doc.has("similarModels_ii")) {
|
|
|
266 |
JSONArray similarModelsArray = doc.getJSONArray("similarModels_ii");
|
|
|
267 |
List<Integer> similarCatalogIds = new ArrayList<>();
|
|
|
268 |
for (int j = 0; j < similarModelsArray.length(); j++) {
|
|
|
269 |
similarCatalogIds.add(similarModelsArray.getInt(j));
|
|
|
270 |
}
|
|
|
271 |
fofoCatalogResponse.setSimilarModelIds(similarCatalogIds);
|
|
|
272 |
}
|
|
|
273 |
|
|
|
274 |
if (doc.has("_childDocuments_")) {
|
|
|
275 |
String modelColorClass = "grey";
|
|
|
276 |
FofoAvailabilityInfo fdiAnyColour = null;
|
|
|
277 |
// Iterating itemIds
|
|
|
278 |
for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
|
|
|
279 |
PriceCircularItemModelNew priceCircularItemModel = priceCircularItemModelMap.get(fofoCatalogResponse.getCatalogId());
|
|
|
280 |
JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
|
|
|
281 |
int itemId = childItem.getInt("itemId_i");
|
|
|
282 |
float sellingPrice = (float) childItem.getDouble("sellingPrice_f");
|
|
|
283 |
if (!fofoAvailabilityInfoMap.containsKey(itemId)) {
|
|
|
284 |
FofoAvailabilityInfo fdi = new FofoAvailabilityInfo();
|
|
|
285 |
List<SaholicCISTable> currentAvailability = saholicCISTableRepository.selectByItemWarehouse(itemId, warehouseId);
|
|
|
286 |
List<SaholicPOItem> poItemAvailability = null;
|
|
|
287 |
if (poItemAvailabilityMap != null) {
|
|
|
288 |
poItemAvailability = poItemAvailabilityMap.get(itemId);
|
|
|
289 |
}
|
|
|
290 |
|
|
|
291 |
if (priceCircularItemModel != null) {
|
|
|
292 |
fdi.setNlc((float) priceCircularItemModel.getNetNlc());
|
|
|
293 |
}
|
|
|
294 |
|
|
|
295 |
for (SaholicCISTable saholicCISTable : currentAvailability) {
|
|
|
296 |
saholicCISTable.setWarehouseName(
|
|
|
297 |
ProfitMandiConstants.WAREHOUSE_MAP.get(saholicCISTable.getWarehouseFrom()));
|
|
|
298 |
}
|
|
|
299 |
|
|
|
300 |
Map<Integer, SaholicCISTable> map = currentAvailability.stream().collect(Collectors.toMap(SaholicCISTable::getWarehouseFrom, x -> x));
|
|
|
301 |
if (poItemAvailability != null) {
|
|
|
302 |
for (SaholicPOItem saholicPOItem : poItemAvailability) {
|
|
|
303 |
if (map.containsKey(saholicPOItem.getWarehouseFrom())) {
|
|
|
304 |
map.get(saholicPOItem.getWarehouseFrom()).setPopendingQty(saholicPOItem.getUnfulfilledQty());
|
|
|
305 |
} else {
|
|
|
306 |
SaholicCISTable saholicCISTable = new SaholicCISTable();
|
|
|
307 |
saholicCISTable.setAvailability(0);
|
|
|
308 |
saholicCISTable.setReserved(0);
|
|
|
309 |
saholicCISTable.setItemId(itemId);
|
|
|
310 |
saholicCISTable.setWarehouseId(warehouseId);
|
|
|
311 |
saholicCISTable.setPopendingQty(saholicPOItem.getUnfulfilledQty());
|
|
|
312 |
saholicCISTable.setWarehouseFrom(saholicPOItem.getWarehouseFrom());
|
|
|
313 |
saholicCISTable.setWarehouseName(
|
|
|
314 |
ProfitMandiConstants.WAREHOUSE_MAP.get(saholicPOItem.getWarehouseFrom()));
|
|
|
315 |
map.put(saholicPOItem.getWarehouseFrom(), saholicCISTable);
|
|
|
316 |
}
|
|
|
317 |
}
|
|
|
318 |
}
|
|
|
319 |
fdi.setSaholicCISTableList(new ArrayList<>(map.values()));
|
|
|
320 |
String poColor = "grey";
|
|
|
321 |
boolean active = false;
|
|
|
322 |
if (currentAvailability != null && currentAvailability.stream().collect(Collectors.summingInt(SaholicCISTable::getNetAvailability)) > 0) {
|
|
|
323 |
poColor = "green";
|
|
|
324 |
modelColorClass = "green";
|
|
|
325 |
} else if (poItemAvailability != null && poItemAvailability.stream().collect(Collectors.summingInt(SaholicPOItem::getUnfulfilledQty)) > 0) {
|
|
|
326 |
if (currentAvailability != null && poItemAvailability.stream().collect(Collectors.summingInt(SaholicPOItem::getUnfulfilledQty)) + currentAvailability.stream().collect(Collectors.summingInt(SaholicCISTable::getNetAvailability)) <= 0) {
|
|
|
327 |
poColor = "grey";
|
|
|
328 |
} else {
|
|
|
329 |
poColor = "yellow";
|
|
|
330 |
if (modelColorClass != "green") {
|
|
|
331 |
modelColorClass = poColor;
|
|
|
332 |
}
|
|
|
333 |
}
|
|
|
334 |
}
|
|
|
335 |
fdi.setColorClass(poColor);
|
|
|
336 |
fdi.setSellingPrice(sellingPrice);
|
|
|
337 |
fdi.setActive(active);
|
|
|
338 |
fdi.setMrp(childItem.getDouble("mrp_f"));
|
|
|
339 |
fdi.setMop((float) childItem.getDouble("mop_f"));
|
|
|
340 |
fdi.setColor(childItem.has("color_s") ? childItem.getString("color_s") : "");
|
|
|
341 |
if (fdi.getColor().equalsIgnoreCase("any colour")) {
|
|
|
342 |
fdiAnyColour = fdi;
|
|
|
343 |
}
|
|
|
344 |
fdi.setTagId(childItem.getInt("tagId_i"));
|
|
|
345 |
fdi.setItem_id(itemId);
|
| 34196 |
ranu |
346 |
fdi.setCatalog_id(doc.getInt("catalogId_i"));
|
| 33873 |
ranu |
347 |
Float cashBack = schemeService.getCatalogSchemeCashBack(fofoId, Arrays.asList(fofoCatalogResponse.getCatalogId())).get(fofoCatalogResponse.getCatalogId());
|
|
|
348 |
cashBack = cashBack == null ? 0 : cashBack;
|
|
|
349 |
fdi.setCashback(cashBack);
|
|
|
350 |
fdi.setMinBuyQuantity(1);
|
|
|
351 |
if (hotDeal) {
|
|
|
352 |
if (currentAvailability != null) {
|
|
|
353 |
fdi.setAvailability(currentAvailability.stream().collect(Collectors.summingInt(SaholicCISTable::getNetAvailability)));
|
|
|
354 |
} else {
|
|
|
355 |
fdi.setAvailability(0);
|
|
|
356 |
}
|
|
|
357 |
} else {
|
|
|
358 |
// Lets consider that its out of stock
|
|
|
359 |
fdi.setAvailability(400);
|
|
|
360 |
Item item = null;
|
|
|
361 |
try {
|
|
|
362 |
item = itemRepository.selectById(itemId);
|
|
|
363 |
} catch (Exception e) {
|
|
|
364 |
e.printStackTrace();
|
|
|
365 |
continue;
|
|
|
366 |
}
|
|
|
367 |
// In case its tampered glass moq should be
|
|
|
368 |
if (item.getCategoryId() == 10020) {
|
|
|
369 |
fdi.setMinBuyQuantity(5);
|
|
|
370 |
}
|
|
|
371 |
}
|
|
|
372 |
fdi.setQuantityStep(1);
|
|
|
373 |
fdi.setMaxQuantity(Math.min(fdi.getAvailability(), 400));
|
|
|
374 |
fofoAvailabilityInfoMap.put(itemId, fdi);
|
|
|
375 |
}
|
|
|
376 |
}
|
|
|
377 |
if (fdiAnyColour != null) {
|
|
|
378 |
fdiAnyColour.setColorClass(modelColorClass);
|
|
|
379 |
}
|
|
|
380 |
fofoCatalogResponse.setInStock(!modelColorClass.equals("grey"));
|
|
|
381 |
}
|
|
|
382 |
if (fofoAvailabilityInfoMap.values().size() > 0) {
|
|
|
383 |
List<FofoAvailabilityInfo> availabilityList = fofoAvailabilityInfoMap.values().stream().sorted(Comparator.comparing(FofoAvailabilityInfo::getAvailability).reversed()).collect(Collectors.toList());
|
|
|
384 |
fofoCatalogResponse.setItems(availabilityList);
|
|
|
385 |
if (priceCircularItemModelMap.containsKey(fofoCatalogResponse.getCatalogId())) {
|
|
|
386 |
PriceCircularItemModelNew priceCircularItemModel = priceCircularItemModelMap.get(fofoCatalogResponse.getCatalogId());
|
|
|
387 |
if (priceCircularItemModel.getSlabPayouts() != null) {
|
|
|
388 |
List<CreateOfferRequest> schemeOffers = new ArrayList<>();
|
|
|
389 |
List<Map<Integer, AmountModel>> slabPayouts = priceCircularItemModel.getSlabPayouts();
|
|
|
390 |
Iterator<Map<Integer, AmountModel>> iterator = slabPayouts.iterator();
|
|
|
391 |
int iteratorCount = 0;
|
|
|
392 |
while (iterator.hasNext()) {
|
|
|
393 |
Map<Integer, AmountModel> slabPayoutMap = iterator.next();
|
|
|
394 |
if (slabPayoutMap != null) {
|
|
|
395 |
schemeOffers.add(allSchemOffers.get(iteratorCount));
|
|
|
396 |
} else {
|
|
|
397 |
iterator.remove();
|
|
|
398 |
}
|
|
|
399 |
iteratorCount++;
|
|
|
400 |
}
|
|
|
401 |
fofoCatalogResponse.setSchemeOffers(schemeOffers);
|
|
|
402 |
}
|
|
|
403 |
fofoCatalogResponse.setPriceCircularItemModel(priceCircularItemModel);
|
|
|
404 |
}
|
|
|
405 |
dealResponse.add(fofoCatalogResponse);
|
|
|
406 |
}
|
|
|
407 |
}
|
|
|
408 |
return dealResponse;
|
|
|
409 |
|
|
|
410 |
}
|
|
|
411 |
|
| 21285 |
kshitij.so |
412 |
}
|