Subversion Repositories SmartDukaan

Rev

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

Rev 37115 Rev 37144
Line 108... Line 108...
108
 
108
 
109
    @Autowired
109
    @Autowired
110
    com.spice.profitmandi.web.services.SolrService webSolrService;
110
    com.spice.profitmandi.web.services.SolrService webSolrService;
111
 
111
 
112
    @Autowired
112
    @Autowired
-
 
113
    private com.spice.profitmandi.web.services.PartnerSolrClient partnerSolrClient;
-
 
114
 
-
 
115
    @Autowired
113
    PinelabsAffordabilityService pinelabsAffordabilityService;
116
    PinelabsAffordabilityService pinelabsAffordabilityService;
114
 
117
 
115
    @Autowired
118
    @Autowired
116
    PinelabsDeviceService pinelabsDeviceService;
119
    PinelabsDeviceService pinelabsDeviceService;
117
 
120
 
Line 220... Line 223...
220
        params.put("rows", "100");
223
        params.put("rows", "100");
221
        params.put("q", StringUtils.join(mandatoryQ, " "));
224
        params.put("q", StringUtils.join(mandatoryQ, " "));
222
        params.put("fl", "*, [child parentFilter=id:catalog*]");
225
        params.put("fl", "*, [child parentFilter=id:catalog*]");
223
 
226
 
224
        params.put("wt", "json");
227
        params.put("wt", "json");
225
        String response = null;
-
 
226
        try {
-
 
227
            response = restClient.get(SchemeType.HTTP, solrUrl, 8984, "solr/demo/select", params);
228
        int fofoId = userAccountRepository.getUserCart((int) request.getAttribute("userId")).getUserId();
228
        } catch (HttpHostConnectException e) {
-
 
229
            throw new ProfitMandiBusinessException("", "", "Could not connect to host");
-
 
230
        }
-
 
231
        JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
-
 
232
        JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
229
        JSONArray docs = partnerSolrClient.selectDocs(params, fofoId);
233
        List<FofoCatalogResponse> dealResponse = getCatalogSingleSkuResponse(docs, itemIdsQtyMap, false);
230
        List<FofoCatalogResponse> dealResponse = getCatalogSingleSkuResponse(docs, itemIdsQtyMap, false);
234
 
231
 
235
        Bucket bucket = itemBucketService.getBuckets(Optional.of(true)).stream().filter(x -> x.getId() == id).collect(Collectors.toList()).get(0);
232
        Bucket bucket = itemBucketService.getBuckets(Optional.of(true)).stream().filter(x -> x.getId() == id).collect(Collectors.toList()).get(0);
236
        bucket.setFofoCatalogResponses(dealResponse);
233
        bucket.setFofoCatalogResponses(dealResponse);
237
        return responseSender.ok(bucket);
234
        return responseSender.ok(bucket);
Line 258... Line 255...
258
        params.put("rows", "100");
255
        params.put("rows", "100");
259
        params.put("q", StringUtils.join(mandatoryQ, " "));
256
        params.put("q", StringUtils.join(mandatoryQ, " "));
260
        params.put("fl", "*, [child parentFilter=id:catalog*]");
257
        params.put("fl", "*, [child parentFilter=id:catalog*]");
261
 
258
 
262
        params.put("wt", "json");
259
        params.put("wt", "json");
263
        String response = null;
-
 
264
        try {
-
 
265
            response = restClient.get(SchemeType.HTTP, solrUrl, 8984, "solr/demo/select", params);
-
 
266
        } catch (HttpHostConnectException e) {
-
 
267
            throw new ProfitMandiBusinessException("", "", "Could not connect to host");
-
 
268
        }
-
 
269
        JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
-
 
270
        JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
260
        JSONArray docs = partnerSolrClient.selectDocs(params, fofoId);
271
        List<FofoCatalogResponse> dealResponse = getCatalogSingleSkuResponse(docs, itemIdsQtyMap, false);
