| Line 4... |
Line 4... |
| 4 |
import in.shop2020.model.v1.inventory.AmazonFbaInventorySnapshot;
|
4 |
import in.shop2020.model.v1.inventory.AmazonFbaInventorySnapshot;
|
| 5 |
import in.shop2020.model.v1.order.AmazonFbaSalesSnapshot;
|
5 |
import in.shop2020.model.v1.order.AmazonFbaSalesSnapshot;
|
| 6 |
import in.shop2020.thrift.clients.CatalogClient;
|
6 |
import in.shop2020.thrift.clients.CatalogClient;
|
| 7 |
import in.shop2020.thrift.clients.InventoryClient;
|
7 |
import in.shop2020.thrift.clients.InventoryClient;
|
| 8 |
import in.shop2020.thrift.clients.TransactionClient;
|
8 |
import in.shop2020.thrift.clients.TransactionClient;
|
| - |
|
9 |
import in.shop2020.utils.GmailUtils;
|
| 9 |
|
10 |
|
| 10 |
import java.io.FileNotFoundException;
|
11 |
import java.io.FileNotFoundException;
|
| 11 |
import java.io.FileOutputStream;
|
12 |
import java.io.FileOutputStream;
|
| 12 |
import java.io.FileReader;
|
13 |
import java.io.FileReader;
|
| 13 |
import java.io.IOException;
|
14 |
import java.io.IOException;
|
| Line 19... |
Line 20... |
| 19 |
import java.util.Date;
|
20 |
import java.util.Date;
|
| 20 |
import java.util.GregorianCalendar;
|
21 |
import java.util.GregorianCalendar;
|
| 21 |
import java.util.HashMap;
|
22 |
import java.util.HashMap;
|
| 22 |
import java.util.List;
|
23 |
import java.util.List;
|
| 23 |
import java.util.Map;
|
24 |
import java.util.Map;
|
| - |
|
25 |
import java.util.Map.Entry;
|
| 24 |
import java.util.TimeZone;
|
26 |
import java.util.TimeZone;
|
| 25 |
|
27 |
|
| 26 |
import javax.xml.datatype.DatatypeConfigurationException;
|
28 |
import javax.xml.datatype.DatatypeConfigurationException;
|
| 27 |
import javax.xml.datatype.DatatypeFactory;
|
29 |
import javax.xml.datatype.DatatypeFactory;
|
| 28 |
import javax.xml.datatype.Duration;
|
30 |
import javax.xml.datatype.Duration;
|
| Line 34... |
Line 36... |
| 34 |
import au.com.bytecode.opencsv.CSVReader;
|
36 |
import au.com.bytecode.opencsv.CSVReader;
|
| 35 |
|
37 |
|
| 36 |
import com.amazonaws.mws.MarketplaceWebService;
|
38 |
import com.amazonaws.mws.MarketplaceWebService;
|
| 37 |
import com.amazonaws.mws.MarketplaceWebServiceClient;
|
39 |
import com.amazonaws.mws.MarketplaceWebServiceClient;
|
| 38 |
import com.amazonaws.mws.MarketplaceWebServiceConfig;
|
40 |
import com.amazonaws.mws.MarketplaceWebServiceConfig;
|
| - |
|
41 |
import com.amazonaws.mws.MarketplaceWebServiceException;
|
| 39 |
import com.amazonaws.mws.model.GetReportListRequest;
|
42 |
import com.amazonaws.mws.model.GetReportListRequest;
|
| 40 |
import com.amazonaws.mws.model.GetReportRequest;
|
43 |
import com.amazonaws.mws.model.GetReportRequest;
|
| 41 |
import com.amazonaws.mws.model.IdList;
|
44 |
import com.amazonaws.mws.model.IdList;
|
| 42 |
import com.amazonaws.mws.model.RequestReportRequest;
|
45 |
import com.amazonaws.mws.model.RequestReportRequest;
|
| 43 |
|
46 |
|
| Line 155... |
Line 158... |
| 155 |
XMLGregorianCalendar inventoryEndDate = df.newXMLGregorianCalendar(new GregorianCalendar());
|
158 |
XMLGregorianCalendar inventoryEndDate = df.newXMLGregorianCalendar(new GregorianCalendar());
|
| 156 |
System.out.println("Inventory Start Date " + inventoryStartDate + "Inventory End Date " + inventoryEndDate);
|
159 |
System.out.println("Inventory Start Date " + inventoryStartDate + "Inventory End Date " + inventoryEndDate);
|
| 157 |
inventoryhealthreportrequest.setStartDate(inventoryStartDate);
|
160 |
inventoryhealthreportrequest.setStartDate(inventoryStartDate);
|
| 158 |
inventoryhealthreportrequest.setEndDate(inventoryEndDate);
|
161 |
inventoryhealthreportrequest.setEndDate(inventoryEndDate);
|
| 159 |
Map<String,String> requestIdreportIdmap;
|
162 |
Map<String,String> requestIdreportIdmap;
|
| - |
|
163 |
String orderreportrequestId = null;
|
| - |
|
164 |
String inventoryhealthreportrequestId = null;
|
| - |
|
165 |
boolean retry=true;
|
| - |
|
166 |
int retryCount =0;
|
| - |
|
167 |
while(retry && retryCount!=5){
|
| - |
|
168 |
if(retryCount==4){
|
| - |
|
169 |
String emailFromAddress = "build@shop2020.in";
|
| - |
|
170 |
String password = "cafe@nes";
|
| - |
|
171 |
String[] sendTo = new String[]{ "vikram.raghav@shop2020.in"};
|
| - |
|
172 |
String emailSubjectTxt = "FBA Stock Estimation Sheet Failure";
|
| - |
|
173 |
|
| - |
|
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 {
|
| 160 |
String orderreportrequestId = RequestReportSample.invokeRequestReport(service, orderreportrequest);
|
185 |
orderreportrequestId = RequestReportSample.invokeRequestReport(service, orderreportrequest);
|
| 161 |
String inventoryhealthreportrequestId = RequestReportSample.invokeRequestReport(service, inventoryhealthreportrequest);
|
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);
|
| 162 |
int retry2=0;
|
193 |
retryCount++;
|
| - |
|
194 |
} catch (InterruptedException e1) {
|
| - |
|
195 |
// TODO Auto-generated catch block
|
| - |
|
196 |
e1.printStackTrace();
|
| - |
|
197 |
}
|
| - |
|
198 |
}
|
| - |
|
199 |
}
|
| 163 |
while(true){
|
200 |
while(true){
|
| 164 |
int retry1 = 0;
|
- |
|
| 165 |
while(true){
|
- |
|
| 166 |
GetReportListRequest requestreportlist = new GetReportListRequest();
|
201 |
GetReportListRequest requestreportlist = new GetReportListRequest();
|
| 167 |
requestreportlist.setMerchant( merchantId );
|
202 |
requestreportlist.setMerchant( merchantId );
|
| 168 |
final IdList requestIdList = new IdList(Arrays.asList(orderreportrequestId,inventoryhealthreportrequestId));
|
203 |
final IdList requestIdList = new IdList(Arrays.asList(orderreportrequestId,inventoryhealthreportrequestId));
|
| 169 |
requestreportlist.setReportRequestIdList(requestIdList);
|
204 |
requestreportlist.setReportRequestIdList(requestIdList);
|
| 170 |
requestIdreportIdmap = GetReportListSample.invokeGetReportList(service, requestreportlist);
|
205 |
requestIdreportIdmap = GetReportListSample.invokeGetReportList(service, requestreportlist);
|
| 171 |
if(requestIdreportIdmap.get(orderreportrequestId)!=null && requestIdreportIdmap.get(inventoryhealthreportrequestId)!=null){
|
206 |
if(requestIdreportIdmap.get(orderreportrequestId)!=null && requestIdreportIdmap.get(inventoryhealthreportrequestId)!=null){
|
| 172 |
GetReportRequest requestorderreport = new GetReportRequest();
|
207 |
GetReportRequest requestorderreport = new GetReportRequest();
|
| 173 |
GetReportRequest requestinventoryhealthreport = new GetReportRequest();
|
208 |
GetReportRequest requestinventoryhealthreport = new GetReportRequest();
|
| 174 |
requestorderreport.setMerchant( merchantId );
|
209 |
requestorderreport.setMerchant( merchantId );
|
| 175 |
requestinventoryhealthreport.setMerchant(merchantId);
|
210 |
requestinventoryhealthreport.setMerchant(merchantId);
|
| 176 |
requestorderreport.setReportId( requestIdreportIdmap.get(orderreportrequestId));
|
211 |
requestorderreport.setReportId( requestIdreportIdmap.get(orderreportrequestId));
|
| 177 |
requestinventoryhealthreport.setReportId(requestIdreportIdmap.get(inventoryhealthreportrequestId));
|
212 |
requestinventoryhealthreport.setReportId(requestIdreportIdmap.get(inventoryhealthreportrequestId));
|
| 178 |
OutputStream orderreport=null;
|
213 |
OutputStream orderreport=null;
|
| 179 |
OutputStream inventoryhealthreport=null;
|
214 |
OutputStream inventoryhealthreport=null;
|
| 180 |
try {
|
215 |
try {
|
| 181 |
orderreport = new FileOutputStream( "/home/vikram/Desktop/amazonorderreport.csv" );
|
216 |
orderreport = new FileOutputStream( "/home/amazonorderreport.csv" );
|
| 182 |
inventoryhealthreport = new FileOutputStream( "/home/vikram/Desktop/inventoryhealthreport.csv" );
|
217 |
inventoryhealthreport = new FileOutputStream( "/home/inventoryhealthreport.csv" );
|
| 183 |
} catch (FileNotFoundException e) {
|
218 |
} catch (FileNotFoundException e) {
|
| 184 |
// TODO Auto-generated catch block
|
219 |
// TODO Auto-generated catch block
|
| 185 |
e.printStackTrace();
|
220 |
e.printStackTrace();
|
| 186 |
}
|
221 |
}
|
| 187 |
requestorderreport.setReportOutputStream(orderreport);
|
222 |
requestorderreport.setReportOutputStream(orderreport);
|
| 188 |
requestinventoryhealthreport.setReportOutputStream(inventoryhealthreport);
|
223 |
requestinventoryhealthreport.setReportOutputStream(inventoryhealthreport);
|
| 189 |
GetReportSample.invokeGetReport(service, requestorderreport);
|
224 |
GetReportSample.invokeGetReport(service, requestorderreport);
|
| 190 |
GetReportSample.invokeGetReport(service, requestinventoryhealthreport);
|
225 |
GetReportSample.invokeGetReport(service, requestinventoryhealthreport);
|
| 191 |
System.out.println("Order and Inventory Reports are ready please check");
|
226 |
System.out.println("Order and Inventory Reports are ready please check");
|
| 192 |
CSVReader orderreportreader = null;
|
227 |
CSVReader orderreportreader = null;
|
| 193 |
CSVReader inventoryhealthreportreader = null;
|
228 |
CSVReader inventoryhealthreportreader = null;
|
| 194 |
try {
|
229 |
try {
|
| 195 |
orderreportreader = new CSVReader(new FileReader("/home/vikram/Desktop/amazonorderreport.csv"),'\t');
|
230 |
orderreportreader = new CSVReader(new FileReader("/home/amazonorderreport.csv"),'\t');
|
| 196 |
inventoryhealthreportreader = new CSVReader(new FileReader("/home/vikram/Desktop/inventoryhealthreport.csv"),'\t');
|
231 |
inventoryhealthreportreader = new CSVReader(new FileReader("/home/inventoryhealthreport.csv"),'\t');
|
| 197 |
} catch (FileNotFoundException e) {
|
232 |
} catch (FileNotFoundException e) {
|
| 198 |
// TODO Auto-generated catch block
|
233 |
// TODO Auto-generated catch block
|
| 199 |
e.printStackTrace();
|
234 |
e.printStackTrace();
|
| 200 |
}
|
235 |
}
|
| 201 |
String [] nextLine;
|
236 |
String [] nextLine;
|
| 202 |
try {
|
237 |
try {
|
| 203 |
int count =1;
|
238 |
int count =1;
|
| 204 |
Map<Date,Map<Long,Integer>> orderDateItemIdCountMap = new HashMap<Date,Map<Long,Integer>>();
|
239 |
Map<Date,Map<Long,FbaSalesSnapshot>> orderDateItemIdFbaSaleSnapshotMap = new HashMap<Date,Map<Long,FbaSalesSnapshot>>();
|
| 205 |
while ((nextLine = orderreportreader.readNext()) != null) {
|
240 |
while ((nextLine = orderreportreader.readNext()) != null) {
|
| 206 |
if(count!=1 && nextLine[5].equalsIgnoreCase("Amazon") && (nextLine[13].equalsIgnoreCase("Unshipped") || nextLine[13].equalsIgnoreCase("Shipped"))){
|
241 |
if(count!=1 && nextLine[5].equalsIgnoreCase("Amazon") && nextLine[6].equalsIgnoreCase("Amazon.in") && (nextLine[13].equalsIgnoreCase("Unshipped") || nextLine[13].equalsIgnoreCase("Shipped"))){
|
| 207 |
SimpleDateFormat istFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
|
242 |
SimpleDateFormat istFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
|
| 208 |
istFormatter .setLenient(false);
|
243 |
istFormatter .setLenient(false);
|
| 209 |
TimeZone zone= TimeZone.getTimeZone("GMT");
|
244 |
TimeZone zone= TimeZone.getTimeZone("GMT");
|
| 210 |
istFormatter.setTimeZone(zone);
|
245 |
istFormatter.setTimeZone(zone);
|
| 211 |
Date date = istFormatter.parse(nextLine[2]);
|
246 |
Date date = istFormatter.parse(nextLine[2]);
|
| 212 |
SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
|
247 |
SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
|
| 213 |
Date date_key = dateFormat.parse(dateFormat.format(date));
|
248 |
Date date_key = dateFormat.parse(dateFormat.format(date));
|
| 214 |
System.out.println(nextLine[0]+" "+date_key+" "+ nextLine[11] +" " + nextLine[13] + " " + nextLine[14]);
|
249 |
System.out.println(nextLine[0]+" "+date_key+" "+ nextLine[11] +" " + nextLine[13] + " " + nextLine[14]);
|
| 215 |
Long itemid = Long.parseLong(nextLine[11].replaceAll("FBA",""));
|
250 |
Long itemid = Long.parseLong(nextLine[11].replaceAll("FBA",""));
|
| - |
|
251 |
|
| 216 |
Integer qty = new Integer(nextLine[14]);
|
252 |
Integer qty = new Integer(nextLine[14]);
|
| - |
|
253 |
Float itemSale = null;
|
| - |
|
254 |
if(nextLine[16].length()!=0){
|
| - |
|
255 |
itemSale = new Float(nextLine[16]);
|
| - |
|
256 |
continue;
|
| - |
|
257 |
}
|
| - |
|
258 |
Float itemDiscount;
|
| - |
|
259 |
if(nextLine[22].length()!=0){
|
| - |
|
260 |
itemDiscount = new Float(nextLine[22]);
|
| - |
|
261 |
}
|
| - |
|
262 |
else{
|
| - |
|
263 |
itemDiscount = new Float(0);
|
| - |
|
264 |
}
|
| 217 |
if(orderDateItemIdCountMap.containsKey(date_key)){
|
265 |
if(orderDateItemIdFbaSaleSnapshotMap.containsKey(date_key)){
|
| 218 |
if(orderDateItemIdCountMap.get(date_key).containsKey(itemid)){
|
266 |
if(orderDateItemIdFbaSaleSnapshotMap.get(date_key).containsKey(itemid)){
|
| 219 |
orderDateItemIdCountMap.get(date_key).put(itemid,orderDateItemIdCountMap.get(date_key).get(itemid)+qty);
|
267 |
FbaSalesSnapshot fbaSalesSnapshot = orderDateItemIdFbaSaleSnapshotMap.get(date_key).get(itemid);
|
| - |
|
268 |
if(itemDiscount!=0){
|
| - |
|
269 |
fbaSalesSnapshot.setPromotionOrderCount(qty);
|
| - |
|
270 |
fbaSalesSnapshot.setTotalPromotionSale(fbaSalesSnapshot.totalPromotionSale + (itemSale - itemDiscount));
|
| 220 |
}
|
271 |
}
|
| 221 |
else{
|
272 |
else{
|
| - |
|
273 |
fbaSalesSnapshot.setPromotionOrderCount(0);
|
| 222 |
orderDateItemIdCountMap.get(date_key).put(itemid,qty);
|
274 |
fbaSalesSnapshot.setTotalPromotionSale((float) 0);
|
| 223 |
}
|
275 |
}
|
| - |
|
276 |
fbaSalesSnapshot.setTotalOrderCount(fbaSalesSnapshot.getTotalOrderCount() + qty);
|
| - |
|
277 |
fbaSalesSnapshot.setTotalSale(fbaSalesSnapshot.getTotalSale() + itemSale);
|
| - |
|
278 |
orderDateItemIdFbaSaleSnapshotMap.get(date_key).put(itemid,fbaSalesSnapshot);
|
| 224 |
}
|
279 |
}
|
| 225 |
else{
|
280 |
else{
|
| 226 |
|
- |
|
| 227 |
Map<Long,Integer> itemIdcountMap = new HashMap<Long,Integer>();
|
281 |
FbaSalesSnapshot fbaSalesSnapshot = new FbaSalesSnapshot();
|
| 228 |
itemIdcountMap.put(itemid,qty);
|
282 |
fbaSalesSnapshot.setTotalOrderCount(qty);
|
| 229 |
orderDateItemIdCountMap.put(date_key,itemIdcountMap);
|
283 |
fbaSalesSnapshot.setTotalSale(itemSale);
|
| 230 |
}
|
- |
|
| 231 |
|
- |
|
| 232 |
}
|
- |
|
| 233 |
count++;
|
- |
|
| 234 |
}
|
- |
|
| 235 |
InventoryClient inventoryServiceClient = null;
|
- |
|
| 236 |
TransactionClient transactionServiceClient = null;
|
- |
|
| 237 |
CatalogClient catalogServiceClient = null;
|
- |
|
| 238 |
try {
|
- |
|
| 239 |
inventoryServiceClient = new InventoryClient();
|
- |
|
| 240 |
transactionServiceClient = new TransactionClient();
|
- |
|
| 241 |
catalogServiceClient = new CatalogClient();
|
- |
|
| 242 |
//catalogServiceClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port");
|
- |
|
| 243 |
} catch (Exception e) {
|
- |
|
| 244 |
// TODO Auto-generated catch block
|
- |
|
| 245 |
e.printStackTrace();
|
284 |
if(itemDiscount!=0){
|
| 246 |
}
|
- |
|
| 247 |
in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
|
- |
|
| 248 |
in.shop2020.model.v1.order.TransactionService.Client transactionClient = transactionServiceClient.getClient();
|
- |
|
| 249 |
in.shop2020.model.v1.catalog.CatalogService.Client catalogClient = catalogServiceClient.getClient();
|
- |
|
| 250 |
SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
|
- |
|
| 251 |
Date date_today = dateFormat.parse(dateFormat.format(new Date()));
|
285 |
fbaSalesSnapshot.setPromotionOrderCount(qty);
|
| 252 |
List<AmazonFbaInventorySnapshot> nonzeroFbaInventorySnapshotlist = inventoryClient.getAllNonzeroAmazonFbaItemInventory();
|
- |
|
| 253 |
if(nonzeroFbaInventorySnapshotlist!=null){
|
- |
|
| 254 |
for(AmazonFbaInventorySnapshot amazonFbaInventory:nonzeroFbaInventorySnapshotlist){
|
286 |
fbaSalesSnapshot.setTotalPromotionSale(itemSale - itemDiscount);
|
| 255 |
if(orderDateItemIdCountMap.containsKey(date_today) ){
|
- |
|
| 256 |
if(!orderDateItemIdCountMap.get(date_today).containsKey(amazonFbaInventory.getItem_id())){
|
- |
|
| 257 |
orderDateItemIdCountMap.get(date_today).put(amazonFbaInventory.getItem_id(),0);
|
- |
|
| 258 |
}
|
287 |
}
|
| 259 |
|
- |
|
| 260 |
}
|
- |
|
| 261 |
else{
|
288 |
else{
|
| 262 |
Map<Long,Integer> itemIdcountMap = new HashMap<Long,Integer>();
|
289 |
fbaSalesSnapshot.setPromotionOrderCount(0);
|
| 263 |
itemIdcountMap.put(amazonFbaInventory.getItem_id(),0);
|
290 |
fbaSalesSnapshot.setTotalPromotionSale((float) 0);
|
| - |
|
291 |
}
|
| 264 |
orderDateItemIdCountMap.put(date_today,itemIdcountMap);
|
292 |
orderDateItemIdFbaSaleSnapshotMap.get(date_key).put(itemid,fbaSalesSnapshot);
|
| 265 |
}
|
293 |
}
|
| 266 |
}
|
294 |
}
|
| 267 |
}
|
- |
|
| 268 |
else{
|
295 |
else{
|
| 269 |
System.out.println("No inventory in FBA");
|
- |
|
| 270 |
}
|
- |
|
| 271 |
orderDateItemIdCountMap.get(date_today);
|
- |
|
| 272 |
Map<Long,Double> itemIdSalePriceMap = new HashMap<Long,Double>();
|
296 |
Map<Long,FbaSalesSnapshot> ItemIdFbaSaleSnapshotMap = new HashMap<Long,FbaSalesSnapshot>();
|
| 273 |
Map<Long,Double> itemIdminFBAPriceMap = new HashMap<Long,Double>();
|
- |
|
| 274 |
Map<Long,Double> itemIdminMFNPriceMap = new HashMap<Long,Double>();
|
- |
|
| 275 |
count=1;
|
- |
|
| 276 |
while ((nextLine = inventoryhealthreportreader.readNext()) != null ) {
|
- |
|
| 277 |
if(count!=1){
|
- |
|
| 278 |
//System.out.println(nextLine[1] +" "+ nextLine[31] +" " + nextLine[32] + " " + nextLine[34]);
|
- |
|
| 279 |
Long item_id = Long.parseLong(nextLine[1].replaceAll("FBA",""));
|
- |
|
| 280 |
Double salePrice = Double.parseDouble(nextLine[31]);
|
- |
|
| 281 |
Double minFBAPrice = Double.parseDouble(nextLine[32]);
|
- |
|
| 282 |
Double minMFNPrice = Double.parseDouble(nextLine[34]);
|
- |
|
| 283 |
itemIdSalePriceMap.put(item_id,salePrice);
|
- |
|
| 284 |
itemIdminFBAPriceMap.put(item_id,minFBAPrice);
|
- |
|
| 285 |
itemIdminMFNPriceMap.put(item_id,minMFNPrice);
|
- |
|
| 286 |
}
|
- |
|
| 287 |
count++;
|
- |
|
| 288 |
}
|
- |
|
| 289 |
boolean oos;
|
- |
|
| 290 |
for (Map.Entry<Date, Map<Long, Integer>> entry : orderDateItemIdCountMap.entrySet()){
|
- |
|
| 291 |
Date orderDate = entry.getKey();
|
- |
|
| 292 |
for(Map.Entry<Long, Integer> entry1 :entry.getValue().entrySet()){
|
- |
|
| 293 |
Long inventory = inventoryClient.getAmazonFbaItemInventory(entry1.getKey());
|
- |
|
| 294 |
oos=false;
|
- |
|
| 295 |
if(inventory==0 && entry1.getValue()==0)
|
- |
|
| 296 |
oos=true;
|
- |
|
| 297 |
Long item_id = entry1.getKey();
|
- |
|
| 298 |
System.out.println(orderDate +","+entry1.getKey()+","+entry1.getValue()+","+ inventory +","+ oos+","+itemIdSalePriceMap.get(item_id)+","+itemIdminFBAPriceMap.get(item_id)+","+itemIdminMFNPriceMap.get(item_id));
|
- |
|
| 299 |
AmazonFbaSalesSnapshot amazonfbasalessnapshot = new AmazonFbaSalesSnapshot();
|
297 |
FbaSalesSnapshot fbaSalesSnapshot = new FbaSalesSnapshot();
|
| 300 |
amazonfbasalessnapshot.setDateOfSale(orderDate.getTime());
|
- |
|
| 301 |
amazonfbasalessnapshot.setItem_id(entry1.getKey());
|
298 |
fbaSalesSnapshot.setTotalOrderCount(qty);
|
| 302 |
amazonfbasalessnapshot.setOrderCount(entry1.getValue());
|
299 |
fbaSalesSnapshot.setTotalSale(itemSale);
|
| 303 |
amazonfbasalessnapshot.setIsOutOfStock(oos);
|
300 |
if(itemDiscount!=0){
|
| 304 |
Amazonlisted amazon_item = catalogClient.getAmazonItemDetails(item_id);
|
- |
|
| 305 |
if(itemIdSalePriceMap.containsKey(item_id) && itemIdSalePriceMap.get(item_id)!=0){
|
301 |
fbaSalesSnapshot.setTotalPromotionSale(itemSale - itemDiscount);
|
| 306 |
amazonfbasalessnapshot.setSalePrice(itemIdSalePriceMap.get(item_id));
|
302 |
fbaSalesSnapshot.setPromotionOrderCount(qty);
|
| 307 |
}
|
303 |
}
|
| 308 |
else{
|
304 |
else{
|
| 309 |
amazonfbasalessnapshot.setSalePrice(amazon_item.getFbaPrice());
|
305 |
fbaSalesSnapshot.setTotalPromotionSale((float) 0);
|
| - |
|
306 |
fbaSalesSnapshot.setPromotionOrderCount(0);
|
| 310 |
}
|
307 |
}
|
| 311 |
if(itemIdminMFNPriceMap.containsKey(item_id) && itemIdminMFNPriceMap.get(item_id)!=0){
|
- |
|
| 312 |
amazonfbasalessnapshot.setMinFbaPrice(itemIdminMFNPriceMap.get(item_id));
|
- |
|
| 313 |
}
|
- |
|
| 314 |
if(itemIdminMFNPriceMap.containsKey(item_id) && itemIdminMFNPriceMap.get(item_id)!=0){
|
- |
|
| 315 |
amazonfbasalessnapshot.setMinMfnPrice(itemIdminMFNPriceMap.get(item_id));
|
- |
|
| 316 |
}
|
- |
|
| 317 |
amazonfbasalessnapshot.setAmazonFbaInventory(inventory);
|
308 |
ItemIdFbaSaleSnapshotMap.put(itemid,fbaSalesSnapshot);
|
| 318 |
transactionClient.addOrUpdateAmazonFbaSalesSnapshot(amazonfbasalessnapshot);
|
309 |
orderDateItemIdFbaSaleSnapshotMap.put(date_key,ItemIdFbaSaleSnapshotMap);
|
| 319 |
}
|
310 |
}
|
| 320 |
}
|
311 |
}
|
| 321 |
} catch (IOException e) {
|
- |
|
| 322 |
// TODO Auto-generated catch block
|
- |
|
| 323 |
e.printStackTrace();
|
- |
|
| 324 |
} catch (ParseException e) {
|
- |
|
| 325 |
// TODO Auto-generated catch block
|
- |
|
| 326 |
e.printStackTrace();
|
- |
|
| 327 |
} catch (TException e) {
|
- |
|
| 328 |
// TODO Auto-generated catch block
|
- |
|
| 329 |
e.printStackTrace();
|
312 |
count++;
|
| 330 |
}
|
313 |
}
|
| 331 |
break;
|
314 |
InventoryClient inventoryServiceClient = null;
|
| 332 |
}
|
- |
|
| 333 |
else{
|
315 |
TransactionClient transactionServiceClient = null;
|
| 334 |
System.out.println("Report not ready");
|
316 |
CatalogClient catalogServiceClient = null;
|
| 335 |
try {
|
317 |
try {
|
| - |
|
318 |
inventoryServiceClient = new InventoryClient();
|
| - |
|
319 |
transactionServiceClient = new TransactionClient();
|
| 336 |
Thread.sleep(5*60*1000);
|
320 |
catalogServiceClient = new CatalogClient();
|
| - |
|
321 |
//catalogServiceClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port");
|
| 337 |
} catch (InterruptedException e) {
|
322 |
} catch (Exception e) {
|
| 338 |
// TODO Auto-generated catch block
|
323 |
// TODO Auto-generated catch block
|
| 339 |
e.printStackTrace();
|
324 |
e.printStackTrace();
|
| - |
|
325 |
}
|
| - |
|
326 |
in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
|
| - |
|
327 |
in.shop2020.model.v1.order.TransactionService.Client transactionClient = transactionServiceClient.getClient();
|
| - |
|
328 |
in.shop2020.model.v1.catalog.CatalogService.Client catalogClient = catalogServiceClient.getClient();
|
| - |
|
329 |
SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
|
| - |
|
330 |
Date date_today = dateFormat.parse(dateFormat.format(new Date()));
|
| - |
|
331 |
List<AmazonFbaInventorySnapshot> nonzeroFbaInventorySnapshotlist = inventoryClient.getAllAmazonFbaItemInventory();
|
| - |
|
332 |
if(nonzeroFbaInventorySnapshotlist!=null){
|
| - |
|
333 |
for(AmazonFbaInventorySnapshot amazonFbaInventory:nonzeroFbaInventorySnapshotlist){
|
| - |
|
334 |
if(orderDateItemIdFbaSaleSnapshotMap.containsKey(date_today) ){
|
| - |
|
335 |
if(!orderDateItemIdFbaSaleSnapshotMap.get(date_today).containsKey(amazonFbaInventory.getItem_id())){
|
| - |
|
336 |
Map<Long,FbaSalesSnapshot> ItemIdFbaSaleSnapshotMap = new HashMap<Long,FbaSalesSnapshot>();
|
| - |
|
337 |
FbaSalesSnapshot fbaSalesSnapshot = new FbaSalesSnapshot();
|
| - |
|
338 |
fbaSalesSnapshot.setTotalOrderCount(0);
|
| - |
|
339 |
fbaSalesSnapshot.setPromotionOrderCount(0);
|
| - |
|
340 |
fbaSalesSnapshot.setTotalPromotionSale((float) 0);
|
| - |
|
341 |
fbaSalesSnapshot.setTotalSale((float) 0);
|
| - |
|
342 |
ItemIdFbaSaleSnapshotMap.put(amazonFbaInventory.getItem_id(),fbaSalesSnapshot);
|
| - |
|
343 |
orderDateItemIdFbaSaleSnapshotMap.get(date_today).put(amazonFbaInventory.getItem_id(),fbaSalesSnapshot);
|
| - |
|
344 |
}
|
| - |
|
345 |
|
| - |
|
346 |
}
|
| - |
|
347 |
else{
|
| - |
|
348 |
Map<Long,FbaSalesSnapshot> ItemIdFbaSaleSnapshotMap = new HashMap<Long,FbaSalesSnapshot>();
|
| - |
|
349 |
FbaSalesSnapshot fbaSalesSnapshot = new FbaSalesSnapshot();
|
| - |
|
350 |
fbaSalesSnapshot.setTotalOrderCount(0);
|
| - |
|
351 |
fbaSalesSnapshot.setPromotionOrderCount(0);
|
| - |
|
352 |
fbaSalesSnapshot.setTotalPromotionSale((float) 0);
|
| - |
|
353 |
fbaSalesSnapshot.setTotalSale((float) 0);
|
| - |
|
354 |
ItemIdFbaSaleSnapshotMap.put(amazonFbaInventory.getItem_id(),fbaSalesSnapshot);
|
| - |
|
355 |
orderDateItemIdFbaSaleSnapshotMap.put(date_today,ItemIdFbaSaleSnapshotMap);
|
| - |
|
356 |
}
|
| - |
|
357 |
}
|
| 340 |
}
|
358 |
}
|
| - |
|
359 |
else{
|
| - |
|
360 |
System.out.println("No inventory in FBA");
|
| - |
|
361 |
}
|
| - |
|
362 |
Map<Long,Double> itemIdSalePriceMap = new HashMap<Long,Double>();
|
| - |
|
363 |
Map<Long,Double> itemIdminFBAPriceMap = new HashMap<Long,Double>();
|
| - |
|
364 |
Map<Long,Double> itemIdminMFNPriceMap = new HashMap<Long,Double>();
|
| - |
|
365 |
count=1;
|
| - |
|
366 |
while ((nextLine = inventoryhealthreportreader.readNext()) != null ) {
|
| - |
|
367 |
if(count!=1){
|
| - |
|
368 |
//System.out.println(nextLine[1] +" "+ nextLine[31] +" " + nextLine[32] + " " + nextLine[34]);
|
| - |
|
369 |
Long item_id = Long.parseLong(nextLine[1].replaceAll("FBA",""));
|
| - |
|
370 |
Double salePrice = Double.parseDouble(nextLine[31]);
|
| - |
|
371 |
Double minFBAPrice = Double.parseDouble(nextLine[32]);
|
| - |
|
372 |
Double minMFNPrice = Double.parseDouble(nextLine[34]);
|
| - |
|
373 |
itemIdSalePriceMap.put(item_id,salePrice);
|
| - |
|
374 |
itemIdminFBAPriceMap.put(item_id,minFBAPrice);
|
| - |
|
375 |
itemIdminMFNPriceMap.put(item_id,minMFNPrice);
|
| - |
|
376 |
}
|
| - |
|
377 |
count++;
|
| - |
|
378 |
}
|
| - |
|
379 |
boolean oos;
|
| - |
|
380 |
for (Entry<Date, Map<Long, FbaSalesSnapshot>> entry : orderDateItemIdFbaSaleSnapshotMap.entrySet()){
|
| - |
|
381 |
Date orderDate = entry.getKey();
|
| - |
|
382 |
for(Entry<Long, FbaSalesSnapshot> entry1 :entry.getValue().entrySet()){
|
| - |
|
383 |
System.out.println("Item ID is " + entry1.getKey());
|
| - |
|
384 |
Long inventory = inventoryClient.getAmazonFbaItemInventory(entry1.getKey());
|
| - |
|
385 |
|
| - |
|
386 |
if(inventory==0 && entry1.getValue().getTotalOrderCount()==0){
|
| - |
|
387 |
oos=true;
|
| - |
|
388 |
}
|
| - |
|
389 |
else{
|
| - |
|
390 |
oos=false;
|
| - |
|
391 |
}
|
| - |
|
392 |
Long item_id = entry1.getKey();
|
| - |
|
393 |
System.out.println(orderDate +","+entry1.getKey()+","+entry1.getValue()+","+ inventory +","+ oos+","+itemIdSalePriceMap.get(item_id)+","+itemIdminFBAPriceMap.get(item_id)+","+itemIdminMFNPriceMap.get(item_id));
|
| - |
|
394 |
AmazonFbaSalesSnapshot amazonfbasalessnapshot = new AmazonFbaSalesSnapshot();
|
| - |
|
395 |
amazonfbasalessnapshot.setDateOfSale(orderDate.getTime());
|
| - |
|
396 |
amazonfbasalessnapshot.setItem_id(entry1.getKey());
|
| - |
|
397 |
amazonfbasalessnapshot.setTotalOrderCount(entry1.getValue().getPromotionOrderCount());
|
| - |
|
398 |
amazonfbasalessnapshot.setTotalOrderCount(entry1.getValue().getTotalOrderCount());
|
| - |
|
399 |
amazonfbasalessnapshot.setTotalSale(entry1.getValue().getTotalSale());
|
| - |
|
400 |
amazonfbasalessnapshot.setPromotionSale(entry1.getValue().getTotalPromotionSale());
|
| - |
|
401 |
amazonfbasalessnapshot.setIsOutOfStock(oos);
|
| - |
|
402 |
Amazonlisted amazon_item=null;
|
| - |
|
403 |
if(catalogClient.getAmazonItemDetails(item_id)!=null)
|
| - |
|
404 |
amazon_item = catalogClient.getAmazonItemDetails(item_id);
|
| - |
|
405 |
else
|
| - |
|
406 |
continue;
|
| - |
|
407 |
if(itemIdSalePriceMap.containsKey(item_id) && itemIdSalePriceMap.get(item_id)!=0){
|
| - |
|
408 |
amazonfbasalessnapshot.setSalePrice(itemIdSalePriceMap.get(item_id));
|
| - |
|
409 |
}
|
| - |
|
410 |
else{
|
| - |
|
411 |
amazonfbasalessnapshot.setSalePrice(amazon_item.getFbaPrice());
|
| - |
|
412 |
}
|
| - |
|
413 |
if(itemIdminMFNPriceMap.containsKey(item_id) && itemIdminMFNPriceMap.get(item_id)!=0){
|
| - |
|
414 |
amazonfbasalessnapshot.setMinFbaPrice(itemIdminMFNPriceMap.get(item_id));
|
| - |
|
415 |
}
|
| - |
|
416 |
else{
|
| - |
|
417 |
amazonfbasalessnapshot.setMinFbaPrice(0.0);
|
| - |
|
418 |
}
|
| - |
|
419 |
if(itemIdminMFNPriceMap.containsKey(item_id) && itemIdminMFNPriceMap.get(item_id)!=0){
|
| - |
|
420 |
amazonfbasalessnapshot.setMinMfnPrice(itemIdminMFNPriceMap.get(item_id));
|
| - |
|
421 |
}
|
| - |
|
422 |
else{
|
| - |
|
423 |
amazonfbasalessnapshot.setMinMfnPrice(0.0);
|
| - |
|
424 |
}
|
| - |
|
425 |
amazonfbasalessnapshot.setAmazonFbaInventory(inventory);
|
| - |
|
426 |
transactionClient.addOrUpdateAmazonFbaSalesSnapshot(amazonfbasalessnapshot);
|
| - |
|
427 |
}
|
| - |
|
428 |
}
|
| - |
|
429 |
} catch (IOException e) {
|
| - |
|
430 |
// TODO Auto-generated catch block
|
| - |
|
431 |
e.printStackTrace();
|
| - |
|
432 |
} catch (ParseException e) {
|
| - |
|
433 |
// TODO Auto-generated catch block
|
| - |
|
434 |
e.printStackTrace();
|
| - |
|
435 |
} catch (TException e) {
|
| - |
|
436 |
// TODO Auto-generated catch block
|
| - |
|
437 |
e.printStackTrace();
|
| - |
|
438 |
continue;
|
| 341 |
}
|
439 |
}
|
| 342 |
retry1++;
|
- |
|
| 343 |
if(retry1==5){
|
- |
|
| 344 |
break;
|
- |
|
| 345 |
}
|
- |
|
| 346 |
}
|
- |
|
| 347 |
Thread.sleep(10*60*1000);
|
- |
|
| 348 |
retry2++;
|
- |
|
| 349 |
if(retry2==5){
|
- |
|
| 350 |
break;
|
440 |
break;
|
| - |
|
441 |
|
| - |
|
442 |
}
|
| - |
|
443 |
else{
|
| - |
|
444 |
System.out.println("Report not ready");
|
| - |
|
445 |
try {
|
| - |
|
446 |
Thread.sleep(5*60*1000);
|
| - |
|
447 |
} catch (InterruptedException e) {
|
| - |
|
448 |
// TODO Auto-generated catch block
|
| - |
|
449 |
e.printStackTrace();
|
| - |
|
450 |
}
|
| 351 |
}
|
451 |
}
|
| 352 |
}
|
452 |
}
|
| 353 |
|
453 |
|
| 354 |
// Note that depending on the type of report being downloaded, a report can reach
|
454 |
// Note that depending on the type of report being downloaded, a report can reach
|
| 355 |
// sizes greater than 1GB. For this reason we recommend that you _always_ program to
|
455 |
// sizes greater than 1GB. For this reason we recommend that you _always_ program to
|