Subversion Repositories SmartDukaan

Rev

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

Rev 8816 Rev 8825
Line 15... Line 15...
15
 
15
 
16
import java.io.FileNotFoundException;
16
import java.io.FileNotFoundException;
17
import java.io.FileOutputStream;
17
import java.io.FileOutputStream;
18
import java.io.FileReader;
18
import java.io.FileReader;
19
import java.io.IOException;
19
import java.io.IOException;
-
 
20
import java.io.OutputStream;
20
import java.text.ParseException;
21
import java.text.ParseException;
21
import java.text.SimpleDateFormat;
22
import java.text.SimpleDateFormat;
22
import java.util.ArrayList;
23
import java.util.ArrayList;
-
 
24
import java.util.Calendar;
23
import java.util.Date;
25
import java.util.Date;
24
import java.util.HashMap;
26
import java.util.HashMap;
25
import java.util.List;
27
import java.util.List;
26
import java.util.Map;
28
import java.util.Map;
27
import java.util.Map.Entry;
29
import java.util.Map.Entry;
Line 132... Line 134...
132
			TransactionClient transactionServiceClient = null;
134
			TransactionClient transactionServiceClient = null;
133
			CatalogClient catalogServiceClient = null;
135
			CatalogClient catalogServiceClient = null;
134
			try {
136
			try {
135
				inventoryServiceClient = new InventoryClient();
137
				inventoryServiceClient = new InventoryClient();
136
				transactionServiceClient = new TransactionClient();
138
				transactionServiceClient = new TransactionClient();
137
				//catalogServiceClient = new CatalogClient();
139
				catalogServiceClient = new CatalogClient();
138
				catalogServiceClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port");
140
				//catalogServiceClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port");
139
			} catch (Exception e) {
141
			} catch (Exception e) {
140
				// TODO Auto-generated catch block
142
				// TODO Auto-generated catch block
141
				e.printStackTrace();
143
				e.printStackTrace();
142
			}	
144
			}	
143
			in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
145
			in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
144
			in.shop2020.model.v1.order.TransactionService.Client transactionClient   = transactionServiceClient.getClient();
146
			in.shop2020.model.v1.order.TransactionService.Client transactionClient   = transactionServiceClient.getClient();
145
			in.shop2020.model.v1.catalog.CatalogService.Client catalogClient   = catalogServiceClient.getClient();
147
			in.shop2020.model.v1.catalog.CatalogService.Client catalogClient   = catalogServiceClient.getClient();
146
			SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
148
			SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
147
			Date date_today = dateFormat.parse(dateFormat.format(new Date()));
149
			//Date date_today = dateFormat.parse(dateFormat.format(new Date()));
-
 
150
			List<Date> dates = new ArrayList<Date>();
-
 
151
			Calendar cal = Calendar.getInstance();
-
 
152
			cal.add(Calendar.DATE, -1);
-
 
153
			Date date_end = dateFormat.parse(dateFormat.format(cal.getTime()));
-
 
154
			cal.add(Calendar.DATE, -5);
-
 
155
			Date date_start = dateFormat.parse(dateFormat.format(cal.getTime()));
-
 
156
			System.out.println("Start Date = " + date_start);
-
 
157
			System.out.println("End Date = " + date_end);
-
 
158
			Date d = date_start;
-
 
159
			while(!d.equals(date_end)){
-
 
160
		        cal.setTime(d);
-
 
161
		        cal.add(Calendar.DATE,1);
-
 
162
				d = cal.getTime();
-
 
163
				dates.add(d);
-
 
164
			}
148
			List<AmazonFbaInventorySnapshot> nonzeroFbaInventorySnapshotlist =  inventoryClient.getAllAmazonFbaItemInventory();
165
			List<AmazonFbaInventorySnapshot> nonzeroFbaInventorySnapshotlist =  inventoryClient.getAllAmazonFbaItemInventory();
-
 
