Subversion Repositories SmartDukaan

Rev

Rev 33575 | Rev 33873 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 33575 Rev 33576
Line 341... Line 341...
341
        params.put("rows", similarCatalogIds.size() + "");
341
        params.put("rows", similarCatalogIds.size() + "");
342
        try {
342
        try {
343
            String response = restClient.get(SchemeType.HTTP, solrUrl, 8984, "solr/demo/select", params);
343
            String response = restClient.get(SchemeType.HTTP, solrUrl, 8984, "solr/demo/select", params);
344
            JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
344
            JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
345
            JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
345
            JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
346
            return responseSender.ok(this.getCatalogResponse(docs, false, userInfo.getRetailerId()));
346
            return responseSender.ok(this.getCatalogResponse(docs, false, userInfo.getRetailerId()).stream().filter(x -> x.isInStock()).collect(Collectors.toList()));
347
        } catch (HttpHostConnectException e) {
347
        } catch (HttpHostConnectException e) {
348
            throw new ProfitMandiBusinessException("", "", "Could not connect to host");
348
            throw new ProfitMandiBusinessException("", "", "Could not connect to host");
349
        }
349
        }
350
    }
350
    }
351
 
351
 
Line 374... Line 374...
374
                .collect(Collectors.toMap(x -> x.getCatalogId(), x -> x.getSimilarModelIds()));
374
                .collect(Collectors.toMap(x -> x.getCatalogId(), x -> x.getSimilarModelIds()));
375
        Set<Integer> similarModelIds = similarModelMap.values().stream().flatMap(x -> x.stream()).collect(Collectors.toSet());
375
        Set<Integer> similarModelIds = similarModelMap.values().stream().flatMap(x -> x.stream()).collect(Collectors.toSet());
376
        logger.info("similarModelIds - {}", similarModelIds);
376
        logger.info("similarModelIds - {}", similarModelIds);
377
        if (similarModelIds.size() > 0) {
377
        if (similarModelIds.size() > 0) {
378
 
378
 
379
            Map<Integer, FofoCatalogResponse> similarCatalogResponsesMap = this.getSimpleDocs(similarModelIds).stream().collect(Collectors.toMap(x -> x.getCatalogId(), x -> x));
379
            Map<Integer, FofoCatalogResponse> similarCatalogResponsesMap = this.getSimpleDocs(fs, similarModelIds).stream().collect(Collectors.toMap(x -> x.getCatalogId(), x -> x));
380
            logger.info("Similar Catalog ResponseMap - {}", similarCatalogResponsesMap.keySet());
380
            logger.info("Similar Catalog ResponseMap - {}", similarCatalogResponsesMap.keySet());
381
 
381
 
382
            for (FofoCatalogResponse deal : dealResponse) {
382
            for (FofoCatalogResponse deal : dealResponse) {
383
                if (similarModelMap.containsKey(deal.getCatalogId())) {
383
                if (similarModelMap.containsKey(deal.getCatalogId())) {
384
                    List<Integer> similarCatalogIds = similarModelMap.get(deal.getCatalogId());
384
                    List<Integer> similarCatalogIds = similarModelMap.get(deal.getCatalogId());
Line 389... Line 389...
389
            }
389
            }
390
        }
390
        }
391
        return responseSender.ok(dealResponse);
391
        return responseSender.ok(dealResponse);
392
    }
392
    }
393
 
393
 
