| 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) {
|
| 8546 |
manish.sha |
106 |
return status.getDescription();
|
| 5874 |
rajveer |
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 |
|
| 6010 |
rajveer |
126 |
public String getLastUpdateTime(Order order){
|
|
|
127 |
long lastActionTime = 0;
|
|
|
128 |
switch (order.getStatus().getValue()) {
|
|
|
129 |
case 2:
|
|
|
130 |
lastActionTime = order.getCreated_timestamp();
|
|
|
131 |
break;
|
|
|
132 |
case 3:
|
|
|
133 |
lastActionTime = (order.getVerification_timestamp() == 0) ? order.getCreated_timestamp() : order.getVerification_timestamp();
|
|
|
134 |
break;
|
|
|
135 |
case 4:
|
|
|
136 |
lastActionTime = order.getAccepted_timestamp();
|
|
|
137 |
break;
|
|
|
138 |
case 5:
|
|
|
139 |
lastActionTime = order.getOutofstock_timestamp();
|
|
|
140 |
break;
|
|
|
141 |
case 7:
|
|
|
142 |
lastActionTime = order.getBilling_timestamp();
|
|
|
143 |
break;
|
|
|
144 |
case 9:
|
|
|
145 |
lastActionTime = order.getShipping_timestamp();
|
|
|
146 |
break;
|
|
|
147 |
case 10:
|
|
|
148 |
lastActionTime = order.getPickup_timestamp();
|
|
|
149 |
break;
|
|
|
150 |
case 12:
|
|
|
151 |
lastActionTime = order.getDelivery_timestamp();
|
|
|
152 |
break;
|
|
|
153 |
case 15:
|
|
|
154 |
lastActionTime = order.getRefund_timestamp();
|
|
|
155 |
break;
|
|
|
156 |
case 18:
|
|
|
157 |
lastActionTime = order.getRefund_timestamp();
|
|
|
158 |
break;
|
|
|
159 |
case 31:
|
|
|
160 |
lastActionTime = order.getRefund_timestamp();
|
|
|
161 |
break;
|
|
|
162 |
case 34:
|
|
|
163 |
lastActionTime = order.getRefund_timestamp();
|
|
|
164 |
break;
|
|
|
165 |
case 80:
|
|
|
166 |
lastActionTime = order.getDelivery_timestamp();
|
|
|
167 |
break;
|
|
|
168 |
case 81:
|
|
|
169 |
lastActionTime = order.getDelivery_timestamp();
|
|
|
170 |
break;
|
|
|
171 |
case 63:
|
|
|
172 |
lastActionTime = order.getDoa_auth_timestamp();
|
|
|
173 |
break;
|
|
|
174 |
case 60:
|
|
|
175 |
lastActionTime = order.getDoa_auth_timestamp();
|
|
|
176 |
break;
|
|
|
177 |
default:
|
|
|
178 |
lastActionTime = Calendar.getInstance().getTimeInMillis();
|
|
|
179 |
break;
|
|
|
180 |
}
|
|
|
181 |
return getDateTime(lastActionTime);
|
| 5876 |
rajveer |
182 |
}
|
|
|
183 |
|
| 5874 |
rajveer |
184 |
public String getServletContextPath() {
|
|
|
185 |
return context.getContextPath();
|
|
|
186 |
}
|
| 6010 |
rajveer |
187 |
|
|
|
188 |
public String getStoreName(long storeId){
|
|
|
189 |
return stores.get(storeId);
|
|
|
190 |
}
|
| 5874 |
rajveer |
191 |
}
|
|
|
192 |
|