| 11904 |
kshitij.so |
1 |
package in.shop2020.support.controllers;
|
|
|
2 |
|
| 12243 |
kshitij.so |
3 |
import java.text.DecimalFormat;
|
| 11904 |
kshitij.so |
4 |
import java.util.List;
|
|
|
5 |
|
|
|
6 |
import in.shop2020.model.v1.catalog.CatalogService.Client;
|
|
|
7 |
import in.shop2020.model.v1.catalog.PdPriceComp;
|
|
|
8 |
import in.shop2020.thrift.clients.CatalogClient;
|
|
|
9 |
|
|
|
10 |
import javax.servlet.ServletContext;
|
|
|
11 |
import javax.servlet.http.HttpServletRequest;
|
|
|
12 |
import javax.servlet.http.HttpServletResponse;
|
|
|
13 |
import javax.servlet.http.HttpSession;
|
|
|
14 |
|
|
|
15 |
import org.apache.struts2.interceptor.ServletRequestAware;
|
|
|
16 |
import org.apache.struts2.interceptor.ServletResponseAware;
|
|
|
17 |
import org.apache.struts2.util.ServletContextAware;
|
|
|
18 |
import org.apache.thrift.TException;
|
|
|
19 |
import org.apache.thrift.transport.TTransportException;
|
|
|
20 |
|
|
|
21 |
import com.opensymphony.xwork2.ValidationAwareSupport;
|
|
|
22 |
|
|
|
23 |
public class PrivateDealsComparisonController extends ValidationAwareSupport implements ServletRequestAware ,ServletResponseAware, ServletContextAware{
|
|
|
24 |
|
|
|
25 |
/**
|
|
|
26 |
*
|
|
|
27 |
*/
|
|
|
28 |
private static final long serialVersionUID = 4278491749496095875L;
|
|
|
29 |
|
|
|
30 |
private HttpServletRequest request;
|
|
|
31 |
private HttpSession session;
|
|
|
32 |
private ServletContext context;
|
|
|
33 |
private HttpServletResponse response;
|
|
|
34 |
private List<PdPriceComp> pdData;
|
| 12169 |
kshitij.so |
35 |
private String lastProcessedTimestamp;
|
| 11904 |
kshitij.so |
36 |
|
|
|
37 |
|
|
|
38 |
public String index() throws TException{
|
|
|
39 |
return "index";
|
|
|
40 |
}
|
|
|
41 |
|
|
|
42 |
public String getCompData() throws TException{
|
| 11909 |
kshitij.so |
43 |
Client catalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
|
| 11904 |
kshitij.so |
44 |
setPdData(catalogClient.getAllPrivateDealsComparison());
|
| 12243 |
kshitij.so |
45 |
for (PdPriceComp data : pdData){
|
|
|
46 |
if (data.getSdPrice()==0 && data.getFkPrice()==0 && data.getAmazonPrice()==0){
|
|
|
47 |
data.setDiff(roundDecimals(data.getDealPrice()-0.0));
|
|
|
48 |
continue;
|
|
|
49 |
}
|
|
|
50 |
if (data.getSdPrice()==0.0){
|
|
|
51 |
data.setSdPrice(999999);
|
|
|
52 |
}
|
|
|
53 |
if (data.getFkPrice()==0.0){
|
|
|
54 |
data.setFkPrice(999999);
|
|
|
55 |
}
|
|
|
56 |
if (data.getAmazonPrice()==0.0){
|
|
|
57 |
data.setAmazonPrice(999999);
|
|
|
58 |
}
|
|
|
59 |
double cheapest = (data.getSdPrice()<data.getFkPrice())?((data.getSdPrice()<data.getAmazonPrice())?data.getSdPrice():data.getAmazonPrice()):((data.getFkPrice()<data.getAmazonPrice())?data.getFkPrice():data.getAmazonPrice());
|
|
|
60 |
data.setDiff(roundDecimals(data.getDealPrice()-cheapest));
|
|
|
61 |
if (data.getSdPrice()==999999){
|
|
|
62 |
data.setSdPrice(0.0);
|
|
|
63 |
}
|
|
|
64 |
if (data.getFkPrice()==999999){
|
|
|
65 |
data.setFkPrice(0.0);
|
|
|
66 |
}
|
|
|
67 |
if (data.getAmazonPrice()==999999){
|
|
|
68 |
data.setAmazonPrice(0.0);
|
|
|
69 |
}
|
|
|
70 |
}
|
| 12169 |
kshitij.so |
71 |
setLastProcessedTimestamp(new java.util.Date(pdData.get(0).getLastProcessedTimestamp()).toLocaleString());
|
| 11904 |
kshitij.so |
72 |
return "private-deals-comp-data";
|
|
|
73 |
}
|
|
|
74 |
|
| 12243 |
kshitij.so |
75 |
double roundDecimals(double d) {
|
|
|
76 |
DecimalFormat twoPlaces = new DecimalFormat("#.#");
|
|
|
77 |
return Double.valueOf(twoPlaces.format(d));
|
|
|
78 |
}
|
| 11904 |
kshitij.so |
79 |
|
|
|
80 |
public void setRequest(HttpServletRequest request) {
|
|
|
81 |
this.request = request;
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
public HttpServletRequest getRequest() {
|
|
|
85 |
return request;
|
|
|
86 |
}
|
|
|
87 |
|
|
|
88 |
public void setSession(HttpSession session) {
|
|
|
89 |
this.session = session;
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
public HttpSession getSession() {
|
|
|
93 |
return session;
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
public void setContext(ServletContext context) {
|
|
|
97 |
this.context = context;
|
|
|
98 |
}
|
|
|
99 |
|
|
|
100 |
public ServletContext getContext() {
|
|
|
101 |
return context;
|
|
|
102 |
}
|
|
|
103 |
|
|
|
104 |
public void setResponse(HttpServletResponse response) {
|
|
|
105 |
this.response = response;
|
|
|
106 |
}
|
|
|
107 |
|
|
|
108 |
public HttpServletResponse getResponse() {
|
|
|
109 |
return response;
|
|
|
110 |
}
|
|
|
111 |
|
|
|
112 |
@Override
|
|
|
113 |
public void setServletContext(ServletContext arg0) {
|
|
|
114 |
// TODO Auto-generated method stub
|
|
|
115 |
|
|
|
116 |
}
|
|
|
117 |
|
|
|
118 |
@Override
|
|
|
119 |
public void setServletResponse(HttpServletResponse arg0) {
|
|
|
120 |
// TODO Auto-generated method stub
|
|
|
121 |
|
|
|
122 |
}
|
|
|
123 |
|
|
|
124 |
@Override
|
|
|
125 |
public void setServletRequest(HttpServletRequest arg0) {
|
|
|
126 |
// TODO Auto-generated method stub
|
|
|
127 |
|
|
|
128 |
}
|
|
|
129 |
|
|
|
130 |
public void setPdData(List<PdPriceComp> pdData) {
|
|
|
131 |
this.pdData = pdData;
|
|
|
132 |
}
|
|
|
133 |
|
|
|
134 |
public List<PdPriceComp> getPdData() {
|
|
|
135 |
return pdData;
|
|
|
136 |
}
|
| 12169 |
kshitij.so |
137 |
|
|
|
138 |
public String getLastProcessedTimestamp() {
|
|
|
139 |
return lastProcessedTimestamp;
|
|
|
140 |
}
|
|
|
141 |
|
|
|
142 |
public void setLastProcessedTimestamp(String lastProcessedTimestamp) {
|
|
|
143 |
this.lastProcessedTimestamp = lastProcessedTimestamp;
|
|
|
144 |
}
|
| 11904 |
kshitij.so |
145 |
|
|
|
146 |
}
|