| 2674 |
vikas |
1 |
package in.shop2020.serving.controllers;
|
|
|
2 |
|
| 3090 |
mandeep.dh |
3 |
import in.shop2020.crm.Activity;
|
|
|
4 |
import in.shop2020.crm.CRMService.Client;
|
|
|
5 |
import in.shop2020.crm.Ticket;
|
|
|
6 |
import in.shop2020.crm.TicketStatus;
|
| 2724 |
vikas |
7 |
import in.shop2020.model.v1.order.Order;
|
|
|
8 |
import in.shop2020.model.v1.order.OrderStatus;
|
| 3090 |
mandeep.dh |
9 |
import in.shop2020.model.v1.order.TransactionServiceException;
|
| 2724 |
vikas |
10 |
import in.shop2020.model.v1.user.Cart;
|
|
|
11 |
import in.shop2020.model.v1.user.Line;
|
|
|
12 |
import in.shop2020.model.v1.user.User;
|
| 3090 |
mandeep.dh |
13 |
import in.shop2020.model.v1.user.UserCommunication;
|
|
|
14 |
import in.shop2020.model.v1.user.UserCommunicationException;
|
|
|
15 |
import in.shop2020.model.v1.user.UserContextException;
|
|
|
16 |
import in.shop2020.model.v1.user.UserState;
|
| 2674 |
vikas |
17 |
|
| 2724 |
vikas |
18 |
import java.text.SimpleDateFormat;
|
|
|
19 |
import java.util.Arrays;
|
|
|
20 |
import java.util.Date;
|
| 3090 |
mandeep.dh |
21 |
import java.util.HashSet;
|
| 2724 |
vikas |
22 |
import java.util.List;
|
| 3090 |
mandeep.dh |
23 |
import java.util.Set;
|
| 2724 |
vikas |
24 |
|
| 2674 |
vikas |
25 |
import org.apache.log4j.Logger;
|
|
|
26 |
import org.apache.struts2.convention.annotation.Action;
|
| 3090 |
mandeep.dh |
27 |
import org.apache.thrift.TException;
|
| 2674 |
vikas |
28 |
|
|
|
29 |
/**
|
|
|
30 |
* @author vikas
|
|
|
31 |
*
|
|
|
32 |
*/
|
|
|
33 |
@SuppressWarnings("serial")
|
|
|
34 |
public class HomeController extends BaseController {
|
| 3090 |
mandeep.dh |
35 |
private static final Logger log = Logger.getLogger(HomeController.class);
|
|
|
36 |
private final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
37 |
|
|
|
38 |
private static final Set<OrderStatus> failedStatusList = new HashSet<OrderStatus>(Arrays.asList(new OrderStatus[] {
|
|
|
39 |
OrderStatus.SALES_RET_RESHIPPED,
|
|
|
40 |
OrderStatus.SALES_RET_REFUNDED,
|
|
|
41 |
OrderStatus.DOA_INVALID_REFUNDED,
|
|
|
42 |
OrderStatus.DOA_INVALID_RESHIPPED,
|
|
|
43 |
OrderStatus.DOA_VALID_REFUNDED,
|
|
|
44 |
OrderStatus.DOA_RESHIPPED,
|
|
|
45 |
OrderStatus.REFUNDED,
|
|
|
46 |
OrderStatus.REJECTED,
|
|
|
47 |
OrderStatus.FAILED}));
|
|
|
48 |
|
| 2724 |
vikas |
49 |
private String email;
|
|
|
50 |
private long orderId;
|
| 3090 |
mandeep.dh |
51 |
private String mobileNumber;
|
| 2724 |
vikas |
52 |
private User user;
|
|
|
53 |
private long orderCount;
|
|
|
54 |
private long completedOrderCount;
|
|
|
55 |
private long openOrderCount;
|
|
|
56 |
private long failedOrderCount;
|
| 2830 |
vikas |
57 |
private long userCommunicationCount;
|
| 3090 |
mandeep.dh |
58 |
private long ticketCount;
|
|
|
59 |
private long openTicketCount;
|
|
|
60 |
private long closedTicketCount;
|
| 3096 |
mandeep.dh |
61 |
private String ticketId;
|
| 2724 |
vikas |
62 |
private String lastLogin;
|
|
|
63 |
private double cartItems;
|
|
|
64 |
private String couponCode = "";
|
| 3106 |
mandeep.dh |
65 |
private long agentTicketCount;
|
|
|
66 |
private long agentOpenTicketCount;
|
|
|
67 |
private long unassignedTicketCount;
|
|
|
68 |
private long allTicketCount;
|
|
|
69 |
private long allOpenTicketCount;
|
|
|
70 |
private long activityCount;
|
| 2674 |
vikas |
71 |
|
|
|
72 |
@Action("/")
|
| 2724 |
vikas |
73 |
public String index() throws Exception {
|
| 3137 |
mandeep.dh |
74 |
createServiceClients();
|
|
|
75 |
String returnValue = INPUT;
|
|
|
76 |
|
| 3090 |
mandeep.dh |
77 |
try {
|
| 3106 |
mandeep.dh |
78 |
if (email == null) {
|
| 3137 |
mandeep.dh |
79 |
loadTicketCounts(crmServiceClient);
|
|
|
80 |
return returnValue;
|
| 3106 |
mandeep.dh |
81 |
}
|
|
|
82 |
|
| 3096 |
mandeep.dh |
83 |
if (email != null && !email.isEmpty()) {
|
|
|
84 |
user = userContextServiceClient.getUserByEmail(email);
|
| 3090 |
mandeep.dh |
85 |
}
|
| 3096 |
mandeep.dh |
86 |
else if (mobileNumber != null && !mobileNumber.isEmpty()) {
|
|
|
87 |
user = userContextServiceClient.getUserByMobileNumber(Long.parseLong(mobileNumber));
|
| 2724 |
vikas |
88 |
}
|
| 3096 |
mandeep.dh |
89 |
else if (orderId != 0) {
|
|
|
90 |
Order order = transactionServiceClient.getOrder(orderId);
|
|
|
91 |
user = userContextServiceClient.getUserById(order.getCustomer_id());
|
| 2724 |
vikas |
92 |
}
|
| 3096 |
mandeep.dh |
93 |
else if (ticketId != null && !ticketId.isEmpty()) {
|
|
|
94 |
Ticket ticket = crmServiceClient.getTicket(Long.parseLong(ticketId));
|
|
|
95 |
user = userContextServiceClient.getUserById(ticket.getCustomerId());
|
|
|
96 |
}
|
| 3090 |
mandeep.dh |
97 |
|
|
|
98 |
if (user == null || user.getUserId() <= 0) {
|
|
|
99 |
addActionError("Invalid Input");
|
|
|
100 |
}
|
| 3137 |
mandeep.dh |
101 |
else {
|
|
|
102 |
loadUserCommunicationDetails(userContextServiceClient);
|
|
|
103 |
loadOrderDetails(transactionServiceClient);
|
|
|
104 |
loadCartDetails(userContextServiceClient);
|
|
|
105 |
loadTicketDetails(crmServiceClient);
|
|
|
106 |
loadActivityDetails(crmServiceClient);
|
|
|
107 |
returnValue = INDEX;
|
|
|
108 |
}
|
| 2724 |
vikas |
109 |
}
|
| 3090 |
mandeep.dh |
110 |
catch (Exception e) {
|
| 3137 |
mandeep.dh |
111 |
addActionError("Invalid input");
|
| 3090 |
mandeep.dh |
112 |
log.error("Error occurred", e);
|
| 2724 |
vikas |
113 |
}
|
| 3137 |
mandeep.dh |
114 |
|
|
|
115 |
if (INPUT.equals(returnValue)) {
|
|
|
116 |
loadTicketCounts(crmServiceClient);
|
|
|
117 |
}
|
|
|
118 |
|
|
|
119 |
return returnValue;
|
| 3090 |
mandeep.dh |
120 |
}
|
|
|
121 |
|
| 3106 |
mandeep.dh |
122 |
private void loadActivityDetails(Client crmServiceClient) throws TException {
|
|
|
123 |
List<Activity> activities = crmServiceClient.getActivities(user.getUserId());
|
|
|
124 |
if (activities != null) {
|
|
|
125 |
activityCount = activities.size();
|
|
|
126 |
}
|
|
|
127 |
}
|
|
|
128 |
|
| 3137 |
mandeep.dh |
129 |
private void loadTicketCounts(Client crmServiceClient) throws TException {
|
|
|
130 |
long currentAgentId = crmServiceClient.getAgentByEmailId(currentAgentEmailId).getId();
|
|
|
131 |
List<Ticket> tickets = crmServiceClient.getAssignedTickets(currentAgentId);
|
|
|
132 |
agentTicketCount = tickets.size();
|
|
|
133 |
for (Ticket ticket : tickets) {
|
|
|
134 |
if (TicketStatus.OPEN.equals(ticket.getStatus())) {
|
|
|
135 |
agentOpenTicketCount++;
|
|
|
136 |
}
|
|
|
137 |
}
|
|
|
138 |
|
|
|
139 |
List<Ticket> unassignedTickets = crmServiceClient.getUnassignedTickets();
|
|
|
140 |
unassignedTicketCount = unassignedTickets.size();
|
|
|
141 |
|
|
|
142 |
List<Ticket> allTickets = crmServiceClient.getAllTickets(currentAgentId);
|
|
|
143 |
allTicketCount = allTickets.size();
|
|
|
144 |
for (Ticket ticket : allTickets) {
|
|
|
145 |
if (TicketStatus.OPEN.equals(ticket.getStatus())) {
|
|
|
146 |
allOpenTicketCount++;
|
|
|
147 |
}
|
|
|
148 |
}
|
| 3106 |
mandeep.dh |
149 |
}
|
|
|
150 |
|
| 3090 |
mandeep.dh |
151 |
private void loadUserCommunicationDetails(
|
|
|
152 |
in.shop2020.model.v1.user.UserContextService.Client userContextServiceClient)
|
|
|
153 |
throws UserCommunicationException, TException {
|
|
|
154 |
List<UserCommunication> userCommunication = userContextServiceClient.getUserCommunicationByUser(user.getUserId());
|
|
|
155 |
userCommunicationCount = userCommunication.size();
|
|
|
156 |
}
|
|
|
157 |
|
|
|
158 |
private void loadOrderDetails(
|
|
|
159 |
in.shop2020.model.v1.order.TransactionService.Client transactionServiceClient)
|
|
|
160 |
throws TransactionServiceException, TException {
|
|
|
161 |
List<Order> allOrders = transactionServiceClient.getOrdersForCustomer(user.getUserId(), 0, (new Date()).getTime(), null);
|
| 2724 |
vikas |
162 |
orderCount = allOrders.size();
|
| 3090 |
mandeep.dh |
163 |
|
| 2724 |
vikas |
164 |
for (Order o : allOrders) {
|
|
|
165 |
if (o.getStatus() == OrderStatus.DELIVERY_SUCCESS) {
|
|
|
166 |
completedOrderCount++;
|
|
|
167 |
}
|
|
|
168 |
else if (failedStatusList.contains(o.getStatus())) {
|
|
|
169 |
failedOrderCount++;
|
|
|
170 |
}
|
|
|
171 |
else {
|
|
|
172 |
openOrderCount++;
|
|
|
173 |
}
|
|
|
174 |
}
|
| 3090 |
mandeep.dh |
175 |
}
|
|
|
176 |
|
|
|
177 |
private void loadCartDetails(
|
|
|
178 |
in.shop2020.model.v1.user.UserContextService.Client userContextServiceClient)
|
|
|
179 |
throws UserContextException, TException {
|
|
|
180 |
UserState userState = userContextServiceClient.getUserState(user.getUserId());
|
|
|
181 |
lastLogin = sdf.format(new Date(userState.getLastLogin()));
|
|
|
182 |
Cart cart = null;
|
|
|
183 |
|
| 2724 |
vikas |
184 |
try {
|
| 3090 |
mandeep.dh |
185 |
cart = userContextServiceClient.getCurrentCart(user.getUserId());
|
| 2724 |
vikas |
186 |
if (cart.getCouponCode() != null) {
|
|
|
187 |
couponCode = cart.getCouponCode();
|
|
|
188 |
}
|
|
|
189 |
for (Line line : cart.getLines()) {
|
|
|
190 |
cartItems += line.getQuantity();
|
|
|
191 |
}
|
|
|
192 |
} catch (Exception e) {
|
|
|
193 |
log.warn("No cart assigned for this user", e);
|
|
|
194 |
}
|
| 2674 |
vikas |
195 |
}
|
| 2724 |
vikas |
196 |
|
| 3090 |
mandeep.dh |
197 |
private void loadTicketDetails(Client crmServiceClient) throws TException {
|
|
|
198 |
// Fetching tickets' info
|
|
|
199 |
ticketCount = 0;
|
|
|
200 |
openTicketCount = 0;
|
|
|
201 |
closedTicketCount = 0;
|
|
|
202 |
|
|
|
203 |
List<Ticket> tickets = crmServiceClient.getTickets(user.getUserId());
|
|
|
204 |
if (tickets != null)
|
|
|
205 |
{
|
|
|
206 |
for (Ticket ticket : tickets) {
|
|
|
207 |
ticketCount++;
|
| 3106 |
mandeep.dh |
208 |
if (!ticket.getStatus().equals(TicketStatus.CLOSED)) {
|
| 3090 |
mandeep.dh |
209 |
openTicketCount++;
|
|
|
210 |
}
|
|
|
211 |
else {
|
|
|
212 |
closedTicketCount++;
|
|
|
213 |
}
|
|
|
214 |
}
|
|
|
215 |
}
|
|
|
216 |
}
|
|
|
217 |
|
| 2724 |
vikas |
218 |
public void setEmail(String email) {
|
|
|
219 |
this.email = email;
|
|
|
220 |
}
|
|
|
221 |
|
|
|
222 |
public String getEmail() {
|
|
|
223 |
return email;
|
|
|
224 |
}
|
|
|
225 |
|
|
|
226 |
public void setOrderId(String orderId) {
|
| 3090 |
mandeep.dh |
227 |
if (orderId != null && !orderId.isEmpty()) {
|
| 2724 |
vikas |
228 |
this.orderId = Long.parseLong(orderId);
|
|
|
229 |
}
|
|
|
230 |
}
|
|
|
231 |
|
|
|
232 |
public Long getOrderId() {
|
|
|
233 |
return orderId;
|
|
|
234 |
}
|
|
|
235 |
|
|
|
236 |
public User getUser() {
|
|
|
237 |
return user;
|
|
|
238 |
}
|
|
|
239 |
|
|
|
240 |
public long getOrderCount() {
|
|
|
241 |
return orderCount;
|
|
|
242 |
}
|
|
|
243 |
|
|
|
244 |
public long getCompletedOrderCount() {
|
|
|
245 |
return completedOrderCount;
|
|
|
246 |
}
|
|
|
247 |
|
|
|
248 |
public long getOpenOrderCount() {
|
|
|
249 |
return openOrderCount;
|
|
|
250 |
}
|
|
|
251 |
|
|
|
252 |
public long getFailedOrderCount() {
|
|
|
253 |
return failedOrderCount;
|
|
|
254 |
}
|
|
|
255 |
|
|
|
256 |
public double getCartItems() {
|
|
|
257 |
return cartItems;
|
|
|
258 |
}
|
|
|
259 |
|
|
|
260 |
public String getLastLogin() {
|
|
|
261 |
return lastLogin;
|
|
|
262 |
}
|
|
|
263 |
|
|
|
264 |
public String getCouponCode() {
|
|
|
265 |
return couponCode;
|
|
|
266 |
}
|
| 2830 |
vikas |
267 |
|
|
|
268 |
public long getUserCommunicationCount() {
|
|
|
269 |
return userCommunicationCount;
|
|
|
270 |
}
|
| 3090 |
mandeep.dh |
271 |
|
|
|
272 |
public long getTicketCount() {
|
|
|
273 |
return ticketCount;
|
|
|
274 |
}
|
|
|
275 |
|
|
|
276 |
public long getOpenTicketCount() {
|
|
|
277 |
return openTicketCount;
|
|
|
278 |
}
|
|
|
279 |
|
|
|
280 |
public long getClosedTicketCount() {
|
|
|
281 |
return closedTicketCount;
|
|
|
282 |
}
|
|
|
283 |
|
|
|
284 |
public void setMobileNumber(String mobileNumber) {
|
|
|
285 |
this.mobileNumber = mobileNumber;
|
|
|
286 |
}
|
| 3096 |
mandeep.dh |
287 |
|
|
|
288 |
public String getTicketId() {
|
|
|
289 |
return ticketId;
|
|
|
290 |
}
|
|
|
291 |
|
|
|
292 |
public void setTicketId(String ticketId) {
|
|
|
293 |
this.ticketId = ticketId;
|
|
|
294 |
}
|
| 3106 |
mandeep.dh |
295 |
|
|
|
296 |
public long getAgentTicketCount() {
|
|
|
297 |
return agentTicketCount;
|
|
|
298 |
}
|
|
|
299 |
|
|
|
300 |
public long getAgentOpenTicketCount() {
|
|
|
301 |
return agentOpenTicketCount;
|
|
|
302 |
}
|
|
|
303 |
|
|
|
304 |
public long getUnassignedTicketCount() {
|
|
|
305 |
return unassignedTicketCount;
|
|
|
306 |
}
|
|
|
307 |
|
|
|
308 |
public long getAllTicketCount() {
|
|
|
309 |
return allTicketCount;
|
|
|
310 |
}
|
|
|
311 |
|
|
|
312 |
public long getAllOpenTicketCount() {
|
|
|
313 |
return allOpenTicketCount;
|
|
|
314 |
}
|
|
|
315 |
|
|
|
316 |
public long getActivityCount() {
|
|
|
317 |
return activityCount;
|
|
|
318 |
}
|
|
|
319 |
|
|
|
320 |
public void setActivityCount(long activityCount) {
|
|
|
321 |
this.activityCount = activityCount;
|
|
|
322 |
}
|
| 2724 |
vikas |
323 |
}
|