| Line 49... |
Line 49... |
| 49 |
import com.spice.profitmandi.dao.entity.catalog.Category;
|
49 |
import com.spice.profitmandi.dao.entity.catalog.Category;
|
| 50 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
50 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
| 51 |
import com.spice.profitmandi.dao.entity.catalog.TagListing;
|
51 |
import com.spice.profitmandi.dao.entity.catalog.TagListing;
|
| 52 |
import com.spice.profitmandi.dao.entity.fofo.SuggestedPo;
|
52 |
import com.spice.profitmandi.dao.entity.fofo.SuggestedPo;
|
| 53 |
import com.spice.profitmandi.dao.entity.fofo.SuggestedPoDetail;
|
53 |
import com.spice.profitmandi.dao.entity.fofo.SuggestedPoDetail;
|
| 54 |
import com.spice.profitmandi.dao.entity.inventory.ItemAvailabilityCache;
|
- |
|
| 55 |
import com.spice.profitmandi.dao.model.UserCart;
|
54 |
import com.spice.profitmandi.dao.model.UserCart;
|
| 56 |
import com.spice.profitmandi.dao.repository.catalog.CategoryRepository;
|
55 |
import com.spice.profitmandi.dao.repository.catalog.CategoryRepository;
|
| 57 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
56 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
| 58 |
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
|
57 |
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
|
| 59 |
import com.spice.profitmandi.dao.repository.dtr.Mongo;
|
58 |
import com.spice.profitmandi.dao.repository.dtr.Mongo;
|
| 60 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
59 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
| - |
|
60 |
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
|
| 61 |
import com.spice.profitmandi.dao.repository.fofo.SuggestedPoDetailRepository;
|
61 |
import com.spice.profitmandi.dao.repository.fofo.SuggestedPoDetailRepository;
|
| 62 |
import com.spice.profitmandi.dao.repository.fofo.SuggestedPoRepository;
|
62 |
import com.spice.profitmandi.dao.repository.fofo.SuggestedPoRepository;
|
| 63 |
import com.spice.profitmandi.dao.repository.inventory.ItemAvailabilityCacheRepository;
|
63 |
import com.spice.profitmandi.dao.repository.inventory.ItemAvailabilityCacheRepository;
|
| 64 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
64 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
| 65 |
import com.spice.profitmandi.service.inventory.AvailabilityInfo;
|
65 |
import com.spice.profitmandi.service.inventory.AvailabilityInfo;
|
| 66 |
import com.spice.profitmandi.service.inventory.Bucket;
|
66 |
import com.spice.profitmandi.service.inventory.Bucket;
|
| 67 |
import com.spice.profitmandi.service.inventory.FofoAvailabilityInfo;
|
67 |
import com.spice.profitmandi.service.inventory.FofoAvailabilityInfo;
|
| 68 |
import com.spice.profitmandi.service.inventory.FofoCatalogResponse;
|
68 |
import com.spice.profitmandi.service.inventory.FofoCatalogResponse;
|
| 69 |
import com.spice.profitmandi.service.inventory.ItemBucketService;
|
69 |
import com.spice.profitmandi.service.inventory.ItemBucketService;
|
| 70 |
import com.spice.profitmandi.service.inventory.ItemQuantityPojo;
|
70 |
import com.spice.profitmandi.service.inventory.ItemQuantityPojo;
|
| - |
|
71 |
import com.spice.profitmandi.service.inventory.SaholicInventoryService;
|
| 71 |
import com.spice.profitmandi.service.pricing.PricingService;
|
72 |
import com.spice.profitmandi.service.pricing.PricingService;
|
| 72 |
import com.spice.profitmandi.service.scheme.SchemeService;
|
73 |
import com.spice.profitmandi.service.scheme.SchemeService;
|
| 73 |
import com.spice.profitmandi.web.res.DealBrands;
|
74 |
import com.spice.profitmandi.web.res.DealBrands;
|
| 74 |
import com.spice.profitmandi.web.res.DealObjectResponse;
|
75 |
import com.spice.profitmandi.web.res.DealObjectResponse;
|
| 75 |
import com.spice.profitmandi.web.res.DealsResponse;
|
76 |
import com.spice.profitmandi.web.res.DealsResponse;
|
| Line 85... |
Line 86... |
| 85 |
private static final Logger logger = LogManager.getLogger(DealsController.class);
|
86 |
private static final Logger logger = LogManager.getLogger(DealsController.class);
|
| 86 |
|
87 |
|
| 87 |
@Value("${python.api.host}")
|
88 |
@Value("${python.api.host}")
|
| 88 |
private String host;
|
89 |
private String host;
|
| 89 |
|
90 |
|
| - |
|
91 |
@Value("${new.solr.url}")
|
| - |
|
92 |
private String solrUrl;
|
| - |
|
93 |
|
| 90 |
@Value("${python.api.port}")
|
94 |
@Value("${python.api.port}")
|
| 91 |
private int port;
|
95 |
private int port;
|
| 92 |
|
96 |
|
| - |
|
97 |
@Autowired
|
| - |
|
98 |
RestClient restClient;
|
| - |
|
99 |
|
| 93 |
// This is now unused as we are not supporting multiple companies.
|
100 |
// This is now unused as we are not supporting multiple companies.
|
| 94 |
@Value("${gadgetCops.invoice.cc}")
|
101 |
@Value("${gadgetCops.invoice.cc}")
|
| 95 |
private String[] ccGadgetCopInvoiceTo;
|
102 |
private String[] ccGadgetCopInvoiceTo;
|
| 96 |
|
103 |
|
| 97 |
@Autowired
|
104 |
@Autowired
|
| 98 |
private PricingService pricingService;
|
105 |
private PricingService pricingService;
|
| 99 |
|
106 |
|
| 100 |
@Autowired
|
107 |
@Autowired
|
| - |
|
108 |
private CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
|
| - |
|
109 |
|
| - |
|
110 |
@Autowired
|
| 101 |
private CategoryRepository categoryRepository;
|
111 |
private CategoryRepository categoryRepository;
|
| 102 |
|
112 |
|
| 103 |
@Autowired
|
113 |
@Autowired
|
| 104 |
private SchemeService schemeService;
|
114 |
private SchemeService schemeService;
|
| 105 |
|
115 |
|
| 106 |
@Autowired
|
116 |
@Autowired
|
| - |
|
117 |
private SaholicInventoryService saholicInventoryService;
|
| - |
|
118 |
|
| - |
|
119 |
@Autowired
|
| 107 |
private Mongo mongoClient;
|
120 |
private Mongo mongoClient;
|
| 108 |
|
121 |
|
| 109 |
@Autowired
|
122 |
@Autowired
|
| 110 |
private ItemBucketService itemBucketService;
|
123 |
private ItemBucketService itemBucketService;
|
| 111 |
|
124 |
|
| Line 163... |
Line 176... |
| 163 |
params.put("fl", "*, [child parentFilter=id:catalog*]");
|
176 |
params.put("fl", "*, [child parentFilter=id:catalog*]");
|
| 164 |
|
177 |
|
| 165 |
params.put("wt", "json");
|
178 |
params.put("wt", "json");
|
| 166 |
String response = null;
|
179 |
String response = null;
|
| 167 |
try {
|
180 |
try {
|
| 168 |
response = rc.get(SchemeType.HTTP, "50.116.10.120", 8984, "solr/demo/select", params);
|
181 |
response = rc.get(SchemeType.HTTP, solrUrl, 8984, "solr/demo/select", params);
|
| 169 |
} catch (HttpHostConnectException e) {
|
182 |
} catch (HttpHostConnectException e) {
|
| 170 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
183 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
| 171 |
}
|
184 |
}
|
| 172 |
JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
|
185 |
JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
|
| 173 |
JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
|
186 |
JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
|
| Line 200... |
Line 213... |
| 200 |
params.put("fl", "*, [child parentFilter=id:catalog*]");
|
213 |
params.put("fl", "*, [child parentFilter=id:catalog*]");
|
| 201 |
|
214 |
|
| 202 |
params.put("wt", "json");
|
215 |
params.put("wt", "json");
|
| 203 |
String response = null;
|
216 |
String response = null;
|
| 204 |
try {
|
217 |
try {
|
| 205 |
response = rc.get(SchemeType.HTTP, "50.116.10.120", 8984, "solr/demo/select", params);
|
218 |
response = rc.get(SchemeType.HTTP, solrUrl, 8984, "solr/demo/select", params);
|
| 206 |
} catch (HttpHostConnectException e) {
|
219 |
} catch (HttpHostConnectException e) {
|
| 207 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
220 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
| 208 |
}
|
221 |
}
|
| 209 |
JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
|
222 |
JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
|
| 210 |
JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
|
223 |
JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
|
| Line 246... |
Line 259... |
| 246 |
@RequestParam(value = "subCategoryId", required = false) int subCategoryId,
|
259 |
@RequestParam(value = "subCategoryId", required = false) int subCategoryId,
|
| 247 |
@RequestParam(value = "q", required = false) String queryTerm,
|
260 |
@RequestParam(value = "q", required = false) String queryTerm,
|
| 248 |
@RequestParam(value = "hotDeal", required = false) boolean hotDeal) throws Throwable {
|
261 |
@RequestParam(value = "hotDeal", required = false) boolean hotDeal) throws Throwable {
|
| 249 |
List<FofoCatalogResponse> dealResponse = new ArrayList<>();
|
262 |
List<FofoCatalogResponse> dealResponse = new ArrayList<>();
|
| 250 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
263 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
| 251 |
if (roleManagerService.isPartner(userInfo.getRoleIds())) {
|
- |
|
| 252 |
// UserCart uc = userAccountRepository.getUserCart(userInfo.getUserId());
|
- |
|
| 253 |
List<Integer> tagIds = pricingService.getTagsIdsByRetailerId(userInfo.getRetailerId());
|
264 |
dealResponse = this.getCatalogResponse(this.getSolrDocs(userInfo.getRetailerId(), queryTerm, categoryId, offset,
|
| 254 |
RestClient rc = new RestClient();
|
- |
|
| 255 |
Map<String, String> params = new HashMap<>();
|
265 |
limit, sort, brand, subCategoryId, hotDeal), hotDeal, 0);
|
| 256 |
List<String> mandatoryQ = new ArrayList<>();
|
266 |
return responseSender.ok(dealResponse);
|
| 257 |
if (queryTerm != null && !queryTerm.equals("null")) {
|
- |
|
| 258 |
mandatoryQ.add(String.format("+(%s)", queryTerm));
|
- |
|
| 259 |
} else {
|
- |
|
| 260 |
queryTerm = null;
|
- |
|
| 261 |
}
|
267 |
}
|
| - |
|
268 |
|
| 262 |
if (subCategoryId != 0) {
|
269 |
private JSONArray getSolrDocs(int fofoId, String queryTerm, String categoryId, String offset, String limit,
|
| 263 |
mandatoryQ.add(String.format("{!parent which=\"subCategoryId_i:%s AND child_b:true\"}tagId_i:(%s)",
|
270 |
String sort, String brand, int subCategoryId, boolean hotDeal) throws Throwable {
|
| 264 |
subCategoryId, StringUtils.join(tagIds, " ")));
|
271 |
List<Integer> tagIds = pricingService.getTagsIdsByRetailerId(fofoId);
|
| 265 |
} else if (hotDeal) {
|
- |
|
| 266 |
mandatoryQ.add(String.format("{!parent which=\"hot_deals_b=true AND child_b:true\"}tagId_i:(%s)",
|
272 |
List<String> parentFilter = new ArrayList<>();
|
| 267 |
StringUtils.join(tagIds, " ")));
|
273 |
parentFilter.add("categoryId_i:" + categoryId);
|
| 268 |
|
274 |
|
| 269 |
} else if (StringUtils.isNotBlank(brand)) {
|
275 |
List<String> childFilter = new ArrayList<>();
|
| 270 |
mandatoryQ.add(String.format(
|
276 |
childFilter.add("itemId_i:*");
|
| 271 |
"{!parent which=\"brand_ss:%s AND categoryId_i:%s " + "AND child_b:true\"}tagId_i:(%s)", brand,
|
- |
|
| 272 |
categoryId, StringUtils.join(tagIds, " ")));
|
- |
|
| 273 |
|
277 |
|
| 274 |
} else {
|
- |
|
| 275 |
mandatoryQ.add(String.format("{!parent which=\"subCategoryId_i:%s\"}tagId_i:(%s) AND child_b:true",
|
- |
|
| 276 |
categoryId, StringUtils.join(tagIds, " ")));
|
278 |
Map<String, String> params = new HashMap<>();
|
| 277 |
}
|
- |
|
| 278 |
params.put("q", StringUtils.join(mandatoryQ, " "));
|
- |
|
| 279 |
params.put("fl", "*, [child parentFilter=id:catalog*]");
|
279 |
if (queryTerm == null || queryTerm.equals("null")) {
|
| 280 |
if (queryTerm == null) {
|
280 |
queryTerm = "";
|
| 281 |
params.put("sort", "create_s desc");
|
- |
|
| 282 |
}
|
- |
|
| 283 |
params.put("start", String.valueOf(offset));
|
- |
|
| 284 |
params.put("rows", String.valueOf(limit));
|
- |
|
| 285 |
params.put("wt", "json");
|
- |
|
| 286 |
String response = null;
|
- |
|
| 287 |
try {
|
- |
|
| 288 |
response = rc.get(SchemeType.HTTP, "50.116.10.120", 8984, "solr/demo/select", params);
|
- |
|
| 289 |
} catch (HttpHostConnectException e) {
|
- |
|
| 290 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
- |
|
| 291 |
}
|
- |
|
| 292 |
JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
|
- |
|
| 293 |
JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
|
- |
|
| 294 |
dealResponse = this.getCatalogResponse(docs, hotDeal);
|
- |
|
| 295 |
/*
|
- |
|
| 296 |
* if (Mongo.PARTNER_BLoCKED_BRANDS.containsKey(userInfo.getEmail())) {
|
- |
|
| 297 |
* dealResponse.stream() .filter(x ->
|
- |
|
| 298 |
* Mongo.PARTNER_BLoCKED_BRANDS.get(userInfo.getEmail()).contains(x.getBrand()))
|
- |
|
| 299 |
* ; }
|
- |
|
| 300 |
*/
|
- |
|
| 301 |
} else {
|
281 |
} else {
|
| 302 |
return responseSender.badRequest(
|
282 |
queryTerm = "(" + queryTerm + ")";
|
| 303 |
new ProfitMandiBusinessException("Retailer id", userInfo.getUserId(), "NOT_FOFO_RETAILER"));
|
- |
|
| 304 |
}
|
283 |
}
|
| - |
|
284 |
if (hotDeal) {
|
| 305 |
return responseSender.ok(dealResponse);
|
285 |
childFilter.add("hot_deal_b:true");
|
| - |
|
286 |
} else {
|
| - |
|
287 |
childFilter.add("active_b:true");
|
| - |
|
288 |
}
|
| - |
|
289 |
if (subCategoryId != 0) {
|
| - |
|
290 |
parentFilter.add("subCategoryId_i:" + subCategoryId);
|
| - |
|
291 |
}
|
| - |
|
292 |
if (StringUtils.isNotBlank(brand)) {
|
| - |
|
293 |
parentFilter.add("brand_ss:" + brand);
|
| - |
|
294 |
}
|
| - |
|
295 |
String parentFilterString = "\"" + String.join(" AND ", parentFilter) + "\"";
|
| - |
|
296 |
String childFilterString = String.join(" AND ", childFilter);
|
| - |
|
297 |
logger.info(parentFilterString);
|
| - |
|
298 |
params.put("q", String.format("%s{!parent which=%s}%s", queryTerm, parentFilterString, childFilterString));
|
| - |
|
299 |
params.put("fl", String.format("*, [child parentFilter=%s childFilter=%s]", parentFilterString,
|
| - |
|
300 |
"\"" + childFilterString + "\""));
|
| - |
|
301 |
if (queryTerm == "") {
|
| - |
|
302 |
params.put("sort", "create_s desc");
|
| - |
|
303 |
}
|
| - |
|
304 |
params.put("start", String.valueOf(offset));
|
| - |
|
305 |
params.put("rows", String.valueOf(limit));
|
| - |
|
306 |
params.put("wt", "json");
|
| - |
|
307 |
String response = null;
|
| - |
|
308 |
try {
|
| - |
|
309 |
response = restClient.get(SchemeType.HTTP, "50.116.10.120", 8984, "solr/demo/select", params);
|
| - |
|
310 |
} catch (HttpHostConnectException e) {
|
| - |
|
311 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
| - |
|
312 |
}
|
| - |
|
313 |
JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
|
| - |
|
314 |
JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
|
| - |
|
315 |
return docs;
|
| 306 |
}
|
316 |
}
|
| 307 |
|
317 |
|
| 308 |
@ApiImplicitParams({
|
318 |
@ApiImplicitParams({
|
| 309 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
319 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
| 310 |
@RequestMapping(value = "/partnerStock", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
320 |
@RequestMapping(value = "/partnerStock", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| Line 318... |
Line 328... |
| 318 |
@RequestParam(value = " ", required = false, defaultValue = "true") boolean partnerStockOnly)
|
328 |
@RequestParam(value = " ", required = false, defaultValue = "true") boolean partnerStockOnly)
|
| 319 |
throws Throwable {
|
329 |
throws Throwable {
|
| 320 |
List<FofoCatalogResponse> dealResponse = new ArrayList<>();
|
330 |
List<FofoCatalogResponse> dealResponse = new ArrayList<>();
|
| 321 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
331 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
| 322 |
UserCart uc = userAccountRepository.getUserCart(userInfo.getUserId());
|
332 |
UserCart uc = userAccountRepository.getUserCart(userInfo.getUserId());
|
| 323 |
|
- |
|
| 324 |
logger.info("Retiler Id ==> {}", uc.getUserId());
|
- |
|
| 325 |
if (roleManagerService.isPartner(userInfo.getRoleIds())) {
|
- |
|
| 326 |
if (partnerStockOnly) {
|
- |
|
| 327 |
|
- |
|
| 328 |
}
|
- |
|
| 329 |
List<Integer> tagIds = pricingService.getTagsIdsByRetailerId(userInfo.getRetailerId());
|
333 |
dealResponse = this.getCatalogResponse(this.getSolrDocs(uc.getUserId(), queryTerm, categoryId, offset, limit,
|
| 330 |
RestClient rc = new RestClient();
|
- |
|
| 331 |
Map<String, String> params = new HashMap<>();
|
- |
|
| 332 |
List<String> mandatoryQ = new ArrayList<>();
|
- |
|
| 333 |
if (queryTerm != null && !queryTerm.equals("null")) {
|
- |
|
| 334 |
mandatoryQ.add(String.format("+(%s)", queryTerm));
|
- |
|
| 335 |
} else {
|
- |
|
| 336 |
queryTerm = null;
|
- |
|
| 337 |
}
|
- |
|
| 338 |
if (subCategoryId != 0) {
|
- |
|
| 339 |
mandatoryQ
|
- |
|
| 340 |
.add(String.format("+(subCategoryId_i:%s) +{!parent which=\"subCategoryId_i:%s\"} tagId_i:(%s)",
|
- |
|
| 341 |
subCategoryId, subCategoryId, StringUtils.join(tagIds, " ")));
|
334 |
sort, brand, subCategoryId, false), false, userInfo.getRetailerId());
|
| 342 |
} else if (StringUtils.isNotBlank(brand)) {
|
- |
|
| 343 |
mandatoryQ.add(
|
- |
|
| 344 |
String.format("+(categoryId_i:%s) +(brand_ss:%s) +{!parent which=\"brand_ss:%s\"} tagId_i:(%s)",
|
- |
|
| 345 |
categoryId, brand, brand, StringUtils.join(tagIds, " ")));
|
- |
|
| 346 |
|
- |
|
| 347 |
} else {
|
- |
|
| 348 |
mandatoryQ.add(
|
- |
|
| 349 |
String.format("+{!parent which=\"id:catalog*\"} tagId_i:(%s)", StringUtils.join(tagIds, " ")));
|
- |
|
| 350 |
}
|
- |
|
| 351 |
params.put("q", StringUtils.join(mandatoryQ, " "));
|
- |
|
| 352 |
params.put("fl", "*, [child parentFilter=id:catalog*]");
|
- |
|
| 353 |
if (queryTerm == null) {
|
- |
|
| 354 |
params.put("sort", "create_s desc");
|
- |
|
| 355 |
}
|
- |
|
| 356 |
params.put("start", String.valueOf(offset));
|
- |
|
| 357 |
params.put("rows", String.valueOf(limit));
|
- |
|
| 358 |
params.put("wt", "json");
|
- |
|
| 359 |
String response = null;
|
- |
|
| 360 |
try {
|
- |
|
| 361 |
response = rc.get(SchemeType.HTTP, "50.116.10.120", 8984, "solr/demo/select", params);
|
- |
|
| 362 |
} catch (HttpHostConnectException e) {
|
- |
|
| 363 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
- |
|
| 364 |
}
|
- |
|
| 365 |
JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
|
- |
|
| 366 |
JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
|
- |
|
| 367 |
dealResponse = getCatalogResponse(docs, false);
|
- |
|
| 368 |
/*
|
- |
|
| 369 |
* if (Mongo.PARTNER_BLoCKED_BRANDS.containsKey(userInfo.getEmail())) {
|
- |
|
| 370 |
* dealResponse.stream() .filter(x ->
|
- |
|
| 371 |
* Mongo.PARTNER_BLoCKED_BRANDS.get(userInfo.getEmail()).contains(x.getBrand()))
|
- |
|
| 372 |
* ; }
|
- |
|
| 373 |
*/
|
- |
|
| 374 |
} else {
|
- |
|
| 375 |
return responseSender.badRequest(
|
- |
|
| 376 |
new ProfitMandiBusinessException("Retailer id", userInfo.getUserId(), "NOT_FOFO_RETAILER"));
|
- |
|
| 377 |
}
|
- |
|
| 378 |
return responseSender.ok(dealResponse);
|
335 |
return responseSender.ok(dealResponse);
|
| 379 |
}
|
336 |
}
|
| 380 |
|
337 |
|
| 381 |
@RequestMapping(value = "/online-deals", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
338 |
@RequestMapping(value = "/online-deals", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 382 |
@ApiImplicitParams({
|
339 |
@ApiImplicitParams({
|
| Line 521... |
Line 478... |
| 521 |
} catch (HttpHostConnectException e) {
|
478 |
} catch (HttpHostConnectException e) {
|
| 522 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
479 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
| 523 |
}
|
480 |
}
|
| 524 |
JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
|
481 |
JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
|
| 525 |
JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
|
482 |
JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
|
| 526 |
dealResponse = getCatalogResponse(docs, false);
|
483 |
dealResponse = getCatalogResponse(docs, false, userInfo.getRetailerId());
|
| 527 |
} else {
|
484 |
} else {
|
| 528 |
return responseSender.badRequest(
|
485 |
return responseSender.badRequest(
|
| 529 |
new ProfitMandiBusinessException("Retailer id", userInfo.getUserId(), "NOT_FOFO_RETAILER"));
|
486 |
new ProfitMandiBusinessException("Retailer id", userInfo.getUserId(), "NOT_FOFO_RETAILER"));
|
| 530 |
}
|
487 |
}
|
| 531 |
return responseSender.ok(dealResponse.get(0));
|
488 |
return responseSender.ok(dealResponse.get(0));
|
| Line 543... |
Line 500... |
| 543 |
|
500 |
|
| 544 |
@RequestMapping(value = "/fofo/accessory/all-categories", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
501 |
@RequestMapping(value = "/fofo/accessory/all-categories", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 545 |
public ResponseEntity<?> getSubCategoriesToDisplay(HttpServletRequest request) throws Exception {
|
502 |
public ResponseEntity<?> getSubCategoriesToDisplay(HttpServletRequest request) throws Exception {
|
| 546 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
503 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
| 547 |
logger.info("userInfo [{}]", userInfo);
|
504 |
logger.info("userInfo [{}]", userInfo);
|
| 548 |
List<DBObject> subCateogriesDisplay = this.getSubCategoriesToDisplay();
|
505 |
List<DBObject> subCategoriesDisplay = this.getSubCategoriesToDisplay();
|
| 549 |
return new ResponseEntity<>(subCateogriesDisplay, HttpStatus.OK);
|
506 |
return new ResponseEntity<>(subCategoriesDisplay, HttpStatus.OK);
|
| 550 |
}
|
507 |
}
|
| 551 |
|
508 |
|
| 552 |
private List<DBObject> getSubCategoriesToDisplay() throws Exception {
|
509 |
private List<DBObject> getSubCategoriesToDisplay() throws Exception {
|
| 553 |
List<DBObject> subCategories = new ArrayList<>();
|
510 |
List<DBObject> subCategories = new ArrayList<>();
|
| 554 |
RestClient rc = new RestClient();
|
511 |
RestClient rc = new RestClient();
|
| Line 627... |
Line 584... |
| 627 |
}
|
584 |
}
|
| 628 |
}
|
585 |
}
|
| 629 |
return responseSender.ok(responseObject);
|
586 |
return responseSender.ok(responseObject);
|
| 630 |
}
|
587 |
}
|
| 631 |
|
588 |
|
| 632 |
private List<FofoCatalogResponse> getCatalogResponse(JSONArray docs, boolean hotDeal)
|
589 |
private List<FofoCatalogResponse> getCatalogResponse(JSONArray docs, boolean hotDeal, int fofoId)
|
| 633 |
throws ProfitMandiBusinessException {
|
590 |
throws ProfitMandiBusinessException {
|
| 634 |
Map<Integer, TagListing> itemTagListingMap = null;
|
591 |
Map<Integer, Integer> ourItemAvailabilityMap = null;
|
| - |
|
592 |
Map<Integer, Integer> partnerStockAvailabilityMap = null;
|
| 635 |
List<FofoCatalogResponse> dealResponse = new ArrayList<>();
|
593 |
List<FofoCatalogResponse> dealResponse = new ArrayList<>();
|
| 636 |
List<Integer> tagIds = Arrays.asList(4);
|
594 |
List<Integer> tagIds = Arrays.asList(4);
|
| 637 |
if (docs.length() > 0) {
|
595 |
if (docs.length() > 0) {
|
| 638 |
HashSet<Integer> itemsSet = new HashSet<>();
|
596 |
HashSet<Integer> itemsSet = new HashSet<>();
|
| 639 |
for (int i = 0; i < docs.length(); i++) {
|
597 |
for (int i = 0; i < docs.length(); i++) {
|
| Line 647... |
Line 605... |
| 647 |
}
|
605 |
}
|
| 648 |
}
|
606 |
}
|
| 649 |
if (itemsSet.size() == 0) {
|
607 |
if (itemsSet.size() == 0) {
|
| 650 |
return dealResponse;
|
608 |
return dealResponse;
|
| 651 |
}
|
609 |
}
|
| - |
|
610 |
if (hotDeal) {
|
| 652 |
itemTagListingMap = tagListingRepository.selectByItemIdsAndTagIds(itemsSet, new HashSet<>(tagIds)).stream()
|
611 |
ourItemAvailabilityMap = saholicInventoryService.getTotalAvailabilityByItemIds(new ArrayList<>(itemsSet));
|
| - |
|
612 |
} else if (fofoId > 0) {
|
| - |
|
613 |
partnerStockAvailabilityMap = currentInventorySnapshotRepository.selectItemsStock().stream()
|
| 653 |
.collect(Collectors.toMap(x -> x.getItemId(), x -> x));
|
614 |
.collect(Collectors.toMap(x -> x.getItemId(), x -> x.getAvailability()));
|
| - |
|
615 |
ourItemAvailabilityMap = saholicInventoryService.getTotalAvailabilityByItemIds(new ArrayList<>(itemsSet));
|
| - |
|
616 |
}
|
| 654 |
}
|
617 |
}
|
| 655 |
|
618 |
|
| - |
|
619 |
List<FofoAvailabilityInfo> fdis = new ArrayList<>();
|
| - |
|
620 |
|
| 656 |
for (int i = 0; i < docs.length(); i++) {
|
621 |
for (int i = 0; i < docs.length(); i++) {
|
| 657 |
Map<Integer, FofoAvailabilityInfo> fofoAvailabilityInfoMap = new HashMap<>();
|
622 |
Map<Integer, FofoAvailabilityInfo> fofoAvailabilityInfoMap = new HashMap<>();
|
| 658 |
JSONObject doc = docs.getJSONObject(i);
|
623 |
JSONObject doc = docs.getJSONObject(i);
|
| 659 |
FofoCatalogResponse ffdr = new FofoCatalogResponse();
|
624 |
FofoCatalogResponse ffdr = new FofoCatalogResponse();
|
| 660 |
ffdr.setCatalogId(doc.getInt("catalogId_i"));
|
625 |
ffdr.setCatalogId(doc.getInt("catalogId_i"));
|
| Line 669... |
Line 634... |
| 669 |
ffdr.setBrand(doc.getJSONArray("brand_ss").getString(0));
|
634 |
ffdr.setBrand(doc.getJSONArray("brand_ss").getString(0));
|
| 670 |
if (doc.has("_childDocuments_")) {
|
635 |
if (doc.has("_childDocuments_")) {
|
| 671 |
for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
|
636 |
for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
|
| 672 |
JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
|
637 |
JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
|
| 673 |
int itemId = childItem.getInt("itemId_i");
|
638 |
int itemId = childItem.getInt("itemId_i");
|
| 674 |
TagListing tl = itemTagListingMap.get(itemId);
|
- |
|
| 675 |
if (tl == null) {
|
- |
|
| 676 |
logger.warn("Could not find item id {}", itemId);
|
- |
|
| 677 |
continue;
|
- |
|
| 678 |
}
|
- |
|
| 679 |
if (hotDeal) {
|
- |
|
| 680 |
if (!tl.isHotDeals()) {
|
- |
|
| 681 |
continue;
|
- |
|
| 682 |
}
|
- |
|
| 683 |
}
|
- |
|
| 684 |
float sellingPrice = (float) childItem.getDouble("sellingPrice_f");
|
639 |
float sellingPrice = (float) childItem.getDouble("sellingPrice_f");
|
| 685 |
if (fofoAvailabilityInfoMap.containsKey(itemId)) {
|
640 |
if (fofoAvailabilityInfoMap.containsKey(itemId)) {
|
| 686 |
if (fofoAvailabilityInfoMap.get(itemId).getSellingPrice() > sellingPrice) {
|
641 |
if (fofoAvailabilityInfoMap.get(itemId).getSellingPrice() > sellingPrice) {
|
| 687 |
fofoAvailabilityInfoMap.get(itemId).setSellingPrice(sellingPrice);
|
642 |
fofoAvailabilityInfoMap.get(itemId).setSellingPrice(sellingPrice);
|
| 688 |
fofoAvailabilityInfoMap.get(itemId).setMop((float) childItem.getDouble("mop_f"));
|
643 |
fofoAvailabilityInfoMap.get(itemId).setMop((float) childItem.getDouble("mop_f"));
|
| 689 |
}
|
644 |
}
|
| 690 |
} else {
|
645 |
} else {
|
| 691 |
FofoAvailabilityInfo fdi = new FofoAvailabilityInfo();
|
646 |
FofoAvailabilityInfo fdi = new FofoAvailabilityInfo();
|
| - |
|
647 |
fdi.setSellingPrice(sellingPrice);
|
| 692 |
fdi.setSellingPrice((float) childItem.getDouble("sellingPrice_f"));
|
648 |
fdi.setActive(childItem.getBoolean("active_b"));
|
| 693 |
fdi.setMrp((double) tl.getMrp());
|
649 |
fdi.setMrp(childItem.getDouble("mrp_f"));
|
| 694 |
fdi.setMop((float) childItem.getDouble("mop_f"));
|
650 |
fdi.setMop((float) childItem.getDouble("mop_f"));
|
| 695 |
fdi.setColor(childItem.has("color_s") ? childItem.getString("color_s") : "");
|
651 |
fdi.setColor(childItem.has("color_s") ? childItem.getString("color_s") : "");
|
| 696 |
fdi.setTagId(childItem.getInt("tagId_i"));
|
652 |
fdi.setTagId(childItem.getInt("tagId_i"));
|
| 697 |
fdi.setItem_id(itemId);
|
653 |
fdi.setItem_id(itemId);
|
| 698 |
Float cashBack = schemeService.getItemSchemeCashBack().get(itemId);
|
654 |
Float cashBack = schemeService.getItemSchemeCashBack().get(itemId);
|
| 699 |
cashBack = cashBack == null ? 0 : cashBack;
|
655 |
cashBack = cashBack == null ? 0 : cashBack;
|
| 700 |
fdi.setCashback(cashBack);
|
656 |
fdi.setCashback(cashBack);
|
| 701 |
Item item = itemRepository.selectById(itemId);
|
- |
|
| 702 |
// In case its tampered glass moq should be 5
|
- |
|
| 703 |
if (item.getCategoryId() == 10020) {
|
- |
|
| 704 |
fdi.setMinBuyQuantity(10);
|
- |
|
| 705 |
} else {
|
- |
|
| 706 |
fdi.setMinBuyQuantity(1);
|
- |
|
| 707 |
}
|
657 |
|
| 708 |
if (hotDeal || !tl.isActive()) {
|
- |
|
| 709 |
|
- |
|
| 710 |
int totalAvailability = 0; // Using item availability
|
- |
|
| 711 |
// cache for now but can be
|
- |
|
| 712 |
// changed to
|
658 |
if (hotDeal) {
|
| 713 |
// use caching later.
|
- |
|
| 714 |
try {
|
659 |
try {
|
| 715 |
ItemAvailabilityCache iac = itemAvailabilityCacheRepository.selectByItemId(itemId);
|
660 |
int totalAvailability = ourItemAvailabilityMap.get(itemId);
|
| 716 |
totalAvailability = iac.getTotalAvailability();
|
661 |
if (totalAvailability <= 0) {
|
| - |
|
662 |
continue;
|
| - |
|
663 |
}
|
| 717 |
fdi.setAvailability(totalAvailability);
|
664 |
fdi.setAvailability(ourItemAvailabilityMap.get(itemId));
|
| 718 |
} catch (Exception e) {
|
665 |
} catch (Exception e) {
|
| 719 |
continue;
|
666 |
continue;
|
| 720 |
}
|
667 |
}
|
| 721 |
if (totalAvailability <= 0) {
|
668 |
} else if (fofoId == 0) {
|
| 722 |
continue;
|
- |
|
| 723 |
}
|
- |
|
| 724 |
} else {
|
- |
|
| 725 |
// For accessories item availability should at be ordered for Rs.1000
|
669 |
// For accessories item availability should at be ordered for Rs.1000
|
| 726 |
fdi.setAvailability(100);
|
670 |
fdi.setAvailability(100);
|
| - |
|
671 |
Item item = itemRepository.selectById(itemId);
|
| - |
|
672 |
// In case its tampered glass moq should be 5
|
| - |
|
673 |
if (item.getCategoryId() == 10020) {
|
| - |
|
674 |
fdi.setMinBuyQuantity(5);
|
| - |
|
675 |
} else {
|
| - |
|
676 |
fdi.setMinBuyQuantity(1);
|
| - |
|
677 |
}
|
| - |
|
678 |
} else {
|
| - |
|
679 |
int ourStockAvailability = ourItemAvailabilityMap.get(itemId) == null ? 0 : ourItemAvailabilityMap.get(itemId);
|
| - |
|
680 |
int partnerAvailability = partnerStockAvailabilityMap.get(itemId) == null ? 0 : partnerStockAvailabilityMap.get(itemId);
|
| - |
|
681 |
fdi.setAvailability(ourStockAvailability + partnerAvailability);
|
| 727 |
}
|
682 |
}
|
| 728 |
fdi.setQuantityStep(1);
|
683 |
fdi.setQuantityStep(1);
|
| 729 |
fdi.setMaxQuantity(Math.min(fdi.getAvailability(), 100));
|
684 |
fdi.setMaxQuantity(Math.min(fdi.getAvailability(), 100));
|
| 730 |
fofoAvailabilityInfoMap.put(itemId, fdi);
|
685 |
fofoAvailabilityInfoMap.put(itemId, fdi);
|
| 731 |
}
|
686 |
}
|