Subversion Repositories SmartDukaan

Rev

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

Rev 26867 Rev 26909
Line 78... Line 78...
78
import com.spice.profitmandi.dao.repository.inventory.ItemAvailabilityCacheRepository;
78
import com.spice.profitmandi.dao.repository.inventory.ItemAvailabilityCacheRepository;
79
import com.spice.profitmandi.service.CustomerService;
79
import com.spice.profitmandi.service.CustomerService;
80
import com.spice.profitmandi.service.authentication.RoleManager;
80
import com.spice.profitmandi.service.authentication.RoleManager;
81
import com.spice.profitmandi.service.inventory.FofoAvailabilityInfo;
81
import com.spice.profitmandi.service.inventory.FofoAvailabilityInfo;
82
import com.spice.profitmandi.service.inventory.FofoCatalogResponse;
82
import com.spice.profitmandi.service.inventory.FofoCatalogResponse;
-
 
83
import com.spice.profitmandi.service.inventory.SaholicInventoryService;
83
import com.spice.profitmandi.service.scheme.SchemeService;
84
import com.spice.profitmandi.service.scheme.SchemeService;
84
import com.spice.profitmandi.service.user.RetailerService;
85
import com.spice.profitmandi.service.user.RetailerService;
85
import com.spice.profitmandi.web.processor.OtpProcessor;
86
import com.spice.profitmandi.web.processor.OtpProcessor;
86
import com.spice.profitmandi.web.res.DealBrands;
87
import com.spice.profitmandi.web.res.DealBrands;
87
import com.spice.profitmandi.web.res.DealObjectResponse;
88
import com.spice.profitmandi.web.res.DealObjectResponse;
Line 113... Line 114...
113
	@Autowired
114
	@Autowired
114
	CustomerService customerService;
115
	CustomerService customerService;
115
 
116
 
116
	@Value("${python.api.port}")
117
	@Value("${python.api.port}")
117
	private int port;
118
	private int port;
-
 
119
	
-
 
120
	@Autowired
-
 
121
	private SaholicInventoryService saholicInventoryService;
118
 
122
 
119
	// This is now unused as we are not supporting multiple companies.
123
	// This is now unused as we are not supporting multiple companies.
120
	@Value("${gadgetCops.invoice.cc}")
124
	@Value("${gadgetCops.invoice.cc}")
121
	private String[] ccGadgetCopInvoiceTo;
125
	private String[] ccGadgetCopInvoiceTo;
122
 
126
 
Line 230... Line 234...
230
			} catch (HttpHostConnectException e) {
234
			} catch (HttpHostConnectException e) {
231
				throw new ProfitMandiBusinessException("", "", "Could not connect to host");
235
				throw new ProfitMandiBusinessException("", "", "Could not connect to host");
232
			}
236
			}
233
			JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
237
			JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
234
			JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
238
			JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
235
			dealResponse = getCatalogResponse(docs, hotDeal);
239
			dealResponse = getCatalogResponse(docs, false, userInfo.getRetailerId());
