Subversion Repositories SmartDukaan

Rev

Rev 26651 | Rev 26654 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
26607 amit.gupta 1
package com.spice.profitmandi.web.controller;
2
 
26628 amit.gupta 3
import java.time.LocalTime;
26607 amit.gupta 4
import java.util.ArrayList;
5
import java.util.Arrays;
6
import java.util.HashMap;
7
import java.util.HashSet;
8
import java.util.List;
9
import java.util.Map;
10
import java.util.Set;
11
import java.util.stream.Collectors;
12
 
13
import javax.servlet.http.HttpServletRequest;
14
 
15
import org.apache.commons.lang3.StringUtils;
16
import org.apache.http.conn.HttpHostConnectException;
17
import org.apache.logging.log4j.LogManager;
18
import org.apache.logging.log4j.Logger;
19
import org.json.JSONArray;
20
import org.json.JSONObject;
21
import org.springframework.beans.factory.annotation.Autowired;
22
import org.springframework.beans.factory.annotation.Value;
23
import org.springframework.http.MediaType;
24
import org.springframework.http.ResponseEntity;
25
import org.springframework.stereotype.Controller;
26
import org.springframework.transaction.annotation.Transactional;
27
import org.springframework.web.bind.annotation.RequestBody;
28
import org.springframework.web.bind.annotation.RequestMapping;
29
import org.springframework.web.bind.annotation.RequestMethod;
30
import org.springframework.web.bind.annotation.RequestParam;
31
 
32
import com.eclipsesource.json.JsonObject;
33
import com.google.gson.Gson;
34
import com.google.gson.reflect.TypeToken;
35
import com.spice.profitmandi.common.enumuration.SchemeType;
36
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
26648 amit.gupta 37
import com.spice.profitmandi.common.model.CreatePendingOrderRequest;
26651 amit.gupta 38
import com.spice.profitmandi.common.model.CustomRetailer;
26607 amit.gupta 39
import com.spice.profitmandi.common.model.ProfitMandiConstants;
40
import com.spice.profitmandi.common.model.UserInfo;
41
import com.spice.profitmandi.common.solr.SolrService;
42
import com.spice.profitmandi.common.web.client.RestClient;
43
import com.spice.profitmandi.common.web.util.ResponseSender;
44
import com.spice.profitmandi.dao.entity.catalog.Item;
45
import com.spice.profitmandi.dao.entity.catalog.TagListing;
46
import com.spice.profitmandi.dao.entity.fofo.CurrentInventorySnapshot;
47
import com.spice.profitmandi.dao.entity.inventory.ItemAvailabilityCache;
26630 amit.gupta 48
import com.spice.profitmandi.dao.enumuration.dtr.OtpType;
26607 amit.gupta 49
import com.spice.profitmandi.dao.model.AddCartRequest;
50
import com.spice.profitmandi.dao.model.CartItem;
51
import com.spice.profitmandi.dao.model.CartItemResponseModel;
52
import com.spice.profitmandi.dao.model.CartResponse;
53
import com.spice.profitmandi.dao.repository.catalog.CategoryRepository;
54
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
55
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
56
import com.spice.profitmandi.dao.repository.dtr.Mongo;
57
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
58
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
26648 amit.gupta 59
import com.spice.profitmandi.dao.repository.fofo.PendingOrderService;
26607 amit.gupta 60
import com.spice.profitmandi.dao.repository.inventory.ItemAvailabilityCacheRepository;
61
import com.spice.profitmandi.service.authentication.RoleManager;
62
import com.spice.profitmandi.service.inventory.FofoAvailabilityInfo;
63
import com.spice.profitmandi.service.inventory.FofoCatalogResponse;
64
import com.spice.profitmandi.service.pricing.PricingService;
26651 amit.gupta 65
import com.spice.profitmandi.service.user.RetailerService;
26630 amit.gupta 66
import com.spice.profitmandi.web.processor.OtpProcessor;
26607 amit.gupta 67
import com.spice.profitmandi.web.res.DealBrands;
68
import com.spice.profitmandi.web.res.DealObjectResponse;
69
import com.spice.profitmandi.web.res.DealsResponse;
70
import com.spice.profitmandi.web.res.ValidateCartResponse;
71
 
