Subversion Repositories SmartDukaan

Rev

Rev 23404 | Rev 23532 | 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;
22952 amit.gupta 6
import java.util.Iterator;
21339 kshitij.so 7
import java.util.List;
8
import java.util.Map;
9
 
10
import javax.servlet.http.HttpServletRequest;
11
 
22319 amit.gupta 12
import org.apache.commons.lang3.StringUtils;
13
import org.json.JSONArray;
14
import org.json.JSONObject;
21339 kshitij.so 15
import org.slf4j.Logger;
16
import org.slf4j.LoggerFactory;
22273 amit.gupta 17
import org.springframework.beans.factory.annotation.Autowired;
21339 kshitij.so 18
import org.springframework.beans.factory.annotation.Value;
19
import org.springframework.http.HttpStatus;
20
import org.springframework.http.MediaType;
21
import org.springframework.http.ResponseEntity;
22
import org.springframework.stereotype.Controller;
22286 amit.gupta 23
import org.springframework.transaction.annotation.Transactional;
21339 kshitij.so 24
import org.springframework.web.bind.annotation.PathVariable;
25
import org.springframework.web.bind.annotation.RequestMapping;
26
import org.springframework.web.bind.annotation.RequestMethod;
27
import org.springframework.web.bind.annotation.RequestParam;
28
 
29
import com.eclipsesource.json.Json;
30
import com.eclipsesource.json.JsonArray;
31
import com.eclipsesource.json.JsonObject;
32
import com.eclipsesource.json.JsonValue;
33
import com.google.gson.Gson;
21356 kshitij.so 34
import com.google.gson.reflect.TypeToken;
21643 ashik.ali 35
import com.spice.profitmandi.common.enumuration.SchemeType;
21339 kshitij.so 36
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
37
import com.spice.profitmandi.common.model.ProfitMandiConstants;
22289 amit.gupta 38
import com.spice.profitmandi.common.model.UserInfo;
21643 ashik.ali 39
import com.spice.profitmandi.common.web.client.RestClient;
22319 amit.gupta 40
import com.spice.profitmandi.common.web.util.ResponseSender;
23426 amit.gupta 41
import com.spice.profitmandi.dao.entity.catalog.Item;
22289 amit.gupta 42
import com.spice.profitmandi.dao.enumuration.dtr.RoleType;
22361 amit.gupta 43
import com.spice.profitmandi.dao.model.UserCart;
23426 amit.gupta 44
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
22333 amit.gupta 45
import com.spice.profitmandi.dao.repository.dtr.Mongo;
22361 amit.gupta 46
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
22989 amit.gupta 47
import com.spice.profitmandi.dao.repository.inventory.ItemAvailabilityCacheRepository;
22931 ashik.ali 48
import com.spice.profitmandi.service.inventory.InventoryService;
22287 amit.gupta 49
import com.spice.profitmandi.service.pricing.PricingService;
22952 amit.gupta 50
import com.spice.profitmandi.web.res.AvailabilityInfo;
21356 kshitij.so 51
import com.spice.profitmandi.web.res.DealBrands;
21339 kshitij.so 52
import com.spice.profitmandi.web.res.DealObjectResponse;
53
import com.spice.profitmandi.web.res.DealsResponse;
22328 amit.gupta 54
import com.spice.profitmandi.web.res.FofoAvailabilityInfo;
55
import com.spice.profitmandi.web.res.FofoCatalogResponse;
21339 kshitij.so 56
 
57
import io.swagger.annotations.ApiImplicitParam;
58
import io.swagger.annotations.ApiImplicitParams;
59
import io.swagger.annotations.ApiOperation;
60
 
