Rev 10253 | Blame | Compare with Previous | Last modification | View Log | RSS feed
package in.shop2020.warehouse.util;import java.util.Arrays;import java.util.Date;import java.util.Hashtable;import java.util.List;import java.util.Map;import java.io.BufferedWriter;import java.io.File;import java.io.FileWriter;import java.io.IOException;import java.util.ArrayList;import in.shop2020.model.v1.inventory.InventoryService;import in.shop2020.model.v1.inventory.Warehouse;import in.shop2020.model.v1.order.LineItem;import in.shop2020.model.v1.order.Order;import in.shop2020.model.v1.order.OrderStatus;import in.shop2020.model.v1.order.TransactionService;import in.shop2020.model.v1.order.TransactionServiceException;import in.shop2020.thrift.clients.InventoryClient;import in.shop2020.thrift.clients.TransactionClient;import in.shop2020.thrift.clients.WarehouseClient;import in.shop2020.utils.GmailUtils;import in.shop2020.warehouse.WarehouseService;import javax.mail.MessagingException;import org.apache.commons.lang.StringUtils;import org.apache.thrift.TException;import org.apache.thrift.transport.TTransportException;public class HotspotStockReportSender {private static final String[] mailTo = {"aman.kumar@shop2020.in","amit.gupta@shop2020.in","chaitnaya.vats@shop2020.in", "raj.kumar@spiceretail.co.in"};private static final String senderAccountMail = "cnc.center@shop2020.in";private static final String senderAccountPswd = "5h0p2o2o";private static final List<Long> hotspotVendors = new ArrayList<Long>(Arrays.asList(1L,38L,64L));private static Map<Long, Warehouse> warehouseMap = new Hashtable<Long, Warehouse>(50);private static List<OrderStatus> undeliveredStatuses;private static List<OrderStatus> retInTransitStatuses;static {undeliveredStatuses = new ArrayList<OrderStatus>();undeliveredStatuses.add(OrderStatus.BILLED);undeliveredStatuses.add(OrderStatus.DELIVERED_AT_STORE);undeliveredStatuses.add(OrderStatus.SHIPPED_FROM_WH);undeliveredStatuses.add(OrderStatus.SHIPPED_TO_DESTINATION_CITY);undeliveredStatuses.add(OrderStatus.SHIPPED_TO_LOGST);undeliveredStatuses.add(OrderStatus.REACHED_DESTINATION_CITY);undeliveredStatuses.add(OrderStatus.RECEIVED_AT_STORE);retInTransitStatuses = new ArrayList<OrderStatus>(20);retInTransitStatuses.add(OrderStatus.RTO_IN_TRANSIT);retInTransitStatuses.add(OrderStatus.RET_PICKUP_CONFIRMED);retInTransitStatuses.add(OrderStatus.RET_PICKUP_REQUEST_RAISED);retInTransitStatuses.add(OrderStatus.RET_REQUEST_RECEIVED);retInTransitStatuses.add(OrderStatus.RET_REQUEST_AUTHORIZED);retInTransitStatuses.add(OrderStatus.RET_PICKUP_CONFIRMED);retInTransitStatuses.add(OrderStatus.RET_RETURN_IN_TRANSIT);retInTransitStatuses.add(OrderStatus.DOA_REQUEST_RECEIVED);retInTransitStatuses.add(OrderStatus.DOA_REQUEST_AUTHORIZED);retInTransitStatuses.add(OrderStatus.DOA_PICKUP_REQUEST_RAISED);retInTransitStatuses.add(OrderStatus.DOA_PICKUP_CONFIRMED);retInTransitStatuses.add(OrderStatus.DOA_PICKUP_DENIED);retInTransitStatuses.add(OrderStatus.DOA_RETURN_IN_TRANSIT);InventoryService.Client inventoryClient;try {inventoryClient = new InventoryClient().getClient();List<Warehouse> warehouses = inventoryClient.getWarehouses(null, null, 1L, 0L, 0L);for(Warehouse warehouse : warehouses) {if(warehouse.getVendor().getId()==1L||warehouse.getVendor().getId()==38L||warehouse.getVendor().getId()==64L) {warehouseMap.put(warehouse.getId(), warehouse);}}} catch (TException e) {e.printStackTrace();}}public static void main(String[] args){HotspotStockReportSender reportSender = new HotspotStockReportSender();List<File> files = new ArrayList<File>(5);try {//File hotspotStockInWarehouseFile = reportSender.getHotspotStockInOurWarehouse();File hotspotStockRetInTransitFile = reportSender.getHotspotStockRetInTransit();File undeliveredHotspotStockFile = reportSender.getUndeliveredHotspotStock();//files.add(hotspotStockInWarehouseFile);files.add(hotspotStockRetInTransitFile);files.add(undeliveredHotspotStockFile);} catch (Exception e) {e.printStackTrace();}GmailUtils mailer = new GmailUtils();try{mailer.sendSSLMessage(mailTo, "Undelivered Hotspot Stock(Billed by Saholic) IMEI details ", "", senderAccountMail, senderAccountPswd, files);} catch (MessagingException e1) {e1.printStackTrace();}}private File getUndeliveredHotspotStock() throws TransactionServiceException, TException, IOException {TransactionService.Client transactionClient = new TransactionClient().getClient();List<Order> orders = transactionClient.getOrdersByVendor(hotspotVendors, undeliveredStatuses);File file = new File("/tmp/undeliveredHotspotStock-"+(new Date()).toString()+".xls");BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(file));bufferedWriter.write(StringUtils.join(new String[] { "Warehouse", "ItemId","Brand", "Model Name", "Model Number","Color", "SerialNumber", "Status", "COD" }, '\t'));for (Order order : orders) {bufferedWriter.newLine();LineItem lineItem = order.getLineitems().get(0);bufferedWriter.write(StringUtils.join(new String[] {warehouseMap.get(order.getWarehouse_id()).getDisplayName(),String.valueOf(lineItem.getItem_id()), lineItem.getBrand(), lineItem.getModel_name(),lineItem.getModel_number(), lineItem.getColor(), lineItem.getSerial_number(), order.getStatus().toString(),(order.isCod()==false?"0":"1") }, "\t"));}bufferedWriter.close();return file;}private File getHotspotStockRetInTransit() throws TransactionServiceException, TException, IOException {TransactionService.Client transactionClient = new TransactionClient().getClient();List<Order> orders = transactionClient.getOrdersByVendor(hotspotVendors, retInTransitStatuses);File file = new File("/tmp/hotspotStockRetInTransit-"+(new Date()).toString()+".xls");BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(file));bufferedWriter.write(StringUtils.join(new String[] {"Warehouse", "ItemId","Brand", "Model Name", "Model Number","Color", "SerialNumber", "Status", "COD" }, '\t'));for (Order order : orders) {bufferedWriter.newLine();LineItem lineItem = order.getLineitems().get(0);bufferedWriter.write(StringUtils.join(new String[] {warehouseMap.get(order.getWarehouse_id()).getDisplayName(),String.valueOf(lineItem.getItem_id()), lineItem.getBrand(), lineItem.getModel_name(),lineItem.getModel_number(), lineItem.getColor(), lineItem.getSerial_number(), order.getStatus().toString(),(order.isCod()==false?"0":"1") }, "\t"));}bufferedWriter.close();return file;}/*private File getHotspotStockInOurWarehouse() throws TException {WarehouseService.Client warehouseClient = new WarehouseClient().getClient();warehouseClient.get}*/}