Subversion Repositories SmartDukaan

Rev

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

Rev 9817 Rev 9821
Line 17... Line 17...
17
import java.text.SimpleDateFormat;
17
import java.text.SimpleDateFormat;
18
import java.util.ArrayList;
18
import java.util.ArrayList;
19
import java.util.HashMap;
19
import java.util.HashMap;
20
import java.util.List;
20
import java.util.List;
21
import java.util.Map;
21
import java.util.Map;
-
 
22
import java.util.Map.Entry;
22
 
23
 
23
import javax.mail.MessagingException;
24
import javax.mail.MessagingException;
24
 
25
 
25
import org.apache.http.HttpResponse;
26
import org.apache.http.HttpResponse;
26
import org.apache.http.NameValuePair;
27
import org.apache.http.NameValuePair;
Line 168... Line 169...
168
		FileInputStream fis = new FileInputStream("/root/code/trunk/SnapDealFeeds/SellerPricing.xls");
169
		FileInputStream fis = new FileInputStream("/root/code/trunk/SnapDealFeeds/SellerPricing.xls");
169
		Workbook hwb = new HSSFWorkbook(fis);
170
		Workbook hwb = new HSSFWorkbook(fis);
170
		Sheet sheet = hwb.getSheetAt(0);
171
		Sheet sheet = hwb.getSheetAt(0);
171
		Row row;
172
		Row row;
172
		int iterator = 1;
173
		int iterator = 1;
173
		List<String> toUpdateSkuList = new ArrayList<String>();
174
		Map<String,Double> toUpdateSkuMap = new HashMap<String,Double>();
174
		for(MarketPlaceItemPrice marketPlaceItemPrice:marketPlaceItemsPrices){
175
		for(MarketPlaceItemPrice marketPlaceItemPrice:marketPlaceItemsPrices){
175
			System.out.println(marketPlaceItemPrice.getItem_id() + " " + marketPlaceItemPrice.getSellingPrice());
176
			System.out.println(marketPlaceItemPrice.getItem_id() + " " + marketPlaceItemPrice.getSellingPrice());
176
			if(itemSnapdealMap.containsKey(marketPlaceItemPrice.getItem_id()) && marketPlaceItemPrice.getLastUpdatedOn() > marketPlaceItemPrice.getLastUpdatedOnMarketplace() && !marketPlaceItemPrice.isIsPriceOverride() && marketPlaceItemPrice.isIsListedOnSource()){
177
			if(itemSnapdealMap.containsKey(marketPlaceItemPrice.getItem_id()) && marketPlaceItemPrice.getLastUpdatedOn() > marketPlaceItemPrice.getLastUpdatedOnMarketplace() && !marketPlaceItemPrice.isIsPriceOverride() && marketPlaceItemPrice.isIsListedOnSource()){
177
				if(currentPricesMap.containsKey(itemSnapdealMap.get(marketPlaceItemPrice.getItem_id()).getSkuAtSnapdeal()) && Double.parseDouble(currentPricesMap.get(itemSnapdealMap.get(marketPlaceItemPrice.getItem_id()).getSkuAtSnapdeal()).getSellingPrice()) != marketPlaceItemPrice.getSellingPrice() && marketPlaceItemPrice.getSellingPrice()!=0){
178
				if(currentPricesMap.containsKey(itemSnapdealMap.get(marketPlaceItemPrice.getItem_id()).getSkuAtSnapdeal()) && Double.parseDouble(currentPricesMap.get(itemSnapdealMap.get(marketPlaceItemPrice.getItem_id()).getSkuAtSnapdeal()).getSellingPrice()) != marketPlaceItemPrice.getSellingPrice() && marketPlaceItemPrice.getSellingPrice()!=0){
178
					row =   sheet.getRow((short) iterator);
179
					row =   sheet.getRow((short) iterator);
179
					row.getCell((short) 0).setCellValue(currentPricesMap.get(itemSnapdealMap.get(marketPlaceItemPrice.getItem_id()).getSkuAtSnapdeal()).getSupc());
180
					row.getCell((short) 0).setCellValue(currentPricesMap.get(itemSnapdealMap.get(marketPlaceItemPrice.getItem_id()).getSkuAtSnapdeal()).getSupc());
180
					row.getCell((short) 1).setCellValue(itemSnapdealMap.get(marketPlaceItemPrice.getItem_id()).getSkuAtSnapdeal());
181
					row.getCell((short) 1).setCellValue(itemSnapdealMap.get(marketPlaceItemPrice.getItem_id()).getSkuAtSnapdeal());
181
					row.getCell((short) 2).setCellValue(currentPricesMap.get(itemSnapdealMap.get(marketPlaceItemPrice.getItem_id()).getSkuAtSnapdeal()).getProductName());
182
					row.getCell((short) 2).setCellValue(currentPricesMap.get(itemSnapdealMap.get(marketPlaceItemPrice.getItem_id()).getSkuAtSnapdeal()).getProductName());
182
					row.getCell((short) 3).setCellValue(marketPlaceItemPrice.getSellingPrice());
183
					row.getCell((short) 3).setCellValue(marketPlaceItemPrice.getSellingPrice());
183
					row.getCell((short) 4).setCellValue(currentPricesMap.get(itemSnapdealMap.get(marketPlaceItemPrice.getItem_id()).getSkuAtSnapdeal()).getLive());
184
					row.getCell((short) 4).setCellValue(currentPricesMap.get(itemSnapdealMap.get(marketPlaceItemPrice.getItem_id()).getSkuAtSnapdeal()).getLive());
184
					toUpdateSkuList.add(itemSnapdealMap.get(marketPlaceItemPrice.getItem_id()).getSkuAtSnapdeal());
185
					toUpdateSkuMap.put(itemSnapdealMap.get(marketPlaceItemPrice.getItem_id()).getSkuAtSnapdeal(),marketPlaceItemPrice.getSellingPrice());
185
					iterator++;
186
					iterator++;
186
				}
187
				}
187
			}
188
			}
188
		}
189
		}