72
import io.swagger.annotations.ApiImplicitParam;
73
import io.swagger.annotations.ApiImplicitParams;
74
import io.swagger.annotations.ApiOperation;
75
 
76
@Controller
77
@Transactional(rollbackFor = Throwable.class)
78
public class StoreController {
79
 
80
	private static final Logger logger = LogManager.getLogger(StoreController.class);
26630 amit.gupta 81
 
26628 amit.gupta 82
	private static final LocalTime CUTOFF_TIME = LocalTime.of(15, 0);
26607 amit.gupta 83
 
84
	@Value("${python.api.host}")
85
	private String host;
86
 
87
	@Value("${python.api.port}")
88
	private int port;
89
 
90
	// This is now unused as we are not supporting multiple companies.
91
	@Value("${gadgetCops.invoice.cc}")
92
	private String[] ccGadgetCopInvoiceTo;
93
 
94
	@Autowired
95
	private PricingService pricingService;
96
 
97
	@Autowired
26651 amit.gupta 98
	private RetailerService retailerService;
26652 amit.gupta 99
 
26651 amit.gupta 100
	@Autowired
26652 amit.gupta 101
	private PendingOrderService pendingOrderService;
26648 amit.gupta 102
 
103
	@Autowired
26607 amit.gupta 104
	private CategoryRepository categoryRepository;
105
 
106
	@Autowired
107
	private SolrService commonSolrService;
108
 
109
	@Autowired
110
	private Mongo mongoClient;
111
 
112
	@Autowired
26630 amit.gupta 113
	private OtpProcessor otpProcessor;
114
 
115
	@Autowired
26607 amit.gupta 116
	private CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
117
 
26609 amit.gupta 118
	@Autowired
26607 amit.gupta 119
	private UserAccountRepository userAccountRepository;
120
 
121
	@Autowired
122
	private ResponseSender<?> responseSender;
123
 
124
	@Autowired
125
	private TagListingRepository tagListingRepository;
126
 
127
	@Autowired
128
	private ItemRepository itemRepository;
129
 
130
	@Autowired
131
	private ItemAvailabilityCacheRepository itemAvailabilityCacheRepository;
132
 
133
	@Autowired
134
	private RoleManager roleManagerService;
135
 
136
	List<String> filterableParams = Arrays.asList("brand");
137
 
138
	@ApiImplicitParams({
139
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
140
	@RequestMapping(value = "/store/fofo", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
141
	public ResponseEntity<?> getFofo(HttpServletRequest request,
142
			@RequestParam(value = "categoryId", required = false, defaultValue = "(3 OR 6)") String categoryId,
143
			@RequestParam(value = "offset") String offset, @RequestParam(value = "limit") String limit,
144
			@RequestParam(value = "sort", required = false) String sort,
145
			@RequestParam(value = "brand", required = false) String brand,
146
			@RequestParam(value = "subCategoryId", required = false) int subCategoryId,
147
			@RequestParam(value = "q", required = false) String queryTerm,
148
			@RequestParam(value = "hotDeal", required = false) boolean hotDeal) throws Throwable {
149
		List<FofoCatalogResponse> dealResponse = new ArrayList<>();
150
		UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
151
		if (roleManagerService.isPartner(userInfo.getRoleIds())) {
152
			// UserCart uc = userAccountRepository.getUserCart(userInfo.getUserId());
153
			List<Integer> tagIds = pricingService.getTagsIdsByRetailerId(userInfo.getRetailerId());
154
			RestClient rc = new RestClient();
155
			Map<String, String> params = new HashMap<>();
156
			List<String> mandatoryQ = new ArrayList<>();
157
			if (queryTerm != null && !queryTerm.equals("null")) {
158
				mandatoryQ.add(String.format("+(%s)", queryTerm));
159
			} else {
160
				queryTerm = null;
161
			}
162
			if (subCategoryId != 0) {
163
				mandatoryQ
164
						.add(String.format("+(subCategoryId_i:%s) +{!parent which=\"subCategoryId_i:%s\"} tagId_i:(%s)",
165
								subCategoryId, subCategoryId, StringUtils.join(tagIds, " ")));
166
			} else if (hotDeal) {
167
				mandatoryQ.add(String.format("+{!parent which=\"hot_deals_b=true\"} tagId_i:(%s)",
168
						StringUtils.join(tagIds, " ")));
169
 
170
			} else if (StringUtils.isNotBlank(brand)) {
171
				mandatoryQ.add(
172
						String.format("+(categoryId_i:%s) +(brand_ss:%s) +{!parent which=\"brand_ss:%s\"} tagId_i:(%s)",
173
								categoryId, brand, brand, StringUtils.join(tagIds, " ")));
174
 
175
			} else {
176
				mandatoryQ.add(
177
						String.format("+{!parent which=\"id:catalog*\"} tagId_i:(%s)", StringUtils.join(tagIds, " ")));
178
			}
179
			params.put("q", StringUtils.join(mandatoryQ, " "));
180
			params.put("fl", "*, [child parentFilter=id:catalog*]");
181
			if (queryTerm == null) {
182
				params.put("sort", "create_s desc");
183
			}
184
			params.put("start", String.valueOf(offset));
185
			params.put("rows", String.valueOf(limit));
186
			params.put("wt", "json");
187
			String response = null;
188
			try {
189
				response = rc.get(SchemeType.HTTP, "50.116.10.120", 8984, "solr/demo/select", params);
190
			} catch (HttpHostConnectException e) {
191
				throw new ProfitMandiBusinessException("", "", "Could not connect to host");
192
			}
193
			JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
194
			JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
195
			dealResponse = getCatalogResponse(docs, hotDeal);
196
			/*
197
			 * if (Mongo.PARTNER_BLoCKED_BRANDS.containsKey(userInfo.getEmail())) {
198
			 * dealResponse.stream() .filter(x ->
199
			 * Mongo.PARTNER_BLoCKED_BRANDS.get(userInfo.getEmail()).contains(x.getBrand()))
200
			 * ; }
201
			 */
202
		} else {
203
			return responseSender.badRequest(
204
					new ProfitMandiBusinessException("Retailer id", userInfo.getUserId(), "NOT_FOFO_RETAILER"));
205
		}
206
		return responseSender.ok(dealResponse);
207
	}
208
 
209
	private Object toDealObject(JsonObject jsonObject) {
210
		if (jsonObject.get("dealObject") != null && jsonObject.get("dealObject").asInt() == 1) {
211
			return new Gson().fromJson(jsonObject.toString(), DealObjectResponse.class);
212
		}
213
		return new Gson().fromJson(jsonObject.toString(), DealsResponse.class);
214
	}
215
 
216
	@RequestMapping(value = "/store/brands", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
217
	@ApiImplicitParams({
218
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
219
	@ApiOperation(value = "Get brand list and count for category")
220
	public ResponseEntity<?> getBrands(HttpServletRequest request,
221
			@RequestParam(value = "category_id") String category_id) throws ProfitMandiBusinessException {
222
		logger.info("Request " + request.getParameterMap());
223
		String response = null;
224
		// TODO: move to properties
225
		String uri = ProfitMandiConstants.URL_BRANDS;
226
		RestClient rc = new RestClient();
227
		Map<String, String> params = new HashMap<>();
228
		params.put("category_id", category_id);
229
		List<DealBrands> dealBrandsResponse = null;
230
		try {
231
			response = rc.get(SchemeType.HTTP, host, port, uri, params);
232
		} catch (HttpHostConnectException e) {
233
			throw new ProfitMandiBusinessException("", "", "Could not connect to host");
234
		}
235
 
236
		dealBrandsResponse = new Gson().fromJson(response, new TypeToken<List<DealBrands>>() {
237
		}.getType());
238
 
239
		return responseSender.ok(dealBrandsResponse);
240
	}
241
 
26632 amit.gupta 242
	@RequestMapping(value = "/store/otp/generateOTP", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
26652 amit.gupta 243
	public ResponseEntity<?> generateOtp(HttpServletRequest request, @RequestParam String email,
244
			@RequestParam String phone) throws Exception {
26630 amit.gupta 245
 
246
		return responseSender.ok(otpProcessor.generateOtp(email, phone, OtpType.PREBOOKING_ORDER));
247
 
248
	}
26652 amit.gupta 249
 
26648 amit.gupta 250
	@RequestMapping(value = "/store/confirmOrder", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
26652 amit.gupta 251
	public ResponseEntity<?> confirmCart(HttpServletRequest request,
252
			@RequestBody CreatePendingOrderRequest createPendingOrderRequest) throws Exception {
26648 amit.gupta 253
		UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
254
		Integer storeId = userInfo.getRetailerId();
255
		createPendingOrderRequest.setFofoId(storeId);
26652 amit.gupta 256
		this.pendingOrderService.createPendingOrder(createPendingOrderRequest);
26648 amit.gupta 257
		return responseSender.ok(true);
26652 amit.gupta 258
 
26648 amit.gupta 259
	}
26630 amit.gupta 260
 
26651 amit.gupta 261
	@RequestMapping(value = "/store/address", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
26607 amit.gupta 262
	@ApiImplicitParams({
263
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
264
	@ApiOperation(value = "Get brand list and count for category")
26652 amit.gupta 265
	public ResponseEntity<?> getAddress(HttpServletRequest request)
26607 amit.gupta 266
			throws Exception {
26651 amit.gupta 267
		UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
268
		Integer storeId = userInfo.getRetailerId();
269
		CustomRetailer customRetailer = retailerService.getFofoRetailer(storeId);
26652 amit.gupta 270
 
26651 amit.gupta 271
		return responseSender.ok(customRetailer.getAddress());
26652 amit.gupta 272
 
26651 amit.gupta 273
	}
26652 amit.gupta 274
 
275
	@RequestMapping(value = "/store/cart", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
276
	@ApiImplicitParams({
26651 amit.gupta 277
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
26652 amit.gupta 278
	@ApiOperation(value = "Get brand list and count for category")
279
	public ResponseEntity<?> cart(HttpServletRequest request, @RequestBody AddCartRequest cartRequest)
280
			throws Exception {
26607 amit.gupta 281
		CartResponse cartResponse = new CartResponse();
26612 amit.gupta 282
		List<CartItemResponseModel> cartItemResponseModels = new ArrayList<>();
283
		cartResponse.setCartItems(cartItemResponseModels);
26620 amit.gupta 284
 
26607 amit.gupta 285
		UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
286
		Integer storeId = userInfo.getRetailerId();
287
		List<Integer> itemIds = cartRequest.getCartItems().stream().map(x -> x.getItemId())
288
				.collect(Collectors.toList());
289
		Set<Integer> itemsIdsSet = new HashSet<>(itemIds);
290
		List<CurrentInventorySnapshot> currentInventorySnapshot = currentInventorySnapshotRepository
291
				.selectByFofoItemIds(storeId, itemsIdsSet);
292
		Map<Integer, Integer> storeItemAvailabilityMap = currentInventorySnapshot.stream()
26620 amit.gupta 293
				.filter(x -> x.getAvailability() > 0)
26607 amit.gupta 294
				.collect(Collectors.toMap(x -> x.getItemId(), x -> x.getAvailability()));
295
 
296
		Map<Integer, Item> itemsMap = itemRepository.selectByIds(itemsIdsSet).stream()
297
				.collect(Collectors.toMap(x -> x.getId(), x -> x));
298
 
299
		Map<Integer, TagListing> sdItemAvailabilityMap = tagListingRepository
300
				.selectByItemIdsAndTagIds(new HashSet<>(itemIds), new HashSet<>(Arrays.asList(4))).stream()
301
				.collect(Collectors.toMap(x -> x.getItemId(), x -> x));
302
 
303
		List<Integer> catalogIds = itemsMap.values().stream().map(x -> x.getCatalogItemId())
304
				.collect(Collectors.toList());
305
 
306
		Map<Integer, JSONObject> contentMap = commonSolrService.getContentByCatalogIds(catalogIds);
307
 
308
		// cartResponse.getCartItems()
309
		for (CartItem cartItem : cartRequest.getCartItems()) {
26620 amit.gupta 310
			if (cartItem.getQuantity() == 0) {
26617 amit.gupta 311
				continue;
312
			}
26607 amit.gupta 313
			Item item = itemsMap.get(cartItem.getItemId());
314
			TagListing tagListing = sdItemAvailabilityMap.get(cartItem.getItemId());
315
			CartItemResponseModel cartItemResponseModel = new CartItemResponseModel();
26628 amit.gupta 316
			int estimate = -2;
26607 amit.gupta 317
			if (storeItemAvailabilityMap.containsKey(cartItem.getItemId())) {
318
				if (storeItemAvailabilityMap.get(cartItem.getItemId()) >= cartItem.getQuantity()) {
26628 amit.gupta 319
					estimate = 0;
26607 amit.gupta 320
				} else if (tagListing.isActive()) {
26628 amit.gupta 321
					estimate = 2;
26607 amit.gupta 322
				} else {
26628 amit.gupta 323
					estimate = -2;
26607 amit.gupta 324
				}
26620 amit.gupta 325
			} else if (tagListing.isActive()) {
26628 amit.gupta 326
				estimate = 2;
26620 amit.gupta 327
			} else {
26628 amit.gupta 328
				estimate = -2;
26607 amit.gupta 329
			}
26630 amit.gupta 330
			if (estimate >= 0 && LocalTime.now().isAfter(CUTOFF_TIME)) {
26628 amit.gupta 331
				estimate = estimate + 1;
332
			}
333
			cartItemResponseModel.setEstimate(estimate);
26616 amit.gupta 334
			cartItemResponseModel.setTitle(item.getItemDescriptionNoColor());
26614 amit.gupta 335
			cartItemResponseModel.setItemId(cartItem.getItemId());
26615 amit.gupta 336
			cartItemResponseModel.setMinBuyQuantity(1);
337
			cartItemResponseModel.setQuantity(cartItem.getQuantity());
26621 amit.gupta 338
			cartItemResponseModel.setQuantityStep(1);
26607 amit.gupta 339
			cartItemResponseModel.setSellingPrice(tagListing.getMop());
340
			cartItemResponseModel.setMaxQuantity(10);
341
			cartItemResponseModel.setCatalogItemId(item.getCatalogItemId());
342
			cartItemResponseModel.setImageUrl(contentMap.get(item.getCatalogItemId()).getString("imageUrl_s"));
343
			cartItemResponseModel.setColor(item.getColor());
26620 amit.gupta 344
			cartItemResponseModels.add(cartItemResponseModel);
26607 amit.gupta 345
		}
346
		ValidateCartResponse vc = new ValidateCartResponse(cartResponse, "Success", "Items added to cart successfully");
347
		return responseSender.ok(vc);
348
	}
26652 amit.gupta 349
 
26648 amit.gupta 350
	private boolean validateCart(int storeId, List<CartItem> cartItems) {
351
		return false;
352
	}
26607 amit.gupta 353
 
354
	private List<FofoCatalogResponse> getCatalogResponse(JSONArray docs, boolean hotDeal)
355
			throws ProfitMandiBusinessException {
356
		Map<Integer, TagListing> itemTagListingMap = null;
357
		List<FofoCatalogResponse> dealResponse = new ArrayList<>();
358
		List<Integer> tagIds = Arrays.asList(4);
359
		if (docs.length() > 0) {
360
			HashSet<Integer> itemsSet = new HashSet<>();
361
			for (int i = 0; i < docs.length(); i++) {
362
				JSONObject doc = docs.getJSONObject(i);
363
				if (doc.has("_childDocuments_")) {
364
					for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
365
						JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
366
						int itemId = childItem.getInt("itemId_i");
367
						itemsSet.add(itemId);
368
					}
369
				}
370
			}
371
			if (itemsSet.size() == 0) {
372
				return dealResponse;
373
			}
374
			itemTagListingMap = tagListingRepository.selectByItemIdsAndTagIds(itemsSet, new HashSet<>(tagIds)).stream()
375
					.collect(Collectors.toMap(x -> x.getItemId(), x -> x));
376
		}
377
 
378
		for (int i = 0; i < docs.length(); i++) {
379
			Map<Integer, FofoAvailabilityInfo> fofoAvailabilityInfoMap = new HashMap<>();
380
			JSONObject doc = docs.getJSONObject(i);
381
			FofoCatalogResponse ffdr = new FofoCatalogResponse();
382
			ffdr.setCatalogId(doc.getInt("catalogId_i"));
383
			ffdr.setImageUrl(doc.getString("imageUrl_s"));
384
			ffdr.setTitle(doc.getString("title_s"));
385
			try {
386
				ffdr.setFeature(doc.getString("feature_s"));
387
			} catch (Exception e) {
388
				ffdr.setFeature(null);
389
				logger.info("Could not find Feature_s for {}", ffdr.getCatalogId());
390
			}
391
			ffdr.setBrand(doc.getJSONArray("brand_ss").getString(0));
392
			if (doc.has("_childDocuments_")) {
393
				for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
394
					JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
395
					int itemId = childItem.getInt("itemId_i");
396
					TagListing tl = itemTagListingMap.get(itemId);
397
					if (tl == null) {
398
						logger.warn("Could not find item id {}", itemId);
399
						continue;
400
					}
401
					if (hotDeal) {
402
						if (!tl.isHotDeals()) {
403
							continue;
404
						}
405
					}
406
					float sellingPrice = (float) childItem.getDouble("sellingPrice_f");
407
					if (fofoAvailabilityInfoMap.containsKey(itemId)) {
408
						if (fofoAvailabilityInfoMap.get(itemId).getSellingPrice() > sellingPrice) {
409
							fofoAvailabilityInfoMap.get(itemId).setSellingPrice(sellingPrice);
410
							fofoAvailabilityInfoMap.get(itemId).setMop((float) childItem.getDouble("mop_f"));
411
						}
412
					} else {
413
						FofoAvailabilityInfo fdi = new FofoAvailabilityInfo();
414
						fdi.setSellingPrice((float) childItem.getDouble("sellingPrice_f"));
415
						fdi.setMop((float) childItem.getDouble("mop_f"));
416
						fdi.setColor(childItem.has("color_s") ? childItem.getString("color_s") : "");
417
						fdi.setTagId(childItem.getInt("tagId_i"));
418
						fdi.setItem_id(itemId);
419
						Item item = itemRepository.selectById(itemId);
420
						// In case its tampered glass moq should be 5
421
						if (item.getCategoryId() == 10020) {
422
							fdi.setMinBuyQuantity(10);
423
						} else {
424
							fdi.setMinBuyQuantity(1);
425
						}
426
						if (hotDeal || !tl.isActive()) {
427
 
428
							int totalAvailability = 0; // Using item availability
429
							// cache for now but can be
430
							// changed to
431
							// use caching later.
432
							try {
433
								ItemAvailabilityCache iac = itemAvailabilityCacheRepository.selectByItemId(itemId);
434
								totalAvailability = iac.getTotalAvailability();
435
								fdi.setAvailability(totalAvailability);
436
							} catch (Exception e) {
437
								continue;
438
							}
439
							if (totalAvailability <= 0) {
440
								continue;
441
							}
442
						} else {
443
							// For accessories item availability should at be ordered for Rs.1000
444
							fdi.setAvailability(100);
445
						}
446
						fdi.setQuantityStep(1);
447
						fdi.setMaxQuantity(Math.min(fdi.getAvailability(), 100));
448
						fofoAvailabilityInfoMap.put(itemId, fdi);
449
					}
450
				}
451
			}
452
			if (fofoAvailabilityInfoMap.values().size() > 0) {
453
				ffdr.setItems(new ArrayList<FofoAvailabilityInfo>(fofoAvailabilityInfoMap.values()));
454
				dealResponse.add(ffdr);
455
			}
456
		}
457
		return dealResponse;
458
 
459
	}
460
 
461
}