Subversion Repositories SmartDukaan

Rev

Rev 3018 | Rev 3575 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3018 Rev 3560
Line 1... Line 1...
1
package in.shop2020.ui.util;
1
package in.shop2020.ui.util;
2
 
2
 
-
 
3
import in.shop2020.model.v1.catalog.InventoryServiceException;
3
import in.shop2020.model.v1.catalog.Item;
4
import in.shop2020.model.v1.catalog.Item;
-
 
5
import in.shop2020.model.v1.catalog.Source;
-
 
6
import in.shop2020.model.v1.catalog.InventoryService.Client;
-
 
7
import in.shop2020.model.v1.catalog.SourceItemPricing;
-
 
8
import in.shop2020.thrift.clients.CatalogClient;
4
import in.shop2020.util.Utils;
9
import in.shop2020.util.Utils;
5
import in.shop2020.utils.CategoryManager;
10
import in.shop2020.utils.CategoryManager;
6
 
11
 
7
import java.io.BufferedWriter;
12
import java.io.BufferedWriter;
8
import java.io.File;
13
import java.io.File;
Line 14... Line 19...
14
import java.util.List;
19
import java.util.List;
15
import java.util.Map;
20
import java.util.Map;
16
import java.util.Properties;
21
import java.util.Properties;
17
 
22
 
18
import org.apache.commons.io.FileUtils;
23
import org.apache.commons.io.FileUtils;
-
 
24
import org.apache.thrift.TException;
-
 
25
import org.apache.thrift.transport.TTransportException;
19
import org.apache.velocity.Template;
26
import org.apache.velocity.Template;
20
import org.apache.velocity.VelocityContext;
27
import org.apache.velocity.VelocityContext;
21
import org.apache.velocity.app.Velocity;
28
import org.apache.velocity.app.Velocity;
22
import org.apache.velocity.exception.ParseErrorException;
29
import org.apache.velocity.exception.ParseErrorException;
23
import org.apache.velocity.exception.ResourceNotFoundException;
30
import org.apache.velocity.exception.ResourceNotFoundException;
Line 29... Line 36...
29
 * 
36
 * 
30
 * @author rajveer
37
 * @author rajveer
31
 *
38
 *
32
 */
39
 */
