| Line 56... |
Line 56... |
| 56 |
import com.spice.profitmandi.dao.repository.dtr.Mongo;
|
56 |
import com.spice.profitmandi.dao.repository.dtr.Mongo;
|
| 57 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
57 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
| 58 |
import com.spice.profitmandi.dao.repository.inventory.ItemAvailabilityCacheRepository;
|
58 |
import com.spice.profitmandi.dao.repository.inventory.ItemAvailabilityCacheRepository;
|
| 59 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
59 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
| 60 |
import com.spice.profitmandi.service.inventory.ItemBucketService;
|
60 |
import com.spice.profitmandi.service.inventory.ItemBucketService;
|
| - |
|
61 |
import com.spice.profitmandi.service.inventory.ItemQuantityPojo;
|
| 61 |
import com.spice.profitmandi.service.pricing.PricingService;
|
62 |
import com.spice.profitmandi.service.pricing.PricingService;
|
| 62 |
import com.spice.profitmandi.web.res.AvailabilityInfo;
|
63 |
import com.spice.profitmandi.web.res.AvailabilityInfo;
|
| 63 |
import com.spice.profitmandi.web.res.DealBrands;
|
64 |
import com.spice.profitmandi.web.res.DealBrands;
|
| 64 |
import com.spice.profitmandi.web.res.DealObjectResponse;
|
65 |
import com.spice.profitmandi.web.res.DealObjectResponse;
|
| 65 |
import com.spice.profitmandi.web.res.DealsResponse;
|
66 |
import com.spice.profitmandi.web.res.DealsResponse;
|
| Line 92... |
Line 93... |
| 92 |
@Autowired
|
93 |
@Autowired
|
| 93 |
private CategoryRepository categoryRepository;
|
94 |
private CategoryRepository categoryRepository;
|
| 94 |
|
95 |
|
| 95 |
@Autowired
|
96 |
@Autowired
|
| 96 |
private Mongo mongoClient;
|
97 |
private Mongo mongoClient;
|
| 97 |
|
98 |
|
| 98 |
@Autowired
|
99 |
@Autowired
|
| 99 |
private ItemBucketService itemBucketService;
|
100 |
private ItemBucketService itemBucketService;
|
| 100 |
|
101 |
|
| 101 |
@Autowired
|
102 |
@Autowired
|
| 102 |
private UserAccountRepository userAccountRepository;
|
103 |
private UserAccountRepository userAccountRepository;
|
| Line 174... |
Line 175... |
| 174 |
}
|
175 |
}
|
| 175 |
return responseSender.ok(responseObject);
|
176 |
return responseSender.ok(responseObject);
|
| 176 |
}
|
177 |
}
|
| 177 |
|
178 |
|
| 178 |
@RequestMapping(value = "/fofo/buckets", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
179 |
@RequestMapping(value = "/fofo/buckets", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 179 |
public ResponseEntity<?> getBuckets(HttpServletRequest request)
|
180 |
public ResponseEntity<?> getBuckets(HttpServletRequest request) throws ProfitMandiBusinessException {
|
| 180 |
throws ProfitMandiBusinessException {
|
- |
|
| 181 |
logger.info("Request " + request.getParameterMap());
|
181 |
logger.info("Request " + request.getParameterMap());
|
| 182 |
return responseSender.ok(itemBucketService.getBuckets(Optional.of(true)));
|
182 |
return responseSender.ok(itemBucketService.getBuckets(Optional.of(true)));
|
| 183 |
}
|
183 |
}
|
| - |
|
184 |
|
| - |
|
185 |
@RequestMapping(value = "/fofo/bucket", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| - |
|
186 |
public ResponseEntity<?> getBucketDetails(HttpServletRequest request, @RequestParam int bucketId)
|
| - |
|
187 |
throws ProfitMandiBusinessException {
|
| - |
|
188 |
List<ItemQuantityPojo> iqPojo = itemBucketService.getBucketDetails(bucketId);
|
| - |
|
189 |
List<Integer> itemIds = iqPojo.stream().map(x -> x.getItemId()).collect(Collectors.toList());
|
| - |
|
190 |
// UserCart uc = userAccountRepository.getUserCart(userInfo.getUserId());
|
| - |
|
191 |
int userId = (int) request.getAttribute("userId");
|
| - |
|
192 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
| - |
|
193 |
|
| - |
|
194 |
RestClient rc = new RestClient();
|
| - |
|
195 |
Map<String, String> params = new HashMap<>();
|
| - |
|
196 |
List<String> mandatoryQ = new ArrayList<>();
|
| - |
|
197 |
mandatoryQ.add(String.format("+{!parent which=\"id:catalog*\"} itemId_i:(%s)", StringUtils.join(itemIds, " ")));
|
| - |
|
198 |
|
| - |
|
199 |
params.put("q", StringUtils.join(mandatoryQ, " "));
|
| - |
|
200 |
params.put("fl", "*, [child parentFilter=id:catalog*]");
|
| - |
|
201 |
|
| - |
|
202 |
params.put("wt", "json");
|
| - |
|
203 |
String response = null;
|
| - |
|
204 |
try {
|
| - |
|
205 |
response = rc.get(SchemeType.HTTP, "dtr", 8984, "solr/demo/select", params);
|
| - |
|
206 |
} catch (HttpHostConnectException e) {
|
| - |
|
207 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
| - |
|
208 |
}
|
| - |
|
209 |
JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
|
| - |
|
210 |
JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
|
| - |
|
211 |
List<FofoCatalogResponse> dealResponse = getCatalogResponse(docs, false);
|
| - |
|
212 |
dealResponse.
|
| - |
|
213 |
return responseSender.ok(dealResponse);
|
| 184 |
|
214 |
}
|
| - |
|
215 |
|
| 185 |
private String getCommaSeparateTags(int userId) {
|
216 |
private String getCommaSeparateTags(int userId) {
|
| 186 |
UserCart uc = userAccountRepository.getUserCart(userId);
|
217 |
UserCart uc = userAccountRepository.getUserCart(userId);
|
| 187 |
List<Integer> tagIds = pricingService.getTagsIdsByRetailerId(uc.getUserId());
|
218 |
List<Integer> tagIds = pricingService.getTagsIdsByRetailerId(uc.getUserId());
|
| 188 |
List<String> strTagIds = new ArrayList<>();
|
219 |
List<String> strTagIds = new ArrayList<>();
|
| 189 |
for (Integer tagId : tagIds) {
|
220 |
for (Integer tagId : tagIds) {
|
| Line 204... |
Line 235... |
| 204 |
@RequestParam(value = "q", required = false) String queryTerm,
|
235 |
@RequestParam(value = "q", required = false) String queryTerm,
|
| 205 |
@RequestParam(value = "hotDeal", required = false) boolean hotDeal) throws Throwable {
|
236 |
@RequestParam(value = "hotDeal", required = false) boolean hotDeal) throws Throwable {
|
| 206 |
List<FofoCatalogResponse> dealResponse = new ArrayList<>();
|
237 |
List<FofoCatalogResponse> dealResponse = new ArrayList<>();
|
| 207 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
238 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
| 208 |
if (roleManagerService.isPartner(userInfo.getRoleIds())) {
|
239 |
if (roleManagerService.isPartner(userInfo.getRoleIds())) {
|
| 209 |
//UserCart uc = userAccountRepository.getUserCart(userInfo.getUserId());
|
240 |
// UserCart uc = userAccountRepository.getUserCart(userInfo.getUserId());
|
| 210 |
List<Integer> tagIds = pricingService.getTagsIdsByRetailerId(userInfo.getRetailerId());
|
241 |
List<Integer> tagIds = pricingService.getTagsIdsByRetailerId(userInfo.getRetailerId());
|
| 211 |
RestClient rc = new RestClient();
|
242 |
RestClient rc = new RestClient();
|
| 212 |
Map<String, String> params = new HashMap<>();
|
243 |
Map<String, String> params = new HashMap<>();
|
| 213 |
List<String> mandatoryQ = new ArrayList<>();
|
244 |
List<String> mandatoryQ = new ArrayList<>();
|
| 214 |
if (queryTerm != null && !queryTerm.equals("null")) {
|
245 |
if (queryTerm != null && !queryTerm.equals("null")) {
|
| Line 417... |
Line 448... |
| 417 |
@RequestMapping(value = "/fofo/brands", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
448 |
@RequestMapping(value = "/fofo/brands", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 418 |
public ResponseEntity<?> getBrandsToDisplay(HttpServletRequest request,
|
449 |
public ResponseEntity<?> getBrandsToDisplay(HttpServletRequest request,
|
| 419 |
@RequestParam(required = false, defaultValue = "0") int categoryId) throws Exception {
|
450 |
@RequestParam(required = false, defaultValue = "0") int categoryId) throws Exception {
|
| 420 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
451 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
| 421 |
logger.info("userInfo [{}]", userInfo);
|
452 |
logger.info("userInfo [{}]", userInfo);
|
| 422 |
List<DBObject> brandsDisplay = mongoClient.getMongoBrands(userInfo.getRetailerId(), userInfo.getEmail(), categoryId);
|
453 |
List<DBObject> brandsDisplay = mongoClient.getMongoBrands(userInfo.getRetailerId(), userInfo.getEmail(),
|
| - |
|
454 |
categoryId);
|
| 423 |
return new ResponseEntity<>(brandsDisplay, HttpStatus.OK);
|
455 |
return new ResponseEntity<>(brandsDisplay, HttpStatus.OK);
|
| 424 |
}
|
456 |
}
|
| - |
|
457 |
|
| 425 |
@RequestMapping(value = "/fofo/accessory/all-categories", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
458 |
@RequestMapping(value = "/fofo/accessory/all-categories", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 426 |
public ResponseEntity<?> getSubCategoriesToDisplay(HttpServletRequest request) throws Exception {
|
459 |
public ResponseEntity<?> getSubCategoriesToDisplay(HttpServletRequest request) throws Exception {
|
| 427 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
460 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
| 428 |
logger.info("userInfo [{}]", userInfo);
|
461 |
logger.info("userInfo [{}]", userInfo);
|
| 429 |
List<DBObject> subCateogriesDisplay = this.getSubCategoriesToDisplay();
|
462 |
List<DBObject> subCateogriesDisplay = this.getSubCategoriesToDisplay();
|
| Line 605... |
Line 638... |
| 605 |
}
|
638 |
}
|
| 606 |
return dealResponse;
|
639 |
return dealResponse;
|
| 607 |
|
640 |
|
| 608 |
}
|
641 |
}
|
| 609 |
|
642 |
|
| - |
|
643 |
private List<FofoCatalogResponse> getCatalogSingleSkuResponse(JSONArray docs, boolean hotDeal)
|
| - |
|
644 |
throws ProfitMandiBusinessException {
|
| - |
|
645 |
Map<Integer, TagListing> itemTagListingMap = null;
|
| - |
|
646 |
List<FofoCatalogResponse> dealResponse = new ArrayList<>();
|
| - |
|
647 |
List<Integer> tagIds = Arrays.asList(4);
|
| - |
|
648 |
if (docs.length() > 0) {
|
| - |
|
649 |
HashSet<Integer> itemsSet = new HashSet<>();
|
| - |
|
650 |
for (int i = 0; i < docs.length(); i++) {
|
| - |
|
651 |
JSONObject doc = docs.getJSONObject(i);
|
| - |
|
652 |
for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
|
| - |
|
653 |
JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
|
| - |
|
654 |
int itemId = childItem.getInt("itemId_i");
|
| - |
|
655 |
itemsSet.add(itemId);
|
| - |
|
656 |
}
|
| - |
|
657 |
}
|
| - |
|
658 |
itemTagListingMap = tagListingRepository.selectByItemIdsAndTagIds(itemsSet, new HashSet<>(tagIds)).stream()
|
| - |
|
659 |
.collect(Collectors.toMap(x -> x.getItemId(), x -> x));
|
| - |
|
660 |
}
|
| - |
|
661 |
|
| - |
|
662 |
for (int i = 0; i < docs.length(); i++) {
|
| - |
|
663 |
Map<Integer, FofoAvailabilityInfo> fofoAvailabilityInfoMap = new HashMap<>();
|
| - |
|
664 |
JSONObject doc = docs.getJSONObject(i);
|
| - |
|
665 |
|
| - |
|
666 |
for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
|
| - |
|
667 |
JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
|
| - |
|
668 |
int itemId = childItem.getInt("itemId_i");
|
| - |
|
669 |
TagListing tl = itemTagListingMap.get(itemId);
|
| - |
|
670 |
if (hotDeal) {
|
| - |
|
671 |
if (!tl.isHotDeals()) {
|
| - |
|
672 |
continue;
|
| - |
|
673 |
}
|
| - |
|
674 |
}
|
| - |
|
675 |
float sellingPrice = (float) childItem.getDouble("sellingPrice_f");
|
| - |
|
676 |
if (fofoAvailabilityInfoMap.containsKey(itemId)) {
|
| - |
|
677 |
if (fofoAvailabilityInfoMap.get(itemId).getSellingPrice() > sellingPrice) {
|
| - |
|
678 |
fofoAvailabilityInfoMap.get(itemId).setSellingPrice(sellingPrice);
|
| - |
|
679 |
fofoAvailabilityInfoMap.get(itemId).setMop((float) childItem.getDouble("mop_f"));
|
| - |
|
680 |
}
|
| - |
|
681 |
} else {
|
| - |
|
682 |
FofoAvailabilityInfo fdi = new FofoAvailabilityInfo();
|
| - |
|
683 |
fdi.setSellingPrice((float) childItem.getDouble("sellingPrice_f"));
|
| - |
|
684 |
fdi.setMop((float) childItem.getDouble("mop_f"));
|
| - |
|
685 |
fdi.setColor(childItem.has("color_s") ? childItem.getString("color_s") : "");
|
| - |
|
686 |
fdi.setTagId(childItem.getInt("tagId_i"));
|
| - |
|
687 |
fdi.setItem_id(itemId);
|
| - |
|
688 |
Item item = itemRepository.selectById(itemId);
|
| - |
|
689 |
// In case its tampered glass moq should be 5
|
| - |
|
690 |
if (item.getCategoryId() == 10020) {
|
| - |
|
691 |
fdi.setMinBuyQuantity(10);
|
| - |
|
692 |
} else {
|
| - |
|
693 |
fdi.setMinBuyQuantity(1);
|
| - |
|
694 |
}
|
| - |
|
695 |
if (hotDeal || !tl.isActive()) {
|
| - |
|
696 |
|
| - |
|
697 |
int totalAvailability = 0; // Using item availability
|
| - |
|
698 |
// cache for now but can be
|
| - |
|
699 |
// changed to
|
| - |
|
700 |
// use caching later.
|
| - |
|
701 |
try {
|
| - |
|
702 |
ItemAvailabilityCache iac = itemAvailabilityCacheRepository.selectByItemId(itemId);
|
| - |
|
703 |
totalAvailability = iac.getTotalAvailability();
|
| - |
|
704 |
fdi.setAvailability(totalAvailability);
|
| - |
|
705 |
} catch (Exception e) {
|
| - |
|
706 |
continue;
|
| - |
|
707 |
}
|
| - |
|
708 |
if (totalAvailability <= 0) {
|
| - |
|
709 |
continue;
|
| - |
|
710 |
}
|
| - |
|
711 |
} else {
|
| - |
|
712 |
// For accessories item availability should at be ordered for Rs.1000
|
| - |
|
713 |
fdi.setAvailability(100);
|
| - |
|
714 |
}
|
| - |
|
715 |
fdi.setQuantityStep(1);
|
| - |
|
716 |
fdi.setMaxQuantity(Math.min(fdi.getAvailability(), 100));
|
| - |
|
717 |
fofoAvailabilityInfoMap.put(itemId, fdi);
|
| - |
|
718 |
}
|
| - |
|
719 |
}
|
| - |
|
720 |
if (fofoAvailabilityInfoMap.values().size() > 0) {
|
| - |
|
721 |
for(FofoAvailabilityInfo fofoAvailabilityInfo : fofoAvailabilityInfoMap.values()) {
|
| - |
|
722 |
FofoCatalogResponse ffdr = new FofoCatalogResponse();
|
| - |
|
723 |
ffdr.setCatalogId(doc.getInt("catalogId_i"));
|
| - |
|
724 |
ffdr.setImageUrl(doc.getString("imageUrl_s"));
|
| - |
|
725 |
ffdr.setTitle(doc.getString("title_s"));
|
| - |
|
726 |
try {
|
| - |
|
727 |
ffdr.setFeature(doc.getString("feature_s"));
|
| - |
|
728 |
} catch (Exception e) {
|
| - |
|
729 |
ffdr.setFeature(null);
|
| - |
|
730 |
logger.info("Could not find Feature_s for {}", ffdr.getCatalogId());
|
| - |
|
731 |
}
|
| - |
|
732 |
ffdr.setBrand(doc.getJSONArray("brand_ss").getString(0));
|
| - |
|
733 |
ffdr.setItems(Arrays.asList(fofoAvailabilityInfo));
|
| - |
|
734 |
dealResponse.add(ffdr);
|
| - |
|
735 |
}
|
| - |
|
736 |
}
|
| - |
|
737 |
}
|
| - |
|
738 |
return dealResponse;
|
| - |
|
739 |
|
| - |
|
740 |
}
|
| - |
|
741 |
|
| 610 |
}
|
742 |
}
|