| 8183 |
amar.kumar |
1 |
package in.shop2020.warehouse.util;
|
|
|
2 |
|
|
|
3 |
import java.util.Arrays;
|
|
|
4 |
import java.util.Date;
|
|
|
5 |
import java.util.Hashtable;
|
|
|
6 |
import java.util.List;
|
|
|
7 |
import java.util.Map;
|
|
|
8 |
import java.io.BufferedWriter;
|
|
|
9 |
import java.io.File;
|
|
|
10 |
import java.io.FileWriter;
|
|
|
11 |
import java.io.IOException;
|
|
|
12 |
import java.util.ArrayList;
|
|
|
13 |
|
|
|
14 |
import in.shop2020.model.v1.inventory.InventoryService;
|
|
|
15 |
import in.shop2020.model.v1.inventory.Warehouse;
|
|
|
16 |
import in.shop2020.model.v1.order.LineItem;
|
|
|
17 |
import in.shop2020.model.v1.order.Order;
|
|
|
18 |
import in.shop2020.model.v1.order.OrderStatus;
|
|
|
19 |
import in.shop2020.model.v1.order.TransactionService;
|
|
|
20 |
import in.shop2020.model.v1.order.TransactionServiceException;
|
|
|
21 |
import in.shop2020.thrift.clients.InventoryClient;
|
|
|
22 |
import in.shop2020.thrift.clients.TransactionClient;
|
|
|
23 |
import in.shop2020.thrift.clients.WarehouseClient;
|
|
|
24 |
import in.shop2020.utils.GmailUtils;
|
|
|
25 |
import in.shop2020.warehouse.WarehouseService;
|
|
|
26 |
|
|
|
27 |
import javax.mail.MessagingException;
|
|
|
28 |
|
|
|
29 |
import org.apache.commons.lang.StringUtils;
|
|
|
30 |
import org.apache.thrift.TException;
|
|
|
31 |
import org.apache.thrift.transport.TTransportException;
|
|
|
32 |
|
|
|
33 |
public class HotspotStockReportSender {
|
| 8187 |
amar.kumar |
34 |
|
| 20003 |
aman.kumar |
35 |
private static final String[] mailTo = {"aman.kumar@shop2020.in","amit.gupta@shop2020.in","chaitnaya.vats@shop2020.in", "raj.kumar@spiceretail.co.in"};
|
| 8183 |
amar.kumar |
36 |
private static final String senderAccountMail = "cnc.center@shop2020.in";
|
| 8184 |
amar.kumar |
37 |
private static final String senderAccountPswd = "5h0p2o2o";
|
| 8183 |
amar.kumar |
38 |
private static final List<Long> hotspotVendors = new ArrayList<Long>(Arrays.asList(1L,38L,64L));
|
|
|
39 |
private static Map<Long, Warehouse> warehouseMap = new Hashtable<Long, Warehouse>(50);
|
|
|
40 |
private static List<OrderStatus> undeliveredStatuses;
|
|
|
41 |
private static List<OrderStatus> retInTransitStatuses;
|
|
|
42 |
static {
|
|
|
43 |
undeliveredStatuses = new ArrayList<OrderStatus>();
|
|
|
44 |
undeliveredStatuses.add(OrderStatus.BILLED);
|
|
|
45 |
undeliveredStatuses.add(OrderStatus.DELIVERED_AT_STORE);
|
|
|
46 |
undeliveredStatuses.add(OrderStatus.SHIPPED_FROM_WH);
|
|
|
47 |
undeliveredStatuses.add(OrderStatus.SHIPPED_TO_DESTINATION_CITY);
|
|
|
48 |
undeliveredStatuses.add(OrderStatus.SHIPPED_TO_LOGST);
|
|
|
49 |
undeliveredStatuses.add(OrderStatus.REACHED_DESTINATION_CITY);
|
|
|
50 |
undeliveredStatuses.add(OrderStatus.RECEIVED_AT_STORE);
|
|
|
51 |
|
|
|
52 |
retInTransitStatuses = new ArrayList<OrderStatus>(20);
|
|
|
53 |
retInTransitStatuses.add(OrderStatus.RTO_IN_TRANSIT);
|
|
|
54 |
retInTransitStatuses.add(OrderStatus.RET_PICKUP_CONFIRMED);
|
|
|
55 |
retInTransitStatuses.add(OrderStatus.RET_PICKUP_REQUEST_RAISED);
|
|
|
56 |
retInTransitStatuses.add(OrderStatus.RET_REQUEST_RECEIVED);
|
|
|
57 |
retInTransitStatuses.add(OrderStatus.RET_REQUEST_AUTHORIZED);
|
|
|
58 |
retInTransitStatuses.add(OrderStatus.RET_PICKUP_CONFIRMED);
|
|
|
59 |
retInTransitStatuses.add(OrderStatus.RET_RETURN_IN_TRANSIT);
|
|
|
60 |
retInTransitStatuses.add(OrderStatus.DOA_REQUEST_RECEIVED);
|
|
|
61 |
retInTransitStatuses.add(OrderStatus.DOA_REQUEST_AUTHORIZED);
|
|
|
62 |
retInTransitStatuses.add(OrderStatus.DOA_PICKUP_REQUEST_RAISED);
|
|
|
63 |
retInTransitStatuses.add(OrderStatus.DOA_PICKUP_CONFIRMED);
|
|
|
64 |
retInTransitStatuses.add(OrderStatus.DOA_PICKUP_DENIED);
|
|
|
65 |
retInTransitStatuses.add(OrderStatus.DOA_RETURN_IN_TRANSIT);
|
|
|
66 |
|
|
|
67 |
InventoryService.Client inventoryClient;
|
|
|
68 |
try {
|
|
|
69 |
inventoryClient = new InventoryClient().getClient();
|
|
|
70 |
List<Warehouse> warehouses = inventoryClient.getWarehouses(null, null, 1L, 0L, 0L);
|
|
|
71 |
for(Warehouse warehouse : warehouses) {
|
|
|
72 |
if(warehouse.getVendor().getId()==1L||warehouse.getVendor().getId()==38L||warehouse.getVendor().getId()==64L) {
|
|
|
73 |
warehouseMap.put(warehouse.getId(), warehouse);
|
|
|
74 |
}
|
|
|
75 |
}
|
|
|
76 |
} catch (TException e) {
|
| 8185 |
amar.kumar |
77 |
e.printStackTrace();
|
| 8183 |
amar.kumar |
78 |
}
|
|
|
79 |
|
|
|
80 |
}
|
|
|
81 |
|
|
|
82 |
public static void main(String[] args){
|
|
|
83 |
HotspotStockReportSender reportSender = new HotspotStockReportSender();
|
|
|
84 |
List<File> files = new ArrayList<File>(5);
|
|
|
85 |
try {
|
|
|
86 |
//File hotspotStockInWarehouseFile = reportSender.getHotspotStockInOurWarehouse();
|
|
|
87 |
File hotspotStockRetInTransitFile = reportSender.getHotspotStockRetInTransit();
|
|
|
88 |
File undeliveredHotspotStockFile = reportSender.getUndeliveredHotspotStock();
|
|
|
89 |
|
|
|
90 |
//files.add(hotspotStockInWarehouseFile);
|
|
|
91 |
files.add(hotspotStockRetInTransitFile);
|
|
|
92 |
files.add(undeliveredHotspotStockFile);
|
|
|
93 |
} catch (Exception e) {
|
| 8185 |
amar.kumar |
94 |
e.printStackTrace();
|
| 8183 |
amar.kumar |
95 |
}
|
|
|
96 |
|
|
|
97 |
GmailUtils mailer = new GmailUtils();
|
|
|
98 |
try{
|
|
|
99 |
mailer.sendSSLMessage(mailTo, "Undelivered Hotspot Stock(Billed by Saholic) IMEI details ", "", senderAccountMail, senderAccountPswd, files);
|
|
|
100 |
} catch (MessagingException e1) {
|
|
|
101 |
e1.printStackTrace();
|
|
|
102 |
}
|
|
|
103 |
}
|
|
|
104 |
|
|
|
105 |
private File getUndeliveredHotspotStock() throws TransactionServiceException, TException, IOException {
|
|
|
106 |
TransactionService.Client transactionClient = new TransactionClient().getClient();
|
|
|
107 |
List<Order> orders = transactionClient.getOrdersByVendor(hotspotVendors, undeliveredStatuses);
|
|
|
108 |
File file = new File("/tmp/undeliveredHotspotStock-"+(new Date()).toString()+".xls");
|
|
|
109 |
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(file));
|
|
|
110 |
bufferedWriter.write(StringUtils.join(new String[] { "Warehouse", "ItemId",
|
|
|
111 |
"Brand", "Model Name", "Model Number",
|
|
|
112 |
"Color", "SerialNumber", "Status", "COD" }, '\t'));
|
|
|
113 |
for (Order order : orders) {
|
|
|
114 |
bufferedWriter.newLine();
|
|
|
115 |
LineItem lineItem = order.getLineitems().get(0);
|
|
|
116 |
bufferedWriter.write(StringUtils.join(new String[] {warehouseMap.get(order.getWarehouse_id()).getDisplayName(),
|
|
|
117 |
String.valueOf(lineItem.getItem_id()), lineItem.getBrand(), lineItem.getModel_name(),
|
|
|
118 |
lineItem.getModel_number(), lineItem.getColor(), lineItem.getSerial_number(), order.getStatus().toString(),
|
|
|
119 |
(order.isCod()==false?"0":"1") }, "\t"));
|
|
|
120 |
}
|
|
|
121 |
bufferedWriter.close();
|
|
|
122 |
return file;
|
|
|
123 |
}
|
|
|
124 |
|
|
|
125 |
private File getHotspotStockRetInTransit() throws TransactionServiceException, TException, IOException {
|
|
|
126 |
TransactionService.Client transactionClient = new TransactionClient().getClient();
|
|
|
127 |
List<Order> orders = transactionClient.getOrdersByVendor(hotspotVendors, retInTransitStatuses);
|
|
|
128 |
File file = new File("/tmp/hotspotStockRetInTransit-"+(new Date()).toString()+".xls");
|
|
|
129 |
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(file));
|
|
|
130 |
bufferedWriter.write(StringUtils.join(new String[] {"Warehouse", "ItemId",
|
|
|
131 |
"Brand", "Model Name", "Model Number",
|
|
|
132 |
"Color", "SerialNumber", "Status", "COD" }, '\t'));
|
|
|
133 |
for (Order order : orders) {
|
|
|
134 |
bufferedWriter.newLine();
|
|
|
135 |
LineItem lineItem = order.getLineitems().get(0);
|
|
|
136 |
bufferedWriter.write(StringUtils.join(new String[] {warehouseMap.get(order.getWarehouse_id()).getDisplayName(),
|
|
|
137 |
String.valueOf(lineItem.getItem_id()), lineItem.getBrand(), lineItem.getModel_name(),
|
|
|
138 |
lineItem.getModel_number(), lineItem.getColor(), lineItem.getSerial_number(), order.getStatus().toString(),
|
|
|
139 |
(order.isCod()==false?"0":"1") }, "\t"));
|
|
|
140 |
}
|
|
|
141 |
bufferedWriter.close();
|
|
|
142 |
return file;
|
|
|
143 |
}
|
|
|
144 |
|
|
|
145 |
/*private File getHotspotStockInOurWarehouse() throws TException {
|
|
|
146 |
WarehouseService.Client warehouseClient = new WarehouseClient().getClient();
|
|
|
147 |
warehouseClient.get
|
|
|
148 |
|
|
|
149 |
}*/
|
|
|
150 |
|
|
|
151 |
|
|
|
152 |
}
|