Subversion Repositories SmartDukaan

Rev

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

Rev 10107 Rev 10122
Line 60... Line 60...
60
	private static List<FlipkartItem> flipkartItems;
60
	private static List<FlipkartItem> flipkartItems;
61
	private static List<FlipkartItem> flipkartInventoryItems = new ArrayList<FlipkartItem>();
61
	private static List<FlipkartItem> flipkartInventoryItems = new ArrayList<FlipkartItem>();
62
	private static Map<Long,Long> itemIdOrdersMap = new HashMap<Long,Long>();
62
	private static Map<Long,Long> itemIdOrdersMap = new HashMap<Long,Long>();
63
	private static Map<Long,Item> aliveItemsMap = new HashMap<Long,Item>();
63
	private static Map<Long,Item> aliveItemsMap = new HashMap<Long,Item>();
64
	private static Map<String,Long> heldOrdersMap = new HashMap<String,Long>();
64
	private static Map<String,Long> heldOrdersMap = new HashMap<String,Long>();
-
 
65
	private static Map<Long,Long>  updatedFlipkartInventoryMap = new HashMap<Long,Long>();
65
	static java.text.SimpleDateFormat sdf;
66
	static java.text.SimpleDateFormat sdf;
66
	static String emailFromAddress;
67
	static String emailFromAddress;
67
	static String password;
68
	static String password;
68
	static GmailUtils mailer;
69
	static GmailUtils mailer;
69
	static String sendTo[];
70
	static String sendTo[];
Line 123... Line 124...
123
			}
124
			}
124
			//e.printStackTrace();
125
			//e.printStackTrace();
125
		}catch (TException e) {
126
		}catch (TException e) {
126
			e.printStackTrace();
127
			e.printStackTrace();
127
		}
128
		}
-
 
129
		in.shop2020.model.v1.inventory.InventoryService.Client inventoryServiceClient = null;
-
 
130
		try {
-
 
131
			inventoryServiceClient = new InventoryClient("inventory_service_server_host","inventory_service_server_port").getClient();
-
 
132
		} catch (TTransportException e) {
-
 
133
			e.printStackTrace();
-
 
134
		}
-
 
135
		try {
-
 
136
			List<FlipkartInventorySnapshot> updatedFlipkartInventoryList = inventoryServiceClient.getFlipkartInventorySnapshot();
-
 
137
			for(FlipkartInventorySnapshot updatedFlipkartInventory:updatedFlipkartInventoryList){
-
 
138
				updatedFlipkartInventoryMap.put(updatedFlipkartInventory.getItem_id(),updatedFlipkartInventory.getAvailability());
-
 
139
			}
-
 
140
		} catch (TException e) {
-
 
141
			e.printStackTrace();
-
 
142
		}
-
 
143
 
128
 
144
 
129
	}
145
	}
130
 
146
 
131
	public static void main(String[] args) throws ClientProtocolException, TException{
147
	public static void main(String[] args) throws ClientProtocolException, TException{
132
		calculateinventory();
148
		calculateinventory();
Line 158... Line 174...
158
		}
174
		}
159
		long stock=0;
175
		long stock=0;
160
		int i=0;
176
		int i=0;
161
		long available,reserve,heldforsource,totalheld,allocable,holdinventory,defaultinventory,actualstock,orders,heldorders;
177
		long available,reserve,heldforsource,totalheld,allocable,holdinventory,defaultinventory,actualstock,orders,heldorders;
162
		StringBuffer inventoryItems =new StringBuffer();
178
		StringBuffer inventoryItems =new StringBuffer();
-
 
179
		StringBuffer backInStockItems =new StringBuffer();
-
 
180
		StringBuffer outOfStockItems =new StringBuffer();
163
		String tableHeader = "<html><table border=\"1\" align=\"center\"><tr>" 
181
		String tableHeader = "<html><table border=\"1\" align=\"center\"><tr>" 
164
			+ "<td><b>" + "Product Name" +"</b></td>"
182
			+ "<td><b>" + "Product Name" +"</b></td>"
165
			+"<td><b>" + "Item ID" + "</b></td>"
183
			+"<td><b>" + "Item ID" + "</b></td>"
166
			+"<td><b>" + "Inventory" + "</b></td>"
184
			+"<td><b>" + "Inventory" + "</b></td>"
167
			+"<td><b>" + "Orders Added to Inventory" + "</b></td>"
185
			+"<td><b>" + "Orders Added to Inventory" + "</b></td>"
168
			+"<td><b>" + "Sent Inventory" + "</b></td>"
186
			+"<td><b>" + "Sent Inventory" + "</b></td>"
169
			+"<td><b>" + "Procurement SLA" + "</b></td>"
187
			+"<td><b>" + "Procurement SLA" + "</b></td>"
170
			+"<td><b>" + "Orders on Hold" + "</b></td>"
188
			+"<td><b>" + "Orders on Hold" + "</b></td>"
171
			+"</tr>";
189
			+"</tr>";
-
 
190
		
172
		String tableFooter = "</table></html>";
191
		String tableFooter = "</table></html>";
173
		Item item;
192
		Item item;
174
		StringBuffer feedResponse=  new StringBuffer();
193
		StringBuffer feedResponse=  new StringBuffer();
175
		List<FlipkartInventorySnapshot> inventorysnapshotlist = new ArrayList<FlipkartInventorySnapshot>();
194
		List<FlipkartInventorySnapshot> inventorysnapshotlist = new ArrayList<FlipkartInventorySnapshot>();
176
		for(Entry<Long, FlipkartInventoryItem> entry:flipkartItemsInventoryMap.entrySet()){
195
		for(Entry<Long, FlipkartInventoryItem> entry:flipkartItemsInventoryMap.entrySet()){
Line 263... Line 282...
263
				inventorySnapshot.setHeldOrders(0);
282
				inventorySnapshot.setHeldOrders(0);
264
			}
283
			}