166
			for(Date date:dates){
149
			if(nonzeroFbaInventorySnapshotlist!=null){
167
				if(nonzeroFbaInventorySnapshotlist!=null){
150
				for(AmazonFbaInventorySnapshot amazonFbaInventory:nonzeroFbaInventorySnapshotlist){
168
					for(AmazonFbaInventorySnapshot amazonFbaInventory:nonzeroFbaInventorySnapshotlist){
151
					if(orderDateItemIdFbaSaleSnapshotMap.containsKey(date_today) ){ 
169
						if(orderDateItemIdFbaSaleSnapshotMap.containsKey(date) ){ 
152
						if(!orderDateItemIdFbaSaleSnapshotMap.get(date_today).containsKey(amazonFbaInventory.getItem_id())){
170
							if(!orderDateItemIdFbaSaleSnapshotMap.get(date).containsKey(amazonFbaInventory.getItem_id())){
-
 
171
								Map<Long,FbaSalesSnapshot> ItemIdFbaSaleSnapshotMap = new HashMap<Long,FbaSalesSnapshot>();
-
 
172
								FbaSalesSnapshot fbaSalesSnapshot = new FbaSalesSnapshot();
-
 
173
								fbaSalesSnapshot.setTotalOrderCount(0);
-
 
174
								fbaSalesSnapshot.setPromotionOrderCount(0);
-
 
175
								fbaSalesSnapshot.setTotalPromotionSale((float) 0);
-
 
176
								fbaSalesSnapshot.setTotalSale((float) 0);
-
 
177
								ItemIdFbaSaleSnapshotMap.put(amazonFbaInventory.getItem_id(),fbaSalesSnapshot);
-
 
178
								orderDateItemIdFbaSaleSnapshotMap.get(date).put(amazonFbaInventory.getItem_id(),fbaSalesSnapshot);
-
 
179
							}
-
 
180
 
-
 
181
						}
-
 
182
						else{
153
							Map<Long,FbaSalesSnapshot> ItemIdFbaSaleSnapshotMap = new HashMap<Long,FbaSalesSnapshot>();
183
							Map<Long,FbaSalesSnapshot> ItemIdFbaSaleSnapshotMap = new HashMap<Long,FbaSalesSnapshot>();
154
							FbaSalesSnapshot fbaSalesSnapshot = new FbaSalesSnapshot();
184
							FbaSalesSnapshot fbaSalesSnapshot = new FbaSalesSnapshot();
155
							fbaSalesSnapshot.setTotalOrderCount(0);
185
							fbaSalesSnapshot.setTotalOrderCount(0);
156
							fbaSalesSnapshot.setPromotionOrderCount(0);
186
							fbaSalesSnapshot.setPromotionOrderCount(0);
157
							fbaSalesSnapshot.setTotalPromotionSale((float) 0);
187
							fbaSalesSnapshot.setTotalPromotionSale((float) 0);
158
							fbaSalesSnapshot.setTotalSale((float) 0);
188
							fbaSalesSnapshot.setTotalSale((float) 0);
159
							ItemIdFbaSaleSnapshotMap.put(amazonFbaInventory.getItem_id(),fbaSalesSnapshot);
189
							ItemIdFbaSaleSnapshotMap.put(amazonFbaInventory.getItem_id(),fbaSalesSnapshot);
160
							orderDateItemIdFbaSaleSnapshotMap.get(date_today).put(amazonFbaInventory.getItem_id(),fbaSalesSnapshot);
190
							orderDateItemIdFbaSaleSnapshotMap.put(date,ItemIdFbaSaleSnapshotMap);
161
						}
191
						}
162
 
-
 
163
					}
-
 
164
					else{
-
 
165
						Map<Long,FbaSalesSnapshot> ItemIdFbaSaleSnapshotMap = new HashMap<Long,FbaSalesSnapshot>();
-
 
166
						FbaSalesSnapshot fbaSalesSnapshot = new FbaSalesSnapshot();
-
 
167
						fbaSalesSnapshot.setTotalOrderCount(0);
-
 
168
						fbaSalesSnapshot.setPromotionOrderCount(0);
-
 
169
						fbaSalesSnapshot.setTotalPromotionSale((float) 0);
-
 
170
						fbaSalesSnapshot.setTotalSale((float) 0);
-
 
171
						ItemIdFbaSaleSnapshotMap.put(amazonFbaInventory.getItem_id(),fbaSalesSnapshot);
-
 
172
						orderDateItemIdFbaSaleSnapshotMap.put(date_today,ItemIdFbaSaleSnapshotMap);
-
 
173
					}
192
					}
174
				}
193
				}
175
			}
-
 
176
			else{
194
				else{
177
				System.out.println("No inventory in FBA");
195
					System.out.println("No inventory in FBA");
-
 
196
				}
178
			}
197
			}
