Subversion Repositories SmartDukaan

Rev

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

Rev 26720 Rev 26745
Line 1... Line 1...
1
package com.spice.profitmandi.web.controller;
1
package com.spice.profitmandi.web.controller;
2
 
2
 
3
import java.time.LocalTime;
3
import java.time.LocalTime;
4
import java.util.ArrayList;
4
import java.util.ArrayList;
5
import java.util.Arrays;
5
import java.util.Arrays;
-
 
6
import java.util.Comparator;
6
import java.util.HashMap;
7
import java.util.HashMap;
7
import java.util.HashSet;
8
import java.util.HashSet;
8
import java.util.List;
9
import java.util.List;
9
import java.util.Map;
10
import java.util.Map;
-
 
11
import java.util.Optional;
10
import java.util.Set;
12
import java.util.Set;
11
import java.util.stream.Collectors;
13
import java.util.stream.Collectors;
12
 
14
 
13
import javax.servlet.http.HttpServletRequest;
15
import javax.servlet.http.HttpServletRequest;
14
 
16
 
Line 18... Line 20...
18
import org.apache.logging.log4j.Logger;
20
import org.apache.logging.log4j.Logger;
19
import org.json.JSONArray;
21
import org.json.JSONArray;
20
import org.json.JSONObject;
22
import org.json.JSONObject;
21
import org.springframework.beans.factory.annotation.Autowired;
23
import org.springframework.beans.factory.annotation.Autowired;
22
import org.springframework.beans.factory.annotation.Value;
24
import org.springframework.beans.factory.annotation.Value;
-
 
25
import org.springframework.cache.annotation.Cacheable;
23
import org.springframework.http.MediaType;
26
import org.springframework.http.MediaType;
24
import org.springframework.http.ResponseEntity;
27
import org.springframework.http.ResponseEntity;
25
import org.springframework.stereotype.Controller;
28
import org.springframework.stereotype.Controller;
26
import org.springframework.transaction.annotation.Transactional;
29
import org.springframework.transaction.annotation.Transactional;
27
import org.springframework.web.bind.annotation.PathVariable;
30
import org.springframework.web.bind.annotation.PathVariable;
Line 29... Line 32...
29
import org.springframework.web.bind.annotation.RequestMapping;
32
import org.springframework.web.bind.annotation.RequestMapping;
30
import org.springframework.web.bind.annotation.RequestMethod;
33
import org.springframework.web.bind.annotation.RequestMethod;
31
import org.springframework.web.bind.annotation.RequestParam;
34
import org.springframework.web.bind.annotation.RequestParam;
32
 
35
 
33
import com.eclipsesource.json.JsonObject;
36
import com.eclipsesource.json.JsonObject;
-
 
37
import com.google.common.collect.Ordering;
34
import com.google.gson.Gson;
38
import com.google.gson.Gson;
35
import com.google.gson.reflect.TypeToken;
39
import com.google.gson.reflect.TypeToken;
36
import com.spice.profitmandi.common.enumuration.SchemeType;
40
import com.spice.profitmandi.common.enumuration.SchemeType;
37
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
41
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
38
import com.spice.profitmandi.common.model.CreatePendingOrderRequest;
42
import com.spice.profitmandi.common.model.CreatePendingOrderRequest;
Line 42... Line 46...
42
import com.spice.profitmandi.common.solr.SolrService;
46
import com.spice.profitmandi.common.solr.SolrService;
43
import com.spice.profitmandi.common.web.client.RestClient;
47
import com.spice.profitmandi.common.web.client.RestClient;
44
import com.spice.profitmandi.common.web.util.ResponseSender;
48
import com.spice.profitmandi.common.web.util.ResponseSender;
45
import com.spice.profitmandi.dao.entity.catalog.Item;
49
import com.spice.profitmandi.dao.entity.catalog.Item;
46
import com.spice.profitmandi.dao.entity.catalog.TagListing;
50
import com.spice.profitmandi.dao.entity.catalog.TagListing;
-
 
