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