179
			Map<Long,PriceAtDate> itemIdOurPriceMap = new HashMap<Long,PriceAtDate>();
198
			Map<Long,PriceAtDate> itemIdOurPriceMap = new HashMap<Long,PriceAtDate>();
180
			Map<Long,PriceAtDate> itemIdSalePriceMap = new HashMap<Long,PriceAtDate>();
199
			Map<Long,PriceAtDate> itemIdSalePriceMap = new HashMap<Long,PriceAtDate>();
181
			Map<Long,PriceAtDate> itemIdminFBAPriceMap = new HashMap<Long,PriceAtDate>();
200
			Map<Long,PriceAtDate> itemIdminFBAPriceMap = new HashMap<Long,PriceAtDate>();
182
			Map<Long,PriceAtDate> itemIdminMFNPriceMap = new HashMap<Long,PriceAtDate>();
201
			Map<Long,PriceAtDate> itemIdminMFNPriceMap = new HashMap<Long,PriceAtDate>();
183
			count=1;
202
			count=1;
184
			while ((nextLine = inventoryhealthreportreader.readNext()) != null ) {
203
			while ((nextLine = inventoryhealthreportreader.readNext()) != null ) {
-
 
204
				try{
185
				if(count!=1){
205
					if(count!=1){
186
					System.out.println(nextLine[0] + " " + nextLine[1]);
-
 
187
					System.out.println(nextLine[30]);
-
 
188
					System.out.println(nextLine[31]);
-
 
189
					System.out.println(nextLine[32]);
-
 
190
					System.out.println(nextLine[34]);
-
 
191
					System.out.println(nextLine[1] +" "+ nextLine[31] +" " + nextLine[32] + " " + nextLine[34]);
206
						//System.out.println(nextLine[1] +" "+ nextLine[31] +" " + nextLine[32] + " " + nextLine[34]);
192
					SimpleDateFormat istFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
207
						SimpleDateFormat istFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
193
					istFormatter .setLenient(false);
208
						istFormatter .setLenient(false);
194
					TimeZone zone= TimeZone.getTimeZone("GMT");
209
						TimeZone zone= TimeZone.getTimeZone("GMT");
195
					istFormatter.setTimeZone(zone);
210
						istFormatter.setTimeZone(zone);
196
					Date date = istFormatter.parse(nextLine[0]);
211
						Date date = istFormatter.parse(nextLine[0]);
197
					Long item_id = Long.parseLong(nextLine[1].replaceAll("FBA",""));
212
						Long item_id = Long.parseLong(nextLine[1].replaceAll("FBA",""));
198
					Double ourPrice = null;
213
						Double ourPrice = null;
199
					Double minFBAPrice= null;
214
						Double minFBAPrice= null;
200
					Double minMFNPrice= null;
215
						Double minMFNPrice= null;
201
					Double salePrice= null; 
216
						Double salePrice= null; 
202
					if(nextLine[30].length() >0){
217
						if(nextLine[30].length() >0){
203
						ourPrice = Double.parseDouble(nextLine[30]);
218
							ourPrice = Double.parseDouble(nextLine[30]);
204
						if(itemIdOurPriceMap.containsKey(item_id)){
219
							if(itemIdOurPriceMap.containsKey(item_id)){
205
							if(itemIdOurPriceMap.get(item_id).getDate().getTime() < date.getTime()){
220
								if(itemIdOurPriceMap.get(item_id).getDate().getTime() < date.getTime()){
-
 
221
									PriceAtDate priceAtDate= new PriceAtDate();
-
 
222
									priceAtDate.setDate(date);
-
 
223
									priceAtDate.setPrice(ourPrice);
-
 
224
									itemIdOurPriceMap.put(item_id,priceAtDate);
-
 
225
								}
-
 
226
							}
-
 
227
							else{	
206
								PriceAtDate priceAtDate= new PriceAtDate();
228
								PriceAtDate priceAtDate= new PriceAtDate();
207
								priceAtDate.setDate(date);
229
								priceAtDate.setDate(date);
208
								priceAtDate.setPrice(ourPrice);
230
								priceAtDate.setPrice(ourPrice);
209
								itemIdOurPriceMap.put(item_id,priceAtDate);
231
								itemIdOurPriceMap.put(item_id,priceAtDate);
210
							}
232
							}
211
						}
233
						}
212
						else{	
234
						if(nextLine[31].length() >0){
-
 
235
							salePrice = Double.parseDouble(nextLine[31]);
-
 
236
							if(itemIdSalePriceMap.containsKey(item_id) ){
-
 
237
								if(itemIdSalePriceMap.get(item_id).getDate().getTime() < date.getTime()){
213
							PriceAtDate priceAtDate= new PriceAtDate();
238
									PriceAtDate priceAtDate= new PriceAtDate();
214
							priceAtDate.setDate(date);
239
									priceAtDate.setDate(date);
215
							priceAtDate.setPrice(ourPrice);
240
									priceAtDate.setPrice(salePrice);
216
							itemIdOurPriceMap.put(item_id,priceAtDate);
241
									itemIdSalePriceMap.put(item_id,priceAtDate);
217
						}
242
								}
218
					}
243
							}
219
					if(nextLine[31].length() >0){
244
							else{	
220
						salePrice = Double.parseDouble(nextLine[31]);
-
 
221
						if(itemIdSalePriceMap.containsKey(item_id) ){
-
 
222
							if(itemIdSalePriceMap.get(item_id).getDate().getTime() < date.getTime()){
-
 
223
								PriceAtDate priceAtDate= new PriceAtDate();
245
								PriceAtDate priceAtDate= new PriceAtDate();
224
								priceAtDate.setDate(date);
246
								priceAtDate.setDate(date);
225
								priceAtDate.setPrice(salePrice);
247
								priceAtDate.setPrice(salePrice);
226
								itemIdSalePriceMap.put(item_id,priceAtDate);
248
								itemIdSalePriceMap.put(item_id,priceAtDate);
227
							}
249
							}
228
						}
250
						}
229
						else{	
251
						if(nextLine[32].length() >0){
-
 
252
							minFBAPrice = Double.parseDouble(nextLine[32]);
-
 
253
							if(itemIdminFBAPriceMap.containsKey(item_id)){
-
 
254
								if(itemIdminFBAPriceMap.get(item_id).getDate().getTime() < date.getTime()){
230
							PriceAtDate priceAtDate= new PriceAtDate();
255
									PriceAtDate priceAtDate= new PriceAtDate();
231
							priceAtDate.setDate(date);
256
									priceAtDate.setDate(date);
232
							priceAtDate.setPrice(salePrice);
257
									priceAtDate.setPrice(minFBAPrice);
233
							itemIdSalePriceMap.put(item_id,priceAtDate);
258
									itemIdminFBAPriceMap.put(item_id,priceAtDate);
234
						}
259
								}
235
					}
260
							}
236
					if(nextLine[32].length() >0){
261
							else{	
237
						minFBAPrice = Double.parseDouble(nextLine[32]);
-
 
238
						if(itemIdminFBAPriceMap.containsKey(item_id)){
-
 
239
							if(itemIdminFBAPriceMap.get(item_id).getDate().getTime() < date.getTime()){
-
 
240
								PriceAtDate priceAtDate= new PriceAtDate();
262
								PriceAtDate priceAtDate= new PriceAtDate();
241
								priceAtDate.setDate(date);
263
								priceAtDate.setDate(date);
242
								priceAtDate.setPrice(minFBAPrice);
264
								priceAtDate.setPrice(minFBAPrice);
243
								itemIdminFBAPriceMap.put(item_id,priceAtDate);
265
								itemIdminFBAPriceMap.put(item_id,priceAtDate);
244
							}
266
							}
245
						}
267
						}
246
						else{	
268
						if(nextLine[34].length() >0){
-
 
269
							minMFNPrice = Double.parseDouble(nextLine[34]);
-
 
270
							if(itemIdminMFNPriceMap.containsKey(item_id)){
-
 
271
								if(itemIdminMFNPriceMap.get(item_id).getDate().getTime() < date.getTime()){
247
							PriceAtDate priceAtDate= new PriceAtDate();
272
									PriceAtDate priceAtDate= new PriceAtDate();
248
							priceAtDate.setDate(date);
273
									priceAtDate.setDate(date);
249
							priceAtDate.setPrice(minFBAPrice);
274
									priceAtDate.setPrice(minMFNPrice);
250
							itemIdminFBAPriceMap.put(item_id,priceAtDate);
275
									itemIdminMFNPriceMap.put(item_id,priceAtDate);
251
						}
276
								}
252
					}
277
							}
253
					if(nextLine[34].length() >0){
278
							else{	
254
						minMFNPrice = Double.parseDouble(nextLine[34]);
-
 
255
						if(itemIdminMFNPriceMap.containsKey(item_id)){
-
 
256
							if(itemIdminMFNPriceMap.get(item_id).getDate().getTime() < date.getTime()){
-
 
257
								PriceAtDate priceAtDate= new PriceAtDate();
279
								PriceAtDate priceAtDate= new PriceAtDate();
258
								priceAtDate.setDate(date);
280
								priceAtDate.setDate(date);
259
								priceAtDate.setPrice(minMFNPrice);
281
								priceAtDate.setPrice(minMFNPrice);
260
								itemIdminMFNPriceMap.put(item_id,priceAtDate);
282
								itemIdminMFNPriceMap.put(item_id,priceAtDate);
261
							}
283
							}
262
						}
284
						}
263
						else{	
-
 
264
							PriceAtDate priceAtDate= new PriceAtDate();
-
 
265
							priceAtDate.setDate(date);
-
 
266
							priceAtDate.setPrice(minMFNPrice);
-
 
267
							itemIdminMFNPriceMap.put(item_id,priceAtDate);
-
 
268
						}
-
 
269
					}
285
					}
270
				}
286
				}
-
 
287
				catch(Exception e){
-
 
288
					e.printStackTrace();
-
 
289
				}
271
				count++;
290
				count++;
272
			}
291
			}