189
		if(iterator!=1){
190
		if(iterator!=1){
Line 227... Line 228...
227
				e.printStackTrace();
228
				e.printStackTrace();
228
			}
229
			}
229
			int retry = 5;
230
			int retry = 5;
230
			boolean exitfetchinghistory;
231
			boolean exitfetchinghistory;
231
			int successfullyUpdated;
232
			int successfullyUpdated;
232
			List<String> updatedSkuList = new ArrayList<String>();
233
			Map<String,Double> updatedSkuMap = new HashMap<String,Double>();
233
			System.out.println("Feed response " + feedresponse);
234
			System.out.println("Feed response " + feedresponse);
234
			if(feedresponse.contains("Error")){
235
			if(feedresponse.contains("Error")){
235
				System.out.println("Error while uploading sheet");
236
				System.out.println("Error while uploading sheet");
236
				try {
237
				try {
237
					mailer.sendSSLMessage(sendTo,"Error at Snapdeal while Changing Prices"+ sdf.format(System.currentTimeMillis()),"No change in Snapdeal Prices to be updated ", emailFromAddress, password, new ArrayList<File>());
238
					mailer.sendSSLMessage(sendTo,"Error at Snapdeal while Changing Prices"+ sdf.format(System.currentTimeMillis()),"No change in Snapdeal Prices to be updated ", emailFromAddress, password, new ArrayList<File>());
Line 256... Line 257...
256
					pricingHistoryItems = (PricingHistoryItems) gson.fromJson(rd, PricingHistoryItems.class);
257
					pricingHistoryItems = (PricingHistoryItems) gson.fromJson(rd, PricingHistoryItems.class);
257
					if(pricingHistoryItems.getRows().size()!=0 &&  successfullyUpdated != (iterator - 1)){
258
					if(pricingHistoryItems.getRows().size()!=0 &&  successfullyUpdated != (iterator - 1)){
258
						for(PricingHistory pricingHistory:pricingHistoryItems.getRows()){
259
						for(PricingHistory pricingHistory:pricingHistoryItems.getRows()){
259
							if(Long.parseLong(pricingHistory.getModifiedOn()) > time && pricingHistory.getApprovalStatus().equals("Done") && pricingHistory.getUploadId().equals(uploadId)){
260
							if(Long.parseLong(pricingHistory.getModifiedOn()) > time && pricingHistory.getApprovalStatus().equals("Done") && pricingHistory.getUploadId().equals(uploadId)){
260
								successfullyUpdated++;
261
								successfullyUpdated++;
261
								updatedSkuList.add(pricingHistory.getSellerSku());
262
								updatedSkuMap.put(pricingHistory.getSellerSku(),Double.parseDouble(pricingHistory.getLineitems().get(0).getNewValue()));
262
								System.out.println("SKU Updated " + pricingHistory.getSellerSku() + " " + pricingHistory.getUploadId());
263
								System.out.println("SKU Updated " + pricingHistory.getSellerSku() + " " + pricingHistory.getUploadId());
263
							}
264
							}
264
						}
265
						}
265
					}
266
					}
266
					else{
267
					else{
Line 280... Line 281...
280
			} catch (TTransportException e1) {
281
			} catch (TTransportException e1) {
281
				e1.printStackTrace();
282
				e1.printStackTrace();
282
			}
283
			}
283
			in.shop2020.model.v1.catalog.CatalogService.Client catalogClient = catalogServiceClient.getClient();
284
			in.shop2020.model.v1.catalog.CatalogService.Client catalogClient = catalogServiceClient.getClient();
284
			List<Long> updatedItems = new ArrayList<Long>();
285
			List<Long> updatedItems = new ArrayList<Long>();
-
 
286
			String tableHeader = "<tr>" 
-
 
287
				+ "<td>" + "Product Name" +"</td>"
-
 
288
				+"<td>" + "Item ID" + "</td>"
-
 
289
				+"<td>" + "SKU at Snapdeal" + "</td>"
-
 
290
				+"<td>" + "Old Price" + "</td>"
-
 
291
				+"<td>" + "New Price" + "</td>"
-
 
292
				+"</tr>";
285
			if(toUpdateSkuList.size() != updatedSkuList.size()){
293
			if(toUpdateSkuMap.size() != updatedSkuMap.size()){
-
 
294
				StringBuffer notUpdatedMailBody =new StringBuffer();
-
 
295
				notUpdatedMailBody.append(tableHeader);
-
 
296
				for(Entry<String, Double> entry:updatedSkuMap.entrySet()){
286
				toUpdateSkuList.removeAll(updatedSkuList);
297
					toUpdateSkuMap.remove(entry.getKey());
-
 
298
				}
-
 
299
				for(Entry<String, Double> entry:toUpdateSkuMap.entrySet()){
-
 
300
					notUpdatedMailBody.append("<tr>" + "<td>" + currentPricesMap.get(entry.getKey()).getProductName() + "</td>"
-
 
301
					+"<td>" + snapdealItemMap.get(entry.getKey()).getItem_id() + "</td>"
-
 
302
					+"<td>" + currentPricesMap.get(entry.getKey()).getSellingPrice() + "</td>" 
-
 
303
					+"<td>" + entry.getValue() +"</td>");
-
 
304
					
-
 
305
				}
-
 
306
				String text = "<html><table border=\"1\" align=\"center\">" 
-
 
307
								+ tableHeader  
-
 
308
								+ notUpdatedMailBody.toString() + "</table></html>";
-
 
309
								
287
				System.out.println("SKUs not updated");
310
				System.out.println("SKUs not updated");
288
				try {
311
				try {
289
					mailer.sendSSLMessage(sendTo,"Snapdeal Item Prices were not updated "+ sdf.format(System.currentTimeMillis()),"Following Snapdeal Item Prices were not updated \n"+toUpdateSkuList.toString(), emailFromAddress, password, new ArrayList<File>());
312
					mailer.sendSSLMessage(sendTo,"Snapdeal Item Prices were not updated "+ sdf.format(System.currentTimeMillis()),emailFromAddress, password, text);
290
				} catch (MessagingException e) {
313
				} catch (MessagingException e) {
291
					// TODO Auto-generated catch block
314
					// TODO Auto-generated catch block
292
					e.printStackTrace();
315
					e.printStackTrace();
293
				}
316
				}
294
				
317
				
295
			}
318
			}
296
			if(updatedSkuList.size()>0){
319
			if(updatedSkuMap.size()>0){
297
				for(String updatedSku:updatedSkuList){
320
				StringBuffer updatedMailBody =new StringBuffer();
298
					if(snapdealItemMap.containsKey(updatedSku)){
321
				for(Entry<String, Double> entry:updatedSkuMap.entrySet()){
-
 
322
					updatedMailBody.append("<tr>" + "<td>" + currentPricesMap.get(entry.getKey()).getProductName() + "</td>"
299
						updatedItems.add(snapdealItemMap.get(updatedSku).getItem_id());
323
							+"<td>" + snapdealItemMap.get(entry.getKey()).getItem_id() + "</td>"
-
 
324
							+"<td>" + currentPricesMap.get(entry.getKey()).getSellingPrice() + "</td>" 
300
					}
325
							+"<td>" + entry.getValue() +"</td>");
301
				}
326
				}
302
				try {
327
				try {
303
					catalogClient.updateMarketPlacePriceUpdateStatus(updatedItems,time,7);
328
					catalogClient.updateMarketPlacePriceUpdateStatus(updatedItems,time,7);
304
				} catch (TException e) {
329
				} catch (TException e) {
305
					try {
330
					try {
Line 309... Line 334...
309
					} catch (TException e1) {
334
					} catch (TException e1) {
310
						e1.printStackTrace();
335
						e1.printStackTrace();
311
					}
336
					}
312
					e.printStackTrace();
337
					e.printStackTrace();
313
				}
338
				}
-
 
339
				String text = "<html><table border=\"1\" align=\"center\">" 
-
 
340
					+ tableHeader  
-
 
341
					+ updatedMailBody.toString() + "</table></html>";
-
 
342
	
314
				try {
343
				try {
315
					System.out.println("Snapdeal Item Prices updated Successfully");
344
					System.out.println("Snapdeal Item Prices updated Successfully");
316
					if(updatedSkuList.size()==1){
345
					if(updatedSkuMap.size()==1){
317
						mailer.sendSSLMessage(sendTo,updatedSkuList.size()+" Snapdeal Item Price updated Successfully "+ sdf.format(System.currentTimeMillis()),"Snapdeal Item Price updated Successfully ", emailFromAddress, password, new ArrayList<File>());
346
						mailer.sendSSLMessage(sendTo,updatedSkuMap.size()+" Snapdeal Item Price updated Successfully "+ sdf.format(System.currentTimeMillis()), emailFromAddress, password,text);
318
					}
347
					}
319
					else{
348
					else{
320
						mailer.sendSSLMessage(sendTo,updatedSkuList.size()+" Snapdeal Items Price updated Successfully "+ sdf.format(System.currentTimeMillis()),"All Snapdeal Item Prices updated Successfully ", emailFromAddress, password, new ArrayList<File>());						
349
						mailer.sendSSLMessage(sendTo,updatedSkuMap.size()+" Snapdeal Items Price updated Successfully "+ sdf.format(System.currentTimeMillis()), emailFromAddress, password,text);						
321
					}
350
					}
322
				} catch (MessagingException e) {
351
				} catch (MessagingException e) {
323
					e.printStackTrace();
352
					e.printStackTrace();
324
				}
353
				}
325
			}
354
			}