| Line 2... |
Line 2... |
| 2 |
|
2 |
|
| 3 |
import in.shop2020.model.v1.order.OrderSource;
|
3 |
import in.shop2020.model.v1.order.OrderSource;
|
| 4 |
import in.shop2020.serving.model.Order;
|
4 |
import in.shop2020.serving.model.Order;
|
| 5 |
import in.shop2020.serving.model.OrderItems;
|
5 |
import in.shop2020.serving.model.OrderItems;
|
| 6 |
import in.shop2020.thrift.clients.TransactionClient;
|
6 |
import in.shop2020.thrift.clients.TransactionClient;
|
| - |
|
7 |
import in.shop2020.utils.GmailUtils;
|
| 7 |
|
8 |
|
| 8 |
import java.io.BufferedReader;
|
9 |
import java.io.BufferedReader;
|
| 9 |
import java.io.InputStreamReader;
|
10 |
import java.io.InputStreamReader;
|
| 10 |
import java.text.SimpleDateFormat;
|
11 |
import java.text.SimpleDateFormat;
|
| 11 |
import java.util.ArrayList;
|
12 |
import java.util.ArrayList;
|
| 12 |
import java.util.Date;
|
13 |
import java.util.Date;
|
| 13 |
import java.util.List;
|
14 |
import java.util.List;
|
| 14 |
|
15 |
|
| - |
|
16 |
import javax.mail.MessagingException;
|
| - |
|
17 |
|
| 15 |
import org.apache.http.HttpResponse;
|
18 |
import org.apache.http.HttpResponse;
|
| 16 |
import org.apache.http.NameValuePair;
|
19 |
import org.apache.http.NameValuePair;
|
| 17 |
import org.apache.http.client.HttpClient;
|
20 |
import org.apache.http.client.HttpClient;
|
| 18 |
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
21 |
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
| 19 |
import org.apache.http.client.methods.HttpGet;
|
22 |
import org.apache.http.client.methods.HttpGet;
|
| 20 |
import org.apache.http.client.methods.HttpPost;
|
23 |
import org.apache.http.client.methods.HttpPost;
|
| 21 |
import org.apache.http.impl.client.DefaultHttpClient;
|
24 |
import org.apache.http.impl.client.DefaultHttpClient;
|
| 22 |
import org.apache.http.message.BasicNameValuePair;
|
25 |
import org.apache.http.message.BasicNameValuePair;
|
| - |
|
26 |
import org.json.JSONArray;
|
| - |
|
27 |
import org.json.JSONObject;
|
| 23 |
|
28 |
|
| 24 |
import com.google.gson.Gson;
|
29 |
import com.google.gson.Gson;
|
| 25 |
|
30 |
|
| 26 |
public class FlipkartOrderStatusReconciliation{
|
31 |
public class FlipkartOrderStatusReconciliation{
|
| - |
|
32 |
static String emailFromAddress;
|
| - |
|
33 |
static String password;
|
| - |
|
34 |
static GmailUtils mailer;
|
| - |
|
35 |
static String sendTo[];
|
| - |
|
36 |
|
| - |
|
37 |
static {
|
| - |
|
38 |
emailFromAddress = "build-staging@shop2020.in";
|
| - |
|
39 |
password = "shop2020";
|
| - |
|
40 |
mailer = new GmailUtils();
|
| - |
|
41 |
sendTo = new String[] { "kshitij.sood@shop2020.in", "manish.sharma@shop2020.in", "amit.gupta@shop2020.in" };
|
| - |
|
42 |
}
|
| - |
|
43 |
|
| 27 |
public static void main(String[] args) {
|
44 |
public static void main(String[] args) throws MessagingException {
|
| 28 |
HttpClient client = new DefaultHttpClient();
|
45 |
HttpClient client = new DefaultHttpClient();
|
| 29 |
HttpPost post = new HttpPost("https://seller.flipkart.com/login");
|
46 |
HttpPost post = new HttpPost("https://seller.flipkart.com/login");
|
| 30 |
BufferedReader rd= null;
|
47 |
BufferedReader rd= null;
|
| 31 |
|
48 |
|
| 32 |
List<List<String>> deliveredOrderDataList = new ArrayList<List<String>>();
|
49 |
List<List<String>> deliveredOrderDataList = new ArrayList<List<String>>();
|
| 33 |
SimpleDateFormat gotFlipkartDateFormat = new SimpleDateFormat("MMM dd, yyyy");
|
50 |
SimpleDateFormat gotFlipkartDateFormat = new SimpleDateFormat("MMM dd, yyyy");
|
| 34 |
//SimpleDateFormat createDateFormatter = new SimpleDateFormat("MMM dd, yyyy hh:mm aaa");
|
51 |
//SimpleDateFormat createDateFormatter = new SimpleDateFormat("MMM dd, yyyy hh:mm aaa");
|
| 35 |
SimpleDateFormat ourDBDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
52 |
SimpleDateFormat ourDBDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
| 36 |
long minCreationDate = 0l;
|
53 |
long minCreationDate = 0l;
|
| 37 |
try {
|
54 |
try {
|
| 38 |
minCreationDate = new TransactionClient().getClient().getMinCreatedTimeStampUndeliveredOrdersForSource(OrderSource.FLIPKART.getValue());
|
55 |
minCreationDate = /*1386432631000l;*/new TransactionClient().getClient().getMinCreatedTimeStampUndeliveredOrdersForSource(OrderSource.FLIPKART.getValue());
|
| 39 |
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
|
56 |
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
|
| 40 |
nameValuePairs.add(new BasicNameValuePair("authName",
|
57 |
nameValuePairs.add(new BasicNameValuePair("authName",
|
| 41 |
"flipkart"));
|
58 |
"flipkart"));
|
| 42 |
nameValuePairs.add(new BasicNameValuePair("username",
|
59 |
nameValuePairs.add(new BasicNameValuePair("username",
|
| 43 |
"flipkart-support@saholic.com"));
|
60 |
"flipkart-support@saholic.com"));
|
| Line 63... |
Line 80... |
| 63 |
get_new = new HttpGet("https://seller.flipkart.com/dashboard/som/shipped_order_items?status=delivered&page="+i+"&page_size=100&_="+time);
|
80 |
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);
|
81 |
response = client.execute(get_new);
|
| 65 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
82 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
| 66 |
line = "";
|
83 |
line = "";
|
| 67 |
gson = new Gson();
|
84 |
gson = new Gson();
|
| - |
|
85 |
|
| 68 |
//System.out.println("RD....."+rd.readLine());
|
86 |
JSONObject jsonDataObj = null;
|
| 69 |
new_orders = (OrderItems) gson.fromJson(rd, OrderItems.class);
|
87 |
line = rd.readLine();
|
| - |
|
88 |
|
| 70 |
if(new_orders.getOrder_items().size()>0){
|
89 |
JSONArray jsonObjArr = null;
|
| - |
|
90 |
|
| 71 |
orders.addAll(new_orders.getOrder_items());
|
91 |
if(line == null || line.isEmpty()){
|
| - |
|
92 |
break;
|
| 72 |
}
|
93 |
}
|
| - |
|
94 |
|
| - |
|
95 |
jsonDataObj = new JSONObject(line);
|
| - |
|
96 |
jsonObjArr = new JSONArray(jsonDataObj.get("order_items").toString());
|
| 73 |
else{
|
97 |
|
| - |
|
98 |
if(jsonObjArr==null || jsonObjArr.length()==0){
|
| 74 |
break;
|
99 |
break;
|
| 75 |
}
|
100 |
}
|
| - |
|
101 |
|
| - |
|
102 |
if(jsonObjArr!=null && jsonObjArr.length()>0){
|
| - |
|
103 |
for(int k=0; k< jsonObjArr.length(); k++){
|
| - |
|
104 |
JSONObject jsonObj = null;
|
| - |
|
105 |
jsonObj = jsonObjArr.getJSONObject(k);
|
| - |
|
106 |
|
| - |
|
107 |
if(jsonObj!=null){
|
| - |
|
108 |
/*System.out.println("jsonObj..... "+ jsonObj);*/
|
| - |
|
109 |
if(minCreationDate > 0l && gotFlipkartDateFormat.parse(gotFlipkartDateFormat.format(minCreationDate)).getTime() <= gotFlipkartDateFormat.parse(jsonObj.get("created_date").toString()).getTime()){
|
| - |
|
110 |
List<String> delivered_dataList = new ArrayList<String>();
|
| - |
|
111 |
String externalId = jsonObj.get("external_id").toString();
|
| - |
|
112 |
String orderItemId = jsonObj.get("order_item_id").toString();
|
| - |
|
113 |
String modifiedDate = jsonObj.get("modified_date").toString();
|
| - |
|
114 |
delivered_dataList.add(externalId);
|
| - |
|
115 |
delivered_dataList.add(orderItemId);
|
| - |
|
116 |
|
| - |
|
117 |
delivered_dataList.add(ourDBDateFormat.format(gotFlipkartDateFormat.parse(modifiedDate).getTime()));
|
| - |
|
118 |
System.out.println("Flipkart Order Id... "+externalId + " ... Flipkart Sub Order Code... "+ orderItemId +" ... Delivery Date ... "+ ourDBDateFormat.format(gotFlipkartDateFormat.parse(modifiedDate).getTime()) + "....Created Date..... "+ jsonObj.get("created_date").toString());
|
| - |
|
119 |
deliveredOrderDataList.add(delivered_dataList);
|
| - |
|
120 |
}
|
| - |
|
121 |
}
|
| - |
|
122 |
}
|
| - |
|
123 |
}
|
| - |
|
124 |
|
| 76 |
i++;
|
125 |
i++;
|
| 77 |
}
|
126 |
}
|
| 78 |
|
127 |
|
| 79 |
for(Order order:orders){
|
- |
|
| 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 |
}
|
- |
|
| 88 |
}
|
- |
|
| 89 |
//System.out.println("deliveredOrderDataList size... "+deliveredOrderDataList.size());
|
128 |
System.out.println("deliveredOrderDataList size... "+deliveredOrderDataList.size());
|
| 90 |
if(deliveredOrderDataList!=null && deliveredOrderDataList.size()>0){
|
129 |
if(deliveredOrderDataList!=null && deliveredOrderDataList.size()>0){
|
| 91 |
new TransactionClient().getClient().updateFlipkartOrdersStatus(deliveredOrderDataList);
|
130 |
new TransactionClient().getClient().updateFlipkartOrdersStatus(deliveredOrderDataList);
|
| 92 |
}
|
131 |
}
|
| 93 |
|
132 |
|
| 94 |
} catch(Exception e){
|
133 |
} catch(Exception e){
|
| 95 |
e.printStackTrace();
|
134 |
e.printStackTrace();
|
| - |
|
135 |
mailer.sendSSLMessage(sendTo, "Error in Flipkart Order Status Recon", emailFromAddress, password, "<html><body><p>Please check log</p></body></html>");
|
| 96 |
}
|
136 |
}
|
| 97 |
}
|
137 |
}
|
| 98 |
}
|
138 |
}
|
| 99 |
|
139 |
|