| 9651 |
manish.sha |
1 |
package in.shop2020.serving.services;
|
|
|
2 |
|
| 9698 |
manish.sha |
3 |
import in.shop2020.model.v1.order.OrderSource;
|
| 9651 |
manish.sha |
4 |
import in.shop2020.serving.model.Order;
|
|
|
5 |
import in.shop2020.serving.model.OrderItems;
|
|
|
6 |
import in.shop2020.thrift.clients.TransactionClient;
|
|
|
7 |
|
|
|
8 |
import java.io.BufferedReader;
|
|
|
9 |
import java.io.InputStreamReader;
|
|
|
10 |
import java.text.SimpleDateFormat;
|
|
|
11 |
import java.util.ArrayList;
|
| 9698 |
manish.sha |
12 |
import java.util.Date;
|
| 9651 |
manish.sha |
13 |
import java.util.List;
|
|
|
14 |
|
|
|
15 |
import org.apache.http.HttpResponse;
|
|
|
16 |
import org.apache.http.NameValuePair;
|
|
|
17 |
import org.apache.http.client.HttpClient;
|
|
|
18 |
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
|
|
19 |
import org.apache.http.client.methods.HttpGet;
|
|
|
20 |
import org.apache.http.client.methods.HttpPost;
|
|
|
21 |
import org.apache.http.impl.client.DefaultHttpClient;
|
|
|
22 |
import org.apache.http.message.BasicNameValuePair;
|
|
|
23 |
|
|
|
24 |
import com.google.gson.Gson;
|
|
|
25 |
|
|
|
26 |
public class FlipkartOrderStatusReconciliation{
|
|
|
27 |
public static void main(String[] args) {
|
|
|
28 |
HttpClient client = new DefaultHttpClient();
|
|
|
29 |
HttpPost post = new HttpPost("https://seller.flipkart.com/login");
|
|
|
30 |
BufferedReader rd= null;
|
|
|
31 |
|
|
|
32 |
List<List<String>> deliveredOrderDataList = new ArrayList<List<String>>();
|
|
|
33 |
SimpleDateFormat gotFlipkartDateFormat = new SimpleDateFormat("MMM dd, yyyy");
|
| 9698 |
manish.sha |
34 |
SimpleDateFormat createDateFormatter = new SimpleDateFormat("MMM dd, yyyy hh:mm aaa");
|
| 9651 |
manish.sha |
35 |
SimpleDateFormat ourDBDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
| 9698 |
manish.sha |
36 |
long minCreationDate = 0l;
|
| 9651 |
manish.sha |
37 |
try {
|
| 9698 |
manish.sha |
38 |
minCreationDate = new TransactionClient().getClient().getMinCreatedTimeStampUndeliveredOrdersForSource(OrderSource.FLIPKART.getValue());
|
| 9651 |
manish.sha |
39 |
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
|
|
|
40 |
nameValuePairs.add(new BasicNameValuePair("authName",
|
|
|
41 |
"flipkart"));
|
|
|
42 |
nameValuePairs.add(new BasicNameValuePair("username",
|
|
|
43 |
"flipkart-support@saholic.com"));
|
|
|
44 |
nameValuePairs.add(new BasicNameValuePair("password",
|
|
|
45 |
"076c27ee24d7596b06608a8ed2559f87"));
|
|
|
46 |
post.setEntity(new UrlEncodedFormEntity(nameValuePairs,"utf-8"));
|
|
|
47 |
HttpResponse response = client.execute(post);
|
|
|
48 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
|
|
49 |
String line = "";
|
|
|
50 |
Gson gson;
|
|
|
51 |
List<Order> orders = new ArrayList<Order>();
|
|
|
52 |
OrderItems new_orders;
|
|
|
53 |
HttpGet get_new;
|
|
|
54 |
|
|
|
55 |
long time;
|
|
|
56 |
int i=1;
|
|
|
57 |
while ((line = rd.readLine()) != null) {
|
|
|
58 |
System.out.println(line);
|
|
|
59 |
}
|
|
|
60 |
time = System.currentTimeMillis();
|
|
|
61 |
|
|
|
62 |
while(true){
|
|
|
63 |
get_new = new HttpGet("https://seller.flipkart.com/dashboard/som/shipped_order_items?status=delivered&page="+i+"&page_size=100&_="+time);
|
|
|
64 |
response = client.execute(get_new);
|
|
|
65 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
|
|
66 |
line = "";
|
|
|
67 |
gson = new Gson();
|
|
|
68 |
//System.out.println("RD....."+rd.readLine());
|
|
|
69 |
new_orders = (OrderItems) gson.fromJson(rd, OrderItems.class);
|
|
|
70 |
if(new_orders.getOrder_items().size()>0){
|
|
|
71 |
orders.addAll(new_orders.getOrder_items());
|
|
|
72 |
}
|
|
|
73 |
else{
|
|
|
74 |
break;
|
|
|
75 |
}
|
|
|
76 |
i++;
|
|
|
77 |
}
|
|
|
78 |
|
|
|
79 |
for(Order order:orders){
|
| 9698 |
manish.sha |
80 |
if(minCreationDate > 0l && gotFlipkartDateFormat.parse(gotFlipkartDateFormat.format(minCreationDate)).getTime() <= gotFlipkartDateFormat.parse(order.getCreatedDate()).getTime()){
|
|
|
81 |
List<String> delivered_dataList = new ArrayList<String>();
|
|
|
82 |
delivered_dataList.add(order.getExternalId());
|
|
|
83 |
delivered_dataList.add(order.getOrderItemId());
|
|
|
84 |
delivered_dataList.add(ourDBDateFormat.format(gotFlipkartDateFormat.parse(order.getModifiedDate()).getTime()));
|
|
|
85 |
System.out.println("Flipkart Order Id... "+order.getExternalId() + " ... Flipkart Sub Order Code... "+ order.getOrderItemId() +" ... Delivery Date ... "+ ourDBDateFormat.format(gotFlipkartDateFormat.parse(order.getModifiedDate()).getTime()) + "....Created Date..... "+ order.getCreatedDate());
|
|
|
86 |
deliveredOrderDataList.add(delivered_dataList);
|
|
|
87 |
}
|
| 9651 |
manish.sha |
88 |
}
|
|
|
89 |
//System.out.println("deliveredOrderDataList size... "+deliveredOrderDataList.size());
|
|
|
90 |
if(deliveredOrderDataList!=null && deliveredOrderDataList.size()>0){
|
|
|
91 |
new TransactionClient().getClient().updateFlipkartOrdersStatus(deliveredOrderDataList);
|
|
|
92 |
}
|
|
|
93 |
|
|
|
94 |
} catch(Exception e){
|
|
|
95 |
e.printStackTrace();
|
|
|
96 |
}
|
|
|
97 |
}
|
|
|
98 |
}
|