| 5874 |
rajveer |
1 |
package in.shop2020.support.controllers;
|
|
|
2 |
|
| 5876 |
rajveer |
3 |
import in.shop2020.logistics.PickupStore;
|
| 5874 |
rajveer |
4 |
import in.shop2020.model.v1.order.LineItem;
|
|
|
5 |
import in.shop2020.model.v1.order.Order;
|
|
|
6 |
import in.shop2020.model.v1.order.OrderStatus;
|
|
|
7 |
import in.shop2020.model.v1.order.TransactionServiceException;
|
|
|
8 |
import in.shop2020.support.utils.ReportsUtils;
|
| 5876 |
rajveer |
9 |
import in.shop2020.thrift.clients.LogisticsClient;
|
| 5874 |
rajveer |
10 |
import in.shop2020.thrift.clients.TransactionClient;
|
|
|
11 |
|
|
|
12 |
import java.text.DateFormat;
|
|
|
13 |
import java.text.SimpleDateFormat;
|
|
|
14 |
import java.util.Calendar;
|
| 5878 |
rajveer |
15 |
import java.util.HashMap;
|
| 5874 |
rajveer |
16 |
import java.util.List;
|
| 5876 |
rajveer |
17 |
import java.util.Map;
|
| 5874 |
rajveer |
18 |
|
|
|
19 |
import javax.servlet.ServletContext;
|
|
|
20 |
import javax.servlet.http.HttpServletRequest;
|
|
|
21 |
import javax.servlet.http.HttpSession;
|
|
|
22 |
|
|
|
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.apache.struts2.util.ServletContextAware;
|
|
|
29 |
import org.apache.thrift.TException;
|
|
|
30 |
import org.slf4j.Logger;
|
|
|
31 |
import org.slf4j.LoggerFactory;
|
|
|
32 |
|
|
|
33 |
|
|
|
34 |
@InterceptorRefs({
|
|
|
35 |
@InterceptorRef("defaultStack"),
|
|
|
36 |
@InterceptorRef("login")
|
|
|
37 |
})
|
|
|
38 |
|
|
|
39 |
@Results({
|
|
|
40 |
@Result(name="authfail", type="redirectAction", params = {"actionName" , "reports"})
|
|
|
41 |
})
|
|
|
42 |
public class PickupStoreStatisticsController implements ServletRequestAware, ServletContextAware {
|
|
|
43 |
|
|
|
44 |
private static Logger logger = LoggerFactory.getLogger(PickupStoreStatisticsController.class);
|
|
|
45 |
|
| 5878 |
rajveer |
46 |
private static Map<Long, String> stores = null;
|
| 5874 |
rajveer |
47 |
private HttpServletRequest request;
|
|
|
48 |
private HttpSession session;
|
|
|
49 |
private ServletContext context;
|
|
|
50 |
|
|
|
51 |
private List<Order> validOrders;
|
|
|
52 |
|
|
|
53 |
|
|
|
54 |
private TransactionClient tsc;
|
|
|
55 |
private in.shop2020.model.v1.order.TransactionService.Client tClient;
|
|
|
56 |
|
| 5876 |
rajveer |
57 |
private LogisticsClient lsc;
|
|
|
58 |
private in.shop2020.logistics.LogisticsService.Client lClient;
|
|
|
59 |
|
| 5874 |
rajveer |
60 |
private final DateFormat formatter = new SimpleDateFormat("EEE, dd-MMM-yyyy hh:mm a");
|
|
|
61 |
|
| 5876 |
rajveer |
62 |
public PickupStoreStatisticsController(){
|
| 5874 |
rajveer |
63 |
try {
|
|
|
64 |
tsc = new TransactionClient();
|
|
|
65 |
tClient = tsc.getClient();
|
| 5878 |
rajveer |
66 |
if(stores == null){
|
|
|
67 |
lsc = new LogisticsClient();
|
|
|
68 |
lClient = lsc.getClient();
|
|
|
69 |
stores = new HashMap<Long, String>();
|
|
|
70 |
for(PickupStore store: lClient.getAllPickupStores()){
|
|
|
71 |
stores.put(store.getId(), store.getName());
|
|
|
72 |
}
|
|
|
73 |
}
|
| 5874 |
rajveer |
74 |
} catch (Exception e) {
|
|
|
75 |
logger.error("Error connecting to one of the user, order or payment service", e);
|
|
|
76 |
}
|
|
|
77 |
}
|
|
|
78 |
|
|
|
79 |
public String index() {
|
|
|
80 |
if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getServletPath())) {
|
|
|
81 |
return "authfail";
|
|
|
82 |
}
|
|
|
83 |
getStats();
|
|
|
84 |
return "authsuccess";
|
|
|
85 |
|
|
|
86 |
}
|
|
|
87 |
|
|
|
88 |
private void getStats() {
|
|
|
89 |
try {
|
| 5977 |
rajveer |
90 |
validOrders = tClient.getValidOrders(0, true);
|
| 5874 |
rajveer |
91 |
} catch (Exception e){
|
|
|
92 |
logger.error("Error while getting order statistics", e);
|
|
|
93 |
}
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
public List<Order> getValidOrders() {
|
|
|
97 |
return validOrders;
|
|
|
98 |
}
|
|
|
99 |
|
|
|
100 |
public LineItem getItem(Order order) throws TransactionServiceException, TException {
|
|
|
101 |
LineItem lItem = order.getLineitems().get(0);
|
|
|
102 |
return lItem;
|
|
|
103 |
}
|
|
|
104 |
|
|
|
105 |
public String getOrderStatusString(OrderStatus status) {
|
|
|
106 |
return status.getDescription();
|
|
|
107 |
}
|
|
|
108 |
|
|
|
109 |
public String getDateTime(long milliseconds) {
|
|
|
110 |
Calendar cal = Calendar.getInstance();
|
|
|
111 |
cal.setTimeInMillis(milliseconds);
|
|
|
112 |
return formatter.format(cal.getTime());
|
|
|
113 |
}
|
|
|
114 |
|
|
|
115 |
@Override
|
|
|
116 |
public void setServletRequest(HttpServletRequest req) {
|
|
|
117 |
this.request = req;
|
|
|
118 |
this.session = req.getSession();
|
|
|
119 |
}
|
|
|
120 |
|
|
|
121 |
@Override
|
|
|
122 |
public void setServletContext(ServletContext context) {
|
|
|
123 |
this.context = context;
|
|
|
124 |
}
|
|
|
125 |
|
| 5876 |
rajveer |
126 |
public String getStoreName(long storeId){
|
|
|
127 |
return stores.get(storeId);
|
|
|
128 |
}
|
|
|
129 |
|
| 5874 |
rajveer |
130 |
public String getServletContextPath() {
|
|
|
131 |
return context.getContextPath();
|
|
|
132 |
}
|
|
|
133 |
}
|
|
|
134 |
|