265
			inventorySnapshot.setCreatedOrders(orders);
284
			inventorySnapshot.setCreatedOrders(orders);
266
			inventorysnapshotlist.add(inventorySnapshot);
285
			inventorysnapshotlist.add(inventorySnapshot);
267
			item = aliveItemsMap.get(entry.getValue().getId());
286
			item = aliveItemsMap.get(entry.getValue().getId());
-
 
287
			if(updatedFlipkartInventoryMap.containsKey(entry.getKey()) && updatedFlipkartInventoryMap.get(entry.getKey()) != stock){
268
			inventoryItems.append("<tr>" 
288
				inventoryItems.append("<tr>" 
-
 
289
						+ "<td>" +getProductName(item)+"</td>"
-
 
290
						+"<td>" + item.getId() + "</td>"
-
 
291
						+"<td>" + actualstock + "</td>"
-
 
292
						+"<td>" + orders + "</td>"
-
 
293
						+"<td>" + stock + "</td>"
-
 
294
						+"<td>" + logisticinfo.getShippingTime() + "</td>"
-
 
295
						+"<td>" + heldorders + "</td>"
-
 
296
						+"</tr>");
-
 
297
			}
-
 
298
			if(updatedFlipkartInventoryMap.containsKey(entry.getKey()) && updatedFlipkartInventoryMap.get(entry.getKey()) == 0 && stock!=0){
-
 
299
				backInStockItems.append("<tr>" 
-
 
300
						+ "<td>" +getProductName(item)+"</td>"
-
 
301
						+"<td>" + item.getId() + "</td>"
-
 
302
						+"<td>" + actualstock + "</td>"
-
 
303
						+"<td>" + orders + "</td>"
-
 
304
						+"<td>" + stock + "</td>"
-
 
305
						+"<td>" + logisticinfo.getShippingTime() + "</td>"
-
 
306
						+"<td>" + heldorders + "</td>"
-
 
307
						+"</tr>");
-
 
308
			}
-
 
309
			if(updatedFlipkartInventoryMap.containsKey(entry.getKey()) && updatedFlipkartInventoryMap.get(entry.getKey()) != 0 && stock==0){
-
 
310
				outOfStockItems.append("<tr>" 
269
					+ "<td>" +getProductName(item)+"</td>"
311
						+ "<td>" +getProductName(item)+"</td>"
270
					+"<td>" + item.getId() + "</td>"
312
						+"<td>" + item.getId() + "</td>"
271
					+"<td>" + actualstock + "</td>"
313
						+"<td>" + actualstock + "</td>"
272
					+"<td>" + orders + "</td>"
314
						+"<td>" + orders + "</td>"
273
					+"<td>" + stock + "</td>"
315
						+"<td>" + stock + "</td>"
274
					+"<td>" + logisticinfo.getShippingTime() + "</td>"
316
						+"<td>" + logisticinfo.getShippingTime() + "</td>"
275
					+"<td>" + heldorders + "</td>"
317
						+"<td>" + heldorders + "</td>"
276
					+"</tr>");
318
						+"</tr>");
-
 
319
			}
277
			i++;
320
			i++;
278
			if(flipkartItemsInventoryMap.entrySet().size()!=1 && (i!=flipkartItemsInventoryMap.entrySet().size()) ){
321
			if(flipkartItemsInventoryMap.entrySet().size()!=1 && (i!=flipkartItemsInventoryMap.entrySet().size()) ){
279
				if(i%10!=0){
322
				if(i%10!=0){
280
					jsonRequest.append(",");
323
					jsonRequest.append(",");
281
				}
324
				}
Line 333... Line 376...
333
		try {
376
		try {
334
			mailer.sendSSLMessage(sendTo,"Flipkart Inventory Sent Details ", emailFromAddress, password, text);
377
			mailer.sendSSLMessage(sendTo,"Flipkart Inventory Sent Details ", emailFromAddress, password, text);
335
		} catch (MessagingException e) {
378
		} catch (MessagingException e) {
336
			e.printStackTrace();
379
			e.printStackTrace();
337
		}
380
		}
-
 
381
		if(backInStockItems.toString().length()>0){
-
 
382
			try {
-
 
383
				text = tableHeader+backInStockItems.toString()+tableFooter;
-
 
384
				mailer.sendSSLMessage(sendTo,"Flipkart Inventory Back in Stock ", emailFromAddress, password, text);
-
 
385
			} catch (MessagingException e) {
-
 
386
				e.printStackTrace();
-
 
387
			}
-
 
388
			
-
 
389
		}
-
 
390
		if(outOfStockItems.toString().length()>0){
-
 
391
			try {
-
 
392
				text = tableHeader+outOfStockItems.toString()+tableFooter;
-
 
393
				mailer.sendSSLMessage(sendTo,"Flipkart Inventory Out of Stock ", emailFromAddress, password, text);
-
 
394
			} catch (MessagingException e) {
-
 
395
				e.printStackTrace();
-
 
396
			}
-
 
397
			
-
 
398
		}
338
		if(feedResponse.toString().length()>0){
399
		if(feedResponse.toString().length()>0){
339
			try {
400
			try {
340
				mailer.sendSSLMessage(sendTo, "Flipkart Inventory could not be updated ", feedResponse.toString(), emailFromAddress, password,new ArrayList<File>());
401
				mailer.sendSSLMessage(sendTo, "Flipkart Inventory could not be updated ", feedResponse.toString(), emailFromAddress, password,new ArrayList<File>());
341
			} catch (MessagingException e) {
402
			} catch (MessagingException e) {
342
				e.printStackTrace();
403
				e.printStackTrace();