261
        List<FofoCatalogResponse> dealResponse = getCatalogSingleSkuResponse(docs, itemIdsQtyMap, false);
272
 
262
 
273
        return responseSender.ok(dealResponse);
263
        return responseSender.ok(dealResponse);
274
    }
264
    }
275
 
265
 
Line 353... Line 343...
353
 
343
 
354
        params.put("q", StringUtils.join(mandatoryQ, " "));
344
        params.put("q", StringUtils.join(mandatoryQ, " "));
355
        params.put("fl", "*, [child parentFilter=id:catalog* childFilter=active_b:true ]");
345
        params.put("fl", "*, [child parentFilter=id:catalog* childFilter=active_b:true ]");
356
        params.put("wt", "json");
346
        params.put("wt", "json");
357
        params.put("rows", similarCatalogIds.size() + "");
347
        params.put("rows", similarCatalogIds.size() + "");
358
        try {
-
 
359
            String response = restClient.get(SchemeType.HTTP, solrUrl, 8984, "solr/demo/select", params);
-
 
360
            JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
-
 
361
            JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
348
        JSONArray docs = partnerSolrClient.selectDocs(params, userInfo.getRetailerId());
362
            return responseSender.ok(this.getCatalogResponse(docs, false, userInfo.getRetailerId()).stream().filter(x -> x.isInStock()).collect(Collectors.toList()));
349
        return responseSender.ok(this.getCatalogResponse(docs, false, userInfo.getRetailerId()).stream().filter(x -> x.isInStock()).collect(Collectors.toList()));
363
        } catch (HttpHostConnectException e) {
-
 
364
            throw new ProfitMandiBusinessException("", "", "Could not connect to host");
-
 
365
        }
-
 
366
    }
350
    }
367
 
351
 
368
    @ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
352
    @ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
369
    @RequestMapping(value = "/fofo", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
353
    @RequestMapping(value = "/fofo", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
370
    public ResponseEntity<?> getFofo(HttpServletRequest request, @RequestParam(value = "categoryId", required = false, defaultValue = "3") String categoryId, @RequestParam(value = "offset") int offset,
354
    public ResponseEntity<?> getFofo(HttpServletRequest request, @RequestParam(value = "categoryId", required = false, defaultValue = "3") String categoryId, @RequestParam(value = "offset") int offset,
Line 382... Line 366...
382
            dealResponse = this.getDealResponses(userInfo, fs, webListing, offset, limit);
366
            dealResponse = this.getDealResponses(userInfo, fs, webListing, offset, limit);
383
 
367
 
384
        } else {
368
        } else {
385
 
369
 
386
            dealResponse = this.getCatalogResponse(
370
            dealResponse = this.getCatalogResponse(
387
                    solrService.getSolrDocs(queryTerm, categoryId, offset, limit, sort, brand, subCategoryId, hotDeal, group,true), hotDeal, userInfo.getRetailerId());
371
                    solrService.getSolrDocs(queryTerm, categoryId, offset, limit, sort, brand, subCategoryId, hotDeal, group, true,
-
 
372
                            brandsService.restrictedBrands(userInfo.getRetailerId())), hotDeal, userInfo.getRetailerId());
388
        }
373
        }
389
 
374
 
390
        Map<Integer, List<Integer>> similarModelMap = dealResponse.stream().filter(x -> x.getSimilarModelIds() != null && x.getSimilarModelIds().size() > 0)
375
        Map<Integer, List<Integer>> similarModelMap = dealResponse.stream().filter(x -> x.getSimilarModelIds() != null && x.getSimilarModelIds().size() > 0)
391
                .collect(Collectors.toMap(x -> x.getCatalogId(), x -> x.getSimilarModelIds()));
376
                .collect(Collectors.toMap(x -> x.getCatalogId(), x -> x.getSimilarModelIds()));
392
        Set<Integer> similarModelIds = similarModelMap.values().stream().flatMap(x -> x.stream()).collect(Collectors.toSet());
377
        Set<Integer> similarModelIds = similarModelMap.values().stream().flatMap(x -> x.stream()).collect(Collectors.toSet());
Line 421... Line 406...
421
        params.put("q", StringUtils.join(mandatoryQ, " "));
406
        params.put("q", StringUtils.join(mandatoryQ, " "));
422
        params.put("fl", "*, [child parentFilter=id:catalog* childFilter=active_b:true ]");
407
        params.put("fl", "*, [child parentFilter=id:catalog* childFilter=active_b:true ]");
423
        params.put("wt", "json");
408
        params.put("wt", "json");
424
        params.put("rows", catalogIds.size() + "");
409
        params.put("rows", catalogIds.size() + "");
425
 
410
 
426
        String response = restClient.get(SchemeType.HTTP, solrUrl, 8984, "solr/demo/select", params);
-
 
427
        JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
-
 
428
        JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
411
        JSONArray docs = partnerSolrClient.selectDocs(params, fofoStore.getId());
429
        int warehouseId = fofoStore.getWarehouseId();
412
        int warehouseId = fofoStore.getWarehouseId();
430
        Map<Integer, List<SaholicPOItem>> poItemAvailabilityMap = saholicInventoryService.getSaholicPOItems().get(warehouseId);
413
        Map<Integer, List<SaholicPOItem>> poItemAvailabilityMap = saholicInventoryService.getSaholicPOItems().get(warehouseId);
431
 
414
 
432
        // Pre-fetch all itemIds for batch CIS query
415
        // Pre-fetch all itemIds for batch CIS query
433
        List<Integer> allItemIds = new ArrayList<>();
416
        List<Integer> allItemIds = new ArrayList<>();
Line 576... Line 559...
576
        }
559
        }
