Subversion Repositories SmartDukaan

Rev

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

Rev 31649 Rev 31670
Line 266... Line 266...
266
	public ResponseEntity<?> getFavourites(HttpServletRequest request) throws Exception {
266
	public ResponseEntity<?> getFavourites(HttpServletRequest request) throws Exception {
267
 
267
 
268
		int userId = (int) request.getAttribute("userId");
268
		int userId = (int) request.getAttribute("userId");
269
		UserCart uc = userAccountRepository.getUserCart(userId);
269
		UserCart uc = userAccountRepository.getUserCart(userId);
270
		int fofoId = uc.getUserId();
270
		int fofoId = uc.getUserId();
271
 
-
 
-
 
271
		List<FofoCatalogResponse> dealResponse = new ArrayList<>();
272
		Set<Integer> catalogIds = catalogFavouriteRepository.selectBypartnerId(fofoId).stream()
272
		Set<Integer> catalogIds = catalogFavouriteRepository.selectBypartnerId(fofoId).stream()
273
				.map(x -> x.getCatalogId()).collect(Collectors.toSet());
273
				.map(x -> x.getCatalogId()).collect(Collectors.toSet());
274
		RestClient rc = new RestClient();
-
 
275
		Map<String, String> params = new HashMap<>();
-
 
276
		List<String> mandatoryQ = new ArrayList<>();
-
 
277
		mandatoryQ.add(
-
 
278
				String.format("+catalogId_i:(%s) +{!parent which=\"id:catalog*\"}", StringUtils.join(catalogIds, " ")));
-
 
279
		params.put("start", "0");
274
		if (!catalogIds.isEmpty()) {
280
		params.put("rows", "100");
-
 
281
		params.put("q", StringUtils.join(mandatoryQ, " "));
-
 
282
		params.put("fl", "*, [child parentFilter=id:catalog*]");
-
 
283
 
275
 
284
		params.put("wt", "json");
276
			RestClient rc = new RestClient();
285
		String response = null;
277
			Map<String, String> params = new HashMap<>();
286
		try {
278
			List<String> mandatoryQ = new ArrayList<>();
287
			response = rc.get(SchemeType.HTTP, solrUrl, 8984, "solr/demo/select", params);
279
			mandatoryQ.add(String.format("+catalogId_i:(%s) +{!parent which=\"id:catalog*\"}",
288
		} catch (HttpHostConnectException e) {
280
					StringUtils.join(catalogIds, " ")));
289
			throw new ProfitMandiBusinessException("", "", "Could not connect to host");
281
			params.put("start", "0");
290
		}
-
 
291
		JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
282
			params.put("rows", "100");
292
		JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
283
			params.put("q", StringUtils.join(mandatoryQ, " "));
293
		List<FofoCatalogResponse> dealResponse = getCatalogResponse(docs, false, fofoId);
284
			params.put("fl", "*, [child parentFilter=id:catalog*]");
294
 
285
 
-
 
286
			params.put("wt", "json");
-
 
287
			String response = null;
-
 
288
			try {
-
 
289
				response = rc.get(SchemeType.HTTP, solrUrl, 8984, "solr/demo/select", params);
-
 
290
			} catch (HttpHostConnectException e) {
-
 
291
				throw new ProfitMandiBusinessException("", "", "Could not connect to host");
-
 
292
			}
-
 
293
			JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
-
 
294
			JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
-
 
295
			dealResponse = getCatalogResponse(docs, false, fofoId);
-
 
296
		}
295
		return responseSender.ok(dealResponse);
297
		return responseSender.ok(dealResponse);
296
	}
298
	}
297
 
299
 
298
	@RequestMapping(value = "/favourites/manage", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
300
	@RequestMapping(value = "/favourites/manage", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
299
	@ApiImplicitParams({
301
	@ApiImplicitParams({
Line 646... Line 648...
646
		RestClient rc = new RestClient();
648
		RestClient rc = new RestClient();
647
		Map<String, String> params = new HashMap<>();
649
		Map<String, String> params = new HashMap<>();
648
		List<String> mandatoryQ = new ArrayList<>();
650
		List<String> mandatoryQ = new ArrayList<>();
649
		mandatoryQ.add("show_default_b:true");
651
		mandatoryQ.add("show_default_b:true");
650
 
652
 
-
 
653
		FofoStore fs = fofoStoreRepository.selectByRetailerId(userInfo.getRetailerId());
-
 
654
 
-
 
655
		params.put("sort", "w" + fs.getWarehouseId() + "_i desc");
-
 
656
 
651
		List<Integer> webProducts = null;
657
		List<Integer> webProducts = null;
652
		if (webListing.getType().equals(WebListingType.solr)) {
658
		if (webListing.getType().equals(WebListingType.solr)) {
653
			logger.info("solrtype {}", webListing.getSolrQuery());
659
			logger.info("solrtype {}", webListing.getSolrQuery());
654
			mandatoryQ.add(String.format("+{!parent which=\"" + webListing.getSolrQuery() + "\"} AND active_b:true"));
660
			mandatoryQ.add(String.format("+{!parent which=\"" + webListing.getSolrQuery() + "\"} AND active_b:true"));
655
			params.put("sort", "create_s desc");
-
 
656
		} else {
661
		} else {
657
			logger.info("solrtype2 {}", webListing.getSolrQuery());
662
			logger.info("solrtype2 {}", webListing.getSolrQuery());
658
 
663
 
659
			webProducts = webProductListingRepository
664
			webProducts = webProductListingRepository
660
					.selectAllByWebListingId(webListing.getId(), Integer.parseInt(offset), Integer.parseInt(limit))
665
					.selectAllByWebListingId(webListing.getId(), Integer.parseInt(offset), Integer.parseInt(limit))
Line 680... Line 685...
680
			throw new ProfitMandiBusinessException("", "", "Could not connect to host");
685
			throw new ProfitMandiBusinessException("", "", "Could not connect to host");
681
		}
686
		}
682
		JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
687
		JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
683
		JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
688
		JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
684
		List<FofoCatalogResponse> dealResponse = getCatalogResponse(docs, false, userInfo.getRetailerId());
689
		List<FofoCatalogResponse> dealResponse = getCatalogResponse(docs, false, userInfo.getRetailerId());
685
		if (webProducts != null) {
690
		/*
686
			List<Integer> webProductsFinal = webProducts;
691
		 * if (webProducts != null) { List<Integer> webProductsFinal = webProducts;
687
			dealResponse = dealResponse.stream()
692
		 * dealResponse = dealResponse.stream() .sorted(Comparator.comparing(x ->
688
					.sorted(Comparator.comparing(x -> webProductsFinal.indexOf(x.getCatalogId())))
693
		 * webProductsFinal.indexOf(x.getCatalogId()))) .collect(Collectors.toList());
-
 
694
		 * 
689
					.collect(Collectors.toList());
695
		 * 
690
		}
696
		 * }
-
 
697
		 */
691
 
698
 
692
		return dealResponse;
699
		return dealResponse;
693
	}
700
	}
694
 
701
 
695
	@Autowired
702
	@Autowired