Subversion Repositories SmartDukaan

Rev

Rev 37250 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 37250 Rev 37260
Line 238... Line 238...
238
        params.put("fl", "*, [child parentFilter=id:catalog*]");
238
        params.put("fl", "*, [child parentFilter=id:catalog*]");
239
 
239
 
240
        params.put("wt", "json");
240
        params.put("wt", "json");
241
        int fofoId = userAccountRepository.getUserCart((int) request.getAttribute("userId")).getUserId();
241
        int fofoId = userAccountRepository.getUserCart((int) request.getAttribute("userId")).getUserId();
242
        JSONArray docs = partnerSolrClient.selectDocs(params, fofoId);
242
        JSONArray docs = partnerSolrClient.selectDocs(params, fofoId);
243
        List<FofoCatalogResponse> dealResponse = getCatalogSingleSkuResponse(docs, itemIdsQtyMap, false);
243
        List<FofoCatalogResponse> dealResponse = getCatalogSingleSkuResponse(docs, itemIdsQtyMap);
244
 
244
 
245
        Bucket bucket = itemBucketService.getBuckets(Optional.of(true)).stream().filter(x -> x.getId() == id).collect(Collectors.toList()).get(0);
245
        Bucket bucket = itemBucketService.getBuckets(Optional.of(true)).stream().filter(x -> x.getId() == id).collect(Collectors.toList()).get(0);
246
        bucket.setFofoCatalogResponses(dealResponse);
246
        bucket.setFofoCatalogResponses(dealResponse);
247
        return responseSender.ok(bucket);
247
        return responseSender.ok(bucket);
248
    }
248
    }
Line 269... Line 269...
269
        params.put("q", StringUtils.join(mandatoryQ, " "));
269
        params.put("q", StringUtils.join(mandatoryQ, " "));
270
        params.put("fl", "*, [child parentFilter=id:catalog*]");
270
        params.put("fl", "*, [child parentFilter=id:catalog*]");
271
 
271
 
272
        params.put("wt", "json");
272
        params.put("wt", "json");
273
        JSONArray docs = partnerSolrClient.selectDocs(params, fofoId);
273
        JSONArray docs = partnerSolrClient.selectDocs(params, fofoId);
274
        List<FofoCatalogResponse> dealResponse = getCatalogSingleSkuResponse(docs, itemIdsQtyMap, false);
274
        List<FofoCatalogResponse> dealResponse = getCatalogSingleSkuResponse(docs, itemIdsQtyMap);
275
 
275
 
276
        return responseSender.ok(dealResponse);
276
        return responseSender.ok(dealResponse);
277
    }
277
    }
278
 
278
 
279
    @RequestMapping(value = "/suggestedPo/status", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
279
    @RequestMapping(value = "/suggestedPo/status", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
Line 362... Line 362...
362
        JSONArray docs = partnerSolrClient.selectDocs(params, userInfo.getRetailerId());
362
        JSONArray docs = partnerSolrClient.selectDocs(params, userInfo.getRetailerId());
363
        return responseSender.ok(this.getCatalogResponse(docs, false, userInfo.getRetailerId()).stream().filter(x -> x.isInStock()).collect(Collectors.toList()));
363
        return responseSender.ok(this.getCatalogResponse(docs, false, userInfo.getRetailerId()).stream().filter(x -> x.isInStock()).collect(Collectors.toList()));
364
    }
364
    }
365
 
365
 
366
    @ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
366
    @ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
-
 
367
    /**
-
 
368
     * Categories present among today's active hot deals (Solr facet over the curated
-
 
369
     * models), for the hot-deals page filter chips: [{"id": 3, "count": 4}, ...].
-
 
370
     */
-
 
