| 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;
|
|
|
10 |
import in.shop2020.thrift.clients.LogisticsServiceClient;
|
|
|
11 |
import in.shop2020.thrift.clients.TransactionServiceClient;
|
|
|
12 |
|
| 507 |
rajveer |
13 |
import java.io.UnsupportedEncodingException;
|
| 2224 |
varun.gupt |
14 |
import java.text.SimpleDateFormat;
|
|
|
15 |
import java.util.ArrayList;
|
|
|
16 |
import java.util.Date;
|
|
|
17 |
import java.util.HashMap;
|
|
|
18 |
import java.util.List;
|
|
|
19 |
import java.util.Map;
|
| 507 |
rajveer |
20 |
|
| 832 |
rajveer |
21 |
import org.apache.log4j.Logger;
|
| 822 |
vikas |
22 |
import org.apache.struts2.convention.annotation.InterceptorRef;
|
|
|
23 |
import org.apache.struts2.convention.annotation.InterceptorRefs;
|
| 507 |
rajveer |
24 |
import org.apache.struts2.convention.annotation.Result;
|
|
|
25 |
import org.apache.struts2.convention.annotation.Results;
|
|
|
26 |
|
|
|
27 |
/**
|
|
|
28 |
* @author rajveer
|
|
|
29 |
*
|
|
|
30 |
*/
|
|
|
31 |
|
| 822 |
vikas |
32 |
@InterceptorRefs({
|
|
|
33 |
@InterceptorRef("myDefault"),
|
|
|
34 |
@InterceptorRef("login")
|
|
|
35 |
})
|
|
|
36 |
|
| 650 |
rajveer |
37 |
@Results({
|
|
|
38 |
@Result(name="redirect", type="redirectAction",
|
|
|
39 |
params = {"actionName" , "login"})
|
|
|
40 |
})
|
|
|
41 |
public class CompletedOrdersController extends BaseController {
|
| 507 |
rajveer |
42 |
|
| 650 |
rajveer |
43 |
private static final long serialVersionUID = 1L;
|
| 2224 |
varun.gupt |
44 |
private static Logger log = Logger.getLogger(Class.class);
|
|
|
45 |
private FormattingUtils formattingUtils = new FormattingUtils();
|
|
|
46 |
|
|
|
47 |
private List<Order> orders = null;
|
|
|
48 |
private List<String> orderDate = new ArrayList<String>();
|
|
|
49 |
private Map<Long, String> providerNames = new HashMap<Long, String>();
|
| 507 |
rajveer |
50 |
|
| 650 |
rajveer |
51 |
public CompletedOrdersController() {
|
| 507 |
rajveer |
52 |
super();
|
|
|
53 |
}
|
|
|
54 |
|
| 650 |
rajveer |
55 |
// GET /completed-orders
|
|
|
56 |
public String index() throws UnsupportedEncodingException {
|
|
|
57 |
log.info("this.request=" + this.request);
|
| 507 |
rajveer |
58 |
|
| 2224 |
varun.gupt |
59 |
TransactionServiceClient transactionServiceClient = null;
|
|
|
60 |
in.shop2020.model.v1.order.TransactionService.Client orderClient = null;
|
|
|
61 |
|
|
|
62 |
try{
|
|
|
63 |
transactionServiceClient = new TransactionServiceClient();
|
|
|
64 |
orderClient = transactionServiceClient.getClient();
|
|
|
65 |
orders = orderClient.getOrdersForCustomer(userinfo.getUserId(), 0, (new Date()).getTime(), OrderStatus.DELIVERY_SUCCESS);
|
|
|
66 |
|
|
|
67 |
LogisticsServiceClient logisticsServiceClient = new LogisticsServiceClient();
|
|
|
68 |
in.shop2020.logistics.LogisticsService.Client logisticsClient = logisticsServiceClient.getClient();
|
|
|
69 |
List<Provider> providers = logisticsClient.getAllProviders();
|
|
|
70 |
for(Provider provider: providers)
|
|
|
71 |
providerNames.put(provider.getId(), provider.getName());
|
|
|
72 |
|
|
|
73 |
SimpleDateFormat dateformat = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss aa");
|
|
|
74 |
|
|
|
75 |
if(orders != null && !orders.isEmpty()){
|
|
|
76 |
for(Order order: orders){
|
|
|
77 |
Date orderedOn = new Date(order.getCreated_timestamp());
|
|
|
78 |
orderDate.add(dateformat.format(orderedOn));
|
|
|
79 |
}
|
|
|
80 |
}
|
|
|
81 |
} catch (Exception e) {
|
|
|
82 |
|
|
|
83 |
}
|
| 650 |
rajveer |
84 |
return "index";
|
| 507 |
rajveer |
85 |
}
|
|
|
86 |
|
| 2224 |
varun.gupt |
87 |
public List<Order> getOrders() {
|
|
|
88 |
return this.orders;
|
| 507 |
rajveer |
89 |
}
|
|
|
90 |
|
| 2224 |
varun.gupt |
91 |
public List<String> getOrderDate() {
|
|
|
92 |
return this.orderDate;
|
| 507 |
rajveer |
93 |
}
|
| 2224 |
varun.gupt |
94 |
|
|
|
95 |
public Map<Long, String> getProviderNames() {
|
|
|
96 |
return this.providerNames;
|
|
|
97 |
}
|
| 620 |
rajveer |
98 |
|
| 2224 |
varun.gupt |
99 |
public String formatPrice(double price) {
|
|
|
100 |
return formattingUtils.formatPrice(price);
|
|
|
101 |
}
|
|
|
102 |
}
|