Subversion Repositories SmartDukaan

Rev

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

Rev 27030 Rev 27045
Line 51... Line 51...
51
import com.spice.profitmandi.common.enumuration.SchemeType;
51
import com.spice.profitmandi.common.enumuration.SchemeType;
52
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
52
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
53
import com.spice.profitmandi.common.model.CreatePendingOrderItem;
53
import com.spice.profitmandi.common.model.CreatePendingOrderItem;
54
import com.spice.profitmandi.common.model.CreatePendingOrderRequest;
54
import com.spice.profitmandi.common.model.CreatePendingOrderRequest;
55
import com.spice.profitmandi.common.model.CustomRetailer;
55
import com.spice.profitmandi.common.model.CustomRetailer;
56
import com.spice.profitmandi.common.model.CustomerOrderDetail;
-
 
57
import com.spice.profitmandi.common.model.ProfitMandiConstants;
56
import com.spice.profitmandi.common.model.ProfitMandiConstants;
58
import com.spice.profitmandi.common.model.UserInfo;
57
import com.spice.profitmandi.common.model.UserInfo;
59
import com.spice.profitmandi.common.solr.SolrService;
58
import com.spice.profitmandi.common.solr.SolrService;
60
import com.spice.profitmandi.common.web.client.RestClient;
59
import com.spice.profitmandi.common.web.client.RestClient;
61
import com.spice.profitmandi.common.web.util.ResponseSender;
60
import com.spice.profitmandi.common.web.util.ResponseSender;
Line 66... Line 65...
66
import com.spice.profitmandi.dao.entity.fofo.CustomerAddress;
65
import com.spice.profitmandi.dao.entity.fofo.CustomerAddress;
67
import com.spice.profitmandi.dao.entity.fofo.PendingOrder;
66
import com.spice.profitmandi.dao.entity.fofo.PendingOrder;
68
import com.spice.profitmandi.dao.entity.fofo.PendingOrderItem;
67
import com.spice.profitmandi.dao.entity.fofo.PendingOrderItem;
69
import com.spice.profitmandi.dao.entity.fofo.PincodePartner;
68
import com.spice.profitmandi.dao.entity.fofo.PincodePartner;
70
import com.spice.profitmandi.dao.enumuration.dtr.OtpType;
69
import com.spice.profitmandi.dao.enumuration.dtr.OtpType;
-
 
70
import com.spice.profitmandi.dao.enumuration.transaction.OrderStatus;
71
import com.spice.profitmandi.dao.model.AddCartRequest;
71
import com.spice.profitmandi.dao.model.AddCartRequest;
72
import com.spice.profitmandi.dao.model.CartItem;
72
import com.spice.profitmandi.dao.model.CartItem;
73
import com.spice.profitmandi.dao.model.CartItemResponseModel;
73
import com.spice.profitmandi.dao.model.CartItemResponseModel;
74
import com.spice.profitmandi.dao.model.CartResponse;
74
import com.spice.profitmandi.dao.model.CartResponse;
-
 
75
import com.spice.profitmandi.dao.model.CustomerOrderDetail;
75
import com.spice.profitmandi.dao.model.UserCart;
76
import com.spice.profitmandi.dao.model.UserCart;
76
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
77
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
77
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
78
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
78
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
79
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
79
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
80
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
Line 121... Line 122...
121
	@Autowired
122
	@Autowired
122
	CustomerAddressRepository customerAddressRepository;
123
	CustomerAddressRepository customerAddressRepository;
123
 
124
 
124
	@Autowired
125
	@Autowired
125
	SolrService solrService;
126
	SolrService solrService;
126
	
127
 
127
	@Autowired
128
	@Autowired
128
	InventoryService inventoryService;
129
	InventoryService inventoryService;
129
	
130
 
130
	@Autowired
131
	@Autowired
131
	UserAccountRepository userAccountRepository;
132
	UserAccountRepository userAccountRepository;
