Subversion Repositories SmartDukaan

Rev

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

Rev 26789 Rev 26846
Line 47... Line 47...
47
import com.spice.profitmandi.common.web.client.RestClient;
47
import com.spice.profitmandi.common.web.client.RestClient;
48
import com.spice.profitmandi.common.web.util.ResponseSender;
48
import com.spice.profitmandi.common.web.util.ResponseSender;
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.SuggestedPoDetail;
52
import com.spice.profitmandi.dao.entity.inventory.ItemAvailabilityCache;
53
import com.spice.profitmandi.dao.entity.inventory.ItemAvailabilityCache;
53
import com.spice.profitmandi.dao.model.UserCart;
54
import com.spice.profitmandi.dao.model.UserCart;
54
import com.spice.profitmandi.dao.repository.catalog.CategoryRepository;
55
import com.spice.profitmandi.dao.repository.catalog.CategoryRepository;
55
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
56
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
56
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
57
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
57
import com.spice.profitmandi.dao.repository.dtr.Mongo;
58
import com.spice.profitmandi.dao.repository.dtr.Mongo;
58
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.SuggestedPoDetailRepository;
59
import com.spice.profitmandi.dao.repository.inventory.ItemAvailabilityCacheRepository;
61
import com.spice.profitmandi.dao.repository.inventory.ItemAvailabilityCacheRepository;
60
import com.spice.profitmandi.service.authentication.RoleManager;
62
import com.spice.profitmandi.service.authentication.RoleManager;
61
import com.spice.profitmandi.service.inventory.AvailabilityInfo;
63
import com.spice.profitmandi.service.inventory.AvailabilityInfo;
62
import com.spice.profitmandi.service.inventory.Bucket;
64
import com.spice.profitmandi.service.inventory.Bucket;
63
import com.spice.profitmandi.service.inventory.FofoAvailabilityInfo;
65
import com.spice.profitmandi.service.inventory.FofoAvailabilityInfo;
Line 124... Line 126...
124
	private ItemAvailabilityCacheRepository itemAvailabilityCacheRepository;
126
	private ItemAvailabilityCacheRepository itemAvailabilityCacheRepository;
125
 
127
 
126
	@Autowired
128
	@Autowired
127
	private RoleManager roleManagerService;
129
	private RoleManager roleManagerService;
128
 
130
 
-
 
131
	@Autowired
129
	List<String> filterableParams = Arrays.asList("brand");
132
	private SuggestedPoDetailRepository monthlyPoDetailRepository;
130
 
133
 
-
 
134
	List<String> filterableParams = Arrays.asList("brand");
131
 
135
 
