| 8303 |
amar.kumar |
1 |
package in.shop2020.support.controllers;
|
|
|
2 |
|
|
|
3 |
import in.shop2020.model.v1.order.EbayOrder;
|
|
|
4 |
import in.shop2020.model.v1.order.Order;
|
|
|
5 |
import in.shop2020.model.v1.order.TransactionService;
|
|
|
6 |
import in.shop2020.support.utils.ReportsUtils;
|
|
|
7 |
import in.shop2020.thrift.clients.TransactionClient;
|
|
|
8 |
|
|
|
9 |
import java.io.File;
|
|
|
10 |
import java.io.FileInputStream;
|
|
|
11 |
import java.io.IOException;
|
|
|
12 |
import java.text.SimpleDateFormat;
|
|
|
13 |
import java.util.Date;
|
|
|
14 |
|
|
|
15 |
import javax.servlet.http.HttpServletRequest;
|
|
|
16 |
import javax.servlet.http.HttpSession;
|
|
|
17 |
|
|
|
18 |
import org.apache.commons.io.FileUtils;
|
|
|
19 |
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
20 |
import org.apache.poi.ss.usermodel.Cell;
|
|
|
21 |
import org.apache.poi.ss.usermodel.Row;
|
|
|
22 |
import org.apache.poi.ss.usermodel.Workbook;
|
|
|
23 |
import org.apache.struts2.convention.annotation.InterceptorRef;
|
|
|
24 |
import org.apache.struts2.convention.annotation.InterceptorRefs;
|
|
|
25 |
import org.apache.struts2.convention.annotation.Result;
|
|
|
26 |
import org.apache.struts2.convention.annotation.Results;
|
|
|
27 |
import org.apache.struts2.interceptor.ServletRequestAware;
|
|
|
28 |
import org.slf4j.Logger;
|
|
|
29 |
import org.slf4j.LoggerFactory;
|
|
|
30 |
|
|
|
31 |
import com.opensymphony.xwork2.ActionSupport;
|
|
|
32 |
|
|
|
33 |
@SuppressWarnings("serial")
|
|
|
34 |
@InterceptorRefs({
|
|
|
35 |
@InterceptorRef("defaultStack"),
|
|
|
36 |
@InterceptorRef("login")
|
|
|
37 |
})
|
|
|
38 |
@Results({
|
|
|
39 |
@Result(name="authfail", type="redirectAction", params = {"actionName" , "reports"})
|
|
|
40 |
})
|
|
|
41 |
public class EbayAwbUploaderController extends ActionSupport implements ServletRequestAware {
|
|
|
42 |
|
|
|
43 |
private static Logger logger = LoggerFactory.getLogger(EbayAwbUploaderController.class);
|
|
|
44 |
|
|
|
45 |
private static final int SALES_REC_NUMBER_INDEX = 0;
|
|
|
46 |
private static final int AWB_INDEX = 1;
|
|
|
47 |
|
|
|
48 |
private HttpServletRequest request;
|
|
|
49 |
private HttpSession session;
|
|
|
50 |
|
|
|
51 |
private String errorMsg = "";
|
|
|
52 |
|
|
|
53 |
private File awbFile;
|
|
|
54 |
|
|
|
55 |
private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
56 |
|
|
|
57 |
public String create() throws IOException {
|
|
|
58 |
FileUtils.copyFile(awbFile, new File("/tmp/ebayAwbFile " + sdf.format(new Date()) + ".xls"));
|
|
|
59 |
Workbook wb = new HSSFWorkbook(new FileInputStream(awbFile));
|
|
|
60 |
|
|
|
61 |
int totalNumRows = 0;
|
|
|
62 |
for (Row row : wb.getSheetAt(0)) {
|
|
|
63 |
EbayOrder ebayOrder = null;
|
|
|
64 |
String airwayBillNum = null;
|
|
|
65 |
Order order = null;
|
|
|
66 |
try {
|
|
|
67 |
totalNumRows++;
|
|
|
68 |
if(totalNumRows==1) {
|
|
|
69 |
continue;
|
|
|
70 |
}
|
|
|
71 |
TransactionService.Client transactionClient = new TransactionClient().getClient();
|
|
|
72 |
try {
|
|
|
73 |
ebayOrder = transactionClient.getEbayOrderBySalesRecNumber(new Double(row.getCell(SALES_REC_NUMBER_INDEX).getNumericCellValue()).longValue());
|
|
|
74 |
} catch (Exception e) {
|
|
|
75 |
setErrorMsg(getErrorMsg() + "<br/>Error in getting Ebay Order for Row Id " + totalNumRows);
|
|
|
76 |
continue;
|
|
|
77 |
}
|
|
|
78 |
try {
|
|
|
79 |
airwayBillNum = row.getCell(AWB_INDEX).getStringCellValue();
|
|
|
80 |
} catch (Exception e) {
|
|
|
81 |
setErrorMsg(getErrorMsg() + "<br/>Error in reading airwaybill number for Row " + totalNumRows);
|
|
|
82 |
continue;
|
|
|
83 |
}
|
|
|
84 |
try {
|
|
|
85 |
order = transactionClient.getOrder(ebayOrder.getOrderId());
|
|
|
86 |
} catch (Exception e) {
|
|
|
87 |
setErrorMsg(getErrorMsg() + "<br/>Error in getting Saholic Order for Row Id " + totalNumRows);
|
|
|
88 |
continue;
|
|
|
89 |
}
|
|
|
90 |
|
|
|
91 |
if(order.getAirwaybill_no()==null || order.getAirwaybill_no().equals("null") || order.getAirwaybill_no().isEmpty()) {
|
|
|
92 |
order.setAirwaybill_no(airwayBillNum);
|
|
|
93 |
order.setTracking_id(airwayBillNum);
|
|
|
94 |
transactionClient.updateOrderForEbay(order);
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
} catch (Exception e) {
|
|
|
98 |
logger.error(e + "\n" + e.getMessage() + e.getCause());
|
|
|
99 |
setErrorMsg(getErrorMsg() + "<br/>Error in row number " + totalNumRows);
|
|
|
100 |
addActionError("Error in row number " + totalNumRows);
|
|
|
101 |
}
|
|
|
102 |
}
|
|
|
103 |
if(errorMsg.isEmpty()) {
|
|
|
104 |
setErrorMsg("Sucessfully uploaded Awb numbers");
|
|
|
105 |
}
|
|
|
106 |
return "authsuccess";
|
|
|
107 |
}
|
|
|
108 |
|
|
|
109 |
public String index() {
|
|
|
110 |
if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), "/ebay-dashboard"))
|
|
|
111 |
return "authfail";
|
|
|
112 |
return "authsuccess";
|
|
|
113 |
}
|
|
|
114 |
|
|
|
115 |
@Override
|
|
|
116 |
public void setServletRequest(HttpServletRequest request) {
|
|
|
117 |
this.request = request;
|
|
|
118 |
this.session = request.getSession();
|
|
|
119 |
}
|
|
|
120 |
|
|
|
121 |
public String getErrorMsg() {
|
|
|
122 |
return errorMsg;
|
|
|
123 |
}
|
|
|
124 |
|
|
|
125 |
public void setErrorMsg(String errorMsg) {
|
|
|
126 |
this.errorMsg = errorMsg;
|
|
|
127 |
}
|
|
|
128 |
|
|
|
129 |
public File getAwbFile() {
|
|
|
130 |
return awbFile;
|
|
|
131 |
}
|
|
|
132 |
|
|
|
133 |
public void setAwbFile(File awbFile) {
|
|
|
134 |
this.awbFile = awbFile;
|
|
|
135 |
}
|
|
|
136 |
|
|
|
137 |
}
|