Subversion Repositories SmartDukaan

Rev

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

Rev 26608 Rev 26609
Line 6... Line 6...
6
import java.util.HashSet;
6
import java.util.HashSet;
7
import java.util.Iterator;
7
import java.util.Iterator;
8
import java.util.List;
8
import java.util.List;
9
import java.util.Map;
9
import java.util.Map;
10
import java.util.Set;
10
import java.util.Set;
11
import java.util.concurrent.atomic.AtomicInteger;
-
 
12
import java.util.stream.Collectors;
11
import java.util.stream.Collectors;
13
 
12
 
14
import javax.servlet.http.HttpServletRequest;
13
import javax.servlet.http.HttpServletRequest;
15
 
14
 
16
import org.apache.commons.lang3.StringUtils;
15
import org.apache.commons.lang3.StringUtils;
Line 19... Line 18...
19
import org.apache.logging.log4j.Logger;
18
import org.apache.logging.log4j.Logger;
20
import org.json.JSONArray;
19
import org.json.JSONArray;
21
import org.json.JSONObject;
20
import org.json.JSONObject;
22
import org.springframework.beans.factory.annotation.Autowired;
21
import org.springframework.beans.factory.annotation.Autowired;
23
import org.springframework.beans.factory.annotation.Value;
22
import org.springframework.beans.factory.annotation.Value;
24
import org.springframework.http.HttpStatus;
-
 
25
import org.springframework.http.MediaType;
23
import org.springframework.http.MediaType;
26
import org.springframework.http.ResponseEntity;
24
import org.springframework.http.ResponseEntity;
27
import org.springframework.stereotype.Controller;
25
import org.springframework.stereotype.Controller;
28
import org.springframework.transaction.annotation.Transactional;
26
import org.springframework.transaction.annotation.Transactional;
29
import org.springframework.web.bind.annotation.PathVariable;
27
import org.springframework.web.bind.annotation.PathVariable;
Line 31... Line 29...
31
import org.springframework.web.bind.annotation.RequestMapping;
29
import org.springframework.web.bind.annotation.RequestMapping;
32
import org.springframework.web.bind.annotation.RequestMethod;
30
import org.springframework.web.bind.annotation.RequestMethod;
33
import org.springframework.web.bind.annotation.RequestParam;
31
import org.springframework.web.bind.annotation.RequestParam;
34
 
32
 
35
import com.eclipsesource.json.Json;
33
import com.eclipsesource.json.Json;
36
import com.eclipsesource.json.JsonArray;
-
 
37
import com.eclipsesource.json.JsonObject;
34
import com.eclipsesource.json.JsonObject;
38
import com.eclipsesource.json.JsonValue;
-
 
39
import com.google.gson.Gson;
35
import com.google.gson.Gson;
40
import com.google.gson.reflect.TypeToken;
36
import com.google.gson.reflect.TypeToken;
41
import com.mongodb.BasicDBObject;
-
 
42
import com.mongodb.DBObject;
-
 
43
import com.spice.profitmandi.common.enumuration.SchemeType;
37
import com.spice.profitmandi.common.enumuration.SchemeType;
44
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
38
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
45
import com.spice.profitmandi.common.model.ProfitMandiConstants;
39
import com.spice.profitmandi.common.model.ProfitMandiConstants;
46
import com.spice.profitmandi.common.model.UserInfo;
40
import com.spice.profitmandi.common.model.UserInfo;
47
import com.spice.profitmandi.common.solr.SolrService;
41
import com.spice.profitmandi.common.solr.SolrService;
48
import com.spice.profitmandi.common.web.client.RestClient;
42
import com.spice.profitmandi.common.web.client.RestClient;
49
import com.spice.profitmandi.common.web.util.ResponseSender;
43
import com.spice.profitmandi.common.web.util.ResponseSender;
50
import com.spice.profitmandi.dao.entity.catalog.Category;
-
 
