Subversion Repositories SmartDukaan

Rev

Rev 3996 | Rev 4146 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3996 Rev 4142
Line 1... Line 1...
1
package in.shop2020.serving.controllers;
1
package in.shop2020.serving.controllers;
2
 
2
 
-
 
3
import in.shop2020.model.v1.order.LineItem;
3
import in.shop2020.model.v1.order.Order;
4
import in.shop2020.model.v1.order.Order;
4
import in.shop2020.model.v1.order.OrderStatus;
5
import in.shop2020.model.v1.order.OrderStatus;
5
import in.shop2020.thrift.clients.TransactionClient;
6
import in.shop2020.thrift.clients.TransactionClient;
6
import in.shop2020.util.CRMConstants;
7
import in.shop2020.utils.ModelUtils;
7
 
8
 
8
import java.text.SimpleDateFormat;
-
 
9
import java.util.ArrayList;
-
 
10
import java.util.Date;
9
import java.util.Date;
11
import java.util.HashMap;
-
 
12
import java.util.List;
10
import java.util.List;
13
import java.util.Map;
-
 
14
import java.util.TimeZone;
-
 
15
 
11
 
16
import org.apache.log4j.Logger;
12
import org.apache.log4j.Logger;
17
 
13
 
18
/**
14
/**
19
 * @author vikas
15
 * @author vikas
Line 23... Line 19...
23
public class UserOrdersController extends BaseController {
19
public class UserOrdersController extends BaseController {
24
    private static Logger log = Logger.getLogger(Class.class);
20
    private static Logger log = Logger.getLogger(Class.class);
25
    private long userId;
21
    private long userId;
26
    private String id;
22
    private String id;
27
    private String status;
23
    private String status;
28
    private List<Map<String, String>> userOrders;
24
    private List<Order> orders;
29
 
-
 
30
    public UserOrdersController(){
-
 
31
        super();
-
 
32
    }
-
 
33
 
25
 
34
    public String index() throws Exception {
26
    public String index() throws Exception {
35
        TransactionClient transactionServiceClient = new TransactionClient();
27
        TransactionClient transactionServiceClient = new TransactionClient();
-
 
28
        orders = transactionServiceClient.getClient().getOrdersForCustomer(userId, 0, (new Date().getTime()), null);
-
 
29
        return INDEX;
-
 
30
    }
36
 
31
 
37
        List<Order> orders = transactionServiceClient.getClient().getOrdersForCustomer(userId, 0, (new Date().getTime()), null);
-
 
38
        userOrders = new ArrayList<Map<String,String>>();
32
    public String getProductName(LineItem lineItem) {
39
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-
 
40
        sdf.setTimeZone(TimeZone.getTimeZone("IST"));
33
        String name = ModelUtils.extractProductNameFromLineItem(lineItem);
41
        
34
 
42
        for (Order order : orders) {
-
 
43
            Map<String, String> orderMap = new HashMap<String, String>();
-
 
44
            orderMap.put("id", Long.toString(order.getId()));
-
 
45
            orderMap.put("created", sdf.format(new Date(order.getCreated_timestamp())));
-
 
46
            
-
 
47
            if (order.getStatus() == OrderStatus.DELIVERY_SUCCESS) {
-
 
48
                orderMap.put("status", "Completed");
-
 
49
            }
-
 
50
            else if (CRMConstants.failedStatusList.contains(order.getStatus())) {
-
 
51
                orderMap.put("status", "Failed");
-
 
52
            }
-
 
53
            else {
-
 
54
                orderMap.put("status", order.getStatus().getDescription());
-
 
55
            }
-
 
56
            
-
 
57
            StringBuilder address = new StringBuilder();
-
 
58
            if (order.getCustomer_address1() != null) {
-
 
59
                address.append(order.getCustomer_address1() + ", ");
-
 
60
            }
-
 
61
            if (order.getCustomer_address2() != null) {
-
 
62
                address.append(order.getCustomer_address2() + ", ");
-
 
63
            }
-
 
64
            if (order.getCustomer_city() != null) {
35
        if (lineItem.getColor() != null) {
65
                address.append(order.getCustomer_city() + ", ");
-
 
66
            }
-
 
67
            if (order.getCustomer_state() != null) {
-
 
68
                address.append(order.getCustomer_state() + "-");
36
            name += "(" + lineItem.getColor() + ")";
69
            }
-
 
70
            if (order.getCustomer_pincode() != null) {
-
 
71
                address.append(order.getCustomer_pincode());
-
 
72
            }
-
 
73
            orderMap.put("shipping", address.toString());
-
 
74
            orderMap.put("city", order.getCustomer_city());
-
 
75
            orderMap.put("mobileNumber", order.getCustomer_mobilenumber());
-
 
76
            orderMap.put("amount", Double.toString(order.getTotal_amount()));
-
 
77
            userOrders.add(orderMap);
-
 
78
        }
37
        }
-
 
38
 
79
        return "index";
39
        return name;
-
 
40
    }
-
 
41
 
-
 
42
    public String getOrderStatus(Order order) {
-
 
43
        String status = order.getStatus().getDescription();
-
 
44
 
-
 
45
        if (order.getStatus() == OrderStatus.DELIVERY_SUCCESS) {
-
 
46
            status = "Completed";
-
 
47
        }
-
 
48
 
-
 
49
        return status;
80
    }
50
    }
81
 
51
 
82
    public void setUserId(String userId) {
52
    public void setUserId(String userId) {
83
        try {
53
        try {
84
            this.userId = Long.parseLong(userId);
54
            this.userId = Long.parseLong(userId);
Line 90... Line 60...
90
 
60
 
91
    public Long getUserId() {
61
    public Long getUserId() {
92
        return userId;
62
        return userId;
93
    }
63
    }
94
 
64
 
95
    public List<Map<String, String>> getUserOrders() {
-
 
96
        return userOrders;
-
 
97
    }
-
 
98
 
-
 
99
    public String getStatus() {
65
    public String getStatus() {
100
        return status;
66
        return status;
101
    }
67
    }
102
 
68
 
103
    public void setStatus(String status) {
69
    public void setStatus(String status) {
Line 109... Line 75...
109
    }
75
    }
110
 
76
 
111
    public void setId(String id) {
77
    public void setId(String id) {
112
        this.id = id;
78
        this.id = id;
113
    }
79
    }
-
 
80
 
-
 
81
    public List<Order> getOrders() {
-
 
82
        return orders;
-
 
83
    }
-
 
84
 
-
 
85
    public void setOrders(List<Order> orders) {
-
 
86
        this.orders = orders;
-
 
87
    }
114
}
88
}
115
89