| 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;
|
| 12427 |
manish.sha |
7 |
import in.shop2020.utils.GmailUtils;
|
| 9651 |
manish.sha |
8 |
|
|
|
9 |
import java.io.BufferedReader;
|
|
|
10 |
import java.io.InputStreamReader;
|
|
|
11 |
import java.text.SimpleDateFormat;
|
|
|
12 |
import java.util.ArrayList;
|
| 9698 |
manish.sha |
13 |
import java.util.Date;
|
| 9651 |
manish.sha |
14 |
import java.util.List;
|
|
|
15 |
|
| 12427 |
manish.sha |
16 |
import javax.mail.MessagingException;
|
|
|
17 |
|
| 9651 |
manish.sha |
18 |
import org.apache.http.HttpResponse;
|
|
|
19 |
import org.apache.http.NameValuePair;
|
|
|
20 |
import org.apache.http.client.HttpClient;
|
|
|
21 |
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
|
|
22 |
import org.apache.http.client.methods.HttpGet;
|
|
|
23 |
import org.apache.http.client.methods.HttpPost;
|
|
|
24 |
import org.apache.http.impl.client.DefaultHttpClient;
|
|
|
25 |
import org.apache.http.message.BasicNameValuePair;
|
| 12427 |
manish.sha |
26 |
import org.json.JSONArray;
|
|
|
27 |
import org.json.JSONObject;
|
| 9651 |
manish.sha |
28 |
|
|
|
29 |
import com.google.gson.Gson;
|
|
|
30 |
|
|
|
31 |
public class FlipkartOrderStatusReconciliation{
|
| 12427 |
manish.sha |
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 |
|
|
|
44 |
public static void main(String[] args) throws MessagingException {
|
| 9651 |
manish.sha |
45 |
HttpClient client = new DefaultHttpClient();
|
|
|
46 |
HttpPost post = new HttpPost("https://seller.flipkart.com/login");
|
|
|
47 |
BufferedReader rd= null;
|
|
|
48 |
|
|
|
49 |
List<List<String>> deliveredOrderDataList = new ArrayList<List<String>>();
|
|
|
50 |
SimpleDateFormat gotFlipkartDateFormat = new SimpleDateFormat("MMM dd, yyyy");
|
| 9699 |
manish.sha |
51 |
//SimpleDateFormat createDateFormatter = new SimpleDateFormat("MMM dd, yyyy hh:mm aaa");
|
| 9651 |
manish.sha |
52 |
SimpleDateFormat ourDBDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
| 9698 |
manish.sha |
53 |
long minCreationDate = 0l;
|
| 9651 |
manish.sha |
54 |
try {
|
| 12427 |
manish.sha |
55 |
minCreationDate = /*1386432631000l;*/new TransactionClient().getClient().getMinCreatedTimeStampUndeliveredOrdersForSource(OrderSource.FLIPKART.getValue());
|
| 9651 |
manish.sha |
56 |
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
|
|
|
57 |
nameValuePairs.add(new BasicNameValuePair("authName",
|
|
|
58 |
"flipkart"));
|
|
|
59 |
nameValuePairs.add(new BasicNameValuePair("username",
|
|
|
60 |
"flipkart-support@saholic.com"));
|
|
|
61 |
nameValuePairs.add(new BasicNameValuePair("password",
|
|
|
62 |
"076c27ee24d7596b06608a8ed2559f87"));
|
|
|
63 |
post.setEntity(new UrlEncodedFormEntity(nameValuePairs,"utf-8"));
|
|
|
64 |
HttpResponse response = client.execute(post);
|
|
|
65 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
|
|
66 |
String line = "";
|
|
|
67 |
Gson gson;
|
|
|
68 |
List<Order> orders = new ArrayList<Order>();
|
|
|
69 |
OrderItems new_orders;
|
|
|
70 |
HttpGet get_new;
|
|
|
71 |
|
|
|
72 |
long time;
|
|
|
73 |
int i=1;
|
|
|
74 |
while ((line = rd.readLine()) != null) {
|
|
|
75 |
System.out.println(line);
|
|
|
76 |
}
|
|
|
77 |
time = System.currentTimeMillis();
|
|
|
78 |
|
|
|
79 |
while(true){
|
|
|
80 |
get_new = new HttpGet("https://seller.flipkart.com/dashboard/som/shipped_order_items?status=delivered&page="+i+"&page_size=100&_="+time);
|
|
|
81 |
response = client.execute(get_new);
|
|
|
82 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
|
|
83 |
line = "";
|
|
|
84 |
gson = new Gson();
|
| 12427 |
manish.sha |
85 |
|
|
|
86 |
JSONObject jsonDataObj = null;
|
|
|
87 |
line = rd.readLine();
|
|
|
88 |
|
|
|
89 |
JSONArray jsonObjArr = null;
|
|
|
90 |
|
|
|
91 |
if(line == null || line.isEmpty()){
|
|
|
92 |
break;
|
| 9651 |
manish.sha |
93 |
}
|
| 12427 |
manish.sha |
94 |
|
|
|
95 |
jsonDataObj = new JSONObject(line);
|
|
|
96 |
jsonObjArr = new JSONArray(jsonDataObj.get("order_items").toString());
|
|
|
97 |
|
|
|
98 |
if(jsonObjArr==null || jsonObjArr.length()==0){
|
| 9651 |
manish.sha |
99 |
break;
|
|
|
100 |
}
|
| 12427 |
manish.sha |
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 |
|
| 9651 |
manish.sha |
125 |
i++;
|
|
|
126 |
}
|
|
|
127 |
|
| 12427 |
manish.sha |
128 |
System.out.println("deliveredOrderDataList size... "+deliveredOrderDataList.size());
|
| 9651 |
manish.sha |
129 |
if(deliveredOrderDataList!=null && deliveredOrderDataList.size()>0){
|
|
|
130 |
new TransactionClient().getClient().updateFlipkartOrdersStatus(deliveredOrderDataList);
|
|
|
131 |
}
|
|
|
132 |
|
|
|
133 |
} catch(Exception e){
|
|
|
134 |
e.printStackTrace();
|
| 12427 |
manish.sha |
135 |
mailer.sendSSLMessage(sendTo, "Error in Flipkart Order Status Recon", emailFromAddress, password, "<html><body><p>Please check log</p></body></html>");
|
| 9651 |
manish.sha |
136 |
}
|
|
|
137 |
}
|
|
|
138 |
}
|