| 2674 |
vikas |
1 |
package in.shop2020.serving.controllers;
|
|
|
2 |
|
|
|
3 |
import in.shop2020.model.v1.order.Order;
|
|
|
4 |
import in.shop2020.model.v1.order.OrderStatus;
|
|
|
5 |
import in.shop2020.model.v1.user.Line;
|
|
|
6 |
import in.shop2020.model.v1.user.User;
|
|
|
7 |
import in.shop2020.thrift.clients.TransactionServiceClient;
|
|
|
8 |
import in.shop2020.thrift.clients.UserContextServiceClient;
|
|
|
9 |
|
|
|
10 |
import java.text.SimpleDateFormat;
|
|
|
11 |
import java.util.Date;
|
|
|
12 |
import java.util.List;
|
|
|
13 |
|
|
|
14 |
import org.apache.log4j.Logger;
|
|
|
15 |
import org.apache.struts2.convention.annotation.Result;
|
|
|
16 |
import org.apache.struts2.convention.annotation.Results;
|
|
|
17 |
|
|
|
18 |
/**
|
|
|
19 |
* @author vikas
|
|
|
20 |
*
|
|
|
21 |
*/
|
|
|
22 |
@Results({
|
|
|
23 |
@Result(name = "input", location = "/", type = "redirect")
|
|
|
24 |
})
|
|
|
25 |
|
|
|
26 |
@SuppressWarnings("serial")
|
|
|
27 |
public class OrderCustomerInputController extends BaseController {
|
|
|
28 |
private static Logger log = Logger.getLogger(Class.class);
|
|
|
29 |
private String email;
|
|
|
30 |
private long orderId;
|
|
|
31 |
private User user;
|
|
|
32 |
private long orderCount;
|
|
|
33 |
private long completedOrderCount;
|
|
|
34 |
private long openOrderCount;
|
|
|
35 |
private long failedOrderCount;
|
|
|
36 |
private String lastLogin;
|
|
|
37 |
private double cartItems;
|
|
|
38 |
|
|
|
39 |
public OrderCustomerInputController(){
|
|
|
40 |
super();
|
|
|
41 |
}
|
|
|
42 |
|
|
|
43 |
public String create() throws Exception {
|
|
|
44 |
UserContextServiceClient userContextServiceClient = new UserContextServiceClient();
|
|
|
45 |
in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
|
|
|
46 |
TransactionServiceClient transactionServiceClient = new TransactionServiceClient();
|
|
|
47 |
if (email == null || email.isEmpty()) {
|
|
|
48 |
if (orderId != 0) {
|
|
|
49 |
Order order = transactionServiceClient.getClient().getOrder(orderId);
|
|
|
50 |
user = userClient.getUserById(order.getCustomer_id());
|
|
|
51 |
}
|
|
|
52 |
}
|
|
|
53 |
else {
|
|
|
54 |
try {
|
|
|
55 |
user = userClient.getUserByEmail(email);
|
|
|
56 |
} catch (Exception e) {
|
|
|
57 |
log.warn("Unable to get user service client", e);
|
|
|
58 |
return "input";
|
|
|
59 |
}
|
|
|
60 |
}
|
|
|
61 |
if (user == null || user.getUserId() <= 0) {
|
|
|
62 |
addActionError("Invalid Input");
|
|
|
63 |
return "input";
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
List<Order> allOrders = transactionServiceClient.getClient().getOrdersForCustomer(user.getUserId(), 0, (new Date()).getTime(), null);
|
|
|
67 |
orderCount = allOrders.size();
|
|
|
68 |
|
|
|
69 |
for (Order o : allOrders) {
|
|
|
70 |
if (o.getStatus() == OrderStatus.COMPLETED) {
|
|
|
71 |
completedOrderCount++;
|
|
|
72 |
}
|
|
|
73 |
else if (o.getStatus() == OrderStatus.FAILED) {
|
|
|
74 |
failedOrderCount++;
|
|
|
75 |
}
|
|
|
76 |
else {
|
|
|
77 |
openOrderCount++;
|
|
|
78 |
}
|
|
|
79 |
}
|
|
|
80 |
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
81 |
lastLogin = sdf.format(new Date(userClient.getUserState(user.getUserId()).getLastLogin()));
|
|
|
82 |
try {
|
|
|
83 |
for (Line line : userClient.getCurrentCart(user.getUserId())
|
|
|
84 |
.getLines()) {
|
|
|
85 |
cartItems += line.getQuantity();
|
|
|
86 |
}
|
|
|
87 |
} catch (Exception e) {
|
|
|
88 |
log.warn("No cart assigned for this user", e);
|
|
|
89 |
}
|
|
|
90 |
return "index";
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
public void setEmail(String email) {
|
|
|
94 |
this.email = email;
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
public String getEmail() {
|
|
|
98 |
return email;
|
|
|
99 |
}
|
|
|
100 |
|
|
|
101 |
public void setOrderId(String orderId) {
|
|
|
102 |
try {
|
|
|
103 |
this.orderId = Long.parseLong(orderId);
|
|
|
104 |
}
|
|
|
105 |
catch (NumberFormatException e) {
|
|
|
106 |
log.error(e);
|
|
|
107 |
}
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
public Long getOrderId() {
|
|
|
111 |
return orderId;
|
|
|
112 |
}
|
|
|
113 |
|
|
|
114 |
public User getUser() {
|
|
|
115 |
return user;
|
|
|
116 |
}
|
|
|
117 |
|
|
|
118 |
public long getOrderCount() {
|
|
|
119 |
return orderCount;
|
|
|
120 |
}
|
|
|
121 |
|
|
|
122 |
public long getCompletedOrderCount() {
|
|
|
123 |
return completedOrderCount;
|
|
|
124 |
}
|
|
|
125 |
|
|
|
126 |
public long getOpenOrderCount() {
|
|
|
127 |
return openOrderCount;
|
|
|
128 |
}
|
|
|
129 |
|
|
|
130 |
public long getFailedOrderCount() {
|
|
|
131 |
return failedOrderCount;
|
|
|
132 |
}
|
|
|
133 |
|
|
|
134 |
public double getCartItems() {
|
|
|
135 |
return cartItems;
|
|
|
136 |
}
|
|
|
137 |
|
|
|
138 |
public String getLastLogin() {
|
|
|
139 |
return lastLogin;
|
|
|
140 |
}
|
|
|
141 |
}
|