Subversion Repositories SmartDukaan

Rev

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

Rev 25879 Rev 25880
Line 55... Line 55...
55
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
55
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
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.AvailabilityInfo;
-
 
61
import com.spice.profitmandi.service.inventory.FofoAvailabilityInfo;
-
 
62
import com.spice.profitmandi.service.inventory.FofoCatalogResponse;
60
import com.spice.profitmandi.service.inventory.ItemBucketService;
63
import com.spice.profitmandi.service.inventory.ItemBucketService;
61
import com.spice.profitmandi.service.inventory.ItemQuantityPojo;
64
import com.spice.profitmandi.service.inventory.ItemQuantityPojo;
62
import com.spice.profitmandi.service.pricing.PricingService;
65
import com.spice.profitmandi.service.pricing.PricingService;
63
import com.spice.profitmandi.web.res.AvailabilityInfo;
-
 
64
import com.spice.profitmandi.web.res.DealBrands;
66
import com.spice.profitmandi.web.res.DealBrands;
65
import com.spice.profitmandi.web.res.DealObjectResponse;
67
import com.spice.profitmandi.web.res.DealObjectResponse;
66
import com.spice.profitmandi.web.res.DealsResponse;
68
import com.spice.profitmandi.web.res.DealsResponse;
67
import com.spice.profitmandi.web.res.FofoAvailabilityInfo;
-
 
68
import com.spice.profitmandi.web.res.FofoCatalogResponse;
-
 
69
 
69
 
70
import io.swagger.annotations.ApiImplicitParam;
70
import io.swagger.annotations.ApiImplicitParam;
71
import io.swagger.annotations.ApiImplicitParams;
71
import io.swagger.annotations.ApiImplicitParams;
72
import io.swagger.annotations.ApiOperation;
72
import io.swagger.annotations.ApiOperation;
73
 
73
 
Line 181... Line 181...
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
 
184
 
185
	@RequestMapping(value = "/fofo/bucket", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
185
	@RequestMapping(value = "/fofo/bucket", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
186
	public ResponseEntity<?> getBucketDetails(HttpServletRequest request, @RequestParam int bucketId)
186
	public ResponseEntity<?> getBucketDetails(HttpServletRequest request, @RequestParam int id)
187
			throws ProfitMandiBusinessException {
187
			throws ProfitMandiBusinessException {
188
		List<ItemQuantityPojo> iqPojo = itemBucketService.getBucketDetails(bucketId);
188
		List<ItemQuantityPojo> iqPojo = itemBucketService.getBucketDetails(id);
189
		List<Integer> itemIds = iqPojo.stream().map(x -> x.getItemId()).collect(Collectors.toList());
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
 
190
 
194
		RestClient rc = new RestClient();
191
		RestClient rc = new RestClient();
195
		Map<String, String> params = new HashMap<>();
192
		Map<String, String> params = new HashMap<>();
196
		List<String> mandatoryQ = new ArrayList<>();
193
		List<String> mandatoryQ = new ArrayList<>();
197
		mandatoryQ.add(String.format("+{!parent which=\"id:catalog*\"} itemId_i:(%s)", StringUtils.join(itemIds, " ")));
194
		mandatoryQ.add(String.format("+{!parent which=\"id:catalog*\"} itemId_i:(%s)", StringUtils.join(itemIds, " ")));
Line 206... Line 203...
206
		} catch (HttpHostConnectException e) {
203
		} catch (HttpHostConnectException e) {
207
			throw new ProfitMandiBusinessException("", "", "Could not connect to host");
204
			throw new ProfitMandiBusinessException("", "", "Could not connect to host");
208
		}
205
		}
209
		JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
206
		JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
210
		JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
207
		JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
211
		List<FofoCatalogResponse> dealResponse = getCatalogResponse(docs, false);
208
		List<FofoCatalogResponse> dealResponse = getCatalogSingleSkuResponse(docs, false);
212
		dealResponse.
-
 
213
		return responseSender.ok(dealResponse);
209
		return responseSender.ok(dealResponse);
214
	}
210
	}
215
 
211
 
