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