| 8285 |
kshitij.so |
1 |
package com.amazonaws.mws.samples;
|
|
|
2 |
|
|
|
3 |
import in.shop2020.model.v1.catalog.Amazonlisted;
|
|
|
4 |
import in.shop2020.model.v1.inventory.AmazonFbaInventorySnapshot;
|
|
|
5 |
import in.shop2020.model.v1.order.AmazonFbaSalesSnapshot;
|
|
|
6 |
import in.shop2020.thrift.clients.CatalogClient;
|
|
|
7 |
import in.shop2020.thrift.clients.InventoryClient;
|
|
|
8 |
import in.shop2020.thrift.clients.TransactionClient;
|
| 8363 |
vikram.rag |
9 |
import in.shop2020.utils.GmailUtils;
|
| 8285 |
kshitij.so |
10 |
|
|
|
11 |
import java.io.FileNotFoundException;
|
|
|
12 |
import java.io.FileOutputStream;
|
|
|
13 |
import java.io.FileReader;
|
|
|
14 |
import java.io.IOException;
|
|
|
15 |
import java.io.OutputStream;
|
|
|
16 |
import java.text.ParseException;
|
|
|
17 |
import java.text.SimpleDateFormat;
|
| 8825 |
vikram.rag |
18 |
import java.util.ArrayList;
|
| 8285 |
kshitij.so |
19 |
import java.util.Arrays;
|
|
|
20 |
import java.util.Calendar;
|
|
|
21 |
import java.util.Date;
|
|
|
22 |
import java.util.GregorianCalendar;
|
|
|
23 |
import java.util.HashMap;
|
|
|
24 |
import java.util.List;
|
|
|
25 |
import java.util.Map;
|
| 8363 |
vikram.rag |
26 |
import java.util.Map.Entry;
|
| 8285 |
kshitij.so |
27 |
import java.util.TimeZone;
|
|
|
28 |
|
|
|
29 |
import javax.xml.datatype.DatatypeConfigurationException;
|
|
|
30 |
import javax.xml.datatype.DatatypeFactory;
|
|
|
31 |
import javax.xml.datatype.Duration;
|
|
|
32 |
import javax.xml.datatype.XMLGregorianCalendar;
|
|
|
33 |
|
|
|
34 |
import org.apache.thrift.TException;
|
|
|
35 |
import org.apache.thrift.transport.TTransportException;
|
|
|
36 |
|
|
|
37 |
import au.com.bytecode.opencsv.CSVReader;
|
|
|
38 |
|
|
|
39 |
import com.amazonaws.mws.MarketplaceWebService;
|
|
|
40 |
import com.amazonaws.mws.MarketplaceWebServiceClient;
|
|
|
41 |
import com.amazonaws.mws.MarketplaceWebServiceConfig;
|
| 8363 |
vikram.rag |
42 |
import com.amazonaws.mws.MarketplaceWebServiceException;
|
| 8285 |
kshitij.so |
43 |
import com.amazonaws.mws.model.GetReportListRequest;
|
|
|
44 |
import com.amazonaws.mws.model.GetReportRequest;
|
|
|
45 |
import com.amazonaws.mws.model.IdList;
|
|
|
46 |
import com.amazonaws.mws.model.RequestReportRequest;
|
|
|
47 |
|
|
|
48 |
public class FetchAmazonSalesSnapshot {
|
|
|
49 |
public static void main(String... args){
|
|
|
50 |
/************************************************************************
|
|
|
51 |
* Access Key ID and Secret Access Key ID, obtained from:
|
|
|
52 |
* http://aws.amazon.com
|
|
|
53 |
***********************************************************************/
|
|
|
54 |
final String accessKeyId = "AKIAII3SGRXBJDPCHSGQ";
|
|
|
55 |
final String secretAccessKey = "B92xTbNBTYygbGs98w01nFQUhbec1pNCkCsKVfpg";
|
|
|
56 |
|
|
|
57 |
final String appName = "Test";
|
|
|
58 |
final String appVersion = "1.0";
|
|
|
59 |
final String merchantId = "AF6E3O0VE0X4D";
|
|
|
60 |
|
|
|
61 |
MarketplaceWebServiceConfig config = new MarketplaceWebServiceConfig();
|
|
|
62 |
|
|
|
63 |
/************************************************************************
|
|
|
64 |
* Uncomment to set the appropriate MWS endpoint.
|
|
|
65 |
************************************************************************/
|
|
|
66 |
// US
|
|
|
67 |
// config.setServiceURL("https://mws.amazonservices.com");
|
|
|
68 |
// UK
|
|
|
69 |
// config.setServiceURL("https://mws.amazonservices.co.uk");
|
|
|
70 |
// Germany
|
|
|
71 |
// config.setServiceURL("https://mws.amazonservices.de");
|
|
|
72 |
// France
|
|
|
73 |
// config.setServiceURL("https://mws.amazonservices.fr");
|
|
|
74 |
// Italy
|
|
|
75 |
// config.setServiceURL("https://mws.amazonservices.it");
|
|
|
76 |
// Japan
|
|
|
77 |
// config.setServiceURL("https://mws.amazonservices.jp");
|
|
|
78 |
// China
|
|
|
79 |
// config.setServiceURL("https://mws.amazonservices.com.cn");
|
|
|
80 |
// Canada
|
|
|
81 |
// config.setServiceURL("https://mws.amazonservices.ca");
|
|
|
82 |
// India
|
|
|
83 |
config.setServiceURL("https://mws.amazonservices.in");
|
|
|
84 |
|
|
|
85 |
/************************************************************************
|
|
|
86 |
* You can also try advanced configuration options. Available options are:
|
|
|
87 |
*
|
|
|
88 |
* - Signature Version
|
|
|
89 |
* - Proxy Host and Proxy Port
|
|
|
90 |
* - User Agent String to be sent to Marketplace Web Service
|
|
|
91 |
*
|
|
|
92 |
***********************************************************************/
|
|
|
93 |
|
|
|
94 |
/************************************************************************
|
|
|
95 |
* Instantiate Http Client Implementation of Marketplace Web Service
|
|
|
96 |
***********************************************************************/
|
|
|
97 |
|
|
|
98 |
MarketplaceWebService service = new MarketplaceWebServiceClient(
|
|
|
99 |
accessKeyId, secretAccessKey, appName, appVersion, config);
|
|
|
100 |
|
|
|
101 |
/************************************************************************
|
|
|
102 |
* Uncomment to try out Mock Service that simulates Marketplace Web Service
|
|
|
103 |
* responses without calling Marketplace Web Service service.
|
|
|
104 |
*
|
|
|
105 |
* Responses are loaded from local XML files. You can tweak XML files to
|
|
|
106 |
* experiment with various outputs during development
|
|
|
107 |
*
|
|
|
108 |
* XML files available under com/amazonaws/mws/mock tree
|
|
|
109 |
*
|
|
|
110 |
***********************************************************************/
|
|
|
111 |
// MarketplaceWebService service = new MarketplaceWebServiceMock();
|
|
|
112 |
|
|
|
113 |
/************************************************************************
|
|
|
114 |
* Setup request parameters and uncomment invoke to try out
|
|
|
115 |
* sample for Request Report
|
|
|
116 |
***********************************************************************/
|
|
|
117 |
|
|
|
118 |
/************************************************************************
|
|
|
119 |
* Marketplace and Merchant IDs are required parameters for all
|
|
|
120 |
* Marketplace Web Service calls.
|
|
|
121 |
***********************************************************************/
|
|
|
122 |
// marketplaces from which data should be included in the report; look at the
|
|
|
123 |
// API reference document on the MWS website to see which marketplaces are
|
|
|
124 |
// included if you do not specify the list yourself
|
|
|
125 |
final IdList marketplaces = new IdList(Arrays.asList(
|
|
|
126 |
"A21TJRUUN4KGV"));
|
|
|
127 |
RequestReportRequest orderreportrequest = new RequestReportRequest()
|
|
|
128 |
.withMerchant(merchantId)
|
|
|
129 |
.withMarketplaceIdList(marketplaces)
|
|
|
130 |
.withReportType("_GET_FLAT_FILE_ALL_ORDERS_DATA_BY_ORDER_DATE_")
|
|
|
131 |
.withReportOptions("ShowSalesChannel=true");
|
|
|
132 |
|
|
|
133 |
RequestReportRequest inventoryhealthreportrequest = new RequestReportRequest()
|
|
|
134 |
.withMerchant(merchantId)
|
|
|
135 |
.withMarketplaceIdList(marketplaces)
|
|
|
136 |
.withReportType("_GET_FBA_FULFILLMENT_INVENTORY_HEALTH_DATA_")
|
|
|
137 |
.withReportOptions("ShowSalesChannel=true");
|
|
|
138 |
|
|
|
139 |
DatatypeFactory df = null;
|
|
|
140 |
try {
|
|
|
141 |
df = DatatypeFactory.newInstance();
|
|
|
142 |
} catch (DatatypeConfigurationException e) {
|
|
|
143 |
e.printStackTrace();
|
|
|
144 |
throw new RuntimeException(e);
|
|
|
145 |
}
|
|
|
146 |
long ordertimediff = System.currentTimeMillis() - 7*24*60*60*1000;
|
|
|
147 |
GregorianCalendar ost = new GregorianCalendar();
|
|
|
148 |
ost.setTimeInMillis(ordertimediff);
|
|
|
149 |
XMLGregorianCalendar orderStartDate = df.newXMLGregorianCalendar(ost);
|
|
|
150 |
XMLGregorianCalendar orderEndDate = df.newXMLGregorianCalendar(new GregorianCalendar());
|
|
|
151 |
System.out.println("Order Start Date " + orderStartDate + "Order End Date " + orderEndDate);
|
|
|
152 |
orderreportrequest.setStartDate(orderStartDate);
|
|
|
153 |
orderreportrequest.setEndDate(orderEndDate);
|
|
|
154 |
long inventorytimediff = System.currentTimeMillis() - 7*24*60*60*1000;
|
|
|
155 |
GregorianCalendar ist = new GregorianCalendar();
|
|
|
156 |
ist.setTimeInMillis(inventorytimediff);
|
|
|
157 |
ist.setTimeInMillis(ordertimediff);
|
|
|
158 |
XMLGregorianCalendar inventoryStartDate = df.newXMLGregorianCalendar(ist);
|
|
|
159 |
XMLGregorianCalendar inventoryEndDate = df.newXMLGregorianCalendar(new GregorianCalendar());
|
|
|
160 |
System.out.println("Inventory Start Date " + inventoryStartDate + "Inventory End Date " + inventoryEndDate);
|
|
|
161 |
inventoryhealthreportrequest.setStartDate(inventoryStartDate);
|
|
|
162 |
inventoryhealthreportrequest.setEndDate(inventoryEndDate);
|
|
|
163 |
Map<String,String> requestIdreportIdmap;
|
| 8363 |
vikram.rag |
164 |
String orderreportrequestId = null;
|
|
|
165 |
String inventoryhealthreportrequestId = null;
|
|
|
166 |
boolean retry=true;
|
|
|
167 |
int retryCount =0;
|
|
|
168 |
while(retry && retryCount!=5){
|
|
|
169 |
if(retryCount==4){
|
|
|
170 |
String emailFromAddress = "build@shop2020.in";
|
|
|
171 |
String password = "cafe@nes";
|
|
|
172 |
String[] sendTo = new String[]{ "vikram.raghav@shop2020.in"};
|
| 8825 |
vikram.rag |
173 |
String emailSubjectTxt = "Fetch FBA Sale failure";
|
| 8363 |
vikram.rag |
174 |
try {
|
|
|
175 |
GmailUtils mailer = new GmailUtils();
|
|
|
176 |
mailer.sendSSLMessage(sendTo, emailSubjectTxt, "", emailFromAddress, password,"");
|
|
|
177 |
}
|
|
|
178 |
catch (Exception ex) {
|
|
|
179 |
ex.printStackTrace();
|
|
|
180 |
}
|
|
|
181 |
|
|
|
182 |
System.exit(1);
|
|
|
183 |
}
|
|
|
184 |
try {
|
|
|
185 |
orderreportrequestId = RequestReportSample.invokeRequestReport(service, orderreportrequest);
|
|
|
186 |
inventoryhealthreportrequestId = RequestReportSample.invokeRequestReport(service, inventoryhealthreportrequest);
|
|
|
187 |
retry = false;
|
|
|
188 |
} catch (MarketplaceWebServiceException e) {
|
|
|
189 |
// TODO Auto-generated catch block
|
|
|
190 |
e.printStackTrace();
|
|
|
191 |
try {
|
|
|
192 |
Thread.sleep(10*60*1000);
|
|
|
193 |
retryCount++;
|
|
|
194 |
} catch (InterruptedException e1) {
|
|
|
195 |
// TODO Auto-generated catch block
|
|
|
196 |
e1.printStackTrace();
|
|
|
197 |
}
|
|
|
198 |
}
|
|
|
199 |
}
|
| 8285 |
kshitij.so |
200 |
while(true){
|
| 8363 |
vikram.rag |
201 |
GetReportListRequest requestreportlist = new GetReportListRequest();
|
|
|
202 |
requestreportlist.setMerchant( merchantId );
|
|
|
203 |
final IdList requestIdList = new IdList(Arrays.asList(orderreportrequestId,inventoryhealthreportrequestId));
|
|
|
204 |
requestreportlist.setReportRequestIdList(requestIdList);
|
|
|
205 |
requestIdreportIdmap = GetReportListSample.invokeGetReportList(service, requestreportlist);
|
|
|
206 |
if(requestIdreportIdmap.get(orderreportrequestId)!=null && requestIdreportIdmap.get(inventoryhealthreportrequestId)!=null){
|
|
|
207 |
GetReportRequest requestorderreport = new GetReportRequest();
|
|
|
208 |
GetReportRequest requestinventoryhealthreport = new GetReportRequest();
|
|
|
209 |
requestorderreport.setMerchant( merchantId );
|
|
|
210 |
requestinventoryhealthreport.setMerchant(merchantId);
|
|
|
211 |
requestorderreport.setReportId( requestIdreportIdmap.get(orderreportrequestId));
|
|
|
212 |
requestinventoryhealthreport.setReportId(requestIdreportIdmap.get(inventoryhealthreportrequestId));
|
|
|
213 |
OutputStream orderreport=null;
|
|
|
214 |
OutputStream inventoryhealthreport=null;
|
|
|
215 |
try {
|
|
|
216 |
orderreport = new FileOutputStream( "/home/amazonorderreport.csv" );
|
|
|
217 |
inventoryhealthreport = new FileOutputStream( "/home/inventoryhealthreport.csv" );
|
|
|
218 |
} catch (FileNotFoundException e) {
|
|
|
219 |
// TODO Auto-generated catch block
|
|
|
220 |
e.printStackTrace();
|
|
|
221 |
}
|
|
|
222 |
requestorderreport.setReportOutputStream(orderreport);
|
|
|
223 |
requestinventoryhealthreport.setReportOutputStream(inventoryhealthreport);
|
|
|
224 |
GetReportSample.invokeGetReport(service, requestorderreport);
|
|
|
225 |
GetReportSample.invokeGetReport(service, requestinventoryhealthreport);
|
|
|
226 |
System.out.println("Order and Inventory Reports are ready please check");
|
|
|
227 |
CSVReader orderreportreader = null;
|
|
|
228 |
CSVReader inventoryhealthreportreader = null;
|
|
|
229 |
try {
|
|
|
230 |
orderreportreader = new CSVReader(new FileReader("/home/amazonorderreport.csv"),'\t');
|
|
|
231 |
inventoryhealthreportreader = new CSVReader(new FileReader("/home/inventoryhealthreport.csv"),'\t');
|
|
|
232 |
} catch (FileNotFoundException e) {
|
|
|
233 |
// TODO Auto-generated catch block
|
|
|
234 |
e.printStackTrace();
|
|
|
235 |
}
|
|
|
236 |
String [] nextLine;
|
|
|
237 |
try {
|
|
|
238 |
int count =1;
|
|
|
239 |
Map<Date,Map<Long,FbaSalesSnapshot>> orderDateItemIdFbaSaleSnapshotMap = new HashMap<Date,Map<Long,FbaSalesSnapshot>>();
|
|
|
240 |
while ((nextLine = orderreportreader.readNext()) != null) {
|
| 8826 |
vikram.rag |
241 |
try{
|
|
|
242 |
if(count!=1 && nextLine[5].equalsIgnoreCase("Amazon") && nextLine[6].equalsIgnoreCase("Amazon.in")){
|
|
|
243 |
SimpleDateFormat istFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
|
|
|
244 |
istFormatter .setLenient(false);
|
|
|
245 |
TimeZone zone= TimeZone.getTimeZone("GMT");
|
|
|
246 |
istFormatter.setTimeZone(zone);
|
|
|
247 |
Date date = istFormatter.parse(nextLine[2]);
|
|
|
248 |
SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
|
|
|
249 |
Date date_key = dateFormat.parse(dateFormat.format(date));
|
| 9255 |
vikram.rag |
250 |
System.out.println("Order Details " + nextLine[0]+" "+date_key+" "+ nextLine[11] +" " + nextLine[13] + " " + nextLine[14]);
|
| 8826 |
vikram.rag |
251 |
Long itemid = Long.parseLong(nextLine[11].replaceAll("FBA",""));
|
|
|
252 |
Integer qty=0;
|
|
|
253 |
if(nextLine[14].length()!=0){
|
|
|
254 |
qty = new Integer(nextLine[14]);
|
|
|
255 |
}
|
|
|
256 |
Float itemSale = null;
|
|
|
257 |
if(nextLine[16].length()!=0){
|
|
|
258 |
itemSale = new Float(nextLine[16]);
|
|
|
259 |
}
|
|
|
260 |
else{
|
|
|
261 |
continue;
|
|
|
262 |
}
|
|
|
263 |
Float itemDiscount;
|
|
|
264 |
if(nextLine[22].length()!=0){
|
|
|
265 |
itemDiscount = new Float(nextLine[22]);
|
|
|
266 |
}
|
|
|
267 |
else{
|
|
|
268 |
itemDiscount = new Float(0);
|
|
|
269 |
}
|
| 9258 |
vikram.rag |
270 |
if(nextLine[4].equalsIgnoreCase("Cancelled") || nextLine[13].equalsIgnoreCase("Cancelled")){
|
| 8826 |
vikram.rag |
271 |
itemSale = (float) 0;
|
|
|
272 |
itemDiscount = (float) 0;
|
|
|
273 |
qty = 0;
|
|
|
274 |
}
|
|
|
275 |
if(orderDateItemIdFbaSaleSnapshotMap.containsKey(date_key)){
|
|
|
276 |
if(orderDateItemIdFbaSaleSnapshotMap.get(date_key).containsKey(itemid)){
|
|
|
277 |
FbaSalesSnapshot fbaSalesSnapshot = orderDateItemIdFbaSaleSnapshotMap.get(date_key).get(itemid);
|
|
|
278 |
if(itemDiscount!=0){
|
|
|
279 |
fbaSalesSnapshot.setPromotionOrderCount(fbaSalesSnapshot.getPromotionOrderCount()+qty);
|
|
|
280 |
fbaSalesSnapshot.setTotalPromotionSale(fbaSalesSnapshot.getTotalPromotionSale() + (itemSale - itemDiscount));
|
|
|
281 |
}
|
| 9330 |
vikram.rag |
282 |
else{
|
|
|
283 |
fbaSalesSnapshot.setPromotionOrderCount(0);
|
|
|
284 |
fbaSalesSnapshot.setTotalPromotionSale((float) 0);
|
|
|
285 |
}
|
| 8826 |
vikram.rag |
286 |
fbaSalesSnapshot.setTotalOrderCount(fbaSalesSnapshot.getTotalOrderCount() + qty);
|
|
|
287 |
fbaSalesSnapshot.setTotalSale(fbaSalesSnapshot.getTotalSale() + itemSale - itemDiscount);
|
|
|
288 |
orderDateItemIdFbaSaleSnapshotMap.get(date_key).put(itemid,fbaSalesSnapshot);
|
| 8294 |
kshitij.so |
289 |
}
|
| 8826 |
vikram.rag |
290 |
else{
|
|
|
291 |
FbaSalesSnapshot fbaSalesSnapshot = new FbaSalesSnapshot();
|
|
|
292 |
fbaSalesSnapshot.setTotalOrderCount(qty);
|
|
|
293 |
fbaSalesSnapshot.setTotalSale(itemSale - itemDiscount);
|
|
|
294 |
if(itemDiscount!=0){
|
|
|
295 |
fbaSalesSnapshot.setPromotionOrderCount(qty);
|
|
|
296 |
fbaSalesSnapshot.setTotalPromotionSale(itemSale - itemDiscount);
|
|
|
297 |
}
|
|
|
298 |
else{
|
|
|
299 |
fbaSalesSnapshot.setPromotionOrderCount(0);
|
|
|
300 |
fbaSalesSnapshot.setTotalPromotionSale((float) 0);
|
|
|
301 |
}
|
|
|
302 |
orderDateItemIdFbaSaleSnapshotMap.get(date_key).put(itemid,fbaSalesSnapshot);
|
|
|
303 |
}
|
| 8285 |
kshitij.so |
304 |
}
|
| 8294 |
kshitij.so |
305 |
else{
|
| 8826 |
vikram.rag |
306 |
Map<Long,FbaSalesSnapshot> ItemIdFbaSaleSnapshotMap = new HashMap<Long,FbaSalesSnapshot>();
|
| 8363 |
vikram.rag |
307 |
FbaSalesSnapshot fbaSalesSnapshot = new FbaSalesSnapshot();
|
|
|
308 |
fbaSalesSnapshot.setTotalOrderCount(qty);
|
| 8826 |
vikram.rag |
309 |
fbaSalesSnapshot.setTotalSale(itemSale);
|
| 8363 |
vikram.rag |
310 |
if(itemDiscount!=0){
|
| 8826 |
vikram.rag |
311 |
fbaSalesSnapshot.setTotalPromotionSale(itemSale - itemDiscount);
|
| 8363 |
vikram.rag |
312 |
fbaSalesSnapshot.setPromotionOrderCount(qty);
|
| 8294 |
kshitij.so |
313 |
}
|
| 8363 |
vikram.rag |
314 |
else{
|
| 8826 |
vikram.rag |
315 |
fbaSalesSnapshot.setTotalPromotionSale((float) 0);
|
| 8363 |
vikram.rag |
316 |
fbaSalesSnapshot.setPromotionOrderCount(0);
|
|
|
317 |
}
|
| 8826 |
vikram.rag |
318 |
ItemIdFbaSaleSnapshotMap.put(itemid,fbaSalesSnapshot);
|
|
|
319 |
orderDateItemIdFbaSaleSnapshotMap.put(date_key,ItemIdFbaSaleSnapshotMap);
|
| 8294 |
kshitij.so |
320 |
}
|
| 8363 |
vikram.rag |
321 |
}
|
| 8826 |
vikram.rag |
322 |
}
|
|
|
323 |
catch(Exception e){
|
|
|
324 |
e.printStackTrace();
|
|
|
325 |
}
|
| 8363 |
vikram.rag |
326 |
count++;
|
|
|
327 |
}
|
|
|
328 |
InventoryClient inventoryServiceClient = null;
|
|
|
329 |
TransactionClient transactionServiceClient = null;
|
|
|
330 |
CatalogClient catalogServiceClient = null;
|
|
|
331 |
try {
|
|
|
332 |
inventoryServiceClient = new InventoryClient();
|
|
|
333 |
transactionServiceClient = new TransactionClient();
|
| 10534 |
vikram.rag |
334 |
//catalogServiceClient = new CatalogClient();
|
|
|
335 |
catalogServiceClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port");
|
| 8363 |
vikram.rag |
336 |
} catch (Exception e) {
|
|
|
337 |
// TODO Auto-generated catch block
|
|
|
338 |
e.printStackTrace();
|
|
|
339 |
}
|
|
|
340 |
in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
|
|
|
341 |
in.shop2020.model.v1.order.TransactionService.Client transactionClient = transactionServiceClient.getClient();
|
|
|
342 |
in.shop2020.model.v1.catalog.CatalogService.Client catalogClient = catalogServiceClient.getClient();
|
|
|
343 |
SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
|
| 8825 |
vikram.rag |
344 |
//Date date_today = dateFormat.parse(dateFormat.format(new Date()));
|
|
|
345 |
List<Date> dates = new ArrayList<Date>();
|
|
|
346 |
Calendar cal = Calendar.getInstance();
|
|
|
347 |
cal.add(Calendar.DATE, -1);
|
|
|
348 |
Date date_end = dateFormat.parse(dateFormat.format(cal.getTime()));
|
|
|
349 |
cal.add(Calendar.DATE, -5);
|
|
|
350 |
Date date_start = dateFormat.parse(dateFormat.format(cal.getTime()));
|
|
|
351 |
System.out.println("Start Date = " + date_start);
|
|
|
352 |
System.out.println("End Date = " + date_end);
|
|
|
353 |
Date d = date_start;
|
|
|
354 |
while(!d.equals(date_end)){
|
| 8826 |
vikram.rag |
355 |
cal.setTime(d);
|
|
|
356 |
cal.add(Calendar.DATE,1);
|
| 8825 |
vikram.rag |
357 |
d = cal.getTime();
|
|
|
358 |
dates.add(d);
|
|
|
359 |
}
|
| 8363 |
vikram.rag |
360 |
List<AmazonFbaInventorySnapshot> nonzeroFbaInventorySnapshotlist = inventoryClient.getAllAmazonFbaItemInventory();
|
| 8825 |
vikram.rag |
361 |
for(Date date:dates){
|
|
|
362 |
if(nonzeroFbaInventorySnapshotlist!=null){
|
|
|
363 |
for(AmazonFbaInventorySnapshot amazonFbaInventory:nonzeroFbaInventorySnapshotlist){
|
|
|
364 |
if(orderDateItemIdFbaSaleSnapshotMap.containsKey(date) ){
|
|
|
365 |
if(!orderDateItemIdFbaSaleSnapshotMap.get(date).containsKey(amazonFbaInventory.getItem_id())){
|
|
|
366 |
Map<Long,FbaSalesSnapshot> ItemIdFbaSaleSnapshotMap = new HashMap<Long,FbaSalesSnapshot>();
|
|
|
367 |
FbaSalesSnapshot fbaSalesSnapshot = new FbaSalesSnapshot();
|
|
|
368 |
fbaSalesSnapshot.setTotalOrderCount(0);
|
|
|
369 |
fbaSalesSnapshot.setPromotionOrderCount(0);
|
|
|
370 |
fbaSalesSnapshot.setTotalPromotionSale((float) 0);
|
|
|
371 |
fbaSalesSnapshot.setTotalSale((float) 0);
|
|
|
372 |
ItemIdFbaSaleSnapshotMap.put(amazonFbaInventory.getItem_id(),fbaSalesSnapshot);
|
|
|
373 |
orderDateItemIdFbaSaleSnapshotMap.get(date).put(amazonFbaInventory.getItem_id(),fbaSalesSnapshot);
|
|
|
374 |
}
|
|
|
375 |
|
|
|
376 |
}
|
|
|
377 |
else{
|
| 8363 |
vikram.rag |
378 |
Map<Long,FbaSalesSnapshot> ItemIdFbaSaleSnapshotMap = new HashMap<Long,FbaSalesSnapshot>();
|
|
|
379 |
FbaSalesSnapshot fbaSalesSnapshot = new FbaSalesSnapshot();
|
|
|
380 |
fbaSalesSnapshot.setTotalOrderCount(0);
|
|
|
381 |
fbaSalesSnapshot.setPromotionOrderCount(0);
|
|
|
382 |
fbaSalesSnapshot.setTotalPromotionSale((float) 0);
|
|
|
383 |
fbaSalesSnapshot.setTotalSale((float) 0);
|
|
|
384 |
ItemIdFbaSaleSnapshotMap.put(amazonFbaInventory.getItem_id(),fbaSalesSnapshot);
|
| 8825 |
vikram.rag |
385 |
orderDateItemIdFbaSaleSnapshotMap.put(date,ItemIdFbaSaleSnapshotMap);
|
| 8363 |
vikram.rag |
386 |
}
|
|
|
387 |
}
|
| 8285 |
kshitij.so |
388 |
}
|
| 8825 |
vikram.rag |
389 |
else{
|
|
|
390 |
System.out.println("No inventory in FBA");
|
|
|
391 |
}
|
| 8363 |
vikram.rag |
392 |
}
|
| 8461 |
vikram.rag |
393 |
Map<Long,PriceAtDate> itemIdOurPriceMap = new HashMap<Long,PriceAtDate>();
|
|
|
394 |
Map<Long,PriceAtDate> itemIdSalePriceMap = new HashMap<Long,PriceAtDate>();
|
|
|
395 |
Map<Long,PriceAtDate> itemIdminFBAPriceMap = new HashMap<Long,PriceAtDate>();
|
|
|
396 |
Map<Long,PriceAtDate> itemIdminMFNPriceMap = new HashMap<Long,PriceAtDate>();
|
| 8363 |
vikram.rag |
397 |
count=1;
|
|
|
398 |
while ((nextLine = inventoryhealthreportreader.readNext()) != null ) {
|
| 8826 |
vikram.rag |
399 |
try{
|
|
|
400 |
if(count!=1){
|
|
|
401 |
//System.out.println(nextLine[1] +" "+ nextLine[31] +" " + nextLine[32] + " " + nextLine[34]);
|
|
|
402 |
SimpleDateFormat istFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
|
|
|
403 |
istFormatter .setLenient(false);
|
|
|
404 |
TimeZone zone= TimeZone.getTimeZone("GMT");
|
|
|
405 |
istFormatter.setTimeZone(zone);
|
|
|
406 |
Date date = istFormatter.parse(nextLine[0]);
|
|
|
407 |
Long item_id = Long.parseLong(nextLine[1].replaceAll("FBA",""));
|
|
|
408 |
Double ourPrice = null;
|
|
|
409 |
Double minFBAPrice= null;
|
|
|
410 |
Double minMFNPrice= null;
|
|
|
411 |
Double salePrice= null;
|
|
|
412 |
if(nextLine[30].length() >0){
|
|
|
413 |
ourPrice = Double.parseDouble(nextLine[30]);
|
|
|
414 |
if(itemIdOurPriceMap.containsKey(item_id)){
|
|
|
415 |
if(itemIdOurPriceMap.get(item_id).getDate().getTime() < date.getTime()){
|
|
|
416 |
PriceAtDate priceAtDate= new PriceAtDate();
|
|
|
417 |
priceAtDate.setDate(date);
|
|
|
418 |
priceAtDate.setPrice(ourPrice);
|
|
|
419 |
itemIdOurPriceMap.put(item_id,priceAtDate);
|
|
|
420 |
}
|
|
|
421 |
}
|
|
|
422 |
else{
|
| 8532 |
vikram.rag |
423 |
PriceAtDate priceAtDate= new PriceAtDate();
|
|
|
424 |
priceAtDate.setDate(date);
|
|
|
425 |
priceAtDate.setPrice(ourPrice);
|
|
|
426 |
itemIdOurPriceMap.put(item_id,priceAtDate);
|
|
|
427 |
}
|
| 8461 |
vikram.rag |
428 |
}
|
| 8826 |
vikram.rag |
429 |
if(nextLine[31].length() >0){
|
|
|
430 |
salePrice = Double.parseDouble(nextLine[31]);
|
|
|
431 |
if(itemIdSalePriceMap.containsKey(item_id) ){
|
|
|
432 |
if(itemIdSalePriceMap.get(item_id).getDate().getTime() < date.getTime()){
|
|
|
433 |
PriceAtDate priceAtDate= new PriceAtDate();
|
|
|
434 |
priceAtDate.setDate(date);
|
|
|
435 |
priceAtDate.setPrice(salePrice);
|
|
|
436 |
itemIdSalePriceMap.put(item_id,priceAtDate);
|
|
|
437 |
}
|
|
|
438 |
}
|
|
|
439 |
else{
|
| 8532 |
vikram.rag |
440 |
PriceAtDate priceAtDate= new PriceAtDate();
|
|
|
441 |
priceAtDate.setDate(date);
|
|
|
442 |
priceAtDate.setPrice(salePrice);
|
|
|
443 |
itemIdSalePriceMap.put(item_id,priceAtDate);
|
|
|
444 |
}
|
| 8461 |
vikram.rag |
445 |
}
|
| 8826 |
vikram.rag |
446 |
if(nextLine[32].length() >0){
|
|
|
447 |
minFBAPrice = Double.parseDouble(nextLine[32]);
|
|
|
448 |
if(itemIdminFBAPriceMap.containsKey(item_id)){
|
|
|
449 |
if(itemIdminFBAPriceMap.get(item_id).getDate().getTime() < date.getTime()){
|
|
|
450 |
PriceAtDate priceAtDate= new PriceAtDate();
|
|
|
451 |
priceAtDate.setDate(date);
|
|
|
452 |
priceAtDate.setPrice(minFBAPrice);
|
|
|
453 |
itemIdminFBAPriceMap.put(item_id,priceAtDate);
|
|
|
454 |
}
|
|
|
455 |
}
|
|
|
456 |
else{
|
| 8532 |
vikram.rag |
457 |
PriceAtDate priceAtDate= new PriceAtDate();
|
|
|
458 |
priceAtDate.setDate(date);
|
|
|
459 |
priceAtDate.setPrice(minFBAPrice);
|
|
|
460 |
itemIdminFBAPriceMap.put(item_id,priceAtDate);
|
|
|
461 |
}
|
| 8461 |
vikram.rag |
462 |
}
|
| 8826 |
vikram.rag |
463 |
if(nextLine[34].length() >0){
|
|
|
464 |
minMFNPrice = Double.parseDouble(nextLine[34]);
|
|
|
465 |
if(itemIdminMFNPriceMap.containsKey(item_id)){
|
|
|
466 |
if(itemIdminMFNPriceMap.get(item_id).getDate().getTime() < date.getTime()){
|
|
|
467 |
PriceAtDate priceAtDate= new PriceAtDate();
|
|
|
468 |
priceAtDate.setDate(date);
|
|
|
469 |
priceAtDate.setPrice(minMFNPrice);
|
|
|
470 |
itemIdminMFNPriceMap.put(item_id,priceAtDate);
|
|
|
471 |
}
|
|
|
472 |
}
|
|
|
473 |
else{
|
| 8532 |
vikram.rag |
474 |
PriceAtDate priceAtDate= new PriceAtDate();
|
|
|
475 |
priceAtDate.setDate(date);
|
|
|
476 |
priceAtDate.setPrice(minMFNPrice);
|
|
|
477 |
itemIdminMFNPriceMap.put(item_id,priceAtDate);
|
|
|
478 |
}
|
| 8461 |
vikram.rag |
479 |
}
|
| 8451 |
vikram.rag |
480 |
}
|
| 8285 |
kshitij.so |
481 |
}
|
| 8826 |
vikram.rag |
482 |
catch(Exception e){
|
|
|
483 |
e.printStackTrace();
|
|
|
484 |
}
|
| 8363 |
vikram.rag |
485 |
count++;
|
|
|
486 |
}
|
|
|
487 |
boolean oos;
|
| 9802 |
manish.sha |
488 |
List<AmazonFbaSalesSnapshot> fbaSalesSnapShotList = new ArrayList<AmazonFbaSalesSnapshot>();
|
| 8363 |
vikram.rag |
489 |
for (Entry<Date, Map<Long, FbaSalesSnapshot>> entry : orderDateItemIdFbaSaleSnapshotMap.entrySet()){
|
|
|
490 |
Date orderDate = entry.getKey();
|
|
|
491 |
for(Entry<Long, FbaSalesSnapshot> entry1 :entry.getValue().entrySet()){
|
|
|
492 |
System.out.println("Item ID is " + entry1.getKey());
|
| 12688 |
amit.gupta |
493 |
Long inventory = 0l;
|
| 8363 |
vikram.rag |
494 |
|
|
|
495 |
if(inventory==0 && entry1.getValue().getTotalOrderCount()==0){
|
|
|
496 |
oos=true;
|
| 8285 |
kshitij.so |
497 |
}
|
| 8363 |
vikram.rag |
498 |
else{
|
| 8294 |
kshitij.so |
499 |
oos=false;
|
| 8285 |
kshitij.so |
500 |
}
|
| 8363 |
vikram.rag |
501 |
Long item_id = entry1.getKey();
|
| 8532 |
vikram.rag |
502 |
Amazonlisted amazon_item=catalogClient.getAmazonItemDetails(item_id);
|
|
|
503 |
if(amazon_item.getItemid()==0){
|
|
|
504 |
continue;
|
|
|
505 |
}
|
| 8363 |
vikram.rag |
506 |
System.out.println(orderDate +","+entry1.getKey()+","+entry1.getValue()+","+ inventory +","+ oos+","+itemIdSalePriceMap.get(item_id)+","+itemIdminFBAPriceMap.get(item_id)+","+itemIdminMFNPriceMap.get(item_id));
|
|
|
507 |
AmazonFbaSalesSnapshot amazonfbasalessnapshot = new AmazonFbaSalesSnapshot();
|
|
|
508 |
amazonfbasalessnapshot.setDateOfSale(orderDate.getTime());
|
|
|
509 |
amazonfbasalessnapshot.setItem_id(entry1.getKey());
|
|
|
510 |
amazonfbasalessnapshot.setTotalOrderCount(entry1.getValue().getPromotionOrderCount());
|
|
|
511 |
amazonfbasalessnapshot.setTotalOrderCount(entry1.getValue().getTotalOrderCount());
|
|
|
512 |
amazonfbasalessnapshot.setTotalSale(entry1.getValue().getTotalSale());
|
|
|
513 |
amazonfbasalessnapshot.setPromotionSale(entry1.getValue().getTotalPromotionSale());
|
|
|
514 |
amazonfbasalessnapshot.setIsOutOfStock(oos);
|
| 8461 |
vikram.rag |
515 |
if(itemIdSalePriceMap.containsKey(item_id) && itemIdSalePriceMap.get(item_id).getPrice()!=0){
|
|
|
516 |
amazonfbasalessnapshot.setSalePrice(itemIdSalePriceMap.get(item_id).getPrice());
|
| 8532 |
vikram.rag |
517 |
amazonfbasalessnapshot.setSalePriceSnapshotDate(itemIdSalePriceMap.get(item_id).getDate().getTime());
|
| 8363 |
vikram.rag |
518 |
}
|
|
|
519 |
else{
|
| 8460 |
vikram.rag |
520 |
amazonfbasalessnapshot.setSalePrice(0.0);
|
| 8532 |
vikram.rag |
521 |
amazonfbasalessnapshot.setSalePriceSnapshotDate(0);
|
| 8363 |
vikram.rag |
522 |
}
|
| 8461 |
vikram.rag |
523 |
if(itemIdminMFNPriceMap.containsKey(item_id) && itemIdminMFNPriceMap.get(item_id).getPrice()!=0){
|
|
|
524 |
amazonfbasalessnapshot.setMinMfnPrice(itemIdminMFNPriceMap.get(item_id).getPrice());
|
| 8532 |
vikram.rag |
525 |
amazonfbasalessnapshot.setMinMfnPriceSnapshotDate(itemIdminMFNPriceMap.get(item_id).getDate().getTime());
|
| 8363 |
vikram.rag |
526 |
}
|
|
|
527 |
else{
|
| 8460 |
vikram.rag |
528 |
amazonfbasalessnapshot.setMinMfnPrice(0.0);
|
| 8532 |
vikram.rag |
529 |
amazonfbasalessnapshot.setMinMfnPriceSnapshotDate(0);
|
| 8363 |
vikram.rag |
530 |
}
|
| 8461 |
vikram.rag |
531 |
if(itemIdminFBAPriceMap.containsKey(item_id) && itemIdminFBAPriceMap.get(item_id).getPrice()!=0){
|
|
|
532 |
amazonfbasalessnapshot.setMinFbaPrice(itemIdminFBAPriceMap.get(item_id).getPrice());
|
| 8532 |
vikram.rag |
533 |
amazonfbasalessnapshot.setMinFbaPriceSnapshotDate(itemIdminFBAPriceMap.get(item_id).getDate().getTime());
|
| 8363 |
vikram.rag |
534 |
}
|
|
|
535 |
else{
|
| 8460 |
vikram.rag |
536 |
amazonfbasalessnapshot.setMinFbaPrice(0.0);
|
| 8532 |
vikram.rag |
537 |
amazonfbasalessnapshot.setMinFbaPriceSnapshotDate(0);
|
| 8363 |
vikram.rag |
538 |
}
|
| 8461 |
vikram.rag |
539 |
if(itemIdOurPriceMap.containsKey(item_id) && itemIdOurPriceMap.get(item_id).getPrice()!=0){
|
|
|
540 |
amazonfbasalessnapshot.setOurPrice(itemIdOurPriceMap.get(item_id).getPrice());
|
| 8532 |
vikram.rag |
541 |
amazonfbasalessnapshot.setOurPriceSnapshotDate(itemIdOurPriceMap.get(item_id).getDate().getTime());
|
| 8445 |
vikram.rag |
542 |
}
|
|
|
543 |
else{
|
| 8460 |
vikram.rag |
544 |
amazonfbasalessnapshot.setOurPrice(amazon_item.getFbaPrice());
|
| 8532 |
vikram.rag |
545 |
amazonfbasalessnapshot.setOurPriceSnapshotDate(0);
|
| 8445 |
vikram.rag |
546 |
}
|
| 8363 |
vikram.rag |
547 |
amazonfbasalessnapshot.setAmazonFbaInventory(inventory);
|
| 9802 |
manish.sha |
548 |
fbaSalesSnapShotList.add(amazonfbasalessnapshot);
|
| 8285 |
kshitij.so |
549 |
}
|
|
|
550 |
}
|
| 9802 |
manish.sha |
551 |
transactionServiceClient.getClient().bulkAddOrUpdateAmazonFbaSalesSnapshot(fbaSalesSnapShotList);
|
| 8363 |
vikram.rag |
552 |
} catch (IOException e) {
|
|
|
553 |
// TODO Auto-generated catch block
|
|
|
554 |
e.printStackTrace();
|
|
|
555 |
} catch (ParseException e) {
|
|
|
556 |
// TODO Auto-generated catch block
|
|
|
557 |
e.printStackTrace();
|
|
|
558 |
} catch (TException e) {
|
|
|
559 |
// TODO Auto-generated catch block
|
|
|
560 |
e.printStackTrace();
|
|
|
561 |
continue;
|
| 8285 |
kshitij.so |
562 |
}
|
| 8363 |
vikram.rag |
563 |
break;
|
|
|
564 |
|
|
|
565 |
}
|
|
|
566 |
else{
|
|
|
567 |
System.out.println("Report not ready");
|
|
|
568 |
try {
|
|
|
569 |
Thread.sleep(5*60*1000);
|
|
|
570 |
} catch (InterruptedException e) {
|
|
|
571 |
// TODO Auto-generated catch block
|
|
|
572 |
e.printStackTrace();
|
| 8294 |
kshitij.so |
573 |
}
|
|
|
574 |
}
|
| 8285 |
kshitij.so |
575 |
}
|
|
|
576 |
|
|
|
577 |
// Note that depending on the type of report being downloaded, a report can reach
|
|
|
578 |
// sizes greater than 1GB. For this reason we recommend that you _always_ program to
|
|
|
579 |
// MWS in a streaming fashion. Otherwise, as your business grows you may silently reach
|
|
|
580 |
// the in-memory size limit and have to re-work your solution.
|
|
|
581 |
//
|
|
|
582 |
|
|
|
583 |
|
|
|
584 |
}
|
|
|
585 |
|
|
|
586 |
}
|