Rev 4353 | Rev 4411 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
package in.shop2020.hotspot.dashbaord.server;import in.shop2020.hotspot.dashbaord.shared.actions.Order;import in.shop2020.hotspot.dashbaord.shared.actions.OrderType;import in.shop2020.hotspot.dashbaord.shared.actions.ReturnOrder;import in.shop2020.model.v1.order.LineItem;import in.shop2020.model.v1.order.OrderStatus;import in.shop2020.model.v1.order.TransactionService.Client;import in.shop2020.thrift.clients.TransactionClient;import java.util.ArrayList;import java.util.Date;import java.util.List;/*** This class is a facade to the Transaction service and should be used to* access all order specific data which requires some kind of transformation.** @author Chandranshu**/public class TransactionUtils {/*** The human user is concerned only with a consolidated view of actionable* orders. Orders with different statuses in the database can be part of the* same consolidated view. This method uses a mapping of <i>type</i> to* <i>status</i> to get all such orders and return them as order beans.** @param type* The type of orders to return.* @param offset* Offset to start from* @param limit* No. of orders to return* @param warehouseId* The warehouse for which the orders should be queried.* @return A list of orders of the given type to be fulfilled from the given* warehouse*/public static List<Order> getOrders(OrderType type, long offset, long limit, long warehouseId){List<OrderStatus> statuses = getStatuses(type);List<Order> orders = new ArrayList<Order>();try{TransactionClient txnClient = new TransactionClient();Client client = txnClient.getClient();List<in.shop2020.model.v1.order.Order> t_orders = new ArrayList<in.shop2020.model.v1.order.Order>();t_orders.addAll(client.getOrdersInBatch(statuses, offset, limit, warehouseId));for (in.shop2020.model.v1.order.Order t_order: t_orders){Order o = getOrderFromThriftOrder(t_order);orders.add(o);}}catch(Exception e){e.printStackTrace();}return orders;}/*** Wrapper around the method of same name in the transaction service. This* method uses a mapping of <i>type</i> to <i>status</i> to get the count of* all orders with a given status.** @param type* The type of orders to return.* @param warehouseId* The warehouse for which the orders should be queried.* @return The count of orders of the given type assigned to the given* warehouse.*/public static int getOrderCount(OrderType type, long warehouseId){List<OrderStatus> statuses = getStatuses(type);int count = 0;try{TransactionClient txnClient = new TransactionClient();Client client = txnClient.getClient();count += client.getOrderCount(statuses, warehouseId);}catch(Exception e){e.printStackTrace();}return count;}/*** Calls the same method of the transaction service and returns the status* returned. Catches all exceptions that are raised and returns false in* that case.** @param warehouseId* The warehouse for which the orders should be marked as* manifested.* @param providerId* The provider for which the orders should be marked as* manifested.* @param cod* Whether cod orders have to be marked as manifested* @return True if everything goes fine, false otherwise.*/public static boolean markOrdersAsManifested(long warehouseId, String providerId, boolean cod){try {long provider_id = Long.parseLong(providerId);TransactionClient client = new TransactionClient();Client c = client.getClient();return c.markOrdersAsManifested(warehouseId, provider_id, cod);}catch(Exception e){e.printStackTrace();return false;}}/**** @param t_order* A thrift order object with line items.* @return an Order bean which can be used for rendering on the client side.*/public static Order getOrderFromThriftOrder(in.shop2020.model.v1.order.Order t_order) {LineItem lineItem = t_order.getLineitems().get(0);String delayReason = null;if(t_order.getDelayReason() != null)delayReason = t_order.getDelayReason().name();Order order = new Order(t_order.getId(),t_order.getCustomer_id(),t_order.getCustomer_name(),t_order.getCustomer_mobilenumber(),t_order.getCustomer_pincode(),t_order.getCustomer_address1(),t_order.getCustomer_address2(),t_order.getCustomer_city(),t_order.getCustomer_state(),t_order.getCustomer_email(),t_order.getCreated_timestamp(),t_order.getShipping_timestamp(),t_order.getVerification_timestamp(),t_order.getExpected_delivery_time(),t_order.getPromised_delivery_time(),t_order.getExpected_shipping_time(),t_order.getStatus().getValue(),t_order.getStatusDescription(),lineItem.getItem_id(),lineItem.getProductGroup(),lineItem.getBrand(),lineItem.getModel_name(),lineItem.getModel_number(),lineItem.getColor(),lineItem.getExtra_info(),lineItem.getDealText(),t_order.getTotal_amount(),t_order.getTotal_weight(),t_order.getAirwaybill_no(),t_order.getBilled_by(),t_order.getInvoice_number(),t_order.getJacket_number(),lineItem.getItem_number(),lineItem.getImei_number(),t_order.getBatchNo(),t_order.getSerialNo(),t_order.isDoaFlag(),t_order.getPickupRequestNo(),t_order.isCod(),delayReason);return order;}/*** Queries the transction server to get the list of all return orders that* have to be processed.** @return A list of all return orders to be processed.*/public static List<ReturnOrder> getReturnOrders(long warehouseId){List<ReturnOrder> retOrders = new ArrayList<ReturnOrder>();try{TransactionClient client = new TransactionClient();Client c = client.getClient();List<in.shop2020.model.v1.order.ReturnOrder> tRetOrders = c.getReturnOrders(warehouseId, 0L, new Date().getTime());for(in.shop2020.model.v1.order.ReturnOrder retOrder : tRetOrders){retOrders.add(getReturnOrderFromThriftRO(retOrder));}}catch(Exception e){e.printStackTrace();}return retOrders;}public static ReturnOrder getReturnOrderFromThriftRO(in.shop2020.model.v1.order.ReturnOrder tRetOrder){ReturnOrder retOrder = new ReturnOrder(tRetOrder.getOrderId(),tRetOrder.getWarehouseId(),tRetOrder.getItemId(),tRetOrder.getProductGroup(),tRetOrder.getBrand(),tRetOrder.getModelName(),tRetOrder.getModelNumber(),tRetOrder.getColor(),tRetOrder.getInvoiceNumber(),tRetOrder.getJacketNumber(),tRetOrder.getTotalPrice(),tRetOrder.getTransferPrice(),false,tRetOrder.getCreatedAt());return retOrder;}/*** This method maps a given type to a list of statuses.** @param type* The type of orders to fetch.* @return The list of Thrift statuses associated with a particular order* type.*/public static List<OrderStatus> getStatuses(OrderType type) {List<OrderStatus> statuses = new ArrayList<OrderStatus>();switch (type) {case ACCEPTED:statuses.add(OrderStatus.ACCEPTED);break;case ALL_PENDING:statuses.add(OrderStatus.SUBMITTED_FOR_PROCESSING);statuses.add(OrderStatus.INVENTORY_LOW);statuses.add(OrderStatus.LOW_INV_PO_RAISED);statuses.add(OrderStatus.LOW_INV_REVERSAL_IN_PROCESS);statuses.add(OrderStatus.LOW_INV_NOT_AVAILABLE_AT_HOTSPOT);break;case NEW:statuses.add(OrderStatus.SUBMITTED_FOR_PROCESSING);break;case BILLED:statuses.add(OrderStatus.BILLED);break;case LOW_INVENTORY:statuses.add(OrderStatus.INVENTORY_LOW);break;case PO_RAISED:statuses.add(OrderStatus.LOW_INV_PO_RAISED);break;case REVERSAL_INITIATED:statuses.add(OrderStatus.LOW_INV_REVERSAL_IN_PROCESS);break;case NOT_AVAILABLE:statuses.add(OrderStatus.LOW_INV_NOT_AVAILABLE_AT_HOTSPOT);break;case CANCEL_CONFIRMED:statuses.add(OrderStatus.CANCEL_REQUEST_CONFIRMED);break;case REJECTED:statuses.add(OrderStatus.REJECTED);break;case SHIPPED:statuses.add(OrderStatus.SHIPPED_FROM_WH);statuses.add(OrderStatus.SHIPPED_TO_LOGST);break;case DELIVERED:statuses.add(OrderStatus.DELIVERY_SUCCESS);statuses.add(OrderStatus.DOA_PICKUP_REQUESTED);break;case DOA_AWAITED:statuses.add(OrderStatus.DOA_RETURN_AUTHORIZED);statuses.add(OrderStatus.DOA_RETURN_IN_TRANSIT);statuses.add(OrderStatus.DOA_RECEIVED);break;case SALES_RETURN_AWAITED:statuses.add(OrderStatus.SALES_RETURN_IN_TRANSIT);break;case DOA_RETURNED:statuses.add(OrderStatus.DOA_CERT_VALID);break;case SALES_RETURNED:statuses.add(OrderStatus.SALES_RET_RECEIVED);statuses.add(OrderStatus.DOA_CERT_INVALID);break;case RESHIPPED:statuses.add(OrderStatus.SALES_RET_RESHIPPED);statuses.add(OrderStatus.DOA_INVALID_RESHIPPED);statuses.add(OrderStatus.DOA_RESHIPPED);break;case REFUNDED:statuses.add(OrderStatus.CANCELED);statuses.add(OrderStatus.SALES_RET_REFUNDED);statuses.add(OrderStatus.DOA_INVALID_REFUNDED);statuses.add(OrderStatus.DOA_VALID_REFUNDED);statuses.add(OrderStatus.REFUNDED);break;case VERIFICATION_PENDING:statuses.add(OrderStatus.INIT);break;default:break;}return statuses;}}