| Line 42... |
Line 42... |
| 42 |
*
|
42 |
*
|
| 43 |
* @author rajveer
|
43 |
* @author rajveer
|
| 44 |
*
|
44 |
*
|
| 45 |
*/
|
45 |
*/
|
| 46 |
public class PriceInsertor {
|
46 |
public class PriceInsertor {
|
| 47 |
static Map<Long, EmiScheme> EMI_SCHEMES = new TreeMap<Long, EmiScheme>();
|
47 |
static Map<Long, EmiScheme> EMI_SCHEMES = new TreeMap<Long, EmiScheme>();
|
| 48 |
|
48 |
|
| 49 |
static {
|
49 |
static {
|
| 50 |
try {
|
50 |
try {
|
| 51 |
TransactionClient transactionClient = new TransactionClient("support_transaction_service_server_host", "transaction_service_server_port");
|
51 |
TransactionClient transactionClient = new TransactionClient("support_transaction_service_server_host", "transaction_service_server_port");
|
| 52 |
in.shop2020.model.v1.order.TransactionService.Client trxClient = transactionClient.getClient();
|
52 |
in.shop2020.model.v1.order.TransactionService.Client trxClient = transactionClient.getClient();
|
| 53 |
List<EmiScheme> emiSchemes = trxClient.getAvailableEmiSchemes();
|
53 |
List<EmiScheme> emiSchemes = trxClient.getAvailableEmiSchemes();
|
| - |
|
54 |
System.out.println("EMIs:" + emiSchemes);
|
| 54 |
for (EmiScheme emiScheme : emiSchemes){
|
55 |
for (EmiScheme emiScheme : emiSchemes){
|
| 55 |
if(!EMI_SCHEMES.containsKey(emiScheme.getMinAmount())) {
|
56 |
if(!EMI_SCHEMES.containsKey(emiScheme.getMinAmount())) {
|
| 56 |
EMI_SCHEMES.put(emiScheme.getMinAmount(), emiScheme);
|
57 |
EMI_SCHEMES.put(emiScheme.getMinAmount(), emiScheme);
|
| 57 |
} else {
|
58 |
} else {
|
| 58 |
EmiScheme emiSchemeOld = EMI_SCHEMES.get(emiScheme.getMinAmount());
|
59 |
EmiScheme emiSchemeOld = EMI_SCHEMES.get(emiScheme.getMinAmount());
|
| - |
|
60 |
double interestRateOld = emiSchemeOld.getInterestRate()/12/100;
|
| - |
|
61 |
double interestRate = emiScheme.getInterestRate()/12/100;
|
| - |
|
62 |
if(Double.compare(
|
| 59 |
if(Double.compare((1 + (emiSchemeOld.getChargeValue()/100))/emiSchemeOld.getTenure(), (1 + (emiScheme.getChargeValue()/100))/emiScheme.getTenure()) > 0){
|
63 |
interestRateOld*Math.pow((1+interestRateOld), emiSchemeOld.getTenure())/(Math.pow((1+interestRateOld), emiSchemeOld.getTenure())-1),
|
| - |
|
64 |
interestRate*Math.pow((1+interestRate), emiScheme.getTenure())/(Math.pow((1+interestRate), emiScheme.getTenure())-1))
|
| - |
|
65 |
> 0){
|
| 60 |
EMI_SCHEMES.put(emiScheme.getMinAmount(), emiScheme);
|
66 |
EMI_SCHEMES.put(emiScheme.getMinAmount(), emiScheme);
|
| 61 |
}
|
67 |
}
|
| 62 |
}
|
68 |
}
|
| 63 |
}
|
69 |
}
|
| 64 |
} catch (Exception e) {
|
70 |
} catch (Exception e) {
|
| 65 |
e.printStackTrace();
|
71 |
e.printStackTrace();
|
| 66 |
}
|
72 |
}
|
| 67 |
}
|
73 |
}
|
| 68 |
CatalogClient csc;
|
74 |
CatalogClient csc;
|
| 69 |
Client client;
|
75 |
Client client;
|
| 70 |
|
76 |
|
| 71 |
public PriceInsertor() throws TTransportException{
|
77 |
public PriceInsertor() throws TTransportException{
|
| 72 |
csc = new CatalogClient();
|
78 |
csc = new CatalogClient();
|
| Line 221... |
Line 227... |
| 221 |
|
227 |
|
| 222 |
Category category = Catalog.getInstance().getDefinitionsContainer().getCategory(items.get(0).getCategory());
|
228 |
Category category = Catalog.getInstance().getDefinitionsContainer().getCategory(items.get(0).getCategory());
|
| 223 |
if(category!=null && !domain.contains("store")){
|
229 |
if(category!=null && !domain.contains("store")){
|
| 224 |
Category parentCategory = category.getParentCategory();
|
230 |
Category parentCategory = category.getParentCategory();
|
| 225 |
|
231 |
|
| 226 |
if(parentCategory.getID() == Utils.MOBILE_PHONES_CATAGORY) {
|
232 |
if(parentCategory.getID() == Utils.MOBILE_PHONES_CATAGORY) {
|
| 227 |
filenames.add("PhonesIOwnSnippet");
|
233 |
filenames.add("PhonesIOwnSnippet");
|
| 228 |
}
|
234 |
}
|
| 229 |
if(parentCategory.isHasAccessories()){
|
235 |
if(parentCategory.isHasAccessories()){
|
| 230 |
filenames.add("RelatedAccessories");
|
236 |
filenames.add("RelatedAccessories");
|
| 231 |
}
|
237 |
}
|
| 232 |
filenames.add("CompareProductSnippet");
|
238 |
filenames.add("CompareProductSnippet");
|
| 233 |
filenames.add("SlideNamesSnippet");
|
239 |
filenames.add("SlideNamesSnippet");
|
| 234 |
filenames.add("ComparisonSnippet");
|
240 |
filenames.add("ComparisonSnippet");
|
| 235 |
if(category.isComparable()) {
|
241 |
if(category.isComparable()) {
|
| 236 |
filenames.add("MostComparedProducts");
|
242 |
filenames.add("MostComparedProducts");
|
| 237 |
filenames.add("CompareProductSummarySnippet");
|
243 |
filenames.add("CompareProductSummarySnippet");
|
| 238 |
filenames.add("MostComparedSnippet");
|
244 |
filenames.add("MostComparedSnippet");
|
| 239 |
}
|
245 |
}
|
| 240 |
}
|
246 |
}
|
| 241 |
getHtmlFromVelocity(filenames,exportPath,context,catalogId);
|
247 |
getHtmlFromVelocity(filenames,exportPath,context,catalogId);
|
| 242 |
return minPriceItem.getSellingPrice();
|
248 |
return minPriceItem.getSellingPrice();
|
| 243 |
}
|
249 |
}
|
| 244 |
|
250 |
|
| 245 |
private static String getEMI(double sellingPrice) {
|
251 |
private static String getEMI(double sellingPrice) {
|
| 246 |
String returnString = null;
|
252 |
String returnString = null;
|
| 247 |
EmiScheme finalEmi = null;
|
253 |
double finalEmiD = 0d;
|
| 248 |
for (EmiScheme emiScheme : EMI_SCHEMES.values() ){
|
254 |
for (EmiScheme emiScheme : EMI_SCHEMES.values() ){
|
| - |
|
255 |
double interestRate = emiScheme.getInterestRate()/12/100;
|
| 249 |
if(emiScheme.getMinAmount() <= sellingPrice) {
|
256 |
if(emiScheme.getMinAmount() <= sellingPrice) {
|
| - |
|
257 |
double emiD = interestRate*Math.pow((1+interestRate), emiScheme.getTenure())/(Math.pow((1+interestRate), emiScheme.getTenure())-1);
|
| 250 |
if(finalEmi == null){
|
258 |
if(finalEmiD == 0d){
|
| 251 |
finalEmi = emiScheme;
|
259 |
finalEmiD = emiD;
|
| 252 |
} else if(Double.compare((1 + (finalEmi.getChargeValue()/100))/finalEmi.getTenure(), (1 + (emiScheme.getChargeValue()/100))/emiScheme.getTenure()) > 0){
|
260 |
} else if(Double.compare(finalEmiD, emiD) > 0){
|
| 253 |
finalEmi = emiScheme;
|
261 |
finalEmiD = emiD;
|
| 254 |
}
|
262 |
}
|
| 255 |
}
|
263 |
}
|
| 256 |
}
|
264 |
}
|
| 257 |
if(finalEmi != null) {
|
265 |
if(finalEmiD != 0d) {
|
| 258 |
returnString = String.format(Locale.getDefault(),"%.0f",sellingPrice * (1 + (finalEmi.getChargeValue()/100))/finalEmi.getTenure());
|
266 |
returnString = String.format(Locale.getDefault(),"%.0f",sellingPrice * finalEmiD);
|
| 259 |
}
|
267 |
}
|
| 260 |
return returnString;
|
268 |
return returnString;
|
| 261 |
}
|
269 |
}
|
| 262 |
|
270 |
|
| 263 |
public void getHtmlFromVelocity(List<String> filenames, String exportPath, VelocityContext context, long catalogId){
|
271 |
public void getHtmlFromVelocity(List<String> filenames, String exportPath, VelocityContext context, long catalogId){
|
| 264 |
try {
|
272 |
try {
|
| 265 |
Properties p = new Properties();
|
273 |
Properties p = new Properties();
|
| 266 |
p.setProperty("resource.loader", "file");
|
274 |
p.setProperty("resource.loader", "file");
|