Subversion Repositories SmartDukaan

Rev

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