Subversion Repositories SmartDukaan

Rev

Rev 30683 | Rev 30690 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 30683 Rev 30686
Line 1... Line 1...
1
package com.spice.profitmandi.web.controller;
1
package com.spice.profitmandi.web.controller;
2
 
2
 
3
import java.util.ArrayList;
-
 
4
import java.util.Arrays;
-
 
5
import java.util.Comparator;
-
 
6
import java.util.HashMap;
-
 
7
import java.util.HashSet;
-
 
8
import java.util.Iterator;
-
 
9
import java.util.List;
-
 
10
import java.util.Map;
-
 
11
import java.util.Optional;
-
 
12
import java.util.Set;
-
 
13
import java.util.concurrent.atomic.AtomicInteger;
-
 
14
import java.util.stream.Collectors;
-
 
15
 
-
 
16
import javax.servlet.http.HttpServletRequest;
-
 
17
 
-
 
18
import org.apache.commons.lang3.StringUtils;
-
 
19
import org.apache.http.conn.HttpHostConnectException;
-
 
20
import org.apache.logging.log4j.LogManager;
-
 
21
import org.apache.logging.log4j.Logger;
-
 
22
import org.json.JSONArray;
-
 
23
import org.json.JSONObject;
-
 
24
import org.springframework.beans.factory.annotation.Autowired;
-
 
25
import org.springframework.beans.factory.annotation.Value;
-
 
26
import org.springframework.http.HttpStatus;
-
 
27
import org.springframework.http.MediaType;
-
 
28
import org.springframework.http.ResponseEntity;
-
 
29
import org.springframework.stereotype.Controller;
-
 
30
import org.springframework.transaction.annotation.Transactional;
-
 
31
import org.springframework.web.bind.annotation.PathVariable;
-
 
32
import org.springframework.web.bind.annotation.RequestMapping;
-
 
33
import org.springframework.web.bind.annotation.RequestMethod;
-
 
34
import org.springframework.web.bind.annotation.RequestParam;
-
 
35
 
-
 
36
import com.eclipsesource.json.Json;
3
import com.eclipsesource.json.Json;
37
import com.eclipsesource.json.JsonArray;
4
import com.eclipsesource.json.JsonArray;
38
import com.eclipsesource.json.JsonObject;
5
import com.eclipsesource.json.JsonObject;
39
import com.eclipsesource.json.JsonValue;
6
import com.eclipsesource.json.JsonValue;
40
import com.google.gson.Gson;
7
import com.google.gson.Gson;
41
import com.google.gson.reflect.TypeToken;
8
import com.google.gson.reflect.TypeToken;
42
import com.itextpdf.text.pdf.security.CertificateInfo.X500Name;
-
 
43
import com.mongodb.BasicDBObject;
9
import com.mongodb.BasicDBObject;
44
import com.mongodb.DBObject;
10
import com.mongodb.DBObject;
45
import com.spice.profitmandi.common.enumuration.SchemeType;
11
import com.spice.profitmandi.common.enumuration.SchemeType;
46
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
12
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
47
import com.spice.profitmandi.common.model.ProfitMandiConstants;
13
import com.spice.profitmandi.common.model.ProfitMandiConstants;
48
import com.spice.profitmandi.common.model.UserInfo;
14
import com.spice.profitmandi.common.model.UserInfo;
49
import com.spice.profitmandi.common.solr.SolrService;
15
import com.spice.profitmandi.common.solr.SolrService;
50
import com.spice.profitmandi.common.web.client.RestClient;
16
import com.spice.profitmandi.common.web.client.RestClient;
51
import com.spice.profitmandi.common.web.util.ResponseSender;
17
import com.spice.profitmandi.common.web.util.ResponseSender;
52
import com.spice.profitmandi.dao.entity.catalog.Category;
-
 
53
import com.spice.profitmandi.dao.entity.catalog.ComboMappedModel;
-
 
54
import com.spice.profitmandi.dao.entity.catalog.ComboModel;
-
 