51
import com.spice.profitmandi.dao.entity.catalog.Item;
44
import com.spice.profitmandi.dao.entity.catalog.Item;
52
import com.spice.profitmandi.dao.entity.catalog.TagListing;
45
import com.spice.profitmandi.dao.entity.catalog.TagListing;
53
import com.spice.profitmandi.dao.entity.fofo.CurrentInventorySnapshot;
46
import com.spice.profitmandi.dao.entity.fofo.CurrentInventorySnapshot;
54
import com.spice.profitmandi.dao.entity.inventory.ItemAvailabilityCache;
47
import com.spice.profitmandi.dao.entity.inventory.ItemAvailabilityCache;
55
import com.spice.profitmandi.dao.model.AddCartRequest;
48
import com.spice.profitmandi.dao.model.AddCartRequest;
Line 107... Line 100...
107
	private Mongo mongoClient;
100
	private Mongo mongoClient;
108
 
101
 
109
	@Autowired
102
	@Autowired
110
	private CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
103
	private CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
111
 
104
 
112
		@Autowired
105
	@Autowired
113
	private UserAccountRepository userAccountRepository;
106
	private UserAccountRepository userAccountRepository;
114
 
107
 
115
	@Autowired
108
	@Autowired
116
	private ResponseSender<?> responseSender;
109
	private ResponseSender<?> responseSender;
117
 
110
 
Line 198... Line 191...
198
					new ProfitMandiBusinessException("Retailer id", userInfo.getUserId(), "NOT_FOFO_RETAILER"));
191
					new ProfitMandiBusinessException("Retailer id", userInfo.getUserId(), "NOT_FOFO_RETAILER"));
199
		}
192
		}
200
		return responseSender.ok(dealResponse);
193
		return responseSender.ok(dealResponse);
201
	}
194
	}
202
 
195
 
