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