55
import com.spice.profitmandi.dao.entity.catalog.Item;
18
import com.spice.profitmandi.dao.entity.catalog.*;
56
import com.spice.profitmandi.dao.entity.catalog.TagListing;
-
 
57
import com.spice.profitmandi.dao.entity.dtr.WebOffer;
19
import com.spice.profitmandi.dao.entity.dtr.WebOffer;
58
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
20
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
59
import com.spice.profitmandi.dao.entity.fofo.SuggestedPo;
21
import com.spice.profitmandi.dao.entity.fofo.SuggestedPo;
60
import com.spice.profitmandi.dao.entity.fofo.SuggestedPoDetail;
22
import com.spice.profitmandi.dao.entity.fofo.SuggestedPoDetail;
61
import com.spice.profitmandi.dao.entity.inventory.SaholicCISTable;
23
import com.spice.profitmandi.dao.entity.inventory.SaholicCISTable;
62
import com.spice.profitmandi.dao.entity.inventory.SaholicPOItem;
24
import com.spice.profitmandi.dao.entity.inventory.SaholicPOItem;
63
import com.spice.profitmandi.dao.model.CreateOfferRequest;
25
import com.spice.profitmandi.dao.model.CreateOfferRequest;
64
import com.spice.profitmandi.dao.model.UserCart;
26
import com.spice.profitmandi.dao.model.UserCart;
65
import com.spice.profitmandi.dao.repository.catalog.CategoryRepository;
-
 
66
import com.spice.profitmandi.dao.repository.catalog.ComboMappedModelRepository;
-
 
67
import com.spice.profitmandi.dao.repository.catalog.ComboModelRepository;
-
 
68
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
27
import com.spice.profitmandi.dao.repository.catalog.*;
69
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
-
 
70
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
28
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
71
import com.spice.profitmandi.dao.repository.dtr.Mongo;
29
import com.spice.profitmandi.dao.repository.dtr.Mongo;
72
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
30
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
73
import com.spice.profitmandi.dao.repository.dtr.WebOfferRepository;
31
import com.spice.profitmandi.dao.repository.dtr.WebOfferRepository;
74
import com.spice.profitmandi.dao.repository.fofo.SuggestedPoDetailRepository;
32
import com.spice.profitmandi.dao.repository.fofo.SuggestedPoDetailRepository;
75
import com.spice.profitmandi.dao.repository.fofo.SuggestedPoRepository;
33
import com.spice.profitmandi.dao.repository.fofo.SuggestedPoRepository;
76
import com.spice.profitmandi.dao.repository.inventory.SaholicCISTableRepository;
34
import com.spice.profitmandi.dao.repository.inventory.SaholicCISTableRepository;
77
import com.spice.profitmandi.service.authentication.RoleManager;
35
import com.spice.profitmandi.service.authentication.RoleManager;
78
import com.spice.profitmandi.service.inventory.AvailabilityInfo;
-
 
79
import com.spice.profitmandi.service.inventory.Bucket;
36
import com.spice.profitmandi.service.inventory.*;
80
import com.spice.profitmandi.service.inventory.FofoAvailabilityInfo;
-
 
81
import com.spice.profitmandi.service.inventory.FofoCatalogResponse;
-
 
82
import com.spice.profitmandi.service.inventory.InventoryService;
-
 
83
import com.spice.profitmandi.service.inventory.ItemBucketService;
-
 
84
import com.spice.profitmandi.service.inventory.ItemQuantityPojo;
-
 
85
import com.spice.profitmandi.service.inventory.SaholicInventoryService;
-
 