577
 
560
 
578
        dealBrandsResponse = new Gson().fromJson(response, new TypeToken<List<DealBrands>>() {
561
        dealBrandsResponse = new Gson().fromJson(response, new TypeToken<List<DealBrands>>() {
579
        }.getType());
562
        }.getType());
580
 
563
 
-
 
564
        UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
-
 
565
        List<String> restrictedBrands = brandsService.restrictedBrands(userInfo.getRetailerId());
-
 
566
        dealBrandsResponse = dealBrandsResponse.stream().filter(x -> !restrictedBrands.contains(x.getBrand()))
-
 
567
                .collect(Collectors.toList());
-
 
568
 
581
        return responseSender.ok(dealBrandsResponse);
569
        return responseSender.ok(dealBrandsResponse);
582
    }
570
    }
583
 
571
 
584
    @RequestMapping(value = ProfitMandiConstants.URL_UNIT_DEAL, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
572
    @RequestMapping(value = ProfitMandiConstants.URL_UNIT_DEAL, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
585
    @ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
573
    @ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
Line 630... Line 618...
630
 
618
 
631
            params.put("q", StringUtils.join(mandatoryQ, " "));
619
            params.put("q", StringUtils.join(mandatoryQ, " "));
632
            params.put("fl", "*, [child parentFilter=id:catalog*]");
620
            params.put("fl", "*, [child parentFilter=id:catalog*]");
633
            params.put("sort", "rank_i asc, create_s desc");
621
            params.put("sort", "rank_i asc, create_s desc");
634
            params.put("wt", "json");
622
            params.put("wt", "json");
635
            String response = null;
-
 
636
            try {
-
 
637
                response = restClient.get(SchemeType.HTTP, solrUrl, 8984, "solr/demo/select", params);
-
 
638
            } catch (HttpHostConnectException e) {
-
 
639
                throw new ProfitMandiBusinessException("", "", "Could not connect to host");
-
 
640
            }
-
 
641
            JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
-
 
642
            JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
623
            JSONArray docs = partnerSolrClient.selectDocs(params, userInfo.getRetailerId());
643
            dealResponse = getCatalogResponse(docs, false, userInfo.getRetailerId());
624
            dealResponse = getCatalogResponse(docs, false, userInfo.getRetailerId());
644
        } else {
625
        } else {
645
            return responseSender.badRequest(
626
            return responseSender.badRequest(
646
                    new ProfitMandiBusinessException("Retailer id", userInfo.getUserId(), "NOT_FOFO_RETAILER"));
627
                    new ProfitMandiBusinessException("Retailer id", userInfo.getUserId(), "NOT_FOFO_RETAILER"));
647
        }
628
        }
