| Line 1... |
Line 1... |
| 1 |
package in.shop2020;
|
1 |
package in.shop2020;
|
| 2 |
|
2 |
|
| 3 |
import in.shop2020.model.v1.catalog.CatalogService;
|
3 |
import in.shop2020.model.v1.catalog.CatalogService;
|
| 4 |
import in.shop2020.model.v1.catalog.Item;
|
4 |
import in.shop2020.model.v1.catalog.Item;
|
| 5 |
import in.shop2020.model.v1.catalog.SnapdealItem;
|
5 |
import in.shop2020.model.v1.catalog.SnapdealItem;
|
| - |
|
6 |
import in.shop2020.model.v1.catalog.SnapdealItemDetails;
|
| 6 |
import in.shop2020.model.v1.inventory.InventoryService.Client;
|
7 |
import in.shop2020.model.v1.inventory.InventoryService.Client;
|
| 7 |
import in.shop2020.model.v1.inventory.InventoryType;
|
8 |
import in.shop2020.model.v1.inventory.InventoryType;
|
| 8 |
import in.shop2020.model.v1.inventory.ItemInventory;
|
9 |
import in.shop2020.model.v1.inventory.ItemInventory;
|
| 9 |
import in.shop2020.model.v1.inventory.SnapdealInventoryItem;
|
10 |
import in.shop2020.model.v1.inventory.SnapdealInventoryItem;
|
| 10 |
import in.shop2020.model.v1.inventory.Warehouse;
|
11 |
import in.shop2020.model.v1.inventory.Warehouse;
|
| Line 15... |
Line 16... |
| 15 |
import in.shop2020.utils.GmailUtils;
|
16 |
import in.shop2020.utils.GmailUtils;
|
| 16 |
import inventory.Inventory;
|
17 |
import inventory.Inventory;
|
| 17 |
import inventory.InventoryHistory;
|
18 |
import inventory.InventoryHistory;
|
| 18 |
import inventory.InventoryHistoryItems;
|
19 |
import inventory.InventoryHistoryItems;
|
| 19 |
import inventory.InventoryItems;
|
20 |
import inventory.InventoryItems;
|
| - |
|
21 |
import inventory.PendingOrderInventoryHistory;
|
| 20 |
import inventory.SnapdealItemForInventory;
|
22 |
import inventory.SnapdealItemForInventory;
|
| 21 |
|
23 |
|
| 22 |
import java.io.BufferedReader;
|
24 |
import java.io.BufferedReader;
|
| 23 |
import java.io.File;
|
25 |
import java.io.File;
|
| 24 |
import java.io.FileInputStream;
|
26 |
import java.io.FileInputStream;
|
| Line 31... |
Line 33... |
| 31 |
import java.util.Calendar;
|
33 |
import java.util.Calendar;
|
| 32 |
import java.util.GregorianCalendar;
|
34 |
import java.util.GregorianCalendar;
|
| 33 |
import java.util.HashMap;
|
35 |
import java.util.HashMap;
|
| 34 |
import java.util.List;
|
36 |
import java.util.List;
|
| 35 |
import java.util.Map;
|
37 |
import java.util.Map;
|
| - |
|
38 |
import java.util.Map.Entry;
|
| 36 |
|
39 |
|
| 37 |
import javax.mail.MessagingException;
|
40 |
import javax.mail.MessagingException;
|
| 38 |
|
41 |
|
| 39 |
import org.apache.http.HttpResponse;
|
42 |
import org.apache.http.HttpResponse;
|
| 40 |
import org.apache.http.NameValuePair;
|
43 |
import org.apache.http.NameValuePair;
|
| Line 58... |
Line 61... |
| 58 |
private static long time = System.currentTimeMillis();
|
61 |
private static long time = System.currentTimeMillis();
|
| 59 |
private static String SNAPDEAL_INVENTORY_SHEET;
|
62 |
private static String SNAPDEAL_INVENTORY_SHEET;
|
| 60 |
private static Map<Long, SnapdealItemForInventory> allItemsInventoryMap = new HashMap<Long, SnapdealItemForInventory>();
|
63 |
private static Map<Long, SnapdealItemForInventory> allItemsInventoryMap = new HashMap<Long, SnapdealItemForInventory>();
|
| 61 |
private static ArrayList<Inventory> inventoryItemList;
|
64 |
private static ArrayList<Inventory> inventoryItemList;
|
| 62 |
static Map<Long,Long> itemIdpendingOrdersMap = new HashMap<Long,Long>();
|
65 |
static Map<Long,Long> itemIdpendingOrdersMap = new HashMap<Long,Long>();
|
| 63 |
static Map<String,Long> skuitemidMap = new HashMap<String,Long>();
|
- |
|
| 64 |
private static Map<String,InventoryHistory> inventoryhistoryItemMap;
|
66 |
private static Map<String,InventoryHistory> inventoryhistoryItemMap;
|
| 65 |
private static DefaultHttpClient client = new DefaultHttpClient();
|
67 |
private static DefaultHttpClient client = new DefaultHttpClient();
|
| - |
|
68 |
static Map<String,SnapdealItemDetails> snapdealItemMap = new HashMap<String,SnapdealItemDetails>();
|
| - |
|
69 |
static Map<Long,SnapdealItemDetails> itemSnapdealMap = new HashMap<Long,SnapdealItemDetails>();
|
| - |
|
70 |
static Map<String,PendingOrderInventoryHistory> PendingOrdersInventoryHistoryMap = new HashMap<String,PendingOrderInventoryHistory>();
|
| - |
|
71 |
static long lastUpdatedInventoryTime = 0;
|
| - |
|
72 |
static{
|
| - |
|
73 |
CatalogClient catalogServiceClient = null;
|
| - |
|
74 |
try {
|
| - |
|
75 |
catalogServiceClient = new CatalogClient();
|
| - |
|
76 |
} catch (TTransportException e1) {
|
| - |
|
77 |
// TODO Auto-generated catch block
|
| - |
|
78 |
e1.printStackTrace();
|
| - |
|
79 |
}
|
| - |
|
80 |
in.shop2020.model.v1.catalog.CatalogService.Client catalogClient = catalogServiceClient.getClient();
|
| - |
|
81 |
List<SnapdealItemDetails> allSnapdealItems = null;
|
| - |
|
82 |
try {
|
| - |
|
83 |
allSnapdealItems = catalogClient.getAllSnapdealItems();
|
| - |
|
84 |
} catch (TException e) {
|
| - |
|
85 |
// TODO Auto-generated catch block
|
| - |
|
86 |
e.printStackTrace();
|
| - |
|
87 |
}
|
| - |
|
88 |
for(SnapdealItemDetails snapdealItem:allSnapdealItems){
|
| - |
|
89 |
snapdealItemMap.put(snapdealItem.getSkuAtSnapdeal(),snapdealItem);
|
| - |
|
90 |
itemSnapdealMap.put(snapdealItem.getItem_id(), snapdealItem);
|
| - |
|
91 |
}
|
| - |
|
92 |
in.shop2020.model.v1.order.TransactionService.Client transactionClient = null;
|
| - |
|
93 |
try {
|
| - |
|
94 |
transactionClient = new TransactionClient().getClient();
|
| - |
|
95 |
lastUpdatedInventoryTime = transactionClient.getSourceDetail(7).getLastUpdatedOn();
|
| - |
|
96 |
} catch (Exception e) {
|
| - |
|
97 |
try {
|
| - |
|
98 |
transactionClient = new TransactionClient().getClient();
|
| - |
|
99 |
lastUpdatedInventoryTime = transactionClient.getSourceDetail(7).getLastUpdatedOn();
|
| - |
|
100 |
} catch (Exception ex) {
|
| - |
|
101 |
ex.printStackTrace();
|
| - |
|
102 |
}
|
| - |
|
103 |
}
|
| - |
|
104 |
|
| - |
|
105 |
}
|
| - |
|
106 |
|
| 66 |
private static void calculateinventory(){
|
107 |
private static void calculateinventory(){
|
| 67 |
CatalogClient catalogServiceClient = null;
|
108 |
CatalogClient catalogServiceClient = null;
|
| 68 |
Map<Long,ItemInventory> availability= new HashMap<Long,ItemInventory>();
|
109 |
Map<Long,ItemInventory> availability= new HashMap<Long,ItemInventory>();
|
| 69 |
try {
|
110 |
try {
|
| 70 |
catalogServiceClient = new CatalogClient();
|
111 |
catalogServiceClient = new CatalogClient();
|
| Line 78... |
Line 119... |
| 78 |
Map<Long,Item> aliveItemsMap = new HashMap<Long,Item>();
|
119 |
Map<Long,Item> aliveItemsMap = new HashMap<Long,Item>();
|
| 79 |
for(in.shop2020.model.v1.catalog.Item thriftItem:aliveItems){
|
120 |
for(in.shop2020.model.v1.catalog.Item thriftItem:aliveItems){
|
| 80 |
aliveItemsMap.put(thriftItem.getId(), thriftItem);
|
121 |
aliveItemsMap.put(thriftItem.getId(), thriftItem);
|
| 81 |
|
122 |
|
| 82 |
}
|
123 |
}
|
| 83 |
InventoryClient inventoryServiceClient = null;
|
124 |
InventoryClient inventoryServiceClient = new InventoryClient();
|
| 84 |
try {
|
125 |
try {
|
| 85 |
inventoryServiceClient = new InventoryClient();
|
126 |
inventoryServiceClient = new InventoryClient();
|
| 86 |
} catch (TTransportException e) {
|
127 |
} catch (TTransportException e) {
|
| 87 |
e.printStackTrace();
|
128 |
e.printStackTrace();
|
| 88 |
}
|
129 |
}
|
| Line 112... |
Line 153... |
| 112 |
double nlc=0;
|
153 |
double nlc=0;
|
| 113 |
double maxnlc=0;
|
154 |
double maxnlc=0;
|
| 114 |
Item thriftItem;
|
155 |
Item thriftItem;
|
| 115 |
long sku = 0;
|
156 |
long sku = 0;
|
| 116 |
for(Inventory inventoryItem:inventoryItemList){
|
157 |
for(Inventory inventoryItem:inventoryItemList){
|
| 117 |
try{
|
158 |
System.out.println(inventoryItem.getSellerSku());
|
| - |
|
159 |
if(snapdealItemMap.containsKey(inventoryItem.getSellerSku())){
|
| 118 |
sku = Long.parseLong(inventoryItem.getSellerSku());
|
160 |
sku = snapdealItemMap.get(inventoryItem.getSellerSku()).getItem_id();
|
| 119 |
}
|
161 |
}
|
| 120 |
catch(NumberFormatException nfe){
|
- |
|
| 121 |
System.out.println(inventoryItem.getSellerSku());
|
- |
|
| 122 |
if(skuitemidMap.get(inventoryItem.getSellerSku())!=null){
|
- |
|
| 123 |
sku = skuitemidMap.get(inventoryItem.getSellerSku());
|
- |
|
| 124 |
}
|
- |
|
| 125 |
else{
|
162 |
else{
|
| 126 |
continue;
|
163 |
continue;
|
| 127 |
}
|
- |
|
| 128 |
}
|
164 |
}
|
| 129 |
if(aliveItemsMap.get(sku) != null){
|
165 |
if(aliveItemsMap.get(sku) != null){
|
| 130 |
thriftItem = aliveItemsMap.get(sku);
|
166 |
thriftItem = aliveItemsMap.get(sku);
|
| 131 |
}
|
167 |
}
|
| 132 |
else{
|
168 |
else{
|
| Line 321... |
Line 357... |
| 321 |
e.printStackTrace();
|
357 |
e.printStackTrace();
|
| 322 |
}
|
358 |
}
|
| 323 |
int i = 1;
|
359 |
int i = 1;
|
| 324 |
Gson gson = new Gson();
|
360 |
Gson gson = new Gson();
|
| 325 |
inventoryhistoryItemMap = new HashMap<String,InventoryHistory>();
|
361 |
inventoryhistoryItemMap = new HashMap<String,InventoryHistory>();
|
| 326 |
Client inventoryClient = null;
|
- |
|
| 327 |
boolean exitfetchinghistory = true;
|
362 |
boolean exitfetchinghistory = true;
|
| 328 |
long lastUpdatedInventoryTime = 0;
|
- |
|
| 329 |
try {
|
- |
|
| 330 |
inventoryClient = new InventoryClient().getClient();
|
- |
|
| 331 |
lastUpdatedInventoryTime = inventoryClient.getLastUpdatedTimeForSnapdealInventory();
|
- |
|
| 332 |
} catch (TTransportException e) {
|
- |
|
| 333 |
// TODO Auto-generated catch block
|
- |
|
| 334 |
e.printStackTrace();
|
- |
|
| 335 |
}
|
- |
|
| 336 |
|
- |
|
| 337 |
while(exitfetchinghistory){
|
363 |
while(exitfetchinghistory){
|
| 338 |
System.out.println("Fetching inventory history page " +i);
|
364 |
System.out.println("Fetching inventory history page " +i);
|
| 339 |
get = new HttpGet("http://seller.snapdeal.com/inventory/search?gridType=history&_search=false&nd="+time+"&rows=30&page="+i+"&sidx=&sord=dsc");
|
365 |
get = new HttpGet("http://seller.snapdeal.com/inventory/search?gridType=history&_search=false&nd="+time+"&rows=30&page="+i+"&sidx=&sord=dsc");
|
| 340 |
try {
|
366 |
try {
|
| 341 |
response = client.execute(get);
|
367 |
response = client.execute(get);
|
| Line 377... |
Line 403... |
| 377 |
else{
|
403 |
else{
|
| 378 |
exitfetchinghistory = false;
|
404 |
exitfetchinghistory = false;
|
| 379 |
}
|
405 |
}
|
| 380 |
i++;
|
406 |
i++;
|
| 381 |
}
|
407 |
}
|
| - |
|
408 |
InventoryClient inventoryServiceClient = new InventoryClient();
|
| - |
|
409 |
in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
|
| - |
|
410 |
List<SnapdealInventoryItem> snapdealInventoryItemHistoryList = inventoryClient.getSnapdealInventorySnapshot();
|
| - |
|
411 |
if(snapdealInventoryItemHistoryList.size()>0){
|
| - |
|
412 |
for(SnapdealInventoryItem snapdealInventoryItem:snapdealInventoryItemHistoryList){
|
| - |
|
413 |
if(itemSnapdealMap.containsKey(snapdealInventoryItem.getItem_id())){
|
| - |
|
414 |
PendingOrderInventoryHistory pendingOrdersInventoryHistory = new PendingOrderInventoryHistory();
|
| - |
|
415 |
pendingOrdersInventoryHistory.setPendingOrders(snapdealInventoryItem.getPendingOrders());
|
| - |
|
416 |
pendingOrdersInventoryHistory.setInventoryHistory(snapdealInventoryItem.getAvailability());
|
| - |
|
417 |
pendingOrdersInventoryHistory.setLastUpdatedTimestamp(snapdealInventoryItem.getLastUpdatedOnSnapdeal());
|
| - |
|
418 |
PendingOrdersInventoryHistoryMap.put(itemSnapdealMap.get(snapdealInventoryItem.getItem_id()).getSkuAtSnapdeal(), pendingOrdersInventoryHistory);
|
| - |
|
419 |
}
|
| - |
|
420 |
}
|
| - |
|
421 |
}
|
| - |
|
422 |
PendingOrderInventoryHistory pendingOrdersInventoryHistory;
|
| - |
|
423 |
for(Entry<String, InventoryHistory> inventoryHistoryItem :inventoryhistoryItemMap.entrySet()){
|
| - |
|
424 |
if(PendingOrdersInventoryHistoryMap.containsKey(inventoryHistoryItem.getValue().getSellerSku())){
|
| - |
|
425 |
pendingOrdersInventoryHistory = PendingOrdersInventoryHistoryMap.get(inventoryHistoryItem.getValue().getSellerSku());
|
| - |
|
426 |
pendingOrdersInventoryHistory.setInventoryHistory(Long.parseLong(inventoryHistoryItem.getValue().getNewValue()));
|
| - |
|
427 |
pendingOrdersInventoryHistory.setLastUpdatedTimestamp(inventoryHistoryItem.getValue().getUpdateTime());
|
| - |
|
428 |
PendingOrdersInventoryHistoryMap.put(inventoryHistoryItem.getValue().getSellerSku(),pendingOrdersInventoryHistory);
|
| - |
|
429 |
}
|
| - |
|
430 |
else{
|
| - |
|
431 |
pendingOrdersInventoryHistory = new PendingOrderInventoryHistory();
|
| - |
|
432 |
pendingOrdersInventoryHistory.setInventoryHistory(Long.parseLong(inventoryHistoryItem.getValue().getNewValue()));
|
| - |
|
433 |
pendingOrdersInventoryHistory.setLastUpdatedTimestamp(inventoryHistoryItem.getValue().getUpdateTime());
|
| - |
|
434 |
pendingOrdersInventoryHistory.setPendingOrders(0);
|
| - |
|
435 |
PendingOrdersInventoryHistoryMap.put(inventoryHistoryItem.getValue().getSellerSku(),pendingOrdersInventoryHistory);
|
| - |
|
436 |
}
|
| - |
|
437 |
}
|
| 382 |
}
|
438 |
}
|
| 383 |
|
439 |
|
| 384 |
private static void fetchinventoryfromsnapdeal() throws UnsupportedEncodingException{
|
440 |
private static void fetchcurrentinventoryfromsnapdeal() throws UnsupportedEncodingException, TException{
|
| 385 |
/*client = new DefaultHttpClient();
|
441 |
/*client = new DefaultHttpClient();
|
| 386 |
HttpPost post = new HttpPost("http://seller.snapdeal.com/login_security_check?spring-security-redirect=http://seller.snapdeal.com/inventory&");
|
442 |
HttpPost post = new HttpPost("http://seller.snapdeal.com/login_security_check?spring-security-redirect=http://seller.snapdeal.com/inventory&");
|
| 387 |
BufferedReader rd= null;
|
443 |
BufferedReader rd= null;
|
| 388 |
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
|
444 |
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
|
| 389 |
nameValuePairs.add(new BasicNameValuePair("j_username",
|
445 |
nameValuePairs.add(new BasicNameValuePair("j_username",
|
| Line 460... |
Line 516... |
| 460 |
break;
|
516 |
break;
|
| 461 |
}
|
517 |
}
|
| 462 |
i++;
|
518 |
i++;
|
| 463 |
}
|
519 |
}
|
| 464 |
in.shop2020.model.v1.catalog.CatalogService.Client catalogServiceClient = null;
|
520 |
in.shop2020.model.v1.catalog.CatalogService.Client catalogServiceClient = null;
|
| 465 |
SnapdealItem snapdealitem = null;
|
521 |
SnapdealItemDetails snapdealitem = null;
|
| 466 |
long sku = 0;
|
522 |
long sku = 0;
|
| 467 |
long created_orders;
|
523 |
long created_orders;
|
| 468 |
long pending_orders;
|
524 |
long pending_orders;
|
| 469 |
try {
|
525 |
try {
|
| 470 |
transactionClient = new TransactionClient("support_transaction_service_server_host","transaction_service_server_port").getClient();
|
526 |
transactionClient = new TransactionClient("support_transaction_service_server_host","transaction_service_server_port").getClient();
|
| Line 480... |
Line 536... |
| 480 |
}
|
536 |
}
|
| 481 |
List<String> notMappedItems = new ArrayList<String>();
|
537 |
List<String> notMappedItems = new ArrayList<String>();
|
| 482 |
for(Inventory inventory:inventoryItemList){
|
538 |
for(Inventory inventory:inventoryItemList){
|
| 483 |
created_orders = 0;
|
539 |
created_orders = 0;
|
| 484 |
pending_orders = 0;
|
540 |
pending_orders = 0;
|
| - |
|
541 |
try {
|
| 485 |
if(inventoryhistoryItemMap.get(inventory.getSellerSku())!=null && inventory.getAvailableInventory()!=Long.parseLong(inventoryhistoryItemMap.get(inventory.getSellerSku()).getNewValue())){
|
542 |
snapdealitem = snapdealItemMap.get(inventory.getSellerSku());
|
| - |
|
543 |
if(snapdealitem==null){
|
| - |
|
544 |
continue;
|
| - |
|
545 |
}
|
| - |
|
546 |
if(snapdealitem.getItem_id()!=0){
|
| - |
|
547 |
sku = snapdealitem.getItem_id();
|
| - |
|
548 |
}
|
| 486 |
try {
|
549 |
else{
|
| - |
|
550 |
notMappedItems.add("inventory.getSellerSku() "+inventory.getProductName());
|
| - |
|
551 |
System.out.println();
|
| - |
|
552 |
}
|
| - |
|
553 |
if(sku!=0){
|
| - |
|
554 |
System.out.println("Fetching created orders for " + sku);
|
| 487 |
try{
|
555 |
try{
|
| 488 |
sku = Long.parseLong(inventory.getSellerSku());
|
- |
|
| 489 |
}
|
- |
|
| 490 |
catch(NumberFormatException nfe){
|
- |
|
| 491 |
try {
|
- |
|
| 492 |
snapdealitem = catalogServiceClient.getSnapdealItembySkuAtSnapdeal(inventory.getSellerSku());
|
- |
|
| 493 |
if(snapdealitem.getItem_id()!=0){
|
556 |
if(lastUpdatedInventoryTime > 0){
|
| 494 |
sku = snapdealitem.getItem_id();
|
- |
|
| 495 |
skuitemidMap.put(inventory.getSellerSku(),sku);
|
- |
|
| 496 |
}
|
- |
|
| 497 |
else{
|
- |
|
| 498 |
notMappedItems.add("inventory.getSellerSku() "+inventory.getProductName());
|
557 |
created_orders = transactionClient.getOrdersCreatedAfterTimestampForSource(lastUpdatedInventoryTime, 7, sku);
|
| 499 |
System.out.println();
|
- |
|
| 500 |
}
|
- |
|
| 501 |
} catch (TTransportException e) {
|
- |
|
| 502 |
// TODO Auto-generated catch block
|
- |
|
| 503 |
e.printStackTrace();
|
- |
|
| 504 |
}
|
558 |
}
|
| 505 |
}
|
559 |
}
|
| 506 |
if(sku!=0){
|
- |
|
| 507 |
System.out.println("Fetching created orders for " + sku);
|
- |
|
| 508 |
try{
|
- |
|
| 509 |
created_orders = transactionClient.getOrdersCreatedAfterTimestampForSource(inventoryhistoryItemMap.get(inventory.getSellerSku()).getUpdateTime(), 7, sku);
|
- |
|
| 510 |
}
|
- |
|
| 511 |
catch(TTransportException e){
|
560 |
catch(TTransportException e){
|
| 512 |
transactionClient = new TransactionClient("support_transaction_service_server_host","transaction_service_server_port").getClient();
|
561 |
transactionClient = new TransactionClient("support_transaction_service_server_host","transaction_service_server_port").getClient();
|
| 513 |
created_orders = transactionClient.getOrdersCreatedAfterTimestampForSource(inventoryhistoryItemMap.get(inventory.getSellerSku()).getUpdateTime(), 7, sku);
|
562 |
created_orders = transactionClient.getOrdersCreatedAfterTimestampForSource(lastUpdatedInventoryTime, 7, sku);
|
| 514 |
}
|
- |
|
| 515 |
}
|
- |
|
| 516 |
else{
|
- |
|
| 517 |
continue;
|
- |
|
| 518 |
}
|
563 |
}
|
| 519 |
} catch (NumberFormatException e) {
|
- |
|
| 520 |
// TODO Auto-generated catch block
|
- |
|
| 521 |
e.printStackTrace();
|
- |
|
| 522 |
} catch (TException e) {
|
- |
|
| 523 |
// TODO Auto-generated catch block
|
- |
|
| 524 |
e.printStackTrace();
|
- |
|
| 525 |
}
|
564 |
}
|
| - |
|
565 |
else{
|
| - |
|
566 |
continue;
|
| - |
|
567 |
}
|
| - |
|
568 |
} catch (NumberFormatException e) {
|
| - |
|
569 |
// TODO Auto-generated catch block
|
| - |
|
570 |
e.printStackTrace();
|
| - |
|
571 |
} catch (TException e) {
|
| 526 |
pending_orders = (inventory.getAvailableInventory() - Long.parseLong(inventoryhistoryItemMap.get(inventory.getSellerSku()).getNewValue()) - created_orders);
|
572 |
// TODO Auto-generated catch block
|
| - |
|
573 |
e.printStackTrace();
|
| 527 |
}
|
574 |
}
|
| - |
|
575 |
pending_orders = PendingOrdersInventoryHistoryMap.get(inventory.getSellerSku()).getPendingOrders()+(inventory.getAvailableInventory() - PendingOrdersInventoryHistoryMap.get(inventory.getSellerSku()).getInventoryHistory() - created_orders);
|
| 528 |
itemIdpendingOrdersMap.put(sku, pending_orders);
|
576 |
itemIdpendingOrdersMap.put(sku, pending_orders);
|
| - |
|
577 |
PendingOrdersInventoryHistoryMap.get(inventory.getSellerSku()).setPendingOrders(pending_orders);
|
| - |
|
578 |
}
|
| - |
|
579 |
List<SnapdealInventoryItem> snapdealInventoryItemList = new ArrayList<SnapdealInventoryItem>();
|
| - |
|
580 |
SnapdealInventoryItem snapdealInventoryItem;
|
| - |
|
581 |
for(Entry<String, PendingOrderInventoryHistory> pendingOrderInventoryHistory:PendingOrdersInventoryHistoryMap.entrySet()){
|
| - |
|
582 |
snapdealInventoryItem = new SnapdealInventoryItem();
|
| - |
|
583 |
if(snapdealItemMap.containsKey(pendingOrderInventoryHistory.getKey())){
|
| - |
|
584 |
snapdealInventoryItem.setItem_id(snapdealItemMap.get(pendingOrderInventoryHistory.getKey()).getItem_id());
|
| - |
|
585 |
snapdealInventoryItem.setPendingOrders(pendingOrderInventoryHistory.getValue().getPendingOrders());
|
| - |
|
586 |
snapdealInventoryItem.setAvailability(pendingOrderInventoryHistory.getValue().getInventoryHistory());
|
| - |
|
587 |
snapdealInventoryItem.setLastUpdatedOnSnapdeal(pendingOrderInventoryHistory.getValue().getLastUpdatedTimestamp());
|
| - |
|
588 |
snapdealInventoryItemList.add(snapdealInventoryItem);
|
| - |
|
589 |
}
|
| 529 |
}
|
590 |
}
|
| - |
|
591 |
InventoryClient inventoryServiceClient = new InventoryClient();
|
| - |
|
592 |
in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
|
| - |
|
593 |
try {
|
| - |
|
594 |
inventoryClient.addOrUpdateAllSnapdealInventory(snapdealInventoryItemList);
|
| - |
|
595 |
} catch (TException e) {
|
| - |
|
596 |
// TODO Auto-generated catch block
|
| - |
|
597 |
e.printStackTrace();
|
| - |
|
598 |
inventoryClient = inventoryServiceClient.getClient();
|
| - |
|
599 |
inventoryClient.addOrUpdateAllSnapdealInventory(snapdealInventoryItemList);
|
| - |
|
600 |
}
|
| - |
|
601 |
|
| 530 |
}
|
602 |
}
|
| 531 |
|
603 |
|
| 532 |
@SuppressWarnings("deprecation")
|
604 |
@SuppressWarnings("deprecation")
|
| 533 |
public static void main(String[] args) throws NumberFormatException, TException, ClientProtocolException, IOException {
|
605 |
public static void main(String[] args) throws NumberFormatException, TException, ClientProtocolException, IOException {
|
| 534 |
fetchinventoryhistoryfromsnapdeal();
|
606 |
fetchinventoryhistoryfromsnapdeal();
|
| 535 |
fetchinventoryfromsnapdeal();
|
607 |
fetchcurrentinventoryfromsnapdeal();
|
| 536 |
calculateinventory();
|
608 |
calculateinventory();
|
| 537 |
in.shop2020.model.v1.catalog.CatalogService.Client catalogServiceClient = null;
|
609 |
in.shop2020.model.v1.catalog.CatalogService.Client catalogServiceClient = null;
|
| 538 |
SnapdealItem snapdealitem = null;
|
610 |
SnapdealItem snapdealitem = null;
|
| 539 |
try {
|
611 |
try {
|
| 540 |
catalogServiceClient = new CatalogClient().getClient();
|
612 |
catalogServiceClient = new CatalogClient().getClient();
|
| Line 554... |
Line 626... |
| 554 |
StringBuffer backInStockItems =new StringBuffer();
|
626 |
StringBuffer backInStockItems =new StringBuffer();
|
| 555 |
long sku = 0;
|
627 |
long sku = 0;
|
| 556 |
for(Inventory inventory:inventoryItemList){
|
628 |
for(Inventory inventory:inventoryItemList){
|
| 557 |
//System.out.println(inventory.getSupc()+" "+inventory.getSellerSku()+ " " +inventory.getProductName()+" "+inventory.getAvailableInventory()+" "+inventory.isLive()+" "+itemIdpendingOrdersMap.get(Long.parseLong(inventory.getSellerSku())));
|
629 |
//System.out.println(inventory.getSupc()+" "+inventory.getSellerSku()+ " " +inventory.getProductName()+" "+inventory.getAvailableInventory()+" "+inventory.isLive()+" "+itemIdpendingOrdersMap.get(Long.parseLong(inventory.getSellerSku())));
|
| 558 |
try{
|
630 |
try{
|
| 559 |
try{
|
631 |
if(snapdealItemMap.containsKey(inventory.getSellerSku())){
|
| 560 |
sku = Long.parseLong(inventory.getSellerSku());
|
632 |
sku = snapdealItemMap.get(inventory.getSellerSku()).getItem_id();
|
| 561 |
}
|
633 |
}
|
| 562 |
catch(NumberFormatException nfe){
|
- |
|
| 563 |
if(skuitemidMap.containsKey(inventory.getSellerSku())){
|
- |
|
| 564 |
sku = skuitemidMap.get(inventory.getSellerSku());
|
- |
|
| 565 |
}
|
- |
|
| 566 |
else{
|
634 |
else{
|
| 567 |
continue;
|
635 |
continue;
|
| 568 |
}
|
- |
|
| 569 |
}
|
636 |
}
|
| 570 |
snapdealitem = catalogServiceClient.getSnapdealItem(sku);
|
637 |
snapdealitem = catalogServiceClient.getSnapdealItem(sku);
|
| 571 |
}
|
638 |
}
|
| 572 |
catch(TTransportException e){
|
639 |
catch(TTransportException e){
|
| 573 |
catalogServiceClient = new CatalogClient().getClient();
|
640 |
catalogServiceClient = new CatalogClient().getClient();
|
| 574 |
snapdealitem = catalogServiceClient.getSnapdealItem(sku);
|
641 |
snapdealitem = catalogServiceClient.getSnapdealItem(sku);
|
| 575 |
}
|
642 |
}
|
| 576 |
if(snapdealitem.getItem_id()!=0 && snapdealitem.isIsListedOnSnapdeal() && !snapdealitem.isSuppressInventoryFeed()){
|
643 |
if(snapdealitem.getItem_id()!=0 && snapdealitem.isIsListedOnSnapdeal() && !snapdealitem.isSuppressInventoryFeed()){
|
| 577 |
inventoryItem = allItemsInventoryMap.get(Long.parseLong(inventory.getSellerSku()));
|
644 |
inventoryItem = allItemsInventoryMap.get(sku);
|
| 578 |
if(inventoryItem==null){
|
645 |
if(inventoryItem==null){
|
| 579 |
continue;
|
646 |
continue;
|
| 580 |
}
|
647 |
}
|
| 581 |
availability = inventoryItem.getAvailability();
|
648 |
availability = inventoryItem.getAvailability();
|
| 582 |
reserve = inventoryItem.getReserve();
|
649 |
reserve = inventoryItem.getReserve();
|
| 583 |
defaultinventory = inventoryItem.getDefaultInventory();
|
650 |
defaultinventory = inventoryItem.getDefaultInventory();
|
| 584 |
holdinventory = inventoryItem.getHoldInventory();
|
651 |
holdinventory = inventoryItem.getHoldInventory();
|
| 585 |
actualavailability = availability - reserve;
|
652 |
actualavailability = availability - reserve;
|
| 586 |
if(itemIdpendingOrdersMap.get(Long.parseLong(inventory.getSellerSku()))!=null){
|
653 |
if(itemIdpendingOrdersMap.containsKey(sku)){
|
| 587 |
heldorders = itemIdpendingOrdersMap.get(Long.parseLong(inventory.getSellerSku()));
|
654 |
heldorders = itemIdpendingOrdersMap.get(sku);
|
| 588 |
if(heldorders < 0){
|
655 |
if(heldorders < 0){
|
| 589 |
heldorders = 0;
|
656 |
heldorders = 0;
|
| 590 |
}
|
657 |
}
|
| 591 |
}
|
658 |
}
|
| 592 |
System.out.println("itemId:" + inventoryItem.getId() + "\tavailable: " + inventoryItem.getAvailability() + "\treserve" + inventoryItem.getReserve() + "\theldForSource:" + inventoryItem.getHeldForSource() + "\twebsite_hold:" + inventoryItem.getHoldInventory() + "\tdefault_inv:" +inventoryItem.getDefaultInventory() + "\theldorders" + heldorders);
|
659 |
System.out.println("itemId:" + inventoryItem.getId() + "\tavailable: " + inventoryItem.getAvailability() + "\treserve" + inventoryItem.getReserve() + "\theldForSource:" + inventoryItem.getHeldForSource() + "\twebsite_hold:" + inventoryItem.getHoldInventory() + "\tdefault_inv:" +inventoryItem.getDefaultInventory() + "\theldorders" + heldorders);
|
| Line 640... |
Line 707... |
| 640 |
row.getCell((short) 5).setCellValue("Yes");
|
707 |
row.getCell((short) 5).setCellValue("Yes");
|
| 641 |
}
|
708 |
}
|
| 642 |
else{
|
709 |
else{
|
| 643 |
row.getCell((short) 5).setCellValue("No");
|
710 |
row.getCell((short) 5).setCellValue("No");
|
| 644 |
}
|
711 |
}
|
| 645 |
SnapdealInventoryItem snapdealinventoryitem = new SnapdealInventoryItem();
|
- |
|
| 646 |
snapdealinventoryitem.setAvailability(sent_inventory);
|
- |
|
| 647 |
snapdealinventoryitem.setItem_id(Long.parseLong(inventory.getSellerSku()));
|
- |
|
| 648 |
System.out.println("Updating inventory snapshot " + inventory.getSellerSku());
|
- |
|
| 649 |
snapdealinventoryitem.setLastUpdatedOnSnapdeal(time);
|
- |
|
| 650 |
try{
|
- |
|
| 651 |
inventoryClient.addOrUpdateSnapdealInventoryForItem(snapdealinventoryitem);
|
- |
|
| 652 |
}
|
- |
|
| 653 |
catch(TTransportException e){
|
- |
|
| 654 |
inventoryClient = new InventoryClient().getClient();
|
- |
|
| 655 |
inventoryClient.addOrUpdateSnapdealInventoryForItem(snapdealinventoryitem);
|
- |
|
| 656 |
}
|
- |
|
| 657 |
iterator++;
|
712 |
iterator++;
|
| 658 |
}
|
713 |
}
|
| 659 |
}
|
714 |
}
|
| 660 |
else{
|
715 |
else{
|
| 661 |
continue;
|
716 |
continue;
|
| Line 726... |
Line 781... |
| 726 |
} catch (IOException e) {
|
781 |
} catch (IOException e) {
|
| 727 |
// TODO Auto-generated catch block
|
782 |
// TODO Auto-generated catch block
|
| 728 |
e.printStackTrace();
|
783 |
e.printStackTrace();
|
| 729 |
}
|
784 |
}
|
| 730 |
*/
|
785 |
*/
|
| - |
|
786 |
in.shop2020.model.v1.order.TransactionService.Client transactionClient = null;
|
| - |
|
787 |
long lastSentInventoryTime = System.currentTimeMillis();
|
| - |
|
788 |
try {
|
| - |
|
789 |
transactionClient = new TransactionClient().getClient();
|
| - |
|
790 |
transactionClient.updateSourceDetailTimestamp(7, lastSentInventoryTime);
|
| - |
|
791 |
} catch (Exception e) {
|
| - |
|
792 |
try {
|
| - |
|
793 |
transactionClient = new TransactionClient().getClient();
|
| - |
|
794 |
transactionClient.updateSourceDetailTimestamp(7, lastSentInventoryTime);
|
| - |
|
795 |
} catch (Exception ex) {
|
| - |
|
796 |
ex.printStackTrace();
|
| - |
|
797 |
}
|
| - |
|
798 |
}
|
| 731 |
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd-HH:mm:ss");
|
799 |
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd-HH:mm:ss");
|
| 732 |
Calendar cal=GregorianCalendar.getInstance();
|
- |
|
| 733 |
String emailFromAddress = "build@shop2020.in";
|
800 |
String emailFromAddress = "build@shop2020.in";
|
| 734 |
String password = "cafe@nes";
|
801 |
String password = "cafe@nes";
|
| 735 |
GmailUtils mailer = new GmailUtils();
|
802 |
GmailUtils mailer = new GmailUtils();
|
| - |
|
803 |
String sendTo[] = new String[]{"vikram.raghav@shop2020.in"};
|
| 736 |
String sendTo[] = new String[]{"vikram.raghav@shop2020.in","kshitij.sood@shop2020.in"};
|
804 |
//String sendTo[] = new String[]{"vikram.raghav@shop2020.in","kshitij.sood@shop2020.in"};
|
| 737 |
/*String sendTo[] = new String[]{ "sandeep.sachdeva@shop2020.in", "vikram.raghav@shop2020.in", "rajneesh.arora@shop2020.in",
|
805 |
/*String sendTo[] = new String[]{ "sandeep.sachdeva@shop2020.in", "vikram.raghav@shop2020.in", "rajneesh.arora@shop2020.in",
|
| 738 |
"khushal.bhatia@shop2020.in","manoj.kumar@saholic.com","chaitnaya.vats@saholic.com",
|
806 |
"khushal.bhatia@shop2020.in","manoj.kumar@saholic.com","chaitnaya.vats@saholic.com",
|
| 739 |
"yukti.jain@shop2020.in","manisha.sharma@shop2020.in","chandan.kumar@shop2020.in","ankush.dhingra@shop2020.in","amar.kumar@shop2020.in"};
|
807 |
"yukti.jain@shop2020.in","manisha.sharma@shop2020.in","chandan.kumar@shop2020.in","ankush.dhingra@shop2020.in","amar.kumar@shop2020.in"};
|
| 740 |
*/
|
808 |
*/
|
| 741 |
String emailSubjectTxt = "Products back in stock on Snapdeal "+sdf.format(cal.getTime());
|
809 |
String emailSubjectTxt = "Products back in stock on Snapdeal "+sdf.format(lastSentInventoryTime);
|
| 742 |
String text = backInStockItems.toString();
|
810 |
String text = backInStockItems.toString();
|
| 743 |
if(text.length() > 0){
|
811 |
if(text.length() > 0){
|
| 744 |
try {
|
812 |
try {
|
| 745 |
mailer.sendSSLMessage(sendTo, emailSubjectTxt, text, emailFromAddress, password, new ArrayList<File>());
|
813 |
mailer.sendSSLMessage(sendTo, emailSubjectTxt, text, emailFromAddress, password, new ArrayList<File>());
|
| 746 |
} catch (MessagingException e) {
|
814 |
} catch (MessagingException e) {
|
| Line 761... |
Line 829... |
| 761 |
try {
|
829 |
try {
|
| 762 |
mailer.sendSSLMessage(sendTo,"Inventory File","Please see attached inventory file", emailFromAddress, password, files);
|
830 |
mailer.sendSSLMessage(sendTo,"Inventory File","Please see attached inventory file", emailFromAddress, password, files);
|
| 763 |
} catch (MessagingException e) {
|
831 |
} catch (MessagingException e) {
|
| 764 |
e.printStackTrace();
|
832 |
e.printStackTrace();
|
| 765 |
}
|
833 |
}
|
| 766 |
|
834 |
|
| 767 |
|
835 |
|
| 768 |
}
|
836 |
}
|
| 769 |
|
837 |
|
| 770 |
}
|
838 |
}
|