86
import com.spice.profitmandi.service.pricecircular.PriceCircularItemModel;
37
import com.spice.profitmandi.service.pricecircular.PriceCircularItemModel;
87
import com.spice.profitmandi.service.pricecircular.PriceCircularModel;
38
import com.spice.profitmandi.service.pricecircular.PriceCircularModel;
88
import com.spice.profitmandi.service.pricecircular.PriceCircularService;
39
import com.spice.profitmandi.service.pricecircular.PriceCircularService;
89
import com.spice.profitmandi.service.pricing.PricingService;
40
import com.spice.profitmandi.service.pricing.PricingService;
90
import com.spice.profitmandi.service.scheme.SchemeService;
41
import com.spice.profitmandi.service.scheme.SchemeService;
91
import com.spice.profitmandi.web.res.DealBrands;
42
import com.spice.profitmandi.web.res.DealBrands;
92
import com.spice.profitmandi.web.res.DealObjectResponse;
43
import com.spice.profitmandi.web.res.DealObjectResponse;
93
import com.spice.profitmandi.web.res.DealsResponse;
44
import com.spice.profitmandi.web.res.DealsResponse;
94
 
-
 
95
import io.swagger.annotations.ApiImplicitParam;
45
import io.swagger.annotations.ApiImplicitParam;
96
import io.swagger.annotations.ApiImplicitParams;
46
import io.swagger.annotations.ApiImplicitParams;
97
import io.swagger.annotations.ApiOperation;
47
import io.swagger.annotations.ApiOperation;
-
 
48
import org.apache.commons.lang3.StringUtils;
-
 
49
import org.apache.http.conn.HttpHostConnectException;
-
 
50
import org.apache.logging.log4j.LogManager;
-
 
51
import org.apache.logging.log4j.Logger;
-
 
52
import org.json.JSONArray;
-
 
53
import org.json.JSONObject;
-
 
54
import org.springframework.beans.factory.annotation.Autowired;
-
 
55
import org.springframework.beans.factory.annotation.Value;
-
 
56
import org.springframework.http.HttpStatus;
-
 
57
import org.springframework.http.MediaType;
-
 
58
import org.springframework.http.ResponseEntity;
-
 
59
import org.springframework.stereotype.Controller;
-
 
60
import org.springframework.transaction.annotation.Transactional;
-
 
61
import org.springframework.web.bind.annotation.PathVariable;
-
 
62
import org.springframework.web.bind.annotation.RequestMapping;
-
 
63
import org.springframework.web.bind.annotation.RequestMethod;
-
 
64
import org.springframework.web.bind.annotation.RequestParam;
-
 
65
 
-
 
66
import javax.servlet.http.HttpServletRequest;
-
 
67
import java.util.*;
-
 
68
import java.util.concurrent.atomic.AtomicInteger;
-
 
69
import java.util.stream.Collectors;
98
 
70
 
99
@Controller
71
@Controller
100
@Transactional(rollbackFor = Throwable.class)
72
@Transactional(rollbackFor = Throwable.class)
101
public class DealsController {
73
public class DealsController {
102
 
74
 
Line 254... Line 226...
254
		return responseSender.ok(dealResponse);
226
		return responseSender.ok(dealResponse);
255
	}
227
	}
256
 
228
 
