| Line 186... |
Line 186... |
| 186 |
|
186 |
|
| 187 |
@RequestMapping(value = "/fofo/bucket", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
187 |
@RequestMapping(value = "/fofo/bucket", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 188 |
public ResponseEntity<?> getBucketDetails(HttpServletRequest request, @RequestParam int id)
|
188 |
public ResponseEntity<?> getBucketDetails(HttpServletRequest request, @RequestParam int id)
|
| 189 |
throws ProfitMandiBusinessException {
|
189 |
throws ProfitMandiBusinessException {
|
| 190 |
List<ItemQuantityPojo> iqPojo = itemBucketService.getBucketDetails(id);
|
190 |
List<ItemQuantityPojo> iqPojo = itemBucketService.getBucketDetails(id);
|
| - |
|
191 |
Map<Integer, Integer> itemIdsQtyMap = iqPojo.stream()
|
| 191 |
Map<Integer, Integer> itemIdsQtyMap = iqPojo.stream().collect(Collectors.toMap(x->x.getItemId(), x->x.getQuantity()));
|
192 |
.collect(Collectors.toMap(x -> x.getItemId(), x -> x.getQuantity()));
|
| 192 |
Set<Integer> catalogIds = itemRepository.selectByIds(itemIdsQtyMap.keySet()).stream().map(x->x.getCatalogItemId()).collect(Collectors.toSet());
|
193 |
Set<Integer> catalogIds = itemRepository.selectByIds(itemIdsQtyMap.keySet()).stream()
|
| - |
|
194 |
.map(x -> x.getCatalogItemId()).collect(Collectors.toSet());
|
| 193 |
RestClient rc = new RestClient();
|
195 |
RestClient rc = new RestClient();
|
| 194 |
Map<String, String> params = new HashMap<>();
|
196 |
Map<String, String> params = new HashMap<>();
|
| 195 |
List<String> mandatoryQ = new ArrayList<>();
|
197 |
List<String> mandatoryQ = new ArrayList<>();
|
| - |
|
198 |
mandatoryQ.add(
|
| 196 |
mandatoryQ.add(String.format("+catalogId_i:(%s) +{!parent which=\"id:catalog*\"}", StringUtils.join(catalogIds, " ")));
|
199 |
String.format("+catalogId_i:(%s) +{!parent which=\"id:catalog*\"}", StringUtils.join(catalogIds, " ")));
|
| 197 |
params.put("start", "0");
|
200 |
params.put("start", "0");
|
| 198 |
params.put("rows", "100");
|
201 |
params.put("rows", "100");
|
| 199 |
params.put("q", StringUtils.join(mandatoryQ, " "));
|
202 |
params.put("q", StringUtils.join(mandatoryQ, " "));
|
| 200 |
params.put("fl", "*, [child parentFilter=id:catalog*]");
|
203 |
params.put("fl", "*, [child parentFilter=id:catalog*]");
|
| 201 |
|
204 |
|
| Line 206... |
Line 209... |
| 206 |
} catch (HttpHostConnectException e) {
|
209 |
} catch (HttpHostConnectException e) {
|
| 207 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
210 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
| 208 |
}
|
211 |
}
|
| 209 |
JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
|
212 |
JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
|
| 210 |
JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
|
213 |
JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
|
| 211 |
List<FofoCatalogResponse> dealResponse = getCatalogSingleSkuResponse(docs, false);
|
214 |
List<FofoCatalogResponse> dealResponse = getCatalogSingleSkuResponse(docs, itemIdsQtyMap, false);
|
| 212 |
dealResponse = dealResponse.stream()
|
215 |
dealResponse = dealResponse.stream()
|
| 213 |
//.filter(x->itemIdsQtyMap.keySet().contains((int)(x.getItems().get(0).getItem_id())))
|
216 |
// .filter(x->itemIdsQtyMap.keySet().contains((int)(x.getItems().get(0).getItem_id())))
|
| 214 |
.map(x->{
|
217 |
.map(x -> {
|
| 215 |
FofoAvailabilityInfo fai = x.getItems().get(0);
|
218 |
FofoAvailabilityInfo fai = x.getItems().get(0);
|
| 216 |
fai.setAvailability(5);
|
219 |
fai.setAvailability(5);
|
| 217 |
return x;
|
220 |
return x;
|
| 218 |
}).collect(Collectors.toList());
|
221 |
}).collect(Collectors.toList());
|
| 219 |
Bucket bucket = itemBucketService.getBuckets(Optional.of(true)).get(0);
|
222 |
Bucket bucket = itemBucketService.getBuckets(Optional.of(true)).get(0);
|
| Line 587... |
Line 590... |
| 587 |
|
590 |
|
| 588 |
for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
|
591 |
for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
|
| 589 |
JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
|
592 |
JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
|
| 590 |
int itemId = childItem.getInt("itemId_i");
|
593 |
int itemId = childItem.getInt("itemId_i");
|
| 591 |
TagListing tl = itemTagListingMap.get(itemId);
|
594 |
TagListing tl = itemTagListingMap.get(itemId);
|
| 592 |
if(tl==null) {
|
595 |
if (tl == null) {
|
| 593 |
logger.warn("Could not find item id {}", itemId);
|
596 |
logger.warn("Could not find item id {}", itemId);
|
| 594 |
continue;
|
597 |
continue;
|
| 595 |
}
|
598 |
}
|
| 596 |
if (hotDeal) {
|
599 |
if (hotDeal) {
|
| 597 |
if (!tl.isHotDeals()) {
|
600 |
if (!tl.isHotDeals()) {
|
| Line 650... |
Line 653... |
| 650 |
}
|
653 |
}
|
| 651 |
return dealResponse;
|
654 |
return dealResponse;
|
| 652 |
|
655 |
|
| 653 |
}
|
656 |
}
|
| 654 |
|
657 |
|
| 655 |
private List<FofoCatalogResponse> getCatalogSingleSkuResponse(JSONArray docs, boolean hotDeal)
|
658 |
private List<FofoCatalogResponse> getCatalogSingleSkuResponse(JSONArray docs, Map<Integer, Integer> itemFilter,
|
| 656 |
throws ProfitMandiBusinessException {
|
659 |
boolean hotDeal) throws ProfitMandiBusinessException {
|
| 657 |
Map<Integer, TagListing> itemTagListingMap = null;
|
660 |
Map<Integer, TagListing> itemTagListingMap = null;
|
| 658 |
List<FofoCatalogResponse> dealResponse = new ArrayList<>();
|
661 |
List<FofoCatalogResponse> dealResponse = new ArrayList<>();
|
| 659 |
List<Integer> tagIds = Arrays.asList(4);
|
662 |
List<Integer> tagIds = Arrays.asList(4);
|
| 660 |
if (docs.length() > 0) {
|
- |
|
| 661 |
HashSet<Integer> itemsSet = new HashSet<>();
|
- |
|
| 662 |
for (int i = 0; i < docs.length(); i++) {
|
- |
|
| 663 |
JSONObject doc = docs.getJSONObject(i);
|
- |
|
| 664 |
for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
|
- |
|
| 665 |
JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
|
- |
|
| 666 |
int itemId = childItem.getInt("itemId_i");
|
- |
|
| 667 |
itemsSet.add(itemId);
|
- |
|
| 668 |
}
|
- |
|
| 669 |
}
|
663 |
|
| 670 |
itemTagListingMap = tagListingRepository.selectByItemIdsAndTagIds(itemsSet, new HashSet<>(tagIds)).stream()
|
664 |
itemTagListingMap = tagListingRepository.selectByItemIdsAndTagIds(itemFilter.keySet(), new HashSet<>(tagIds))
|
| 671 |
.collect(Collectors.toMap(x -> x.getItemId(), x -> x));
|
665 |
.stream().collect(Collectors.toMap(x -> x.getItemId(), x -> x));
|
| 672 |
}
|
- |
|
| 673 |
|
666 |
|
| 674 |
for (int i = 0; i < docs.length(); i++) {
|
667 |
for (int i = 0; i < docs.length(); i++) {
|
| 675 |
Map<Integer, FofoAvailabilityInfo> fofoAvailabilityInfoMap = new HashMap<>();
|
668 |
Map<Integer, FofoAvailabilityInfo> fofoAvailabilityInfoMap = new HashMap<>();
|
| 676 |
JSONObject doc = docs.getJSONObject(i);
|
669 |
JSONObject doc = docs.getJSONObject(i);
|
| 677 |
|
670 |
|
| 678 |
for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
|
671 |
for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
|
| 679 |
JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
|
672 |
JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
|
| 680 |
int itemId = childItem.getInt("itemId_i");
|
673 |
int itemId = childItem.getInt("itemId_i");
|
| 681 |
TagListing tl = itemTagListingMap.get(itemId);
|
674 |
TagListing tl = itemTagListingMap.get(itemId);
|
| - |
|
675 |
if(tl==null) {
|
| - |
|
676 |
continue;
|
| - |
|
677 |
}
|
| 682 |
if (hotDeal) {
|
678 |
if (hotDeal) {
|
| 683 |
if (!tl.isHotDeals()) {
|
679 |
if (!tl.isHotDeals()) {
|
| 684 |
continue;
|
680 |
continue;
|
| 685 |
}
|
681 |
}
|
| 686 |
}
|
682 |
}
|