| 12855 |
manish.sha |
1 |
package in.shop2020.inventory.service;
|
|
|
2 |
|
|
|
3 |
import in.shop2020.thrift.clients.WarehouseClient;
|
|
|
4 |
import in.shop2020.utils.GmailUtils;
|
|
|
5 |
import in.shop2020.warehouse.InventoryAvailability;
|
|
|
6 |
import in.shop2020.warehouse.WarehouseService.Client;
|
|
|
7 |
|
| 12931 |
manish.sha |
8 |
import java.io.BufferedReader;
|
| 12855 |
manish.sha |
9 |
import java.io.BufferedWriter;
|
|
|
10 |
import java.io.File;
|
| 12931 |
manish.sha |
11 |
import java.io.FileReader;
|
| 12855 |
manish.sha |
12 |
import java.io.FileWriter;
|
|
|
13 |
import java.io.IOException;
|
|
|
14 |
import java.util.ArrayList;
|
|
|
15 |
import java.util.Date;
|
|
|
16 |
import java.util.List;
|
|
|
17 |
|
|
|
18 |
import org.apache.commons.lang.StringUtils;
|
|
|
19 |
import org.apache.thrift.TException;
|
|
|
20 |
import org.slf4j.LoggerFactory;
|
|
|
21 |
|
|
|
22 |
public class StockSheetSender{
|
|
|
23 |
public static org.slf4j.Logger logger = LoggerFactory.getLogger(StockSheetSender.class);
|
|
|
24 |
public static void main(String[] args) {
|
|
|
25 |
List<InventoryAvailability> serializedInventoryAvailability = new ArrayList<InventoryAvailability>();
|
|
|
26 |
List<InventoryAvailability> nonSerializedInventoryAvailability = new ArrayList<InventoryAvailability>();
|
|
|
27 |
List<InventoryAvailability> inventoryAvailability = new ArrayList<InventoryAvailability>();
|
|
|
28 |
|
|
|
29 |
String emailFromAddress = "build-staging@shop2020.in";
|
|
|
30 |
String password = "shop2020";
|
|
|
31 |
GmailUtils mailer = new GmailUtils();
|
| 12856 |
manish.sha |
32 |
//String sendTo[] = new String[]{"manish.sharma@shop2020.in"};
|
|
|
33 |
String sendTo[] = new String[]{ "rajneesh.arora@saholic.com","amit.sirohi@shop2020.in","chaitnaya.vats@saholic.com",
|
|
|
34 |
"lakshman.g@smobility.in","sandeep.sachdeva@shop2020.in"};
|
| 12855 |
manish.sha |
35 |
File file = null;
|
|
|
36 |
|
|
|
37 |
try {
|
|
|
38 |
Client warehouseClient = new WarehouseClient().getClient();
|
|
|
39 |
serializedInventoryAvailability = warehouseClient.getCurrentSerializedInventoryByScans(3298L);
|
|
|
40 |
nonSerializedInventoryAvailability = warehouseClient.getCurrentNonSerializedInventoryByScans(3298L);
|
|
|
41 |
} catch(TException ex) {
|
|
|
42 |
logger.error(ex.getMessage(), ex);
|
|
|
43 |
}
|
|
|
44 |
inventoryAvailability.addAll(serializedInventoryAvailability);
|
|
|
45 |
inventoryAvailability.addAll(nonSerializedInventoryAvailability);
|
|
|
46 |
try {
|
|
|
47 |
file = createInventoryAvailabilityFile(inventoryAvailability);
|
| 12931 |
manish.sha |
48 |
String htmlFileName = getHtmlFileGenrator(file, "Stock Sheet - Hyderabad");
|
| 12855 |
manish.sha |
49 |
List<File> files = new ArrayList<File>();
|
|
|
50 |
files.add(file);
|
| 12931 |
manish.sha |
51 |
if(htmlFileName!=null && !htmlFileName.isEmpty()){
|
|
|
52 |
mailer.sendSSLMessage(sendTo, "Stock Sheet - Hyderabad", " ", emailFromAddress, password, files, htmlFileName);
|
|
|
53 |
}else {
|
|
|
54 |
mailer.sendSSLMessage(sendTo, "Stock Sheet - Hyderabad", " ", emailFromAddress, password, files);
|
|
|
55 |
}
|
| 12855 |
manish.sha |
56 |
}
|
|
|
57 |
catch(Exception e) {
|
|
|
58 |
logger.error(e.getMessage(), e);
|
|
|
59 |
}
|
|
|
60 |
}
|
| 12931 |
manish.sha |
61 |
|
|
|
62 |
|
| 12855 |
manish.sha |
63 |
private static File createInventoryAvailabilityFile(List<InventoryAvailability> inventoryAvailability) throws IOException {
|
|
|
64 |
File file = new File("/tmp/SaholicInventory-Hyderabad.xls");
|
| 12931 |
manish.sha |
65 |
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(file));
|
|
|
66 |
bufferedWriter.write(StringUtils.join(new String[] {
|
|
|
67 |
"Item Id",
|
|
|
68 |
"Brand",
|
|
|
69 |
"Model Name",
|
|
|
70 |
"Model Number",
|
|
|
71 |
"Color",
|
|
|
72 |
"Quantity" }, '\t'));
|
| 12855 |
manish.sha |
73 |
|
| 12931 |
manish.sha |
74 |
for(InventoryAvailability invAvailability : inventoryAvailability) {
|
|
|
75 |
if((invAvailability.getModelNumber().equals("Q50")) || (invAvailability.getItemId() == 1457)) {
|
|
|
76 |
continue;
|
|
|
77 |
}
|
|
|
78 |
bufferedWriter.newLine();
|
|
|
79 |
bufferedWriter.write(StringUtils.join(
|
|
|
80 |
new String[] {
|
|
|
81 |
String.valueOf(invAvailability.getItemId()),
|
|
|
82 |
invAvailability.getBrand(),
|
|
|
83 |
invAvailability.getModelName(),
|
|
|
84 |
invAvailability.getModelNumber(),
|
|
|
85 |
invAvailability.getColor(),
|
|
|
86 |
String.valueOf(invAvailability.getQuantity())}, '\t'));
|
|
|
87 |
}
|
| 12855 |
manish.sha |
88 |
bufferedWriter.close();
|
|
|
89 |
return file;
|
|
|
90 |
}
|
| 12931 |
manish.sha |
91 |
|
|
|
92 |
public static String getHtmlFileGenrator(File file, String tableTitle){
|
|
|
93 |
|
|
|
94 |
String htmlFilePath = "/tmp/"+tableTitle+"-file.htm";
|
|
|
95 |
StringBuffer sb = new StringBuffer();
|
|
|
96 |
sb.append("");
|
|
|
97 |
|
|
|
98 |
try{
|
|
|
99 |
BufferedReader br = new BufferedReader(new FileReader(file));
|
|
|
100 |
String line = "";
|
|
|
101 |
|
|
|
102 |
sb.append("<html><table border=\"1\" align=\"center\">"
|
|
|
103 |
+ "<caption><b>" + tableTitle + "</b></caption>");
|
|
|
104 |
|
|
|
105 |
int lineCount = 1;
|
|
|
106 |
while((line = br.readLine())!= null){
|
|
|
107 |
String[] values = line.split("\t");
|
|
|
108 |
sb.append("<tr>");
|
|
|
109 |
for(String value : values){
|
|
|
110 |
if(lineCount ==1){
|
|
|
111 |
sb.append("<td><b>"+ value.toUpperCase()+"</b></td>");
|
|
|
112 |
}else{
|
|
|
113 |
sb.append("<td>"+ value+"</td>");
|
|
|
114 |
}
|
|
|
115 |
}
|
|
|
116 |
sb.append("</tr>");
|
|
|
117 |
lineCount++;
|
|
|
118 |
}
|
|
|
119 |
|
|
|
120 |
sb.append("</table></html>");
|
|
|
121 |
|
|
|
122 |
BufferedWriter out = new BufferedWriter(new FileWriter(htmlFilePath));
|
|
|
123 |
out.write(sb.toString());
|
|
|
124 |
out.flush();
|
|
|
125 |
out.close();
|
|
|
126 |
|
|
|
127 |
}
|
|
|
128 |
catch(Exception e){
|
|
|
129 |
e.printStackTrace();
|
|
|
130 |
return "";
|
|
|
131 |
}
|
|
|
132 |
return htmlFilePath;
|
|
|
133 |
}
|
| 12855 |
manish.sha |
134 |
}
|