| 6154 |
rajveer |
1 |
package in.shop2020.support.controllers;
|
|
|
2 |
|
| 6194 |
rajveer |
3 |
import in.shop2020.model.v1.order.RechargeOrderStatus;
|
| 6244 |
rajveer |
4 |
import in.shop2020.model.v1.order.RechargePlan;
|
| 6194 |
rajveer |
5 |
import in.shop2020.model.v1.order.RechargeStatistics;
|
| 6161 |
rajveer |
6 |
import in.shop2020.model.v1.order.RechargeType;
|
| 6154 |
rajveer |
7 |
import in.shop2020.support.utils.ReportsUtils;
|
|
|
8 |
import in.shop2020.thrift.clients.TransactionClient;
|
|
|
9 |
|
|
|
10 |
import java.text.DateFormat;
|
|
|
11 |
import java.text.SimpleDateFormat;
|
|
|
12 |
import java.util.Calendar;
|
| 6244 |
rajveer |
13 |
import java.util.HashMap;
|
|
|
14 |
import java.util.List;
|
| 6161 |
rajveer |
15 |
import java.util.Map;
|
|
|
16 |
import java.util.Map.Entry;
|
| 6154 |
rajveer |
17 |
|
|
|
18 |
import javax.servlet.ServletContext;
|
|
|
19 |
import javax.servlet.http.HttpServletRequest;
|
|
|
20 |
import javax.servlet.http.HttpSession;
|
|
|
21 |
|
|
|
22 |
import org.apache.struts2.convention.annotation.InterceptorRef;
|
|
|
23 |
import org.apache.struts2.convention.annotation.InterceptorRefs;
|
|
|
24 |
import org.apache.struts2.convention.annotation.Result;
|
|
|
25 |
import org.apache.struts2.convention.annotation.Results;
|
|
|
26 |
import org.apache.struts2.interceptor.ServletRequestAware;
|
|
|
27 |
import org.apache.struts2.util.ServletContextAware;
|
|
|
28 |
import org.slf4j.Logger;
|
|
|
29 |
import org.slf4j.LoggerFactory;
|
|
|
30 |
|
|
|
31 |
|
|
|
32 |
@InterceptorRefs({
|
|
|
33 |
@InterceptorRef("defaultStack"),
|
|
|
34 |
@InterceptorRef("login")
|
|
|
35 |
})
|
|
|
36 |
|
|
|
37 |
@Results({
|
|
|
38 |
@Result(name="authfail", type="redirectAction", params = {"actionName" , "reports"})
|
|
|
39 |
})
|
|
|
40 |
public class RechargeOrdersController implements ServletRequestAware, ServletContextAware {
|
|
|
41 |
|
|
|
42 |
private static Logger logger = LoggerFactory.getLogger(RechargeOrdersController.class);
|
|
|
43 |
|
|
|
44 |
private HttpServletRequest request;
|
|
|
45 |
private HttpSession session;
|
|
|
46 |
private ServletContext context;
|
|
|
47 |
|
| 6194 |
rajveer |
48 |
private RechargeStatistics stats;
|
| 6154 |
rajveer |
49 |
|
| 6161 |
rajveer |
50 |
private static Map<Long, String> providers;
|
| 6244 |
rajveer |
51 |
static Map<String, String> planMap = new HashMap<String, String>();
|
|
|
52 |
|
| 6154 |
rajveer |
53 |
private TransactionClient tsc;
|
|
|
54 |
private in.shop2020.model.v1.order.TransactionService.Client tClient;
|
|
|
55 |
|
|
|
56 |
private final DateFormat formatter = new SimpleDateFormat("EEE, dd-MMM-yyyy hh:mm a");
|
|
|
57 |
|
|
|
58 |
public RechargeOrdersController(){
|
|
|
59 |
try {
|
|
|
60 |
tsc = new TransactionClient();
|
|
|
61 |
tClient = tsc.getClient();
|
|
|
62 |
} catch (Exception e) {
|
|
|
63 |
logger.error("Error connecting to one of the user, order or payment service", e);
|
|
|
64 |
}
|
|
|
65 |
}
|
|
|
66 |
|
| 6161 |
rajveer |
67 |
static{
|
|
|
68 |
TransactionClient tc;
|
|
|
69 |
try {
|
|
|
70 |
tc = new TransactionClient();
|
| 6206 |
rajveer |
71 |
providers = tc.getClient().getServiceProviders(RechargeType.MOBILE, false);
|
| 6244 |
rajveer |
72 |
for (Long operatorId : providers.keySet()) {
|
|
|
73 |
List<RechargePlan> plans = tc.getClient().getPlansForOperator(operatorId);
|
|
|
74 |
if (!plans.isEmpty()) {
|
|
|
75 |
for(RechargePlan plan: plans){
|
|
|
76 |
planMap.put(plan.getName(), plan.getDisplayName());
|
|
|
77 |
}
|
|
|
78 |
}
|
|
|
79 |
}
|
| 6206 |
rajveer |
80 |
for(Entry<Long, String> providerEntry: tc.getClient().getServiceProviders(RechargeType.DTH, false).entrySet()){
|
| 6161 |
rajveer |
81 |
providers.put(providerEntry.getKey(), providerEntry.getValue());
|
|
|
82 |
}
|
| 6244 |
rajveer |
83 |
|
| 6161 |
rajveer |
84 |
} catch (Exception e) {
|
|
|
85 |
logger.error("Cannot get providers", e);
|
|
|
86 |
}
|
|
|
87 |
}
|
|
|
88 |
|
| 6154 |
rajveer |
89 |
public String index() {
|
|
|
90 |
if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getServletPath())) {
|
|
|
91 |
return "authfail";
|
|
|
92 |
}
|
| 6194 |
rajveer |
93 |
try {
|
|
|
94 |
stats = tClient.getRechargeStatistics();
|
| 6154 |
rajveer |
95 |
} catch (Exception e){
|
|
|
96 |
logger.error("Error while getting order statistics", e);
|
|
|
97 |
}
|
| 6194 |
rajveer |
98 |
return "authsuccess";
|
|
|
99 |
|
| 6154 |
rajveer |
100 |
}
|
|
|
101 |
|
| 6194 |
rajveer |
102 |
public RechargeStatistics getStats() {
|
|
|
103 |
return stats;
|
| 6154 |
rajveer |
104 |
}
|
| 6161 |
rajveer |
105 |
|
|
|
106 |
public String getOperator(long operatorId) {
|
|
|
107 |
return providers.get(operatorId);
|
|
|
108 |
}
|
|
|
109 |
|
| 6244 |
rajveer |
110 |
public String getPlanString(String plan) {
|
|
|
111 |
return planMap.get(plan);
|
|
|
112 |
}
|
|
|
113 |
|
| 6196 |
rajveer |
114 |
public String getStatusDescription(long status) {
|
|
|
115 |
return RechargeOrderStatus.findByValue((int)status).toString();
|
| 6194 |
rajveer |
116 |
}
|
|
|
117 |
|
| 6154 |
rajveer |
118 |
public String getDateTime(long milliseconds) {
|
|
|
119 |
Calendar cal = Calendar.getInstance();
|
|
|
120 |
cal.setTimeInMillis(milliseconds);
|
|
|
121 |
return formatter.format(cal.getTime());
|
|
|
122 |
}
|
|
|
123 |
|
|
|
124 |
@Override
|
|
|
125 |
public void setServletRequest(HttpServletRequest req) {
|
|
|
126 |
this.request = req;
|
|
|
127 |
this.session = req.getSession();
|
|
|
128 |
}
|
|
|
129 |
|
|
|
130 |
@Override
|
|
|
131 |
public void setServletContext(ServletContext context) {
|
|
|
132 |
this.context = context;
|
|
|
133 |
}
|
|
|
134 |
|
|
|
135 |
public String getServletContextPath() {
|
|
|
136 |
return context.getContextPath();
|
|
|
137 |
}
|
| 6161 |
rajveer |
138 |
|
| 6371 |
rajveer |
139 |
public static Map<Long, String> getProviderMap() {
|
| 6161 |
rajveer |
140 |
return providers;
|
|
|
141 |
}
|
| 6154 |
rajveer |
142 |
}
|
|
|
143 |
|