236
			/*
240
			/*
237
			 * if (Mongo.PARTNER_BLoCKED_BRANDS.containsKey(userInfo.getEmail())) {
241
			 * if (Mongo.PARTNER_BLoCKED_BRANDS.containsKey(userInfo.getEmail())) {
238
			 * dealResponse.stream() .filter(x ->
242
			 * dealResponse.stream() .filter(x ->
239
			 * Mongo.PARTNER_BLoCKED_BRANDS.get(userInfo.getEmail()).contains(x.getBrand()))
243
			 * Mongo.PARTNER_BLoCKED_BRANDS.get(userInfo.getEmail()).contains(x.getBrand()))
240
			 * ; }
244
			 * ; }
Line 276... Line 280...
276
			} catch (HttpHostConnectException e) {
280
			} catch (HttpHostConnectException e) {
277
				throw new ProfitMandiBusinessException("", "", "Could not connect to host");
281
				throw new ProfitMandiBusinessException("", "", "Could not connect to host");
278
			}
282
			}
279
			JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
283
			JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
280
			JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
284
			JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
281
			dealResponse = getCatalogResponse(docs, false);
285
			dealResponse = getCatalogResponse(docs, false, userInfo.getRetailerId());
282
		} else {
286
		} else {
283
			return responseSender.badRequest(
287
			return responseSender.badRequest(
284
					new ProfitMandiBusinessException("Retailer id", userInfo.getUserId(), "NOT_FOFO_RETAILER"));
288
					new ProfitMandiBusinessException("Retailer id", userInfo.getUserId(), "NOT_FOFO_RETAILER"));
285
		}
289
		}
286
		return responseSender.ok(dealResponse.get(0));
290
		return responseSender.ok(dealResponse.get(0));
Line 320... Line 324...
320
	}
324
	}
321
 
325
 
322
	@RequestMapping(value = "/store/listing/{listingUrl}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
326
	@RequestMapping(value = "/store/listing/{listingUrl}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
323
	public ResponseEntity<?> bestSellers(HttpServletRequest request, @PathVariable String listingUrl) throws Exception {
327
	public ResponseEntity<?> bestSellers(HttpServletRequest request, @PathVariable String listingUrl) throws Exception {
324
		List<FofoCatalogResponse> dealResponse = new ArrayList<>();
328
		List<FofoCatalogResponse> dealResponse = new ArrayList<>();
325
		// UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
329
		UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
326
		// UserCart uc = userAccountRepository.getUserCart(userInfo.getUserId());
-
 
327
		List<Integer> tagIds = Arrays.asList(4);
330
		List<Integer> tagIds = Arrays.asList(4);
328
 
331
 
329
		WebListing webListing = webListingRepository.selectByUrl("url");
332
		WebListing webListing = webListingRepository.selectByUrl("url");
330
		if (webListing == null) {
333
		if (webListing == null) {
331
			throw new ProfitMandiBusinessException("Url", listingUrl, "Could not find the Url");
334
			throw new ProfitMandiBusinessException("Url", listingUrl, "Could not find the Url");
Line 352... Line 355...
352
			throw new ProfitMandiBusinessException("", "", "Could not connect to host");
355
			throw new ProfitMandiBusinessException("", "", "Could not connect to host");
353
		}
356
		}
354
		JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
357
		JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
355
		JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
358
		JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
356
		final Ordering<Integer> rankOrdering = Ordering.explicit(webProducts);
359
		final Ordering<Integer> rankOrdering = Ordering.explicit(webProducts);
357
		dealResponse = getCatalogResponse(docs, false).stream().sorted(new Comparator<FofoCatalogResponse>() {
360
		dealResponse = getCatalogResponse(docs, false, userInfo.getRetailerId()).stream().sorted(new Comparator<FofoCatalogResponse>() {
358
			@Override
361
			@Override
359
			public int compare(FofoCatalogResponse o1, FofoCatalogResponse o2) {
362
			public int compare(FofoCatalogResponse o1, FofoCatalogResponse o2) {
360
				return rankOrdering.compare(o1.getCatalogId(), o2.getCatalogId());
363
				return rankOrdering.compare(o1.getCatalogId(), o2.getCatalogId());
361
			}
364
			}
362
		}).collect(Collectors.toList());
365
		}).collect(Collectors.toList());
Line 484... Line 487...
484
	@RequestMapping(value = "/store/listing", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
487
	@RequestMapping(value = "/store/listing", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
485
	@Cacheable(value = "storelisting.all", cacheManager = "thirtyMinsTimeOutCacheManager")
488
	@Cacheable(value = "storelisting.all", cacheManager = "thirtyMinsTimeOutCacheManager")
486
	public ResponseEntity<?> getStoresListing(HttpServletRequest request) throws Exception {
489
	public ResponseEntity<?> getStoresListing(HttpServletRequest request) throws Exception {
487
		List<WebListing> webListings = webListingRepository.selectAllWebListing(Optional.of(true));
490
		List<WebListing> webListings = webListingRepository.selectAllWebListing(Optional.of(true));
488
		for (WebListing webListing : webListings) {
491
		for (WebListing webListing : webListings) {
-
 
492
			UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
-
 
493
			Integer storeId = userInfo.getRetailerId();
-
 
494
			
489
			List<Integer> webProducts = webProductListingRepository.selectAllByWebListingId(webListing.getId()).stream()
495
			List<Integer> webProducts = webProductListingRepository.selectAllByWebListingId(webListing.getId()).stream()
490
					.filter(x -> x.getRank() > 0).map(x -> x.getEntityId()).collect(Collectors.toList());
496
					.filter(x -> x.getRank() > 0).map(x -> x.getEntityId()).collect(Collectors.toList());
491
 
497
 
492
			RestClient rc = new RestClient();
498
			RestClient rc = new RestClient();
493
			Map<String, String> params = new HashMap<>();
499
			Map<String, String> params = new HashMap<>();
Line 508... Line 514...
508
				throw new ProfitMandiBusinessException("", "", "Could not connect to host");
514
				throw new ProfitMandiBusinessException("", "", "Could not connect to host");
509
			}
515
			}
510
			JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
516
			JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
511
			JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
517
			JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
512
			final Ordering<Integer> colorOrdering = Ordering.explicit(webProducts);
518
			final Ordering<Integer> colorOrdering = Ordering.explicit(webProducts);
513
			List<FofoCatalogResponse> dealResponse = getCatalogResponse(docs, false).stream()
519
			List<FofoCatalogResponse> dealResponse = getCatalogResponse(docs, false, userInfo.getRetailerId()).stream()
514
					.sorted(new Comparator<FofoCatalogResponse>() {
520
					.sorted(new Comparator<FofoCatalogResponse>() {
515
						@Override
521
						@Override
516
						public int compare(FofoCatalogResponse o1, FofoCatalogResponse o2) {
522
						public int compare(FofoCatalogResponse o1, FofoCatalogResponse o2) {
517
							return colorOrdering.compare(o1.getCatalogId(), o2.getCatalogId());
523
							return colorOrdering.compare(o1.getCatalogId(), o2.getCatalogId());
518
						}
524
						}
Line 602... Line 608...
602
 
608
 
603
	private boolean validateCart(int storeId, List<CartItem> cartItems) {
609
	private boolean validateCart(int storeId, List<CartItem> cartItems) {
604
		return false;
610
		return false;
605
	}
611
	}
606
 
612
 
607
	private List<FofoCatalogResponse> getCatalogResponse(JSONArray docs, boolean hotDeal)
613
	private List<FofoCatalogResponse> getCatalogResponse(JSONArray docs, boolean hotDeal, int fofoId)
608
			throws ProfitMandiBusinessException {
614
			throws ProfitMandiBusinessException {
609
		Map<Integer, Float> itemCashbackMap = schemeService.getItemSchemeCashBack();
615
		Map<Integer, Integer> ourItemAvailabilityMap = null;
610
		Map<Integer, TagListing> itemTagListingMap = null;
616
		Map<Integer, Integer> partnerStockAvailabilityMap = null;
611
		List<FofoCatalogResponse> dealResponse = new ArrayList<>();
617
		List<FofoCatalogResponse> dealResponse = new ArrayList<>();
612
		List<Integer> tagIds = Arrays.asList(4);
618
		List<Integer> tagIds = Arrays.asList(4);
613
		if (docs.length() > 0) {
619
		if (docs.length() > 0) {
614
			HashSet<Integer> itemsSet = new HashSet<>();
620
			HashSet<Integer> itemsSet = new HashSet<>();
615
			for (int i = 0; i < docs.length(); i++) {
621
			for (int i = 0; i < docs.length(); i++) {
Line 623... Line 629...
623
				}
629
				}
624
			}
630
			}
625
			if (itemsSet.size() == 0) {
631
			if (itemsSet.size() == 0) {
626
				return dealResponse;
632
				return dealResponse;
627
			}
633
			}
-
 
634
			if (hotDeal) {
-
 
635
				ourItemAvailabilityMap = saholicInventoryService
-
 
636
						.getTotalAvailabilityByItemIds(new ArrayList<>(itemsSet));
-
 
637
			} else if (fofoId > 0) {
628
			itemTagListingMap = tagListingRepository.selectByItemIdsAndTagIds(itemsSet, new HashSet<>(tagIds)).stream()
638
				partnerStockAvailabilityMap = currentInventorySnapshotRepository.selectItemsStock(fofoId).stream()
629
					.collect(Collectors.toMap(x -> x.getItemId(), x -> x));
639
						.collect(Collectors.toMap(x -> x.getItemId(), x -> x.getAvailability()));
-
 
640
				ourItemAvailabilityMap = saholicInventoryService
-
 
641
						.getTotalAvailabilityByItemIds(new ArrayList<>(itemsSet));
-
 
642
			}
630
		}
643
		}
631
 
644
 
632
		for (int i = 0; i < docs.length(); i++) {
645
		for (int i = 0; i < docs.length(); i++) {
633
			Map<Integer, FofoAvailabilityInfo> fofoAvailabilityInfoMap = new HashMap<>();
646
			Map<Integer, FofoAvailabilityInfo> fofoAvailabilityInfoMap = new HashMap<>();
634
			JSONObject doc = docs.getJSONObject(i);
647
			JSONObject doc = docs.getJSONObject(i);
Line 645... Line 658...
645
			ffdr.setBrand(doc.getJSONArray("brand_ss").getString(0));
658
			ffdr.setBrand(doc.getJSONArray("brand_ss").getString(0));
646
			if (doc.has("_childDocuments_")) {
659
			if (doc.has("_childDocuments_")) {
647
				for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
660
				for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
648
					JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
661
					JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
649
					int itemId = childItem.getInt("itemId_i");
662
					int itemId = childItem.getInt("itemId_i");
650
					TagListing tl = itemTagListingMap.get(itemId);
-
 
651
					if (tl == null) {
-
 
652
						logger.warn("Could not find item id {}", itemId);
-
 
653
						continue;
-
 
654
					}
-
 
655
					if (hotDeal) {
-
 
656
						if (!tl.isHotDeals()) {
-
 
657
							continue;
-
 
658
						}
-
 
659
					}
-
 
660
					float sellingPrice = (float) childItem.getDouble("sellingPrice_f");
663
					float sellingPrice = (float) childItem.getDouble("sellingPrice_f");
661
					if (fofoAvailabilityInfoMap.containsKey(itemId)) {
664
					if (fofoAvailabilityInfoMap.containsKey(itemId)) {
662
						if (fofoAvailabilityInfoMap.get(itemId).getSellingPrice() > sellingPrice) {
665
						if (fofoAvailabilityInfoMap.get(itemId).getSellingPrice() > sellingPrice) {
663
							fofoAvailabilityInfoMap.get(itemId).setSellingPrice(sellingPrice);
666
							fofoAvailabilityInfoMap.get(itemId).setSellingPrice(sellingPrice);
664
							fofoAvailabilityInfoMap.get(itemId).setMop((float) childItem.getDouble("mop_f"));
667
							fofoAvailabilityInfoMap.get(itemId).setMop((float) childItem.getDouble("mop_f"));
665
						}
668
						}
666
					} else {
669
					} else {
667
						FofoAvailabilityInfo fdi = new FofoAvailabilityInfo();
670
						FofoAvailabilityInfo fdi = new FofoAvailabilityInfo();
-
 
671
						fdi.setSellingPrice(sellingPrice);
668
						fdi.setCashback(itemCashbackMap.get(itemId) == null ? 0 : itemCashbackMap.get(itemId));
672
						fdi.setActive(childItem.getBoolean("active_b"));
669
						fdi.setSellingPrice((float) childItem.getDouble("sellingPrice_f"));
673
						fdi.setMrp(childItem.getDouble("mrp_f"));
670
						fdi.setMop((float) childItem.getDouble("mop_f"));
674
						fdi.setMop((float) childItem.getDouble("mop_f"));
671
						fdi.setColor(childItem.has("color_s") ? childItem.getString("color_s") : "");
675
						fdi.setColor(childItem.has("color_s") ? childItem.getString("color_s") : "");
672
						fdi.setTagId(childItem.getInt("tagId_i"));
676
						fdi.setTagId(childItem.getInt("tagId_i"));
673
						fdi.setItem_id(itemId);
677
						fdi.setItem_id(itemId);
674
						fdi.setMrp(tl.getMrp());
678
						Float cashBack = schemeService.getItemSchemeCashBack().get(itemId);
675
						// In case its tampered glass moq should be 5
679
						cashBack = cashBack == null ? 0 : cashBack;
-
 
680
						fdi.setCashback(cashBack);
676
						fdi.setMinBuyQuantity(1);
681
						fdi.setMinBuyQuantity(1);
677
						if (hotDeal || !tl.isActive()) {
-
 
678
 
-
 
679
							int totalAvailability = 0; // Using item availability
-
 
680
							// cache for now but can be
-
 
681
							// changed to
682
						if (hotDeal) {
682
							// use caching later.
-
 
683
							try {
683
							try {
684
								ItemAvailabilityCache iac = itemAvailabilityCacheRepository.selectByItemId(itemId);
684
								int totalAvailability = ourItemAvailabilityMap.get(itemId);
685
								totalAvailability = iac.getTotalAvailability();
685
								if (totalAvailability <= 0) {
-
 
686
									continue;
-
 
687
								}
686
								fdi.setAvailability(totalAvailability);
688
								fdi.setAvailability(ourItemAvailabilityMap.get(itemId));
687
							} catch (Exception e) {
689
							} catch (Exception e) {
688
								continue;
690
								continue;
689
							}
691
							}
-
 
692
						} else if (fofoId == 0) {
-
 
693
							// For accessories item availability should at be ordered for Rs.1000
690
							if (totalAvailability <= 0) {
694
							fdi.setAvailability(100);
-
 
695
							Item item = itemRepository.selectById(itemId);
-
 
696
							// In case its tampered glass moq should be 5
-
 
697
							if (item.getCategoryId() == 10020) {
691
								continue;
698
								fdi.setMinBuyQuantity(5);
692
							}
699
							}
693
						} else {
700
						} else {
694
							// For accessories item availability should at be ordered for Rs.1000
701
							int ourStockAvailability = ourItemAvailabilityMap.get(itemId) == null ? 0
695
							fdi.setAvailability(2);
702
									: ourItemAvailabilityMap.get(itemId);
-
 
703
							int partnerAvailability = partnerStockAvailabilityMap.get(itemId) == null ? 0
-
 
704
									: partnerStockAvailabilityMap.get(itemId);
-
 
705
							fdi.setAvailability(ourStockAvailability + partnerAvailability);
696
						}
706
						}
697
						fdi.setQuantityStep(1);
707
						fdi.setQuantityStep(1);
698
						fdi.setMaxQuantity(Math.min(fdi.getAvailability(), 2));
708
						fdi.setMaxQuantity(Math.min(fdi.getAvailability(), 100));
699
						fofoAvailabilityInfoMap.put(itemId, fdi);
709
						fofoAvailabilityInfoMap.put(itemId, fdi);
700
					}
710
					}
701
				}
711
				}
702
			}
712
			}
703
			if (fofoAvailabilityInfoMap.values().size() > 0) {
713
			if (fofoAvailabilityInfoMap.values().size() > 0) {
704
				ffdr.setItems(new ArrayList<FofoAvailabilityInfo>(fofoAvailabilityInfoMap.values()));
714
				ffdr.setItems(fofoAvailabilityInfoMap.values().stream()
-
 
715
							.sorted((x,y)->y.getAvailability()-x.getAvailability())
-
 
716
							.collect(Collectors.toList()));
705
				dealResponse.add(ffdr);
717
				dealResponse.add(ffdr);
706
			}
718
			}
707
		}
719
		}
708
		return dealResponse;
720
		return dealResponse;
709
	}
-
 
710
 
721
 
-
 
722
	}
711
	@RequestMapping(value = "/store/addresses/{customerId}", method = RequestMethod.GET)
723
	@RequestMapping(value = "/store/addresses/{customerId}", method = RequestMethod.GET)
712
	public ResponseEntity<?> getAll(HttpServletRequest request, @PathVariable int customerId) throws Throwable {
724
	public ResponseEntity<?> getAll(HttpServletRequest request, @PathVariable int customerId) throws Throwable {
713
		return responseSender.ok(customerAddressRepository.selectByCustomerId(customerId));
725
		return responseSender.ok(customerAddressRepository.selectByCustomerId(customerId));
714
	}
726
	}
715
 
727