51
import com.spice.profitmandi.dao.entity.dtr.WebListing;
47
import com.spice.profitmandi.dao.entity.fofo.CurrentInventorySnapshot;
52
import com.spice.profitmandi.dao.entity.fofo.CurrentInventorySnapshot;
48
import com.spice.profitmandi.dao.entity.fofo.PincodePartner;
53
import com.spice.profitmandi.dao.entity.fofo.PincodePartner;
49
import com.spice.profitmandi.dao.entity.inventory.ItemAvailabilityCache;
54
import com.spice.profitmandi.dao.entity.inventory.ItemAvailabilityCache;
50
import com.spice.profitmandi.dao.enumuration.dtr.OtpType;
55
import com.spice.profitmandi.dao.enumuration.dtr.OtpType;
51
import com.spice.profitmandi.dao.model.AddCartRequest;
56
import com.spice.profitmandi.dao.model.AddCartRequest;
52
import com.spice.profitmandi.dao.model.CartItem;
57
import com.spice.profitmandi.dao.model.CartItem;
53
import com.spice.profitmandi.dao.model.CartItemResponseModel;
58
import com.spice.profitmandi.dao.model.CartItemResponseModel;
54
import com.spice.profitmandi.dao.model.CartResponse;
59
import com.spice.profitmandi.dao.model.CartResponse;
55
import com.spice.profitmandi.dao.model.UserCart;
-
 
56
import com.spice.profitmandi.dao.repository.catalog.CategoryRepository;
-
 
57
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
60
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
58
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
61
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
59
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
62
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
60
import com.spice.profitmandi.dao.repository.dtr.Mongo;
-
 
61
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
63
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
-
 
64
import com.spice.profitmandi.dao.repository.dtr.WebListingRepository;
-
 
65
import com.spice.profitmandi.dao.repository.dtr.WebProductListingRepository;
62
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
66
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
63
import com.spice.profitmandi.dao.repository.fofo.PendingOrderService;
67
import com.spice.profitmandi.dao.repository.fofo.PendingOrderService;
64
import com.spice.profitmandi.dao.repository.fofo.PincodePartnerRepository;
68
import com.spice.profitmandi.dao.repository.fofo.PincodePartnerRepository;
65
import com.spice.profitmandi.dao.repository.inventory.ItemAvailabilityCacheRepository;
69
import com.spice.profitmandi.dao.repository.inventory.ItemAvailabilityCacheRepository;
66
import com.spice.profitmandi.service.authentication.RoleManager;
70
import com.spice.profitmandi.service.authentication.RoleManager;
67
import com.spice.profitmandi.service.inventory.FofoAvailabilityInfo;
71
import com.spice.profitmandi.service.inventory.FofoAvailabilityInfo;
68
import com.spice.profitmandi.service.inventory.FofoCatalogResponse;
72
import com.spice.profitmandi.service.inventory.FofoCatalogResponse;
69
import com.spice.profitmandi.service.pricing.PricingService;
-
 