33
public class PriceInsertor {
40
public class PriceInsertor {
-
 
41
    CatalogClient csc;
-
 
42
    Client client;
34
 
43
 
-
 
44
	public PriceInsertor() throws TTransportException{
-
 
45
        csc = new CatalogClient();
-
 
46
        client = csc.getClient();
-
 
47
	}
-
 
48
	
35
	public void insertPriceInSolrData(long catalogId, double price) throws IOException{
49
	public void insertPriceInSolrData(long catalogId, String priceString) throws IOException{
36
		String irSolrFilename = Utils.EXPORT_PATH + "xml/final/" + catalogId + "_irdata_solr.xml";
50
		String irSolrFilename = Utils.EXPORT_PATH + "xml/final/" + catalogId + "_irdata_solr.xml";
37
		String finalFile = Utils.EXPORT_PATH + "solr/" + catalogId + "_irdata_solr.xml";
51
		String finalFile = Utils.EXPORT_PATH + "solr/" + catalogId + "_irdata_solr.xml";
38
		File f = new File(irSolrFilename);
52
		File f = new File(irSolrFilename);
39
		String s = FileUtils.readFileToString(f);
53
		String s = FileUtils.readFileToString(f);
40
		s = s.replaceAll("<field name=\"F_50002\">.*</field>", "<field name=\"F_50002\">"+price+"</field>");
54
		s = s.replaceAll("<field name=\"F_50002\">.*</field>", priceString);
41
		File f1 = new File(finalFile);
55
		File f1 = new File(finalFile);
42
		FileUtils.writeStringToFile(f1, s);
56
		FileUtils.writeStringToFile(f1, s);
43
	}
57
	}
44
	
58
	
45
	public void insertPriceInHtml(List<Item> items, long catalogId, String domain, String exportPath){
59
	public double insertPriceInHtml(List<Item> items, long catalogId, String domain, String exportPath, Source source){
46
		List<Map<String, String>> itemDetails = new ArrayList<Map<String,String>>(); 
60
		List<Map<String, String>> itemDetails = new ArrayList<Map<String,String>>(); 
47
		Item minPriceItem = null;
61
		Item minPriceItem = null;
48
		for(Item item: items){
62
		for(Item item: items){
49
			Map<String, String> itemDetail = new HashMap<String, String>();
63
			Map<String, String> itemDetail = new HashMap<String, String>();
50
			boolean showmrp = true;
64
			boolean showmrp = true;
51
			if (item.getMrp() <= item.getSellingPrice()) {
65
			double sellingPrice = item.getSellingPrice();
-
 
66
			double mrp = item.getMrp();
-
 
67
			
-
 
68
			if(source != null){
-
 
69
				try {
-
 
70
					SourceItemPricing sip = client.getItemPricingBySource(item.getId(), source.getId());
-
 
71
					sellingPrice = sip.getSellingPrice();
-
 
72
					mrp = sip.getMrp();
-
 
73
				} catch (TException e) {
-
 
74
					e.printStackTrace();
-
 
75
				} catch (InventoryServiceException e) {
-
 
76
					e.printStackTrace();
-
 
77
				}
-
 
78
			}
-
 
79
			
-
 
80
			if (mrp <= sellingPrice) {
52
				showmrp = false;
81
				showmrp = false;
53
			}
82
			}
54
			if(minPriceItem == null || minPriceItem.getSellingPrice() > item.getSellingPrice()){
83
			if(minPriceItem == null || minPriceItem.getSellingPrice() > item.getSellingPrice()){
55
				minPriceItem = item;
84
				minPriceItem = item;
56
			}
85
			}
57
			double sellingPrice = item.getSellingPrice();
-
 
58
			double mrp = item.getMrp();
86
			
59
			double saving = Math.round((mrp-sellingPrice)/mrp*100);
87
			double saving = Math.round((mrp-sellingPrice)/mrp*100);
60
			itemDetail.put("ITEM_ID", ((int)item.getId())+"");	
88
			itemDetail.put("ITEM_ID", ((int)item.getId())+"");	
61
			itemDetail.put("SP", ((int)item.getSellingPrice())+"");
89
			itemDetail.put("SP", ((int)sellingPrice)+"");
62
			itemDetail.put("MRP", ((int)item.getMrp())+"");
90
			itemDetail.put("MRP", ((int)mrp)+"");
63
			itemDetail.put("SAVING", ((int)saving)+"");
91
			itemDetail.put("SAVING", ((int)saving)+"");
64
			itemDetail.put("COLOR", item.getColor());
92
			itemDetail.put("COLOR", item.getColor());
65
			itemDetail.put("CATALOG_ID", ((int)item.getCatalogItemId())+"");
93
			itemDetail.put("CATALOG_ID", ((int)item.getCatalogItemId())+"");
66
			itemDetail.put("SHOWMRP", showmrp +"");
94
			itemDetail.put("SHOWMRP", showmrp +"");
67
			itemDetail.put("IS_SELECTED", item.isDefaultForEntity() ? "SELECTED" : "");
95
			itemDetail.put("IS_SELECTED", item.isDefaultForEntity() ? "SELECTED" : "");
68
			itemDetails.add(itemDetail);
96
			itemDetails.add(itemDetail);
69
		}
97
		}
70
		
-
 
71
		File exportDir = new File(exportPath + catalogId);
98
		File exportDir = new File(exportPath + catalogId);
-
 
99
		if(source != null){
-
 
100
			exportDir = new File(exportPath + catalogId + File.separator + source.getId());	
-
 
101
		}
-
 
102
		
72
		if(!exportDir.exists()) {
103
		if(!exportDir.exists()) {
73
			exportDir.mkdir();
104
			exportDir.mkdir();
74
		}
105
		}
75
 
106
 
76
		// This URL is used to ensure that images such as icon and thumbnail for
107
		// This URL is used to ensure that images such as icon and thumbnail for
Line 103... Line 134...
103
			filenames.add("SlideNamesSnippet");
134
			filenames.add("SlideNamesSnippet");
104
			filenames.add("RelatedAccessories");
135
			filenames.add("RelatedAccessories");
105
			filenames.add("MostComparedProducts");
136
			filenames.add("MostComparedProducts");
106
		}
137
		}
107
		getHtmlFromVelocity(filenames,exportPath,context,catalogId);
138
		getHtmlFromVelocity(filenames,exportPath,context,catalogId);
-
 
139
		return minPriceItem.getSellingPrice();
108
	}
140
	}
109
	
141
	
110
	public void getHtmlFromVelocity(List<String> filenames, String exportPath, VelocityContext context, long catalogId){
142
	public void getHtmlFromVelocity(List<String> filenames, String exportPath, VelocityContext context, long catalogId){
111
		try {
143
		try {
112
			Properties p = new Properties();
144
			Properties p = new Properties();