| 507 |
rajveer |
1 |
/**
|
|
|
2 |
*
|
|
|
3 |
*/
|
|
|
4 |
package in.shop2020.serving.controllers;
|
|
|
5 |
|
| 2224 |
varun.gupt |
6 |
import in.shop2020.logistics.Provider;
|
|
|
7 |
import in.shop2020.model.v1.order.Order;
|
|
|
8 |
import in.shop2020.model.v1.order.OrderStatus;
|
|
|
9 |
import in.shop2020.serving.utils.FormattingUtils;
|
| 3126 |
rajveer |
10 |
import in.shop2020.thrift.clients.LogisticsClient;
|
|
|
11 |
import in.shop2020.thrift.clients.TransactionClient;
|
| 2224 |
varun.gupt |
12 |
|
| 507 |
rajveer |
13 |
import java.io.UnsupportedEncodingException;
|
| 2224 |
varun.gupt |
14 |
import java.text.SimpleDateFormat;
|
|
|
15 |
import java.util.ArrayList;
|
| 3014 |
chandransh |
16 |
import java.util.Arrays;
|
| 2355 |
rajveer |
17 |
import java.util.Collections;
|
| 2224 |
varun.gupt |
18 |
import java.util.Date;
|
|
|
19 |
import java.util.HashMap;
|
|
|
20 |
import java.util.List;
|
|
|
21 |
import java.util.Map;
|
| 507 |
rajveer |
22 |
|
| 832 |
rajveer |
23 |
import org.apache.log4j.Logger;
|
| 822 |
vikas |
24 |
import org.apache.struts2.convention.annotation.InterceptorRef;
|
|
|
25 |
import org.apache.struts2.convention.annotation.InterceptorRefs;
|
| 507 |
rajveer |
26 |
import org.apache.struts2.convention.annotation.Result;
|
|
|
27 |
import org.apache.struts2.convention.annotation.Results;
|
|
|
28 |
|
|
|
29 |
/**
|
|
|
30 |
* @author rajveer
|
|
|
31 |
*
|
|
|
32 |
*/
|
|
|
33 |
|
| 3014 |
chandransh |
34 |
@SuppressWarnings("serial")
|
| 822 |
vikas |
35 |
@InterceptorRefs({
|
|
|
36 |
@InterceptorRef("myDefault"),
|
|
|
37 |
@InterceptorRef("login")
|
|
|
38 |
})
|
|
|
39 |
|
| 650 |
rajveer |
40 |
@Results({
|
|
|
41 |
@Result(name="redirect", type="redirectAction",
|
|
|
42 |
params = {"actionName" , "login"})
|
|
|
43 |
})
|
|
|
44 |
public class CompletedOrdersController extends BaseController {
|
| 507 |
rajveer |
45 |
|
| 2224 |
varun.gupt |
46 |
private static Logger log = Logger.getLogger(Class.class);
|
| 3014 |
chandransh |
47 |
private static final List<OrderStatus> statuses = Arrays.asList(new OrderStatus[] {OrderStatus.DELIVERY_SUCCESS});
|
|
|
48 |
|
| 2224 |
varun.gupt |
49 |
private FormattingUtils formattingUtils = new FormattingUtils();
|
|
|
50 |
private List<Order> orders = null;
|
|
|
51 |
private List<String> orderDate = new ArrayList<String>();
|
|
|
52 |
private Map<Long, String> providerNames = new HashMap<Long, String>();
|
| 507 |
rajveer |
53 |
|
| 650 |
rajveer |
54 |
public CompletedOrdersController() {
|
| 507 |
rajveer |
55 |
super();
|
|
|
56 |
}
|
|
|
57 |
|
| 650 |
rajveer |
58 |
// GET /completed-orders
|
|
|
59 |
public String index() throws UnsupportedEncodingException {
|
|
|
60 |
log.info("this.request=" + this.request);
|
| 507 |
rajveer |
61 |
|
| 3126 |
rajveer |
62 |
TransactionClient transactionServiceClient = null;
|
| 2224 |
varun.gupt |
63 |
in.shop2020.model.v1.order.TransactionService.Client orderClient = null;
|
|
|
64 |
|
|
|
65 |
try{
|
| 3126 |
rajveer |
66 |
transactionServiceClient = new TransactionClient();
|
| 2224 |
varun.gupt |
67 |
orderClient = transactionServiceClient.getClient();
|
| 3014 |
chandransh |
68 |
orders = orderClient.getOrdersForCustomer(userinfo.getUserId(), 0, (new Date()).getTime(), statuses);
|
| 2355 |
rajveer |
69 |
Collections.reverse(orders);
|
| 3126 |
rajveer |
70 |
LogisticsClient logisticsServiceClient = new LogisticsClient();
|
| 2224 |
varun.gupt |
71 |
in.shop2020.logistics.LogisticsService.Client logisticsClient = logisticsServiceClient.getClient();
|
|
|
72 |
List<Provider> providers = logisticsClient.getAllProviders();
|
|
|
73 |
for(Provider provider: providers)
|
|
|
74 |
providerNames.put(provider.getId(), provider.getName());
|
|
|
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 |
}
|
|
|
84 |
} catch (Exception e) {
|
|
|
85 |
|
|
|
86 |
}
|
| 650 |
rajveer |
87 |
return "index";
|
| 507 |
rajveer |
88 |
}
|
|
|
89 |
|
| 2224 |
varun.gupt |
90 |
public List<Order> getOrders() {
|
|
|
91 |
return this.orders;
|
| 507 |
rajveer |
92 |
}
|
|
|
93 |
|
| 2224 |
varun.gupt |
94 |
public List<String> getOrderDate() {
|
|
|
95 |
return this.orderDate;
|
| 507 |
rajveer |
96 |
}
|
| 2224 |
varun.gupt |
97 |
|
|
|
98 |
public Map<Long, String> getProviderNames() {
|
|
|
99 |
return this.providerNames;
|
|
|
100 |
}
|
| 620 |
rajveer |
101 |
|
| 2224 |
varun.gupt |
102 |
public String formatPrice(double price) {
|
|
|
103 |
return formattingUtils.formatPrice(price);
|
|
|
104 |
}
|
|
|
105 |
}
|