257
	@RequestMapping(value = "/suggestedPo/status", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
229
	@RequestMapping(value = "/suggestedPo/status", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
258
	@ApiImplicitParams({
230
	@ApiImplicitParams({
259
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
231
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
260
	@ApiOperation(value = "")
232
	@ApiOperation(value = "")
261
	public ResponseEntity<?> changeSuggestedPoStatus(HttpServletRequest request, @RequestParam int id)
233
	public ResponseEntity<?> changeSuggestedPoStatus(HttpServletRequest request, @RequestParam int id)
262
			throws ProfitMandiBusinessException {
234
			throws ProfitMandiBusinessException {
263
		SuggestedPo suggestedPo = suggestedPoRepository.selectById(id);
235
		SuggestedPo suggestedPo = suggestedPoRepository.selectById(id);
264
		suggestedPo.setStatus("closed");
236
		suggestedPo.setStatus("closed");
Line 275... Line 247...
275
		}
247
		}
276
		return String.join(",", strTagIds);
248
		return String.join(",", strTagIds);
277
	}
249
	}
278
 
250
 
279
	@ApiImplicitParams({
251
	@ApiImplicitParams({
280
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
252
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
281
	@RequestMapping(value = "/fofo", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
253
	@RequestMapping(value = "/fofo", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
282
	public ResponseEntity<?> getFofo(HttpServletRequest request,
254
	public ResponseEntity<?> getFofo(HttpServletRequest request,
283
			@RequestParam(value = "categoryId", required = false, defaultValue = "3") String categoryId,
255
									 @RequestParam(value = "categoryId", required = false, defaultValue = "3") String categoryId,
284
			@RequestParam(value = "offset") String offset, @RequestParam(value = "limit") String limit,
256
									 @RequestParam(value = "offset") String offset, @RequestParam(value = "limit") String limit,
285
			@RequestParam(value = "sort", required = false) String sort,
257
									 @RequestParam(value = "sort", required = false) String sort,
286
			@RequestParam(value = "brand", required = false) String brand,
258
									 @RequestParam(value = "brand", required = false) String brand,
287
			@RequestParam(value = "subCategoryId", required = false) int subCategoryId,
259
									 @RequestParam(value = "subCategoryId", required = false) int subCategoryId,
288
			@RequestParam(value = "q", required = false) String queryTerm,
260
									 @RequestParam(value = "q", required = false) String queryTerm,
289
			@RequestParam(value = "hotDeal", required = false) boolean hotDeal) throws Throwable {
261
									 @RequestParam(value = "hotDeal", required = false) boolean hotDeal) throws Throwable {
290
		List<FofoCatalogResponse> dealResponse = new ArrayList<>();
262
		List<FofoCatalogResponse> dealResponse = new ArrayList<>();
291
		UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
263
		UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
292
		FofoStore fs = fofoStoreRepository.selectByRetailerId(userInfo.getRetailerId());
264
		FofoStore fs = fofoStoreRepository.selectByRetailerId(userInfo.getRetailerId());
293
		sort = "w" + fs.getWarehouseId() + "_i desc";
265
		sort = "w" + fs.getWarehouseId() + "_i desc";
294
		dealResponse = this.getCatalogResponse(
266
		dealResponse = this.getCatalogResponse(
Line 298... Line 270...
298
		return responseSender.ok(dealResponse);
270
		return responseSender.ok(dealResponse);
299
	}
271
	}
300
 
272
 
301
	@RequestMapping(value = "/online-deals", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
273
	@RequestMapping(value = "/online-deals", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
302
	@ApiImplicitParams({
274
	@ApiImplicitParams({
303
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
275
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
304
	@ApiOperation(value = "Get online deals")
276
	@ApiOperation(value = "Get online deals")
305
	public ResponseEntity<?> getOnlineDeals(HttpServletRequest request,
277
	public ResponseEntity<?> getOnlineDeals(HttpServletRequest request,
306
			@RequestParam(value = "categoryId") String categoryId, @RequestParam(value = "offset") String offset,
278
											@RequestParam(value = "categoryId") String categoryId, @RequestParam(value = "offset") String offset,
307
			@RequestParam(value = "limit") String limit, @RequestParam(value = "sort", required = false) String sort,
279
											@RequestParam(value = "limit") String limit, @RequestParam(value = "sort", required = false) String sort,
308
			@RequestParam(value = "direction", required = false) String direction,
280
											@RequestParam(value = "direction", required = false) String direction,
309
			@RequestParam(value = "filterData", required = false) String filterData) throws Throwable {
281
											@RequestParam(value = "filterData", required = false) String filterData) throws Throwable {
310
		logger.info("Request " + request.getParameterMap());
282
		logger.info("Request " + request.getParameterMap());
311
		String response = null;
283
		String response = null;
312
		int userId = (int) request.getAttribute("userId");
284
		int userId = (int) request.getAttribute("userId");
313
 
285
 
314
		String uri = "/deals/" + userId;
286
		String uri = "/deals/" + userId;
Line 353... Line 325...
353
		return new Gson().fromJson(jsonObject.toString(), DealsResponse.class);
325
		return new Gson().fromJson(jsonObject.toString(), DealsResponse.class);
354
	}
326
	}
355
 
327
 
356
	@RequestMapping(value = ProfitMandiConstants.URL_BRANDS, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
328
	@RequestMapping(value = ProfitMandiConstants.URL_BRANDS, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
357
	@ApiImplicitParams({
329
	@ApiImplicitParams({
358
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
330
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
359
	@ApiOperation(value = "Get brand list and count for category")
331
	@ApiOperation(value = "Get brand list and count for category")
360
	public ResponseEntity<?> getBrands(HttpServletRequest request,
332
	public ResponseEntity<?> getBrands(HttpServletRequest request,
361
			@RequestParam(value = "category_id") String category_id) throws ProfitMandiBusinessException {
333
									   @RequestParam(value = "category_id") String category_id) throws ProfitMandiBusinessException {
362
		logger.info("Request " + request.getParameterMap());
334
		logger.info("Request " + request.getParameterMap());
363
		String response = null;
335
		String response = null;
364
		// TODO: move to properties
336
		// TODO: move to properties
365
		String uri = ProfitMandiConstants.URL_BRANDS;
337
		String uri = ProfitMandiConstants.URL_BRANDS;
366
		RestClient rc = new RestClient();
338
		RestClient rc = new RestClient();
Line 379... Line 351...
379
		return responseSender.ok(dealBrandsResponse);
351
		return responseSender.ok(dealBrandsResponse);
380
	}
352
	}
381
 
353
 
382
	@RequestMapping(value = ProfitMandiConstants.URL_UNIT_DEAL, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
354
	@RequestMapping(value = ProfitMandiConstants.URL_UNIT_DEAL, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
383
	@ApiImplicitParams({
355
	@ApiImplicitParams({
384
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
356
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
385
	@ApiOperation(value = "Get unit deal object")
357
	@ApiOperation(value = "Get unit deal object")
386
	public ResponseEntity<?> getUnitDeal(HttpServletRequest request, @PathVariable(value = "id") long id)
358
	public ResponseEntity<?> getUnitDeal(HttpServletRequest request, @PathVariable(value = "id") long id)
387
			throws ProfitMandiBusinessException {
359
			throws ProfitMandiBusinessException {
388
		String response = null;
360
		String response = null;
389
		// TODO: move to properties
361
		// TODO: move to properties
Line 411... Line 383...
411
		return responseSender.ok(dealsResponse);
383
		return responseSender.ok(dealsResponse);
412
	}
384
	}
413
 
385
 
414
	@RequestMapping(value = "/partnerdeals/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
386
	@RequestMapping(value = "/partnerdeals/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
415
	@ApiImplicitParams({
387
	@ApiImplicitParams({
416
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
388
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
417
	@ApiOperation(value = "Get unit deal object")
389
	@ApiOperation(value = "Get unit deal object")
418
	public ResponseEntity<?> getUnitFocoDeal(HttpServletRequest request, @PathVariable(value = "id") long id)
390
	public ResponseEntity<?> getUnitFocoDeal(HttpServletRequest request, @PathVariable(value = "id") long id)
419
			throws Exception {
391
			throws Exception {
420
		List<FofoCatalogResponse> dealResponse = new ArrayList<>();
392
		List<FofoCatalogResponse> dealResponse = new ArrayList<>();
421
		List<Integer> tagIds = Arrays.asList(4);
393
		List<Integer> tagIds = Arrays.asList(4);
Line 451... Line 423...
451
		return responseSender.ok(dealResponse.get(0));
423
		return responseSender.ok(dealResponse.get(0));
452
	}
424
	}
453
 
425
 
454
	@RequestMapping(value = "/fofo/brands", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
426
	@RequestMapping(value = "/fofo/brands", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
455
	public ResponseEntity<?> getBrandsToDisplay(HttpServletRequest request,
427
	public ResponseEntity<?> getBrandsToDisplay(HttpServletRequest request,
456
			@RequestParam(required = false, defaultValue = "0") int categoryId) throws Exception {
428
												@RequestParam(required = false, defaultValue = "0") int categoryId) throws Exception {
457
		UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
429
		UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
458
		logger.info("userInfo [{}]", userInfo);
430
		logger.info("userInfo [{}]", userInfo);
459
		List<DBObject> brandsDisplay = mongoClient.getMongoBrands(userInfo.getRetailerId(), userInfo.getEmail(),
431
		List<DBObject> brandsDisplay = mongoClient.getMongoBrands(userInfo.getRetailerId(), userInfo.getEmail(),
460
				categoryId);
432
				categoryId);
461
		return new ResponseEntity<>(brandsDisplay, HttpStatus.OK);
433
		return new ResponseEntity<>(brandsDisplay, HttpStatus.OK);
Line 520... Line 492...
520
	public ResponseEntity<?> getSubcategoriesToDisplay() {
492
	public ResponseEntity<?> getSubcategoriesToDisplay() {
521
		return new ResponseEntity<>(mongoClient.getSubcategoriesToDisplay(), HttpStatus.OK);
493
		return new ResponseEntity<>(mongoClient.getSubcategoriesToDisplay(), HttpStatus.OK);
522
	}
494
	}
523
 
495
 
524
	@ApiImplicitParams({
496
	@ApiImplicitParams({
525
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
497
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
526
	@RequestMapping(value = "/deals/skus/{skus}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
498
	@RequestMapping(value = "/deals/skus/{skus}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
527
	public ResponseEntity<?> getDealsBySkus(@PathVariable String skus) throws ProfitMandiBusinessException {
499
	public ResponseEntity<?> getDealsBySkus(@PathVariable String skus) throws ProfitMandiBusinessException {
528
		StringBuffer sb = new StringBuffer("/getDealsForNotification/");
500
		StringBuffer sb = new StringBuffer("/getDealsForNotification/");
529
		String uri = sb.append(skus).toString();
501
		String uri = sb.append(skus).toString();
530
		RestClient rc = new RestClient();
502
		RestClient rc = new RestClient();
Line 633... Line 605...
633
			}
605
			}
634
			fofoCatalogResponse.setBrand(doc.getJSONArray("brand_ss").getString(0));
606
			fofoCatalogResponse.setBrand(doc.getJSONArray("brand_ss").getString(0));
635
			if (doc.has("_childDocuments_")) {
607
			if (doc.has("_childDocuments_")) {
636
				String modelColorClass = "grey";
608
				String modelColorClass = "grey";
637
				FofoAvailabilityInfo fdiAnyColour = null;
609
				FofoAvailabilityInfo fdiAnyColour = null;
638
				int allColorNetAvailability = 0;
-
 
639
				for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
610
				for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
640
					PriceCircularItemModel priceCircularItemModel = priceCircularItemModelMap
611
					PriceCircularItemModel priceCircularItemModel = priceCircularItemModelMap
641
							.get(fofoCatalogResponse.getCatalogId());
612
							.get(fofoCatalogResponse.getCatalogId());
642
					JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
613
					JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
643
					int itemId = childItem.getInt("itemId_i");
614
					int itemId = childItem.getInt("itemId_i");
Line 655... Line 626...
655
						List<SaholicPOItem> poItemAvailability = null;
626
						List<SaholicPOItem> poItemAvailability = null;
656
						if (poItemAvailabilityMap != null) {
627
						if (poItemAvailabilityMap != null) {
657
							poItemAvailability = poItemAvailabilityMap.get(itemId);
628
							poItemAvailability = poItemAvailabilityMap.get(itemId);
658
						}
629
						}
659
						fdi.setNlc(priceCircularItemModel == null ? 0 : priceCircularItemModel.getNetPrice());
630
						fdi.setNlc(priceCircularItemModel == null ? 0 : priceCircularItemModel.getNetPrice());
-
 
631
 
660
						if (currentAvailability != null) {
632
						Map<Integer, SaholicCISTable> map = null;
661
							allColorNetAvailability += currentAvailability.stream()
633
						for (SaholicCISTable saholicCISTable : currentAvailability) {
-
 
634
							saholicCISTable.setWarehouseName(
662
									.collect(Collectors.summingInt(SaholicCISTable::getNetAvailability));
635
									ProfitMandiConstants.WAREHOUSE_MAP.get(saholicCISTable.getWarehouseFrom()));
663
						}
636
						}
-
 
637
						map = currentAvailability.stream()
-
 
638
								.collect(Collectors.toMap(SaholicCISTable::getWarehouseFrom, x -> x));
664
						if (poItemAvailability != null) {
639
						if (poItemAvailability != null) {
665
							allColorNetAvailability += poItemAvailability.stream()
-
 
666
									.collect(Collectors.summingInt(SaholicPOItem::getUnfulfilledQty));
-
 
667
						}
-
 
668
						Map<Integer, SaholicCISTable> map = null;
-
 
669
						if (currentAvailability != null) {
-
 
670
							for (SaholicCISTable saholicCISTable : currentAvailability) {
-
 
671
								saholicCISTable.setWarehouseName(
-
 
672
										ProfitMandiConstants.WAREHOUSE_MAP.get(saholicCISTable.getWarehouseFrom()));
-
 
673
							}
-
 
674
							map = currentAvailability.stream()
-
 
675
									.collect(Collectors.toMap(SaholicCISTable::getWarehouseFrom, x -> x));
-
 
676
							if (poItemAvailability != null) {
-
 
677
								for (SaholicPOItem saholicPOItem : poItemAvailability) {
640
							for (SaholicPOItem saholicPOItem : poItemAvailability) {
678
									if (map.containsKey(saholicPOItem.getWarehouseFrom())) {
641
								if (map.containsKey(saholicPOItem.getWarehouseFrom())) {
679
										map.get(saholicPOItem.getWarehouseFrom())
642
									map.get(saholicPOItem.getWarehouseFrom())
680
												.setPopendingQty(saholicPOItem.getUnfulfilledQty());
643
											.setPopendingQty(saholicPOItem.getUnfulfilledQty());
681
										map.get(saholicPOItem.getWarehouseFrom())
-
 
682
												.setWarehouseName(ProfitMandiConstants.WAREHOUSE_MAP
-
 
683
														.get(saholicPOItem.getWarehouseFrom()));
-
 
684
									} else {
644
								} else {
685
										SaholicCISTable saholicCISTable = new SaholicCISTable();
-
 
686
										saholicCISTable.setAvailability(0);
-
 
687
										saholicCISTable.setReserved(0);
-
 
688
										saholicCISTable.setItemId(itemId);
-
 
689
										saholicCISTable.setPopendingQty(saholicPOItem.getUnfulfilledQty());
-
 
690
										saholicCISTable.setWarehouseFrom(saholicPOItem.getWarehouseFrom());
-
 
691
										saholicCISTable.setWarehouseName(ProfitMandiConstants.WAREHOUSE_MAP
-
 
692
												.get(saholicPOItem.getWarehouseFrom()));
-
 
693
										map.put(saholicPOItem.getWarehouseFrom(), saholicCISTable);
-
 
694
									}
-
 
695
								}
-
 
696
							}
-
 
697
						} else {
-
 
698
							map = new HashMap<>();
-
 
699
							if (poItemAvailability != null) {
-
 
700
								for (SaholicPOItem saholicPOItem : poItemAvailability) {
-
 
701
									SaholicCISTable saholicCISTable = new SaholicCISTable();
645
									SaholicCISTable saholicCISTable = new SaholicCISTable();
702
									saholicCISTable.setAvailability(0);
646
									saholicCISTable.setAvailability(0);
703
									saholicCISTable.setReserved(0);
647
									saholicCISTable.setReserved(0);
704
									saholicCISTable.setItemId(itemId);
648
									saholicCISTable.setItemId(itemId);
705
									saholicCISTable.setPopendingQty(saholicPOItem.getUnfulfilledQty());
649
									saholicCISTable.setPopendingQty(saholicPOItem.getUnfulfilledQty());
706
									saholicCISTable.setWarehouseFrom(saholicPOItem.getWarehouseFrom());
650
									saholicCISTable.setWarehouseFrom(saholicPOItem.getWarehouseFrom());
707
									saholicCISTable.setWarehouseName(
651
									saholicCISTable.setWarehouseName(ProfitMandiConstants.WAREHOUSE_MAP
708
											ProfitMandiConstants.WAREHOUSE_MAP.get(saholicPOItem.getWarehouseFrom()));
652
											.get(saholicPOItem.getWarehouseFrom()));
709
									map.put(saholicPOItem.getWarehouseFrom(), saholicCISTable);
653
									map.put(saholicPOItem.getWarehouseFrom(), saholicCISTable);
710
								}
654
								}
711
							}
655
							}
712
 
-
 
713
						}
656
						}
714
						fdi.setSaholicCISTableList(new ArrayList<>(map.values()));
657
						fdi.setSaholicCISTableList(new ArrayList<>(map.values()));
715
						String poColor = "grey";
658
						String poColor = "grey";
716
						boolean active = false;
659
						boolean active = false;
717
						if (currentAvailability != null && currentAvailability.stream()
660
						if (currentAvailability != null && currentAvailability.stream()
Line 774... Line 717...
774
						fdi.setMaxQuantity(Math.min(fdi.getAvailability(), 100));
717
						fdi.setMaxQuantity(Math.min(fdi.getAvailability(), 100));
775
						fofoAvailabilityInfoMap.put(itemId, fdi);
718
						fofoAvailabilityInfoMap.put(itemId, fdi);
776
					}
719
					}
777
				}
720
				}
778
				if (fdiAnyColour != null) {
721
				if (fdiAnyColour != null) {
779
					/*
-
 
780
					 * if (allColorNetAvailability <= 0) { for (Map.Entry<Integer,
-
 
781
					 * FofoAvailabilityInfo> entry : fofoAvailabilityInfoMap.entrySet()) {
-
 
782
					 * entry.getValue().setColorClass("grey"); } } else {
-
 
783
					 * 
-
 
784
					 * }
-
 
785
					 */
-
 
786
					fdiAnyColour.setColorClass(modelColorClass);
722
					fdiAnyColour.setColorClass(modelColorClass);
787
				}
723
				}
788
			}
724
			}
789
			if (fofoAvailabilityInfoMap.values().size() > 0) {
725
			if (fofoAvailabilityInfoMap.values().size() > 0) {
790
				List<FofoAvailabilityInfo> availabilityList = fofoAvailabilityInfoMap.values().stream()
726
				List<FofoAvailabilityInfo> availabilityList = fofoAvailabilityInfoMap.values().stream()
Line 818... Line 754...
818
		return dealResponse;
754
		return dealResponse;
819
 
755
 
820
	}
756
	}
821
 
757
 
822
	private List<FofoCatalogResponse> getCatalogSingleSkuResponse(JSONArray docs, Map<Integer, Integer> itemFilter,
758
	private List<FofoCatalogResponse> getCatalogSingleSkuResponse(JSONArray docs, Map<Integer, Integer> itemFilter,
823
			boolean hotDeal) throws ProfitMandiBusinessException {
759
																  boolean hotDeal) throws ProfitMandiBusinessException {
824
		Map<Integer, TagListing> itemTagListingMap = null;
760
		Map<Integer, TagListing> itemTagListingMap = null;
825
		List<FofoCatalogResponse> dealResponse = new ArrayList<>();
761
		List<FofoCatalogResponse> dealResponse = new ArrayList<>();
826
		List<Integer> tagIds = Arrays.asList(4);
762
		List<Integer> tagIds = Arrays.asList(4);
827
 
763
 
828
		itemTagListingMap = tagListingRepository.selectByItemIdsAndTagIds(itemFilter.keySet(), new HashSet<>(tagIds))
764
		itemTagListingMap = tagListingRepository.selectByItemIdsAndTagIds(itemFilter.keySet(), new HashSet<>(tagIds))