| 8363 |
vikram.rag |
1 |
package com.amazonaws.mws.samples;
|
|
|
2 |
|
|
|
3 |
import in.shop2020.model.v1.catalog.Amazonlisted;
|
|
|
4 |
import in.shop2020.model.v1.catalog.CatalogServiceException;
|
|
|
5 |
import in.shop2020.model.v1.catalog.Item;
|
|
|
6 |
import in.shop2020.model.v1.inventory.AmazonFbaInventorySnapshot;
|
|
|
7 |
import in.shop2020.model.v1.inventory.InventoryServiceException;
|
|
|
8 |
import in.shop2020.model.v1.inventory.Vendor;
|
|
|
9 |
import in.shop2020.model.v1.inventory.VendorItemPricing;
|
|
|
10 |
import in.shop2020.model.v1.order.AmazonFbaSalesSnapshot;
|
|
|
11 |
import in.shop2020.model.v1.order.TransactionService.Client;
|
|
|
12 |
import in.shop2020.thrift.clients.CatalogClient;
|
|
|
13 |
import in.shop2020.thrift.clients.InventoryClient;
|
|
|
14 |
import in.shop2020.thrift.clients.TransactionClient;
|
|
|
15 |
|
|
|
16 |
import java.io.FileNotFoundException;
|
|
|
17 |
import java.io.FileOutputStream;
|
|
|
18 |
import java.io.FileReader;
|
|
|
19 |
import java.io.IOException;
|
| 8825 |
vikram.rag |
20 |
import java.io.OutputStream;
|
| 8363 |
vikram.rag |
21 |
import java.text.ParseException;
|
|
|
22 |
import java.text.SimpleDateFormat;
|
|
|
23 |
import java.util.ArrayList;
|
| 8825 |
vikram.rag |
24 |
import java.util.Calendar;
|
| 8363 |
vikram.rag |
25 |
import java.util.Date;
|
|
|
26 |
import java.util.HashMap;
|
|
|
27 |
import java.util.List;
|
|
|
28 |
import java.util.Map;
|
|
|
29 |
import java.util.Map.Entry;
|
|
|
30 |
import java.util.TimeZone;
|
|
|
31 |
|
|
|
32 |
import org.apache.poi.hssf.usermodel.HSSFRow;
|
|
|
33 |
import org.apache.poi.hssf.usermodel.HSSFSheet;
|
|
|
34 |
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
35 |
import org.apache.thrift.TException;
|
|
|
36 |
|
|
|
37 |
import au.com.bytecode.opencsv.CSVReader;
|
|
|
38 |
|
|
|
39 |
public class FileParser {
|
|
|
40 |
public static void main(String... args){
|
|
|
41 |
CSVReader orderreportreader = null;
|
|
|
42 |
CSVReader inventoryhealthreportreader = null;
|
|
|
43 |
try {
|
| 8438 |
vikram.rag |
44 |
orderreportreader = new CSVReader(new FileReader("/home/amazonorderreport.csv"),'\t');
|
|
|
45 |
inventoryhealthreportreader = new CSVReader(new FileReader("/home/inventoryhealthreport.csv"),'\t');
|
| 8363 |
vikram.rag |
46 |
} catch (FileNotFoundException e) {
|
|
|
47 |
// TODO Auto-generated catch block
|
|
|
48 |
e.printStackTrace();
|
|
|
49 |
}
|
|
|
50 |
String [] nextLine;
|
|
|
51 |
try {
|
|
|
52 |
int count =1;
|
|
|
53 |
Map<Date,Map<Long,FbaSalesSnapshot>> orderDateItemIdFbaSaleSnapshotMap = new HashMap<Date,Map<Long,FbaSalesSnapshot>>();
|
| 9757 |
vikram.rag |
54 |
while ((nextLine = orderreportreader.readNext()) != null) {
|
|
|
55 |
if(count!=1 && nextLine[5].equalsIgnoreCase("Amazon") && nextLine[6].equalsIgnoreCase("Amazon.in")){
|
|
|
56 |
SimpleDateFormat istFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
|
|
|
57 |
istFormatter .setLenient(false);
|
|
|
58 |
TimeZone zone= TimeZone.getTimeZone("GMT");
|
|
|
59 |
istFormatter.setTimeZone(zone);
|
|
|
60 |
Date date = istFormatter.parse(nextLine[2]);
|
|
|
61 |
SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
|
|
|
62 |
Date date_key = dateFormat.parse(dateFormat.format(date));
|
|
|
63 |
System.out.println("Order Details " + nextLine[0]+" "+date_key+" "+ nextLine[11] +" " + nextLine[14] + " " + nextLine[4] + " " + nextLine[13] );
|
|
|
64 |
Long itemid = Long.parseLong(nextLine[11].replaceAll("FBA",""));
|
|
|
65 |
Integer qty=0;
|
|
|
66 |
if(nextLine[14].length()!=0){
|
|
|
67 |
qty = new Integer(nextLine[14]);
|
|
|
68 |
}
|
|
|
69 |
Float itemSale = null;
|
|
|
70 |
if(nextLine[16].length()!=0){
|
|
|
71 |
itemSale = new Float(nextLine[16]);
|
|
|
72 |
}
|
|
|
73 |
else{
|
|
|
74 |
itemSale = (float) 0;
|
|
|
75 |
}
|
|
|
76 |
Float itemDiscount;
|
|
|
77 |
if(nextLine[22].length()!=0){
|
|
|
78 |
itemDiscount = new Float(nextLine[22]);
|
|
|
79 |
}
|
|
|
80 |
else{
|
|
|
81 |
itemDiscount = new Float(0);
|
|
|
82 |
}
|
|
|
83 |
if(nextLine[4].equalsIgnoreCase("Cancelled") || nextLine[13].equalsIgnoreCase("Cancelled")){
|
|
|
84 |
itemSale = (float) 0;
|
|
|
85 |
itemDiscount = (float) 0;
|
|
|
86 |
qty = 0;
|
|
|
87 |
}
|
|
|
88 |
System.out.println("Order Details after parsing " + nextLine[0]+" "+date_key+" "+ itemid +" " + qty);
|
|
|
89 |
if(orderDateItemIdFbaSaleSnapshotMap.containsKey(date_key)){
|
|
|
90 |
Map<Long,FbaSalesSnapshot> ItemIdFbaSaleSnapshotMap;
|
|
|
91 |
if(orderDateItemIdFbaSaleSnapshotMap.get(date_key).containsKey(itemid)){
|
|
|
92 |
FbaSalesSnapshot fbaSalesSnapshot = orderDateItemIdFbaSaleSnapshotMap.get(date_key).get(itemid);
|
|
|
93 |
if(itemDiscount!=0){
|
|
|
94 |
fbaSalesSnapshot.setPromotionOrderCount(fbaSalesSnapshot.getPromotionOrderCount()+qty);
|
|
|
95 |
fbaSalesSnapshot.setTotalPromotionSale(fbaSalesSnapshot.getTotalPromotionSale() + (itemSale - itemDiscount));
|
|
|
96 |
}
|
|
|
97 |
fbaSalesSnapshot.setTotalOrderCount(fbaSalesSnapshot.getTotalOrderCount() + qty);
|
|
|
98 |
fbaSalesSnapshot.setTotalSale(fbaSalesSnapshot.getTotalSale() + itemSale - itemDiscount);
|
|
|
99 |
ItemIdFbaSaleSnapshotMap = orderDateItemIdFbaSaleSnapshotMap.get(date_key);
|
|
|
100 |
ItemIdFbaSaleSnapshotMap.put(itemid,fbaSalesSnapshot);
|
|
|
101 |
orderDateItemIdFbaSaleSnapshotMap.put(date_key,ItemIdFbaSaleSnapshotMap);
|
| 8825 |
vikram.rag |
102 |
}
|
| 9757 |
vikram.rag |
103 |
else{
|
|
|
104 |
FbaSalesSnapshot fbaSalesSnapshot = new FbaSalesSnapshot();
|
|
|
105 |
fbaSalesSnapshot.setTotalOrderCount(qty);
|
|
|
106 |
fbaSalesSnapshot.setTotalSale(itemSale - itemDiscount);
|
|
|
107 |
if(itemDiscount!=0){
|
|
|
108 |
fbaSalesSnapshot.setPromotionOrderCount(qty);
|
|
|
109 |
fbaSalesSnapshot.setTotalPromotionSale(itemSale - itemDiscount);
|
|
|
110 |
}
|
|
|
111 |
else{
|
|
|
112 |
fbaSalesSnapshot.setPromotionOrderCount(0);
|
|
|
113 |
fbaSalesSnapshot.setTotalPromotionSale((float) 0);
|
|
|
114 |
}
|
|
|
115 |
ItemIdFbaSaleSnapshotMap = orderDateItemIdFbaSaleSnapshotMap.get(date_key);
|
|
|
116 |
ItemIdFbaSaleSnapshotMap.put(itemid,fbaSalesSnapshot);
|
|
|
117 |
orderDateItemIdFbaSaleSnapshotMap.put(date_key,ItemIdFbaSaleSnapshotMap);
|
|
|
118 |
}
|
| 9756 |
vikram.rag |
119 |
}
|
|
|
120 |
else{
|
| 9757 |
vikram.rag |
121 |
Map<Long,FbaSalesSnapshot> ItemIdFbaSaleSnapshotMap = new HashMap<Long,FbaSalesSnapshot>();
|
| 9756 |
vikram.rag |
122 |
FbaSalesSnapshot fbaSalesSnapshot = new FbaSalesSnapshot();
|
|
|
123 |
fbaSalesSnapshot.setTotalOrderCount(qty);
|
| 9757 |
vikram.rag |
124 |
fbaSalesSnapshot.setTotalSale(itemSale);
|
| 9756 |
vikram.rag |
125 |
if(itemDiscount!=0){
|
| 9757 |
vikram.rag |
126 |
fbaSalesSnapshot.setTotalPromotionSale(itemSale - itemDiscount);
|
| 9756 |
vikram.rag |
127 |
fbaSalesSnapshot.setPromotionOrderCount(qty);
|
|
|
128 |
}
|
| 8825 |
vikram.rag |
129 |
else{
|
| 9757 |
vikram.rag |
130 |
fbaSalesSnapshot.setTotalPromotionSale((float) 0);
|
| 8363 |
vikram.rag |
131 |
fbaSalesSnapshot.setPromotionOrderCount(0);
|
|
|
132 |
}
|
| 9757 |
vikram.rag |
133 |
ItemIdFbaSaleSnapshotMap.put(itemid,fbaSalesSnapshot);
|
| 9756 |
vikram.rag |
134 |
orderDateItemIdFbaSaleSnapshotMap.put(date_key,ItemIdFbaSaleSnapshotMap);
|
| 8363 |
vikram.rag |
135 |
}
|
|
|
136 |
}
|
| 9757 |
vikram.rag |
137 |
count++;
|
| 8363 |
vikram.rag |
138 |
}
|
| 9757 |
vikram.rag |
139 |
InventoryClient inventoryServiceClient = null;
|
|
|
140 |
TransactionClient transactionServiceClient = null;
|
|
|
141 |
CatalogClient catalogServiceClient = null;
|
|
|
142 |
try {
|
|
|
143 |
inventoryServiceClient = new InventoryClient();
|
|
|
144 |
transactionServiceClient = new TransactionClient();
|
| 10533 |
vikram.rag |
145 |
//catalogServiceClient = new CatalogClient();
|
|
|
146 |
catalogServiceClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port");
|
| 9757 |
vikram.rag |
147 |
} catch (Exception e) {
|
|
|
148 |
// TODO Auto-generated catch block
|
|
|
149 |
e.printStackTrace();
|
|
|
150 |
}
|
|
|
151 |
in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
|
|
|
152 |
in.shop2020.model.v1.order.TransactionService.Client transactionClient = transactionServiceClient.getClient();
|
|
|
153 |
in.shop2020.model.v1.catalog.CatalogService.Client catalogClient = catalogServiceClient.getClient();
|
|
|
154 |
SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
|
|
|
155 |
//Date date_today = dateFormat.parse(dateFormat.format(new Date()));
|
|
|
156 |
List<Date> dates = new ArrayList<Date>();
|
|
|
157 |
Calendar cal = Calendar.getInstance();
|
|
|
158 |
cal.add(Calendar.DATE, -1);
|
|
|
159 |
Date date_end = dateFormat.parse(dateFormat.format(cal.getTime()));
|
|
|
160 |
cal.add(Calendar.DATE, -5);
|
|
|
161 |
Date date_start = dateFormat.parse(dateFormat.format(cal.getTime()));
|
|
|
162 |
//System.out.println("Start Date = " + date_start);
|
|
|
163 |
//System.out.println("End Date = " + date_end);
|
|
|
164 |
Date d = date_start;
|
|
|
165 |
while(!d.equals(date_end)){
|
|
|
166 |
cal.setTime(d);
|
|
|
167 |
cal.add(Calendar.DATE,1);
|
|
|
168 |
d = cal.getTime();
|
|
|
169 |
dates.add(d);
|
|
|
170 |
}
|
|
|
171 |
List<AmazonFbaInventorySnapshot> nonzeroFbaInventorySnapshotlist = inventoryClient.getAllAmazonFbaItemInventory();
|
|
|
172 |
for(Date date:dates){
|
|
|
173 |
if(nonzeroFbaInventorySnapshotlist!=null){
|
|
|
174 |
for(AmazonFbaInventorySnapshot amazonFbaInventory:nonzeroFbaInventorySnapshotlist){
|
|
|
175 |
if(orderDateItemIdFbaSaleSnapshotMap.containsKey(date) ){
|
|
|
176 |
if(!orderDateItemIdFbaSaleSnapshotMap.get(date).containsKey(amazonFbaInventory.getItem_id())){
|
|
|
177 |
Map<Long,FbaSalesSnapshot> ItemIdFbaSaleSnapshotMap = new HashMap<Long,FbaSalesSnapshot>();
|
|
|
178 |
FbaSalesSnapshot fbaSalesSnapshot = new FbaSalesSnapshot();
|
|
|
179 |
fbaSalesSnapshot.setTotalOrderCount(0);
|
|
|
180 |
fbaSalesSnapshot.setPromotionOrderCount(0);
|
|
|
181 |
fbaSalesSnapshot.setTotalPromotionSale((float) 0);
|
|
|
182 |
fbaSalesSnapshot.setTotalSale((float) 0);
|
|
|
183 |
ItemIdFbaSaleSnapshotMap.put(amazonFbaInventory.getItem_id(),fbaSalesSnapshot);
|
|
|
184 |
orderDateItemIdFbaSaleSnapshotMap.get(date).put(amazonFbaInventory.getItem_id(),fbaSalesSnapshot);
|
|
|
185 |
}
|
|
|
186 |
|
|
|
187 |
}
|
|
|
188 |
else{
|
|
|
189 |
Map<Long,FbaSalesSnapshot> ItemIdFbaSaleSnapshotMap = new HashMap<Long,FbaSalesSnapshot>();
|
|
|
190 |
FbaSalesSnapshot fbaSalesSnapshot = new FbaSalesSnapshot();
|
|
|
191 |
fbaSalesSnapshot.setTotalOrderCount(0);
|
|
|
192 |
fbaSalesSnapshot.setPromotionOrderCount(0);
|
|
|
193 |
fbaSalesSnapshot.setTotalPromotionSale((float) 0);
|
|
|
194 |
fbaSalesSnapshot.setTotalSale((float) 0);
|
|
|
195 |
ItemIdFbaSaleSnapshotMap.put(amazonFbaInventory.getItem_id(),fbaSalesSnapshot);
|
|
|
196 |
orderDateItemIdFbaSaleSnapshotMap.put(date,ItemIdFbaSaleSnapshotMap);
|
|
|
197 |
}
|
| 8451 |
vikram.rag |
198 |
}
|
| 8363 |
vikram.rag |
199 |
}
|
| 9756 |
vikram.rag |
200 |
else{
|
| 9757 |
vikram.rag |
201 |
System.out.println("No inventory in FBA");
|
| 8825 |
vikram.rag |
202 |
}
|
| 8363 |
vikram.rag |
203 |
}
|
| 9757 |
vikram.rag |
204 |
Map<Long,PriceAtDate> itemIdOurPriceMap = new HashMap<Long,PriceAtDate>();
|
|
|
205 |
Map<Long,PriceAtDate> itemIdSalePriceMap = new HashMap<Long,PriceAtDate>();
|
|
|
206 |
Map<Long,PriceAtDate> itemIdminFBAPriceMap = new HashMap<Long,PriceAtDate>();
|
|
|
207 |
Map<Long,PriceAtDate> itemIdminMFNPriceMap = new HashMap<Long,PriceAtDate>();
|
|
|
208 |
count=1;
|
|
|
209 |
while ((nextLine = inventoryhealthreportreader.readNext()) != null ) {
|
|
|
210 |
try{
|
|
|
211 |
if(count!=1){
|
|
|
212 |
//System.out.println(nextLine[1] +" "+ nextLine[31] +" " + nextLine[32] + " " + nextLine[34]);
|
|
|
213 |
SimpleDateFormat istFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
|
|
|
214 |
istFormatter .setLenient(false);
|
|
|
215 |
TimeZone zone= TimeZone.getTimeZone("GMT");
|
|
|
216 |
istFormatter.setTimeZone(zone);
|
|
|
217 |
Date date = istFormatter.parse(nextLine[0]);
|
|
|
218 |
Long item_id = Long.parseLong(nextLine[1].replaceAll("FBA",""));
|
|
|
219 |
Double ourPrice = null;
|
|
|
220 |
Double minFBAPrice= null;
|
|
|
221 |
Double minMFNPrice= null;
|
|
|
222 |
Double salePrice= null;
|
|
|
223 |
if(nextLine[30].length() >0){
|
|
|
224 |
ourPrice = Double.parseDouble(nextLine[30]);
|
|
|
225 |
if(itemIdOurPriceMap.containsKey(item_id)){
|
|
|
226 |
if(itemIdOurPriceMap.get(item_id).getDate().getTime() < date.getTime()){
|
|
|
227 |
PriceAtDate priceAtDate= new PriceAtDate();
|
|
|
228 |
priceAtDate.setDate(date);
|
|
|
229 |
priceAtDate.setPrice(ourPrice);
|
|
|
230 |
itemIdOurPriceMap.put(item_id,priceAtDate);
|
|
|
231 |
}
|
|
|
232 |
}
|
|
|
233 |
else{
|
|
|
234 |
PriceAtDate priceAtDate= new PriceAtDate();
|
|
|
235 |
priceAtDate.setDate(date);
|
|
|
236 |
priceAtDate.setPrice(ourPrice);
|
|
|
237 |
itemIdOurPriceMap.put(item_id,priceAtDate);
|
|
|
238 |
}
|
| 9756 |
vikram.rag |
239 |
}
|
| 9757 |
vikram.rag |
240 |
if(nextLine[31].length() >0){
|
|
|
241 |
salePrice = Double.parseDouble(nextLine[31]);
|
|
|
242 |
if(itemIdSalePriceMap.containsKey(item_id) ){
|
|
|
243 |
if(itemIdSalePriceMap.get(item_id).getDate().getTime() < date.getTime()){
|
|
|
244 |
PriceAtDate priceAtDate= new PriceAtDate();
|
|
|
245 |
priceAtDate.setDate(date);
|
|
|
246 |
priceAtDate.setPrice(salePrice);
|
|
|
247 |
itemIdSalePriceMap.put(item_id,priceAtDate);
|
|
|
248 |
}
|
|
|
249 |
}
|
|
|
250 |
else{
|
|
|
251 |
PriceAtDate priceAtDate= new PriceAtDate();
|
|
|
252 |
priceAtDate.setDate(date);
|
|
|
253 |
priceAtDate.setPrice(salePrice);
|
|
|
254 |
itemIdSalePriceMap.put(item_id,priceAtDate);
|
|
|
255 |
}
|
|
|
256 |
}
|
|
|
257 |
if(nextLine[32].length() >0){
|
|
|
258 |
minFBAPrice = Double.parseDouble(nextLine[32]);
|
|
|
259 |
if(itemIdminFBAPriceMap.containsKey(item_id)){
|
|
|
260 |
if(itemIdminFBAPriceMap.get(item_id).getDate().getTime() < date.getTime()){
|
|
|
261 |
PriceAtDate priceAtDate= new PriceAtDate();
|
|
|
262 |
priceAtDate.setDate(date);
|
|
|
263 |
priceAtDate.setPrice(minFBAPrice);
|
|
|
264 |
itemIdminFBAPriceMap.put(item_id,priceAtDate);
|
|
|
265 |
}
|
|
|
266 |
}
|
|
|
267 |
else{
|
|
|
268 |
PriceAtDate priceAtDate= new PriceAtDate();
|
|
|
269 |
priceAtDate.setDate(date);
|
|
|
270 |
priceAtDate.setPrice(minFBAPrice);
|
|
|
271 |
itemIdminFBAPriceMap.put(item_id,priceAtDate);
|
|
|
272 |
}
|
|
|
273 |
}
|
|
|
274 |
if(nextLine[34].length() >0){
|
|
|
275 |
minMFNPrice = Double.parseDouble(nextLine[34]);
|
|
|
276 |
if(itemIdminMFNPriceMap.containsKey(item_id)){
|
|
|
277 |
if(itemIdminMFNPriceMap.get(item_id).getDate().getTime() < date.getTime()){
|
|
|
278 |
PriceAtDate priceAtDate= new PriceAtDate();
|
|
|
279 |
priceAtDate.setDate(date);
|
|
|
280 |
priceAtDate.setPrice(minMFNPrice);
|
|
|
281 |
itemIdminMFNPriceMap.put(item_id,priceAtDate);
|
|
|
282 |
}
|
|
|
283 |
}
|
|
|
284 |
else{
|
|
|
285 |
PriceAtDate priceAtDate= new PriceAtDate();
|
|
|
286 |
priceAtDate.setDate(date);
|
|
|
287 |
priceAtDate.setPrice(minMFNPrice);
|
|
|
288 |
itemIdminMFNPriceMap.put(item_id,priceAtDate);
|
|
|
289 |
}
|
|
|
290 |
}
|
| 8363 |
vikram.rag |
291 |
}
|
| 9756 |
vikram.rag |
292 |
}
|
| 9757 |
vikram.rag |
293 |
catch(Exception e){
|
|
|
294 |
e.printStackTrace();
|
|
|
295 |
}
|
|
|
296 |
count++;
|
|
|
297 |
}
|
|
|
298 |
boolean oos;
|
| 9802 |
manish.sha |
299 |
List<AmazonFbaSalesSnapshot> fbaSalesSnapShotList = new ArrayList<AmazonFbaSalesSnapshot>();
|
| 9757 |
vikram.rag |
300 |
for (Entry<Date, Map<Long, FbaSalesSnapshot>> entry : orderDateItemIdFbaSaleSnapshotMap.entrySet()){
|
|
|
301 |
Date orderDate = entry.getKey();
|
|
|
302 |
for(Entry<Long, FbaSalesSnapshot> entry1 :entry.getValue().entrySet()){
|
|
|
303 |
//System.out.println("Item ID is " + entry1.getKey());
|
|
|
304 |
Long inventory = inventoryClient.getAmazonFbaItemInventory(entry1.getKey());
|
|
|
305 |
|
|
|
306 |
if(inventory==0 && entry1.getValue().getTotalOrderCount()==0){
|
|
|
307 |
oos=true;
|
| 8534 |
vikram.rag |
308 |
}
|
| 9757 |
vikram.rag |
309 |
else{
|
|
|
310 |
oos=false;
|
| 8363 |
vikram.rag |
311 |
}
|
| 9757 |
vikram.rag |
312 |
Long item_id = entry1.getKey();
|
|
|
313 |
Amazonlisted amazon_item=catalogClient.getAmazonItemDetails(item_id);
|
|
|
314 |
if(amazon_item.getItemid()==0){
|
|
|
315 |
continue;
|
| 8363 |
vikram.rag |
316 |
}
|
| 9757 |
vikram.rag |
317 |
//System.out.println(orderDate +","+entry1.getKey()+","+entry1.getValue()+","+ inventory +","+ oos+","+itemIdSalePriceMap.get(item_id)+","+itemIdminFBAPriceMap.get(item_id)+","+itemIdminMFNPriceMap.get(item_id));
|
|
|
318 |
AmazonFbaSalesSnapshot amazonfbasalessnapshot = new AmazonFbaSalesSnapshot();
|
|
|
319 |
amazonfbasalessnapshot.setDateOfSale(orderDate.getTime());
|
|
|
320 |
amazonfbasalessnapshot.setItem_id(entry1.getKey());
|
|
|
321 |
amazonfbasalessnapshot.setTotalOrderCount(entry1.getValue().getPromotionOrderCount());
|
|
|
322 |
amazonfbasalessnapshot.setTotalOrderCount(entry1.getValue().getTotalOrderCount());
|
|
|
323 |
amazonfbasalessnapshot.setTotalSale(entry1.getValue().getTotalSale());
|
|
|
324 |
amazonfbasalessnapshot.setPromotionSale(entry1.getValue().getTotalPromotionSale());
|
|
|
325 |
amazonfbasalessnapshot.setIsOutOfStock(oos);
|
|
|
326 |
if(itemIdSalePriceMap.containsKey(item_id) && itemIdSalePriceMap.get(item_id).getPrice()!=0){
|
|
|
327 |
amazonfbasalessnapshot.setSalePrice(itemIdSalePriceMap.get(item_id).getPrice());
|
|
|
328 |
amazonfbasalessnapshot.setSalePriceSnapshotDate(itemIdSalePriceMap.get(item_id).getDate().getTime());
|
| 8363 |
vikram.rag |
329 |
}
|
| 9757 |
vikram.rag |
330 |
else{
|
|
|
331 |
amazonfbasalessnapshot.setSalePrice(0.0);
|
|
|
332 |
amazonfbasalessnapshot.setSalePriceSnapshotDate(0);
|
| 8363 |
vikram.rag |
333 |
}
|
| 9757 |
vikram.rag |
334 |
if(itemIdminMFNPriceMap.containsKey(item_id) && itemIdminMFNPriceMap.get(item_id).getPrice()!=0){
|
|
|
335 |
amazonfbasalessnapshot.setMinMfnPrice(itemIdminMFNPriceMap.get(item_id).getPrice());
|
|
|
336 |
amazonfbasalessnapshot.setMinMfnPriceSnapshotDate(itemIdminMFNPriceMap.get(item_id).getDate().getTime());
|
| 8363 |
vikram.rag |
337 |
}
|
| 9757 |
vikram.rag |
338 |
else{
|
|
|
339 |
amazonfbasalessnapshot.setMinMfnPrice(0.0);
|
|
|
340 |
amazonfbasalessnapshot.setMinMfnPriceSnapshotDate(0);
|
|
|
341 |
}
|
|
|
342 |
if(itemIdminFBAPriceMap.containsKey(item_id) && itemIdminFBAPriceMap.get(item_id).getPrice()!=0){
|
|
|
343 |
amazonfbasalessnapshot.setMinFbaPrice(itemIdminFBAPriceMap.get(item_id).getPrice());
|
|
|
344 |
amazonfbasalessnapshot.setMinFbaPriceSnapshotDate(itemIdminFBAPriceMap.get(item_id).getDate().getTime());
|
|
|
345 |
}
|
|
|
346 |
else{
|
|
|
347 |
amazonfbasalessnapshot.setMinFbaPrice(0.0);
|
|
|
348 |
amazonfbasalessnapshot.setMinFbaPriceSnapshotDate(0);
|
|
|
349 |
}
|
|
|
350 |
if(itemIdOurPriceMap.containsKey(item_id) && itemIdOurPriceMap.get(item_id).getPrice()!=0){
|
|
|
351 |
amazonfbasalessnapshot.setOurPrice(itemIdOurPriceMap.get(item_id).getPrice());
|
|
|
352 |
amazonfbasalessnapshot.setOurPriceSnapshotDate(itemIdOurPriceMap.get(item_id).getDate().getTime());
|
|
|
353 |
}
|
|
|
354 |
else{
|
|
|
355 |
amazonfbasalessnapshot.setOurPrice(amazon_item.getFbaPrice());
|
|
|
356 |
amazonfbasalessnapshot.setOurPriceSnapshotDate(0);
|
|
|
357 |
}
|
|
|
358 |
if(amazonfbasalessnapshot.getTotalOrderCount() > 0){
|
|
|
359 |
Date date = new Date(amazonfbasalessnapshot.getDateOfSale());
|
|
|
360 |
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
|
|
|
361 |
System.out.println(" Item details are " + sdf.format(date) + " "+ amazonfbasalessnapshot.getItem_id() + " " + amazonfbasalessnapshot.getTotalOrderCount());
|
|
|
362 |
}
|
|
|
363 |
amazonfbasalessnapshot.setAmazonFbaInventory(inventory);
|
| 9802 |
manish.sha |
364 |
fbaSalesSnapShotList.add(amazonfbasalessnapshot);
|
| 8363 |
vikram.rag |
365 |
}
|
|
|
366 |
}
|
| 9802 |
manish.sha |
367 |
transactionServiceClient.getClient().bulkAddOrUpdateAmazonFbaSalesSnapshot(fbaSalesSnapShotList);
|
| 9757 |
vikram.rag |
368 |
} catch (IOException e) {
|
|
|
369 |
// TODO Auto-generated catch block
|
|
|
370 |
e.printStackTrace();
|
|
|
371 |
} catch (ParseException e) {
|
|
|
372 |
// TODO Auto-generated catch block
|
|
|
373 |
e.printStackTrace();
|
|
|
374 |
} catch (TException e) {
|
|
|
375 |
// TODO Auto-generated catch block
|
|
|
376 |
e.printStackTrace();
|
| 9256 |
vikram.rag |
377 |
}
|
| 9757 |
vikram.rag |
378 |
catch (Exception e) {
|
|
|
379 |
// TODO Auto-generated catch block
|
| 8825 |
vikram.rag |
380 |
e.printStackTrace();
|
| 8363 |
vikram.rag |
381 |
}
|
| 8825 |
vikram.rag |
382 |
|
| 8363 |
vikram.rag |
383 |
}
|
|
|
384 |
|
| 9757 |
vikram.rag |
385 |
public static Double getPercentageDifferenceFromMinimumPrice(AmazonFbaSalesSnapshot snapshot){
|
|
|
386 |
Double minPrice = getMinimumSalePriceOnAmazonFBA(snapshot);
|
|
|
387 |
return (((minPrice - snapshot.getOurPrice())/snapshot.getOurPrice())*100);
|
| 8363 |
vikram.rag |
388 |
|
| 9757 |
vikram.rag |
389 |
}
|
| 8363 |
vikram.rag |
390 |
|
| 9757 |
vikram.rag |
391 |
public static Double getMinimumSalePriceOnAmazonFBA(AmazonFbaSalesSnapshot snapshot){
|
|
|
392 |
if(snapshot.getMinFbaPrice() > snapshot.getMinMfnPrice()){
|
|
|
393 |
return snapshot.getMinMfnPrice();
|
|
|
394 |
}
|
|
|
395 |
else{
|
|
|
396 |
return snapshot.getMinFbaPrice();
|
|
|
397 |
}
|
| 8363 |
vikram.rag |
398 |
}
|
|
|
399 |
|
|
|
400 |
}
|