Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
21339 kshitij.so 1
package com.spice.profitmandi.web.controller;
2
 
3
import java.util.ArrayList;
22336 amit.gupta 4
import java.util.Arrays;
21339 kshitij.so 5
import java.util.HashMap;
23814 amit.gupta 6
import java.util.HashSet;
22952 amit.gupta 7
import java.util.Iterator;
21339 kshitij.so 8
import java.util.List;
9
import java.util.Map;
25875 amit.gupta 10
import java.util.Optional;
25959 amit.gupta 11
import java.util.Set;
25010 amit.gupta 12
import java.util.concurrent.atomic.AtomicInteger;
23814 amit.gupta 13
import java.util.stream.Collectors;
21339 kshitij.so 14
 
15
import javax.servlet.http.HttpServletRequest;
16
 
22319 amit.gupta 17
import org.apache.commons.lang3.StringUtils;
23532 amit.gupta 18
import org.apache.http.conn.HttpHostConnectException;
23786 amit.gupta 19
import org.apache.logging.log4j.LogManager;
20
import org.apache.logging.log4j.Logger;
22319 amit.gupta 21
import org.json.JSONArray;
22
import org.json.JSONObject;
22273 amit.gupta 23
import org.springframework.beans.factory.annotation.Autowired;
21339 kshitij.so 24
import org.springframework.beans.factory.annotation.Value;
25
import org.springframework.http.HttpStatus;
26
import org.springframework.http.MediaType;
27
import org.springframework.http.ResponseEntity;
28
import org.springframework.stereotype.Controller;
22286 amit.gupta 29
import org.springframework.transaction.annotation.Transactional;
21339 kshitij.so 30
import org.springframework.web.bind.annotation.PathVariable;
31
import org.springframework.web.bind.annotation.RequestMapping;
32
import org.springframework.web.bind.annotation.RequestMethod;
33
import org.springframework.web.bind.annotation.RequestParam;
34
 
35
import com.eclipsesource.json.Json;
36
import com.eclipsesource.json.JsonArray;
37
import com.eclipsesource.json.JsonObject;
38
import com.eclipsesource.json.JsonValue;
39
import com.google.gson.Gson;
21356 kshitij.so 40
import com.google.gson.reflect.TypeToken;
25010 amit.gupta 41
import com.mongodb.BasicDBObject;
24163 amit.gupta 42
import com.mongodb.DBObject;
21643 ashik.ali 43
import com.spice.profitmandi.common.enumuration.SchemeType;
21339 kshitij.so 44
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
45
import com.spice.profitmandi.common.model.ProfitMandiConstants;
22289 amit.gupta 46
import com.spice.profitmandi.common.model.UserInfo;
21643 ashik.ali 47
import com.spice.profitmandi.common.web.client.RestClient;
22319 amit.gupta 48
import com.spice.profitmandi.common.web.util.ResponseSender;
25010 amit.gupta 49
import com.spice.profitmandi.dao.entity.catalog.Category;
23426 amit.gupta 50
import com.spice.profitmandi.dao.entity.catalog.Item;
23814 amit.gupta 51
import com.spice.profitmandi.dao.entity.catalog.TagListing;
26847 tejbeer 52
import com.spice.profitmandi.dao.entity.fofo.SuggestedPo;
26846 tejbeer 53
import com.spice.profitmandi.dao.entity.fofo.SuggestedPoDetail;
23861 amit.gupta 54
import com.spice.profitmandi.dao.entity.inventory.ItemAvailabilityCache;
22361 amit.gupta 55
import com.spice.profitmandi.dao.model.UserCart;
25010 amit.gupta 56
import com.spice.profitmandi.dao.repository.catalog.CategoryRepository;
23426 amit.gupta 57
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
23814 amit.gupta 58
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
22333 amit.gupta 59
import com.spice.profitmandi.dao.repository.dtr.Mongo;
22361 amit.gupta 60
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
26846 tejbeer 61
import com.spice.profitmandi.dao.repository.fofo.SuggestedPoDetailRepository;
26847 tejbeer 62
import com.spice.profitmandi.dao.repository.fofo.SuggestedPoRepository;
22989 amit.gupta 63
import com.spice.profitmandi.dao.repository.inventory.ItemAvailabilityCacheRepository;
23798 amit.gupta 64
import com.spice.profitmandi.service.authentication.RoleManager;
25880 amit.gupta 65
import com.spice.profitmandi.service.inventory.AvailabilityInfo;
25882 amit.gupta 66
import com.spice.profitmandi.service.inventory.Bucket;
25880 amit.gupta 67
import com.spice.profitmandi.service.inventory.FofoAvailabilityInfo;
68
import com.spice.profitmandi.service.inventory.FofoCatalogResponse;
25875 amit.gupta 69
import com.spice.profitmandi.service.inventory.ItemBucketService;
25879 amit.gupta 70
import com.spice.profitmandi.service.inventory.ItemQuantityPojo;
22287 amit.gupta 71
import com.spice.profitmandi.service.pricing.PricingService;
26695 amit.gupta 72
import com.spice.profitmandi.service.scheme.SchemeService;
21356 kshitij.so 73
import com.spice.profitmandi.web.res.DealBrands;
21339 kshitij.so 74
import com.spice.profitmandi.web.res.DealObjectResponse;
75
import com.spice.profitmandi.web.res.DealsResponse;
76
 
77
import io.swagger.annotations.ApiImplicitParam;
78
import io.swagger.annotations.ApiImplicitParams;
79
import io.swagger.annotations.ApiOperation;
80
 