216
	private String getCommaSeparateTags(int userId) {
212
	private String getCommaSeparateTags(int userId) {
217
		UserCart uc = userAccountRepository.getUserCart(userId);
213
		UserCart uc = userAccountRepository.getUserCart(userId);
Line 656... Line 652...
656
				}
652
				}
657
			}
653
			}
658
			itemTagListingMap = tagListingRepository.selectByItemIdsAndTagIds(itemsSet, new HashSet<>(tagIds)).stream()
654
			itemTagListingMap = tagListingRepository.selectByItemIdsAndTagIds(itemsSet, new HashSet<>(tagIds)).stream()
659
					.collect(Collectors.toMap(x -> x.getItemId(), x -> x));
655
					.collect(Collectors.toMap(x -> x.getItemId(), x -> x));
660
		}
656
		}
661
		
657
 
662
		for (int i = 0; i < docs.length(); i++) {
658
		for (int i = 0; i < docs.length(); i++) {
663
			Map<Integer, FofoAvailabilityInfo> fofoAvailabilityInfoMap = new HashMap<>();
659
			Map<Integer, FofoAvailabilityInfo> fofoAvailabilityInfoMap = new HashMap<>();
664
			JSONObject doc = docs.getJSONObject(i);
660
			JSONObject doc = docs.getJSONObject(i);
665
			
661
 
666
			for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
662
			for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
667
				JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
663
				JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
668
				int itemId = childItem.getInt("itemId_i");
664
				int itemId = childItem.getInt("itemId_i");
669
				TagListing tl = itemTagListingMap.get(itemId);
665
				TagListing tl = itemTagListingMap.get(itemId);
670
				if (hotDeal) {
666
				if (hotDeal) {
Line 691... Line 687...
691
						fdi.setMinBuyQuantity(10);
687
						fdi.setMinBuyQuantity(10);
692
					} else {
688
					} else {
693
						fdi.setMinBuyQuantity(1);
689
						fdi.setMinBuyQuantity(1);
694
					}
690
					}
695
					if (hotDeal || !tl.isActive()) {
691
					if (hotDeal || !tl.isActive()) {
696
						
692
 
697
						int totalAvailability = 0; // Using item availability
693
						int totalAvailability = 0; // Using item availability
698
						// cache for now but can be
694
						// cache for now but can be
699
						// changed to
695
						// changed to
700
						// use caching later.
696
						// use caching later.
701
						try {
697
						try {
Line 716... Line 712...
716
					fdi.setMaxQuantity(Math.min(fdi.getAvailability(), 100));
712
					fdi.setMaxQuantity(Math.min(fdi.getAvailability(), 100));
717
					fofoAvailabilityInfoMap.put(itemId, fdi);
713
					fofoAvailabilityInfoMap.put(itemId, fdi);
718
				}
714
				}
719
			}
715
			}
720
			if (fofoAvailabilityInfoMap.values().size() > 0) {
716
			if (fofoAvailabilityInfoMap.values().size() > 0) {
721
				for(FofoAvailabilityInfo fofoAvailabilityInfo : fofoAvailabilityInfoMap.values()) {
717
				for (FofoAvailabilityInfo fofoAvailabilityInfo : fofoAvailabilityInfoMap.values()) {
722
					FofoCatalogResponse ffdr = new FofoCatalogResponse();
718
					FofoCatalogResponse ffdr = new FofoCatalogResponse();
723
					ffdr.setCatalogId(doc.getInt("catalogId_i"));
719
					ffdr.setCatalogId(doc.getInt("catalogId_i"));
724
					ffdr.setImageUrl(doc.getString("imageUrl_s"));
720
					ffdr.setImageUrl(doc.getString("imageUrl_s"));
725
					ffdr.setTitle(doc.getString("title_s"));
721
					ffdr.setTitle(doc.getString("title_s"));
726
					try {
722
					try {
Line 734... Line 730...
734
					dealResponse.add(ffdr);
730
					dealResponse.add(ffdr);
735
				}
731
				}
736
			}
732
			}
737
		}
733
		}
738
		return dealResponse;
734
		return dealResponse;
739
		
735
 
740
	}
736
	}
741
 
737
 
742
}
738
}