| 405 |
rajveer |
1 |
package in.shop2020.serving.controllers;
|
|
|
2 |
|
| 2191 |
varun.gupt |
3 |
import java.text.SimpleDateFormat;
|
|
|
4 |
import java.util.ArrayList;
|
| 3014 |
chandransh |
5 |
import java.util.Arrays;
|
| 2355 |
rajveer |
6 |
import java.util.Collections;
|
| 2191 |
varun.gupt |
7 |
import java.util.Date;
|
|
|
8 |
import java.util.HashMap;
|
|
|
9 |
import java.util.List;
|
|
|
10 |
import java.util.Map;
|
|
|
11 |
|
|
|
12 |
import in.shop2020.logistics.Provider;
|
|
|
13 |
import in.shop2020.model.v1.order.Order;
|
| 3014 |
chandransh |
14 |
import in.shop2020.model.v1.order.OrderStatus;
|
| 4837 |
varun.gupt |
15 |
import in.shop2020.model.v1.order.OrderStatusGroups;
|
| 2191 |
varun.gupt |
16 |
import in.shop2020.serving.utils.FormattingUtils;
|
| 3126 |
rajveer |
17 |
import in.shop2020.thrift.clients.LogisticsClient;
|
|
|
18 |
import in.shop2020.thrift.clients.TransactionClient;
|
| 2191 |
varun.gupt |
19 |
|
| 832 |
rajveer |
20 |
import org.apache.log4j.Logger;
|
| 781 |
vikas |
21 |
import org.apache.struts2.convention.annotation.InterceptorRef;
|
|
|
22 |
import org.apache.struts2.convention.annotation.InterceptorRefs;
|
| 413 |
rajveer |
23 |
import org.apache.struts2.convention.annotation.Result;
|
|
|
24 |
import org.apache.struts2.convention.annotation.Results;
|
| 405 |
rajveer |
25 |
|
|
|
26 |
/**
|
| 413 |
rajveer |
27 |
* @author rajveer
|
| 405 |
rajveer |
28 |
*
|
|
|
29 |
*/
|
| 413 |
rajveer |
30 |
|
| 3014 |
chandransh |
31 |
@SuppressWarnings("serial")
|
| 781 |
vikas |
32 |
@InterceptorRefs({
|
| 822 |
vikas |
33 |
@InterceptorRef("myDefault"),
|
|
|
34 |
@InterceptorRef("login")
|
| 781 |
vikas |
35 |
})
|
|
|
36 |
|
| 637 |
rajveer |
37 |
@Results({
|
|
|
38 |
@Result(name="redirect", type="redirectAction",
|
|
|
39 |
params = {"actionName" , "login"})
|
|
|
40 |
})
|
| 650 |
rajveer |
41 |
public class MyaccountController extends BaseController {
|
| 405 |
rajveer |
42 |
|
| 2897 |
chandransh |
43 |
private static Logger logger = Logger.getLogger(Class.class);
|
| 4837 |
varun.gupt |
44 |
|
| 2191 |
varun.gupt |
45 |
private FormattingUtils formattingUtils = new FormattingUtils();
|
| 4837 |
varun.gupt |
46 |
|
| 2191 |
varun.gupt |
47 |
Map<Long, String> providerNames = new HashMap<Long, String>();
|
|
|
48 |
List<Order> orders = null;
|
|
|
49 |
List<String> orderDate = new ArrayList<String>();
|
| 405 |
rajveer |
50 |
|
|
|
51 |
public MyaccountController() {
|
|
|
52 |
super();
|
|
|
53 |
}
|
| 650 |
rajveer |
54 |
|
|
|
55 |
public String index(){
|
| 2897 |
chandransh |
56 |
logger.info("this.request=" + this.request);
|
| 4837 |
varun.gupt |
57 |
|
| 2191 |
varun.gupt |
58 |
try {
|
| 4837 |
varun.gupt |
59 |
OrderStatusGroups statusGroup = new OrderStatusGroups();
|
|
|
60 |
List<OrderStatus> openOrderStatuses = statusGroup.getOpenOrders();
|
| 3126 |
rajveer |
61 |
TransactionClient transactionServiceClient = new TransactionClient();
|
| 2191 |
varun.gupt |
62 |
in.shop2020.model.v1.order.TransactionService.Client orderClient = transactionServiceClient.getClient();
|
| 4837 |
varun.gupt |
63 |
orders = orderClient.getOrdersForCustomer(userinfo.getUserId(), 0, (new Date()).getTime(), openOrderStatuses);
|
| 2355 |
rajveer |
64 |
//Reverse the list of order. Last come first displayed
|
|
|
65 |
Collections.reverse(orders);
|
| 3126 |
rajveer |
66 |
LogisticsClient logisticsServiceClient = new LogisticsClient();
|
| 2191 |
varun.gupt |
67 |
in.shop2020.logistics.LogisticsService.Client logisticsClient = logisticsServiceClient.getClient();
|
|
|
68 |
List<Provider> providers = logisticsClient.getAllProviders();
|
|
|
69 |
|
|
|
70 |
for(Provider provider: providers)
|
|
|
71 |
providerNames.put(provider.getId(), provider.getName());
|
|
|
72 |
|
|
|
73 |
} catch (Exception e) {
|
| 2897 |
chandransh |
74 |
logger.error("Error while getting the orders for the user", e);
|
| 2191 |
varun.gupt |
75 |
}
|
|
|
76 |
SimpleDateFormat dateformat = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss aa");
|
|
|
77 |
|
|
|
78 |
if(orders != null && !orders.isEmpty()){
|
|
|
79 |
for(Order order: orders) {
|
|
|
80 |
Date orderedOn = new Date(order.getCreated_timestamp());
|
|
|
81 |
orderDate.add(dateformat.format(orderedOn));
|
|
|
82 |
}
|
|
|
83 |
}
|
| 650 |
rajveer |
84 |
return "index";
|
| 405 |
rajveer |
85 |
}
|
|
|
86 |
|
| 2191 |
varun.gupt |
87 |
public String formatPrice(double price) {
|
|
|
88 |
return formattingUtils.formatPrice(price);
|
|
|
89 |
}
|
| 507 |
rajveer |
90 |
|
| 2191 |
varun.gupt |
91 |
public Map<Long, String> getProviderNames() {
|
|
|
92 |
return providerNames;
|
|
|
93 |
}
|
|
|
94 |
|
|
|
95 |
public List<Order> getOrders() {
|
|
|
96 |
return orders;
|
|
|
97 |
}
|
|
|
98 |
|
|
|
99 |
public List<String> getOrderDate() {
|
|
|
100 |
return orderDate;
|
|
|
101 |
}
|
|
|
102 |
}
|