81
@Controller
22319 amit.gupta 82
@Transactional(rollbackFor = Throwable.class)
21339 kshitij.so 83
public class DealsController {
84
 
23568 govind 85
	private static final Logger logger = LogManager.getLogger(DealsController.class);
21339 kshitij.so 86
 
87
	@Value("${python.api.host}")
88
	private String host;
23816 amit.gupta 89
 
21339 kshitij.so 90
	@Value("${python.api.port}")
91
	private int port;
23816 amit.gupta 92
 
93
	// This is now unused as we are not supporting multiple companies.
23300 amit.gupta 94
	@Value("${gadgetCops.invoice.cc}")
23816 amit.gupta 95
	private String[] ccGadgetCopInvoiceTo;
22319 amit.gupta 96
 
97
	@Autowired
98
	private PricingService pricingService;
23816 amit.gupta 99
 
22273 amit.gupta 100
	@Autowired
25010 amit.gupta 101
	private CategoryRepository categoryRepository;
102
 
103
	@Autowired
26695 amit.gupta 104
	private SchemeService schemeService;
105
 
106
	@Autowired
22333 amit.gupta 107
	private Mongo mongoClient;
25879 amit.gupta 108
 
25875 amit.gupta 109
	@Autowired
110
	private ItemBucketService itemBucketService;
23816 amit.gupta 111
 
22333 amit.gupta 112
	@Autowired
22361 amit.gupta 113
	private UserAccountRepository userAccountRepository;
23816 amit.gupta 114
 
22989 amit.gupta 115
	@Autowired
22931 ashik.ali 116
	private ResponseSender<?> responseSender;
23816 amit.gupta 117
 
22554 amit.gupta 118
	@Autowired
25010 amit.gupta 119
	private CategoryRepository repository;
120
 
121
	@Autowired
23814 amit.gupta 122
	private TagListingRepository tagListingRepository;
23816 amit.gupta 123
 
23814 amit.gupta 124
	@Autowired
23426 amit.gupta 125
	private ItemRepository itemRepository;
23816 amit.gupta 126
 
23786 amit.gupta 127
	@Autowired
23861 amit.gupta 128
	private ItemAvailabilityCacheRepository itemAvailabilityCacheRepository;
129
 
130
	@Autowired
23798 amit.gupta 131
	private RoleManager roleManagerService;
23816 amit.gupta 132
 
26846 tejbeer 133
	@Autowired
134
	private SuggestedPoDetailRepository monthlyPoDetailRepository;
135
 
26847 tejbeer 136
	@Autowired
137
	private SuggestedPoRepository suggestedPoRepository;
138
 
22336 amit.gupta 139
	List<String> filterableParams = Arrays.asList("brand");
24949 amit.gupta 140
 
25876 amit.gupta 141
	@RequestMapping(value = "/fofo/buckets", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
25879 amit.gupta 142
	public ResponseEntity<?> getBuckets(HttpServletRequest request) throws ProfitMandiBusinessException {
25875 amit.gupta 143
		logger.info("Request " + request.getParameterMap());
144
		return responseSender.ok(itemBucketService.getBuckets(Optional.of(true)));
145
	}
25879 amit.gupta 146
 
147
	@RequestMapping(value = "/fofo/bucket", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
25880 amit.gupta 148
	public ResponseEntity<?> getBucketDetails(HttpServletRequest request, @RequestParam int id)
25879 amit.gupta 149
			throws ProfitMandiBusinessException {
25880 amit.gupta 150
		List<ItemQuantityPojo> iqPojo = itemBucketService.getBucketDetails(id);
25968 amit.gupta 151
		Map<Integer, Integer> itemIdsQtyMap = iqPojo.stream()
152
				.collect(Collectors.toMap(x -> x.getItemId(), x -> x.getQuantity()));
153
		Set<Integer> catalogIds = itemRepository.selectByIds(itemIdsQtyMap.keySet()).stream()
154
				.map(x -> x.getCatalogItemId()).collect(Collectors.toSet());
25879 amit.gupta 155
		RestClient rc = new RestClient();
156
		Map<String, String> params = new HashMap<>();
157
		List<String> mandatoryQ = new ArrayList<>();
25968 amit.gupta 158
		mandatoryQ.add(
159
				String.format("+catalogId_i:(%s) +{!parent which=\"id:catalog*\"}", StringUtils.join(catalogIds, " ")));
25959 amit.gupta 160
		params.put("start", "0");
161
		params.put("rows", "100");
25879 amit.gupta 162
		params.put("q", StringUtils.join(mandatoryQ, " "));
163
		params.put("fl", "*, [child parentFilter=id:catalog*]");
164
 
165
		params.put("wt", "json");
166
		String response = null;
167
		try {
26573 amit.gupta 168
			response = rc.get(SchemeType.HTTP, "50.116.10.120", 8984, "solr/demo/select", params);
25879 amit.gupta 169
		} catch (HttpHostConnectException e) {
170
			throw new ProfitMandiBusinessException("", "", "Could not connect to host");
171
		}
172
		JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
173
		JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
25968 amit.gupta 174
		List<FofoCatalogResponse> dealResponse = getCatalogSingleSkuResponse(docs, itemIdsQtyMap, false);
26051 amit.gupta 175
 
26589 amit.gupta 176
		Bucket bucket = itemBucketService.getBuckets(Optional.of(true)).stream().filter(x -> x.getId() == id)
177
				.collect(Collectors.toList()).get(0);
25882 amit.gupta 178
		bucket.setFofoCatalogResponses(dealResponse);
179
		return responseSender.ok(bucket);
25879 amit.gupta 180
	}
181
 
26846 tejbeer 182
	@RequestMapping(value = "/fofo/suggestedPo", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
183
	public ResponseEntity<?> getSuggestedPo(HttpServletRequest request, @RequestParam int id)
184
			throws ProfitMandiBusinessException {
185
 
186
		List<SuggestedPoDetail> mpd = monthlyPoDetailRepository.selectByPoId(id);
187
		Map<Integer, Integer> itemIdsQtyMap = mpd.stream()
188
				.collect(Collectors.toMap(x -> x.getItemId(), x -> x.getQuantity()));
189
 
190
		Set<Integer> catalogIds = itemRepository.selectByIds(itemIdsQtyMap.keySet()).stream()
191
				.map(x -> x.getCatalogItemId()).collect(Collectors.toSet());
192
		RestClient rc = new RestClient();
193
		Map<String, String> params = new HashMap<>();
194
		List<String> mandatoryQ = new ArrayList<>();
195
		mandatoryQ.add(
196
				String.format("+catalogId_i:(%s) +{!parent which=\"id:catalog*\"}", StringUtils.join(catalogIds, " ")));
197
		params.put("start", "0");
198
		params.put("rows", "100");
199
		params.put("q", StringUtils.join(mandatoryQ, " "));
200
		params.put("fl", "*, [child parentFilter=id:catalog*]");
201
 
202
		params.put("wt", "json");
203
		String response = null;
204
		try {
205
			response = rc.get(SchemeType.HTTP, "50.116.10.120", 8984, "solr/demo/select", params);
206
		} catch (HttpHostConnectException e) {
207
			throw new ProfitMandiBusinessException("", "", "Could not connect to host");
208
		}
209
		JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
210
		JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
211
		List<FofoCatalogResponse> dealResponse = getCatalogSingleSkuResponse(docs, itemIdsQtyMap, false);
212
 
213
		return responseSender.ok(dealResponse);
214
	}
215
 
26847 tejbeer 216
	@RequestMapping(value = "/suggestedPo/status", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
217
	public ResponseEntity<?> changeSuggestedPoStatus(HttpServletRequest request, @RequestParam int id)
218
			throws ProfitMandiBusinessException {
219
		SuggestedPo suggestedPo = suggestedPoRepository.selectById(id);
220
		suggestedPo.setStatus("closed");
221
 
222
		return responseSender.ok(true);
223
	}
224
 
23816 amit.gupta 225
	private String getCommaSeparateTags(int userId) {
22361 amit.gupta 226
		UserCart uc = userAccountRepository.getUserCart(userId);
227
		List<Integer> tagIds = pricingService.getTagsIdsByRetailerId(uc.getUserId());
22287 amit.gupta 228
		List<String> strTagIds = new ArrayList<>();
229
		for (Integer tagId : tagIds) {
230
			strTagIds.add(String.valueOf(tagId));
22273 amit.gupta 231
		}
22287 amit.gupta 232
		return String.join(",", strTagIds);
22273 amit.gupta 233
	}
234
 
22319 amit.gupta 235
	@ApiImplicitParams({
236
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
237
	@RequestMapping(value = "/fofo", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
24091 tejbeer 238
	public ResponseEntity<?> getFofo(HttpServletRequest request,
26758 amit.gupta 239
			@RequestParam(value = "categoryId", required = false, defaultValue = "3") String categoryId,
22319 amit.gupta 240
			@RequestParam(value = "offset") String offset, @RequestParam(value = "limit") String limit,
23816 amit.gupta 241
			@RequestParam(value = "sort", required = false) String sort,
242
			@RequestParam(value = "brand", required = false) String brand,
25011 amit.gupta 243
			@RequestParam(value = "subCategoryId", required = false) int subCategoryId,
24946 amit.gupta 244
			@RequestParam(value = "q", required = false) String queryTerm,
24091 tejbeer 245
			@RequestParam(value = "hotDeal", required = false) boolean hotDeal) throws Throwable {
22328 amit.gupta 246
		List<FofoCatalogResponse> dealResponse = new ArrayList<>();
22319 amit.gupta 247
		UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
23786 amit.gupta 248
		if (roleManagerService.isPartner(userInfo.getRoleIds())) {
25879 amit.gupta 249
			// UserCart uc = userAccountRepository.getUserCart(userInfo.getUserId());
25389 tejbeer 250
			List<Integer> tagIds = pricingService.getTagsIdsByRetailerId(userInfo.getRetailerId());
23816 amit.gupta 251
			RestClient rc = new RestClient();
22319 amit.gupta 252
			Map<String, String> params = new HashMap<>();
22336 amit.gupta 253
			List<String> mandatoryQ = new ArrayList<>();
24974 amit.gupta 254
			if (queryTerm != null && !queryTerm.equals("null")) {
24975 amit.gupta 255
				mandatoryQ.add(String.format("+(%s)", queryTerm));
256
			} else {
257
				queryTerm = null;
24971 amit.gupta 258
			}
25015 amit.gupta 259
			if (subCategoryId != 0) {
24949 amit.gupta 260
				mandatoryQ
261
						.add(String.format("+(subCategoryId_i:%s) +{!parent which=\"subCategoryId_i:%s\"} tagId_i:(%s)",
24875 amit.gupta 262
								subCategoryId, subCategoryId, StringUtils.join(tagIds, " ")));
23814 amit.gupta 263
			} else if (hotDeal) {
23816 amit.gupta 264
				mandatoryQ.add(String.format("+{!parent which=\"hot_deals_b=true\"} tagId_i:(%s)",
265
						StringUtils.join(tagIds, " ")));
25015 amit.gupta 266
 
267
			} else if (StringUtils.isNotBlank(brand)) {
268
				mandatoryQ.add(
269
						String.format("+(categoryId_i:%s) +(brand_ss:%s) +{!parent which=\"brand_ss:%s\"} tagId_i:(%s)",
270
								categoryId, brand, brand, StringUtils.join(tagIds, " ")));
271
 
22347 amit.gupta 272
			} else {
26789 amit.gupta 273
				mandatoryQ
26846 tejbeer 274
						.add(String.format("+(subCategoryId_i:%s) +{!parent which=\"subCategoryId_i:%s\"} tagId_i:(%s)",
275
								categoryId, categoryId, StringUtils.join(tagIds, " ")));
22336 amit.gupta 276
			}
23816 amit.gupta 277
			params.put("q", StringUtils.join(mandatoryQ, " "));
22319 amit.gupta 278
			params.put("fl", "*, [child parentFilter=id:catalog*]");
24995 amit.gupta 279
			if (queryTerm == null) {
24975 amit.gupta 280
				params.put("sort", "create_s desc");
281
			}
22319 amit.gupta 282
			params.put("start", String.valueOf(offset));
283
			params.put("rows", String.valueOf(limit));
284
			params.put("wt", "json");
23532 amit.gupta 285
			String response = null;
286
			try {
26575 amit.gupta 287
				response = rc.get(SchemeType.HTTP, "50.116.10.120", 8984, "solr/demo/select", params);
23532 amit.gupta 288
			} catch (HttpHostConnectException e) {
289
				throw new ProfitMandiBusinessException("", "", "Could not connect to host");
290
			}
22319 amit.gupta 291
			JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
292
			JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
24149 amit.gupta 293
			dealResponse = getCatalogResponse(docs, hotDeal);
26589 amit.gupta 294
			/*
295
			 * if (Mongo.PARTNER_BLoCKED_BRANDS.containsKey(userInfo.getEmail())) {
296
			 * dealResponse.stream() .filter(x ->
297
			 * Mongo.PARTNER_BLoCKED_BRANDS.get(userInfo.getEmail()).contains(x.getBrand()))
298
			 * ; }
299
			 */
300
		} else {
301
			return responseSender.badRequest(
302
					new ProfitMandiBusinessException("Retailer id", userInfo.getUserId(), "NOT_FOFO_RETAILER"));
303
		}
304
		return responseSender.ok(dealResponse);
305
	}
306
 
307
	@ApiImplicitParams({
308
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
309
	@RequestMapping(value = "/partnerStock", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
310
	public ResponseEntity<?> partnerStock(HttpServletRequest request,
26758 amit.gupta 311
			@RequestParam(value = "categoryId", required = false, defaultValue = "3") String categoryId,
26589 amit.gupta 312
			@RequestParam(value = "offset") String offset, @RequestParam(value = "limit") String limit,
313
			@RequestParam(value = "sort", required = false) String sort,
314
			@RequestParam(value = "brand", required = false) String brand,
315
			@RequestParam(value = "subCategoryId", required = false) int subCategoryId,
316
			@RequestParam(value = "q", required = false) String queryTerm,
317
			@RequestParam(value = " ", required = false, defaultValue = "true") boolean partnerStockOnly)
318
			throws Throwable {
319
		List<FofoCatalogResponse> dealResponse = new ArrayList<>();
320
		UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
321
		UserCart uc = userAccountRepository.getUserCart(userInfo.getUserId());
26846 tejbeer 322
 
26589 amit.gupta 323
		logger.info("Retiler Id ==> {}", uc.getUserId());
324
		if (roleManagerService.isPartner(userInfo.getRoleIds())) {
26846 tejbeer 325
			if (partnerStockOnly) {
326
 
24168 amit.gupta 327
			}
26589 amit.gupta 328
			List<Integer> tagIds = pricingService.getTagsIdsByRetailerId(userInfo.getRetailerId());
329
			RestClient rc = new RestClient();
330
			Map<String, String> params = new HashMap<>();
331
			List<String> mandatoryQ = new ArrayList<>();
332
			if (queryTerm != null && !queryTerm.equals("null")) {
333
				mandatoryQ.add(String.format("+(%s)", queryTerm));
334
			} else {
335
				queryTerm = null;
336
			}
337
			if (subCategoryId != 0) {
338
				mandatoryQ
339
						.add(String.format("+(subCategoryId_i:%s) +{!parent which=\"subCategoryId_i:%s\"} tagId_i:(%s)",
340
								subCategoryId, subCategoryId, StringUtils.join(tagIds, " ")));
341
			} else if (StringUtils.isNotBlank(brand)) {
342
				mandatoryQ.add(
343
						String.format("+(categoryId_i:%s) +(brand_ss:%s) +{!parent which=\"brand_ss:%s\"} tagId_i:(%s)",
344
								categoryId, brand, brand, StringUtils.join(tagIds, " ")));
345
 
346
			} else {
347
				mandatoryQ.add(
348
						String.format("+{!parent which=\"id:catalog*\"} tagId_i:(%s)", StringUtils.join(tagIds, " ")));
349
			}
350
			params.put("q", StringUtils.join(mandatoryQ, " "));
351
			params.put("fl", "*, [child parentFilter=id:catalog*]");
352
			if (queryTerm == null) {
353
				params.put("sort", "create_s desc");
354
			}
355
			params.put("start", String.valueOf(offset));
356
			params.put("rows", String.valueOf(limit));
357
			params.put("wt", "json");
358
			String response = null;
359
			try {
360
				response = rc.get(SchemeType.HTTP, "50.116.10.120", 8984, "solr/demo/select", params);
361
			} catch (HttpHostConnectException e) {
362
				throw new ProfitMandiBusinessException("", "", "Could not connect to host");
363
			}
364
			JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
365
			JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
366
			dealResponse = getCatalogResponse(docs, false);
367
			/*
368
			 * if (Mongo.PARTNER_BLoCKED_BRANDS.containsKey(userInfo.getEmail())) {
369
			 * dealResponse.stream() .filter(x ->
370
			 * Mongo.PARTNER_BLoCKED_BRANDS.get(userInfo.getEmail()).contains(x.getBrand()))
371
			 * ; }
372
			 */
22319 amit.gupta 373
		} else {
23816 amit.gupta 374
			return responseSender.badRequest(
375
					new ProfitMandiBusinessException("Retailer id", userInfo.getUserId(), "NOT_FOFO_RETAILER"));
22319 amit.gupta 376
		}
377
		return responseSender.ok(dealResponse);
378
	}
22273 amit.gupta 379
 
22319 amit.gupta 380
	@RequestMapping(value = "/online-deals", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
22272 amit.gupta 381
	@ApiImplicitParams({
22319 amit.gupta 382
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
22272 amit.gupta 383
	@ApiOperation(value = "Get online deals")
22319 amit.gupta 384
	public ResponseEntity<?> getOnlineDeals(HttpServletRequest request,
385
			@RequestParam(value = "categoryId") String categoryId, @RequestParam(value = "offset") String offset,
386
			@RequestParam(value = "limit") String limit, @RequestParam(value = "sort", required = false) String sort,
387
			@RequestParam(value = "direction", required = false) String direction,
388
			@RequestParam(value = "filterData", required = false) String filterData) throws Throwable {
389
		logger.info("Request " + request.getParameterMap());
22272 amit.gupta 390
		String response = null;
22319 amit.gupta 391
		int userId = (int) request.getAttribute("userId");
22289 amit.gupta 392
 
22319 amit.gupta 393
		String uri = "/deals/" + userId;
23532 amit.gupta 394
		RestClient rc = new RestClient();
22272 amit.gupta 395
		Map<String, String> params = new HashMap<>();
396
		params.put("offset", offset);
397
		params.put("limit", limit);
398
		params.put("categoryId", categoryId);
399
		params.put("direction", direction);
400
		params.put("sort", sort);
401
		params.put("source", "online");
402
		params.put("filterData", filterData);
23816 amit.gupta 403
		/*
404
		 * if (userInfo.getRoleNames().contains(RoleType.FOFO.toString())) {
405
		 * params.put("tag_ids", getCommaSeparateTags(userId)); }
406
		 */
22272 amit.gupta 407
		List<Object> responseObject = new ArrayList<>();
23532 amit.gupta 408
		try {
409
			response = rc.get(SchemeType.HTTP, host, port, uri, params);
410
		} catch (HttpHostConnectException e) {
411
			throw new ProfitMandiBusinessException("", "", "Could not connect to host");
412
		}
22931 ashik.ali 413
 
22272 amit.gupta 414
		JsonArray result_json = Json.parse(response).asArray();
22319 amit.gupta 415
		for (JsonValue j : result_json) {
23816 amit.gupta 416
			// logger.info("res " + j.asArray());
22272 amit.gupta 417
			List<Object> innerObject = new ArrayList<>();
22319 amit.gupta 418
			for (JsonValue jsonObject : j.asArray()) {
22272 amit.gupta 419
				innerObject.add(toDealObject(jsonObject.asObject()));
420
			}
22319 amit.gupta 421
			if (innerObject.size() > 0) {
22272 amit.gupta 422
				responseObject.add(innerObject);
423
			}
424
		}
23022 ashik.ali 425
		return responseSender.ok(responseObject);
22272 amit.gupta 426
	}
427
 
22319 amit.gupta 428
	private Object toDealObject(JsonObject jsonObject) {
429
		if (jsonObject.get("dealObject") != null && jsonObject.get("dealObject").asInt() == 1) {
21339 kshitij.so 430
			return new Gson().fromJson(jsonObject.toString(), DealObjectResponse.class);
431
		}
432
		return new Gson().fromJson(jsonObject.toString(), DealsResponse.class);
433
	}
22319 amit.gupta 434
 
435
	@RequestMapping(value = ProfitMandiConstants.URL_BRANDS, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
21356 kshitij.so 436
	@ApiImplicitParams({
22319 amit.gupta 437
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
21356 kshitij.so 438
	@ApiOperation(value = "Get brand list and count for category")
22319 amit.gupta 439
	public ResponseEntity<?> getBrands(HttpServletRequest request,
23816 amit.gupta 440
			@RequestParam(value = "category_id") String category_id) throws ProfitMandiBusinessException {
22319 amit.gupta 441
		logger.info("Request " + request.getParameterMap());
21356 kshitij.so 442
		String response = null;
22319 amit.gupta 443
		// TODO: move to properties
21356 kshitij.so 444
		String uri = ProfitMandiConstants.URL_BRANDS;
23532 amit.gupta 445
		RestClient rc = new RestClient();
21356 kshitij.so 446
		Map<String, String> params = new HashMap<>();
447
		params.put("category_id", category_id);
21358 kshitij.so 448
		List<DealBrands> dealBrandsResponse = null;
23532 amit.gupta 449
		try {
450
			response = rc.get(SchemeType.HTTP, host, port, uri, params);
451
		} catch (HttpHostConnectException e) {
452
			throw new ProfitMandiBusinessException("", "", "Could not connect to host");
453
		}
23816 amit.gupta 454
 
22319 amit.gupta 455
		dealBrandsResponse = new Gson().fromJson(response, new TypeToken<List<DealBrands>>() {
456
		}.getType());
23022 ashik.ali 457
 
458
		return responseSender.ok(dealBrandsResponse);
21356 kshitij.so 459
	}
22319 amit.gupta 460
 
461
	@RequestMapping(value = ProfitMandiConstants.URL_UNIT_DEAL, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
21445 kshitij.so 462
	@ApiImplicitParams({
22319 amit.gupta 463
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
21445 kshitij.so 464
	@ApiOperation(value = "Get unit deal object")
23816 amit.gupta 465
	public ResponseEntity<?> getUnitDeal(HttpServletRequest request, @PathVariable(value = "id") long id)
466
			throws ProfitMandiBusinessException {
21445 kshitij.so 467
		String response = null;
22319 amit.gupta 468
		// TODO: move to properties
469
		String uri = "getDealById/" + id;
470
		System.out.println("Unit deal " + uri);
23532 amit.gupta 471
		RestClient rc = new RestClient();
21445 kshitij.so 472
		Map<String, String> params = new HashMap<>();
473
		DealsResponse dealsResponse = null;
23532 amit.gupta 474
		try {
475
			response = rc.get(SchemeType.HTTP, host, port, uri, params);
476
		} catch (HttpHostConnectException e) {
477
			throw new ProfitMandiBusinessException("", "", "Could not connect to host");
478
		}
23816 amit.gupta 479
 
21445 kshitij.so 480
		JsonObject result_json = Json.parse(response).asObject();
22319 amit.gupta 481
		if (!result_json.isEmpty()) {
21445 kshitij.so 482
			dealsResponse = new Gson().fromJson(response, DealsResponse.class);
22952 amit.gupta 483
			Iterator<AvailabilityInfo> iter = dealsResponse.getAvailabilityInfo().iterator();
23816 amit.gupta 484
			while (iter.hasNext()) {
22952 amit.gupta 485
				AvailabilityInfo ai = iter.next();
23816 amit.gupta 486
				if (ai.getAvailability() <= 0)
22952 amit.gupta 487
					iter.remove();
488
			}
21445 kshitij.so 489
		}
22952 amit.gupta 490
		return responseSender.ok(dealsResponse);
21445 kshitij.so 491
	}
23816 amit.gupta 492
 
24091 tejbeer 493
	@RequestMapping(value = "/partnerdeals/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
494
	@ApiImplicitParams({
495
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
496
	@ApiOperation(value = "Get unit deal object")
497
	public ResponseEntity<?> getUnitFocoDeal(HttpServletRequest request, @PathVariable(value = "id") long id)
498
			throws ProfitMandiBusinessException {
499
		List<FofoCatalogResponse> dealResponse = new ArrayList<>();
500
		List<Integer> tagIds = Arrays.asList(4);
501
		UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
502
		if (roleManagerService.isPartner(userInfo.getRoleIds())) {
503
			String categoryId = "(3 OR 6)";
504
			UserCart uc = userAccountRepository.getUserCart(userInfo.getUserId());
505
			RestClient rc = new RestClient();
506
			Map<String, String> params = new HashMap<>();
507
			List<String> mandatoryQ = new ArrayList<>();
508
			String catalogString = "catalog" + id;
509
 
24149 amit.gupta 510
			mandatoryQ.add(String.format("+(categoryId_i:%s) +(id:%s) +{!parent which=\"id:%s\"} tagId_i:(%s)",
511
					categoryId, catalogString, catalogString, StringUtils.join(tagIds, " ")));
512
 
24091 tejbeer 513
			params.put("q", StringUtils.join(mandatoryQ, " "));
514
			params.put("fl", "*, [child parentFilter=id:catalog*]");
515
			params.put("sort", "rank_i asc, create_s desc");
516
			params.put("wt", "json");
517
			String response = null;
518
			try {
26575 amit.gupta 519
				response = rc.get(SchemeType.HTTP, "50.116.10.120", 8984, "solr/demo/select", params);
24091 tejbeer 520
			} catch (HttpHostConnectException e) {
521
				throw new ProfitMandiBusinessException("", "", "Could not connect to host");
522
			}
523
			JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
524
			JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
24149 amit.gupta 525
			dealResponse = getCatalogResponse(docs, false);
24091 tejbeer 526
		} else {
527
			return responseSender.badRequest(
528
					new ProfitMandiBusinessException("Retailer id", userInfo.getUserId(), "NOT_FOFO_RETAILER"));
529
		}
530
		return responseSender.ok(dealResponse.get(0));
531
	}
532
 
22333 amit.gupta 533
	@RequestMapping(value = "/fofo/brands", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
24949 amit.gupta 534
	public ResponseEntity<?> getBrandsToDisplay(HttpServletRequest request,
25010 amit.gupta 535
			@RequestParam(required = false, defaultValue = "0") int categoryId) throws Exception {
24163 amit.gupta 536
		UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
25543 amit.gupta 537
		logger.info("userInfo [{}]", userInfo);
25879 amit.gupta 538
		List<DBObject> brandsDisplay = mongoClient.getMongoBrands(userInfo.getRetailerId(), userInfo.getEmail(),
539
				categoryId);
24163 amit.gupta 540
		return new ResponseEntity<>(brandsDisplay, HttpStatus.OK);
22333 amit.gupta 541
	}
25879 amit.gupta 542
 
25813 amit.gupta 543
	@RequestMapping(value = "/fofo/accessory/all-categories", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
544
	public ResponseEntity<?> getSubCategoriesToDisplay(HttpServletRequest request) throws Exception {
545
		UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
546
		logger.info("userInfo [{}]", userInfo);
547
		List<DBObject> subCateogriesDisplay = this.getSubCategoriesToDisplay();
548
		return new ResponseEntity<>(subCateogriesDisplay, HttpStatus.OK);
549
	}
23816 amit.gupta 550
 
25011 amit.gupta 551
	private List<DBObject> getSubCategoriesToDisplay() throws Exception {
25010 amit.gupta 552
		List<DBObject> subCategories = new ArrayList<>();
553
		RestClient rc = new RestClient();
554
		Map<String, String> params = new HashMap<>();
555
		params.put("q", "categoryId_i:6");
556
		params.put("group", "true");
557
		params.put("group.field", "subCategoryId_i");
558
		params.put("wt", "json");
25126 amit.gupta 559
		params.put("rows", "50");
25014 amit.gupta 560
		params.put("fl", "subCategoryId_i");
25010 amit.gupta 561
		String response = null;
562
		try {
26575 amit.gupta 563
			response = rc.get(SchemeType.HTTP, "50.116.10.120", 8984, "solr/demo/select", params);
25010 amit.gupta 564
		} catch (HttpHostConnectException e) {
565
			throw new ProfitMandiBusinessException("", "", "Could not connect to host");
566
		}
567
		JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("grouped");
568
		JSONArray groups = solrResponseJSONObj.getJSONObject("subCategoryId_i").getJSONArray("groups");
569
		List<Integer> categoryIds = new ArrayList<>();
25015 amit.gupta 570
		for (int i = 0; i < groups.length(); i++) {
571
			JSONObject groupObject = groups.getJSONObject(i);
572
			int subCategoryId = groupObject.getInt("groupValue");
25010 amit.gupta 573
			int quantity = groupObject.getJSONObject("doclist").getInt("numFound");
25013 amit.gupta 574
			categoryIds.add(subCategoryId);
25010 amit.gupta 575
		}
25015 amit.gupta 576
 
25010 amit.gupta 577
		List<Category> categories = categoryRepository.selectByIds(categoryIds);
25015 amit.gupta 578
		AtomicInteger i = new AtomicInteger(0);
579
		categories.forEach(x -> {
25011 amit.gupta 580
			DBObject dbObject = new BasicDBObject();
581
			dbObject.put("name", x.getLabel());
582
			dbObject.put("subCategoryId", x.getId());
583
			dbObject.put("rank", i.incrementAndGet());
584
			dbObject.put("categoryId", 6);
26441 tejbeer 585
			dbObject.put("url", "https://images.smartdukaan.com/uploads/campaigns/" + x.getId() + ".png");
25011 amit.gupta 586
			subCategories.add(dbObject);
25010 amit.gupta 587
		});
25015 amit.gupta 588
 
25011 amit.gupta 589
		return subCategories;
25015 amit.gupta 590
 
25010 amit.gupta 591
	}
592
 
22446 amit.gupta 593
	@RequestMapping(value = "/banners/{bannerType}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
22448 amit.gupta 594
	public ResponseEntity<?> getBanners(@PathVariable String bannerType) {
22447 amit.gupta 595
		return new ResponseEntity<>(mongoClient.getBannersByType(bannerType), HttpStatus.OK);
22446 amit.gupta 596
	}
23816 amit.gupta 597
 
23793 tejbeer 598
	@RequestMapping(value = "/deals/subCategories", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
599
	public ResponseEntity<?> getSubcategoriesToDisplay() {
600
		return new ResponseEntity<>(mongoClient.getSubcategoriesToDisplay(), HttpStatus.OK);
601
	}
23816 amit.gupta 602
 
22406 amit.gupta 603
	@ApiImplicitParams({
23816 amit.gupta 604
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
22401 amit.gupta 605
	@RequestMapping(value = "/deals/skus/{skus}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
22931 ashik.ali 606
	public ResponseEntity<?> getDealsBySkus(@PathVariable String skus) throws ProfitMandiBusinessException {
22401 amit.gupta 607
		StringBuffer sb = new StringBuffer("/getDealsForNotification/");
608
		String uri = sb.append(skus).toString();
23532 amit.gupta 609
		RestClient rc = new RestClient();
610
		String response;
611
		try {
612
			response = rc.get(SchemeType.HTTP, host, port, uri, new HashMap<>());
23816 amit.gupta 613
		} catch (HttpHostConnectException e) {
23532 amit.gupta 614
			throw new ProfitMandiBusinessException("", "", "Could not connect to host");
615
		}
22406 amit.gupta 616
		JsonArray result_json = Json.parse(response).asArray();
22407 amit.gupta 617
		List<Object> responseObject = new ArrayList<>();
618
		for (JsonValue j : result_json) {
23816 amit.gupta 619
			// logger.info("res " + j.asArray());
22407 amit.gupta 620
			List<Object> innerObject = new ArrayList<>();
621
			for (JsonValue jsonObject : j.asArray()) {
622
				innerObject.add(toDealObject(jsonObject.asObject()));
623
			}
624
			if (innerObject.size() > 0) {
625
				responseObject.add(innerObject);
626
			}
627
		}
22408 amit.gupta 628
		return responseSender.ok(responseObject);
22401 amit.gupta 629
	}
21339 kshitij.so 630
 
24149 amit.gupta 631
	private List<FofoCatalogResponse> getCatalogResponse(JSONArray docs, boolean hotDeal)
632
			throws ProfitMandiBusinessException {
24091 tejbeer 633
		Map<Integer, TagListing> itemTagListingMap = null;
634
		List<FofoCatalogResponse> dealResponse = new ArrayList<>();
635
		List<Integer> tagIds = Arrays.asList(4);
636
		if (docs.length() > 0) {
637
			HashSet<Integer> itemsSet = new HashSet<>();
638
			for (int i = 0; i < docs.length(); i++) {
639
				JSONObject doc = docs.getJSONObject(i);
26589 amit.gupta 640
				if (doc.has("_childDocuments_")) {
26515 amit.gupta 641
					for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
642
						JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
643
						int itemId = childItem.getInt("itemId_i");
644
						itemsSet.add(itemId);
645
					}
24091 tejbeer 646
				}
647
			}
26589 amit.gupta 648
			if (itemsSet.size() == 0) {
26573 amit.gupta 649
				return dealResponse;
650
			}
24091 tejbeer 651
			itemTagListingMap = tagListingRepository.selectByItemIdsAndTagIds(itemsSet, new HashSet<>(tagIds)).stream()
652
					.collect(Collectors.toMap(x -> x.getItemId(), x -> x));
653
		}
654
 
655
		for (int i = 0; i < docs.length(); i++) {
656
			Map<Integer, FofoAvailabilityInfo> fofoAvailabilityInfoMap = new HashMap<>();
657
			JSONObject doc = docs.getJSONObject(i);
658
			FofoCatalogResponse ffdr = new FofoCatalogResponse();
659
			ffdr.setCatalogId(doc.getInt("catalogId_i"));
660
			ffdr.setImageUrl(doc.getString("imageUrl_s"));
661
			ffdr.setTitle(doc.getString("title_s"));
24117 amit.gupta 662
			try {
663
				ffdr.setFeature(doc.getString("feature_s"));
24149 amit.gupta 664
			} catch (Exception e) {
24117 amit.gupta 665
				ffdr.setFeature(null);
24149 amit.gupta 666
				logger.info("Could not find Feature_s for {}", ffdr.getCatalogId());
24117 amit.gupta 667
			}
24091 tejbeer 668
			ffdr.setBrand(doc.getJSONArray("brand_ss").getString(0));
26589 amit.gupta 669
			if (doc.has("_childDocuments_")) {
26515 amit.gupta 670
				for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
671
					JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
672
					int itemId = childItem.getInt("itemId_i");
673
					TagListing tl = itemTagListingMap.get(itemId);
674
					if (tl == null) {
675
						logger.warn("Could not find item id {}", itemId);
24091 tejbeer 676
						continue;
677
					}
26515 amit.gupta 678
					if (hotDeal) {
679
						if (!tl.isHotDeals()) {
680
							continue;
681
						}
24091 tejbeer 682
					}
26515 amit.gupta 683
					float sellingPrice = (float) childItem.getDouble("sellingPrice_f");
684
					if (fofoAvailabilityInfoMap.containsKey(itemId)) {
685
						if (fofoAvailabilityInfoMap.get(itemId).getSellingPrice() > sellingPrice) {
686
							fofoAvailabilityInfoMap.get(itemId).setSellingPrice(sellingPrice);
687
							fofoAvailabilityInfoMap.get(itemId).setMop((float) childItem.getDouble("mop_f"));
688
						}
24091 tejbeer 689
					} else {
26515 amit.gupta 690
						FofoAvailabilityInfo fdi = new FofoAvailabilityInfo();
691
						fdi.setSellingPrice((float) childItem.getDouble("sellingPrice_f"));
26846 tejbeer 692
						fdi.setMrp((double) tl.getMrp());
26515 amit.gupta 693
						fdi.setMop((float) childItem.getDouble("mop_f"));
694
						fdi.setColor(childItem.has("color_s") ? childItem.getString("color_s") : "");
695
						fdi.setTagId(childItem.getInt("tagId_i"));
696
						fdi.setItem_id(itemId);
26696 amit.gupta 697
						Float cashBack = schemeService.getItemSchemeCashBack().get(itemId);
26846 tejbeer 698
						cashBack = cashBack == null ? 0 : cashBack;
26696 amit.gupta 699
						fdi.setCashback(cashBack);
26515 amit.gupta 700
						Item item = itemRepository.selectById(itemId);
701
						// In case its tampered glass moq should be 5
702
						if (item.getCategoryId() == 10020) {
703
							fdi.setMinBuyQuantity(10);
704
						} else {
705
							fdi.setMinBuyQuantity(1);
24091 tejbeer 706
						}
26515 amit.gupta 707
						if (hotDeal || !tl.isActive()) {
26589 amit.gupta 708
 
26515 amit.gupta 709
							int totalAvailability = 0; // Using item availability
710
							// cache for now but can be
711
							// changed to
712
							// use caching later.
713
							try {
714
								ItemAvailabilityCache iac = itemAvailabilityCacheRepository.selectByItemId(itemId);
715
								totalAvailability = iac.getTotalAvailability();
716
								fdi.setAvailability(totalAvailability);
717
							} catch (Exception e) {
718
								continue;
719
							}
720
							if (totalAvailability <= 0) {
721
								continue;
722
							}
723
						} else {
724
							// For accessories item availability should at be ordered for Rs.1000
725
							fdi.setAvailability(100);
24091 tejbeer 726
						}
26515 amit.gupta 727
						fdi.setQuantityStep(1);
728
						fdi.setMaxQuantity(Math.min(fdi.getAvailability(), 100));
729
						fofoAvailabilityInfoMap.put(itemId, fdi);
24091 tejbeer 730
					}
731
				}
732
			}
733
			if (fofoAvailabilityInfoMap.values().size() > 0) {
734
				ffdr.setItems(new ArrayList<FofoAvailabilityInfo>(fofoAvailabilityInfoMap.values()));
735
				dealResponse.add(ffdr);
736
			}
737
		}
738
		return dealResponse;
739
 
740
	}
741
 
25968 amit.gupta 742
	private List<FofoCatalogResponse> getCatalogSingleSkuResponse(JSONArray docs, Map<Integer, Integer> itemFilter,
743
			boolean hotDeal) throws ProfitMandiBusinessException {
25879 amit.gupta 744
		Map<Integer, TagListing> itemTagListingMap = null;
745
		List<FofoCatalogResponse> dealResponse = new ArrayList<>();
746
		List<Integer> tagIds = Arrays.asList(4);
26589 amit.gupta 747
 
25968 amit.gupta 748
		itemTagListingMap = tagListingRepository.selectByItemIdsAndTagIds(itemFilter.keySet(), new HashSet<>(tagIds))
749
				.stream().collect(Collectors.toMap(x -> x.getItemId(), x -> x));
25880 amit.gupta 750
 
25879 amit.gupta 751
		for (int i = 0; i < docs.length(); i++) {
752
			Map<Integer, FofoAvailabilityInfo> fofoAvailabilityInfoMap = new HashMap<>();
753
			JSONObject doc = docs.getJSONObject(i);
25880 amit.gupta 754
 
25879 amit.gupta 755
			for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
756
				JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
757
				int itemId = childItem.getInt("itemId_i");
758
				TagListing tl = itemTagListingMap.get(itemId);
26589 amit.gupta 759
				if (tl == null) {
25968 amit.gupta 760
					continue;
761
				}
25879 amit.gupta 762
				if (hotDeal) {
763
					if (!tl.isHotDeals()) {
764
						continue;
765
					}
766
				}
767
				float sellingPrice = (float) childItem.getDouble("sellingPrice_f");
768
				if (fofoAvailabilityInfoMap.containsKey(itemId)) {
769
					if (fofoAvailabilityInfoMap.get(itemId).getSellingPrice() > sellingPrice) {
770
						fofoAvailabilityInfoMap.get(itemId).setSellingPrice(sellingPrice);
771
						fofoAvailabilityInfoMap.get(itemId).setMop((float) childItem.getDouble("mop_f"));
772
					}
773
				} else {
774
					FofoAvailabilityInfo fdi = new FofoAvailabilityInfo();
775
					fdi.setSellingPrice((float) childItem.getDouble("sellingPrice_f"));
776
					fdi.setMop((float) childItem.getDouble("mop_f"));
26665 amit.gupta 777
					fdi.setMop((float) tl.getMrp());
25879 amit.gupta 778
					fdi.setColor(childItem.has("color_s") ? childItem.getString("color_s") : "");
779
					fdi.setTagId(childItem.getInt("tagId_i"));
780
					fdi.setItem_id(itemId);
781
					Item item = itemRepository.selectById(itemId);
782
					// In case its tampered glass moq should be 5
783
					if (item.getCategoryId() == 10020) {
784
						fdi.setMinBuyQuantity(10);
785
					} else {
786
						fdi.setMinBuyQuantity(1);
787
					}
26050 amit.gupta 788
					fdi.setAvailability(itemFilter.get(itemId));
25879 amit.gupta 789
					fdi.setQuantityStep(1);
790
					fdi.setMaxQuantity(Math.min(fdi.getAvailability(), 100));
791
					fofoAvailabilityInfoMap.put(itemId, fdi);
792
				}
793
			}
794
			if (fofoAvailabilityInfoMap.values().size() > 0) {
25880 amit.gupta 795
				for (FofoAvailabilityInfo fofoAvailabilityInfo : fofoAvailabilityInfoMap.values()) {
25879 amit.gupta 796
					FofoCatalogResponse ffdr = new FofoCatalogResponse();
797
					ffdr.setCatalogId(doc.getInt("catalogId_i"));
798
					ffdr.setImageUrl(doc.getString("imageUrl_s"));
799
					ffdr.setTitle(doc.getString("title_s"));
800
					try {
801
						ffdr.setFeature(doc.getString("feature_s"));
802
					} catch (Exception e) {
803
						ffdr.setFeature(null);
804
						logger.info("Could not find Feature_s for {}", ffdr.getCatalogId());
805
					}
806
					ffdr.setBrand(doc.getJSONArray("brand_ss").getString(0));
807
					ffdr.setItems(Arrays.asList(fofoAvailabilityInfo));
808
					dealResponse.add(ffdr);
809
				}
810
			}
811
		}
812
		return dealResponse;
25880 amit.gupta 813
 
25879 amit.gupta 814
	}
25967 amit.gupta 815
}