132
 
133
 
133
	@Value("${python.api.host}")
134
	@Value("${python.api.host}")
134
	private String host;
135
	private String host;
Line 206... Line 207...
206
	@Autowired
207
	@Autowired
207
	JavaMailSender mailSender;
208
	JavaMailSender mailSender;
208
 
209
 
209
	List<String> filterableParams = Arrays.asList("brand");
210
	List<String> filterableParams = Arrays.asList("brand");
210
 
211
 
-
 
212
	/*
211
	/*@ApiImplicitParams({
213
	 * @ApiImplicitParams({
-
 
214
	 * 
212
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
215
	 * @ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true,
-
 
216
	 * dataType = "string", paramType = "header") })
-
 
217
	 * 
213
	@RequestMapping(value = "/store/fofo", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
218
	 * @RequestMapping(value = "/store/fofo", method = RequestMethod.GET, produces =
-
 
219
	 * MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<?>
214
	public ResponseEntity<?> getFofo(HttpServletRequest request,
220
	 * getFofo(HttpServletRequest request,
-
 
221
	 * 
215
			@RequestParam(value = "categoryId", required = false, defaultValue = "(3 OR 6)") String categoryId,
222
	 * @RequestParam(value = "categoryId", required = false, defaultValue =
-
 
223
	 * "(3 OR 6)") String categoryId,
-
 
224
	 * 
216
			@RequestParam(value = "offset") String offset, @RequestParam(value = "limit") String limit,
225
	 * @RequestParam(value = "offset") String offset, @RequestParam(value = "limit")
-
 
226
	 * String limit,
-
 
227
	 * 
217
			@RequestParam(value = "sort", required = false) String sort,
228
	 * @RequestParam(value = "sort", required = false) String sort,
-
 
229
	 * 
218
			@RequestParam(value = "brand", required = false) String brand,
230
	 * @RequestParam(value = "brand", required = false) String brand,
-
 
231
	 * 
219
			@RequestParam(value = "subCategoryId", required = false) int subCategoryId,
232
	 * @RequestParam(value = "subCategoryId", required = false) int subCategoryId,
-
 
233
	 * 
220
			@RequestParam(value = "q", required = false) String queryTerm,
234
	 * @RequestParam(value = "q", required = false) String queryTerm,
-
 
235
	 * 
221
			@RequestParam(value = "hotDeal", required = false) boolean hotDeal) throws Throwable {
236
	 * @RequestParam(value = "hotDeal", required = false) boolean hotDeal) throws
222
		List<FofoCatalogResponse> dealResponse = new ArrayList<>();
237
	 * Throwable { List<FofoCatalogResponse> dealResponse = new ArrayList<>();
223
		UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
238
	 * UserInfo userInfo = (UserInfo) request.getAttribute("userInfo"); if
224
		if (roleManagerService.isPartner(userInfo.getRoleIds())) {
239
	 * (roleManagerService.isPartner(userInfo.getRoleIds())) { // UserCart uc =
225
			// UserCart uc = userAccountRepository.getUserCart(userInfo.getUserId());
240
	 * userAccountRepository.getUserCart(userInfo.getUserId()); RestClient rc = new
226
			RestClient rc = new RestClient();
-
 
227
			Map<String, String> params = new HashMap<>();
241
	 * RestClient(); Map<String, String> params = new HashMap<>(); List<String>
228
			List<String> mandatoryQ = new ArrayList<>();
242
	 * mandatoryQ = new ArrayList<>(); if (queryTerm != null &&
229
			if (queryTerm != null && !queryTerm.equals("null")) {
-
 
230
				mandatoryQ.add(String.format("+(%s)", queryTerm));
243
	 * !queryTerm.equals("null")) { mandatoryQ.add(String.format("+(%s)",
231
			} else {
-
 
232
				queryTerm = null;
-
 
233
			}
-
 
234
			if (subCategoryId != 0) {
244
	 * queryTerm)); } else { queryTerm = null; } if (subCategoryId != 0) {
235
				mandatoryQ
245
	 * mandatoryQ .add(String.
236
						.add(String.format("+(subCategoryId_i:%s) +{!parent which=\"subCategoryId_i:%s\"} tagId_i:(%s)",
246
	 * format("+(subCategoryId_i:%s) +{!parent which=\"subCategoryId_i:%s\"} tagId_i:(%s)"
237
								subCategoryId, subCategoryId, StringUtils.join(TAG_IDS, " ")));
247
	 * , subCategoryId, subCategoryId, StringUtils.join(TAG_IDS, " "))); } else if
238
			} else if (hotDeal) {
248
	 * (hotDeal) { mandatoryQ.add(String.
239
				mandatoryQ.add(String.format("+{!parent which=\"hot_deals_b=true\"} tagId_i:(%s)",
249
	 * format("+{!parent which=\"hot_deals_b=true\"} tagId_i:(%s)",
240
						StringUtils.join(TAG_IDS, " ")));
250
	 * StringUtils.join(TAG_IDS, " ")));
241
 
251
	 * 
242
			} else if (StringUtils.isNotBlank(brand)) {
252
	 * } else if (StringUtils.isNotBlank(brand)) { mandatoryQ.add( String.
243
				mandatoryQ.add(
-
 
244
						String.format("+(categoryId_i:%s) +(brand_ss:%s) +{!parent which=\"brand_ss:%s\"} tagId_i:(%s)",
253
	 * format("+(categoryId_i:%s) +(brand_ss:%s) +{!parent which=\"brand_ss:%s\"} tagId_i:(%s)"
245
								categoryId, brand, brand, StringUtils.join(TAG_IDS, " ")));
254
	 * , categoryId, brand, brand, StringUtils.join(TAG_IDS, " ")));
246
 
-
 
247
			} else {
255
	 * 
248
				mandatoryQ.add(
256
	 * } else { mandatoryQ.add(
249
						String.format("+{!parent which=\"id:catalog*\"} tagId_i:(%s)", StringUtils.join(TAG_IDS, " ")));
257
	 * String.format("+{!parent which=\"id:catalog*\"} tagId_i:(%s)",
250
			}
-
 
251
			params.put("q", StringUtils.join(mandatoryQ, " "));
258
	 * StringUtils.join(TAG_IDS, " "))); } params.put("q",
252
			params.put("fl", "*, [child parentFilter=id:catalog*]");
259
	 * StringUtils.join(mandatoryQ, " ")); params.put("fl",
253
			if (queryTerm == null) {
260
	 * "*, [child parentFilter=id:catalog*]"); if (queryTerm == null) {
254
				params.put("sort", "create_s desc");
261
	 * params.put("sort", "create_s desc"); } params.put("start",
255
			}
-
 
256
			params.put("start", String.valueOf(offset));
-
 
257
			params.put("rows", String.valueOf(limit));
262
	 * String.valueOf(offset)); params.put("rows", String.valueOf(limit));
258
			params.put("wt", "json");
263
	 * params.put("wt", "json"); String response = null; try { response =
259
			String response = null;
-
 
260
			try {
-
 
261
				response = rc.get(SchemeType.HTTP, "50.116.10.120", 8984, "solr/demo/select", params);
264
	 * rc.get(SchemeType.HTTP, "50.116.10.120", 8984, "solr/demo/select", params); }
262
			} catch (HttpHostConnectException e) {
265
	 * catch (HttpHostConnectException e) { throw new
263
				throw new ProfitMandiBusinessException("", "", "Could not connect to host");
266
	 * ProfitMandiBusinessException("", "", "Could not connect to host"); }
264
			}
-
 
-
 
267
	 * JSONObject solrResponseJSONObj = new
265
			JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
268
	 * JSONObject(response).getJSONObject("response"); JSONArray docs =
266
			JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
269
	 * solrResponseJSONObj.getJSONArray("docs"); dealResponse =
267
			dealResponse = getCatalogResponse(docs, false, userInfo.getRetailerId());
270
	 * getCatalogResponse(docs, false, userInfo.getRetailerId());
268
			
271
	 * 
269
			 * if (Mongo.PARTNER_BLoCKED_BRANDS.containsKey(userInfo.getEmail())) {
272
	 * if (Mongo.PARTNER_BLoCKED_BRANDS.containsKey(userInfo.getEmail())) {
270
			 * dealResponse.stream() .filter(x ->
273
	 * dealResponse.stream() .filter(x ->
271
			 * Mongo.PARTNER_BLoCKED_BRANDS.get(userInfo.getEmail()).contains(x.getBrand()))
274
	 * Mongo.PARTNER_BLoCKED_BRANDS.get(userInfo.getEmail()).contains(x.getBrand()))
272
			 * ; }
275
	 * ; }
273
			 
276
	 * 
274
		} else {
-
 
275
			return responseSender.badRequest(
277
	 * } else { return responseSender.badRequest( new
276
					new ProfitMandiBusinessException("Retailer id", userInfo.getUserId(), "NOT_FOFO_RETAILER"));
278
	 * ProfitMandiBusinessException("Retailer id", userInfo.getUserId(),
277
		}
-
 
278
		return responseSender.ok(dealResponse);
279
	 * "NOT_FOFO_RETAILER")); } return responseSender.ok(dealResponse); }
279
	}*/
