Subversion Repositories SmartDukaan

Rev

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