203
	@ApiImplicitParams({
-
 
204
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
-
 
205
	@RequestMapping(value = "/partnerStock", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
-
 
206
	public ResponseEntity<?> partnerStock(HttpServletRequest request,
-
 
207
			@RequestParam(value = "categoryId", required = false, defaultValue = "(3 OR 6)") String categoryId,
-
 
208
			@RequestParam(value = "offset") String offset, @RequestParam(value = "limit") String limit,
-
 
209
			@RequestParam(value = "sort", required = false) String sort,
-
 
210
			@RequestParam(value = "brand", required = false) String brand,
-
 
211
			@RequestParam(value = "subCategoryId", required = false) int subCategoryId,
-
 
212
			@RequestParam(value = "q", required = false) String queryTerm,
-
 
213
			@RequestParam(value = " ", required = false, defaultValue = "true") boolean partnerStockOnly)
-
 
214
			throws Throwable {
-
 
215
		List<FofoCatalogResponse> dealResponse = new ArrayList<>();
-
 
216
		UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
-
 
217
		UserCart uc = userAccountRepository.getUserCart(userInfo.getUserId());
-
 
218
 
-
 
219
		logger.info("Retiler Id ==> {}", uc.getUserId());
-
 
220
		if (roleManagerService.isPartner(userInfo.getRoleIds())) {
-
 
221
			if (partnerStockOnly) {
-
 
222
 
-
 
223
			}
-
 
224
			List<Integer> tagIds = pricingService.getTagsIdsByRetailerId(userInfo.getRetailerId());
-
 
225
			RestClient rc = new RestClient();
-
 
226
			Map<String, String> params = new HashMap<>();
-
 
227
			List<String> mandatoryQ = new ArrayList<>();
-
 
228
			if (queryTerm != null && !queryTerm.equals("null")) {
-
 
229
				mandatoryQ.add(String.format("+(%s)", queryTerm));
-
 
230
			} else {
-
 
231
				queryTerm = null;
-
 
232
			}
-
 
233
			if (subCategoryId != 0) {
-
 
234
				mandatoryQ
-
 
235
						.add(String.format("+(subCategoryId_i:%s) +{!parent which=\"subCategoryId_i:%s\"} tagId_i:(%s)",
-
 
236
								subCategoryId, subCategoryId, StringUtils.join(tagIds, " ")));
-
 
237
			} else if (StringUtils.isNotBlank(brand)) {
-
 
238
				mandatoryQ.add(
-
 
239
						String.format("+(categoryId_i:%s) +(brand_ss:%s) +{!parent which=\"brand_ss:%s\"} tagId_i:(%s)",
-
 
240
								categoryId, brand, brand, StringUtils.join(tagIds, " ")));
-
 
241
 
-
 
242
			} else {
-
 
243
				mandatoryQ.add(
-
 
244
						String.format("+{!parent which=\"id:catalog*\"} tagId_i:(%s)", StringUtils.join(tagIds, " ")));
-
 
245
			}
-
 
246
			params.put("q", StringUtils.join(mandatoryQ, " "));
-
 
247
			params.put("fl", "*, [child parentFilter=id:catalog*]");
-
 
248
			if (queryTerm == null) {
-
 
249
				params.put("sort", "create_s desc");
-
 
250
			}
-
 
251
			params.put("start", String.valueOf(offset));
-
 
252
			params.put("rows", String.valueOf(limit));
-
 
253
			params.put("wt", "json");
-
 
254
			String response = null;
-
 
255
			try {
-
 
256
				response = rc.get(SchemeType.HTTP, "50.116.10.120", 8984, "solr/demo/select", params);
-
 
257
			} catch (HttpHostConnectException e) {
-
 
258
				throw new ProfitMandiBusinessException("", "", "Could not connect to host");
-
 
259
			}
-
 
260
			JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
-
 
261
			JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
-
 
262
			dealResponse = getCatalogResponse(docs, false);
-
 
263
			/*
-
 
264
			 * if (Mongo.PARTNER_BLoCKED_BRANDS.containsKey(userInfo.getEmail())) {
-
 
265
			 * dealResponse.stream() .filter(x ->
-
 
266
			 * Mongo.PARTNER_BLoCKED_BRANDS.get(userInfo.getEmail()).contains(x.getBrand()))
-
 
267
			 * ; }
-
 
268
			 */
-
 
269
		} else {
-
 
270
			return responseSender.badRequest(
-
 
271
					new ProfitMandiBusinessException("Retailer id", userInfo.getUserId(), "NOT_FOFO_RETAILER"));
-
 
272
		}
-
 
273
		return responseSender.ok(dealResponse);
-
 
274
	}
-
 
275
 
-
 
276
	private Object toDealObject(JsonObject jsonObject) {
196
	private Object toDealObject(JsonObject jsonObject) {
277
		if (jsonObject.get("dealObject") != null && jsonObject.get("dealObject").asInt() == 1) {
197
		if (jsonObject.get("dealObject") != null && jsonObject.get("dealObject").asInt() == 1) {
278
			return new Gson().fromJson(jsonObject.toString(), DealObjectResponse.class);
198
			return new Gson().fromJson(jsonObject.toString(), DealObjectResponse.class);
279
		}
199
		}
280
		return new Gson().fromJson(jsonObject.toString(), DealsResponse.class);
200
		return new Gson().fromJson(jsonObject.toString(), DealsResponse.class);
Line 357... Line 277...
357
		}
277
		}
358
		ValidateCartResponse vc = new ValidateCartResponse(cartResponse, "Success", "Items added to cart successfully");
278
		ValidateCartResponse vc = new ValidateCartResponse(cartResponse, "Success", "Items added to cart successfully");
359
		return responseSender.ok(vc);
279
		return responseSender.ok(vc);
360
	}
280
	}
361
 
281
 
362
	@RequestMapping(value = ProfitMandiConstants.URL_UNIT_DEAL, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
-
 
363
	@ApiImplicitParams({
-
 
364
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
-
 
365
	@ApiOperation(value = "Get unit deal object")
-
 
366
	public ResponseEntity<?> getUnitDeal(HttpServletRequest request, @PathVariable(value = "id") long id)
-
 
367
			throws ProfitMandiBusinessException {
-
 
368
		String response = null;
-
 
369
		// TODO: move to properties
-
 
370
		String uri = "getDealById/" + id;
-
 
371
		System.out.println("Unit deal " + uri);
-
 
372
		RestClient rc = new RestClient();
-
 
373
		Map<String, String> params = new HashMap<>();
-
 
374
		DealsResponse dealsResponse = null;
-
 
375
		try {
-
 
376
			response = rc.get(SchemeType.HTTP, host, port, uri, params);
-
 
377
		} catch (HttpHostConnectException e) {
-
 
378
			throw new ProfitMandiBusinessException("", "", "Could not connect to host");
-
 
379
		}
-
 
380
 
-
 
381
		JsonObject result_json = Json.parse(response).asObject();
-
 
382
		if (!result_json.isEmpty()) {
-
 
383
			dealsResponse = new Gson().fromJson(response, DealsResponse.class);
-
 
384
			Iterator<AvailabilityInfo> iter = dealsResponse.getAvailabilityInfo().iterator();
-
 
385
			while (iter.hasNext()) {
-
 
386
				AvailabilityInfo ai = iter.next();
-
 
387
				if (ai.getAvailability() <= 0)
-
 
388
					iter.remove();
-
 
389
			}
-
 
390
		}
-
 
391
		return responseSender.ok(dealsResponse);
-
 
392
	}
-
 
393
 
-
 
394
	@RequestMapping(value = "/partnerdeals/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
-
 
395
	@ApiImplicitParams({
-
 
396
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
-
 
397
	@ApiOperation(value = "Get unit deal object")
-
 
398
	public ResponseEntity<?> getUnitFocoDeal(HttpServletRequest request, @PathVariable(value = "id") long id)
-
 
399
			throws ProfitMandiBusinessException {
-
 
400
		List<FofoCatalogResponse> dealResponse = new ArrayList<>();
-
 
401
		List<Integer> tagIds = Arrays.asList(4);
-
 
402
		UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
-
 
403
		if (roleManagerService.isPartner(userInfo.getRoleIds())) {
-
 
404
			String categoryId = "(3 OR 6)";
-
 
405
			UserCart uc = userAccountRepository.getUserCart(userInfo.getUserId());
-
 
406
			RestClient rc = new RestClient();
-
 
407
			Map<String, String> params = new HashMap<>();
-
 
408
			List<String> mandatoryQ = new ArrayList<>();
-
 
409
			String catalogString = "catalog" + id;
-
 
410
 
-
 
411
			mandatoryQ.add(String.format("+(categoryId_i:%s) +(id:%s) +{!parent which=\"id:%s\"} tagId_i:(%s)",
-
 
412
					categoryId, catalogString, catalogString, StringUtils.join(tagIds, " ")));
-
 
413
 
-
 
414
			params.put("q", StringUtils.join(mandatoryQ, " "));
-
 
415
			params.put("fl", "*, [child parentFilter=id:catalog*]");
-
 
416
			params.put("sort", "rank_i asc, create_s desc");
-
 
417
			params.put("wt", "json");
-
 
418
			String response = null;
-
 
419
			try {
-
 
420
				response = rc.get(SchemeType.HTTP, "50.116.10.120", 8984, "solr/demo/select", params);
-
 
421
			} catch (HttpHostConnectException e) {
-
 
422
				throw new ProfitMandiBusinessException("", "", "Could not connect to host");
-
 
423
			}
-
 
424
			JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
-
 
425
			JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
-
 
426
			dealResponse = getCatalogResponse(docs, false);
-
 
427
		} else {
-
 
428
			return responseSender.badRequest(
-
 
429
					new ProfitMandiBusinessException("Retailer id", userInfo.getUserId(), "NOT_FOFO_RETAILER"));
-
 
430
		}
-
 
431
		return responseSender.ok(dealResponse.get(0));
-
 
432
	}
-
 
433
 
-
 
434
	@RequestMapping(value = "/fofo/brands", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
-
 
435
	public ResponseEntity<?> getBrandsToDisplay(HttpServletRequest request,
-
 
436
			@RequestParam(required = false, defaultValue = "0") int categoryId) throws Exception {
-
 
437
		UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
-
 
438
		logger.info("userInfo [{}]", userInfo);
-
 
439
		List<DBObject> brandsDisplay = mongoClient.getMongoBrands(userInfo.getRetailerId(), userInfo.getEmail(),
-
 
440
				categoryId);
-
 
441
		return new ResponseEntity<>(brandsDisplay, HttpStatus.OK);
-
 
442
	}
-
 
443
 
-
 
444
	@RequestMapping(value = "/fofo/accessory/all-categories", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
-
 
445
	public ResponseEntity<?> getSubCategoriesToDisplay(HttpServletRequest request) throws Exception {
-
 
446
		UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
-
 
447
		logger.info("userInfo [{}]", userInfo);
-
 
448
		List<DBObject> subCateogriesDisplay = this.getSubCategoriesToDisplay();
-
 
449
		return new ResponseEntity<>(subCateogriesDisplay, HttpStatus.OK);
-
 
450
	}
-
 
451
 
-
 
452
	private List<DBObject> getSubCategoriesToDisplay() throws Exception {
-
 
453
		List<DBObject> subCategories = new ArrayList<>();
-
 
454
		RestClient rc = new RestClient();
-
 
455
		Map<String, String> params = new HashMap<>();
-
 
456
		params.put("q", "categoryId_i:6");
-
 
457
		params.put("group", "true");
-
 
458
		params.put("group.field", "subCategoryId_i");
-
 
459
		params.put("wt", "json");
-
 
460
		params.put("rows", "50");
-
 
461
		params.put("fl", "subCategoryId_i");
-
 
462
		String response = null;
-
 
463
		try {
-
 
464
			response = rc.get(SchemeType.HTTP, "50.116.10.120", 8984, "solr/demo/select", params);
-
 
465
		} catch (HttpHostConnectException e) {
-
 
466
			throw new ProfitMandiBusinessException("", "", "Could not connect to host");
-
 
467
		}
-
 
468
		JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("grouped");
-
 
469
		JSONArray groups = solrResponseJSONObj.getJSONObject("subCategoryId_i").getJSONArray("groups");
-
 
470
		List<Integer> categoryIds = new ArrayList<>();
-
 
471
		for (int i = 0; i < groups.length(); i++) {
-
 
472
			JSONObject groupObject = groups.getJSONObject(i);
-
 
473
			int subCategoryId = groupObject.getInt("groupValue");
-
 
474
			int quantity = groupObject.getJSONObject("doclist").getInt("numFound");
-
 
475
			categoryIds.add(subCategoryId);
-
 
476
		}
-
 
477
 
-
 
478
		List<Category> categories = categoryRepository.selectByIds(categoryIds);
-
 
479
		AtomicInteger i = new AtomicInteger(0);
-
 
480
		categories.forEach(x -> {
-
 
481
			DBObject dbObject = new BasicDBObject();
-
 
482
			dbObject.put("name", x.getLabel());
-
 
483
			dbObject.put("subCategoryId", x.getId());
-
 
484
			dbObject.put("rank", i.incrementAndGet());
-
 
485
			dbObject.put("categoryId", 6);
-
 
486
			dbObject.put("url", "https://images.smartdukaan.com/uploads/campaigns/" + x.getId() + ".png");
-
 
487
			subCategories.add(dbObject);
-
 
488
		});
-
 
489
 
-
 
490
		return subCategories;
-
 
491
 
-
 
492
	}
-
 
493
 
-
 
494
	@RequestMapping(value = "/banners/{bannerType}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
-
 
495
	public ResponseEntity<?> getBanners(@PathVariable String bannerType) {
-
 
496
		return new ResponseEntity<>(mongoClient.getBannersByType(bannerType), HttpStatus.OK);
-
 
497
	}
-
 
498
 
-
 
499
	@RequestMapping(value = "/deals/subCategories", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
-
 
500
	public ResponseEntity<?> getSubcategoriesToDisplay() {
-
 
501
		return new ResponseEntity<>(mongoClient.getSubcategoriesToDisplay(), HttpStatus.OK);
-
 
502
	}
-
 
503
 
-
 
504
	@ApiImplicitParams({
-
 
505
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
-
 
506
	@RequestMapping(value = "/deals/skus/{skus}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
-
 
507
	public ResponseEntity<?> getDealsBySkus(@PathVariable String skus) throws ProfitMandiBusinessException {
-
 
508
		StringBuffer sb = new StringBuffer("/getDealsForNotification/");
-
 
509
		String uri = sb.append(skus).toString();
-
 
510
		RestClient rc = new RestClient();
-
 
511
		String response;
-
 
512
		try {
-
 
513
			response = rc.get(SchemeType.HTTP, host, port, uri, new HashMap<>());
-
 
514
		} catch (HttpHostConnectException e) {
-
 
515
			throw new ProfitMandiBusinessException("", "", "Could not connect to host");
-
 
516
		}
-
 
517
		JsonArray result_json = Json.parse(response).asArray();
-
 
518
		List<Object> responseObject = new ArrayList<>();
-
 
519
		for (JsonValue j : result_json) {
-
 
520
			// logger.info("res " + j.asArray());
-
 
521
			List<Object> innerObject = new ArrayList<>();
-
 
522
			for (JsonValue jsonObject : j.asArray()) {
-
 
523
				innerObject.add(toDealObject(jsonObject.asObject()));
-
 
524
			}
-
 
525
			if (innerObject.size() > 0) {
-
 
526
				responseObject.add(innerObject);
-
 
527
			}
-
 
528
		}
-
 
529
		return responseSender.ok(responseObject);
-
 
530
	}
-
 
531
 
-
 
532
	private List<FofoCatalogResponse> getCatalogResponse(JSONArray docs, boolean hotDeal)
282
	private List<FofoCatalogResponse> getCatalogResponse(JSONArray docs, boolean hotDeal)
533
			throws ProfitMandiBusinessException {
283
			throws ProfitMandiBusinessException {
534
		Map<Integer, TagListing> itemTagListingMap = null;
284
		Map<Integer, TagListing> itemTagListingMap = null;
535
		List<FofoCatalogResponse> dealResponse = new ArrayList<>();
285
		List<FofoCatalogResponse> dealResponse = new ArrayList<>();
536
		List<Integer> tagIds = Arrays.asList(4);
286
		List<Integer> tagIds = Arrays.asList(4);
Line 634... Line 384...
634
		}
384
		}
635
		return dealResponse;
385
		return dealResponse;
636
 
386
 
637
	}
387
	}
638
 
388
 
639
	private List<FofoCatalogResponse> getCatalogSingleSkuResponse(JSONArray docs, Map<Integer, Integer> itemFilter,
-
 
640
			boolean hotDeal) throws ProfitMandiBusinessException {
-
 
641
		Map<Integer, TagListing> itemTagListingMap = null;
-
 
642
		List<FofoCatalogResponse> dealResponse = new ArrayList<>();
-
 
643
		List<Integer> tagIds = Arrays.asList(4);
-
 
644
 
-
 
645
		itemTagListingMap = tagListingRepository.selectByItemIdsAndTagIds(itemFilter.keySet(), new HashSet<>(tagIds))
-
 
646
				.stream().collect(Collectors.toMap(x -> x.getItemId(), x -> x));
-
 
647
 
-
 
648
		for (int i = 0; i < docs.length(); i++) {
-
 
649
			Map<Integer, FofoAvailabilityInfo> fofoAvailabilityInfoMap = new HashMap<>();
-
 
650
			JSONObject doc = docs.getJSONObject(i);
-
 
651
 
-
 
652
			for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
-
 
653
				JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
-
 
654
				int itemId = childItem.getInt("itemId_i");
-
 
655
				TagListing tl = itemTagListingMap.get(itemId);
-
 
656
				if (tl == null) {
-
 
657
					continue;
-
 
658
				}
-
 
659
				if (hotDeal) {
-
 
660
					if (!tl.isHotDeals()) {
-
 
661
						continue;
-
 
662
					}
-
 
663
				}
-
 
664
				float sellingPrice = (float) childItem.getDouble("sellingPrice_f");
-
 
665
				if (fofoAvailabilityInfoMap.containsKey(itemId)) {
-
 
666
					if (fofoAvailabilityInfoMap.get(itemId).getSellingPrice() > sellingPrice) {
-
 
667
						fofoAvailabilityInfoMap.get(itemId).setSellingPrice(sellingPrice);
-
 
668
						fofoAvailabilityInfoMap.get(itemId).setMop((float) childItem.getDouble("mop_f"));
-
 
669
					}
-
 
670
				} else {
-
 
671
					FofoAvailabilityInfo fdi = new FofoAvailabilityInfo();
-
 
672
					fdi.setSellingPrice((float) childItem.getDouble("sellingPrice_f"));
-
 
673
					fdi.setMop((float) childItem.getDouble("mop_f"));
-
 
674
					fdi.setColor(childItem.has("color_s") ? childItem.getString("color_s") : "");
-
 
675
					fdi.setTagId(childItem.getInt("tagId_i"));
-
 
676
					fdi.setItem_id(itemId);
-
 
677
					Item item = itemRepository.selectById(itemId);
-
 
678
					// In case its tampered glass moq should be 5
-
 
679
					if (item.getCategoryId() == 10020) {
-
 
680
						fdi.setMinBuyQuantity(10);
-
 
681
					} else {
-
 
682
						fdi.setMinBuyQuantity(1);
-
 
683
					}
-
 
684
					fdi.setAvailability(itemFilter.get(itemId));
-
 
685
					fdi.setQuantityStep(1);
-
 
686
					fdi.setMaxQuantity(Math.min(fdi.getAvailability(), 100));
-
 
687
					fofoAvailabilityInfoMap.put(itemId, fdi);
-
 
688
				}
-
 
689
			}
-
 
690
			if (fofoAvailabilityInfoMap.values().size() > 0) {
-
 
691
				for (FofoAvailabilityInfo fofoAvailabilityInfo : fofoAvailabilityInfoMap.values()) {
-
 
692
					FofoCatalogResponse ffdr = new FofoCatalogResponse();
-
 
693
					ffdr.setCatalogId(doc.getInt("catalogId_i"));
-
 
694
					ffdr.setImageUrl(doc.getString("imageUrl_s"));
-
 
695
					ffdr.setTitle(doc.getString("title_s"));
-
 
696
					try {
-
 
697
						ffdr.setFeature(doc.getString("feature_s"));
-
 
698
					} catch (Exception e) {
-
 
699
						ffdr.setFeature(null);
-
 
700
						logger.info("Could not find Feature_s for {}", ffdr.getCatalogId());
-
 
701
					}
-
 
702
					ffdr.setBrand(doc.getJSONArray("brand_ss").getString(0));
-
 
703
					ffdr.setItems(Arrays.asList(fofoAvailabilityInfo));
-
 
704
					dealResponse.add(ffdr);
-
 
705
				}
-
 
706
			}
-
 
707
		}
-
 
708
		return dealResponse;
-
 
709
 
-
 
710
	}
-
 
711
}
389
}
712
390