280
	 */
280
 
281
 
281
	@RequestMapping(value = "/store/entity/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
282
	@RequestMapping(value = "/store/entity/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
282
	@ApiImplicitParams({
283
	@ApiImplicitParams({
283
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
284
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
284
	@ApiOperation(value = "Get unit deal object")
285
	@ApiOperation(value = "Get unit deal object")
Line 461... Line 462...
461
		if (cr.getCartMessageChanged() > 0 || cr.getTotalAmount() != createPendingOrderRequest.getTotalAmount()) {
462
		if (cr.getCartMessageChanged() > 0 || cr.getTotalAmount() != createPendingOrderRequest.getTotalAmount()) {
462
			return responseSender.badRequest("Invalid request");
463
			return responseSender.badRequest("Invalid request");
463
		}
464
		}
464
 
465
 
465
		Map<String, String> returnMap = this.pendingOrderService.createPendingOrder(createPendingOrderRequest, cr);
466
		Map<String, String> returnMap = this.pendingOrderService.createPendingOrder(createPendingOrderRequest, cr);
466
		Customer customer = customerRepository.selectById(createPendingOrderRequest.getCustomerId());
-
 
467
		Template t = velocityEngine.getTemplate("sms.vm");
-
 
468
		VelocityContext context = new VelocityContext();
-
 
469
 
467
 
470
		context.put("customer", customer.getFirstName());
-
 
471
		context.put("invoiceNumber", returnMap.get("poid"));
-
 
472
		StringWriter writer = new StringWriter();
-
 
473
		t.merge(context, writer);
-
 
474
		sendMailWithAttachments("Order Confirmation", writer.toString());
-
 
475
		return responseSender.ok(returnMap);
468
		return responseSender.ok(returnMap);
476
 
469
 
477
	}
470
	}
478
 
471
 
479
	private void sendMailWithAttachments(String subject, String messageText) throws Exception {
472
	private void sendMailWithAttachments(String subject, String messageText) throws Exception {
Line 536... Line 529...
536
					customerOrderDetail.setId(poi.getOrderId());
529
					customerOrderDetail.setId(poi.getOrderId());
537
					customerOrderDetail.setItemId(poi.getItemId());
530
					customerOrderDetail.setItemId(poi.getItemId());
538
					customerOrderDetail.setModelName(item.getModelName());
531
					customerOrderDetail.setModelName(item.getModelName());
539
					customerOrderDetail.setModelNumber(item.getModelNumber());
532
					customerOrderDetail.setModelNumber(item.getModelNumber());
540
					customerOrderDetail.setQuantity(poi.getQuantity());
533
					customerOrderDetail.setQuantity(poi.getQuantity());
-
 
534
					customerOrderDetail.setBilledTimestamp(poi.getBilledTimestamp());
541
					customerOrderDetail.setStatus(po.getStatus());
535
					customerOrderDetail.setStatus(poi.getStatus());
542
					customerOrderDetail.setTotalPrice(poi.getSellingPrice());
536
					customerOrderDetail.setTotalPrice(poi.getSellingPrice());
543
					customerOrderDetail.setPayMethod(po.getPayMethod());
537
					customerOrderDetail.setPayMethod(po.getPayMethod());
544
					customerOrderDetail.setCreatedTimeStamp(po.getCreateTimestamp());
538
					customerOrderDetail.setCreatedTimeStamp(po.getCreateTimestamp());
545
					customerOrderDetails.add(customerOrderDetail);
539
					customerOrderDetails.add(customerOrderDetail);
546
				}
540
				}
Line 711... Line 705...
711
			@RequestParam(value = "q", required = false) String queryTerm,
705
			@RequestParam(value = "q", required = false) String queryTerm,
712
			@RequestParam(value = " ", required = false, defaultValue = "true") boolean partnerStockOnly)
706
			@RequestParam(value = " ", required = false, defaultValue = "true") boolean partnerStockOnly)
713
			throws Throwable {
707
			throws Throwable {
714
		List<FofoCatalogResponse> dealResponse = new ArrayList<>();
708
		List<FofoCatalogResponse> dealResponse = new ArrayList<>();
715
		UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
709
		UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
-
 
710
		dealResponse = this.getCatalogResponse(
716
		dealResponse = this.getCatalogResponse(solrService.getSolrDocs(queryTerm, categoryId, offset, limit,
711
				solrService.getSolrDocs(queryTerm, categoryId, offset, limit, sort, brand, subCategoryId, false), false,
717
				sort, brand, subCategoryId, false), false, userInfo.getRetailerId());
712
				userInfo.getRetailerId());
718
		return responseSender.ok(dealResponse);
713
		return responseSender.ok(dealResponse);
719
	}
714
	}
720
 
715
 
721
	private List<FofoCatalogResponse> getCatalogResponse(JSONArray docs, boolean hotDeal, int fofoId)
716
	private List<FofoCatalogResponse> getCatalogResponse(JSONArray docs, boolean hotDeal, int fofoId)
722
			throws ProfitMandiBusinessException {
717
			throws ProfitMandiBusinessException {
Line 849... Line 844...
849
		return responseSender.ok(pendingOrder);
844
		return responseSender.ok(pendingOrder);
850
	}
845
	}
851
 
846
 
852
	@RequestMapping(value = "/store/addresses/{customerId}", method = RequestMethod.GET)
847
	@RequestMapping(value = "/store/addresses/{customerId}", method = RequestMethod.GET)
853
	public ResponseEntity<?> getAll(HttpServletRequest request, @PathVariable int customerId) throws Throwable {
848
	public ResponseEntity<?> getAll(HttpServletRequest request, @PathVariable int customerId) throws Throwable {
854
		return responseSender.ok(customerAddressRepository.selectByCustomerId(customerId));
849
		return responseSender.ok(customerAddressRepository.selectByActiveCustomerId(customerId));
855
	}
850
	}
856
 
851
 
857
	@RequestMapping(value = "/store/address", method = RequestMethod.POST)
852
	@RequestMapping(value = "/store/address", method = RequestMethod.POST)
858
	public ResponseEntity<?> addAddress(HttpServletRequest request, @RequestBody CustomerAddress customerAddress)
853
	public ResponseEntity<?> addAddress(HttpServletRequest request, @RequestBody CustomerAddress customerAddress)
859
			throws Throwable {
854
			throws Throwable {
860
		customerAddressRepository.persist(customerAddress);
855
		customerAddressRepository.persist(customerAddress);
861
		return responseSender.ok(customerAddress);
856
		return responseSender.ok(customerAddress);
862
	}
857
	}
863
 
858
 
-
 
859
	@RequestMapping(value = "/store/deactivateCustomerAddress", method = RequestMethod.POST)
-
 
860
	public ResponseEntity<?> deactivateAddresss(HttpServletRequest request, @RequestParam int id) throws Throwable {
-
 
861
		CustomerAddress cust = customerAddressRepository.selectById(id);
-
 
862
		cust.setActive(false);
-
 
863
		return responseSender.ok(cust);
-
 
864
	}
-
 
865
 
864
	@RequestMapping(value = "/store/updateCustomer", method = RequestMethod.POST)
866
	@RequestMapping(value = "/store/updateCustomer", method = RequestMethod.POST)
865
	public ResponseEntity<?> updateCustomerProfile(HttpServletRequest request, @RequestBody Customer customer)
867
	public ResponseEntity<?> updateCustomerProfile(HttpServletRequest request, @RequestBody Customer customer)
866
			throws Throwable {
868
			throws Throwable {
867
		Customer cust = customerRepository.selectById(customer.getId());
869
		Customer cust = customerRepository.selectById(customer.getId());
868
		cust.setGender(customer.getGender());
870
		cust.setGender(customer.getGender());
869
		cust.setProfileImageId(customer.getProfileImageId());
871
		cust.setProfileImageId(customer.getProfileImageId());
870
		cust.setDob(customer.getDob());
872
		cust.setDob(customer.getDob());
871
		return responseSender.ok(cust);
873
		return responseSender.ok(cust);
872
	}
874
	}
873
 
875
 
-
 
876
	/*
-
 
877
	 * @RequestMapping(value = "/cancelPendingOrderItem", method =
-
 
878
	 * RequestMethod.POST) public ResponseEntity<?>
-
 
879
	 * cancelPendingOrderItem(HttpServletRequest request, @RequestParam int id,
-
 
880
	 * 
-
 
881
	 * @RequestParam String statusDescription) throws Exception {
-
 
882
	 * 
-
 
883
	 * PendingOrderItem pendingOrderItem =
-
 
884
	 * pendingOrderItemRepository.selectById(id);
-
 
885
	 * 
-
 
886
	 * PendingOrder pendingOrder =
-
 
887
	 * pendingOrderRepository.selectById(pendingOrderItem.getId()); if
-
 
888
	 * (pendingOrderItem.getBilledTimestamp() == null) {
-
 
889
	 * pendingOrderItem.setStatus(OrderStatus.CANCELLED);
-
 
890
	 * pendingOrderItem.setStatusDescription(statusDescription); List<OrderStatus>
-
 
891
	 * status =
-
 
892
	 * pendingOrderItemRepository.selectByOrderId(pendingOrderItem.getOrderId())
-
 
893
	 * .stream().map(x -> x.getStatus()).collect(Collectors.toList());
-
 
894
	 * 
-
 
895
	 * if (!status.contains(OrderStatus.PENDING)) {
-
 
896
	 * pendingOrder.setStatus(OrderStatus.CLOSED); }
-
 
897
	 * 
-
 
898
	 * pendingOrderItemRepository.persist(pendingOrderItem); }
-
 
899
	 * 
-
 
900
	 * return responseSender.ok(true);
-
 
901
	 * 
-
 
902
	 * }
-
 
903
	 */
-
 
904
 
874
}
905
}
875
 
906
 
876
class UserModel {
907
class UserModel {
877
	@JsonProperty(required = true)
908
	@JsonProperty(required = true)
878
	private String mobile;
909
	private String mobile;