70
import com.spice.profitmandi.service.scheme.SchemeService;
73
import com.spice.profitmandi.service.scheme.SchemeService;
71
import com.spice.profitmandi.service.user.RetailerService;
74
import com.spice.profitmandi.service.user.RetailerService;
72
import com.spice.profitmandi.web.processor.OtpProcessor;
75
import com.spice.profitmandi.web.processor.OtpProcessor;
73
import com.spice.profitmandi.web.res.DealBrands;
76
import com.spice.profitmandi.web.res.DealBrands;
74
import com.spice.profitmandi.web.res.DealObjectResponse;
77
import com.spice.profitmandi.web.res.DealObjectResponse;
Line 84... Line 87...
84
public class StoreController {
87
public class StoreController {
85
 
88
 
86
	private static final Logger logger = LogManager.getLogger(StoreController.class);
89
	private static final Logger logger = LogManager.getLogger(StoreController.class);
87
 
90
 
88
	private static final LocalTime CUTOFF_TIME = LocalTime.of(15, 0);
91
	private static final LocalTime CUTOFF_TIME = LocalTime.of(15, 0);
-
 
92
 
-
 
93
	private static final List<Integer> TAG_IDS = Arrays.asList(4);
89
	
94
 
90
	private static final int DEFAULT_STORE = 171912487;
95
	private static final int DEFAULT_STORE = 171912487;
91
 
96
 
92
	@Value("${python.api.host}")
97
	@Value("${python.api.host}")
93
	private String host;
98
	private String host;
94
 
99
 
Line 98... Line 103...
98
	// This is now unused as we are not supporting multiple companies.
103
	// This is now unused as we are not supporting multiple companies.
99
	@Value("${gadgetCops.invoice.cc}")
104
	@Value("${gadgetCops.invoice.cc}")
100
	private String[] ccGadgetCopInvoiceTo;
105
	private String[] ccGadgetCopInvoiceTo;
101
 
106
 
102
	@Autowired
107
	@Autowired
103
	private PricingService pricingService;
-
 
104
 
-
 
105
	@Autowired
-
 
106
	private PincodePartnerRepository pincodePartnerRepository;
108
	private PincodePartnerRepository pincodePartnerRepository;
107
 
109
 
108
	@Autowired
110
	@Autowired
109
	private FofoStoreRepository fofoStoreRepository;
111
	private FofoStoreRepository fofoStoreRepository;
110
	
112
 
111
	@Autowired
113
	@Autowired
112
	private RetailerService retailerService;
114
	private RetailerService retailerService;
113
 
115
 
114
	@Autowired
116
	@Autowired
115
	private PendingOrderService pendingOrderService;
117
	private PendingOrderService pendingOrderService;
116
 
118
 
117
	@Autowired
119
	@Autowired
118
	private CategoryRepository categoryRepository;
-
 
119
 
-
 
120
	@Autowired
-
 
121
	private SolrService commonSolrService;
120
	private SolrService commonSolrService;
122
 
121
 
123
	@Autowired
122
	@Autowired
124
	private Mongo mongoClient;
-
 
125
 
-
 
126
	@Autowired
-
 
127
	private OtpProcessor otpProcessor;
123
	private OtpProcessor otpProcessor;
128
 
124
 
129
	@Autowired
125
	@Autowired
130
	private CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
126
	private CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
131
 
127
 
132
	@Autowired
128
	@Autowired
133
	private UserAccountRepository userAccountRepository;
-
 
134
 
-
 
135
	@Autowired
-
 
136
	private ResponseSender<?> responseSender;
129
	private ResponseSender<?> responseSender;
137
 
130
 
138
	@Autowired
131
	@Autowired
139
	private TagListingRepository tagListingRepository;
132
	private TagListingRepository tagListingRepository;
140
 
133
 
Line 146... Line 139...
146
 
139
 
147
	@Autowired
140
	@Autowired
148
	private ItemAvailabilityCacheRepository itemAvailabilityCacheRepository;
141
	private ItemAvailabilityCacheRepository itemAvailabilityCacheRepository;
149
 
142
 
150
	@Autowired
143
	@Autowired
151
	private RoleManager roleManagerService;
144
	private WebListingRepository webListingRepository;
152
 
145
 
-
 
146
	@Autowired
153
	List<String> filterableParams = Arrays.asList("brand");
147
	private WebProductListingRepository webProductListingRepository;
154
 
-
 
155
	private Set<Integer> bestSellers = new HashSet<>(Arrays.asList(1022090, 1022346, 1022344, 1022343, 1022336, 1021933,
-
 
156
			1022025, 1003800, 1022322, 1022307, 1022304, 1022004, 1022004, 1021934, 1021897, 1021768));
-
 
157
 
148
 
-
 
149
	@Autowired
158
	private Set<Integer> latestArrivals = new HashSet<>(Arrays.asList(1022382, 1022335, 1022381, 1022386, 1022380,
150
	private RoleManager roleManagerService;
159
			1022377, 1022376, 1022375, 1022374, 1022373, 1022372, 1022371, 1022370));
-
 
160
 
151
 
161
	private Set<Integer> healthGadgets = new HashSet<>(Arrays.asList(1022383, 1022384));
152
	List<String> filterableParams = Arrays.asList("brand");
162
	
-
 
163
	private Set<Integer> topGadgets = new HashSet<>(Arrays.asList(1022167, 1022174, 1022177, 1022184, 1022185, 1022359,
-
 
164
			1022359, 1022359, 1022369, 1022369, 1022369, 1022361, 1022361, 1022361, 1022361, 1022368, 1022368, 1022368,
-
 
165
			1022368, 1021443, 1021439, 1021440, 1021441, 1022313, 1022312, 1022311));
-
 
166
 
153
 
167
	
-
 
168
	@ApiImplicitParams({
154
	@ApiImplicitParams({
169
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
155
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
170
	@RequestMapping(value = "/store/fofo", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
156
	@RequestMapping(value = "/store/fofo", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
171
	public ResponseEntity<?> getFofo(HttpServletRequest request,
157
	public ResponseEntity<?> getFofo(HttpServletRequest request,
172
			@RequestParam(value = "categoryId", required = false, defaultValue = "(3 OR 6)") String categoryId,
158
			@RequestParam(value = "categoryId", required = false, defaultValue = "(3 OR 6)") String categoryId,
Line 178... Line 164...
178
			@RequestParam(value = "hotDeal", required = false) boolean hotDeal) throws Throwable {
164
			@RequestParam(value = "hotDeal", required = false) boolean hotDeal) throws Throwable {
179
		List<FofoCatalogResponse> dealResponse = new ArrayList<>();
165
		List<FofoCatalogResponse> dealResponse = new ArrayList<>();
180
		UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
166
		UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
181
		if (roleManagerService.isPartner(userInfo.getRoleIds())) {
167
		if (roleManagerService.isPartner(userInfo.getRoleIds())) {
182
			// UserCart uc = userAccountRepository.getUserCart(userInfo.getUserId());
168
			// UserCart uc = userAccountRepository.getUserCart(userInfo.getUserId());
183
			List<Integer> tagIds = pricingService.getTagsIdsByRetailerId(userInfo.getRetailerId());
-
 
184
			RestClient rc = new RestClient();
169
			RestClient rc = new RestClient();
185
			Map<String, String> params = new HashMap<>();
170
			Map<String, String> params = new HashMap<>();
186
			List<String> mandatoryQ = new ArrayList<>();
171
			List<String> mandatoryQ = new ArrayList<>();
187
			if (queryTerm != null && !queryTerm.equals("null")) {
172
			if (queryTerm != null && !queryTerm.equals("null")) {
188
				mandatoryQ.add(String.format("+(%s)", queryTerm));
173
				mandatoryQ.add(String.format("+(%s)", queryTerm));
Line 190... Line 175...
190
				queryTerm = null;
175
				queryTerm = null;
191
			}
176
			}
192
			if (subCategoryId != 0) {
177
			if (subCategoryId != 0) {
193
				mandatoryQ
178
				mandatoryQ
194
						.add(String.format("+(subCategoryId_i:%s) +{!parent which=\"subCategoryId_i:%s\"} tagId_i:(%s)",
179
						.add(String.format("+(subCategoryId_i:%s) +{!parent which=\"subCategoryId_i:%s\"} tagId_i:(%s)",
195
								subCategoryId, subCategoryId, StringUtils.join(tagIds, " ")));
180
								subCategoryId, subCategoryId, StringUtils.join(TAG_IDS, " ")));
196
			} else if (hotDeal) {
181
			} else if (hotDeal) {
197
				mandatoryQ.add(String.format("+{!parent which=\"hot_deals_b=true\"} tagId_i:(%s)",
182
				mandatoryQ.add(String.format("+{!parent which=\"hot_deals_b=true\"} tagId_i:(%s)",
198
						StringUtils.join(tagIds, " ")));
183
						StringUtils.join(TAG_IDS, " ")));
199
 
184
 
200
			} else if (StringUtils.isNotBlank(brand)) {
185
			} else if (StringUtils.isNotBlank(brand)) {
201
				mandatoryQ.add(
186
				mandatoryQ.add(
202
						String.format("+(categoryId_i:%s) +(brand_ss:%s) +{!parent which=\"brand_ss:%s\"} tagId_i:(%s)",
187
						String.format("+(categoryId_i:%s) +(brand_ss:%s) +{!parent which=\"brand_ss:%s\"} tagId_i:(%s)",
203
								categoryId, brand, brand, StringUtils.join(tagIds, " ")));
188
								categoryId, brand, brand, StringUtils.join(TAG_IDS, " ")));
204
 
189
 
205
			} else {
190
			} else {
206
				mandatoryQ.add(
191
				mandatoryQ.add(
207
						String.format("+{!parent which=\"id:catalog*\"} tagId_i:(%s)", StringUtils.join(tagIds, " ")));
192
						String.format("+{!parent which=\"id:catalog*\"} tagId_i:(%s)", StringUtils.join(TAG_IDS, " ")));
208
			}
193
			}
209
			params.put("q", StringUtils.join(mandatoryQ, " "));
194
			params.put("q", StringUtils.join(mandatoryQ, " "));
210
			params.put("fl", "*, [child parentFilter=id:catalog*]");
195
			params.put("fl", "*, [child parentFilter=id:catalog*]");
211
			if (queryTerm == null) {
196
			if (queryTerm == null) {
212
				params.put("sort", "create_s desc");
197
				params.put("sort", "create_s desc");
Line 245... Line 230...
245
		List<FofoCatalogResponse> dealResponse = new ArrayList<>();
230
		List<FofoCatalogResponse> dealResponse = new ArrayList<>();
246
		List<Integer> tagIds = Arrays.asList(4);
231
		List<Integer> tagIds = Arrays.asList(4);
247
		UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
232
		UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
248
		if (roleManagerService.isPartner(userInfo.getRoleIds())) {
233
		if (roleManagerService.isPartner(userInfo.getRoleIds())) {
249
			String categoryId = "(3 OR 6)";
234
			String categoryId = "(3 OR 6)";
250
			UserCart uc = userAccountRepository.getUserCart(userInfo.getUserId());
-
 
-
 
235
 
251
			RestClient rc = new RestClient();
236
			RestClient rc = new RestClient();
252
			Map<String, String> params = new HashMap<>();
237
			Map<String, String> params = new HashMap<>();
253
			List<String> mandatoryQ = new ArrayList<>();
238
			List<String> mandatoryQ = new ArrayList<>();
254
			String catalogString = "catalog" + id;
239
			String catalogString = "catalog" + id;
255
 
240
 
Line 307... Line 292...
307
		}.getType());
292
		}.getType());
308
 
293
 
309
		return responseSender.ok(dealBrandsResponse);
294
		return responseSender.ok(dealBrandsResponse);
310
	}
295
	}
311
 
296
 
312
	@RequestMapping(value = "/store/tag/{tag}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
297
	@RequestMapping(value = "/store/listing/{listingUrl}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
313
	public ResponseEntity<?> bestSellers(HttpServletRequest request, @PathVariable String tag) throws Exception {
298
	public ResponseEntity<?> bestSellers(HttpServletRequest request, @PathVariable String listingUrl) throws Exception {
314
		List<FofoCatalogResponse> dealResponse = new ArrayList<>();
299
		List<FofoCatalogResponse> dealResponse = new ArrayList<>();
315
		UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
300
		// UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
316
		// UserCart uc = userAccountRepository.getUserCart(userInfo.getUserId());
301
		// UserCart uc = userAccountRepository.getUserCart(userInfo.getUserId());
317
		List<Integer> tagIds = Arrays.asList(4);
302
		List<Integer> tagIds = Arrays.asList(4);
-
 
303
 
-
 
304
		WebListing webListing = webListingRepository.selectByUrl("url");
-
 
305
		if (webListing == null) {
-
 
306
			throw new ProfitMandiBusinessException("Url", listingUrl, "Could not find the Url");
-
 
307
		}
-
 
308
		List<Integer> webProducts = webProductListingRepository.selectAllByWebListingId(webListing.getId()).stream()
-
 
309
				.filter(x -> x.getRank() > 0).map(x -> x.getEntityId()).collect(Collectors.toList());
-
 
310
 
318
		RestClient rc = new RestClient();
311
		RestClient rc = new RestClient();
319
		Map<String, String> params = new HashMap<>();
312
		Map<String, String> params = new HashMap<>();
320
		List<String> mandatoryQ = new ArrayList<>();
313
		List<String> mandatoryQ = new ArrayList<>();
321
		Set<Integer> catalogIds = this.bestSellers;
-
 
322
		if (tag.equalsIgnoreCase("latestArrivals")) {
-
 
323
			catalogIds = this.latestArrivals;
-
 
324
		} else if (tag.equalsIgnoreCase("topGadgets")) {
-
 
325
			catalogIds = this.topGadgets;
-
 
326
		} else if (tag.equalsIgnoreCase("healthGadgets")) {
-
 
327
		catalogIds = this.healthGadgets;
-
 
328
	}
-
 
329
		mandatoryQ.add(
314
		mandatoryQ.add(String.format(
330
				String.format("+{!parent which=\"catalogId_i:" + StringUtils.join(catalogIds, " ") + "\"} tagId_i:(%s)",
315
				"+{!parent which=\"catalogId_i:" + StringUtils.join(webProducts, " ") + "\"} tagId_i:(%s)",
331
						StringUtils.join(tagIds, " ")));
316
				StringUtils.join(tagIds, " ")));
332
		params.put("q", StringUtils.join(mandatoryQ, " "));
317
		params.put("q", StringUtils.join(mandatoryQ, " "));
333
		params.put("fl", "*, [child parentFilter=id:catalog*]");
318
		params.put("fl", "*, [child parentFilter=id:catalog*]");
334
		// params.put("sort", "create_s desc");
319
		// params.put("sort", "create_s desc");
335
		params.put("start", String.valueOf(0));
320
		params.put("start", String.valueOf(0));
336
		params.put("rows", String.valueOf(30));
321
		params.put("rows", String.valueOf(30));
Line 341... Line 326...
341
		} catch (HttpHostConnectException e) {
326
		} catch (HttpHostConnectException e) {
342
			throw new ProfitMandiBusinessException("", "", "Could not connect to host");
327
			throw new ProfitMandiBusinessException("", "", "Could not connect to host");
343
		}
328
		}
344
		JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
329
		JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
345
		JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
330
		JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
-
 
331
		final Ordering<Integer> rankOrdering = Ordering.explicit(webProducts);
-
 
332
		dealResponse = getCatalogResponse(docs, false).stream().sorted(new Comparator<FofoCatalogResponse>() {
-
 
333
			@Override
-
 
334
			public int compare(FofoCatalogResponse o1, FofoCatalogResponse o2) {
-
 
335
				return rankOrdering.compare(o1.getCatalogId(), o2.getCatalogId());
-
 
336
			}
-
 
337
		}).collect(Collectors.toList());
346
		dealResponse = getCatalogResponse(docs, false);
338
		webListing.setFofoCatalogResponses(dealResponse);
347
		return responseSender.ok(dealResponse);
339
		return responseSender.ok(webListing);
348
	}
340
	}
349
 
341
 
350
	@RequestMapping(value = "/store/otp/generateOTP", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
342
	@RequestMapping(value = "/store/otp/generateOTP", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
351
	public ResponseEntity<?> generateOtp(HttpServletRequest request, @RequestParam String email,
343
	public ResponseEntity<?> generateOtp(HttpServletRequest request, @RequestParam String email,
352
			@RequestParam String phone) throws Exception {
344
			@RequestParam String phone) throws Exception {
Line 376... Line 368...
376
		CustomRetailer customRetailer = retailerService.getFofoRetailer(storeId);
368
		CustomRetailer customRetailer = retailerService.getFofoRetailer(storeId);
377
 
369
 
378
		return responseSender.ok(customRetailer.getAddress());
370
		return responseSender.ok(customRetailer.getAddress());
379
 
371
 
380
	}
372
	}
381
	
373
 
382
	@RequestMapping(value = "/store/address/{pincode}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
374
	@RequestMapping(value = "/store/address/{pincode}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
383
	@ApiImplicitParams({
375
	@ApiImplicitParams({
384
		@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
376
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
385
	@ApiOperation(value = "Get brand list and count for category")
377
	@ApiOperation(value = "Get brand list and count for category")
386
	public ResponseEntity<?> getStoresByPincode(HttpServletRequest request, @PathVariable String pincode) throws Exception {
378
	public ResponseEntity<?> getStoresByPincode(HttpServletRequest request, @PathVariable String pincode)
-
 
379
			throws Exception {
387
		List<PincodePartner> pincodePartners = pincodePartnerRepository.selectPartnersByPincode(pincode);
380
		List<PincodePartner> pincodePartners = pincodePartnerRepository.selectPartnersByPincode(pincode);
388
		int fofoId = DEFAULT_STORE;
381
		int fofoId = DEFAULT_STORE;
389
		if(pincodePartners.size()>0) {
382
		if (pincodePartners.size() > 0) {
390
			fofoId = pincodePartners.get(0).getFofoId();
383
			fofoId = pincodePartners.get(0).getFofoId();
391
		}
384
		}
392
		return responseSender.ok(fofoStoreRepository.selectByRetailerId(fofoId).getCode());
385
		return responseSender.ok(fofoStoreRepository.selectByRetailerId(fofoId).getCode());
393
	}
386
	}
394
 
387
 
-
 
388
	@RequestMapping(value = "/store/listing", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
-
 
389
	@Cacheable(value = "storelisting.all", cacheManager = "thirtyMinsTimeOutCacheManager")
-
 
390
	public ResponseEntity<?> getStoresListing(HttpServletRequest request, @PathVariable String pincode)
-
 
391
			throws Exception {
-
 
392
		List<WebListing> webListings = webListingRepository.selectAllWebListing(Optional.of(true));
-
 
393
		for (WebListing webListing : webListings) {
-
 
394
			List<Integer> webProducts = webProductListingRepository.selectAllByWebListingId(webListing.getId()).stream()
-
 
395
					.filter(x -> x.getRank() > 0).map(x -> x.getEntityId()).collect(Collectors.toList());
-
 
396
 
-
 
397
			RestClient rc = new RestClient();
-
 
398
			Map<String, String> params = new HashMap<>();
-
 
399
			List<String> mandatoryQ = new ArrayList<>();
-
 
400
			mandatoryQ.add(String.format(
-
 
401
					"+{!parent which=\"catalogId_i:" + StringUtils.join(webProducts, " ") + "\"} tagId_i:(%s)",
-
 
402
					StringUtils.join(TAG_IDS, " ")));
-
 
403
			params.put("q", StringUtils.join(mandatoryQ, " "));
-
 
404
			params.put("fl", "*, [child parentFilter=id:catalog*]");
-
 
405
			// params.put("sort", "create_s desc");
-
 
406
			params.put("start", String.valueOf(0));
-
 
407
			params.put("rows", String.valueOf(30));
-
 
408
			params.put("wt", "json");
-
 
409
			String response = null;
-
 
410
			try {
-
 
411
				response = rc.get(SchemeType.HTTP, "50.116.10.120", 8984, "solr/demo/select", params);
-
 
412
			} catch (HttpHostConnectException e) {
-
 
413
				throw new ProfitMandiBusinessException("", "", "Could not connect to host");
-
 
414
			}
-
 
415
			JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
-
 
416
			JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
-
 
417
			final Ordering<Integer> colorOrdering = Ordering.explicit(webProducts);
-
 
418
			List<FofoCatalogResponse> dealResponse = getCatalogResponse(docs, false).stream()
-
 
419
					.sorted(new Comparator<FofoCatalogResponse>() {
-
 
420
						@Override
-
 
421
						public int compare(FofoCatalogResponse o1, FofoCatalogResponse o2) {
-
 
422
							return colorOrdering.compare(o1.getCatalogId(), o2.getCatalogId());
-
 
423
						}
-
 
424
					}).collect(Collectors.toList());
-
 
425
			webListing.setFofoCatalogResponses(dealResponse);
-
 
426
		}
-
 
427
		return responseSender.ok(webListings);
-
 
428
	}
-
 
429
 
395
	@RequestMapping(value = "/store/cart", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
430
	@RequestMapping(value = "/store/cart", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
396
	@ApiImplicitParams({
431
	@ApiImplicitParams({
397
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
432
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
398
	@ApiOperation(value = "Get brand list and count for category")
433
	@ApiOperation(value = "Get brand list and count for category")
399
	public ResponseEntity<?> cart(HttpServletRequest request, @RequestBody AddCartRequest cartRequest)
434
	public ResponseEntity<?> cart(HttpServletRequest request, @RequestBody AddCartRequest cartRequest)
Line 574... Line 609...
574
				ffdr.setItems(new ArrayList<FofoAvailabilityInfo>(fofoAvailabilityInfoMap.values()));
609
				ffdr.setItems(new ArrayList<FofoAvailabilityInfo>(fofoAvailabilityInfoMap.values()));
575
				dealResponse.add(ffdr);
610
				dealResponse.add(ffdr);
576
			}
611
			}
577
		}
612
		}
578
		return dealResponse;
613
		return dealResponse;
579
 
-
 
580
	}
614
	}
581
 
615
 
582
}
616
}
583
617