394
    private List<FofoCatalogResponse> getSimpleDocs(Set<Integer> catalogIds) throws ProfitMandiBusinessException {
394
    private List<FofoCatalogResponse> getSimpleDocs(FofoStore fofoStore, Set<Integer> catalogIds) throws Exception {
395
        List<FofoCatalogResponse> fofoCatalogResponses = new ArrayList<>();
395
        List<FofoCatalogResponse> fofoCatalogResponses = new ArrayList<>();
396
 
396
 
397
 
397
 
398
        Map<String, String> params = new HashMap<>();
398
        Map<String, String> params = new HashMap<>();
399
        List<String> mandatoryQ = new ArrayList<>();
399
        List<String> mandatoryQ = new ArrayList<>();
Line 403... Line 403...
403
 
403
 
404
        params.put("q", StringUtils.join(mandatoryQ, " "));
404
        params.put("q", StringUtils.join(mandatoryQ, " "));
405
        params.put("fl", "*, [child parentFilter=id:catalog* childFilter=active_b:true ]");
405
        params.put("fl", "*, [child parentFilter=id:catalog* childFilter=active_b:true ]");
406
        params.put("wt", "json");
406
        params.put("wt", "json");
407
        params.put("rows", catalogIds.size() + "");
407
        params.put("rows", catalogIds.size() + "");
408
        try {
-
 
409
            String response = restClient.get(SchemeType.HTTP, solrUrl, 8984, "solr/demo/select", params);
-
 
410
            JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
-
 
411
            JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
-
 
412
 
408
 
-
 
409
        String response = restClient.get(SchemeType.HTTP, solrUrl, 8984, "solr/demo/select", params);
-
 
410
        JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
-
 
411
        JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
-
 
412
        int warehouseId = fofoStoreRepository.selectByRetailerId(fofoStore.getId()).getWarehouseId();
-
 
413
        Map<Integer, List<SaholicPOItem>> poItemAvailabilityMap = saholicInventoryService.getSaholicPOItems().get(warehouseId);
413
            for (int i = 0; i < docs.length(); i++) {
414
        for (int i = 0; i < docs.length(); i++) {
414
                JSONObject doc = docs.getJSONObject(i);
415
            JSONObject doc = docs.getJSONObject(i);
415
                FofoCatalogResponse fofoCatalogResponse = this.toFofoCatalogResponse(doc);
416
            FofoCatalogResponse fofoCatalogResponse = this.toFofoCatalogResponse(doc);
-
 
417
            if (doc.has("_childDocuments_")) {
-
 
418
                String modelColorClass = "grey";
-
 
419
                FofoAvailabilityInfo fdiAnyColour = null;
-
 
420
                // Iterating itemIds
-
 
421
                for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
-
 
422
                    JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
-
 
423
                    int itemId = childItem.getInt("itemId_i");
-
 
424
 
-
 
425
                    List<SaholicCISTable> currentAvailability = saholicCISTableRepository.selectByItemWarehouse(itemId, warehouseId);
-
 
426
                    List<SaholicPOItem> poItemAvailability = null;
-
 
427
                    if (poItemAvailabilityMap != null) {
-
 
428
                        poItemAvailability = poItemAvailabilityMap.get(itemId);
-
 
429
                    }
-
 
430
 
-
 
431
                    for (SaholicCISTable saholicCISTable : currentAvailability) {
-
 
432
                        saholicCISTable.setWarehouseName(
-
 
433
                                ProfitMandiConstants.WAREHOUSE_MAP.get(saholicCISTable.getWarehouseFrom()));
-
 
434
                    }
-
 
435
 
-
 
436
 
-
 
437
                    String poColor = "grey";
-
 
438
                    boolean active = false;
-
 
439
                    if (currentAvailability != null && currentAvailability.stream().collect(Collectors.summingInt(SaholicCISTable::getNetAvailability)) > 0) {
-
 
440
                        poColor = "green";
-
 
441
                        modelColorClass = "green";
-
 
442
                    } else if (poItemAvailability != null && poItemAvailability.stream().collect(Collectors.summingInt(SaholicPOItem::getUnfulfilledQty)) > 0) {
416
                fofoCatalogResponses.add(fofoCatalogResponse);
443
                        if (currentAvailability != null && poItemAvailability.stream().collect(Collectors.summingInt(SaholicPOItem::getUnfulfilledQty)) + currentAvailability.stream().collect(Collectors.summingInt(SaholicCISTable::getNetAvailability)) <= 0) {
-
 
444
                            poColor = "grey";
-
 
445
                        } else {
-
 
446
                            poColor = "yellow";
-
 
447
                            if (!modelColorClass.equals("green")) {
-
 
448
                                modelColorClass = poColor;
-
 
449
                            }
-
 
450
                        }
-
 
451
                    }
-
 
452
 
-
 
453
                }
-
 
454
                fofoCatalogResponse.setInStock(!modelColorClass.equals("grey"));
417
            }
455
            }
-
 
456
 
418
        } catch (HttpHostConnectException e) {
457
            fofoCatalogResponses.add(fofoCatalogResponse);
419
            throw new ProfitMandiBusinessException("", "", "Could not connect to host");
-
 
420
        }
458
        }
421
        return fofoCatalogResponses;
-
 
422
 
459
 
-
 
460
        return fofoCatalogResponses;
423
    }
