| Line 1... |
Line 1... |
| 1 |
package in.shop2020;
|
1 |
package in.shop2020;
|
| 2 |
|
2 |
|
| 3 |
import in.shop2020.model.v1.catalog.CatalogService;
|
3 |
import in.shop2020.model.v1.catalog.CatalogService;
|
| - |
|
4 |
import in.shop2020.model.v1.catalog.SnapdealItem;
|
| 4 |
import in.shop2020.model.v1.catalog.CatalogServiceException;
|
5 |
import in.shop2020.model.v1.catalog.CatalogServiceException;
|
| 5 |
import in.shop2020.model.v1.catalog.Item;
|
6 |
import in.shop2020.model.v1.catalog.Item;
|
| - |
|
7 |
import in.shop2020.model.v1.catalog.SnapdealItem;
|
| 6 |
import in.shop2020.model.v1.inventory.InventoryService;
|
8 |
import in.shop2020.model.v1.inventory.InventoryService;
|
| 7 |
import in.shop2020.model.v1.inventory.InventoryServiceException;
|
9 |
import in.shop2020.model.v1.inventory.InventoryServiceException;
|
| 8 |
import in.shop2020.model.v1.inventory.VendorItemPricing;
|
10 |
import in.shop2020.model.v1.inventory.VendorItemPricing;
|
| 9 |
import in.shop2020.model.v1.inventory.Warehouse;
|
11 |
import in.shop2020.model.v1.inventory.Warehouse;
|
| 10 |
import in.shop2020.model.v1.order.LineItem;
|
12 |
import in.shop2020.model.v1.order.LineItem;
|
| Line 37... |
Line 39... |
| 37 |
|
39 |
|
| 38 |
import javax.xml.bind.JAXBContext;
|
40 |
import javax.xml.bind.JAXBContext;
|
| 39 |
import javax.xml.bind.JAXBException;
|
41 |
import javax.xml.bind.JAXBException;
|
| 40 |
import javax.xml.bind.Marshaller;
|
42 |
import javax.xml.bind.Marshaller;
|
| 41 |
import javax.xml.bind.Unmarshaller;
|
43 |
import javax.xml.bind.Unmarshaller;
|
| - |
|
44 |
|
| - |
|
45 |
import org.apache.poi.ss.usermodel.Cell;
|
| 42 |
import org.apache.thrift.TException;
|
46 |
import org.apache.thrift.TException;
|
| 43 |
import org.apache.thrift.transport.TTransportException;
|
47 |
import org.apache.thrift.transport.TTransportException;
|
| 44 |
import org.slf4j.Logger;
|
48 |
import org.slf4j.Logger;
|
| 45 |
import org.slf4j.LoggerFactory;
|
49 |
import org.slf4j.LoggerFactory;
|
| 46 |
|
50 |
|
| Line 104... |
Line 108... |
| 104 |
for(Order order:orders.getOrder()){
|
108 |
for(Order order:orders.getOrder()){
|
| 105 |
long subOrderId = (long) order.getSuborderId();
|
109 |
long subOrderId = (long) order.getSuborderId();
|
| 106 |
Client transaction_client = null;
|
110 |
Client transaction_client = null;
|
| 107 |
try {
|
111 |
try {
|
| 108 |
transaction_client = new TransactionClient().getClient();
|
112 |
transaction_client = new TransactionClient().getClient();
|
| 109 |
//transaction_client.snapdealOrderExists(subOrderId);
|
- |
|
| 110 |
System.out.println("Suborder id " + subOrderId);
|
113 |
System.out.println("Suborder id " + subOrderId);
|
| 111 |
if(transaction_client.snapdealOrderExists(subOrderId)) {
|
114 |
if(transaction_client.snapdealOrderExists(subOrderId)) {
|
| - |
|
115 |
logger.error("Snapdeal suborder id exists " + subOrderId);
|
| 112 |
System.out.println("Suborder id exists");
|
116 |
System.out.println("Suborder id exists");
|
| 113 |
continue;
|
117 |
continue;
|
| 114 |
}
|
118 |
}
|
| 115 |
|
119 |
|
| 116 |
} catch (TTransportException e1) {
|
120 |
} catch (TTransportException e1) {
|
| Line 118... |
Line 122... |
| 118 |
e1.printStackTrace();
|
122 |
e1.printStackTrace();
|
| 119 |
} catch (TException e) {
|
123 |
} catch (TException e) {
|
| 120 |
// TODO Auto-generated catch block
|
124 |
// TODO Auto-generated catch block
|
| 121 |
e.printStackTrace();
|
125 |
e.printStackTrace();
|
| 122 |
}
|
126 |
}
|
| 123 |
System.out.println("Inside Order Parsing");
|
127 |
//System.out.println("Inside Order Parsing");
|
| 124 |
Transaction txn = new Transaction();
|
128 |
Transaction txn = new Transaction();
|
| 125 |
System.out.println("User details are " + user.getActiveCartId());
|
129 |
//System.out.println("User details are " + user.getActiveCartId());
|
| 126 |
txn.setShoppingCartid(user.getActiveCartId());
|
130 |
txn.setShoppingCartid(user.getActiveCartId());
|
| 127 |
System.out.println("transaction created");
|
131 |
//System.out.println("creating transaction");
|
| 128 |
txn.setCustomer_id(user.getUserId());
|
132 |
txn.setCustomer_id(user.getUserId());
|
| 129 |
System.out.println("User Id is " + user.getUserId());
|
133 |
System.out.println("User Id is " + user.getUserId());
|
| 130 |
txn.setCreatedOn(new Date().getTime());
|
134 |
txn.setCreatedOn(new Date().getTime());
|
| 131 |
txn.setTransactionStatus(TransactionStatus.INIT);
|
135 |
txn.setTransactionStatus(TransactionStatus.INIT);
|
| 132 |
txn.setStatusDescription("Order for Snapdeal ");
|
136 |
txn.setStatusDescription("Order for Snapdeal ");
|
| 133 |
List<in.shop2020.model.v1.order.Order> orderlist = new ArrayList<in.shop2020.model.v1.order.Order>();
|
137 |
List<in.shop2020.model.v1.order.Order> orderlist = new ArrayList<in.shop2020.model.v1.order.Order>();
|
| 134 |
LineItem lineItem = null;
|
138 |
LineItem lineItem = null;
|
| - |
|
139 |
CatalogService.Client catalogClient = null;
|
| - |
|
140 |
SnapdealItem snapdealItem = null;
|
| - |
|
141 |
double SellingPrice = 0;
|
| 135 |
try {
|
142 |
try {
|
| - |
|
143 |
catalogClient = new CatalogClient().getClient();
|
| - |
|
144 |
snapdealItem = catalogClient.getSnapdealItem(order.getSKUCode());
|
| - |
|
145 |
if(order.getSellingPricePerItem() < snapdealItem.getExceptionPrice()){
|
| - |
|
146 |
SellingPrice = snapdealItem.getExceptionPrice();
|
| - |
|
147 |
}
|
| - |
|
148 |
else{
|
| - |
|
149 |
SellingPrice = order.getSellingPricePerItem();
|
| - |
|
150 |
}
|
| 136 |
lineItem = createLineItem(order.getSKUCode(),order.getSellingPricePerItem());
|
151 |
lineItem = createLineItem(order.getSKUCode(),SellingPrice);
|
| 137 |
System.out.println("Line item created");
|
152 |
System.out.println("Line item created");
|
| 138 |
} catch (CatalogServiceException e) {
|
153 |
} catch (CatalogServiceException e) {
|
| 139 |
logger.error("Unable to create order for suborderid " + order.getSuborderId());
|
154 |
logger.error("Unable to create order for suborderid " + order.getSuborderId());
|
| 140 |
e.printStackTrace();
|
155 |
e.printStackTrace();
|
| 141 |
} catch (TException e) {
|
156 |
} catch (TException e) {
|
| Line 180... |
Line 195... |
| 180 |
} catch(Exception e) {
|
195 |
} catch(Exception e) {
|
| 181 |
logger.error("Error in updating Shipping or Delivery Time for suborderid " + order.getSuborderId());
|
196 |
logger.error("Error in updating Shipping or Delivery Time for suborderid " + order.getSuborderId());
|
| 182 |
continue;
|
197 |
continue;
|
| 183 |
}
|
198 |
}
|
| 184 |
InventoryService.Client inventoryClient = null;
|
199 |
InventoryService.Client inventoryClient = null;
|
| 185 |
Warehouse fulfillmentWarehouse= null;
|
200 |
Warehouse fulfillmentWarehouse= null;
|
| 186 |
try {
|
201 |
try {
|
| 187 |
inventoryClient = new InventoryClient().getClient();
|
202 |
inventoryClient = new InventoryClient().getClient();
|
| - |
|
203 |
if(snapdealItem.getItem_id()!=0 && snapdealItem.getWarehouseId()!=0) {
|
| - |
|
204 |
fulfillmentWarehouse = inventoryClient.getWarehouse(snapdealItem.getWarehouseId());
|
| - |
|
205 |
} else {
|
| 188 |
List<Long> itemAvailability = inventoryClient.getItemAvailabilityAtLocation(order.getSKUCode(), 1);
|
206 |
List<Long> itemAvailability = inventoryClient.getItemAvailabilityAtLocation(order.getSKUCode(), 1);
|
| 189 |
fulfillmentWarehouse = inventoryClient.getWarehouse(itemAvailability.get(0));
|
207 |
fulfillmentWarehouse = inventoryClient.getWarehouse(itemAvailability.get(0));
|
| - |
|
208 |
}
|
| 190 |
logger.info("Fulfillment warehouse id for suborderid " + order.getSuborderId() + " is " + fulfillmentWarehouse.getId());
|
209 |
logger.info("Fulfillment warehouse id for suborderid " + order.getSuborderId() + " is " + fulfillmentWarehouse.getId());
|
| 191 |
t_order.setFulfilmentWarehouseId(fulfillmentWarehouse.getId());
|
210 |
t_order.setFulfilmentWarehouseId(fulfillmentWarehouse.getId());
|
| 192 |
logger.info("Billing warehouse id for suborderid " + order.getSuborderId() + " is " + fulfillmentWarehouse.getBillingWarehouseId());
|
211 |
logger.info("Billing warehouse id for suborderid " + order.getSuborderId() + " is " + fulfillmentWarehouse.getBillingWarehouseId());
|
| 193 |
t_order.setWarehouse_id(fulfillmentWarehouse.getBillingWarehouseId());
|
212 |
t_order.setWarehouse_id(fulfillmentWarehouse.getBillingWarehouseId());
|
| 194 |
VendorItemPricing vendorItemPricing = inventoryClient.getItemPricing(lineItem.getItem_id(), fulfillmentWarehouse.getVendor().getId());
|
213 |
VendorItemPricing vendorItemPricing = inventoryClient.getItemPricing(lineItem.getItem_id(), fulfillmentWarehouse.getVendor().getId());
|
| 195 |
t_order.getLineitems().get(0).setTransfer_price(vendorItemPricing.getTransferPrice());
|
214 |
t_order.getLineitems().get(0).setTransfer_price(vendorItemPricing.getTransferPrice());
|
| 196 |
t_order.getLineitems().get(0).setNlc(vendorItemPricing.getNlc());
|
215 |
t_order.getLineitems().get(0).setNlc(vendorItemPricing.getNlc());
|
| 197 |
} catch (InventoryServiceException e) {
|
216 |
} catch (InventoryServiceException e) {
|
| 198 |
logger.error("Error connecting inventory service for suborderid " + order.getSuborderId());
|
217 |
logger.error("Error connecting inventory service for suborderid " + order.getSuborderId());
|
| 199 |
continue;
|
218 |
continue;
|
| 200 |
} catch (TTransportException e) {
|
219 |
} catch (TTransportException e) {
|
| 201 |
// TODO Auto-generated catch block
|
220 |
// TODO Auto-generated catch block
|
| 202 |
e.printStackTrace();
|
221 |
e.printStackTrace();
|
| 203 |
} catch (TException e) {
|
222 |
} catch (TException e) {
|
| 204 |
// TODO Auto-generated catch block
|
223 |
// TODO Auto-generated catch block
|
| Line 278... |
Line 297... |
| 278 |
continue;
|
297 |
continue;
|
| 279 |
}
|
298 |
}
|
| 280 |
|
299 |
|
| 281 |
t_order.setAirwaybill_no(String.valueOf(order.getAWBNumber()));
|
300 |
t_order.setAirwaybill_no(String.valueOf(order.getAWBNumber()));
|
| 282 |
t_order.setTracking_id(String.valueOf(order.getAWBNumber()));
|
301 |
t_order.setTracking_id(String.valueOf(order.getAWBNumber()));
|
| 283 |
t_order.setTotal_amount(order.getSellingPricePerItem());
|
302 |
t_order.setTotal_amount(SellingPrice);
|
| 284 |
t_order.setOrderType(OrderType.B2C);
|
303 |
t_order.setOrderType(OrderType.B2C);
|
| 285 |
t_order.setSource(SNAPDEAL_SOURCE_ID);
|
304 |
t_order.setSource(SNAPDEAL_SOURCE_ID);
|
| 286 |
t_order.setOrderType(OrderType.B2C);
|
305 |
t_order.setOrderType(OrderType.B2C);
|
| 287 |
orderlist.add(t_order);
|
306 |
orderlist.add(t_order);
|
| 288 |
txn.setOrders(orderlist);
|
307 |
txn.setOrders(orderlist);
|
| 289 |
String referenceCode = order.getReferenceCode();
|
308 |
String referenceCode = order.getReferenceCode();
|
| 290 |
String productName = order.getProduct();
|
309 |
String productName = order.getProduct();
|
| 291 |
SimpleDateFormat istFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
310 |
SimpleDateFormat istFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
| 292 |
Date snapdealTxnDate = null;
|
311 |
Date snapdealTxnDate = null;
|
| 293 |
try {
|
312 |
try {
|
| 294 |
snapdealTxnDate = istFormatter.parse(order.getOrderPlacedDate());
|
313 |
snapdealTxnDate = istFormatter.parse(order.getOrderPlacedDate());
|
| 295 |
} catch (ParseException e) {
|
314 |
} catch (ParseException e) {
|
| 296 |
logger.error("Could not parse order date from file ");
|
315 |
logger.error("Could not parse order date from file ");
|
| 297 |
e.printStackTrace();
|
316 |
e.printStackTrace();
|
| 298 |
}
|
317 |
}
|
| 299 |
try {
|
318 |
try {
|
| 300 |
transactionId = String.valueOf(transaction_client.createTransaction(txn));
|
319 |
transactionId = String.valueOf(transaction_client.createTransaction(txn));
|
| 301 |
} catch (TransactionServiceException e) {
|
320 |
} catch (TransactionServiceException e) {
|
| 302 |
logger.error("Could not create transaction ");
|
321 |
logger.error("Could not create transaction ");
|
| 303 |
e.printStackTrace();
|
322 |
e.printStackTrace();
|
| 304 |
} catch (TException e) {
|
323 |
} catch (TException e) {
|
| 305 |
logger.error("Problem with transaction service while creating transaction");
|
324 |
logger.error("Problem with transaction service while creating transaction");
|
| 306 |
e.printStackTrace();
|
325 |
e.printStackTrace();
|
| 307 |
}
|
326 |
}
|
| 308 |
createPayment(user, (new Long(subOrderId)).toString(), lineItem.getTotal_price());
|
327 |
createPayment(user, (new Long(subOrderId)).toString(),lineItem.getTotal_price());
|
| 309 |
|
328 |
|
| 310 |
Transaction transaction = null;
|
329 |
Transaction transaction = null;
|
| 311 |
try {
|
330 |
try {
|
| 312 |
transaction = transaction_client.getTransaction(Long.parseLong(transactionId));
|
331 |
transaction = transaction_client.getTransaction(Long.parseLong(transactionId));
|
| 313 |
} catch (NumberFormatException e) {
|
332 |
} catch (NumberFormatException e) {
|
| 314 |
logger.error("Problem parsing transaction id " + transactionId);
|
333 |
logger.error("Problem parsing transaction id " + transactionId);
|
| 315 |
e.printStackTrace();
|
334 |
e.printStackTrace();
|
| 316 |
} catch (TransactionServiceException e) {
|
335 |
} catch (TransactionServiceException e) {
|
| 317 |
logger.error("Problem getting transaction from service transaction id " + transactionId);
|
336 |
logger.error("Problem getting transaction from service transaction id " + transactionId);
|
| 318 |
e.printStackTrace();
|
337 |
e.printStackTrace();
|
| 319 |
} catch (TException e) {
|
338 |
} catch (TException e) {
|
| 320 |
logger.error("Problem with transaction service while getting transaction id " + transactionId);
|
339 |
logger.error("Problem with transaction service while getting transaction id " + transactionId);
|
| 321 |
e.printStackTrace();
|
340 |
e.printStackTrace();
|
| 322 |
}
|
341 |
}
|
| 323 |
in.shop2020.model.v1.order.Order snapdealorder = transaction.getOrders().get(0);
|
342 |
in.shop2020.model.v1.order.Order snapdealorder = transaction.getOrders().get(0);
|
| 324 |
|
343 |
|
| 325 |
//inventoryClient.reserveItemInWarehouse(lineItem.getItem_id(), fulfillmentWarehouse.getId(), 1,
|
344 |
//inventoryClient.reserveItemInWarehouse(lineItem.getItem_id(), fulfillmentWarehouse.getId(), 1,
|
| 326 |
// snapdealorder.getId(), snapdealorder.getCreated_timestamp(), snapdealorder.getPromised_shipping_time(), snapdealorder.getLineitems().get(0).getQuantity());
|
345 |
// snapdealorder.getId(), snapdealorder.getCreated_timestamp(), snapdealorder.getPromised_shipping_time(), snapdealorder.getLineitems().get(0).getQuantity());
|
| 327 |
|
346 |
|
| 328 |
|
347 |
|
| 329 |
SnapdealOrder snapdealOrder = new SnapdealOrder();
|
348 |
SnapdealOrder snapdealOrder = new SnapdealOrder();
|
| 330 |
snapdealOrder.setOrderId(snapdealorder.getId());
|
349 |
snapdealOrder.setOrderId(snapdealorder.getId());
|
| 331 |
snapdealOrder.setSubOrderId(subOrderId);
|
350 |
snapdealOrder.setSubOrderId(subOrderId);
|
| 332 |
snapdealOrder.setReferenceCode(referenceCode);
|
351 |
snapdealOrder.setReferenceCode(referenceCode);
|
| 333 |
snapdealOrder.setProductName(productName);
|
352 |
snapdealOrder.setProductName(productName);
|
| 334 |
snapdealOrder.setSnapdealTxnDate(snapdealTxnDate.getTime());
|
353 |
snapdealOrder.setSnapdealTxnDate(snapdealTxnDate.getTime());
|
| 335 |
snapdealOrder.setListingPrice(lineItem.getTotal_price());
|
354 |
snapdealOrder.setListingPrice(order.getSellingPricePerItem());
|
| 336 |
try {
|
355 |
try {
|
| 337 |
transaction_client.createSnapdealOrder(snapdealOrder);
|
356 |
transaction_client.createSnapdealOrder(snapdealOrder);
|
| 338 |
} catch (TException e) {
|
357 |
} catch (TException e) {
|
| 339 |
logger.error("Could not create Snapdeal Order");
|
358 |
logger.error("Could not create Snapdeal Order");
|
| 340 |
e.printStackTrace();
|
359 |
e.printStackTrace();
|
| 341 |
}
|
360 |
}
|
| 342 |
|
361 |
|
| 343 |
}
|
362 |
}
|
| 344 |
|
363 |
|
| 345 |
}
|
364 |
}
|
| 346 |
|
365 |
|
| 347 |
public static void createPayment(User user, String subOrderId, double amount) {
|
366 |
public static void createPayment(User user, String subOrderId, double amount) {
|
| 348 |
in.shop2020.payments.PaymentService.Client client = null;
|
367 |
in.shop2020.payments.PaymentService.Client client = null;
|
| Line 391... |
Line 410... |
| 391 |
lineItem.setUnit_weight(item.getWeight());
|
410 |
lineItem.setUnit_weight(item.getWeight());
|
| 392 |
lineItem.setTotal_weight(item.getWeight());
|
411 |
lineItem.setTotal_weight(item.getWeight());
|
| 393 |
lineItem.setUnit_price(amount);
|
412 |
lineItem.setUnit_price(amount);
|
| 394 |
lineItem.setTotal_price(amount);
|
413 |
lineItem.setTotal_price(amount);
|
| 395 |
|
414 |
|
| 396 |
if (item.getColor() == null || "NA".equals(item.getColor())) {
|
415 |
if (item.getColor() == null || "NA".equals(item.getColor())) {
|
| 397 |
lineItem.setColor("");
|
416 |
lineItem.setColor("");
|
| 398 |
} else {
|
417 |
} else {
|
| 399 |
lineItem.setColor(item.getColor());
|
418 |
lineItem.setColor(item.getColor());
|
| 400 |
}
|
419 |
}
|
| 401 |
return lineItem;
|
420 |
return lineItem;
|