61
@Controller
22319 amit.gupta 62
@Transactional(rollbackFor = Throwable.class)
21339 kshitij.so 63
public class DealsController {
64
 
22319 amit.gupta 65
	private static final Logger logger = LoggerFactory.getLogger(DealsController.class);
21339 kshitij.so 66
 
67
	@Value("${python.api.host}")
68
	private String host;
22931 ashik.ali 69
 
21339 kshitij.so 70
	@Value("${python.api.port}")
71
	private int port;
22708 amit.gupta 72
 
22989 amit.gupta 73
	//This is now unused as we are not supporting multiple companies.
23300 amit.gupta 74
	@Value("${gadgetCops.invoice.cc}")
75
	private String[] ccGadgetCopInvoiceTo; 
22319 amit.gupta 76
 
77
	@Autowired
78
	private PricingService pricingService;
22273 amit.gupta 79
 
80
	@Autowired
22333 amit.gupta 81
	private Mongo mongoClient;
82
 
83
	@Autowired
22361 amit.gupta 84
	private UserAccountRepository userAccountRepository;
85
 
86
	@Autowired
22989 amit.gupta 87
	private ItemAvailabilityCacheRepository itemAvailabilityCacheRepository;
88
 
89
	@Autowired
22931 ashik.ali 90
	private ResponseSender<?> responseSender;
22336 amit.gupta 91
 
22554 amit.gupta 92
	@Autowired
22931 ashik.ali 93
	private InventoryService inventoryService;
22401 amit.gupta 94
 
23426 amit.gupta 95
	@Autowired
96
	private ItemRepository itemRepository;
22554 amit.gupta 97
 
23426 amit.gupta 98
 
22336 amit.gupta 99
	List<String> filterableParams = Arrays.asList("brand");
21339 kshitij.so 100
 
22319 amit.gupta 101
	@RequestMapping(value = ProfitMandiConstants.URL_DEALS, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
21339 kshitij.so 102
	@ApiImplicitParams({
22319 amit.gupta 103
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
21339 kshitij.so 104
	@ApiOperation(value = "Get deals")
22319 amit.gupta 105
	public ResponseEntity<?> getDeals(HttpServletRequest request, @RequestParam(value = "categoryId") String categoryId,
106
			@RequestParam(value = "offset") String offset, @RequestParam(value = "limit") String limit,
107
			@RequestParam(value = "sort", required = false) String sort,
108
			@RequestParam(value = "direction", required = false) String direction,
22931 ashik.ali 109
			@RequestParam(value = "filterData", required = false) String filterData) throws ProfitMandiBusinessException {
22319 amit.gupta 110
		logger.info("Request " + request.getParameterMap());
21339 kshitij.so 111
		String response = null;
22319 amit.gupta 112
		int userId = (int) request.getAttribute("userId");
22988 amit.gupta 113
 
114
		//If pincode belongs to Specific warehouse marked
115
		//availability should be fetched for that warehouse only
116
		//show only skus belonging to that specific
117
		//else use normal flow
22319 amit.gupta 118
		UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
119
		// TODO: move to properties
120
		String uri = "/deals/" + userId;
121
		RestClient rc = new RestClient(SchemeType.HTTP, host, port);
21339 kshitij.so 122
		Map<String, String> params = new HashMap<>();
123
		params.put("offset", offset);
124
		params.put("limit", limit);
125
		params.put("categoryId", categoryId);
126
		params.put("direction", direction);
127
		params.put("sort", sort);
128
		params.put("filterData", filterData);
22272 amit.gupta 129
		params.put("source", "deals");
22319 amit.gupta 130
		if (userInfo.getRoleNames().contains(RoleType.FOFO.toString())) {
22289 amit.gupta 131
			params.put("tag_ids", getCommaSeparateTags(userId));
132
		}
21356 kshitij.so 133
		List<Object> responseObject = new ArrayList<>();
22931 ashik.ali 134
		response = rc.get(uri, params);
135
 
21339 kshitij.so 136
		JsonArray result_json = Json.parse(response).asArray();
22319 amit.gupta 137
		for (JsonValue j : result_json) {
22842 amit.gupta 138
			//logger.info("res " + j.asArray());
21339 kshitij.so 139
			List<Object> innerObject = new ArrayList<>();
22319 amit.gupta 140
			for (JsonValue jsonObject : j.asArray()) {
21356 kshitij.so 141
				innerObject.add(toDealObject(jsonObject.asObject()));
21339 kshitij.so 142
			}
22319 amit.gupta 143
			if (innerObject.size() > 0) {
21339 kshitij.so 144
				responseObject.add(innerObject);
145
			}
146
		}
23022 ashik.ali 147
		return responseSender.ok(responseObject);
21339 kshitij.so 148
	}
149
 
22931 ashik.ali 150
	private String getCommaSeparateTags(int userId){
22361 amit.gupta 151
		UserCart uc = userAccountRepository.getUserCart(userId);
152
		List<Integer> tagIds = pricingService.getTagsIdsByRetailerId(uc.getUserId());
22287 amit.gupta 153
		List<String> strTagIds = new ArrayList<>();
154
		for (Integer tagId : tagIds) {
155
			strTagIds.add(String.valueOf(tagId));
22273 amit.gupta 156
		}
22287 amit.gupta 157
		return String.join(",", strTagIds);
22273 amit.gupta 158
	}
159
 
22319 amit.gupta 160
	@ApiImplicitParams({
161
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
162
	@RequestMapping(value = "/fofo", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
163
	public ResponseEntity<?> getFofo(HttpServletRequest request, @RequestParam(value = "categoryId") String categoryId,
164
			@RequestParam(value = "offset") String offset, @RequestParam(value = "limit") String limit,
22336 amit.gupta 165
			@RequestParam(value = "sort", required = false) String sort, @RequestParam(value = "brand", required = false) String brand) throws Throwable {
22328 amit.gupta 166
		List<FofoCatalogResponse> dealResponse = new ArrayList<>();
22319 amit.gupta 167
		UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
168
		if (userInfo.getRoleNames().contains(RoleType.FOFO.toString())) {
22361 amit.gupta 169
			UserCart uc = userAccountRepository.getUserCart(userInfo.getUserId());
170
			List<Integer> tagIds = pricingService.getTagsIdsByRetailerId(uc.getUserId());
22319 amit.gupta 171
			RestClient rc  = new RestClient(SchemeType.HTTP, "dtr", 8984);
172
			Map<String, String> params = new HashMap<>();
22336 amit.gupta 173
			List<String> mandatoryQ = new ArrayList<>();
174
			if(brand != null) {
22347 amit.gupta 175
 
22348 amit.gupta 176
				mandatoryQ.add(String.format("+{!parent which=\"brand_s=%s\"} tagId_i:(%s)", brand, StringUtils.join(tagIds, " ")));
22347 amit.gupta 177
			} else {
178
				mandatoryQ.add(String.format("+{!parent which=\"id:catalog*\"} tagId_i:(%s)", StringUtils.join(tagIds, " ")));
22336 amit.gupta 179
			}
22340 amit.gupta 180
			params.put("q", StringUtils.join(mandatoryQ," "));
22319 amit.gupta 181
			params.put("fl", "*, [child parentFilter=id:catalog*]");
182
			params.put("sort", "rank_i asc");
183
			params.put("start", String.valueOf(offset));
184
			params.put("rows", String.valueOf(limit));
185
			params.put("wt", "json");
22330 amit.gupta 186
			logger.info(rc.getUrl());
22319 amit.gupta 187
			String response  =rc.get("solr/demo/select", params);
188
			JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
189
			JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
190
			for(int i=0; i < docs.length(); i++) {
22328 amit.gupta 191
				Map<Integer, FofoAvailabilityInfo> fofoAvailabilityInfoMap = new HashMap<>();
22319 amit.gupta 192
				JSONObject doc = docs.getJSONObject(i);
22328 amit.gupta 193
				FofoCatalogResponse ffdr = new FofoCatalogResponse();
22319 amit.gupta 194
				ffdr.setCatalogId(doc.getInt("catalogId_i"));
195
				ffdr.setImageUrl(doc.getString("imageUrl_s"));
196
				ffdr.setTitle(doc.getString("title_s"));
22333 amit.gupta 197
				ffdr.setBrand(doc.getString("brand_s"));
22323 amit.gupta 198
				for(int j=0; j< doc.getJSONArray("_childDocuments_").length(); j++) {
199
					JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
22319 amit.gupta 200
					int itemId = childItem.getInt("itemId_i");
201
					float sellingPrice = (float)childItem.getDouble("sellingPrice_f");
22328 amit.gupta 202
					if(fofoAvailabilityInfoMap.containsKey(itemId)) {
203
						if(fofoAvailabilityInfoMap.get(itemId).getSellingPrice() > sellingPrice) {
204
							fofoAvailabilityInfoMap.get(itemId).setSellingPrice(sellingPrice);
205
							fofoAvailabilityInfoMap.get(itemId).setMop((float)childItem.getDouble("mop_f"));
22319 amit.gupta 206
						} 
207
					} else {
22328 amit.gupta 208
							FofoAvailabilityInfo fdi = new FofoAvailabilityInfo();
22319 amit.gupta 209
							fdi.setSellingPrice((float)childItem.getDouble("sellingPrice_f"));
210
							fdi.setMop((float)childItem.getDouble("mop_f"));
22324 amit.gupta 211
							fdi.setColor(childItem.has("color_s")?childItem.getString("color_s"): "");
22319 amit.gupta 212
							fdi.setTagId(childItem.getInt("tagId_i"));
22328 amit.gupta 213
							fdi.setItem_id(itemId);
23404 amit.gupta 214
							/*int totalAvailability = 0;
22989 amit.gupta 215
							//Using item availability cache for now but can be changed to use caching later.
216
							try {
217
								ItemAvailabilityCache iac = itemAvailabilityCacheRepository.selectByItemId(itemId);
218
								totalAvailability = iac.getTotalAvailability();
219
							} catch (Exception e) {}
22990 amit.gupta 220
							if(totalAvailability <= 0){
221
								continue;
23404 amit.gupta 222
							}*/
23426 amit.gupta 223
							Item item = itemRepository.selectById(itemId);
224
							//In case its tampered glass moq should be 5
225
							if(item.getCategoryId()==10020) {
226
								fdi.setMinBuyQuantity(5);
227
							} else {
228
								fdi.setMinBuyQuantity(1);
229
							}
23404 amit.gupta 230
							fdi.setAvailability(10);
22328 amit.gupta 231
							fdi.setQuantityStep(1);
22561 amit.gupta 232
							fdi.setMaxQuantity(Math.min(fdi.getAvailability(), 100));
22990 amit.gupta 233
							fofoAvailabilityInfoMap.put(itemId, fdi);
22319 amit.gupta 234
					}
235
				}
22988 amit.gupta 236
				if(fofoAvailabilityInfoMap.values().size() > 0) {
237
					ffdr.setItems(new ArrayList<FofoAvailabilityInfo>(fofoAvailabilityInfoMap.values()));
238
					dealResponse.add(ffdr);
239
				}
22319 amit.gupta 240
			}
241
 
242
		} else {
243
			return responseSender.badRequest(new ProfitMandiBusinessException("Retailer id", userInfo.getUserId(), "NOT_FOFO_RETAILER"));
244
		}
245
		return responseSender.ok(dealResponse);
246
	}
22273 amit.gupta 247
 
22319 amit.gupta 248
	@RequestMapping(value = "/online-deals", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
22272 amit.gupta 249
	@ApiImplicitParams({
22319 amit.gupta 250
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
22272 amit.gupta 251
	@ApiOperation(value = "Get online deals")
22319 amit.gupta 252
	public ResponseEntity<?> getOnlineDeals(HttpServletRequest request,
253
			@RequestParam(value = "categoryId") String categoryId, @RequestParam(value = "offset") String offset,
254
			@RequestParam(value = "limit") String limit, @RequestParam(value = "sort", required = false) String sort,
255
			@RequestParam(value = "direction", required = false) String direction,
256
			@RequestParam(value = "filterData", required = false) String filterData) throws Throwable {
257
		logger.info("Request " + request.getParameterMap());
22272 amit.gupta 258
		String response = null;
22319 amit.gupta 259
		int userId = (int) request.getAttribute("userId");
22289 amit.gupta 260
 
22319 amit.gupta 261
		String uri = "/deals/" + userId;
262
		RestClient rc = new RestClient(SchemeType.HTTP, host, port);
22272 amit.gupta 263
		Map<String, String> params = new HashMap<>();
264
		params.put("offset", offset);
265
		params.put("limit", limit);
266
		params.put("categoryId", categoryId);
267
		params.put("direction", direction);
268
		params.put("sort", sort);
269
		params.put("source", "online");
270
		params.put("filterData", filterData);
22357 amit.gupta 271
		/*if (userInfo.getRoleNames().contains(RoleType.FOFO.toString())) {
22289 amit.gupta 272
			params.put("tag_ids", getCommaSeparateTags(userId));
22357 amit.gupta 273
		}*/
22272 amit.gupta 274
		List<Object> responseObject = new ArrayList<>();
22931 ashik.ali 275
		response = rc.get(uri, params);
276
 
22272 amit.gupta 277
		JsonArray result_json = Json.parse(response).asArray();
22319 amit.gupta 278
		for (JsonValue j : result_json) {
22843 amit.gupta 279
			//logger.info("res " + j.asArray());
22272 amit.gupta 280
			List<Object> innerObject = new ArrayList<>();
22319 amit.gupta 281
			for (JsonValue jsonObject : j.asArray()) {
22272 amit.gupta 282
				innerObject.add(toDealObject(jsonObject.asObject()));
283
			}
22319 amit.gupta 284
			if (innerObject.size() > 0) {
22272 amit.gupta 285
				responseObject.add(innerObject);
286
			}
287
		}
23022 ashik.ali 288
		return responseSender.ok(responseObject);
22272 amit.gupta 289
	}
290
 
22319 amit.gupta 291
	/*
292
	 * @RequestMapping(value = "/direct-deals",
293
	 * method=RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
294
	 * 
295
	 * @ApiImplicitParams({
296
	 * 
297
	 * @ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required =
298
	 * true, dataType = "string", paramType = "header") }) public
299
	 * ResponseEntity<?> getDirectDeals(HttpServletRequest
300
	 * request, @RequestParam(value="categoryId") String
301
	 * categoryId,@RequestParam(value="offset") String offset,
302
	 * 
303
	 * @RequestParam(value="limit") String limit, @RequestParam(value="sort",
304
	 * required=false) String sort, @RequestParam(value="direction",
305
	 * required=false) String direction,
306
	 * 
307
	 * @RequestParam(value="filterData", required=false) String filterData ){
308
	 * 
309
	 * return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK); }
310
	 */
311
 
312
	private Object toDealObject(JsonObject jsonObject) {
313
		if (jsonObject.get("dealObject") != null && jsonObject.get("dealObject").asInt() == 1) {
21339 kshitij.so 314
			return new Gson().fromJson(jsonObject.toString(), DealObjectResponse.class);
315
		}
316
		return new Gson().fromJson(jsonObject.toString(), DealsResponse.class);
317
	}
22319 amit.gupta 318
 
319
	@RequestMapping(value = ProfitMandiConstants.URL_BRANDS, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
21356 kshitij.so 320
	@ApiImplicitParams({
22319 amit.gupta 321
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
21356 kshitij.so 322
	@ApiOperation(value = "Get brand list and count for category")
22319 amit.gupta 323
	public ResponseEntity<?> getBrands(HttpServletRequest request,
22931 ashik.ali 324
			@RequestParam(value = "category_id") String category_id) throws ProfitMandiBusinessException{
22319 amit.gupta 325
		logger.info("Request " + request.getParameterMap());
21356 kshitij.so 326
		String response = null;
22319 amit.gupta 327
		// TODO: move to properties
21356 kshitij.so 328
		String uri = ProfitMandiConstants.URL_BRANDS;
22319 amit.gupta 329
		RestClient rc = new RestClient(SchemeType.HTTP, host, port);
21356 kshitij.so 330
		Map<String, String> params = new HashMap<>();
331
		params.put("category_id", category_id);
21358 kshitij.so 332
		List<DealBrands> dealBrandsResponse = null;
22931 ashik.ali 333
		response = rc.get(uri, params);
334
 
22319 amit.gupta 335
		dealBrandsResponse = new Gson().fromJson(response, new TypeToken<List<DealBrands>>() {
336
		}.getType());
23022 ashik.ali 337
 
338
		return responseSender.ok(dealBrandsResponse);
21356 kshitij.so 339
	}
22319 amit.gupta 340
 
341
	@RequestMapping(value = ProfitMandiConstants.URL_UNIT_DEAL, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
21445 kshitij.so 342
	@ApiImplicitParams({
22319 amit.gupta 343
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
21445 kshitij.so 344
	@ApiOperation(value = "Get unit deal object")
22931 ashik.ali 345
	public ResponseEntity<?> getUnitDeal(HttpServletRequest request, @PathVariable(value = "id") long id) 
346
			throws ProfitMandiBusinessException{
21445 kshitij.so 347
		String response = null;
22319 amit.gupta 348
		// TODO: move to properties
349
		String uri = "getDealById/" + id;
350
		System.out.println("Unit deal " + uri);
351
		RestClient rc = new RestClient(SchemeType.HTTP, host, port);
21445 kshitij.so 352
		Map<String, String> params = new HashMap<>();
353
		DealsResponse dealsResponse = null;
22931 ashik.ali 354
		response = rc.get(uri, params);
355
 
21445 kshitij.so 356
		JsonObject result_json = Json.parse(response).asObject();
22319 amit.gupta 357
		if (!result_json.isEmpty()) {
21445 kshitij.so 358
			dealsResponse = new Gson().fromJson(response, DealsResponse.class);
22952 amit.gupta 359
			Iterator<AvailabilityInfo> iter = dealsResponse.getAvailabilityInfo().iterator();
360
			while (iter.hasNext()){
361
				AvailabilityInfo ai = iter.next();
362
				if(ai.getAvailability() <= 0)
363
					iter.remove();
364
			}
21445 kshitij.so 365
		}
22952 amit.gupta 366
		/*final ProfitMandiResponse<?> profitMandiResponse = new ProfitMandiResponse<>(LocalDateTime.now(),
22319 amit.gupta 367
				request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS,
22952 amit.gupta 368
				dealsResponse);*/
369
		return responseSender.ok(dealsResponse);
21445 kshitij.so 370
	}
22333 amit.gupta 371
 
372
	@RequestMapping(value = "/fofo/brands", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
373
	public ResponseEntity<?> getBrandsToDisplay() {
374
		return new ResponseEntity<>(mongoClient.getBrandsToDisplay(), HttpStatus.OK);
375
	}
22401 amit.gupta 376
 
22446 amit.gupta 377
	@RequestMapping(value = "/banners/{bannerType}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
22448 amit.gupta 378
	public ResponseEntity<?> getBanners(@PathVariable String bannerType) {
22447 amit.gupta 379
		return new ResponseEntity<>(mongoClient.getBannersByType(bannerType), HttpStatus.OK);
22446 amit.gupta 380
	}
381
 
22406 amit.gupta 382
	@ApiImplicitParams({
383
		@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })	
22401 amit.gupta 384
	@RequestMapping(value = "/deals/skus/{skus}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
22931 ashik.ali 385
	public ResponseEntity<?> getDealsBySkus(@PathVariable String skus) throws ProfitMandiBusinessException {
22401 amit.gupta 386
		StringBuffer sb = new StringBuffer("/getDealsForNotification/");
387
		String uri = sb.append(skus).toString();
388
		RestClient rc = new RestClient(SchemeType.HTTP, host, port);
389
		String response = rc.get(uri, new HashMap<>());
22406 amit.gupta 390
		JsonArray result_json = Json.parse(response).asArray();
22407 amit.gupta 391
		List<Object> responseObject = new ArrayList<>();
392
		for (JsonValue j : result_json) {
22843 amit.gupta 393
			//logger.info("res " + j.asArray());
22407 amit.gupta 394
			List<Object> innerObject = new ArrayList<>();
395
			for (JsonValue jsonObject : j.asArray()) {
396
				innerObject.add(toDealObject(jsonObject.asObject()));
397
			}
398
			if (innerObject.size() > 0) {
399
				responseObject.add(innerObject);
400
			}
401
		}
22408 amit.gupta 402
		return responseSender.ok(responseObject);
22401 amit.gupta 403
	}
21339 kshitij.so 404
 
405
}