| 31604 |
tejbeer |
1 |
package com.spice.profitmandi.dao.service.solr;
|
|
|
2 |
|
| 33245 |
ranu |
3 |
import com.google.gson.Gson;
|
|
|
4 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 33562 |
amit.gupta |
5 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 33245 |
ranu |
6 |
import com.spice.profitmandi.dao.entity.catalog.TagListing;
|
|
|
7 |
import com.spice.profitmandi.dao.entity.catalog.TagRanking;
|
|
|
8 |
import com.spice.profitmandi.dao.entity.dtr.WebProductListing;
|
| 33542 |
amit.gupta |
9 |
import com.spice.profitmandi.dao.entity.similarModel.SimilarModel;
|
| 33245 |
ranu |
10 |
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
|
|
|
11 |
import com.spice.profitmandi.dao.repository.catalog.TagRankingRepository;
|
|
|
12 |
import com.spice.profitmandi.dao.repository.dtr.Mongo;
|
|
|
13 |
import com.spice.profitmandi.dao.repository.dtr.WebListingRepository;
|
|
|
14 |
import com.spice.profitmandi.dao.repository.dtr.WebProductListingRepository;
|
| 33542 |
amit.gupta |
15 |
import com.spice.profitmandi.dao.repository.similarModel.SimilarModelRepository;
|
| 33245 |
ranu |
16 |
import com.spice.profitmandi.service.tag.ItemTagModel;
|
|
|
17 |
import in.shop2020.model.v1.catalog.status;
|
| 31604 |
tejbeer |
18 |
import org.apache.logging.log4j.LogManager;
|
|
|
19 |
import org.apache.logging.log4j.Logger;
|
|
|
20 |
import org.apache.solr.client.solrj.SolrClient;
|
|
|
21 |
import org.apache.solr.client.solrj.impl.HttpSolrClient;
|
|
|
22 |
import org.apache.solr.common.SolrInputDocument;
|
| 33570 |
amit.gupta |
23 |
import org.apache.solr.common.SolrInputField;
|
| 31604 |
tejbeer |
24 |
import org.json.JSONArray;
|
|
|
25 |
import org.json.JSONException;
|
|
|
26 |
import org.json.JSONObject;
|
|
|
27 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 31613 |
tejbeer |
28 |
import org.springframework.beans.factory.annotation.Value;
|
| 31604 |
tejbeer |
29 |
import org.springframework.stereotype.Component;
|
|
|
30 |
|
| 33245 |
ranu |
31 |
import java.io.BufferedReader;
|
|
|
32 |
import java.io.IOException;
|
|
|
33 |
import java.io.InputStream;
|
|
|
34 |
import java.io.InputStreamReader;
|
|
|
35 |
import java.net.HttpURLConnection;
|
|
|
36 |
import java.net.URL;
|
|
|
37 |
import java.net.URLConnection;
|
|
|
38 |
import java.time.ZoneId;
|
|
|
39 |
import java.util.*;
|
|
|
40 |
import java.util.Map.Entry;
|
|
|
41 |
import java.util.stream.Collectors;
|
|
|
42 |
import java.util.zip.GZIPInputStream;
|
| 31604 |
tejbeer |
43 |
|
|
|
44 |
@Component
|
|
|
45 |
public class FofoSolr {
|
|
|
46 |
|
| 33542 |
amit.gupta |
47 |
@Autowired
|
|
|
48 |
private Gson gson;
|
| 31604 |
tejbeer |
49 |
|
| 33542 |
amit.gupta |
50 |
@Autowired
|
|
|
51 |
private TagListingRepository tagListingRepository;
|
| 31604 |
tejbeer |
52 |
|
| 33542 |
amit.gupta |
53 |
@Autowired
|
|
|
54 |
TagRankingRepository tagRankingRepository;
|
| 31604 |
tejbeer |
55 |
|
| 33542 |
amit.gupta |
56 |
@Autowired
|
|
|
57 |
private Mongo contentMongoClient;
|
| 31604 |
tejbeer |
58 |
|
| 33542 |
amit.gupta |
59 |
@Autowired
|
|
|
60 |
private WebListingRepository webListingRepository;
|
| 31612 |
tejbeer |
61 |
|
| 33542 |
amit.gupta |
62 |
@Autowired
|
|
|
63 |
private WebProductListingRepository webProductListingRepository;
|
| 31612 |
tejbeer |
64 |
|
| 33542 |
amit.gupta |
65 |
@Value("${new.solr.url}")
|
|
|
66 |
private String solrUrl;
|
| 31613 |
tejbeer |
67 |
|
| 33542 |
amit.gupta |
68 |
@Value("${reportico.url}")
|
|
|
69 |
private String reporticoUrl;
|
| 33486 |
amit.gupta |
70 |
|
| 33542 |
amit.gupta |
71 |
private static final Logger logger = LogManager.getLogger(FofoSolr.class);
|
| 31604 |
tejbeer |
72 |
|
| 33542 |
amit.gupta |
73 |
private static final List<Integer> CATEGORY_MASTER = Arrays.asList(10006, 10010, 14202, 14203);
|
| 31604 |
tejbeer |
74 |
|
| 33542 |
amit.gupta |
75 |
private static String getUrlContent(String urlString) {
|
|
|
76 |
BufferedReader reader = null;
|
|
|
77 |
try {
|
|
|
78 |
URL url = new URL(urlString);
|
|
|
79 |
URLConnection conn = url.openConnection();
|
|
|
80 |
conn.setConnectTimeout(5000);
|
|
|
81 |
conn.setReadTimeout(5000);
|
|
|
82 |
reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
|
|
83 |
return reader.lines().collect(Collectors.joining(System.lineSeparator()));
|
|
|
84 |
} catch (IOException e) {
|
|
|
85 |
e.printStackTrace();
|
|
|
86 |
} finally {
|
|
|
87 |
if (reader != null) {
|
|
|
88 |
try {
|
|
|
89 |
reader.close();
|
|
|
90 |
} catch (IOException e) {
|
|
|
91 |
e.printStackTrace();
|
|
|
92 |
}
|
|
|
93 |
}
|
|
|
94 |
}
|
|
|
95 |
return null;
|
|
|
96 |
}
|
| 31604 |
tejbeer |
97 |
|
| 33542 |
amit.gupta |
98 |
public JSONArray getAvailability() throws IOException, JSONException {
|
|
|
99 |
String url = reporticoUrl + "?execute_mode=EXECUTE&xmlin=warehousecisnew.xml&project=FOCOR&project_password=focor&target_format=JSON";
|
|
|
100 |
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
|
|
|
101 |
connection.setRequestProperty("Accept-Encoding", "gzip");
|
|
|
102 |
BufferedReader reader = null;
|
| 31604 |
tejbeer |
103 |
|
| 33542 |
amit.gupta |
104 |
try {
|
|
|
105 |
InputStream inputStream = connection.getInputStream();
|
| 31604 |
tejbeer |
106 |
|
| 33542 |
amit.gupta |
107 |
if ("gzip".equals(connection.getContentEncoding())) {
|
|
|
108 |
inputStream = new GZIPInputStream(inputStream);
|
|
|
109 |
}
|
| 31604 |
tejbeer |
110 |
|
| 33542 |
amit.gupta |
111 |
reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
|
|
|
112 |
StringBuilder responseBuilder = new StringBuilder();
|
|
|
113 |
String line;
|
| 31604 |
tejbeer |
114 |
|
| 33542 |
amit.gupta |
115 |
while ((line = reader.readLine()) != null) {
|
|
|
116 |
responseBuilder.append(line);
|
|
|
117 |
}
|
| 31604 |
tejbeer |
118 |
|
| 33542 |
amit.gupta |
119 |
JSONObject responseJson = new JSONObject(responseBuilder.toString());
|
|
|
120 |
return responseJson.getJSONArray("data");
|
|
|
121 |
} finally {
|
|
|
122 |
if (reader != null) {
|
|
|
123 |
try {
|
|
|
124 |
reader.close();
|
|
|
125 |
} catch (IOException e) {
|
|
|
126 |
// Ignore
|
|
|
127 |
}
|
|
|
128 |
}
|
|
|
129 |
}
|
|
|
130 |
}
|
| 31604 |
tejbeer |
131 |
|
| 33542 |
amit.gupta |
132 |
public JSONArray getPendingPO() throws IOException, JSONException {
|
|
|
133 |
String url = reporticoUrl + "?execute_mode=EXECUTE&xmlin=UnfulfilledPOItemsNew.xml&project=FOCOR&project_password=focor&target_format=JSON";
|
|
|
134 |
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
|
|
|
135 |
connection.setRequestProperty("Accept-Encoding", "gzip");
|
|
|
136 |
BufferedReader reader = null;
|
| 31604 |
tejbeer |
137 |
|
| 33542 |
amit.gupta |
138 |
try {
|
|
|
139 |
InputStream inputStream = connection.getInputStream();
|
| 31604 |
tejbeer |
140 |
|
| 33542 |
amit.gupta |
141 |
if ("gzip".equals(connection.getContentEncoding())) {
|
|
|
142 |
inputStream = new GZIPInputStream(inputStream);
|
|
|
143 |
}
|
| 31604 |
tejbeer |
144 |
|
| 33542 |
amit.gupta |
145 |
reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
|
|
|
146 |
StringBuilder responseBuilder = new StringBuilder();
|
|
|
147 |
String line;
|
| 31604 |
tejbeer |
148 |
|
| 33542 |
amit.gupta |
149 |
while ((line = reader.readLine()) != null) {
|
|
|
150 |
responseBuilder.append(line);
|
|
|
151 |
}
|
| 31604 |
tejbeer |
152 |
|
| 33542 |
amit.gupta |
153 |
JSONObject responseJson = new JSONObject(responseBuilder.toString());
|
|
|
154 |
return responseJson.getJSONArray("data");
|
|
|
155 |
} finally {
|
|
|
156 |
if (reader != null) {
|
|
|
157 |
try {
|
|
|
158 |
reader.close();
|
|
|
159 |
} catch (IOException e) {
|
|
|
160 |
// Ignore
|
|
|
161 |
}
|
|
|
162 |
}
|
|
|
163 |
}
|
|
|
164 |
}
|
| 31604 |
tejbeer |
165 |
|
| 33542 |
amit.gupta |
166 |
public Map<String, Map<String, Map<String, Integer>>> getItemMap() throws Exception {
|
|
|
167 |
JSONArray availabilityJSONArray = this.getAvailability();
|
|
|
168 |
JSONArray pendingPOJSONArray = this.getPendingPO();
|
|
|
169 |
Map<String, Map<String, Map<String, Integer>>> availabilityItemMap = new HashMap<>();
|
| 31604 |
tejbeer |
170 |
|
| 33542 |
amit.gupta |
171 |
for (int i = 0; i < availabilityJSONArray.length(); i++) {
|
|
|
172 |
JSONObject rawAvailability = availabilityJSONArray.getJSONObject(i);
|
|
|
173 |
if (!availabilityItemMap.containsKey(rawAvailability.getString("Itemid"))) {
|
|
|
174 |
availabilityItemMap.put(rawAvailability.getString("Itemid"),
|
|
|
175 |
new HashMap<String, Map<String, Integer>>());
|
|
|
176 |
}
|
|
|
177 |
if (!availabilityItemMap.get(rawAvailability.getString("Itemid"))
|
|
|
178 |
.containsKey(rawAvailability.getString("Warehouseid"))) {
|
|
|
179 |
availabilityItemMap.get(rawAvailability.getString("Itemid"))
|
|
|
180 |
.put(rawAvailability.getString("Warehouseid"), new HashMap<String, Integer>());
|
|
|
181 |
availabilityItemMap.get(rawAvailability.getString("Itemid"))
|
|
|
182 |
.get(rawAvailability.getString("Warehouseid")).put("netAvailability", 0);
|
|
|
183 |
availabilityItemMap.get(rawAvailability.getString("Itemid"))
|
|
|
184 |
.get(rawAvailability.getString("Warehouseid")).put("netPo", 0);
|
|
|
185 |
}
|
|
|
186 |
int netAvailability = availabilityItemMap.get(rawAvailability.getString("Itemid"))
|
|
|
187 |
.get(rawAvailability.getString("Warehouseid")).get("netAvailability")
|
|
|
188 |
+ rawAvailability.getInt("Netavailability");
|
|
|
189 |
availabilityItemMap.get(rawAvailability.getString("Itemid")).get(rawAvailability.getString("Warehouseid"))
|
|
|
190 |
.put("netAvailability", netAvailability);
|
|
|
191 |
}
|
| 31604 |
tejbeer |
192 |
|
| 33542 |
amit.gupta |
193 |
for (int i = 0; i < pendingPOJSONArray.length(); i++) {
|
|
|
194 |
JSONObject rawPendingPo = pendingPOJSONArray.getJSONObject(i);
|
| 31604 |
tejbeer |
195 |
|
| 33542 |
amit.gupta |
196 |
String itemId = rawPendingPo.getString("Itemid");
|
|
|
197 |
String warehouseId = rawPendingPo.getString("Warehouseid");
|
|
|
198 |
if (!availabilityItemMap.containsKey(itemId)) {
|
|
|
199 |
availabilityItemMap.put(itemId, new HashMap<String, Map<String, Integer>>());
|
|
|
200 |
}
|
|
|
201 |
if (!availabilityItemMap.get(itemId).containsKey(warehouseId)) {
|
|
|
202 |
availabilityItemMap.get(itemId).put(warehouseId, new HashMap<String, Integer>() {
|
|
|
203 |
{
|
|
|
204 |
put("netAvailability", 0);
|
|
|
205 |
put("netPo", 0);
|
|
|
206 |
}
|
|
|
207 |
});
|
|
|
208 |
}
|
|
|
209 |
availabilityItemMap.get(itemId).get(warehouseId).put("netPo",
|
|
|
210 |
availabilityItemMap.get(itemId).get(warehouseId).get("netPo") + rawPendingPo.getInt("Unfulfilled"));
|
| 31604 |
tejbeer |
211 |
|
| 33542 |
amit.gupta |
212 |
}
|
|
|
213 |
return availabilityItemMap;
|
| 31604 |
tejbeer |
214 |
|
| 33542 |
amit.gupta |
215 |
}
|
| 31604 |
tejbeer |
216 |
|
| 33245 |
ranu |
217 |
public Map<Integer, List<String>> getLabels() throws ProfitMandiBusinessException {
|
| 33542 |
amit.gupta |
218 |
List<String> labels = Arrays.asList("partner-best-sellers", "partner-price-drop", "new-launches",
|
|
|
219 |
"upgrade-offer", "special-support");
|
| 31612 |
tejbeer |
220 |
|
| 33542 |
amit.gupta |
221 |
Map<Integer, String> webListing = webListingRepository.selectByUrls(labels).stream()
|
|
|
222 |
.collect(Collectors.toMap(x -> x.getId(), x -> x.getUrl()));
|
| 31612 |
tejbeer |
223 |
|
| 33542 |
amit.gupta |
224 |
Map<Integer, List<WebProductListing>> webProductListingMap = webProductListingRepository
|
|
|
225 |
.selectAllByWebListingIds(new ArrayList<>(webListing.keySet())).stream()
|
|
|
226 |
.collect(Collectors.groupingBy(x -> x.getWebListingId()));
|
| 31612 |
tejbeer |
227 |
|
| 33542 |
amit.gupta |
228 |
Map<Integer, List<String>> catalogLabelMap = new HashMap<>();
|
|
|
229 |
for (Entry<Integer, List<WebProductListing>> webProductListingEntry : webProductListingMap.entrySet()) {
|
| 31612 |
tejbeer |
230 |
|
| 33542 |
amit.gupta |
231 |
for (WebProductListing webProduct : webProductListingEntry.getValue()) {
|
| 31612 |
tejbeer |
232 |
|
| 33542 |
amit.gupta |
233 |
if (!catalogLabelMap.containsKey(webProduct.getEntityId())) {
|
| 31612 |
tejbeer |
234 |
|
| 33542 |
amit.gupta |
235 |
catalogLabelMap.put(webProduct.getEntityId(), new ArrayList<>());
|
| 31612 |
tejbeer |
236 |
|
| 33542 |
amit.gupta |
237 |
}
|
| 31612 |
tejbeer |
238 |
|
| 33542 |
amit.gupta |
239 |
List<String> itemLabels = catalogLabelMap.get(webProduct.getEntityId());
|
|
|
240 |
itemLabels.add(webListing.get(webProduct.getWebListingId()));
|
|
|
241 |
catalogLabelMap.put(webProduct.getEntityId(), itemLabels);
|
| 31612 |
tejbeer |
242 |
|
| 33542 |
amit.gupta |
243 |
}
|
| 31612 |
tejbeer |
244 |
|
| 33542 |
amit.gupta |
245 |
}
|
| 31612 |
tejbeer |
246 |
|
| 33542 |
amit.gupta |
247 |
return catalogLabelMap;
|
|
|
248 |
}
|
| 31612 |
tejbeer |
249 |
|
| 33542 |
amit.gupta |
250 |
@Autowired
|
|
|
251 |
SimilarModelRepository similarModelRepository;
|
| 31604 |
tejbeer |
252 |
|
| 33542 |
amit.gupta |
253 |
public void populateTagItems() throws Exception {
|
|
|
254 |
Map<String, Map<String, Map<String, Integer>>> availabilityItemMap = getItemMap();
|
|
|
255 |
List<TagRanking> tagRankingList = tagRankingRepository.getAllTagRanking();
|
|
|
256 |
List<Integer> rankingList = new ArrayList<>();
|
|
|
257 |
Map<Integer, String> featureMap = new HashMap<>();
|
|
|
258 |
for (TagRanking tagRanking : tagRankingList) {
|
|
|
259 |
rankingList.add(tagRanking.getCatalogItemId());
|
|
|
260 |
featureMap.put(tagRanking.getCatalogItemId(), tagRanking.getFeature());
|
|
|
261 |
}
|
|
|
262 |
//Get Similar Models
|
| 33570 |
amit.gupta |
263 |
/*List<SimilarModel> similarModels = similarModelRepository.selectAll();
|
| 31612 |
tejbeer |
264 |
|
| 33570 |
amit.gupta |
265 |
Map<Integer, List<Integer>> similarModelsMap = similarModels.stream().collect(Collectors.groupingBy(SimilarModel::getCatalogId, Collectors.mapping(x -> x.getSimilarCatalogId(), Collectors.toList())));*/
|
| 31612 |
tejbeer |
266 |
|
| 33542 |
amit.gupta |
267 |
Map<Integer, Map<String, Object>> catalogMap = new HashMap<>();
|
| 31612 |
tejbeer |
268 |
|
| 33542 |
amit.gupta |
269 |
List<status> statuses = Arrays.asList(status.ACTIVE, status.PAUSED_BY_RISK, status.PARTIALLY_ACTIVE);
|
| 31612 |
tejbeer |
270 |
|
| 33542 |
amit.gupta |
271 |
Map<Integer, List<String>> catalogLabelMap = this.getLabels();
|
| 31604 |
tejbeer |
272 |
|
| 33542 |
amit.gupta |
273 |
logger.info("catalogLabelMap {}", catalogLabelMap);
|
| 31604 |
tejbeer |
274 |
|
| 33562 |
amit.gupta |
275 |
List<ItemTagModel> itemTagModels = tagListingRepository.getAllItemTagByStatus(statuses);
|
| 31604 |
tejbeer |
276 |
|
| 33542 |
amit.gupta |
277 |
Map<String, Object> projection = new HashMap<>();
|
|
|
278 |
projection.put("defaultImageUrl", 1);
|
| 31604 |
tejbeer |
279 |
|
| 33542 |
amit.gupta |
280 |
List<String> excludeBrands = Arrays.asList("Dummy", "FOC HANDSET");
|
| 31604 |
tejbeer |
281 |
|
| 33562 |
amit.gupta |
282 |
Map<Float, List<Integer>> priceModelMap = new TreeMap<>();
|
|
|
283 |
for (ItemTagModel itemTagModel : itemTagModels) {
|
|
|
284 |
TagListing tagListing = itemTagModel.getTagListing();
|
|
|
285 |
com.spice.profitmandi.dao.entity.catalog.Item item = itemTagModel.getItem();
|
| 33542 |
amit.gupta |
286 |
if (excludeBrands.contains(item.getBrand())) {
|
|
|
287 |
continue;
|
|
|
288 |
}
|
| 31604 |
tejbeer |
289 |
|
| 33542 |
amit.gupta |
290 |
if (!catalogMap.containsKey(item.getCatalogItemId())) {
|
| 33571 |
amit.gupta |
291 |
if (!priceModelMap.containsKey(tagListing.getMop()) && item.getCategoryId() == 10006) {
|
| 33572 |
amit.gupta |
292 |
priceModelMap.put(tagListing.getMop(), new ArrayList<>());
|
| 33562 |
amit.gupta |
293 |
}
|
| 33570 |
amit.gupta |
294 |
if (item.getCategoryId() == 10006) {
|
| 33571 |
amit.gupta |
295 |
List<Integer> priceModels = priceModelMap.get(tagListing.getMop());
|
| 33565 |
amit.gupta |
296 |
priceModels.add(item.getCatalogItemId());
|
|
|
297 |
}
|
| 33562 |
amit.gupta |
298 |
|
| 33542 |
amit.gupta |
299 |
Map<String, Object> catalogObj = new HashMap<>();
|
| 33570 |
amit.gupta |
300 |
catalogObj.put("stockColor", 0);
|
| 33542 |
amit.gupta |
301 |
catalogObj.put("feature", "");
|
|
|
302 |
catalogObj.put("hsnCode", item.getHsnCode());
|
|
|
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())));
|
|
|
306 |
catalogObj.put("brand", new String[]{item.getBrand()});
|
|
|
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 {
|
|
|
320 |
String imageUrl = contentMongoClient.getEntityById(item.getCatalogItemId()).getDefaultImageUrl();
|
| 31624 |
tejbeer |
321 |
|
| 33542 |
amit.gupta |
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 |
}
|
|
|
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()));
|
| 31612 |
tejbeer |
346 |
|
| 33542 |
amit.gupta |
347 |
}
|
| 31612 |
tejbeer |
348 |
|
| 33542 |
amit.gupta |
349 |
catalogObj.put("categoryId", CATEGORY_MASTER.contains(item.getCategoryId()) ? item.getCategoryId() : 6);
|
| 31612 |
tejbeer |
350 |
|
| 33542 |
amit.gupta |
351 |
if (item.getCategoryId() == 10006) {
|
|
|
352 |
catalogObj.put("categoryId", 3);
|
|
|
353 |
}
|
|
|
354 |
catalogObj.put("subCategoryId", item.getCategoryId());
|
|
|
355 |
catalogObj.put("create_timestamp",
|
| 33562 |
amit.gupta |
356 |
tagListing.getCreatedTimestamp().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli());
|
| 31604 |
tejbeer |
357 |
|
| 33542 |
amit.gupta |
358 |
if (catalogLabelMap.containsKey(item.getCatalogItemId())
|
|
|
359 |
&& catalogLabelMap.get(item.getCatalogItemId()) != null) {
|
|
|
360 |
catalogObj.put("labels", catalogLabelMap.get(item.getCatalogItemId()));
|
| 31604 |
tejbeer |
361 |
|
| 33542 |
amit.gupta |
362 |
}
|
|
|
363 |
catalogMap.put(item.getCatalogItemId(), catalogObj);
|
|
|
364 |
catalogObj.put("avColor", new HashMap<>());
|
| 31604 |
tejbeer |
365 |
|
| 33542 |
amit.gupta |
366 |
}
|
| 31604 |
tejbeer |
367 |
|
| 33542 |
amit.gupta |
368 |
Map<String, Object> catalogObj = catalogMap.get(item.getCatalogItemId());
|
|
|
369 |
Map<Integer, Integer> avColorMap = (Map<Integer, Integer>) catalogObj.get("avColor");
|
| 31604 |
tejbeer |
370 |
|
| 33542 |
amit.gupta |
371 |
if (availabilityItemMap.containsKey(String.valueOf(item.getId()))) {
|
| 33570 |
amit.gupta |
372 |
int itemStockColor = 0;
|
| 33542 |
amit.gupta |
373 |
for (Map.Entry<String, Map<String, Integer>> entry : availabilityItemMap
|
|
|
374 |
.get(String.valueOf(item.getId())).entrySet()) {
|
|
|
375 |
String warehouseId = entry.getKey();
|
|
|
376 |
Map<String, Integer> avMap = entry.getValue();
|
|
|
377 |
if (!avColorMap.containsKey(Integer.parseInt(warehouseId))) {
|
|
|
378 |
avColorMap.put(Integer.parseInt(warehouseId), 0);
|
|
|
379 |
}
|
|
|
380 |
int color = avColorMap.get(Integer.parseInt(warehouseId));
|
| 31604 |
tejbeer |
381 |
|
| 33542 |
amit.gupta |
382 |
if (avMap.get("netAvailability") > 0) {
|
|
|
383 |
color = 2;
|
| 33562 |
amit.gupta |
384 |
} else if (avMap.get("netPo") > 0) {
|
| 33542 |
amit.gupta |
385 |
color = Math.max(color, 1);
|
|
|
386 |
} else {
|
|
|
387 |
color = Math.max(color, 0);
|
|
|
388 |
}
|
|
|
389 |
avColorMap.put(Integer.parseInt(warehouseId), color);
|
| 31604 |
tejbeer |
390 |
|
| 33542 |
amit.gupta |
391 |
catalogObj.put("avColor", avColorMap);
|
| 33570 |
amit.gupta |
392 |
if (color > itemStockColor) {
|
|
|
393 |
itemStockColor = color;
|
|
|
394 |
}
|
| 33542 |
amit.gupta |
395 |
}
|
| 33570 |
amit.gupta |
396 |
if (itemStockColor > 0 && itemStockColor > (Integer) catalogObj.get("stockColor")) {
|
|
|
397 |
catalogObj.put("stockColor", itemStockColor);
|
|
|
398 |
}
|
| 33542 |
amit.gupta |
399 |
}
|
| 31604 |
tejbeer |
400 |
|
| 33542 |
amit.gupta |
401 |
Map<Integer, Object> itemColorMap = (Map<Integer, Object>) catalogObj.get("items");
|
| 31604 |
tejbeer |
402 |
|
| 33542 |
amit.gupta |
403 |
if (!itemColorMap.containsKey(item.getId())) {
|
|
|
404 |
itemColorMap.put(item.getId(), new HashMap<String, Object>() {
|
|
|
405 |
{
|
|
|
406 |
put("color", item.getColor().replace("f_", ""));
|
|
|
407 |
put("tagPricing", new ArrayList<TagListing>());
|
|
|
408 |
}
|
|
|
409 |
});
|
|
|
410 |
}
|
|
|
411 |
Map<String, Object> itemMap = (Map<String, Object>) itemColorMap.get(item.getId());
|
|
|
412 |
List<TagListing> tagPricing = (List<TagListing>) itemMap.get("tagPricing");
|
| 33562 |
amit.gupta |
413 |
tagPricing.add(tagListing);
|
| 33542 |
amit.gupta |
414 |
}
|
| 33562 |
amit.gupta |
415 |
//logger.info("catalogObj {}", catalogMap);
|
| 31604 |
tejbeer |
416 |
|
| 33542 |
amit.gupta |
417 |
List<SolrInputDocument> catalogSolrObjs = new ArrayList<>();
|
|
|
418 |
for (Entry<Integer, Map<String, Object>> entry : catalogMap.entrySet()) {
|
|
|
419 |
int catalogId = entry.getKey();
|
|
|
420 |
Map<String, Object> catalogValMap = entry.getValue();
|
|
|
421 |
Map<Integer, Object> itemsMap = (Map<Integer, Object>) catalogValMap.get("items");
|
| 31604 |
tejbeer |
422 |
|
| 33542 |
amit.gupta |
423 |
boolean active = false;
|
|
|
424 |
// Map<Integer, Object> itemsMap = (Map<String, Object>)
|
|
|
425 |
// catalogValMap.get("items");
|
|
|
426 |
List<SolrInputDocument> itemObjs = new ArrayList<>();
|
|
|
427 |
float mop = 0;
|
| 33574 |
amit.gupta |
428 |
float dp = 0;
|
| 31604 |
tejbeer |
429 |
|
| 33542 |
amit.gupta |
430 |
for (Entry<Integer, Object> itemEntry : itemsMap.entrySet()) {
|
|
|
431 |
int itemId = itemEntry.getKey();
|
|
|
432 |
Map<String, Object> itemMap = (Map<String, Object>) itemEntry.getValue();
|
|
|
433 |
List<TagListing> tags = (List<TagListing>) itemMap.get("tagPricing");
|
|
|
434 |
SolrInputDocument itemObj = new SolrInputDocument();
|
| 31604 |
tejbeer |
435 |
|
| 33542 |
amit.gupta |
436 |
for (TagListing taglist : tags) {
|
| 33562 |
amit.gupta |
437 |
active = active || taglist.isActive();
|
| 33542 |
amit.gupta |
438 |
itemObj.setField("id", "itemtag-" + itemId + "-" + taglist.getTagId());
|
|
|
439 |
itemObj.setField("color_s", itemMap.get("color"));
|
|
|
440 |
itemObj.setField("itemId_i", itemId);
|
|
|
441 |
itemObj.setField("tagId_i", taglist.getTagId());
|
|
|
442 |
itemObj.setField("mrp_f", taglist.getMrp());
|
|
|
443 |
itemObj.setField("mop_f", taglist.getMop());
|
|
|
444 |
itemObj.setField("sellingPrice_f", taglist.getSellingPrice());
|
|
|
445 |
itemObj.setField("active_b", taglist.isActive());
|
|
|
446 |
itemObj.setField("hot_deal_b", taglist.isHotDeals());
|
|
|
447 |
mop = taglist.getMop();
|
| 33574 |
amit.gupta |
448 |
dp = taglist.getSellingPrice();
|
| 33542 |
amit.gupta |
449 |
}
|
|
|
450 |
itemObjs.add(itemObj);
|
|
|
451 |
}
|
| 33570 |
amit.gupta |
452 |
//logger.info("catalogValMap {}", catalogValMap);
|
|
|
453 |
//logger.info("rank {}", catalogValMap.get("rank"));
|
| 31604 |
tejbeer |
454 |
|
| 33542 |
amit.gupta |
455 |
SolrInputDocument catalogSolrObj = new SolrInputDocument();
|
|
|
456 |
catalogSolrObj.setField("id", "catalog" + catalogId);
|
|
|
457 |
catalogSolrObj.setField("rank_i", catalogValMap.get("rank"));
|
|
|
458 |
catalogSolrObj.setField("title_s", catalogValMap.get("title"));
|
|
|
459 |
// catalogSolrObj.setField("_childDocuments_", itemObjs);
|
|
|
460 |
catalogSolrObj.addChildDocuments(itemObjs);
|
|
|
461 |
catalogSolrObj.setField("child_b", itemObjs.size() > 0);
|
|
|
462 |
catalogSolrObj.setField("catalogId_i", catalogId);
|
|
|
463 |
catalogSolrObj.setField("imageUrl_s",
|
|
|
464 |
catalogValMap.get("imageUrl").toString().replace("saholic", "smartdukaan"));
|
|
|
465 |
catalogSolrObj.setField("feature_s", catalogValMap.get("feature"));
|
|
|
466 |
catalogSolrObj.setField("brand_ss", catalogValMap.get("brand"));
|
|
|
467 |
catalogSolrObj.setField("create_s", catalogValMap.get("create_timestamp"));
|
|
|
468 |
catalogSolrObj.setField("categoryId_i", catalogValMap.get("categoryId"));
|
|
|
469 |
catalogSolrObj.setField("subCategoryId_i", catalogValMap.get("subCategoryId"));
|
|
|
470 |
catalogSolrObj.setField("label_ss", catalogValMap.get("labels"));
|
|
|
471 |
catalogSolrObj.setField("mop_f", mop);
|
| 33574 |
amit.gupta |
472 |
catalogSolrObj.setField("dp_f", dp);
|
| 33542 |
amit.gupta |
473 |
catalogSolrObj.setField("hsncode_s", catalogValMap.get("hsnCode"));
|
|
|
474 |
catalogSolrObj.setField("show_default_b", true);
|
| 31710 |
tejbeer |
475 |
|
| 33542 |
amit.gupta |
476 |
String[] brands = (String[]) catalogValMap.get("brand");
|
|
|
477 |
for (String brand : brands) {
|
|
|
478 |
if (brand.equals("FOC")) {
|
|
|
479 |
catalogSolrObj.setField("show_default_b", false);
|
| 31604 |
tejbeer |
480 |
|
| 33542 |
amit.gupta |
481 |
}
|
| 31604 |
tejbeer |
482 |
|
| 33542 |
amit.gupta |
483 |
if (brand.equals("Live Demo")) {
|
|
|
484 |
catalogSolrObj.setField("show_default_b", false);
|
| 31604 |
tejbeer |
485 |
|
| 33542 |
amit.gupta |
486 |
}
|
|
|
487 |
}
|
|
|
488 |
Map<Integer, Integer> avColorMap = (Map<Integer, Integer>) catalogValMap.get("avColor");
|
| 33499 |
amit.gupta |
489 |
|
| 33570 |
amit.gupta |
490 |
|
|
|
491 |
for (Integer warehouseId : ProfitMandiConstants.WAREHOUSE_MAP.keySet()) {
|
|
|
492 |
catalogSolrObj.setField("w" + warehouseId + "_i", 0);
|
|
|
493 |
}
|
| 33542 |
amit.gupta |
494 |
for (Entry<Integer, Integer> avColorEntry : avColorMap.entrySet()) {
|
|
|
495 |
int whId = avColorEntry.getKey();
|
| 33562 |
amit.gupta |
496 |
int color = avColorEntry.getValue();
|
| 33542 |
amit.gupta |
497 |
catalogSolrObj.setField("w" + whId + "_i", color);
|
|
|
498 |
}
|
| 33570 |
amit.gupta |
499 |
|
|
|
500 |
List<Integer> similalarModels = null;
|
|
|
501 |
if ((Integer) catalogValMap.get("categoryId") == 3) {
|
| 33571 |
amit.gupta |
502 |
float starPrice = mop - 500f;
|
|
|
503 |
float endPrice = mop + 1000f;
|
| 33570 |
amit.gupta |
504 |
similalarModels = new ArrayList<>();
|
|
|
505 |
for (Entry<Float, List<Integer>> floatListEntry : priceModelMap.entrySet()) {
|
|
|
506 |
float modelPrice = floatListEntry.getKey();
|
|
|
507 |
if (modelPrice >= starPrice && modelPrice <= endPrice) {
|
|
|
508 |
List<Integer> instock = floatListEntry.getValue().stream().filter(x->catalogMap.get(x).get("stockColor") != null && (Integer) (catalogMap.get(x).get("stockColor"))>0).collect(Collectors.toList());
|
| 33571 |
amit.gupta |
509 |
logger.info("Entry before - {}, after - {}", floatListEntry.getValue().size(), instock.size());
|
| 33570 |
amit.gupta |
510 |
similalarModels.addAll(instock);
|
|
|
511 |
}
|
|
|
512 |
if (modelPrice > endPrice) break;
|
|
|
513 |
}
|
|
|
514 |
similalarModels.remove(Integer.valueOf(catalogId));
|
|
|
515 |
}
|
|
|
516 |
catalogSolrObj.setField("similarModels_ii", similalarModels == null ? Collections.EMPTY_LIST : similalarModels);
|
|
|
517 |
|
|
|
518 |
|
| 33542 |
amit.gupta |
519 |
catalogSolrObj.setField("active_b", active);
|
|
|
520 |
logger.info("catalogSolrObj {}", catalogSolrObj.get("rank_i"));
|
|
|
521 |
catalogSolrObjs.add(catalogSolrObj);
|
|
|
522 |
}
|
| 31604 |
tejbeer |
523 |
|
| 33570 |
amit.gupta |
524 |
|
| 33542 |
amit.gupta |
525 |
logger.info("catalogSolrObjs {}", catalogSolrObjs);
|
| 31604 |
tejbeer |
526 |
|
| 33542 |
amit.gupta |
527 |
String solrPath = "http://" + solrUrl + ":8984/solr/demo";
|
|
|
528 |
SolrClient solr = new HttpSolrClient.Builder(solrPath).build();
|
| 31604 |
tejbeer |
529 |
|
| 33542 |
amit.gupta |
530 |
solr.deleteByQuery("*:*");
|
|
|
531 |
solr.add(catalogSolrObjs);
|
|
|
532 |
|
|
|
533 |
org.apache.solr.client.solrj.response.UpdateResponse updateResponse = solr.commit();
|
|
|
534 |
logger.info("solr {}", updateResponse.getStatus());
|
|
|
535 |
|
|
|
536 |
}
|
|
|
537 |
|
|
|
538 |
public void pushData() throws Exception {
|
|
|
539 |
this.populateTagItems();
|
|
|
540 |
}
|
| 31604 |
tejbeer |
541 |
}
|