| Line 33... |
Line 33... |
| 33 |
import org.apache.thrift.TException;
|
33 |
import org.apache.thrift.TException;
|
| 34 |
|
34 |
|
| 35 |
import au.com.bytecode.opencsv.CSVReader;
|
35 |
import au.com.bytecode.opencsv.CSVReader;
|
| 36 |
|
36 |
|
| 37 |
public class FileParser {
|
37 |
public class FileParser {
|
| 38 |
final public static String AMAZON_FBA_SHEET = "/home/vikram/Desktop/FBA-Stock-File.xls";
|
- |
|
| 39 |
public static void main(String... args){
|
38 |
public static void main(String... args){
|
| 40 |
CSVReader orderreportreader = null;
|
39 |
CSVReader orderreportreader = null;
|
| 41 |
CSVReader inventoryhealthreportreader = null;
|
40 |
CSVReader inventoryhealthreportreader = null;
|
| 42 |
try {
|
41 |
try {
|
| 43 |
orderreportreader = new CSVReader(new FileReader("/home/amazonorderreport.csv"),'\t');
|
42 |
orderreportreader = new CSVReader(new FileReader("/home/amazonorderreport.csv"),'\t');
|
| Line 49... |
Line 48... |
| 49 |
String [] nextLine;
|
48 |
String [] nextLine;
|
| 50 |
try {
|
49 |
try {
|
| 51 |
int count =1;
|
50 |
int count =1;
|
| 52 |
Map<Date,Map<Long,FbaSalesSnapshot>> orderDateItemIdFbaSaleSnapshotMap = new HashMap<Date,Map<Long,FbaSalesSnapshot>>();
|
51 |
Map<Date,Map<Long,FbaSalesSnapshot>> orderDateItemIdFbaSaleSnapshotMap = new HashMap<Date,Map<Long,FbaSalesSnapshot>>();
|
| 53 |
while ((nextLine = orderreportreader.readNext()) != null) {
|
52 |
while ((nextLine = orderreportreader.readNext()) != null) {
|
| 54 |
if(count!=1 && nextLine[5].equalsIgnoreCase("Amazon") && nextLine[6].equalsIgnoreCase("Amazon.in") && (nextLine[13].equalsIgnoreCase("Unshipped") || nextLine[13].equalsIgnoreCase("Shipped"))){
|
53 |
if(count!=1 && nextLine[5].equalsIgnoreCase("Amazon") && nextLine[6].equalsIgnoreCase("Amazon.in")){
|
| 55 |
SimpleDateFormat istFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
|
54 |
SimpleDateFormat istFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
|
| 56 |
istFormatter .setLenient(false);
|
55 |
istFormatter .setLenient(false);
|
| 57 |
TimeZone zone= TimeZone.getTimeZone("GMT");
|
56 |
TimeZone zone= TimeZone.getTimeZone("GMT");
|
| 58 |
istFormatter.setTimeZone(zone);
|
57 |
istFormatter.setTimeZone(zone);
|
| 59 |
Date date = istFormatter.parse(nextLine[2]);
|
58 |
Date date = istFormatter.parse(nextLine[2]);
|
| 60 |
SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
|
59 |
SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
|
| 61 |
Date date_key = dateFormat.parse(dateFormat.format(date));
|
60 |
Date date_key = dateFormat.parse(dateFormat.format(date));
|
| 62 |
System.out.println(nextLine[0]+" "+date_key+" "+ nextLine[11] +" " + nextLine[13] + " " + nextLine[14]);
|
61 |
System.out.println(nextLine[0]+" "+date_key+" "+ nextLine[11] +" " + nextLine[13] + " " + nextLine[14]);
|
| 63 |
Long itemid = Long.parseLong(nextLine[11].replaceAll("FBA",""));
|
62 |
Long itemid = Long.parseLong(nextLine[11].replaceAll("FBA",""));
|
| 64 |
|
- |
|
| - |
|
63 |
Integer qty=0;
|
| - |
|
64 |
if(nextLine[14].length()!=0){
|
| 65 |
Integer qty = new Integer(nextLine[14]);
|
65 |
qty = new Integer(nextLine[14]);
|
| - |
|
66 |
}
|
| 66 |
Float itemSale = null;
|
67 |
Float itemSale = null;
|
| 67 |
if(nextLine[16].length()!=0){
|
68 |
if(nextLine[16].length()!=0){
|
| 68 |
itemSale = new Float(nextLine[16]);
|
69 |
itemSale = new Float(nextLine[16]);
|
| 69 |
}
|
70 |
}
|
| 70 |
else{
|
71 |
else{
|
| Line 75... |
Line 76... |
| 75 |
itemDiscount = new Float(nextLine[22]);
|
76 |
itemDiscount = new Float(nextLine[22]);
|
| 76 |
}
|
77 |
}
|
| 77 |
else{
|
78 |
else{
|
| 78 |
itemDiscount = new Float(0);
|
79 |
itemDiscount = new Float(0);
|
| 79 |
}
|
80 |
}
|
| - |
|
81 |
if(nextLine[4].equalsIgnoreCase("Cancelled") || nextLine[4].equalsIgnoreCase("Cancelled")){
|
| - |
|
82 |
itemSale = (float) 0;
|
| - |
|
83 |
itemDiscount = (float) 0;
|
| - |
|
84 |
qty = 0;
|
| - |
|
85 |
}
|
| 80 |
if(orderDateItemIdFbaSaleSnapshotMap.containsKey(date_key)){
|
86 |
if(orderDateItemIdFbaSaleSnapshotMap.containsKey(date_key)){
|
| 81 |
if(orderDateItemIdFbaSaleSnapshotMap.get(date_key).containsKey(itemid)){
|
87 |
if(orderDateItemIdFbaSaleSnapshotMap.get(date_key).containsKey(itemid)){
|
| 82 |
FbaSalesSnapshot fbaSalesSnapshot = orderDateItemIdFbaSaleSnapshotMap.get(date_key).get(itemid);
|
88 |
FbaSalesSnapshot fbaSalesSnapshot = orderDateItemIdFbaSaleSnapshotMap.get(date_key).get(itemid);
|
| 83 |
if(itemDiscount!=0){
|
89 |
if(itemDiscount!=0){
|
| 84 |
fbaSalesSnapshot.setPromotionOrderCount(fbaSalesSnapshot.getPromotionOrderCount()+qty);
|
90 |
fbaSalesSnapshot.setPromotionOrderCount(fbaSalesSnapshot.getPromotionOrderCount()+qty);
|
| Line 126... |
Line 132... |
| 126 |
TransactionClient transactionServiceClient = null;
|
132 |
TransactionClient transactionServiceClient = null;
|
| 127 |
CatalogClient catalogServiceClient = null;
|
133 |
CatalogClient catalogServiceClient = null;
|
| 128 |
try {
|
134 |
try {
|
| 129 |
inventoryServiceClient = new InventoryClient();
|
135 |
inventoryServiceClient = new InventoryClient();
|
| 130 |
transactionServiceClient = new TransactionClient();
|
136 |
transactionServiceClient = new TransactionClient();
|
| 131 |
//catalogServiceClient = new CatalogClient();
|
137 |
catalogServiceClient = new CatalogClient();
|
| 132 |
catalogServiceClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port");
|
138 |
//catalogServiceClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port");
|
| 133 |
} catch (Exception e) {
|
139 |
} catch (Exception e) {
|
| 134 |
// TODO Auto-generated catch block
|
140 |
// TODO Auto-generated catch block
|
| 135 |
e.printStackTrace();
|
141 |
e.printStackTrace();
|
| 136 |
}
|
142 |
}
|
| 137 |
in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
|
143 |
in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
|
| Line 188... |
Line 194... |
| 188 |
Double minFBAPrice= null;
|
194 |
Double minFBAPrice= null;
|
| 189 |
Double minMFNPrice= null;
|
195 |
Double minMFNPrice= null;
|
| 190 |
Double salePrice= null;
|
196 |
Double salePrice= null;
|
| 191 |
if(nextLine[30].length() >0){
|
197 |
if(nextLine[30].length() >0){
|
| 192 |
ourPrice = Double.parseDouble(nextLine[30]);
|
198 |
ourPrice = Double.parseDouble(nextLine[30]);
|
| - |
|
199 |
if(itemIdOurPriceMap.containsKey(item_id)){
|
| 193 |
if(itemIdOurPriceMap.containsKey(item_id) && itemIdOurPriceMap.get(item_id).getDate().after(date)){
|
200 |
if(itemIdOurPriceMap.get(item_id).getDate().getTime() < date.getTime()){
|
| 194 |
PriceAtDate priceAtDate= new PriceAtDate();
|
201 |
PriceAtDate priceAtDate= new PriceAtDate();
|
| 195 |
priceAtDate.setDate(date);
|
202 |
priceAtDate.setDate(date);
|
| 196 |
priceAtDate.setPrice(ourPrice);
|
203 |
priceAtDate.setPrice(ourPrice);
|
| 197 |
itemIdOurPriceMap.put(item_id,priceAtDate);
|
204 |
itemIdOurPriceMap.put(item_id,priceAtDate);
|
| - |
|
205 |
}
|
| 198 |
}
|
206 |
}
|
| 199 |
else{
|
207 |
else{
|
| 200 |
PriceAtDate priceAtDate= new PriceAtDate();
|
208 |
PriceAtDate priceAtDate= new PriceAtDate();
|
| 201 |
priceAtDate.setDate(date);
|
209 |
priceAtDate.setDate(date);
|
| 202 |
priceAtDate.setPrice(ourPrice);
|
210 |
priceAtDate.setPrice(ourPrice);
|
| 203 |
itemIdOurPriceMap.put(item_id,priceAtDate);
|
211 |
itemIdOurPriceMap.put(item_id,priceAtDate);
|
| 204 |
}
|
212 |
}
|
| 205 |
}
|
213 |
}
|
| 206 |
if(nextLine[31].length() >0){
|
214 |
if(nextLine[31].length() >0){
|
| 207 |
salePrice = Double.parseDouble(nextLine[31]);
|
215 |
salePrice = Double.parseDouble(nextLine[31]);
|
| - |
|
216 |
if(itemIdSalePriceMap.containsKey(item_id) ){
|
| 208 |
if(itemIdSalePriceMap.containsKey(item_id) && itemIdSalePriceMap.get(item_id).getDate().after(date)){
|
217 |
if(itemIdSalePriceMap.get(item_id).getDate().getTime() < date.getTime()){
|
| 209 |
PriceAtDate priceAtDate= new PriceAtDate();
|
218 |
PriceAtDate priceAtDate= new PriceAtDate();
|
| 210 |
priceAtDate.setDate(date);
|
219 |
priceAtDate.setDate(date);
|
| 211 |
priceAtDate.setPrice(salePrice);
|
220 |
priceAtDate.setPrice(salePrice);
|
| 212 |
itemIdOurPriceMap.put(item_id,priceAtDate);
|
221 |
itemIdSalePriceMap.put(item_id,priceAtDate);
|
| - |
|
222 |
}
|
| 213 |
}
|
223 |
}
|
| 214 |
else{
|
224 |
else{
|
| 215 |
PriceAtDate priceAtDate= new PriceAtDate();
|
225 |
PriceAtDate priceAtDate= new PriceAtDate();
|
| 216 |
priceAtDate.setDate(date);
|
226 |
priceAtDate.setDate(date);
|
| 217 |
priceAtDate.setPrice(salePrice);
|
227 |
priceAtDate.setPrice(salePrice);
|
| 218 |
itemIdSalePriceMap.put(item_id,priceAtDate);
|
228 |
itemIdSalePriceMap.put(item_id,priceAtDate);
|
| 219 |
}
|
229 |
}
|
| 220 |
}
|
230 |
}
|
| 221 |
if(nextLine[32].length() >0){
|
231 |
if(nextLine[32].length() >0){
|
| 222 |
minFBAPrice = Double.parseDouble(nextLine[32]);
|
232 |
minFBAPrice = Double.parseDouble(nextLine[32]);
|
| - |
|
233 |
if(itemIdminFBAPriceMap.containsKey(item_id)){
|
| 223 |
if(itemIdminFBAPriceMap.containsKey(item_id) && itemIdminFBAPriceMap.get(item_id).getDate().after(date)){
|
234 |
if(itemIdminFBAPriceMap.get(item_id).getDate().getTime() < date.getTime()){
|
| 224 |
PriceAtDate priceAtDate= new PriceAtDate();
|
235 |
PriceAtDate priceAtDate= new PriceAtDate();
|
| 225 |
priceAtDate.setDate(date);
|
236 |
priceAtDate.setDate(date);
|
| 226 |
priceAtDate.setPrice(minFBAPrice);
|
237 |
priceAtDate.setPrice(minFBAPrice);
|
| 227 |
itemIdOurPriceMap.put(item_id,priceAtDate);
|
238 |
itemIdminFBAPriceMap.put(item_id,priceAtDate);
|
| - |
|
239 |
}
|
| 228 |
}
|
240 |
}
|
| 229 |
else{
|
241 |
else{
|
| 230 |
PriceAtDate priceAtDate= new PriceAtDate();
|
242 |
PriceAtDate priceAtDate= new PriceAtDate();
|
| 231 |
priceAtDate.setDate(date);
|
243 |
priceAtDate.setDate(date);
|
| 232 |
priceAtDate.setPrice(minFBAPrice);
|
244 |
priceAtDate.setPrice(minFBAPrice);
|
| 233 |
itemIdminFBAPriceMap.put(item_id,priceAtDate);
|
245 |
itemIdminFBAPriceMap.put(item_id,priceAtDate);
|
| 234 |
}
|
246 |
}
|
| 235 |
}
|
247 |
}
|
| 236 |
if(nextLine[34].length() >0){
|
248 |
if(nextLine[34].length() >0){
|
| 237 |
minMFNPrice = Double.parseDouble(nextLine[34]);
|
249 |
minMFNPrice = Double.parseDouble(nextLine[34]);
|
| - |
|
250 |
if(itemIdminMFNPriceMap.containsKey(item_id)){
|
| 238 |
if(itemIdminMFNPriceMap.containsKey(item_id) && itemIdminMFNPriceMap.get(item_id).getDate().after(date)){
|
251 |
if(itemIdminMFNPriceMap.get(item_id).getDate().getTime() < date.getTime()){
|
| 239 |
PriceAtDate priceAtDate= new PriceAtDate();
|
252 |
PriceAtDate priceAtDate= new PriceAtDate();
|
| 240 |
priceAtDate.setDate(date);
|
253 |
priceAtDate.setDate(date);
|
| 241 |
priceAtDate.setPrice(minMFNPrice);
|
254 |
priceAtDate.setPrice(minMFNPrice);
|
| 242 |
itemIdOurPriceMap.put(item_id,priceAtDate);
|
255 |
itemIdminMFNPriceMap.put(item_id,priceAtDate);
|
| - |
|
256 |
}
|
| 243 |
}
|
257 |
}
|
| 244 |
else{
|
258 |
else{
|
| 245 |
PriceAtDate priceAtDate= new PriceAtDate();
|
259 |
PriceAtDate priceAtDate= new PriceAtDate();
|
| 246 |
priceAtDate.setDate(date);
|
260 |
priceAtDate.setDate(date);
|
| 247 |
priceAtDate.setPrice(minMFNPrice);
|
261 |
priceAtDate.setPrice(minMFNPrice);
|
| Line 273... |
Line 287... |
| 273 |
amazonfbasalessnapshot.setTotalOrderCount(entry1.getValue().getTotalOrderCount());
|
287 |
amazonfbasalessnapshot.setTotalOrderCount(entry1.getValue().getTotalOrderCount());
|
| 274 |
amazonfbasalessnapshot.setTotalSale(entry1.getValue().getTotalSale());
|
288 |
amazonfbasalessnapshot.setTotalSale(entry1.getValue().getTotalSale());
|
| 275 |
amazonfbasalessnapshot.setPromotionSale(entry1.getValue().getTotalPromotionSale());
|
289 |
amazonfbasalessnapshot.setPromotionSale(entry1.getValue().getTotalPromotionSale());
|
| 276 |
amazonfbasalessnapshot.setIsOutOfStock(oos);
|
290 |
amazonfbasalessnapshot.setIsOutOfStock(oos);
|
| 277 |
Amazonlisted amazon_item=null;
|
291 |
Amazonlisted amazon_item=null;
|
| 278 |
if(catalogClient.getAmazonItemDetails(item_id)!=null){
|
292 |
if(catalogClient.getAmazonItemDetails(item_id).getItemid()!=0){
|
| 279 |
amazon_item = catalogClient.getAmazonItemDetails(item_id);
|
293 |
amazon_item = catalogClient.getAmazonItemDetails(item_id);
|
| 280 |
}
|
294 |
}
|
| 281 |
else{
|
295 |
else{
|
| 282 |
continue;
|
296 |
continue;
|
| 283 |
}
|
297 |
}
|
| 284 |
if(itemIdSalePriceMap.containsKey(item_id) && itemIdSalePriceMap.get(item_id).getPrice()!=0){
|
298 |
if(itemIdSalePriceMap.containsKey(item_id) && itemIdSalePriceMap.get(item_id).getPrice()!=0){
|
| 285 |
amazonfbasalessnapshot.setSalePrice(itemIdSalePriceMap.get(item_id).getPrice());
|
299 |
amazonfbasalessnapshot.setSalePrice(itemIdSalePriceMap.get(item_id).getPrice());
|
| - |
|
300 |
amazonfbasalessnapshot.setSalePriceSnapshotDate(itemIdSalePriceMap.get(item_id).getDate().getTime());
|
| 286 |
}
|
301 |
}
|
| 287 |
else{
|
302 |
else{
|
| 288 |
amazonfbasalessnapshot.setSalePrice(0.0);
|
303 |
amazonfbasalessnapshot.setSalePrice(0.0);
|
| - |
|
304 |
amazonfbasalessnapshot.setSalePriceSnapshotDate(0);
|
| 289 |
}
|
305 |
}
|
| 290 |
if(itemIdminMFNPriceMap.containsKey(item_id) && itemIdminMFNPriceMap.get(item_id).getPrice()!=0){
|
306 |
if(itemIdminMFNPriceMap.containsKey(item_id) && itemIdminMFNPriceMap.get(item_id).getPrice()!=0){
|
| 291 |
amazonfbasalessnapshot.setMinMfnPrice(itemIdminMFNPriceMap.get(item_id).getPrice());
|
307 |
amazonfbasalessnapshot.setMinMfnPrice(itemIdminMFNPriceMap.get(item_id).getPrice());
|
| - |
|
308 |
amazonfbasalessnapshot.setMinMfnPriceSnapshotDate(itemIdminMFNPriceMap.get(item_id).getDate().getTime());
|
| 292 |
}
|
309 |
}
|
| 293 |
else{
|
310 |
else{
|
| 294 |
amazonfbasalessnapshot.setMinMfnPrice(0.0);
|
311 |
amazonfbasalessnapshot.setMinMfnPrice(0.0);
|
| - |
|
312 |
amazonfbasalessnapshot.setMinMfnPriceSnapshotDate(0);
|
| 295 |
}
|
313 |
}
|
| 296 |
if(itemIdminFBAPriceMap.containsKey(item_id) && itemIdminFBAPriceMap.get(item_id).getPrice()!=0){
|
314 |
if(itemIdminFBAPriceMap.containsKey(item_id) && itemIdminFBAPriceMap.get(item_id).getPrice()!=0){
|
| 297 |
amazonfbasalessnapshot.setMinFbaPrice(itemIdminFBAPriceMap.get(item_id).getPrice());
|
315 |
amazonfbasalessnapshot.setMinFbaPrice(itemIdminFBAPriceMap.get(item_id).getPrice());
|
| - |
|
316 |
amazonfbasalessnapshot.setMinFbaPriceSnapshotDate(itemIdminFBAPriceMap.get(item_id).getDate().getTime());
|
| 298 |
}
|
317 |
}
|
| 299 |
else{
|
318 |
else{
|
| 300 |
amazonfbasalessnapshot.setMinFbaPrice(0.0);
|
319 |
amazonfbasalessnapshot.setMinFbaPrice(0.0);
|
| - |
|
320 |
amazonfbasalessnapshot.setMinFbaPriceSnapshotDate(0);
|
| 301 |
}
|
321 |
}
|
| 302 |
if(itemIdOurPriceMap.containsKey(item_id) && itemIdOurPriceMap.get(item_id).getPrice()!=0){
|
322 |
if(itemIdOurPriceMap.containsKey(item_id) && itemIdOurPriceMap.get(item_id).getPrice()!=0){
|
| 303 |
amazonfbasalessnapshot.setOurPrice(itemIdOurPriceMap.get(item_id).getPrice());
|
323 |
amazonfbasalessnapshot.setOurPrice(itemIdOurPriceMap.get(item_id).getPrice());
|
| - |
|
324 |
amazonfbasalessnapshot.setOurPriceSnapshotDate(itemIdOurPriceMap.get(item_id).getDate().getTime());
|
| 304 |
}
|
325 |
}
|
| 305 |
else{
|
326 |
else{
|
| 306 |
amazonfbasalessnapshot.setOurPrice(amazon_item.getFbaPrice());
|
327 |
amazonfbasalessnapshot.setOurPrice(amazon_item.getFbaPrice());
|
| - |
|
328 |
amazonfbasalessnapshot.setOurPriceSnapshotDate(0);
|
| 307 |
}
|
329 |
}
|
| 308 |
amazonfbasalessnapshot.setAmazonFbaInventory(inventory);
|
330 |
amazonfbasalessnapshot.setAmazonFbaInventory(inventory);
|
| 309 |
transactionClient.addOrUpdateAmazonFbaSalesSnapshot(amazonfbasalessnapshot);
|
331 |
transactionClient.addOrUpdateAmazonFbaSalesSnapshot(amazonfbasalessnapshot);
|
| 310 |
}
|
332 |
}
|
| 311 |
}
|
333 |
}
|
| Line 317... |
Line 339... |
| 317 |
e.printStackTrace();
|
339 |
e.printStackTrace();
|
| 318 |
} catch (TException e) {
|
340 |
} catch (TException e) {
|
| 319 |
// TODO Auto-generated catch block
|
341 |
// TODO Auto-generated catch block
|
| 320 |
e.printStackTrace();
|
342 |
e.printStackTrace();
|
| 321 |
}
|
343 |
}
|
| 322 |
|
- |
|
| 323 |
}
|
344 |
}
|
| 324 |
|
345 |
|
| 325 |
public static Double getPercentageDifferenceFromMinimumPrice(AmazonFbaSalesSnapshot snapshot){
|
346 |
public static Double getPercentageDifferenceFromMinimumPrice(AmazonFbaSalesSnapshot snapshot){
|
| 326 |
Double minPrice = getMinimumSalePriceOnAmazonFBA(snapshot);
|
347 |
Double minPrice = getMinimumSalePriceOnAmazonFBA(snapshot);
|
| 327 |
return (((minPrice - snapshot.getOurPrice())/snapshot.getOurPrice())*100);
|
348 |
return (((minPrice - snapshot.getOurPrice())/snapshot.getOurPrice())*100);
|