461
    }
424
 
462
 
425
    private FofoCatalogResponse toFofoCatalogResponse(JSONObject doc) {
463
    private FofoCatalogResponse toFofoCatalogResponse(JSONObject doc) {
426
        FofoCatalogResponse fofoCatalogResponse = new FofoCatalogResponse();
464
        FofoCatalogResponse fofoCatalogResponse = new FofoCatalogResponse();
427
        fofoCatalogResponse.setCatalogId(doc.getInt("catalogId_i"));
465
        fofoCatalogResponse.setCatalogId(doc.getInt("catalogId_i"));
Line 697... Line 735...
697
            webListing.setFofoCatalogResponses(getDealResponses(userInfo, webListing, 0, 20));
735
            webListing.setFofoCatalogResponses(getDealResponses(userInfo, webListing, 0, 20));
698
        }
736
        }
699
        return responseSender.ok(webListings);
737
        return responseSender.ok(webListings);
700
    }
738
    }
701
 
739
 
702
    private List<FofoCatalogResponse> getDealResponses(UserInfo userInfo, WebListing webListing, int offset, int limit) throws Exception {
740
    private List<FofoCatalogResponse> getDealResponses(UserInfo userInfo, WebListing webListing, int offset,
-
 
741
                                                       int limit) throws Exception {
703
 
742
 
704
        RestClient rc = new RestClient();
743
        RestClient rc = new RestClient();
705
        Map<String, String> params = new HashMap<>();
744
        Map<String, String> params = new HashMap<>();
706
        List<String> mandatoryQ = new ArrayList<>();
745
        List<String> mandatoryQ = new ArrayList<>();
707
 
746
 
Line 968... Line 1007...
968
                    }
1007
                    }
969
                }
1008
                }
970
                if (fdiAnyColour != null) {
1009
                if (fdiAnyColour != null) {
971
                    fdiAnyColour.setColorClass(modelColorClass);
1010
                    fdiAnyColour.setColorClass(modelColorClass);
972
                }
1011
                }
-
 
1012
                fofoCatalogResponse.setInStock(!modelColorClass.equals("grey"));
973
            }
1013
            }
974
            if (fofoAvailabilityInfoMap.values().size() > 0) {
1014
            if (fofoAvailabilityInfoMap.values().size() > 0) {
975
                List<FofoAvailabilityInfo> availabilityList = fofoAvailabilityInfoMap.values().stream().sorted(Comparator.comparing(FofoAvailabilityInfo::getAvailability).reversed()).collect(Collectors.toList());
1015
                List<FofoAvailabilityInfo> availabilityList = fofoAvailabilityInfoMap.values().stream().sorted(Comparator.comparing(FofoAvailabilityInfo::getAvailability).reversed()).collect(Collectors.toList());
976
                fofoCatalogResponse.setItems(availabilityList);
1016
                fofoCatalogResponse.setItems(availabilityList);
977
                if (priceCircularItemModelMap.containsKey(fofoCatalogResponse.getCatalogId())) {
1017
                if (priceCircularItemModelMap.containsKey(fofoCatalogResponse.getCatalogId())) {