| Line 6... |
Line 6... |
| 6 |
import in.shop2020.model.v1.catalog.CatalogServiceException;
|
6 |
import in.shop2020.model.v1.catalog.CatalogServiceException;
|
| 7 |
import in.shop2020.model.v1.catalog.Item;
|
7 |
import in.shop2020.model.v1.catalog.Item;
|
| 8 |
import in.shop2020.model.v1.catalog.Source;
|
8 |
import in.shop2020.model.v1.catalog.Source;
|
| 9 |
import in.shop2020.model.v1.catalog.SourceItemPricing;
|
9 |
import in.shop2020.model.v1.catalog.SourceItemPricing;
|
| 10 |
import in.shop2020.model.v1.catalog.status;
|
10 |
import in.shop2020.model.v1.catalog.status;
|
| - |
|
11 |
import in.shop2020.model.v1.order.EmiScheme;
|
| 11 |
import in.shop2020.thrift.clients.CatalogClient;
|
12 |
import in.shop2020.thrift.clients.CatalogClient;
|
| - |
|
13 |
import in.shop2020.thrift.clients.TransactionClient;
|
| 12 |
import in.shop2020.util.Utils;
|
14 |
import in.shop2020.util.Utils;
|
| 13 |
|
15 |
|
| 14 |
import java.io.BufferedWriter;
|
16 |
import java.io.BufferedWriter;
|
| 15 |
import java.io.File;
|
17 |
import java.io.File;
|
| 16 |
import java.io.FileOutputStream;
|
18 |
import java.io.FileOutputStream;
|
| 17 |
import java.io.IOException;
|
19 |
import java.io.IOException;
|
| 18 |
import java.io.OutputStreamWriter;
|
20 |
import java.io.OutputStreamWriter;
|
| 19 |
import java.util.ArrayList;
|
21 |
import java.util.ArrayList;
|
| 20 |
import java.util.HashMap;
|
22 |
import java.util.HashMap;
|
| 21 |
import java.util.List;
|
23 |
import java.util.List;
|
| - |
|
24 |
import java.util.Locale;
|
| 22 |
import java.util.Map;
|
25 |
import java.util.Map;
|
| 23 |
import java.util.Properties;
|
26 |
import java.util.Properties;
|
| - |
|
27 |
import java.util.TreeMap;
|
| 24 |
|
28 |
|
| 25 |
import org.apache.commons.io.FileUtils;
|
29 |
import org.apache.commons.io.FileUtils;
|
| 26 |
import org.apache.thrift.TException;
|
30 |
import org.apache.thrift.TException;
|
| 27 |
import org.apache.thrift.transport.TTransportException;
|
31 |
import org.apache.thrift.transport.TTransportException;
|
| 28 |
import org.apache.velocity.Template;
|
32 |
import org.apache.velocity.Template;
|
| Line 38... |
Line 42... |
| 38 |
*
|
42 |
*
|
| 39 |
* @author rajveer
|
43 |
* @author rajveer
|
| 40 |
*
|
44 |
*
|
| 41 |
*/
|
45 |
*/
|
| 42 |
public class PriceInsertor {
|
46 |
public class PriceInsertor {
|
| - |
|
47 |
static Map<Long, EmiScheme> EMI_SCHEMES = new TreeMap<Long, EmiScheme>();
|
| - |
|
48 |
|
| - |
|
49 |
static {
|
| - |
|
50 |
try {
|
| - |
|
51 |
TransactionClient transactionClient = new TransactionClient();
|
| - |
|
52 |
in.shop2020.model.v1.order.TransactionService.Client trxClient = transactionClient.getClient();
|
| - |
|
53 |
List<EmiScheme> emiSchemes = trxClient.getAvailableEmiSchemes();
|
| - |
|
54 |
for (EmiScheme emiScheme : emiSchemes){
|
| - |
|
55 |
if(!EMI_SCHEMES.containsKey(emiScheme.getMinAmount())) {
|
| - |
|
56 |
EMI_SCHEMES.put(emiScheme.getMinAmount(), emiScheme);
|
| - |
|
57 |
} else {
|
| - |
|
58 |
EmiScheme emiSchemeOld = EMI_SCHEMES.get(emiScheme.getMinAmount());
|
| - |
|
59 |
if(Double.compare((1 + (emiSchemeOld.getChargeValue()/100))/emiSchemeOld.getTenure(), (1 + (emiScheme.getChargeValue()/100))/emiScheme.getTenure()) > 0){
|
| - |
|
60 |
EMI_SCHEMES.put(emiScheme.getMinAmount(), emiScheme);
|
| - |
|
61 |
}
|
| - |
|
62 |
}
|
| - |
|
63 |
}
|
| - |
|
64 |
} catch (Exception e) {
|
| - |
|
65 |
e.printStackTrace();
|
| - |
|
66 |
}
|
| - |
|
67 |
}
|
| 43 |
CatalogClient csc;
|
68 |
CatalogClient csc;
|
| 44 |
Client client;
|
69 |
Client client;
|
| 45 |
|
70 |
|
| 46 |
public PriceInsertor() throws TTransportException{
|
71 |
public PriceInsertor() throws TTransportException{
|
| 47 |
csc = new CatalogClient();
|
72 |
csc = new CatalogClient();
|
| Line 172... |
Line 197... |
| 172 |
context.put("OFFER_DETAIL_TEXT", offerDetailText);
|
197 |
context.put("OFFER_DETAIL_TEXT", offerDetailText);
|
| 173 |
context.put("OFFER_DETAIL_LINK", offerDetailLink);
|
198 |
context.put("OFFER_DETAIL_LINK", offerDetailLink);
|
| 174 |
context.put("AFTER_ARRIVAL", afterArrival);
|
199 |
context.put("AFTER_ARRIVAL", afterArrival);
|
| 175 |
context.put("SHOW_PRICE", domain.contains("store")?"FALSE":showPrice);
|
200 |
context.put("SHOW_PRICE", domain.contains("store")?"FALSE":showPrice);
|
| 176 |
context.put("IS_STORE", domain.contains("store")?"TRUE":"FALSE");
|
201 |
context.put("IS_STORE", domain.contains("store")?"TRUE":"FALSE");
|
| - |
|
202 |
context.put("EMI", getEMI(items.get(0).getSellingPrice()));
|
| 177 |
List<String> filenames = new ArrayList<String>();
|
203 |
List<String> filenames = new ArrayList<String>();
|
| 178 |
if(!domain.contains("store")){
|
204 |
if(!domain.contains("store")){
|
| 179 |
filenames.add("WidgetSnippet");
|
205 |
filenames.add("WidgetSnippet");
|
| 180 |
filenames.add("ProductPropertiesSnippet");
|
206 |
filenames.add("ProductPropertiesSnippet");
|
| 181 |
filenames.add("MyResearchSnippet");
|
207 |
filenames.add("MyResearchSnippet");
|
| Line 214... |
Line 240... |
| 214 |
}
|
240 |
}
|
| 215 |
getHtmlFromVelocity(filenames,exportPath,context,catalogId);
|
241 |
getHtmlFromVelocity(filenames,exportPath,context,catalogId);
|
| 216 |
return minPriceItem.getSellingPrice();
|
242 |
return minPriceItem.getSellingPrice();
|
| 217 |
}
|
243 |
}
|
| 218 |
|
244 |
|
| - |
|
245 |
private static String getEMI(double sellingPrice) {
|
| - |
|
246 |
String returnString = null;
|
| - |
|
247 |
EmiScheme finalEmi = null;
|
| - |
|
248 |
for (EmiScheme emiScheme : EMI_SCHEMES.values() ){
|
| - |
|
249 |
if(emiScheme.getMinAmount() <= sellingPrice) {
|
| - |
|
250 |
if(finalEmi == null){
|
| - |
|
251 |
finalEmi = emiScheme;
|
| - |
|
252 |
} else if(Double.compare((1 + (finalEmi.getChargeValue()/100))/finalEmi.getTenure(), (1 + (emiScheme.getChargeValue()/100))/emiScheme.getTenure()) > 0){
|
| - |
|
253 |
finalEmi = emiScheme;
|
| - |
|
254 |
}
|
| - |
|
255 |
}
|
| - |
|
256 |
}
|
| - |
|
257 |
if(finalEmi != null) {
|
| - |
|
258 |
returnString = String.format(Locale.getDefault(),"%.0f",sellingPrice * (1 + (finalEmi.getChargeValue()/100))/finalEmi.getTenure());
|
| - |
|
259 |
}
|
| - |
|
260 |
return returnString;
|
| - |
|
261 |
}
|
| - |
|
262 |
|
| 219 |
public void getHtmlFromVelocity(List<String> filenames, String exportPath, VelocityContext context, long catalogId){
|
263 |
public void getHtmlFromVelocity(List<String> filenames, String exportPath, VelocityContext context, long catalogId){
|
| 220 |
try {
|
264 |
try {
|
| 221 |
Properties p = new Properties();
|
265 |
Properties p = new Properties();
|
| 222 |
p.setProperty("resource.loader", "file");
|
266 |
p.setProperty("resource.loader", "file");
|
| 223 |
p.setProperty("file.resource.loader.class","org.apache.velocity.runtime.resource.loader.FileResourceLoader");
|
267 |
p.setProperty("file.resource.loader.class","org.apache.velocity.runtime.resource.loader.FileResourceLoader");
|