371
    @RequestMapping(value = "/fofo/hotDeals/categories", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
-
 
372
    public ResponseEntity<?> getHotDealCategories(HttpServletRequest request) throws Exception {
-
 
373
        List<Integer> hotDealCatalogIds = modelHotDealRepository.selectAllActive(java.time.LocalDate.now())
-
 
374
                .stream().map(com.spice.profitmandi.dao.entity.catalog.ModelHotDeal::getCatalogItemId)
-
 
375
                .distinct().collect(Collectors.toList());
-
 
376
        List<Map<String, Object>> categories = new ArrayList<>();
-
 
377
        for (Map.Entry<Integer, Integer> entry : solrService.getHotDealCategoryFacet(hotDealCatalogIds).entrySet()) {
-
 
378
            Map<String, Object> category = new HashMap<>();
-
 
379
            category.put("id", entry.getKey());
-
 
380
            category.put("count", entry.getValue());
-
 
381
            categories.add(category);
-
 
382
        }
-
 
383
        return responseSender.ok(categories);
-
 
384
    }
-
 
385
 
367
    @RequestMapping(value = "/fofo", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
386
    @RequestMapping(value = "/fofo", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
368
    public ResponseEntity<?> getFofo(HttpServletRequest request, @RequestParam(value = "categoryId", required = false, defaultValue = "3") String categoryId, @RequestParam(value = "offset") int offset,
387
    public ResponseEntity<?> getFofo(HttpServletRequest request, @RequestParam(value = "categoryId", required = false, defaultValue = "3") String categoryId, @RequestParam(value = "offset") int offset,
369
         @RequestParam(value = "limit") int limit, @RequestParam(value = "sort", required = false) String sort, @RequestParam(value = "brand", required = false) String brand, @RequestParam(value = "subCategoryId", required = false) int subCategoryId, @RequestParam(value = "q", required = false) String queryTerm, @RequestParam(value = "hotDeal", required = false) boolean hotDeal, @RequestParam(value = "endPoint", required = false) String endPoint,@RequestParam(value = "group", required = false) boolean group) throws Throwable {
388
         @RequestParam(value = "limit") int limit, @RequestParam(value = "sort", required = false) String sort, @RequestParam(value = "brand", required = false) String brand, @RequestParam(value = "subCategoryId", required = false, defaultValue = "0") int subCategoryId, @RequestParam(value = "q", required = false) String queryTerm, @RequestParam(value = "hotDeal", required = false) boolean hotDeal, @RequestParam(value = "endPoint", required = false) String endPoint,@RequestParam(value = "group", required = false) boolean group) throws Throwable {
370
        // Band-aid for URL '+' decode issue on brand names.
389
        // Band-aid for URL '+' decode issue on brand names.
371
        // Front-end sends `brand=Ai+`. Depending on where along the request path the
390
        // Front-end sends `brand=Ai+`. Depending on where along the request path the
372
        // '+' is decoded, the servlet may receive "Ai " (trailing space) or just "Ai"
391
        // '+' is decoded, the servlet may receive "Ai " (trailing space) or just "Ai"
373
        // (plus dropped entirely by the SPA before the request goes out).
392
        // (plus dropped entirely by the SPA before the request goes out).
374
        // Strategy: if the received value doesn't exist as a real brand in catalog.brand,
393
        // Strategy: if the received value doesn't exist as a real brand in catalog.brand,
Line 402... Line 421...
402
        if (endPoint != null && !endPoint.trim().isEmpty()) {
421
        if (endPoint != null && !endPoint.trim().isEmpty()) {
403
            WebListing webListing = webListingRepository.selectByUrl(endPoint);
422
            WebListing webListing = webListingRepository.selectByUrl(endPoint);
404
            dealResponse = this.getDealResponses(userInfo, fs, webListing, offset, limit);
423
            dealResponse = this.getDealResponses(userInfo, fs, webListing, offset, limit);
405
 
424
 
406
        } else if (hotDeal) {
425
        } else if (hotDeal) {
407
            // Hot deals are sourced from catalog.model_hot_deal (date-windowed, curated),
426
            // Hot deals are sourced from catalog.model_hot_deal (date-windowed, curated);
-
 
427
            // Solr's hot_deal_b derives from the same table but is resolved here so the
408
            // not the legacy Solr hot_deal_b flag
428
            // listing does not depend on the last re-index
409
            List<Integer> hotDealCatalogIds = modelHotDealRepository.selectAllActive(java.time.LocalDate.now())
429
            List<Integer> hotDealCatalogIds = modelHotDealRepository.selectAllActive(java.time.LocalDate.now())
410
                    .stream().map(com.spice.profitmandi.dao.entity.catalog.ModelHotDeal::getCatalogItemId)
430
                    .stream().map(com.spice.profitmandi.dao.entity.catalog.ModelHotDeal::getCatalogItemId)
411
                    .distinct().collect(Collectors.toList());
431
                    .distinct().collect(Collectors.toList());
412
            if (hotDealCatalogIds.isEmpty()) {
432
            if (hotDealCatalogIds.isEmpty()) {
413
                dealResponse = new ArrayList<>();
433
                dealResponse = new ArrayList<>();
414
            } else {
434
            } else {
-
 
435
                // Cross-category by default; a category chip on the page sends categoryId
-
 
436
                // explicitly, and only then does it narrow the hot-deal listing
-
 
437
                String explicitCategory = request.getParameter("categoryId") != null ? categoryId : null;
415
                dealResponse = this.getCatalogResponse(
438
                dealResponse = this.getCatalogResponse(
416
                        solrService.getSolrDocs(queryTerm, categoryId, offset, limit, sort, brand, subCategoryId, false, group, true,
439
                        solrService.getSolrDocs(queryTerm, explicitCategory, offset, limit, sort, brand, subCategoryId, false, group, true,
417
                                brandsService.restrictedBrands(userInfo.getRetailerId()), hotDealCatalogIds), false, userInfo.getRetailerId());
440
                                brandsService.restrictedBrands(userInfo.getRetailerId()), hotDealCatalogIds), false, userInfo.getRetailerId());
418
            }
441
            }
419
        } else {
442
        } else {
420
 
443
 
421
            dealResponse = this.getCatalogResponse(
444
            dealResponse = this.getCatalogResponse(
Line 1267... Line 1290...
1267
        return dealResponse;
1290
        return dealResponse;
1268
 
1291
 
1269
    }
1292
    }
1270
 
1293
 
1271
    private List<FofoCatalogResponse> getCatalogSingleSkuResponse(JSONArray
1294
    private List<FofoCatalogResponse> getCatalogSingleSkuResponse(JSONArray
1272
                                                                          docs, Map<Integer, Integer> itemFilter, boolean hotDeal) throws ProfitMandiBusinessException {
1295
                                                                          docs, Map<Integer, Integer> itemFilter) throws ProfitMandiBusinessException {
1273
        List<FofoCatalogResponse> dealResponse = new ArrayList<>();
1296
        List<FofoCatalogResponse> dealResponse = new ArrayList<>();
1274
        List<Integer> tagIds = Arrays.asList(4);
1297
        List<Integer> tagIds = Arrays.asList(4);
1275
 
1298
 
1276
        Map<Integer, TagListing> itemTagListingMap = tagListingRepository.selectByItemIdsAndTagIds(itemFilter.keySet(), new HashSet<>(tagIds)).stream().collect(Collectors.toMap(x -> x.getItemId(), x -> x));
1299
        Map<Integer, TagListing> itemTagListingMap = tagListingRepository.selectByItemIdsAndTagIds(itemFilter.keySet(), new HashSet<>(tagIds)).stream().collect(Collectors.toMap(x -> x.getItemId(), x -> x));
1277
 
1300
 
Line 1288... Line 1311...
1288
                int itemId = childItem.getInt("itemId_i");
1311
                int itemId = childItem.getInt("itemId_i");
1289
                TagListing tl = itemTagListingMap.get(itemId);
1312
                TagListing tl = itemTagListingMap.get(itemId);
1290
                if (tl == null) {
1313
                if (tl == null) {
1291
                    continue;
1314
                    continue;
1292
                }
1315
                }
1293
                if (hotDeal) {
-
 
1294
                    if (!tl.isHotDeals()) {
-
 
1295
                        continue;
-
 
1296
                    }
-
 
1297
                }
-
 
1298
                float sellingPrice = (float) childItem.getDouble("sellingPrice_f");
1316
                float sellingPrice = (float) childItem.getDouble("sellingPrice_f");
1299
                if (fofoAvailabilityInfoMap.containsKey(itemId)) {
1317
                if (fofoAvailabilityInfoMap.containsKey(itemId)) {
1300
                    if (fofoAvailabilityInfoMap.get(itemId).getSellingPrice() > sellingPrice) {
1318
                    if (fofoAvailabilityInfoMap.get(itemId).getSellingPrice() > sellingPrice) {
1301
                        fofoAvailabilityInfoMap.get(itemId).setSellingPrice(sellingPrice);
1319
                        fofoAvailabilityInfoMap.get(itemId).setSellingPrice(sellingPrice);
1302
                        fofoAvailabilityInfoMap.get(itemId).setMop((float) childItem.getDouble("mop_f"));
1320
                        fofoAvailabilityInfoMap.get(itemId).setMop((float) childItem.getDouble("mop_f"));