| Line 194... |
Line 194... |
| 194 |
@RequestMapping(value = "/fofo/bucket", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
194 |
@RequestMapping(value = "/fofo/bucket", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 195 |
public ResponseEntity<?> getBucketDetails(HttpServletRequest request, @RequestParam int id) throws ProfitMandiBusinessException {
|
195 |
public ResponseEntity<?> getBucketDetails(HttpServletRequest request, @RequestParam int id) throws ProfitMandiBusinessException {
|
| 196 |
List<ItemQuantityPojo> iqPojo = itemBucketService.getBucketDetails(id);
|
196 |
List<ItemQuantityPojo> iqPojo = itemBucketService.getBucketDetails(id);
|
| 197 |
Map<Integer, Integer> itemIdsQtyMap = iqPojo.stream().collect(Collectors.toMap(x -> x.getItemId(), x -> x.getQuantity()));
|
197 |
Map<Integer, Integer> itemIdsQtyMap = iqPojo.stream().collect(Collectors.toMap(x -> x.getItemId(), x -> x.getQuantity()));
|
| 198 |
Set<Integer> catalogIds = itemRepository.selectByIds(itemIdsQtyMap.keySet()).stream().map(x -> x.getCatalogItemId()).collect(Collectors.toSet());
|
198 |
Set<Integer> catalogIds = itemRepository.selectByIds(itemIdsQtyMap.keySet()).stream().map(x -> x.getCatalogItemId()).collect(Collectors.toSet());
|
| 199 |
RestClient rc = new RestClient();
|
- |
|
| 200 |
Map<String, String> params = new HashMap<>();
|
199 |
Map<String, String> params = new HashMap<>();
|
| 201 |
List<String> mandatoryQ = new ArrayList<>();
|
200 |
List<String> mandatoryQ = new ArrayList<>();
|
| 202 |
mandatoryQ.add(
|
201 |
mandatoryQ.add(
|
| 203 |
String.format("+catalogId_i:(%s) +{!parent which=\"id:catalog*\"}", StringUtils.join(catalogIds, " ")));
|
202 |
String.format("+catalogId_i:(%s) +{!parent which=\"id:catalog*\"}", StringUtils.join(catalogIds, " ")));
|
| 204 |
params.put("start", "0");
|
203 |
params.put("start", "0");
|
| Line 207... |
Line 206... |
| 207 |
params.put("fl", "*, [child parentFilter=id:catalog*]");
|
206 |
params.put("fl", "*, [child parentFilter=id:catalog*]");
|
| 208 |
|
207 |
|
| 209 |
params.put("wt", "json");
|
208 |
params.put("wt", "json");
|
| 210 |
String response = null;
|
209 |
String response = null;
|
| 211 |
try {
|
210 |
try {
|
| 212 |
response = rc.get(SchemeType.HTTP, solrUrl, 8984, "solr/demo/select", params);
|
211 |
response = restClient.get(SchemeType.HTTP, solrUrl, 8984, "solr/demo/select", params);
|
| 213 |
} catch (HttpHostConnectException e) {
|
212 |
} catch (HttpHostConnectException e) {
|
| 214 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
213 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
| 215 |
}
|
214 |
}
|
| 216 |
JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
|
215 |
JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
|
| 217 |
JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
|
216 |
JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
|
| Line 233... |
Line 232... |
| 233 |
}
|
232 |
}
|
| 234 |
List<SuggestedPoDetail> mpd = suggestedPoDetailRepository.selectByPoId(suggestedPo.getId());
|
233 |
List<SuggestedPoDetail> mpd = suggestedPoDetailRepository.selectByPoId(suggestedPo.getId());
|
| 235 |
Map<Integer, Integer> itemIdsQtyMap = mpd.stream().collect(Collectors.toMap(x -> x.getItemId(), x -> x.getQuantity()));
|
234 |
Map<Integer, Integer> itemIdsQtyMap = mpd.stream().collect(Collectors.toMap(x -> x.getItemId(), x -> x.getQuantity()));
|
| 236 |
|
235 |
|
| 237 |
Set<Integer> catalogIds = itemRepository.selectByIds(itemIdsQtyMap.keySet()).stream().map(x -> x.getCatalogItemId()).collect(Collectors.toSet());
|
236 |
Set<Integer> catalogIds = itemRepository.selectByIds(itemIdsQtyMap.keySet()).stream().map(x -> x.getCatalogItemId()).collect(Collectors.toSet());
|
| 238 |
RestClient rc = new RestClient();
|
- |
|
| 239 |
Map<String, String> params = new HashMap<>();
|
237 |
Map<String, String> params = new HashMap<>();
|
| 240 |
List<String> mandatoryQ = new ArrayList<>();
|
238 |
List<String> mandatoryQ = new ArrayList<>();
|
| 241 |
mandatoryQ.add(
|
239 |
mandatoryQ.add(
|
| 242 |
String.format("+catalogId_i:(%s) +{!parent which=\"id:catalog*\"}", StringUtils.join(catalogIds, " ")));
|
240 |
String.format("+catalogId_i:(%s) +{!parent which=\"id:catalog*\"}", StringUtils.join(catalogIds, " ")));
|
| 243 |
params.put("start", "0");
|
241 |
params.put("start", "0");
|
| 244 |
params.put("rows", "100");
|
242 |
params.put("rows", "100");
|
| Line 246... |
Line 244... |
| 246 |
params.put("fl", "*, [child parentFilter=id:catalog*]");
|
244 |
params.put("fl", "*, [child parentFilter=id:catalog*]");
|
| 247 |
|
245 |
|
| 248 |
params.put("wt", "json");
|
246 |
params.put("wt", "json");
|
| 249 |
String response = null;
|
247 |
String response = null;
|
| 250 |
try {
|
248 |
try {
|
| 251 |
response = rc.get(SchemeType.HTTP, solrUrl, 8984, "solr/demo/select", params);
|
249 |
response = restClient.get(SchemeType.HTTP, solrUrl, 8984, "solr/demo/select", params);
|
| 252 |
} catch (HttpHostConnectException e) {
|
250 |
} catch (HttpHostConnectException e) {
|
| 253 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
251 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
| 254 |
}
|
252 |
}
|
| 255 |
JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
|
253 |
JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
|
| 256 |
JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
|
254 |
JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
|
| Line 410... |
Line 408... |
| 410 |
params.put("rows", catalogIds.size() + "");
|
408 |
params.put("rows", catalogIds.size() + "");
|
| 411 |
|
409 |
|
| 412 |
String response = restClient.get(SchemeType.HTTP, solrUrl, 8984, "solr/demo/select", params);
|
410 |
String response = restClient.get(SchemeType.HTTP, solrUrl, 8984, "solr/demo/select", params);
|
| 413 |
JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
|
411 |
JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
|
| 414 |
JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
|
412 |
JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
|
| 415 |
int warehouseId = fofoStoreRepository.selectByRetailerId(fofoStore.getId()).getWarehouseId();
|
413 |
int warehouseId = fofoStore.getWarehouseId();
|
| 416 |
Map<Integer, List<SaholicPOItem>> poItemAvailabilityMap = saholicInventoryService.getSaholicPOItems().get(warehouseId);
|
414 |
Map<Integer, List<SaholicPOItem>> poItemAvailabilityMap = saholicInventoryService.getSaholicPOItems().get(warehouseId);
|
| - |
|
415 |
|
| - |
|
416 |
// Pre-fetch all itemIds for batch CIS query
|
| - |
|
417 |
List<Integer> allItemIds = new ArrayList<>();
|
| - |
|
418 |
for (int i = 0; i < docs.length(); i++) {
|
| - |
|
419 |
JSONObject doc = docs.getJSONObject(i);
|
| - |
|
420 |
if (doc.has("_childDocuments_")) {
|
| - |
|
421 |
for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
|
| - |
|
422 |
allItemIds.add(doc.getJSONArray("_childDocuments_").getJSONObject(j).getInt("itemId_i"));
|
| - |
|
423 |
}
|
| - |
|
424 |
}
|
| - |
|
425 |
}
|
| - |
|
426 |
// Batch fetch CIS data
|
| - |
|
427 |
Map<Integer, List<SaholicCISTable>> cisDataByItemId = saholicCISTableRepository
|
| - |
|
428 |
.selectByItemWarehouse(allItemIds, warehouseId).stream()
|
| - |
|
429 |
.collect(Collectors.groupingBy(SaholicCISTable::getItemId));
|
| - |
|
430 |
|
| 417 |
for (int i = 0; i < docs.length(); i++) {
|
431 |
for (int i = 0; i < docs.length(); i++) {
|
| 418 |
JSONObject doc = docs.getJSONObject(i);
|
432 |
JSONObject doc = docs.getJSONObject(i);
|
| 419 |
FofoCatalogResponse fofoCatalogResponse = this.toFofoCatalogResponse(doc);
|
433 |
FofoCatalogResponse fofoCatalogResponse = this.toFofoCatalogResponse(doc);
|
| 420 |
if (doc.has("_childDocuments_")) {
|
434 |
if (doc.has("_childDocuments_")) {
|
| 421 |
String modelColorClass = "grey";
|
435 |
String modelColorClass = "grey";
|
| Line 423... |
Line 437... |
| 423 |
// Iterating itemIds
|
437 |
// Iterating itemIds
|
| 424 |
for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
|
438 |
for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
|
| 425 |
JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
|
439 |
JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
|
| 426 |
int itemId = childItem.getInt("itemId_i");
|
440 |
int itemId = childItem.getInt("itemId_i");
|
| 427 |
|
441 |
|
| 428 |
List<SaholicCISTable> currentAvailability = saholicCISTableRepository.selectByItemWarehouse(itemId, warehouseId);
|
442 |
List<SaholicCISTable> currentAvailability = cisDataByItemId.getOrDefault(itemId, new ArrayList<>());
|
| 429 |
List<SaholicPOItem> poItemAvailability = null;
|
443 |
List<SaholicPOItem> poItemAvailability = null;
|
| 430 |
if (poItemAvailabilityMap != null) {
|
444 |
if (poItemAvailabilityMap != null) {
|
| 431 |
poItemAvailability = poItemAvailabilityMap.get(itemId);
|
445 |
poItemAvailability = poItemAvailabilityMap.get(itemId);
|
| 432 |
}
|
446 |
}
|
| 433 |
|
447 |
|
| Line 485... |
Line 499... |
| 485 |
logger.info("Request " + request.getParameterMap());
|
499 |
logger.info("Request " + request.getParameterMap());
|
| 486 |
String response = null;
|
500 |
String response = null;
|
| 487 |
int userId = (int) request.getAttribute("userId");
|
501 |
int userId = (int) request.getAttribute("userId");
|
| 488 |
|
502 |
|
| 489 |
String uri = "/deals/" + userId;
|
503 |
String uri = "/deals/" + userId;
|
| 490 |
RestClient rc = new RestClient();
|
- |
|
| 491 |
Map<String, String> params = new HashMap<>();
|
504 |
Map<String, String> params = new HashMap<>();
|
| 492 |
params.put("offset", offset);
|
505 |
params.put("offset", offset);
|
| 493 |
params.put("limit", limit);
|
506 |
params.put("limit", limit);
|
| 494 |
params.put("categoryId", categoryId);
|
507 |
params.put("categoryId", categoryId);
|
| 495 |
params.put("direction", direction);
|
508 |
params.put("direction", direction);
|
| 496 |
params.put("sort", sort);
|
509 |
params.put("sort", sort);
|
| Line 500... |
Line 513... |
| 500 |
* if (userInfo.getRoleNames().contains(RoleType.FOFO.toString())) {
|
513 |
* if (userInfo.getRoleNames().contains(RoleType.FOFO.toString())) {
|
| 501 |
* params.put("tag_ids", getCommaSeparateTags(userId)); }
|
514 |
* params.put("tag_ids", getCommaSeparateTags(userId)); }
|
| 502 |
*/
|
515 |
*/
|
| 503 |
List<Object> responseObject = new ArrayList<>();
|
516 |
List<Object> responseObject = new ArrayList<>();
|
| 504 |
try {
|
517 |
try {
|
| 505 |
response = rc.get(SchemeType.HTTP, host, port, uri, params);
|
518 |
response = restClient.get(SchemeType.HTTP, host, port, uri, params);
|
| 506 |
} catch (HttpHostConnectException e) {
|
519 |
} catch (HttpHostConnectException e) {
|
| 507 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
520 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
| 508 |
}
|
521 |
}
|
| 509 |
|
522 |
|
| 510 |
JsonArray result_json = Json.parse(response).asArray();
|
523 |
JsonArray result_json = Json.parse(response).asArray();
|
| Line 535... |
Line 548... |
| 535 |
category_id) throws ProfitMandiBusinessException {
|
548 |
category_id) throws ProfitMandiBusinessException {
|
| 536 |
logger.info("Request " + request.getParameterMap());
|
549 |
logger.info("Request " + request.getParameterMap());
|
| 537 |
String response = null;
|
550 |
String response = null;
|
| 538 |
// TODO: move to properties
|
551 |
// TODO: move to properties
|
| 539 |
String uri = ProfitMandiConstants.URL_BRANDS;
|
552 |
String uri = ProfitMandiConstants.URL_BRANDS;
|
| 540 |
RestClient rc = new RestClient();
|
- |
|
| 541 |
Map<String, String> params = new HashMap<>();
|
553 |
Map<String, String> params = new HashMap<>();
|
| 542 |
params.put("category_id", category_id);
|
554 |
params.put("category_id", category_id);
|
| 543 |
List<DealBrands> dealBrandsResponse = null;
|
555 |
List<DealBrands> dealBrandsResponse = null;
|
| 544 |
try {
|
556 |
try {
|
| 545 |
response = rc.get(SchemeType.HTTP, host, port, uri, params);
|
557 |
response = restClient.get(SchemeType.HTTP, host, port, uri, params);
|
| 546 |
} catch (HttpHostConnectException e) {
|
558 |
} catch (HttpHostConnectException e) {
|
| 547 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
559 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
| 548 |
}
|
560 |
}
|
| 549 |
|
561 |
|
| 550 |
dealBrandsResponse = new Gson().fromJson(response, new TypeToken<List<DealBrands>>() {
|
562 |
dealBrandsResponse = new Gson().fromJson(response, new TypeToken<List<DealBrands>>() {
|
| Line 560... |
Line 572... |
| 560 |
ProfitMandiBusinessException {
|
572 |
ProfitMandiBusinessException {
|
| 561 |
String response = null;
|
573 |
String response = null;
|
| 562 |
// TODO: move to properties
|
574 |
// TODO: move to properties
|
| 563 |
String uri = "getDealById/" + id;
|
575 |
String uri = "getDealById/" + id;
|
| 564 |
System.out.println("Unit deal " + uri);
|
576 |
System.out.println("Unit deal " + uri);
|
| 565 |
RestClient rc = new RestClient();
|
- |
|
| 566 |
Map<String, String> params = new HashMap<>();
|
577 |
Map<String, String> params = new HashMap<>();
|
| 567 |
DealsResponse dealsResponse = null;
|
578 |
DealsResponse dealsResponse = null;
|
| 568 |
try {
|
579 |
try {
|
| 569 |
response = rc.get(SchemeType.HTTP, host, port, uri, params);
|
580 |
response = restClient.get(SchemeType.HTTP, host, port, uri, params);
|
| 570 |
} catch (HttpHostConnectException e) {
|
581 |
} catch (HttpHostConnectException e) {
|
| 571 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
582 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
| 572 |
}
|
583 |
}
|
| 573 |
|
584 |
|
| 574 |
JsonObject result_json = Json.parse(response).asObject();
|
585 |
JsonObject result_json = Json.parse(response).asObject();
|
| Line 593... |
Line 604... |
| 593 |
List<Integer> tagIds = Arrays.asList(4);
|
604 |
List<Integer> tagIds = Arrays.asList(4);
|
| 594 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
605 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
| 595 |
if (roleManagerService.isPartner(userInfo.getRoleIds())) {
|
606 |
if (roleManagerService.isPartner(userInfo.getRoleIds())) {
|
| 596 |
String categoryId = "(3 OR 6)";
|
607 |
String categoryId = "(3 OR 6)";
|
| 597 |
UserCart uc = userAccountRepository.getUserCart(userInfo.getUserId());
|
608 |
UserCart uc = userAccountRepository.getUserCart(userInfo.getUserId());
|
| 598 |
RestClient rc = new RestClient();
|
- |
|
| 599 |
Map<String, String> params = new HashMap<>();
|
609 |
Map<String, String> params = new HashMap<>();
|
| 600 |
List<String> mandatoryQ = new ArrayList<>();
|
610 |
List<String> mandatoryQ = new ArrayList<>();
|
| 601 |
String catalogString = "catalog" + id;
|
611 |
String catalogString = "catalog" + id;
|
| 602 |
|
612 |
|
| 603 |
mandatoryQ.add(String.format("+(categoryId_i:%s) +(id:%s) +{!parent which=\"id:%s\"} tagId_i:(%s)", categoryId, catalogString, catalogString, StringUtils.join(tagIds, " ")));
|
613 |
mandatoryQ.add(String.format("+(categoryId_i:%s) +(id:%s) +{!parent which=\"id:%s\"} tagId_i:(%s)", categoryId, catalogString, catalogString, StringUtils.join(tagIds, " ")));
|
| 604 |
|
614 |
|
| Line 606... |
Line 616... |
| 606 |
params.put("fl", "*, [child parentFilter=id:catalog*]");
|
616 |
params.put("fl", "*, [child parentFilter=id:catalog*]");
|
| 607 |
params.put("sort", "rank_i asc, create_s desc");
|
617 |
params.put("sort", "rank_i asc, create_s desc");
|
| 608 |
params.put("wt", "json");
|
618 |
params.put("wt", "json");
|
| 609 |
String response = null;
|
619 |
String response = null;
|
| 610 |
try {
|
620 |
try {
|
| 611 |
response = rc.get(SchemeType.HTTP, solrUrl, 8984, "solr/demo/select", params);
|
621 |
response = restClient.get(SchemeType.HTTP, solrUrl, 8984, "solr/demo/select", params);
|
| 612 |
} catch (HttpHostConnectException e) {
|
622 |
} catch (HttpHostConnectException e) {
|
| 613 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
623 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
| 614 |
}
|
624 |
}
|
| 615 |
JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
|
625 |
JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
|
| 616 |
JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
|
626 |
JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
|
| Line 664... |
Line 674... |
| 664 |
return new ResponseEntity<>(subCategoriesDisplay, HttpStatus.OK);
|
674 |
return new ResponseEntity<>(subCategoriesDisplay, HttpStatus.OK);
|
| 665 |
}
|
675 |
}
|
| 666 |
|
676 |
|
| 667 |
private List<DBObject> getSubCategoriesToDisplay() throws Exception {
|
677 |
private List<DBObject> getSubCategoriesToDisplay() throws Exception {
|
| 668 |
List<DBObject> subCategories = new ArrayList<>();
|
678 |
List<DBObject> subCategories = new ArrayList<>();
|
| 669 |
RestClient rc = new RestClient();
|
- |
|
| 670 |
Map<String, String> params = new HashMap<>();
|
679 |
Map<String, String> params = new HashMap<>();
|
| 671 |
params.put("q", "categoryId_i:6");
|
680 |
params.put("q", "categoryId_i:6");
|
| 672 |
params.put("group", "true");
|
681 |
params.put("group", "true");
|
| 673 |
params.put("group.field", "subCategoryId_i");
|
682 |
params.put("group.field", "subCategoryId_i");
|
| 674 |
params.put("wt", "json");
|
683 |
params.put("wt", "json");
|
| 675 |
params.put("rows", "50");
|
684 |
params.put("rows", "50");
|
| 676 |
params.put("fl", "subCategoryId_i");
|
685 |
params.put("fl", "subCategoryId_i");
|
| 677 |
String response = null;
|
686 |
String response = null;
|
| 678 |
try {
|
687 |
try {
|
| 679 |
response = rc.get(SchemeType.HTTP, solrUrl, 8984, "solr/demo/select", params);
|
688 |
response = restClient.get(SchemeType.HTTP, solrUrl, 8984, "solr/demo/select", params);
|
| 680 |
} catch (HttpHostConnectException e) {
|
689 |
} catch (HttpHostConnectException e) {
|
| 681 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
690 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
| 682 |
}
|
691 |
}
|
| 683 |
JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("grouped");
|
692 |
JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("grouped");
|
| 684 |
JSONArray groups = solrResponseJSONObj.getJSONObject("subCategoryId_i").getJSONArray("groups");
|
693 |
JSONArray groups = solrResponseJSONObj.getJSONObject("subCategoryId_i").getJSONArray("groups");
|
| Line 719... |
Line 728... |
| 719 |
@ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
728 |
@ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
| 720 |
@RequestMapping(value = "/deals/skus/{skus}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
729 |
@RequestMapping(value = "/deals/skus/{skus}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 721 |
public ResponseEntity<?> getDealsBySkus(@PathVariable String skus) throws ProfitMandiBusinessException {
|
730 |
public ResponseEntity<?> getDealsBySkus(@PathVariable String skus) throws ProfitMandiBusinessException {
|
| 722 |
StringBuffer sb = new StringBuffer("/getDealsForNotification/");
|
731 |
StringBuffer sb = new StringBuffer("/getDealsForNotification/");
|
| 723 |
String uri = sb.append(skus).toString();
|
732 |
String uri = sb.append(skus).toString();
|
| 724 |
RestClient rc = new RestClient();
|
- |
|
| 725 |
String response;
|
733 |
String response;
|
| 726 |
try {
|
734 |
try {
|
| 727 |
response = rc.get(SchemeType.HTTP, host, port, uri, new HashMap<>());
|
735 |
response = restClient.get(SchemeType.HTTP, host, port, uri, new HashMap<>());
|
| 728 |
} catch (HttpHostConnectException e) {
|
736 |
} catch (HttpHostConnectException e) {
|
| 729 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
737 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
| 730 |
}
|
738 |
}
|
| 731 |
JsonArray result_json = Json.parse(response).asArray();
|
739 |
JsonArray result_json = Json.parse(response).asArray();
|
| 732 |
List<Object> responseObject = new ArrayList<>();
|
740 |
List<Object> responseObject = new ArrayList<>();
|
| Line 757... |
Line 765... |
| 757 |
}
|
765 |
}
|
| 758 |
|
766 |
|
| 759 |
private List<FofoCatalogResponse> getDealResponses(UserInfo userInfo, WebListing webListing, int offset,
|
767 |
private List<FofoCatalogResponse> getDealResponses(UserInfo userInfo, WebListing webListing, int offset,
|
| 760 |
int limit) throws Exception {
|
768 |
int limit) throws Exception {
|
| 761 |
|
769 |
|
| 762 |
RestClient rc = new RestClient();
|
- |
|
| 763 |
Map<String, String> params = new HashMap<>();
|
770 |
Map<String, String> params = new HashMap<>();
|
| 764 |
List<String> mandatoryQ = new ArrayList<>();
|
771 |
List<String> mandatoryQ = new ArrayList<>();
|
| 765 |
|
772 |
|
| 766 |
FofoStore fs = fofoStoreRepository.selectByRetailerId(userInfo.getRetailerId());
|
773 |
FofoStore fs = fofoStoreRepository.selectByRetailerId(userInfo.getRetailerId());
|
| 767 |
params.put("sort", "w" + fs.getWarehouseId() + "_i desc");
|
774 |
params.put("sort", "w" + fs.getWarehouseId() + "_i desc");
|
| 768 |
|
775 |
|
| Line 789... |
Line 796... |
| 789 |
params.put("start", String.valueOf(offset));
|
796 |
params.put("start", String.valueOf(offset));
|
| 790 |
params.put("rows", String.valueOf(limit));
|
797 |
params.put("rows", String.valueOf(limit));
|
| 791 |
params.put("wt", "json");
|
798 |
params.put("wt", "json");
|
| 792 |
String response = null;
|
799 |
String response = null;
|
| 793 |
try {
|
800 |
try {
|
| 794 |
response = rc.get(SchemeType.HTTP, solrUrl, 8984, "solr/demo/select", params);
|
801 |
response = restClient.get(SchemeType.HTTP, solrUrl, 8984, "solr/demo/select", params);
|
| 795 |
} catch (HttpHostConnectException e) {
|
802 |
} catch (HttpHostConnectException e) {
|
| 796 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
803 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
| 797 |
}
|
804 |
}
|
| 798 |
JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
|
805 |
JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
|
| 799 |
JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
|
806 |
JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
|
| Line 868... |
Line 875... |
| 868 |
}
|
875 |
}
|
| 869 |
List<CatalogFavourite> catalogFavouriteList = catalogFavouriteRepository.selectBypartnerId(fofoId);
|
876 |
List<CatalogFavourite> catalogFavouriteList = catalogFavouriteRepository.selectBypartnerId(fofoId);
|
| 870 |
Set<Integer> favouriteCatalogIds = catalogFavouriteList.stream()
|
877 |
Set<Integer> favouriteCatalogIds = catalogFavouriteList.stream()
|
| 871 |
.map(CatalogFavourite::getCatalogId)
|
878 |
.map(CatalogFavourite::getCatalogId)
|
| 872 |
.collect(Collectors.toSet());
|
879 |
.collect(Collectors.toSet());
|
| - |
|
880 |
|
| - |
|
881 |
// Pre-fetch CIS data for all items (batch query instead of N+1)
|
| - |
|
882 |
Map<Integer, List<SaholicCISTable>> cisDataByItemId = saholicCISTableRepository
|
| - |
|
883 |
.selectByItemWarehouse(itemIds, warehouseId).stream()
|
| - |
|
884 |
.collect(Collectors.groupingBy(SaholicCISTable::getItemId));
|
| - |
|
885 |
|
| - |
|
886 |
// Pre-fetch all Items (batch query instead of N+1)
|
| - |
|
887 |
Map<Integer, Item> itemMap = itemRepository.selectByIds(new HashSet<>(itemIds)).stream()
|
| - |
|
888 |
.collect(Collectors.toMap(Item::getId, x -> x));
|
| - |
|
889 |
|
| - |
|
890 |
// Pre-fetch cashback data for all catalogs (batch query instead of N+1)
|
| - |
|
891 |
Map<Integer, Float> cashbackMap = schemeService.getCatalogSchemeCashBack(fofoId, catalogIds);
|
| - |
|
892 |
|
| - |
|
893 |
// Pre-fetch web offers (call once instead of inside loop)
|
| - |
|
894 |
Map<Integer, List<WebOffer>> webOffersMap = webOfferRepository.selectAllActiveOffers();
|
| - |
|
895 |
|
| - |
|
896 |
// Pre-fetch combo models (call once instead of inside loop)
|
| - |
|
897 |
Map<Integer, List<ComboModel>> comboModelsByCatalogId = comboModelRepository.selectByWarehouseId(warehouseId)
|
| - |
|
898 |
.stream().collect(Collectors.groupingBy(ComboModel::getCatalogId));
|
| - |
|
899 |
|
| 873 |
for (int i = 0; i < docs.length(); i++) {
|
900 |
for (int i = 0; i < docs.length(); i++) {
|
| 874 |
Map<Integer, FofoAvailabilityInfo> fofoAvailabilityInfoMap = new HashMap<>();
|
901 |
Map<Integer, FofoAvailabilityInfo> fofoAvailabilityInfoMap = new HashMap<>();
|
| 875 |
JSONObject doc = docs.getJSONObject(i);
|
902 |
JSONObject doc = docs.getJSONObject(i);
|
| 876 |
FofoCatalogResponse fofoCatalogResponse = new FofoCatalogResponse();
|
903 |
FofoCatalogResponse fofoCatalogResponse = new FofoCatalogResponse();
|
| 877 |
fofoCatalogResponse.setCatalogId(doc.getInt("catalogId_i"));
|
904 |
fofoCatalogResponse.setCatalogId(doc.getInt("catalogId_i"));
|
| Line 884... |
Line 911... |
| 884 |
if (favouriteCatalogIds.contains(fofoCatalogResponse.getCatalogId())) {
|
911 |
if (favouriteCatalogIds.contains(fofoCatalogResponse.getCatalogId())) {
|
| 885 |
fofoCatalogResponse.setFavourite(true);
|
912 |
fofoCatalogResponse.setFavourite(true);
|
| 886 |
} else {
|
913 |
} else {
|
| 887 |
fofoCatalogResponse.setFavourite(false); // optional, since default is false
|
914 |
fofoCatalogResponse.setFavourite(false); // optional, since default is false
|
| 888 |
}
|
915 |
}
|
| 889 |
List<WebOffer> webOffers = webOfferRepository.selectAllActiveOffers().get(fofoCatalogResponse.getCatalogId());
|
916 |
List<WebOffer> webOffers = webOffersMap.get(fofoCatalogResponse.getCatalogId());
|
| 890 |
|
917 |
|
| 891 |
//logger.info("webOffers {}", webOffers);
|
918 |
//logger.info("webOffers {}", webOffers);
|
| 892 |
if (webOffers != null && webOffers.size() > 0) {
|
919 |
if (webOffers != null && webOffers.size() > 0) {
|
| 893 |
fofoCatalogResponse.setWebOffers(webOffers);
|
920 |
fofoCatalogResponse.setWebOffers(webOffers);
|
| 894 |
fofoCatalogResponse.setOffers(webOffers.stream().map(x -> x.getTitle()).collect(Collectors.toList()));
|
921 |
fofoCatalogResponse.setOffers(webOffers.stream().map(x -> x.getTitle()).collect(Collectors.toList()));
|
| 895 |
|
922 |
|
| 896 |
}
|
923 |
}
|
| 897 |
|
924 |
|
| 898 |
List<ComboModel> comboModels = comboModelRepository.selectByWarehouseId(warehouseId).stream().filter(x -> x.getCatalogId() == fofoCatalogResponse.getCatalogId()).collect(Collectors.toList());
|
925 |
List<ComboModel> comboModels = comboModelsByCatalogId.get(fofoCatalogResponse.getCatalogId());
|
| 899 |
|
926 |
|
| 900 |
//logger.info("comboModels {}", comboModels);
|
927 |
//logger.info("comboModels {}", comboModels);
|
| 901 |
|
928 |
|
| 902 |
if (comboModels != null && comboModels.size() > 0) {
|
929 |
if (comboModels != null && comboModels.size() > 0) {
|
| 903 |
fofoCatalogResponse.setComboModels(comboModels);
|
930 |
fofoCatalogResponse.setComboModels(comboModels);
|
| Line 944... |
Line 971... |
| 944 |
int itemId = childItem.getInt("itemId_i");
|
971 |
int itemId = childItem.getInt("itemId_i");
|
| 945 |
float sellingPrice = (float) childItem.getDouble("sellingPrice_f");
|
972 |
float sellingPrice = (float) childItem.getDouble("sellingPrice_f");
|
| 946 |
int partnerAvailability = partnerStockAvailabilityMap.get(itemId) == null ? 0 : partnerStockAvailabilityMap.get(itemId);
|
973 |
int partnerAvailability = partnerStockAvailabilityMap.get(itemId) == null ? 0 : partnerStockAvailabilityMap.get(itemId);
|
| 947 |
if (!fofoAvailabilityInfoMap.containsKey(itemId)) {
|
974 |
if (!fofoAvailabilityInfoMap.containsKey(itemId)) {
|
| 948 |
FofoAvailabilityInfo fdi = new FofoAvailabilityInfo();
|
975 |
FofoAvailabilityInfo fdi = new FofoAvailabilityInfo();
|
| 949 |
List<SaholicCISTable> currentAvailability = saholicCISTableRepository.selectByItemWarehouse(itemId, warehouseId);
|
976 |
List<SaholicCISTable> currentAvailability = cisDataByItemId.getOrDefault(itemId, new ArrayList<>());
|
| 950 |
List<SaholicPOItem> poItemAvailability = null;
|
977 |
List<SaholicPOItem> poItemAvailability = null;
|
| 951 |
if (poItemAvailabilityMap != null) {
|
978 |
if (poItemAvailabilityMap != null) {
|
| 952 |
poItemAvailability = poItemAvailabilityMap.get(itemId);
|
979 |
poItemAvailability = poItemAvailabilityMap.get(itemId);
|
| 953 |
}
|
980 |
}
|
| 954 |
|
981 |
|
| Line 989... |
Line 1016... |
| 989 |
} else if (poItemAvailability != null && poItemAvailability.stream().collect(Collectors.summingInt(SaholicPOItem::getUnfulfilledQty)) > 0) {
|
1016 |
} else if (poItemAvailability != null && poItemAvailability.stream().collect(Collectors.summingInt(SaholicPOItem::getUnfulfilledQty)) > 0) {
|
| 990 |
if (currentAvailability != null && poItemAvailability.stream().collect(Collectors.summingInt(SaholicPOItem::getUnfulfilledQty)) + currentAvailability.stream().collect(Collectors.summingInt(SaholicCISTable::getNetAvailability)) <= 0) {
|
1017 |
if (currentAvailability != null && poItemAvailability.stream().collect(Collectors.summingInt(SaholicPOItem::getUnfulfilledQty)) + currentAvailability.stream().collect(Collectors.summingInt(SaholicCISTable::getNetAvailability)) <= 0) {
|
| 991 |
poColor = "grey";
|
1018 |
poColor = "grey";
|
| 992 |
} else {
|
1019 |
} else {
|
| 993 |
poColor = "yellow";
|
1020 |
poColor = "yellow";
|
| 994 |
if (modelColorClass != "green") {
|
1021 |
if (!"green".equals(modelColorClass)) {
|
| 995 |
modelColorClass = poColor;
|
1022 |
modelColorClass = poColor;
|
| 996 |
}
|
1023 |
}
|
| 997 |
}
|
1024 |
}
|
| 998 |
}
|
1025 |
}
|
| 999 |
fdi.setColorClass(poColor);
|
1026 |
fdi.setColorClass(poColor);
|
| Line 1008... |
Line 1035... |
| 1008 |
fdi.setBrand((String) doc.getJSONArray("brand_ss").get(0));
|
1035 |
fdi.setBrand((String) doc.getJSONArray("brand_ss").get(0));
|
| 1009 |
fdi.setCategoryId(doc.getInt("subCategoryId_i"));
|
1036 |
fdi.setCategoryId(doc.getInt("subCategoryId_i"));
|
| 1010 |
fdi.setTagId(childItem.getInt("tagId_i"));
|
1037 |
fdi.setTagId(childItem.getInt("tagId_i"));
|
| 1011 |
fdi.setItem_id(itemId);
|
1038 |
fdi.setItem_id(itemId);
|
| 1012 |
fdi.setCatalog_id(doc.getInt("catalogId_i"));
|
1039 |
fdi.setCatalog_id(doc.getInt("catalogId_i"));
|
| 1013 |
Float cashBack = schemeService.getCatalogSchemeCashBack(fofoId, Arrays.asList(fofoCatalogResponse.getCatalogId())).get(fofoCatalogResponse.getCatalogId());
|
1040 |
Float cashBack = cashbackMap.get(fofoCatalogResponse.getCatalogId());
|
| 1014 |
cashBack = cashBack == null ? 0 : cashBack;
|
1041 |
cashBack = cashBack == null ? 0 : cashBack;
|
| 1015 |
fdi.setCashback(cashBack);
|
1042 |
fdi.setCashback(cashBack);
|
| 1016 |
fdi.setMinBuyQuantity(1);
|
1043 |
fdi.setMinBuyQuantity(1);
|
| 1017 |
if (hotDeal) {
|
1044 |
if (hotDeal) {
|
| 1018 |
if (currentAvailability != null) {
|
1045 |
if (currentAvailability != null) {
|
| Line 1022... |
Line 1049... |
| 1022 |
}
|
1049 |
}
|
| 1023 |
fdi.setPartnerAvailability(partnerAvailability);
|
1050 |
fdi.setPartnerAvailability(partnerAvailability);
|
| 1024 |
} else {
|
1051 |
} else {
|
| 1025 |
// Lets consider that its out of stock
|
1052 |
// Lets consider that its out of stock
|
| 1026 |
fdi.setAvailability(400);
|
1053 |
fdi.setAvailability(400);
|
| 1027 |
Item item = null;
|
- |
|
| 1028 |
try {
|
- |
|
| 1029 |
item = itemRepository.selectById(itemId);
|
1054 |
Item item = itemMap.get(itemId);
|
| 1030 |
} catch (Exception e) {
|
- |
|
| 1031 |
e.printStackTrace();
|
- |
|
| 1032 |
continue;
|
- |
|
| 1033 |
}
|
- |
|
| 1034 |
// In case its tampered glass moq should be
|
1055 |
// In case its tampered glass moq should be
|
| 1035 |
if (item.getCategoryId() == 10020) {
|
1056 |
if (item != null && item.getCategoryId() == 10020) {
|
| 1036 |
fdi.setMinBuyQuantity(5);
|
1057 |
fdi.setMinBuyQuantity(5);
|
| 1037 |
}
|
1058 |
}
|
| 1038 |
}
|
1059 |
}
|
| 1039 |
fdi.setQuantityStep(1);
|
1060 |
fdi.setQuantityStep(1);
|
| 1040 |
fdi.setMaxQuantity(Math.min(fdi.getAvailability(), 400));
|
1061 |
fdi.setMaxQuantity(Math.min(fdi.getAvailability(), 400));
|
| Line 1081... |
Line 1102... |
| 1081 |
List<FofoCatalogResponse> dealResponse = new ArrayList<>();
|
1102 |
List<FofoCatalogResponse> dealResponse = new ArrayList<>();
|
| 1082 |
List<Integer> tagIds = Arrays.asList(4);
|
1103 |
List<Integer> tagIds = Arrays.asList(4);
|
| 1083 |
|
1104 |
|
| 1084 |
Map<Integer, TagListing> itemTagListingMap = tagListingRepository.selectByItemIdsAndTagIds(itemFilter.keySet(), new HashSet<>(tagIds)).stream().collect(Collectors.toMap(x -> x.getItemId(), x -> x));
|
1105 |
Map<Integer, TagListing> itemTagListingMap = tagListingRepository.selectByItemIdsAndTagIds(itemFilter.keySet(), new HashSet<>(tagIds)).stream().collect(Collectors.toMap(x -> x.getItemId(), x -> x));
|
| 1085 |
|
1106 |
|
| - |
|
1107 |
// Pre-fetch all items (batch query instead of N+1)
|
| - |
|
1108 |
Map<Integer, Item> itemMap = itemRepository.selectByIds(itemFilter.keySet()).stream()
|
| - |
|
1109 |
.collect(Collectors.toMap(Item::getId, x -> x));
|
| - |
|
1110 |
|
| 1086 |
for (int i = 0; i < docs.length(); i++) {
|
1111 |
for (int i = 0; i < docs.length(); i++) {
|
| 1087 |
Map<Integer, FofoAvailabilityInfo> fofoAvailabilityInfoMap = new HashMap<>();
|
1112 |
Map<Integer, FofoAvailabilityInfo> fofoAvailabilityInfoMap = new HashMap<>();
|
| 1088 |
JSONObject doc = docs.getJSONObject(i);
|
1113 |
JSONObject doc = docs.getJSONObject(i);
|
| 1089 |
|
1114 |
|
| 1090 |
for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
|
1115 |
for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
|
| Line 1112... |
Line 1137... |
| 1112 |
fdi.setMop((float) tl.getMrp());
|
1137 |
fdi.setMop((float) tl.getMrp());
|
| 1113 |
fdi.setColor(childItem.has("color_s") ? childItem.getString("color_s") : "");
|
1138 |
fdi.setColor(childItem.has("color_s") ? childItem.getString("color_s") : "");
|
| 1114 |
fdi.setTagId(childItem.getInt("tagId_i"));
|
1139 |
fdi.setTagId(childItem.getInt("tagId_i"));
|
| 1115 |
fdi.setItem_id(itemId);
|
1140 |
fdi.setItem_id(itemId);
|
| 1116 |
fdi.setCatalog_id(doc.getInt("catalogId_i"));
|
1141 |
fdi.setCatalog_id(doc.getInt("catalogId_i"));
|
| 1117 |
Item item = itemRepository.selectById(itemId);
|
1142 |
Item item = itemMap.get(itemId);
|
| 1118 |
// In case its tampered glass moq should be 5
|
1143 |
// In case its tampered glass moq should be 5
|
| 1119 |
if (item.getCategoryId() == 10020) {
|
1144 |
if (item != null && item.getCategoryId() == 10020) {
|
| 1120 |
fdi.setMinBuyQuantity(10);
|
1145 |
fdi.setMinBuyQuantity(10);
|
| 1121 |
} else {
|
1146 |
} else {
|
| 1122 |
fdi.setMinBuyQuantity(1);
|
1147 |
fdi.setMinBuyQuantity(1);
|
| 1123 |
}
|
1148 |
}
|
| 1124 |
fdi.setAvailability(itemFilter.get(itemId));
|
1149 |
fdi.setAvailability(itemFilter.get(itemId));
|