273
			boolean oos;
292
			boolean oos;
274
			for (Entry<Date, Map<Long, FbaSalesSnapshot>> entry : orderDateItemIdFbaSaleSnapshotMap.entrySet()){
293
			for (Entry<Date, Map<Long, FbaSalesSnapshot>> entry : orderDateItemIdFbaSaleSnapshotMap.entrySet()){
275
				Date orderDate = entry.getKey();
294
				Date orderDate = entry.getKey();
Line 331... Line 350...
331
					}
350
					}
332
					amazonfbasalessnapshot.setAmazonFbaInventory(inventory);
351
					amazonfbasalessnapshot.setAmazonFbaInventory(inventory);
333
					transactionClient.addOrUpdateAmazonFbaSalesSnapshot(amazonfbasalessnapshot);
352
					transactionClient.addOrUpdateAmazonFbaSalesSnapshot(amazonfbasalessnapshot);
334
				}
353
				}
335
			}
354
			}
-
 
355
		}
-
 
356
		
336
		} catch (IOException e) {
357
		catch (IOException e) {
337
			// TODO Auto-generated catch block
358
			// TODO Auto-generated catch block
338
			e.printStackTrace();
359
			e.printStackTrace();
339
		} catch (ParseException e) {
360
		} catch (ParseException e) {
340
			// TODO Auto-generated catch block
361
			// TODO Auto-generated catch block
341
			e.printStackTrace();
362
			e.printStackTrace();
342
		} catch (TException e) {
363
		} catch (TException e) {
343
			// TODO Auto-generated catch block
364
			// TODO Auto-generated catch block
344
			e.printStackTrace();
365
			e.printStackTrace();
-
 
366
		}catch (Exception e) {
-
 
367
			// TODO Auto-generated catch block
-
 
368
			e.printStackTrace();
345
		}
369
		}
-
 
370
 
346
	}
371
	}
347
 
372
 
348
	public static Double getPercentageDifferenceFromMinimumPrice(AmazonFbaSalesSnapshot snapshot){
373
	public static Double getPercentageDifferenceFromMinimumPrice(AmazonFbaSalesSnapshot snapshot){
349
		Double minPrice = getMinimumSalePriceOnAmazonFBA(snapshot);
374
		Double minPrice = getMinimumSalePriceOnAmazonFBA(snapshot);
350
		return (((minPrice - snapshot.getOurPrice())/snapshot.getOurPrice())*100);
375
		return (((minPrice - snapshot.getOurPrice())/snapshot.getOurPrice())*100);