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