| 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 |
|
| 4983 |
phani.kuma |
51 |
private static final OrderStatusGroups statusGroup = new OrderStatusGroups();
|
|
|
52 |
private static final List<OrderStatus> openOrderStatuses = statusGroup.getOpenOrders();
|
|
|
53 |
private static final List<OrderStatus> shippedOrderStatuses = statusGroup.getShippedOrders();
|
|
|
54 |
|
| 405 |
rajveer |
55 |
public MyaccountController() {
|
|
|
56 |
super();
|
|
|
57 |
}
|
| 650 |
rajveer |
58 |
|
|
|
59 |
public String index(){
|
| 2897 |
chandransh |
60 |
logger.info("this.request=" + this.request);
|
| 4837 |
varun.gupt |
61 |
|
| 2191 |
varun.gupt |
62 |
try {
|
| 3126 |
rajveer |
63 |
TransactionClient transactionServiceClient = new TransactionClient();
|
| 2191 |
varun.gupt |
64 |
in.shop2020.model.v1.order.TransactionService.Client orderClient = transactionServiceClient.getClient();
|
| 4837 |
varun.gupt |
65 |
orders = orderClient.getOrdersForCustomer(userinfo.getUserId(), 0, (new Date()).getTime(), openOrderStatuses);
|
| 2355 |
rajveer |
66 |
//Reverse the list of order. Last come first displayed
|
|
|
67 |
Collections.reverse(orders);
|
| 3126 |
rajveer |
68 |
LogisticsClient logisticsServiceClient = new LogisticsClient();
|
| 2191 |
varun.gupt |
69 |
in.shop2020.logistics.LogisticsService.Client logisticsClient = logisticsServiceClient.getClient();
|
|
|
70 |
List<Provider> providers = logisticsClient.getAllProviders();
|
|
|
71 |
|
|
|
72 |
for(Provider provider: providers)
|
|
|
73 |
providerNames.put(provider.getId(), provider.getName());
|
|
|
74 |
|
|
|
75 |
} catch (Exception e) {
|
| 2897 |
chandransh |
76 |
logger.error("Error while getting the orders for the user", e);
|
| 2191 |
varun.gupt |
77 |
}
|
|
|
78 |
SimpleDateFormat dateformat = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss aa");
|
|
|
79 |
|
|
|
80 |
if(orders != null && !orders.isEmpty()){
|
|
|
81 |
for(Order order: orders) {
|
|
|
82 |
Date orderedOn = new Date(order.getCreated_timestamp());
|
|
|
83 |
orderDate.add(dateformat.format(orderedOn));
|
|
|
84 |
}
|
|
|
85 |
}
|
| 650 |
rajveer |
86 |
return "index";
|
| 405 |
rajveer |
87 |
}
|
|
|
88 |
|
| 2191 |
varun.gupt |
89 |
public String formatPrice(double price) {
|
|
|
90 |
return formattingUtils.formatPrice(price);
|
|
|
91 |
}
|
| 507 |
rajveer |
92 |
|
| 2191 |
varun.gupt |
93 |
public Map<Long, String> getProviderNames() {
|
|
|
94 |
return providerNames;
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
public List<Order> getOrders() {
|
|
|
98 |
return orders;
|
|
|
99 |
}
|
|
|
100 |
|
|
|
101 |
public List<String> getOrderDate() {
|
|
|
102 |
return orderDate;
|
|
|
103 |
}
|
| 4983 |
phani.kuma |
104 |
|
|
|
105 |
public boolean showAwbforOrder(OrderStatus status) {
|
|
|
106 |
if(shippedOrderStatuses.contains(status)){
|
|
|
107 |
return true;
|
|
|
108 |
}
|
|
|
109 |
return false;
|
|
|
110 |
}
|
| 2191 |
varun.gupt |
111 |
}
|