132
	@RequestMapping(value = "/fofo/buckets", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
136
	@RequestMapping(value = "/fofo/buckets", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
133
	public ResponseEntity<?> getBuckets(HttpServletRequest request) throws ProfitMandiBusinessException {
137
	public ResponseEntity<?> getBuckets(HttpServletRequest request) throws ProfitMandiBusinessException {
134
		logger.info("Request " + request.getParameterMap());
138
		logger.info("Request " + request.getParameterMap());
135
		return responseSender.ok(itemBucketService.getBuckets(Optional.of(true)));
139
		return responseSender.ok(itemBucketService.getBuckets(Optional.of(true)));
Line 168... Line 172...
168
				.collect(Collectors.toList()).get(0);
172
				.collect(Collectors.toList()).get(0);
169
		bucket.setFofoCatalogResponses(dealResponse);
173
		bucket.setFofoCatalogResponses(dealResponse);
170
		return responseSender.ok(bucket);
174
		return responseSender.ok(bucket);
171
	}
175
	}
172
 
176
 
-
 
177
	@RequestMapping(value = "/fofo/suggestedPo", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
-
 
178
	public ResponseEntity<?> getSuggestedPo(HttpServletRequest request, @RequestParam int id)
-
 
179
			throws ProfitMandiBusinessException {
-
 
180
 
-
 
181
		List<SuggestedPoDetail> mpd = monthlyPoDetailRepository.selectByPoId(id);
-
 
182
		Map<Integer, Integer> itemIdsQtyMap = mpd.stream()
-
 
183
				.collect(Collectors.toMap(x -> x.getItemId(), x -> x.getQuantity()));
-
 
184
 
-
 
185
		Set<Integer> catalogIds = itemRepository.selectByIds(itemIdsQtyMap.keySet()).stream()
-
 
186
				.map(x -> x.getCatalogItemId()).collect(Collectors.toSet());
-
 
187
		RestClient rc = new RestClient();
-
 
188
		Map<String, String> params = new HashMap<>();
-
 
189
		List<String> mandatoryQ = new ArrayList<>();
-
 
190
		mandatoryQ.add(
-
 
191
				String.format("+catalogId_i:(%s) +{!parent which=\"id:catalog*\"}", StringUtils.join(catalogIds, " ")));
-
 
192
		params.put("start", "0");
-
 
193
		params.put("rows", "100");
-
 
194
		params.put("q", StringUtils.join(mandatoryQ, " "));
-
 
195
		params.put("fl", "*, [child parentFilter=id:catalog*]");
-
 
196
 
-
 
197
		params.put("wt", "json");
-
 
198
		String response = null;
-
 
199
		try {
-
 
200
			response = rc.get(SchemeType.HTTP, "50.116.10.120", 8984, "solr/demo/select", params);
-
 
201
		} catch (HttpHostConnectException e) {
-
 
202
			throw new ProfitMandiBusinessException("", "", "Could not connect to host");
-
 
203
		}
-
 
204
		JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
-
 
205
		JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
-
 
206
		List<FofoCatalogResponse> dealResponse = getCatalogSingleSkuResponse(docs, itemIdsQtyMap, false);
-
 
207
 
-
 
208
		return responseSender.ok(dealResponse);
-
 
209
	}
-
 
210
 
173
	private String getCommaSeparateTags(int userId) {
211
	private String getCommaSeparateTags(int userId) {
174
		UserCart uc = userAccountRepository.getUserCart(userId);
212
		UserCart uc = userAccountRepository.getUserCart(userId);
175
		List<Integer> tagIds = pricingService.getTagsIdsByRetailerId(uc.getUserId());
213
		List<Integer> tagIds = pricingService.getTagsIdsByRetailerId(uc.getUserId());
176
		List<String> strTagIds = new ArrayList<>();
214
		List<String> strTagIds = new ArrayList<>();
177
		for (Integer tagId : tagIds) {
215
		for (Integer tagId : tagIds) {
Line 217... Line 255...
217
						String.format("+(categoryId_i:%s) +(brand_ss:%s) +{!parent which=\"brand_ss:%s\"} tagId_i:(%s)",
255
						String.format("+(categoryId_i:%s) +(brand_ss:%s) +{!parent which=\"brand_ss:%s\"} tagId_i:(%s)",
218
								categoryId, brand, brand, StringUtils.join(tagIds, " ")));
256
								categoryId, brand, brand, StringUtils.join(tagIds, " ")));
219
 
257
 
220
			} else {
258
			} else {
221
				mandatoryQ
259
				mandatoryQ
222
				.add(String.format("+(subCategoryId_i:%s) +{!parent which=\"subCategoryId_i:%s\"} tagId_i:(%s)",
260
						.add(String.format("+(subCategoryId_i:%s) +{!parent which=\"subCategoryId_i:%s\"} tagId_i:(%s)",
223
						categoryId, categoryId, StringUtils.join(tagIds, " ")));
261
								categoryId, categoryId, StringUtils.join(tagIds, " ")));
224
			}
262
			}
225
			params.put("q", StringUtils.join(mandatoryQ, " "));
263
			params.put("q", StringUtils.join(mandatoryQ, " "));
226
			params.put("fl", "*, [child parentFilter=id:catalog*]");
264
			params.put("fl", "*, [child parentFilter=id:catalog*]");
227
			if (queryTerm == null) {
265
			if (queryTerm == null) {
228
				params.put("sort", "create_s desc");
266
				params.put("sort", "create_s desc");
Line 265... Line 303...
265
			@RequestParam(value = " ", required = false, defaultValue = "true") boolean partnerStockOnly)
303
			@RequestParam(value = " ", required = false, defaultValue = "true") boolean partnerStockOnly)
266
			throws Throwable {
304
			throws Throwable {
267
		List<FofoCatalogResponse> dealResponse = new ArrayList<>();
305
		List<FofoCatalogResponse> dealResponse = new ArrayList<>();
268
		UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
306
		UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
269
		UserCart uc = userAccountRepository.getUserCart(userInfo.getUserId());
307
		UserCart uc = userAccountRepository.getUserCart(userInfo.getUserId());
270
		
308
 
271
		logger.info("Retiler Id ==> {}", uc.getUserId());
309
		logger.info("Retiler Id ==> {}", uc.getUserId());
272
		if (roleManagerService.isPartner(userInfo.getRoleIds())) {
310
		if (roleManagerService.isPartner(userInfo.getRoleIds())) {
273
			if(partnerStockOnly) {
311
			if (partnerStockOnly) {
274
				
312
 
275
			}
313
			}
276
			List<Integer> tagIds = pricingService.getTagsIdsByRetailerId(userInfo.getRetailerId());
314
			List<Integer> tagIds = pricingService.getTagsIdsByRetailerId(userInfo.getRetailerId());
277
			RestClient rc = new RestClient();
315
			RestClient rc = new RestClient();
278
			Map<String, String> params = new HashMap<>();
316
			Map<String, String> params = new HashMap<>();
279
			List<String> mandatoryQ = new ArrayList<>();
317
			List<String> mandatoryQ = new ArrayList<>();
Line 635... Line 673...
635
							fofoAvailabilityInfoMap.get(itemId).setMop((float) childItem.getDouble("mop_f"));
673
							fofoAvailabilityInfoMap.get(itemId).setMop((float) childItem.getDouble("mop_f"));
636
						}
674
						}
637
					} else {
675
					} else {
638
						FofoAvailabilityInfo fdi = new FofoAvailabilityInfo();
676
						FofoAvailabilityInfo fdi = new FofoAvailabilityInfo();
639
						fdi.setSellingPrice((float) childItem.getDouble("sellingPrice_f"));
677
						fdi.setSellingPrice((float) childItem.getDouble("sellingPrice_f"));
640
						fdi.setMrp((double)tl.getMrp());
678
						fdi.setMrp((double) tl.getMrp());
641
						fdi.setMop((float) childItem.getDouble("mop_f"));
679
						fdi.setMop((float) childItem.getDouble("mop_f"));
642
						fdi.setColor(childItem.has("color_s") ? childItem.getString("color_s") : "");
680
						fdi.setColor(childItem.has("color_s") ? childItem.getString("color_s") : "");
643
						fdi.setTagId(childItem.getInt("tagId_i"));
681
						fdi.setTagId(childItem.getInt("tagId_i"));
644
						fdi.setItem_id(itemId);
682
						fdi.setItem_id(itemId);
645
						Float cashBack = schemeService.getItemSchemeCashBack().get(itemId);
683
						Float cashBack = schemeService.getItemSchemeCashBack().get(itemId);
646
						cashBack = cashBack==null? 0 : cashBack;
684
						cashBack = cashBack == null ? 0 : cashBack;
647
						fdi.setCashback(cashBack);
685
						fdi.setCashback(cashBack);
648
						Item item = itemRepository.selectById(itemId);
686
						Item item = itemRepository.selectById(itemId);
649
						// In case its tampered glass moq should be 5
687
						// In case its tampered glass moq should be 5
650
						if (item.getCategoryId() == 10020) {
688
						if (item.getCategoryId() == 10020) {
651
							fdi.setMinBuyQuantity(10);
689
							fdi.setMinBuyQuantity(10);