| 7263 |
anupam.sin |
1 |
/**
|
|
|
2 |
*
|
|
|
3 |
*/
|
|
|
4 |
package in.shop2020.serving.controllers;
|
|
|
5 |
|
|
|
6 |
import java.text.SimpleDateFormat;
|
|
|
7 |
import java.util.Date;
|
|
|
8 |
import java.util.HashMap;
|
|
|
9 |
import java.util.Map;
|
|
|
10 |
import java.util.StringTokenizer;
|
|
|
11 |
|
|
|
12 |
import in.shop2020.datalogger.EventType;
|
|
|
13 |
import in.shop2020.logistics.LogisticsInfo;
|
|
|
14 |
import in.shop2020.logistics.LogisticsService.Client;
|
|
|
15 |
import in.shop2020.logistics.DeliveryType;
|
|
|
16 |
import in.shop2020.logistics.LogisticsServiceException;
|
|
|
17 |
import in.shop2020.model.v1.catalog.StorePricing;
|
|
|
18 |
import in.shop2020.thrift.clients.CatalogClient;
|
|
|
19 |
import in.shop2020.thrift.clients.LogisticsClient;
|
|
|
20 |
import in.shop2020.utils.DataLogger;
|
|
|
21 |
|
|
|
22 |
import org.apache.log4j.Logger;
|
|
|
23 |
import org.apache.struts2.rest.DefaultHttpHeaders;
|
|
|
24 |
import org.apache.struts2.rest.HttpHeaders;
|
|
|
25 |
import org.apache.thrift.TException;
|
|
|
26 |
|
|
|
27 |
import com.google.gson.Gson;
|
|
|
28 |
|
|
|
29 |
/**
|
|
|
30 |
* @author rajveer
|
|
|
31 |
*
|
|
|
32 |
*/
|
|
|
33 |
public class EstimateController extends BaseController {
|
|
|
34 |
|
|
|
35 |
private static final long serialVersionUID = 8023801600023970837L;
|
|
|
36 |
|
|
|
37 |
private static Logger log = Logger.getLogger(Class.class);
|
|
|
38 |
private String id;
|
|
|
39 |
private long itemId;
|
|
|
40 |
private long product_id;
|
|
|
41 |
private String pin;
|
|
|
42 |
private long date = -1;
|
|
|
43 |
private boolean isCODAvailable;
|
|
|
44 |
private boolean isOTGAvailable;
|
|
|
45 |
private double sellingPrice;
|
|
|
46 |
private double minAdvanceAmount;
|
|
|
47 |
private Map<String, String> response = new HashMap<String, String>();
|
|
|
48 |
|
|
|
49 |
public EstimateController() {
|
|
|
50 |
super();
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
// GET /logout
|
| 7268 |
anupam.sin |
54 |
public String create(){
|
| 7263 |
anupam.sin |
55 |
LogisticsClient logisticsServiceClient = null;
|
|
|
56 |
CatalogClient catalogServiceClient = null;
|
|
|
57 |
try {
|
|
|
58 |
logisticsServiceClient = new LogisticsClient();
|
|
|
59 |
Client logisticsClient = logisticsServiceClient.getClient();
|
|
|
60 |
LogisticsInfo logistincInfo = logisticsClient.getLogisticsEstimationForStore(itemId, pin, DeliveryType.COD);
|
|
|
61 |
date = logistincInfo.getDeliveryTime();
|
|
|
62 |
isCODAvailable = logistincInfo.isCodAllowed();
|
|
|
63 |
isOTGAvailable = logistincInfo.isOtgAvailable();
|
|
|
64 |
catalogServiceClient = new CatalogClient();
|
|
|
65 |
StorePricing sp = catalogServiceClient.getClient().getStorePricing(itemId);
|
|
|
66 |
sellingPrice = sp.getRecommendedPrice();
|
|
|
67 |
minAdvanceAmount = sp.getMinAdvancePrice();
|
|
|
68 |
|
| 7268 |
anupam.sin |
69 |
} catch (Exception e) {
|
| 7263 |
anupam.sin |
70 |
date = -1;
|
|
|
71 |
isCODAvailable = false;
|
|
|
72 |
log.error("Unable to get estimate/COD availability for " + itemId, e);
|
|
|
73 |
}
|
|
|
74 |
SimpleDateFormat dateformat = new SimpleDateFormat("dd/MM/yyyy");
|
|
|
75 |
|
|
|
76 |
response.put("delivery_estimate", dateformat.format(new Date(date)));
|
|
|
77 |
response.put("is_cod_available_for_location", Boolean.toString(isCODAvailable));
|
|
|
78 |
response.put("on_time_guarantee", Boolean.toString(isOTGAvailable));
|
|
|
79 |
response.put("selling_price", Double.toString(sellingPrice));
|
|
|
80 |
response.put("min_advance_amount", Double.toString(minAdvanceAmount));
|
|
|
81 |
|
|
|
82 |
|
| 7268 |
anupam.sin |
83 |
return "index";
|
| 7263 |
anupam.sin |
84 |
}
|
|
|
85 |
|
|
|
86 |
public String getResponseJSONString() {
|
|
|
87 |
Gson gson = new Gson();
|
|
|
88 |
return gson.toJson(response);
|
|
|
89 |
}
|
|
|
90 |
|
|
|
91 |
public void setProduct_id(long product_id) {
|
|
|
92 |
this.itemId = product_id;
|
|
|
93 |
}
|
|
|
94 |
|
|
|
95 |
public long getProduct_id() {
|
|
|
96 |
return product_id;
|
|
|
97 |
}
|
| 7268 |
anupam.sin |
98 |
|
|
|
99 |
public String getPin() {
|
|
|
100 |
return pin;
|
|
|
101 |
}
|
|
|
102 |
|
|
|
103 |
public void setPin(String pin) {
|
|
|
104 |
this.pin = pin;
|
|
|
105 |
}
|
| 7263 |
anupam.sin |
106 |
}
|