| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.dao.service.solr;
|
1 |
package com.spice.profitmandi.dao.service.solr;
|
| 2 |
|
2 |
|
| 3 |
import com.google.gson.Gson;
|
3 |
import com.google.gson.Gson;
|
| 4 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
4 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| - |
|
5 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 5 |
import com.spice.profitmandi.dao.entity.catalog.TagListing;
|
6 |
import com.spice.profitmandi.dao.entity.catalog.TagListing;
|
| 6 |
import com.spice.profitmandi.dao.entity.catalog.TagRanking;
|
7 |
import com.spice.profitmandi.dao.entity.catalog.TagRanking;
|
| 7 |
import com.spice.profitmandi.dao.entity.dtr.WebProductListing;
|
8 |
import com.spice.profitmandi.dao.entity.dtr.WebProductListing;
|
| 8 |
import com.spice.profitmandi.dao.entity.similarModel.SimilarModel;
|
9 |
import com.spice.profitmandi.dao.entity.similarModel.SimilarModel;
|
| 9 |
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
|
10 |
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
|
| Line 68... |
Line 69... |
| 68 |
|
69 |
|
| 69 |
private static final Logger logger = LogManager.getLogger(FofoSolr.class);
|
70 |
private static final Logger logger = LogManager.getLogger(FofoSolr.class);
|
| 70 |
|
71 |
|
| 71 |
private static final List<Integer> CATEGORY_MASTER = Arrays.asList(10006, 10010, 14202, 14203);
|
72 |
private static final List<Integer> CATEGORY_MASTER = Arrays.asList(10006, 10010, 14202, 14203);
|
| 72 |
|
73 |
|
| 73 |
String mongoHost = "localhost";
|
- |
|
| 74 |
|
- |
|
| 75 |
private String getAvailabilityJSON() {
|
- |
|
| 76 |
String url = reporticoUrl + "?execute_mode=EXECUTE&xmlin=warehousecisnew.xml&project=FOCOR&project_password=focor&target_format=JSON";
|
- |
|
| 77 |
return getUrlContent(url);
|
- |
|
| 78 |
}
|
- |
|
| 79 |
|
- |
|
| 80 |
private String getPendingPOJSON() {
|
- |
|
| 81 |
String url = reporticoUrl + "?execute_mode=EXECUTE&xmlin=UnfulfilledPOItemsNew.xml&project=FOCOR&project_password=focor&target_format=JSON";
|
- |
|
| 82 |
return getUrlContent(url);
|
- |
|
| 83 |
}
|
- |
|
| 84 |
|
- |
|
| 85 |
private static String getUrlContent(String urlString) {
|
74 |
private static String getUrlContent(String urlString) {
|
| 86 |
BufferedReader reader = null;
|
75 |
BufferedReader reader = null;
|
| 87 |
try {
|
76 |
try {
|
| 88 |
URL url = new URL(urlString);
|
77 |
URL url = new URL(urlString);
|
| 89 |
URLConnection conn = url.openConnection();
|
78 |
URLConnection conn = url.openConnection();
|
| Line 270... |
Line 259... |
| 270 |
featureMap.put(tagRanking.getCatalogItemId(), tagRanking.getFeature());
|
259 |
featureMap.put(tagRanking.getCatalogItemId(), tagRanking.getFeature());
|
| 271 |
}
|
260 |
}
|
| 272 |
//Get Similar Models
|
261 |
//Get Similar Models
|
| 273 |
List<SimilarModel> similarModels = similarModelRepository.selectAll();
|
262 |
List<SimilarModel> similarModels = similarModelRepository.selectAll();
|
| 274 |
|
263 |
|
| 275 |
Map<Integer, List<Integer>> similarModelsMap = similarModels.stream().collect(Collectors.groupingBy(SimilarModel::getCatalogId, Collectors.mapping(x->x.getSimilarCatalogId(), Collectors.toList())));
|
264 |
Map<Integer, List<Integer>> similarModelsMap = similarModels.stream().collect(Collectors.groupingBy(SimilarModel::getCatalogId, Collectors.mapping(x -> x.getSimilarCatalogId(), Collectors.toList())));
|
| 276 |
|
265 |
|
| 277 |
Map<Integer, Map<String, Object>> catalogMap = new HashMap<>();
|
266 |
Map<Integer, Map<String, Object>> catalogMap = new HashMap<>();
|
| 278 |
|
267 |
|
| 279 |
List<status> statuses = Arrays.asList(status.ACTIVE, status.PAUSED_BY_RISK, status.PARTIALLY_ACTIVE);
|
268 |
List<status> statuses = Arrays.asList(status.ACTIVE, status.PAUSED_BY_RISK, status.PARTIALLY_ACTIVE);
|
| 280 |
|
269 |
|
| Line 286... |
Line 275... |
| 286 |
* List<ItemTagModel> tuples =
|
275 |
* List<ItemTagModel> tuples =
|
| 287 |
* tagListingRepository.getAllItemTagByStatus(statuses).stream() .filter(x ->
|
276 |
* tagListingRepository.getAllItemTagByStatus(statuses).stream() .filter(x ->
|
| 288 |
* x.getItem().getCatalogItemId() == 1023747).collect(Collectors.toList());
|
277 |
* x.getItem().getCatalogItemId() == 1023747).collect(Collectors.toList());
|
| 289 |
*/
|
278 |
*/
|
| 290 |
|
279 |
|
| 291 |
List<ItemTagModel> tuples = tagListingRepository.getAllItemTagByStatus(statuses);
|
280 |
List<ItemTagModel> itemTagModels = tagListingRepository.getAllItemTagByStatus(statuses);
|
| 292 |
|
281 |
|
| 293 |
Map<String, Object> projection = new HashMap<>();
|
282 |
Map<String, Object> projection = new HashMap<>();
|
| 294 |
projection.put("defaultImageUrl", 1);
|
283 |
projection.put("defaultImageUrl", 1);
|
| 295 |
|
284 |
|
| 296 |
List<String> excludeBrands = Arrays.asList("Dummy", "FOC HANDSET");
|
285 |
List<String> excludeBrands = Arrays.asList("Dummy", "FOC HANDSET");
|
| 297 |
|
286 |
|
| - |
|
287 |
Map<Float, List<Integer>> priceModelMap = new TreeMap<>();
|
| 298 |
for (ItemTagModel result : tuples) {
|
288 |
for (ItemTagModel itemTagModel : itemTagModels) {
|
| 299 |
TagListing tag = result.getTagListing();
|
289 |
TagListing tagListing = itemTagModel.getTagListing();
|
| 300 |
com.spice.profitmandi.dao.entity.catalog.Item item = result.getItem();
|
290 |
com.spice.profitmandi.dao.entity.catalog.Item item = itemTagModel.getItem();
|
| 301 |
if (excludeBrands.contains(item.getBrand())) {
|
291 |
if (excludeBrands.contains(item.getBrand())) {
|
| 302 |
continue;
|
292 |
continue;
|
| 303 |
}
|
293 |
}
|
| 304 |
|
294 |
|
| 305 |
if (!catalogMap.containsKey(item.getCatalogItemId())) {
|
295 |
if (!catalogMap.containsKey(item.getCatalogItemId())) {
|
| - |
|
296 |
|
| - |
|
297 |
if (!priceModelMap.containsKey(tagListing.getSellingPrice()) && item.getCategoryId()==10006) {
|
| - |
|
298 |
priceModelMap.put(tagListing.getSellingPrice(), new ArrayList<>());
|
| - |
|
299 |
}
|
| - |
|
300 |
List<Integer> priceModels = priceModelMap.get(tagListing.getSellingPrice());
|
| - |
|
301 |
priceModels.add(item.getCatalogItemId());
|
| - |
|
302 |
|
| 306 |
Map<String, Object> catalogObj = new HashMap<>();
|
303 |
Map<String, Object> catalogObj = new HashMap<>();
|
| 307 |
if(similarModelsMap.containsKey(item.getCatalogItemId())) {
|
304 |
if (similarModelsMap.containsKey(item.getCatalogItemId())) {
|
| 308 |
catalogObj.put("similarModels", similarModelsMap.get(item.getCatalogItemId()));
|
305 |
catalogObj.put("similarModels", similarModelsMap.get(item.getCatalogItemId()));
|
| 309 |
} else {
|
306 |
} else {
|
| 310 |
catalogObj.put("similarModels", Collections.EMPTY_LIST);
|
307 |
catalogObj.put("similarModels", Collections.EMPTY_LIST);
|
| 311 |
}
|
308 |
}
|
| 312 |
|
309 |
|
| Line 363... |
Line 360... |
| 363 |
if (item.getCategoryId() == 10006) {
|
360 |
if (item.getCategoryId() == 10006) {
|
| 364 |
catalogObj.put("categoryId", 3);
|
361 |
catalogObj.put("categoryId", 3);
|
| 365 |
}
|
362 |
}
|
| 366 |
catalogObj.put("subCategoryId", item.getCategoryId());
|
363 |
catalogObj.put("subCategoryId", item.getCategoryId());
|
| 367 |
catalogObj.put("create_timestamp",
|
364 |
catalogObj.put("create_timestamp",
|
| 368 |
tag.getCreatedTimestamp().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli());
|
365 |
tagListing.getCreatedTimestamp().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli());
|
| 369 |
|
366 |
|
| 370 |
if (catalogLabelMap.containsKey(item.getCatalogItemId())
|
367 |
if (catalogLabelMap.containsKey(item.getCatalogItemId())
|
| 371 |
&& catalogLabelMap.get(item.getCatalogItemId()) != null) {
|
368 |
&& catalogLabelMap.get(item.getCatalogItemId()) != null) {
|
| 372 |
catalogObj.put("labels", catalogLabelMap.get(item.getCatalogItemId()));
|
369 |
catalogObj.put("labels", catalogLabelMap.get(item.getCatalogItemId()));
|
| 373 |
|
370 |
|
| Line 390... |
Line 387... |
| 390 |
}
|
387 |
}
|
| 391 |
int color = avColorMap.get(Integer.parseInt(warehouseId));
|
388 |
int color = avColorMap.get(Integer.parseInt(warehouseId));
|
| 392 |
|
389 |
|
| 393 |
if (avMap.get("netAvailability") > 0) {
|
390 |
if (avMap.get("netAvailability") > 0) {
|
| 394 |
color = 2;
|
391 |
color = 2;
|
| 395 |
} else if (avMap.get("netAvailability") + avMap.get("netPo") > 0) {
|
392 |
} else if (avMap.get("netPo") > 0) {
|
| 396 |
color = Math.max(color, 1);
|
393 |
color = Math.max(color, 1);
|
| 397 |
} else {
|
394 |
} else {
|
| 398 |
color = Math.max(color, 0);
|
395 |
color = Math.max(color, 0);
|
| 399 |
}
|
396 |
}
|
| 400 |
avColorMap.put(Integer.parseInt(warehouseId), color);
|
397 |
avColorMap.put(Integer.parseInt(warehouseId), color);
|
| Line 415... |
Line 412... |
| 415 |
}
|
412 |
}
|
| 416 |
});
|
413 |
});
|
| 417 |
}
|
414 |
}
|
| 418 |
Map<String, Object> itemMap = (Map<String, Object>) itemColorMap.get(item.getId());
|
415 |
Map<String, Object> itemMap = (Map<String, Object>) itemColorMap.get(item.getId());
|
| 419 |
List<TagListing> tagPricing = (List<TagListing>) itemMap.get("tagPricing");
|
416 |
List<TagListing> tagPricing = (List<TagListing>) itemMap.get("tagPricing");
|
| 420 |
tagPricing.add(tag);
|
417 |
tagPricing.add(tagListing);
|
| 421 |
}
|
418 |
}
|
| - |
|
419 |
//logger.info("catalogObj {}", catalogMap);
|
| 422 |
|
420 |
|
| 423 |
logger.info("catalogObj {}", catalogMap);
|
- |
|
| 424 |
List<SolrInputDocument> catalogSolrObjs = new ArrayList<>();
|
421 |
List<SolrInputDocument> catalogSolrObjs = new ArrayList<>();
|
| 425 |
for (Entry<Integer, Map<String, Object>> entry : catalogMap.entrySet()) {
|
422 |
for (Entry<Integer, Map<String, Object>> entry : catalogMap.entrySet()) {
|
| 426 |
int catalogId = entry.getKey();
|
423 |
int catalogId = entry.getKey();
|
| 427 |
Map<String, Object> catalogValMap = entry.getValue();
|
424 |
Map<String, Object> catalogValMap = entry.getValue();
|
| 428 |
Map<Integer, Object> itemsMap = (Map<Integer, Object>) catalogValMap.get("items");
|
425 |
Map<Integer, Object> itemsMap = (Map<Integer, Object>) catalogValMap.get("items");
|
| Line 430... |
Line 427... |
| 430 |
boolean active = false;
|
427 |
boolean active = false;
|
| 431 |
// Map<Integer, Object> itemsMap = (Map<String, Object>)
|
428 |
// Map<Integer, Object> itemsMap = (Map<String, Object>)
|
| 432 |
// catalogValMap.get("items");
|
429 |
// catalogValMap.get("items");
|
| 433 |
List<SolrInputDocument> itemObjs = new ArrayList<>();
|
430 |
List<SolrInputDocument> itemObjs = new ArrayList<>();
|
| 434 |
float mop = 0;
|
431 |
float mop = 0;
|
| - |
|
432 |
float dp = 0;
|
| 435 |
|
433 |
|
| 436 |
for (Entry<Integer, Object> itemEntry : itemsMap.entrySet()) {
|
434 |
for (Entry<Integer, Object> itemEntry : itemsMap.entrySet()) {
|
| 437 |
int itemId = itemEntry.getKey();
|
435 |
int itemId = itemEntry.getKey();
|
| 438 |
Map<String, Object> itemMap = (Map<String, Object>) itemEntry.getValue();
|
436 |
Map<String, Object> itemMap = (Map<String, Object>) itemEntry.getValue();
|
| 439 |
List<TagListing> tags = (List<TagListing>) itemMap.get("tagPricing");
|
437 |
List<TagListing> tags = (List<TagListing>) itemMap.get("tagPricing");
|
| 440 |
SolrInputDocument itemObj = new SolrInputDocument();
|
438 |
SolrInputDocument itemObj = new SolrInputDocument();
|
| 441 |
|
439 |
|
| 442 |
for (TagListing taglist : tags) {
|
440 |
for (TagListing taglist : tags) {
|
| 443 |
active = active || (Boolean) taglist.isActive();
|
441 |
active = active || taglist.isActive();
|
| 444 |
itemObj.setField("id", "itemtag-" + itemId + "-" + taglist.getTagId());
|
442 |
itemObj.setField("id", "itemtag-" + itemId + "-" + taglist.getTagId());
|
| 445 |
itemObj.setField("color_s", itemMap.get("color"));
|
443 |
itemObj.setField("color_s", itemMap.get("color"));
|
| 446 |
itemObj.setField("itemId_i", itemId);
|
444 |
itemObj.setField("itemId_i", itemId);
|
| 447 |
itemObj.setField("tagId_i", taglist.getTagId());
|
445 |
itemObj.setField("tagId_i", taglist.getTagId());
|
| 448 |
itemObj.setField("mrp_f", taglist.getMrp());
|
446 |
itemObj.setField("mrp_f", taglist.getMrp());
|
| 449 |
itemObj.setField("mop_f", taglist.getMop());
|
447 |
itemObj.setField("mop_f", taglist.getMop());
|
| 450 |
itemObj.setField("sellingPrice_f", taglist.getSellingPrice());
|
448 |
itemObj.setField("sellingPrice_f", taglist.getSellingPrice());
|
| 451 |
itemObj.setField("active_b", taglist.isActive());
|
449 |
itemObj.setField("active_b", taglist.isActive());
|
| 452 |
itemObj.setField("hot_deal_b", taglist.isHotDeals());
|
450 |
itemObj.setField("hot_deal_b", taglist.isHotDeals());
|
| 453 |
mop = taglist.getMop();
|
451 |
mop = taglist.getMop();
|
| - |
|
452 |
dp = taglist.getSellingPrice();
|
| 454 |
|
453 |
|
| 455 |
}
|
454 |
}
|
| 456 |
|
- |
|
| 457 |
itemObjs.add(itemObj);
|
455 |
itemObjs.add(itemObj);
|
| 458 |
}
|
456 |
}
|
| 459 |
|
457 |
|
| - |
|
458 |
float starPrice = dp - 500f;
|
| - |
|
459 |
float endPrice = dp + 1000f;
|
| - |
|
460 |
List<Integer> similalarModels = null;
|
| - |
|
461 |
if((Integer)catalogValMap.get("categoryId")==3) {
|
| - |
|
462 |
similalarModels = new ArrayList<>();
|
| - |
|
463 |
for (Entry<Float, List<Integer>> floatListEntry : priceModelMap.entrySet()) {
|
| - |
|
464 |
float modelPrice = floatListEntry.getKey();
|
| - |
|
465 |
if (modelPrice >= starPrice && modelPrice <= endPrice) {
|
| - |
|
466 |
similalarModels.addAll(floatListEntry.getValue());
|
| - |
|
467 |
}
|
| - |
|
468 |
if(modelPrice > endPrice) break;
|
| - |
|
469 |
}
|
| - |
|
470 |
similalarModels.remove(catalogId);
|
| - |
|
471 |
}
|
| - |
|
472 |
|
| - |
|
473 |
|
| 460 |
logger.info("catalogValMap {}", catalogValMap);
|
474 |
logger.info("catalogValMap {}", catalogValMap);
|
| 461 |
|
475 |
|
| 462 |
logger.info("rank {}", catalogValMap.get("rank"));
|
476 |
logger.info("rank {}", catalogValMap.get("rank"));
|
| 463 |
|
477 |
|
| 464 |
SolrInputDocument catalogSolrObj = new SolrInputDocument();
|
478 |
SolrInputDocument catalogSolrObj = new SolrInputDocument();
|
| 465 |
|
479 |
|
| 466 |
catalogSolrObj.setField("id", "catalog" + catalogId);
|
480 |
catalogSolrObj.setField("id", "catalog" + catalogId);
|
| 467 |
catalogSolrObj.setField("rank_i", catalogValMap.get("rank"));
|
481 |
catalogSolrObj.setField("rank_i", catalogValMap.get("rank"));
|
| 468 |
catalogSolrObj.setField("similarModels_ii", catalogValMap.get("similarModels"));
|
482 |
catalogSolrObj.setField("similarModels_ii", similalarModels);
|
| 469 |
catalogSolrObj.setField("title_s", catalogValMap.get("title"));
|
483 |
catalogSolrObj.setField("title_s", catalogValMap.get("title"));
|
| 470 |
// catalogSolrObj.setField("_childDocuments_", itemObjs);
|
484 |
// catalogSolrObj.setField("_childDocuments_", itemObjs);
|
| 471 |
catalogSolrObj.addChildDocuments(itemObjs);
|
485 |
catalogSolrObj.addChildDocuments(itemObjs);
|
| 472 |
catalogSolrObj.setField("child_b", itemObjs.size() > 0);
|
486 |
catalogSolrObj.setField("child_b", itemObjs.size() > 0);
|
| 473 |
catalogSolrObj.setField("catalogId_i", catalogId);
|
487 |
catalogSolrObj.setField("catalogId_i", catalogId);
|
| Line 477... |
Line 491... |
| 477 |
catalogSolrObj.setField("brand_ss", catalogValMap.get("brand"));
|
491 |
catalogSolrObj.setField("brand_ss", catalogValMap.get("brand"));
|
| 478 |
catalogSolrObj.setField("create_s", catalogValMap.get("create_timestamp"));
|
492 |
catalogSolrObj.setField("create_s", catalogValMap.get("create_timestamp"));
|
| 479 |
catalogSolrObj.setField("categoryId_i", catalogValMap.get("categoryId"));
|
493 |
catalogSolrObj.setField("categoryId_i", catalogValMap.get("categoryId"));
|
| 480 |
catalogSolrObj.setField("subCategoryId_i", catalogValMap.get("subCategoryId"));
|
494 |
catalogSolrObj.setField("subCategoryId_i", catalogValMap.get("subCategoryId"));
|
| 481 |
catalogSolrObj.setField("label_ss", catalogValMap.get("labels"));
|
495 |
catalogSolrObj.setField("label_ss", catalogValMap.get("labels"));
|
| 482 |
catalogSolrObj.setField("w7573_i", 0);
|
496 |
for (Integer warehouseId : ProfitMandiConstants.WAREHOUSE_MAP.keySet()) {
|
| 483 |
catalogSolrObj.setField("w7678_i", 0);
|
497 |
catalogSolrObj.setField("w" + warehouseId + "_i", 0);
|
| 484 |
catalogSolrObj.setField("w7720_i", 0);
|
- |
|
| 485 |
catalogSolrObj.setField("w8468_i", 0);
|
- |
|
| 486 |
catalogSolrObj.setField("w8889_i", 0);
|
- |
|
| 487 |
catalogSolrObj.setField("w8947_i", 0);
|
- |
|
| 488 |
catalogSolrObj.setField("w9213_i", 0);
|
- |
|
| 489 |
catalogSolrObj.setField("w9203_i", 0);
|
498 |
}
|
| 490 |
catalogSolrObj.setField("mop_f", mop);
|
499 |
catalogSolrObj.setField("mop_f", mop);
|
| 491 |
catalogSolrObj.setField("hsncode_s", catalogValMap.get("hsnCode"));
|
500 |
catalogSolrObj.setField("hsncode_s", catalogValMap.get("hsnCode"));
|
| 492 |
catalogSolrObj.setField("show_default_b", true);
|
501 |
catalogSolrObj.setField("show_default_b", true);
|
| 493 |
|
502 |
|
| 494 |
String[] brands = (String[]) catalogValMap.get("brand");
|
503 |
String[] brands = (String[]) catalogValMap.get("brand");
|
| Line 505... |
Line 514... |
| 505 |
}
|
514 |
}
|
| 506 |
Map<Integer, Integer> avColorMap = (Map<Integer, Integer>) catalogValMap.get("avColor");
|
515 |
Map<Integer, Integer> avColorMap = (Map<Integer, Integer>) catalogValMap.get("avColor");
|
| 507 |
|
516 |
|
| 508 |
for (Entry<Integer, Integer> avColorEntry : avColorMap.entrySet()) {
|
517 |
for (Entry<Integer, Integer> avColorEntry : avColorMap.entrySet()) {
|
| 509 |
int whId = avColorEntry.getKey();
|
518 |
int whId = avColorEntry.getKey();
|
| 510 |
int color = (int) avColorEntry.getValue();
|
519 |
int color = avColorEntry.getValue();
|
| 511 |
catalogSolrObj.setField("w" + whId + "_i", color);
|
520 |
catalogSolrObj.setField("w" + whId + "_i", color);
|
| 512 |
}
|
521 |
}
|
| 513 |
catalogSolrObj.setField("active_b", active);
|
522 |
catalogSolrObj.setField("active_b", active);
|
| 514 |
logger.info("catalogSolrObj {}", catalogSolrObj.get("rank_i"));
|
523 |
logger.info("catalogSolrObj {}", catalogSolrObj.get("rank_i"));
|
| 515 |
catalogSolrObjs.add(catalogSolrObj);
|
524 |
catalogSolrObjs.add(catalogSolrObj);
|