Line 681... Line 662...
681
                                       @RequestParam(required = false, defaultValue = "0") int categoryId) throws Exception {
662
                                       @RequestParam(required = false, defaultValue = "0") int categoryId) throws Exception {
682
        UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
663
        UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
683
        logger.info("userInfo [{}]", userInfo);
664
        logger.info("userInfo [{}]", userInfo);
684
 
665
 
685
        List<BrandCatalog> brandsDisplay = brandsService.getBrands(userInfo.getRetailerId(), userInfo.getEmail(), categoryId);
666
        List<BrandCatalog> brandsDisplay = brandsService.getBrands(userInfo.getRetailerId(), userInfo.getEmail(), categoryId);
-
 
667
        List<String> restrictedBrands = brandsService.restrictedBrands(userInfo.getRetailerId());
-
 
668
        brandsDisplay = brandsDisplay.stream().filter(x -> !restrictedBrands.contains(x.getName()))
-
 
669
                .collect(Collectors.toList());
686
        return new ResponseEntity<>(brandsDisplay, HttpStatus.OK);
670
        return new ResponseEntity<>(brandsDisplay, HttpStatus.OK);
687
    }
671
    }
688
 
672
 
689
    @RequestMapping(value = "/fofo/accessory/all-categories", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
673
    @RequestMapping(value = "/fofo/accessory/all-categories", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
690
    public ResponseEntity<?> getSubCategoriesToDisplay(HttpServletRequest request) throws Exception {
674
    public ResponseEntity<?> getSubCategoriesToDisplay(HttpServletRequest request) throws Exception {
Line 831... Line 815...
831
        params.put("fl", "*, [child parentFilter=id:catalog* childFilter=active_b:true ]");
815
        params.put("fl", "*, [child parentFilter=id:catalog* childFilter=active_b:true ]");
832
 
816
 
833
        params.put("start", String.valueOf(offset));
817
        params.put("start", String.valueOf(offset));
834
        params.put("rows", String.valueOf(limit));
818
        params.put("rows", String.valueOf(limit));
835
        params.put("wt", "json");
819
        params.put("wt", "json");
836
        String response = null;
-
 
837
        try {
-
 
838
            response = restClient.get(SchemeType.HTTP, solrUrl, 8984, "solr/demo/select", params);
-
 
839
        } catch (HttpHostConnectException e) {
-
 
840
            throw new ProfitMandiBusinessException("", "", "Could not connect to host");
-
 
841
        }
-
 
842
        JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
-
 
843
        JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
820
        JSONArray docs = partnerSolrClient.selectDocs(params, userInfo.getRetailerId());
844
        List<FofoCatalogResponse> dealResponse = getCatalogResponse(docs, false, userInfo.getRetailerId());
821
        List<FofoCatalogResponse> dealResponse = getCatalogResponse(docs, false, userInfo.getRetailerId());
845
 
822
 
846
        if (webProducts != null && webListing.getUrl().equals("new-launches")) {
823
        if (webProducts != null && webListing.getUrl().equals("new-launches")) {
847
            List<Integer> webProductsFinal = webProducts;
824
            List<Integer> webProductsFinal = webProducts;
848
            dealResponse = dealResponse.stream().sorted(Comparator.comparing(x -> webProductsFinal.indexOf(x.getCatalogId()))).collect(Collectors.toList());
825
            dealResponse = dealResponse.stream().sorted(Comparator.comparing(x -> webProductsFinal.indexOf(x.getCatalogId()))).collect(Collectors.toList());