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