| 31604 |
tejbeer |
1 |
package com.spice.profitmandi.dao.service.solr;
|
|
|
2 |
|
|
|
3 |
import java.io.BufferedReader;
|
|
|
4 |
import java.io.IOException;
|
|
|
5 |
import java.io.InputStream;
|
|
|
6 |
import java.io.InputStreamReader;
|
|
|
7 |
import java.net.HttpURLConnection;
|
|
|
8 |
import java.net.URL;
|
|
|
9 |
import java.net.URLConnection;
|
|
|
10 |
import java.time.ZoneId;
|
|
|
11 |
import java.util.ArrayList;
|
|
|
12 |
import java.util.Arrays;
|
|
|
13 |
import java.util.HashMap;
|
|
|
14 |
import java.util.List;
|
|
|
15 |
import java.util.Map;
|
|
|
16 |
import java.util.Map.Entry;
|
|
|
17 |
import java.util.stream.Collectors;
|
|
|
18 |
import java.util.zip.GZIPInputStream;
|
|
|
19 |
|
|
|
20 |
import org.apache.logging.log4j.LogManager;
|
|
|
21 |
import org.apache.logging.log4j.Logger;
|
|
|
22 |
import org.apache.solr.client.solrj.SolrClient;
|
|
|
23 |
import org.apache.solr.client.solrj.impl.HttpSolrClient;
|
|
|
24 |
import org.apache.solr.common.SolrInputDocument;
|
|
|
25 |
import org.json.JSONArray;
|
|
|
26 |
import org.json.JSONException;
|
|
|
27 |
import org.json.JSONObject;
|
|
|
28 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 31613 |
tejbeer |
29 |
import org.springframework.beans.factory.annotation.Value;
|
| 31604 |
tejbeer |
30 |
import org.springframework.stereotype.Component;
|
|
|
31 |
|
|
|
32 |
import com.google.gson.Gson;
|
|
|
33 |
import com.spice.profitmandi.dao.entity.catalog.TagListing;
|
|
|
34 |
import com.spice.profitmandi.dao.entity.catalog.TagRanking;
|
| 31612 |
tejbeer |
35 |
import com.spice.profitmandi.dao.entity.dtr.WebProductListing;
|
| 31604 |
tejbeer |
36 |
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
|
|
|
37 |
import com.spice.profitmandi.dao.repository.catalog.TagRankingRepository;
|
|
|
38 |
import com.spice.profitmandi.dao.repository.dtr.Mongo;
|
| 31612 |
tejbeer |
39 |
import com.spice.profitmandi.dao.repository.dtr.WebListingRepository;
|
|
|
40 |
import com.spice.profitmandi.dao.repository.dtr.WebProductListingRepository;
|
| 31604 |
tejbeer |
41 |
import com.spice.profitmandi.service.tag.ItemTagModel;
|
|
|
42 |
|
|
|
43 |
import in.shop2020.model.v1.catalog.status;
|
|
|
44 |
|
|
|
45 |
@Component
|
|
|
46 |
public class FofoSolr {
|
|
|
47 |
|
|
|
48 |
@Autowired
|
|
|
49 |
private Gson gson;
|
|
|
50 |
|
|
|
51 |
@Autowired
|
|
|
52 |
private TagListingRepository tagListingRepository;
|
|
|
53 |
|
|
|
54 |
@Autowired
|
|
|
55 |
TagRankingRepository tagRankingRepository;
|
|
|
56 |
|
|
|
57 |
@Autowired
|
|
|
58 |
private Mongo contentMongoClient;
|
|
|
59 |
|
| 31612 |
tejbeer |
60 |
@Autowired
|
|
|
61 |
private WebListingRepository webListingRepository;
|
|
|
62 |
|
|
|
63 |
@Autowired
|
|
|
64 |
private WebProductListingRepository webProductListingRepository;
|
|
|
65 |
|
| 31613 |
tejbeer |
66 |
@Value("${new.solr.url}")
|
|
|
67 |
private String solrUrl;
|
|
|
68 |
|
| 31604 |
tejbeer |
69 |
private static final Logger logger = LogManager.getLogger(FofoSolr.class);
|
|
|
70 |
|
|
|
71 |
private static final List<Integer> CATEGORY_MASTER = Arrays.asList(10006, 10010, 14202, 14203);
|
|
|
72 |
|
| 31623 |
tejbeer |
73 |
String solrPath = "http://" + "50.116.10.120" + ":8984/solr/demo";
|
| 31604 |
tejbeer |
74 |
String mongoHost = "localhost";
|
|
|
75 |
SolrClient solr = new HttpSolrClient.Builder(solrPath).build();
|
|
|
76 |
|
|
|
77 |
private String getAvailabilityJSON() {
|
|
|
78 |
String url = "http://50.116.10.120/reports/run.php?execute_mode=EXECUTE&xmlin=warehousecisnew.xml&project=FOCOR&project_password=focor&target_format=JSON";
|
|
|
79 |
return getUrlContent(url);
|
|
|
80 |
}
|
|
|
81 |
|
|
|
82 |
private String getPendingPOJSON() {
|
|
|
83 |
String url = "http://50.116.10.120/reports/run.php?execute_mode=EXECUTE&xmlin=UnfulfilledPOItemsNew.xml&project=FOCOR&project_password=focor&target_format=JSON";
|
|
|
84 |
return getUrlContent(url);
|
|
|
85 |
}
|
|
|
86 |
|
|
|
87 |
private static String getUrlContent(String urlString) {
|
|
|
88 |
BufferedReader reader = null;
|
|
|
89 |
try {
|
|
|
90 |
URL url = new URL(urlString);
|
|
|
91 |
URLConnection conn = url.openConnection();
|
|
|
92 |
conn.setConnectTimeout(5000);
|
|
|
93 |
conn.setReadTimeout(5000);
|
|
|
94 |
reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
|
|
95 |
return reader.lines().collect(Collectors.joining(System.lineSeparator()));
|
|
|
96 |
} catch (IOException e) {
|
|
|
97 |
e.printStackTrace();
|
|
|
98 |
} finally {
|
|
|
99 |
if (reader != null) {
|
|
|
100 |
try {
|
|
|
101 |
reader.close();
|
|
|
102 |
} catch (IOException e) {
|
|
|
103 |
e.printStackTrace();
|
|
|
104 |
}
|
|
|
105 |
}
|
|
|
106 |
}
|
|
|
107 |
return null;
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
public JSONArray getAvailability() throws IOException, JSONException {
|
|
|
111 |
String url = "http://50.116.10.120/reports/run.php?execute_mode=EXECUTE&xmlin=warehousecisnew.xml&project=FOCOR&project_password=focor&target_format=JSON";
|
|
|
112 |
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
|
|
|
113 |
connection.setRequestProperty("Accept-Encoding", "gzip");
|
|
|
114 |
BufferedReader reader = null;
|
|
|
115 |
|
|
|
116 |
try {
|
|
|
117 |
InputStream inputStream = connection.getInputStream();
|
|
|
118 |
|
|
|
119 |
if ("gzip".equals(connection.getContentEncoding())) {
|
|
|
120 |
inputStream = new GZIPInputStream(inputStream);
|
|
|
121 |
}
|
|
|
122 |
|
|
|
123 |
reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
|
|
|
124 |
StringBuilder responseBuilder = new StringBuilder();
|
|
|
125 |
String line;
|
|
|
126 |
|
|
|
127 |
while ((line = reader.readLine()) != null) {
|
|
|
128 |
responseBuilder.append(line);
|
|
|
129 |
}
|
|
|
130 |
|
|
|
131 |
JSONObject responseJson = new JSONObject(responseBuilder.toString());
|
|
|
132 |
return responseJson.getJSONArray("data");
|
|
|
133 |
} finally {
|
|
|
134 |
if (reader != null) {
|
|
|
135 |
try {
|
|
|
136 |
reader.close();
|
|
|
137 |
} catch (IOException e) {
|
|
|
138 |
// Ignore
|
|
|
139 |
}
|
|
|
140 |
}
|
|
|
141 |
}
|
|
|
142 |
}
|
|
|
143 |
|
|
|
144 |
public JSONArray getPendingPO() throws IOException, JSONException {
|
|
|
145 |
String url = "http://50.116.10.120/reports/run.php?execute_mode=EXECUTE&xmlin=UnfulfilledPOItemsNew.xml&project=FOCOR&project_password=focor&target_format=JSON";
|
|
|
146 |
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
|
|
|
147 |
connection.setRequestProperty("Accept-Encoding", "gzip");
|
|
|
148 |
BufferedReader reader = null;
|
|
|
149 |
|
|
|
150 |
try {
|
|
|
151 |
InputStream inputStream = connection.getInputStream();
|
|
|
152 |
|
|
|
153 |
if ("gzip".equals(connection.getContentEncoding())) {
|
|
|
154 |
inputStream = new GZIPInputStream(inputStream);
|
|
|
155 |
}
|
|
|
156 |
|
|
|
157 |
reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
|
|
|
158 |
StringBuilder responseBuilder = new StringBuilder();
|
|
|
159 |
String line;
|
|
|
160 |
|
|
|
161 |
while ((line = reader.readLine()) != null) {
|
|
|
162 |
responseBuilder.append(line);
|
|
|
163 |
}
|
|
|
164 |
|
|
|
165 |
JSONObject responseJson = new JSONObject(responseBuilder.toString());
|
|
|
166 |
return responseJson.getJSONArray("data");
|
|
|
167 |
} finally {
|
|
|
168 |
if (reader != null) {
|
|
|
169 |
try {
|
|
|
170 |
reader.close();
|
|
|
171 |
} catch (IOException e) {
|
|
|
172 |
// Ignore
|
|
|
173 |
}
|
|
|
174 |
}
|
|
|
175 |
}
|
|
|
176 |
}
|
|
|
177 |
|
|
|
178 |
public Map<String, Map<String, Map<String, Integer>>> getItemMap() throws Exception {
|
|
|
179 |
JSONArray availabilityJSONArray = this.getAvailability();
|
|
|
180 |
JSONArray pendingPOJSONArray = this.getPendingPO();
|
|
|
181 |
Map<String, Map<String, Map<String, Integer>>> availabilityItemMap = new HashMap<>();
|
|
|
182 |
|
|
|
183 |
for (int i = 0; i < availabilityJSONArray.length(); i++) {
|
|
|
184 |
JSONObject rawAvailability = availabilityJSONArray.getJSONObject(i);
|
|
|
185 |
if (!availabilityItemMap.containsKey(rawAvailability.getString("Itemid"))) {
|
|
|
186 |
availabilityItemMap.put(rawAvailability.getString("Itemid"),
|
|
|
187 |
new HashMap<String, Map<String, Integer>>());
|
|
|
188 |
}
|
|
|
189 |
if (!availabilityItemMap.get(rawAvailability.getString("Itemid"))
|
|
|
190 |
.containsKey(rawAvailability.getString("Warehouseid"))) {
|
|
|
191 |
availabilityItemMap.get(rawAvailability.getString("Itemid"))
|
|
|
192 |
.put(rawAvailability.getString("Warehouseid"), new HashMap<String, Integer>());
|
|
|
193 |
availabilityItemMap.get(rawAvailability.getString("Itemid"))
|
|
|
194 |
.get(rawAvailability.getString("Warehouseid")).put("netAvailability", 0);
|
|
|
195 |
availabilityItemMap.get(rawAvailability.getString("Itemid"))
|
|
|
196 |
.get(rawAvailability.getString("Warehouseid")).put("netPo", 0);
|
|
|
197 |
}
|
|
|
198 |
int netAvailability = availabilityItemMap.get(rawAvailability.getString("Itemid"))
|
|
|
199 |
.get(rawAvailability.getString("Warehouseid")).get("netAvailability")
|
|
|
200 |
+ rawAvailability.getInt("Netavailability");
|
|
|
201 |
availabilityItemMap.get(rawAvailability.getString("Itemid")).get(rawAvailability.getString("Warehouseid"))
|
|
|
202 |
.put("netAvailability", netAvailability);
|
|
|
203 |
}
|
|
|
204 |
|
|
|
205 |
for (int i = 0; i < pendingPOJSONArray.length(); i++) {
|
|
|
206 |
JSONObject rawPendingPo = pendingPOJSONArray.getJSONObject(i);
|
|
|
207 |
|
|
|
208 |
String itemId = rawPendingPo.getString("Itemid");
|
|
|
209 |
String warehouseId = rawPendingPo.getString("Warehouseid");
|
|
|
210 |
if (!availabilityItemMap.containsKey(itemId)) {
|
|
|
211 |
availabilityItemMap.put(itemId, new HashMap<String, Map<String, Integer>>());
|
|
|
212 |
}
|
|
|
213 |
if (!availabilityItemMap.get(itemId).containsKey(warehouseId)) {
|
|
|
214 |
availabilityItemMap.get(itemId).put(warehouseId, new HashMap<String, Integer>() {
|
|
|
215 |
{
|
|
|
216 |
put("netAvailability", 0);
|
|
|
217 |
put("netPo", 0);
|
|
|
218 |
}
|
|
|
219 |
});
|
|
|
220 |
}
|
|
|
221 |
availabilityItemMap.get(itemId).get(warehouseId).put("netPo",
|
|
|
222 |
availabilityItemMap.get(itemId).get(warehouseId).get("netPo") + rawPendingPo.getInt("Unfulfilled"));
|
|
|
223 |
|
|
|
224 |
}
|
|
|
225 |
return availabilityItemMap;
|
|
|
226 |
|
|
|
227 |
}
|
|
|
228 |
|
| 31612 |
tejbeer |
229 |
public Map<Integer, List<String>> getLabels() {
|
| 31634 |
tejbeer |
230 |
List<String> labels = Arrays.asList("partner-best-sellers", "partner-price-drop", "new-launches",
|
|
|
231 |
"upgrade-offer", "special-support");
|
| 31612 |
tejbeer |
232 |
|
|
|
233 |
Map<Integer, String> webListing = webListingRepository.selectByUrls(labels).stream()
|
|
|
234 |
.collect(Collectors.toMap(x -> x.getId(), x -> x.getUrl()));
|
|
|
235 |
|
|
|
236 |
Map<Integer, List<WebProductListing>> webProductListingMap = webProductListingRepository
|
|
|
237 |
.selectAllByWebListingIds(new ArrayList<>(webListing.keySet())).stream()
|
|
|
238 |
.collect(Collectors.groupingBy(x -> x.getWebListingId()));
|
|
|
239 |
|
|
|
240 |
Map<Integer, List<String>> catalogLabelMap = new HashMap<>();
|
|
|
241 |
for (Entry<Integer, List<WebProductListing>> webProductListingEntry : webProductListingMap.entrySet()) {
|
|
|
242 |
|
|
|
243 |
for (WebProductListing webProduct : webProductListingEntry.getValue()) {
|
|
|
244 |
|
|
|
245 |
if (!catalogLabelMap.containsKey(webProduct.getEntityId())) {
|
|
|
246 |
|
|
|
247 |
catalogLabelMap.put(webProduct.getEntityId(), new ArrayList<>());
|
|
|
248 |
|
|
|
249 |
}
|
|
|
250 |
|
|
|
251 |
List<String> itemLabels = catalogLabelMap.get(webProduct.getEntityId());
|
|
|
252 |
itemLabels.add(webListing.get(webProduct.getWebListingId()));
|
|
|
253 |
catalogLabelMap.put(webProduct.getEntityId(), itemLabels);
|
|
|
254 |
|
|
|
255 |
}
|
|
|
256 |
|
|
|
257 |
}
|
|
|
258 |
|
|
|
259 |
return catalogLabelMap;
|
|
|
260 |
}
|
|
|
261 |
|
| 31620 |
tejbeer |
262 |
public void populateTagItems() throws Exception {
|
| 31604 |
tejbeer |
263 |
Map<String, Map<String, Map<String, Integer>>> availabilityItemMap = getItemMap();
|
|
|
264 |
List<TagRanking> tagRankingList = tagRankingRepository.getAllTagRanking();
|
|
|
265 |
List<Integer> rankingList = new ArrayList<>();
|
|
|
266 |
Map<Integer, String> featureMap = new HashMap<>();
|
|
|
267 |
for (TagRanking tagRanking : tagRankingList) {
|
|
|
268 |
rankingList.add(tagRanking.getCatalogItemId());
|
|
|
269 |
featureMap.put(tagRanking.getCatalogItemId(), tagRanking.getFeature());
|
|
|
270 |
}
|
|
|
271 |
Map<Integer, Map<String, Object>> catalogMap = new HashMap<>();
|
|
|
272 |
|
| 31612 |
tejbeer |
273 |
List<status> statuses = Arrays.asList(status.ACTIVE, status.PAUSED_BY_RISK, status.PARTIALLY_ACTIVE);
|
|
|
274 |
|
|
|
275 |
Map<Integer, List<String>> catalogLabelMap = this.getLabels();
|
|
|
276 |
|
|
|
277 |
logger.info("catalogLabelMap {}", catalogLabelMap);
|
|
|
278 |
|
|
|
279 |
/*
|
|
|
280 |
* List<ItemTagModel> tuples =
|
|
|
281 |
* tagListingRepository.getAllItemTagByStatus(statuses).stream() .filter(x ->
|
|
|
282 |
* x.getItem().getCatalogItemId() == 1023747).collect(Collectors.toList());
|
|
|
283 |
*/
|
|
|
284 |
|
| 31604 |
tejbeer |
285 |
List<ItemTagModel> tuples = tagListingRepository.getAllItemTagByStatus(statuses);
|
|
|
286 |
|
|
|
287 |
Map<String, Object> projection = new HashMap<>();
|
|
|
288 |
projection.put("defaultImageUrl", 1);
|
|
|
289 |
|
| 31710 |
tejbeer |
290 |
List<String> excludeBrands = Arrays.asList("Dummy", "FOC HANDSET");
|
| 31604 |
tejbeer |
291 |
|
|
|
292 |
for (ItemTagModel result : tuples) {
|
|
|
293 |
TagListing tag = result.getTagListing();
|
|
|
294 |
com.spice.profitmandi.dao.entity.catalog.Item item = result.getItem();
|
|
|
295 |
if (excludeBrands.contains(item.getBrand())) {
|
|
|
296 |
continue;
|
|
|
297 |
}
|
|
|
298 |
|
|
|
299 |
if (!catalogMap.containsKey(item.getCatalogItemId())) {
|
|
|
300 |
Map<String, Object> catalogObj = new HashMap<>();
|
|
|
301 |
catalogObj.put("feature", "");
|
| 31641 |
tejbeer |
302 |
catalogObj.put("hsnCode", item.getHsnCode());
|
| 31604 |
tejbeer |
303 |
catalogObj.put("title",
|
|
|
304 |
String.join(" ", Arrays.asList(item.getBrand(), item.getModelName(), item.getModelNumber())
|
|
|
305 |
.stream().filter(s -> s != null && !s.isEmpty()).collect(Collectors.toList())));
|
| 31612 |
tejbeer |
306 |
catalogObj.put("brand", new String[] { item.getBrand() });
|
| 31604 |
tejbeer |
307 |
if (item.getBrand().equals("Huawei") || item.getBrand().equals("Honor")) {
|
|
|
308 |
catalogObj.put("brand", new String[] { "Huawei", "Honor" });
|
|
|
309 |
}
|
|
|
310 |
if (item.getBrand().equals("Mi") || item.getBrand().equals("Xiaomi")
|
|
|
311 |
|| item.getBrand().equals("Redmi")) {
|
|
|
312 |
catalogObj.put("brand", new String[] { "Mi", "Xiaomi", "Redmi" });
|
|
|
313 |
}
|
|
|
314 |
catalogObj.put("identifier", item.getCatalogItemId());
|
|
|
315 |
catalogObj.put("items", new HashMap<Integer, Map<String, Object>>());
|
|
|
316 |
Map<String, Object> filterMap = new HashMap<>();
|
|
|
317 |
filterMap.put("_id", item.getCatalogItemId());
|
|
|
318 |
// Don't include if catalog not available
|
|
|
319 |
try {
|
| 31620 |
tejbeer |
320 |
String imageUrl = contentMongoClient.getEntityById(item.getCatalogItemId()).getDefaultImageUrl();
|
| 31604 |
tejbeer |
321 |
|
| 31620 |
tejbeer |
322 |
if (imageUrl != null) {
|
|
|
323 |
catalogObj.put("imageUrl", imageUrl);
|
|
|
324 |
} else {
|
|
|
325 |
catalogObj.put("imageUrl",
|
|
|
326 |
"https://images.smartdukaan.com/uploads/campaigns/" + item.getCatalogItemId() + ".jpg");
|
|
|
327 |
}
|
| 31604 |
tejbeer |
328 |
} catch (Exception e) {
|
|
|
329 |
try {
|
|
|
330 |
catalogObj.put("imageUrl",
|
|
|
331 |
"https://images.smartdukaan.com/uploads/campaigns/" + item.getCatalogItemId() + ".jpg");
|
|
|
332 |
} catch (Exception e2) {
|
|
|
333 |
e2.printStackTrace();
|
|
|
334 |
}
|
|
|
335 |
}
|
|
|
336 |
try {
|
|
|
337 |
catalogObj.put("rank", rankingList.indexOf(item.getCatalogItemId()));
|
|
|
338 |
} catch (Exception e) {
|
|
|
339 |
// A very big number
|
|
|
340 |
e.printStackTrace();
|
|
|
341 |
catalogObj.put("rank", 50000000);
|
|
|
342 |
}
|
|
|
343 |
if (featureMap.containsKey(item.getCatalogItemId())
|
|
|
344 |
&& featureMap.get(item.getCatalogItemId()) != null) {
|
|
|
345 |
catalogObj.put("feature", featureMap.get(item.getCatalogItemId()));
|
|
|
346 |
|
|
|
347 |
}
|
|
|
348 |
|
| 31634 |
tejbeer |
349 |
catalogObj.put("categoryId", CATEGORY_MASTER.contains(item.getCategoryId()) ? item.getCategoryId() : 6);
|
| 31624 |
tejbeer |
350 |
|
| 31604 |
tejbeer |
351 |
if (item.getCategoryId() == 10006) {
|
|
|
352 |
catalogObj.put("categoryId", 3);
|
|
|
353 |
}
|
|
|
354 |
catalogObj.put("subCategoryId", item.getCategoryId());
|
| 31612 |
tejbeer |
355 |
catalogObj.put("create_timestamp",
|
|
|
356 |
tag.getCreatedTimestamp().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli());
|
|
|
357 |
|
|
|
358 |
if (catalogLabelMap.containsKey(item.getCatalogItemId())
|
|
|
359 |
&& catalogLabelMap.get(item.getCatalogItemId()) != null) {
|
|
|
360 |
catalogObj.put("labels", catalogLabelMap.get(item.getCatalogItemId()));
|
|
|
361 |
|
|
|
362 |
}
|
| 31604 |
tejbeer |
363 |
catalogMap.put(item.getCatalogItemId(), catalogObj);
|
|
|
364 |
catalogObj.put("avColor", new HashMap<>());
|
| 31612 |
tejbeer |
365 |
|
| 31604 |
tejbeer |
366 |
}
|
|
|
367 |
|
|
|
368 |
Map<String, Object> catalogObj = catalogMap.get(item.getCatalogItemId());
|
|
|
369 |
Map<Integer, Integer> avColorMap = (Map<Integer, Integer>) catalogObj.get("avColor");
|
|
|
370 |
|
|
|
371 |
if (availabilityItemMap.containsKey(String.valueOf(item.getId()))) {
|
|
|
372 |
for (Map.Entry<String, Map<String, Integer>> entry : availabilityItemMap
|
|
|
373 |
.get(String.valueOf(item.getId())).entrySet()) {
|
|
|
374 |
String warehouseId = entry.getKey();
|
|
|
375 |
Map<String, Integer> avMap = entry.getValue();
|
|
|
376 |
if (!avColorMap.containsKey(Integer.parseInt(warehouseId))) {
|
|
|
377 |
avColorMap.put(Integer.parseInt(warehouseId), 0);
|
|
|
378 |
}
|
|
|
379 |
int color = avColorMap.get(Integer.parseInt(warehouseId));
|
|
|
380 |
|
|
|
381 |
if (avMap.get("netAvailability") > 0) {
|
|
|
382 |
color = 2;
|
|
|
383 |
} else if (avMap.get("netAvailability") + avMap.get("netPo") > 0) {
|
|
|
384 |
color = Math.max(color, 1);
|
|
|
385 |
} else {
|
|
|
386 |
color = Math.max(color, 0);
|
|
|
387 |
}
|
|
|
388 |
avColorMap.put(Integer.parseInt(warehouseId), color);
|
|
|
389 |
|
|
|
390 |
catalogObj.put("avColor", avColorMap);
|
|
|
391 |
|
|
|
392 |
}
|
|
|
393 |
|
|
|
394 |
}
|
|
|
395 |
|
|
|
396 |
Map<Integer, Object> itemColorMap = (Map<Integer, Object>) catalogObj.get("items");
|
|
|
397 |
|
|
|
398 |
if (!itemColorMap.containsKey(item.getId())) {
|
|
|
399 |
itemColorMap.put(item.getId(), new HashMap<String, Object>() {
|
|
|
400 |
{
|
|
|
401 |
put("color", item.getColor().replace("f_", ""));
|
|
|
402 |
put("tagPricing", new ArrayList<TagListing>());
|
|
|
403 |
}
|
|
|
404 |
});
|
|
|
405 |
}
|
|
|
406 |
Map<String, Object> itemMap = (Map<String, Object>) itemColorMap.get(item.getId());
|
|
|
407 |
List<TagListing> tagPricing = (List<TagListing>) itemMap.get("tagPricing");
|
|
|
408 |
tagPricing.add(tag);
|
|
|
409 |
}
|
|
|
410 |
|
|
|
411 |
logger.info("catalogObj {}", catalogMap);
|
|
|
412 |
List<SolrInputDocument> catalogSolrObjs = new ArrayList<>();
|
|
|
413 |
for (Entry<Integer, Map<String, Object>> entry : catalogMap.entrySet()) {
|
|
|
414 |
int catalogId = entry.getKey();
|
|
|
415 |
Map<String, Object> catalogValMap = entry.getValue();
|
|
|
416 |
Map<Integer, Object> itemsMap = (Map<Integer, Object>) catalogValMap.get("items");
|
|
|
417 |
|
|
|
418 |
boolean active = false;
|
|
|
419 |
// Map<Integer, Object> itemsMap = (Map<String, Object>)
|
|
|
420 |
// catalogValMap.get("items");
|
|
|
421 |
List<SolrInputDocument> itemObjs = new ArrayList<>();
|
|
|
422 |
float mop = 0;
|
|
|
423 |
|
|
|
424 |
for (Entry<Integer, Object> itemEntry : itemsMap.entrySet()) {
|
|
|
425 |
int itemId = itemEntry.getKey();
|
|
|
426 |
Map<String, Object> itemMap = (Map<String, Object>) itemEntry.getValue();
|
|
|
427 |
List<TagListing> tags = (List<TagListing>) itemMap.get("tagPricing");
|
|
|
428 |
SolrInputDocument itemObj = new SolrInputDocument();
|
|
|
429 |
|
|
|
430 |
for (TagListing taglist : tags) {
|
|
|
431 |
active = active || (Boolean) taglist.isActive();
|
|
|
432 |
itemObj.setField("id", "itemtag-" + itemId + "-" + taglist.getTagId());
|
|
|
433 |
itemObj.setField("color_s", itemMap.get("color"));
|
|
|
434 |
itemObj.setField("itemId_i", itemId);
|
|
|
435 |
itemObj.setField("tagId_i", taglist.getTagId());
|
|
|
436 |
itemObj.setField("mrp_f", taglist.getMrp());
|
|
|
437 |
itemObj.setField("mop_f", taglist.getMop());
|
|
|
438 |
itemObj.setField("sellingPrice_f", taglist.getSellingPrice());
|
|
|
439 |
itemObj.setField("active_b", taglist.isActive());
|
|
|
440 |
itemObj.setField("hot_deal_b", taglist.isHotDeals());
|
|
|
441 |
mop = taglist.getMop();
|
|
|
442 |
|
|
|
443 |
}
|
|
|
444 |
|
|
|
445 |
itemObjs.add(itemObj);
|
|
|
446 |
}
|
|
|
447 |
|
|
|
448 |
logger.info("catalogValMap {}", catalogValMap);
|
|
|
449 |
|
|
|
450 |
logger.info("rank {}", catalogValMap.get("rank"));
|
|
|
451 |
|
|
|
452 |
SolrInputDocument catalogSolrObj = new SolrInputDocument();
|
|
|
453 |
|
|
|
454 |
catalogSolrObj.setField("id", "catalog" + catalogId);
|
|
|
455 |
catalogSolrObj.setField("rank_i", catalogValMap.get("rank"));
|
|
|
456 |
catalogSolrObj.setField("title_s", catalogValMap.get("title"));
|
| 31612 |
tejbeer |
457 |
// catalogSolrObj.setField("_childDocuments_", itemObjs);
|
| 31604 |
tejbeer |
458 |
catalogSolrObj.addChildDocuments(itemObjs);
|
| 31616 |
tejbeer |
459 |
catalogSolrObj.setField("child_b", itemObjs.size() > 0);
|
| 31604 |
tejbeer |
460 |
catalogSolrObj.setField("catalogId_i", catalogId);
|
|
|
461 |
catalogSolrObj.setField("imageUrl_s",
|
|
|
462 |
catalogValMap.get("imageUrl").toString().replace("saholic", "smartdukaan"));
|
|
|
463 |
catalogSolrObj.setField("feature_s", catalogValMap.get("feature"));
|
|
|
464 |
catalogSolrObj.setField("brand_ss", catalogValMap.get("brand"));
|
|
|
465 |
catalogSolrObj.setField("create_s", catalogValMap.get("create_timestamp"));
|
|
|
466 |
catalogSolrObj.setField("categoryId_i", catalogValMap.get("categoryId"));
|
|
|
467 |
catalogSolrObj.setField("subCategoryId_i", catalogValMap.get("subCategoryId"));
|
| 31612 |
tejbeer |
468 |
catalogSolrObj.setField("label_ss", catalogValMap.get("labels"));
|
| 31604 |
tejbeer |
469 |
catalogSolrObj.setField("w7573_i", 0);
|
|
|
470 |
catalogSolrObj.setField("w7678_i", 0);
|
|
|
471 |
catalogSolrObj.setField("w7720_i", 0);
|
|
|
472 |
catalogSolrObj.setField("w8468_i", 0);
|
|
|
473 |
catalogSolrObj.setField("w8889_i", 0);
|
|
|
474 |
catalogSolrObj.setField("w8947_i", 0);
|
|
|
475 |
catalogSolrObj.setField("w9213_i", 0);
|
|
|
476 |
catalogSolrObj.setField("w9203_i", 0);
|
|
|
477 |
catalogSolrObj.setField("mop_f", mop);
|
| 31641 |
tejbeer |
478 |
catalogSolrObj.setField("hsncode_s", catalogValMap.get("hsnCode"));
|
| 31660 |
tejbeer |
479 |
catalogSolrObj.setField("show_default_b", true);
|
| 31612 |
tejbeer |
480 |
|
|
|
481 |
String[] brands = (String[]) catalogValMap.get("brand");
|
|
|
482 |
for (String brand : brands) {
|
| 31660 |
tejbeer |
483 |
if (brand.equals("FOC")) {
|
|
|
484 |
catalogSolrObj.setField("show_default_b", false);
|
| 31612 |
tejbeer |
485 |
|
|
|
486 |
}
|
| 31710 |
tejbeer |
487 |
|
|
|
488 |
if (brand.equals("Live Demo")) {
|
|
|
489 |
catalogSolrObj.setField("show_default_b", false);
|
|
|
490 |
|
|
|
491 |
}
|
| 31612 |
tejbeer |
492 |
}
|
| 31604 |
tejbeer |
493 |
Map<Integer, Integer> avColorMap = (Map<Integer, Integer>) catalogValMap.get("avColor");
|
|
|
494 |
|
|
|
495 |
for (Entry<Integer, Integer> avColorEntry : avColorMap.entrySet()) {
|
|
|
496 |
int whId = avColorEntry.getKey();
|
|
|
497 |
int color = (int) avColorEntry.getValue();
|
|
|
498 |
catalogSolrObj.setField("w" + whId + "_i", color);
|
|
|
499 |
}
|
|
|
500 |
catalogSolrObj.setField("active_b", active);
|
|
|
501 |
logger.info("catalogSolrObj {}", catalogSolrObj.get("rank_i"));
|
|
|
502 |
|
|
|
503 |
catalogSolrObjs.add(catalogSolrObj);
|
|
|
504 |
|
|
|
505 |
}
|
|
|
506 |
|
|
|
507 |
logger.info("catalogSolrObjs {}", catalogSolrObjs);
|
|
|
508 |
solr.deleteByQuery("*:*");
|
|
|
509 |
solr.add(catalogSolrObjs);
|
|
|
510 |
|
| 31612 |
tejbeer |
511 |
org.apache.solr.client.solrj.response.UpdateResponse updateResponse = solr.commit();
|
| 31604 |
tejbeer |
512 |
logger.info("solr {}", updateResponse.getStatus());
|
|
|
513 |
|
|
|
514 |
}
|
|
|
515 |
|
|
|
516 |
/*
|
|
|
517 |
* public void populateTagItems() throws Exception { Map<String, Map<String,
|
|
|
518 |
* Map<String, Integer>>> availabilityItemMap = getItemMap(); List<TagRanking>
|
|
|
519 |
* tagRankingList = tagRankingRepository.getAllTagRanking();
|
|
|
520 |
*
|
|
|
521 |
* List<Integer> rankingList = new ArrayList<>(); SolrInputDocument featureMap =
|
|
|
522 |
* new SolrInputDocument(); for (TagRanking tagRanking : tagRankingList) {
|
|
|
523 |
* rankingList.add(tagRanking.getCatalogItemId());
|
|
|
524 |
* featureMap.addField(String.valueOf(tagRanking.getCatalogItemId()),
|
|
|
525 |
* tagRanking.getFeature()); }
|
|
|
526 |
*
|
|
|
527 |
* Map<Integer, SolrInputDocument> catalogMap = new HashMap<>(); List<status>
|
|
|
528 |
* statuses = new ArrayList<>(); statuses.add(status.ACTIVE);
|
|
|
529 |
* statuses.add(status.PAUSED_BY_RISK); statuses.add(status.PARTIALLY_ACTIVE);
|
|
|
530 |
* List<ItemTagModel> tuples =
|
|
|
531 |
* tagListingRepository.getAllItemTagByStatus(statuses); SolrInputDocument
|
|
|
532 |
* projection = new SolrInputDocument();
|
|
|
533 |
*
|
|
|
534 |
* projection.addField("defaultImageUrl", 1); List<String> excludeBrands =
|
|
|
535 |
* Arrays.asList("Live Demo", "FOC", "Dummy", "FOC HANDSET");
|
|
|
536 |
*
|
|
|
537 |
* for (ItemTagModel result : tuples) { TagListing tag = result.getTagListing();
|
|
|
538 |
* com.spice.profitmandi.dao.entity.catalog.Item item = result.getItem(); if
|
|
|
539 |
* (excludeBrands.contains(item.getBrand())) { continue; }
|
|
|
540 |
*
|
|
|
541 |
* if (!catalogMap.containsKey(item.getCatalogItemId())) { SolrInputDocument
|
|
|
542 |
* catalogObj = new SolrInputDocument(); catalogObj.addField("feature", "");
|
|
|
543 |
* catalogObj.addField("title", String.join(" ", Arrays.asList(item.getBrand(),
|
|
|
544 |
* item.getModelName(), item.getModelNumber()) .stream().filter(s -> s != null
|
|
|
545 |
* && !s.isEmpty()).collect(Collectors.toList()))); catalogObj.addField("brand",
|
|
|
546 |
* item.getBrand()); if (item.getBrand().equals("Huawei") ||
|
|
|
547 |
* item.getBrand().equals("Honor")) { catalogObj.addField("brand", new String[]
|
|
|
548 |
* { "Huawei", "Honor" }); } if (item.getBrand().equals("Mi") ||
|
|
|
549 |
* item.getBrand().equals("Xiaomi") || item.getBrand().equals("Redmi")) {
|
|
|
550 |
* catalogObj.addField("brand", new String[] { "Mi", "Xiaomi", "Redmi" }); }
|
|
|
551 |
* catalogObj.addField("identifier", item.getCatalogItemId());
|
|
|
552 |
* catalogObj.addField("items", new SolrInputDocument()); SolrInputDocument
|
|
|
553 |
* filterMap = new SolrInputDocument(); filterMap.addField("_id",
|
|
|
554 |
* item.getCatalogItemId());
|
|
|
555 |
*
|
|
|
556 |
* try {
|
|
|
557 |
*
|
|
|
558 |
* BrandCatalog brandCatalog = brandsRepository.selectByBrand(item.getBrand());
|
|
|
559 |
* catalogObj.addField("imageUrl", brandCatalog.getLogoUrl());
|
|
|
560 |
* System.out.println(catalogObj.get("imageUrl")); } catch (Exception e) { try {
|
|
|
561 |
* catalogObj.addField("imageUrl",
|
|
|
562 |
* "https://images.smartdukaan.com/uploads/campaigns/" + item.getCatalogItemId()
|
|
|
563 |
* + ".jpg"); } catch (Exception e2) { e2.printStackTrace(); } } try {
|
|
|
564 |
* catalogObj.addField("rank", rankingList.indexOf(item.getCatalogItemId())); }
|
|
|
565 |
* catch (Exception e) { // A very big number e.printStackTrace();
|
|
|
566 |
* catalogObj.addField("rank", 50000000); } if
|
|
|
567 |
* (featureMap.containsKey(String.valueOf(item.getCatalogItemId())) &&
|
|
|
568 |
* featureMap.get(String.valueOf(item.getCatalogItemId())) != null) {
|
|
|
569 |
* catalogObj.addField("feature", featureMap.get(item.getCatalogItemId()));
|
|
|
570 |
*
|
|
|
571 |
* catalogObj.addField("categoryId",
|
|
|
572 |
* CATEGORY_MASTER.contains(item.getCategoryId()) ? item.getCategoryId() : 6);
|
|
|
573 |
*
|
|
|
574 |
* }
|
|
|
575 |
*
|
|
|
576 |
* if (item.getCategoryId() == 10006) { catalogObj.addField("categoryId", 3); }
|
|
|
577 |
* catalogObj.addField("subCategoryId", item.getCategoryId());
|
|
|
578 |
* catalogObj.addField("create_timestamp", tag.getCreatedTimestamp());
|
|
|
579 |
* catalogMap.put(item.getCatalogItemId(), catalogObj);
|
|
|
580 |
* catalogObj.addField("avColor", new SolrInputDocument());
|
|
|
581 |
*
|
|
|
582 |
* // Don't include if catalog not available
|
|
|
583 |
*
|
|
|
584 |
* catalogObj = catalogMap.get(item.getCatalogItemId()); if
|
|
|
585 |
* (availabilityItemMap.containsKey(String.valueOf(item.getId()))) { for
|
|
|
586 |
* (Map.Entry<String, Map<String, Integer>> entry : availabilityItemMap
|
|
|
587 |
* .get(String.valueOf(item.getId())).entrySet()) { String warehouseId =
|
|
|
588 |
* entry.getKey(); Map<String, Integer> avMap = entry.getValue();
|
|
|
589 |
*
|
|
|
590 |
* SolrInputDocument avColorDoc = (SolrInputDocument)
|
|
|
591 |
* catalogObj.getFieldValue("avColor"); //.catalogObj.get if
|
|
|
592 |
* (!avColorDoc.containsKey(warehouseId)) { avColorDoc.addField(warehouseId, 0);
|
|
|
593 |
* } int color = (int) avColorDoc.getFieldValue(warehouseId);
|
|
|
594 |
*
|
|
|
595 |
* if (avMap.get("netAvailability") > 0) { color = 2; } else if
|
|
|
596 |
* (avMap.get("netAvailability") + avMap.get("netPo") > 0) { color =
|
|
|
597 |
* Math.max(color, 1); } else { color = Math.max(color, 0); }
|
|
|
598 |
*
|
|
|
599 |
* avColorDoc.addField(warehouseId, 0);
|
|
|
600 |
*
|
|
|
601 |
* }
|
|
|
602 |
*
|
|
|
603 |
* }
|
|
|
604 |
*
|
|
|
605 |
* SolrInputDocument itemColorDoc = (SolrInputDocument)
|
|
|
606 |
* catalogObj.getFieldValue("items");
|
|
|
607 |
*
|
|
|
608 |
* if (!itemColorDoc.containsKey(item.getId())) {
|
|
|
609 |
*
|
|
|
610 |
* itemColorDoc.addField(String.valueOf(item.getId()), new SolrInputDocument() {
|
|
|
611 |
* { addField("color", item.getColor().replace("f_", ""));
|
|
|
612 |
* addField("tagPricing", new ArrayList<TagListing>()); } }); }
|
|
|
613 |
*
|
|
|
614 |
* SolrInputDocument itemMap = (SolrInputDocument) itemColorDoc
|
|
|
615 |
* .getFieldValue(String.valueOf(item.getId()));
|
|
|
616 |
*
|
|
|
617 |
* List<TagListing> tagPricing = (List<TagListing>)
|
|
|
618 |
* itemMap.getFieldValue("tagPricing"); tagPricing.add(tag);
|
|
|
619 |
*
|
|
|
620 |
* List<Map<String, Object>> catalogObjs = new ArrayList<>(); for
|
|
|
621 |
* (Entry<Integer, HashMap<String, Object>> entry : catalogMap.entrySet()) { int
|
|
|
622 |
* catalogId = entry.getKey(); Map<String, Object> catalogValMap =
|
|
|
623 |
* entry.getValue();
|
|
|
624 |
*
|
|
|
625 |
* boolean active = false; Map<String, Object> itemsMap = (Map<String, Object>)
|
|
|
626 |
* catalogValMap.get("items"); List<Map<String, Object>> itemObjs = new
|
|
|
627 |
* ArrayList<>(); float mop = 0;
|
|
|
628 |
*
|
|
|
629 |
* for (Entry<String, Object> itemEntry : itemsMap.entrySet()) { int itemId =
|
|
|
630 |
* Integer.parseInt(itemEntry.getKey()); Map<String, Object> itemValMap =
|
|
|
631 |
* (Map<String, Object>) itemEntry.getValue(); List<TagListing> tags =
|
|
|
632 |
* (List<TagListing>) catalogValMap.get("tagPricing");
|
|
|
633 |
*
|
|
|
634 |
* for (TagListing taglist : tags) { active = active || (Boolean)
|
|
|
635 |
* taglist.isActive(); Map<String, Object> itemObj = new HashMap<>();
|
|
|
636 |
* itemObj.put("id", "itemtag-" + itemId + "-" + tag.getTagId());
|
|
|
637 |
* itemObj.put("color_s", itemMap.get("color")); itemObj.put("itemId_i",
|
|
|
638 |
* itemId); itemObj.put("tagId_i", tag.getTagId()); itemObj.put("mrp_f",
|
|
|
639 |
* tag.getMrp()); itemObj.put("mop_f", tag.getMop());
|
|
|
640 |
* itemObj.put("sellingPrice_f", tag.getSellingPrice()); itemObj.put("active_b",
|
|
|
641 |
* tag.isActive()); itemObj.put("hot_deal_b", tag.isHotDeals()); mop =
|
|
|
642 |
* tag.getMop(); itemObjs.add(itemObj); } } // Map<String, Object> catalogObj =
|
|
|
643 |
* new HashMap<String, Object>(); catalogObj.put("id", "catalog" + catalogId);
|
|
|
644 |
* catalogObj.put("rank_i", catalogMap.get("rank")); catalogObj.put("title_s",
|
|
|
645 |
* catalogMap.get("title")); catalogObj.put("_childDocuments_", itemObjs);
|
|
|
646 |
* catalogObj.put("child_b", itemObjs.size() > 0); catalogObj.put("catalogId_i",
|
|
|
647 |
* catalogId); catalogObj.put("imageUrl_s",
|
|
|
648 |
* catalogMap.get("imageUrl").toString().replace("saholic", "smartdukaan"));
|
|
|
649 |
* catalogObj.put("feature_s", catalogMap.get("feature"));
|
|
|
650 |
* catalogObj.put("brand_ss", catalogMap.get("brand"));
|
|
|
651 |
* catalogObj.put("create_s", catalogMap.get("create_timestamp"));
|
|
|
652 |
* catalogObj.put("categoryId_i", catalogMap.get("categoryId"));
|
|
|
653 |
* catalogObj.put("subCategoryId_i", catalogMap.get("subCategoryId"));
|
|
|
654 |
* catalogObj.put("w7573_i", 0); catalogObj.put("w7678_i", 0);
|
|
|
655 |
* catalogObj.put("w7720_i", 0); catalogObj.put("w8468_i", 0);
|
|
|
656 |
* catalogObj.put("w8889_i", 0); catalogObj.put("w8947_i", 0);
|
|
|
657 |
* catalogObj.put("w9213_i", 0); catalogObj.put("w9203_i", 0);
|
|
|
658 |
* catalogObj.put("mop_f", mop); for (Entry<Integer, Integer> avColorEntry :
|
|
|
659 |
* avColorMap.entrySet()) { int whId = avColorEntry.getKey(); int color = (int)
|
|
|
660 |
* avColorEntry.getValue(); catalogObj.put("w" + whId + "_i", color);
|
|
|
661 |
*
|
|
|
662 |
* catalogObj.put("active_b", active); catalogObjs.add(catalogObj);
|
|
|
663 |
* solr.deleteByQuery("*:*"); // solr.add((catalogObjs); }
|
|
|
664 |
*
|
|
|
665 |
* } } }
|
|
|
666 |
*
|
|
|
667 |
* }
|
|
|
668 |
*/
|
|
|
669 |
|
|
|
670 |
public void pushData() throws Exception {
|
|
|
671 |
this.populateTagItems();
|
|
|
672 |
}
|
|
|
673 |
}
|