| 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",
|
| 13184 |
manish.sha |
66 |
"bestmobiledeals2010"));
|
| 9651 |
manish.sha |
67 |
post.setEntity(new UrlEncodedFormEntity(nameValuePairs,"utf-8"));
|
| 13167 |
manish.sha |
68 |
post.addHeader("Cookie","__gads=ID=dfe0374cf04d1576:T=1381304511:S=ALNI_Ma2TpDrlF9_amkoqp3MOYJBaFAOUg; km_lv=x; S=d1t173VTuVxLMgd3in7R3mbHGNz0STqFkHgnidNrhKqBdz8wEKt%2BO9d%2B%2FRDHtf6fmq2ugaE7nZHV7zYSxOLcWBzq31A%3D%3D; __isReg=true; _ga=GA1.2.1156779613.1390806906; km_ai=m2z93iskuj81qiid; km_ni=m2z93iskuj81qiid; km_uq=; pincode=201301; __sonar=6631097455123118581; s_cc=true; s_sq=%5B%5BB%5D%5D; __utma=19769839.1733153395.1408690721.1416647806.1417179072.33; __utmc=19769839; __utmz=19769839.1415795608.26.5.utmcsr=savemoneyindia.com|utmccn=(referral)|utmcmd=referral|utmcct=/; SN=2.VIB1DBEC9C6CD94162ACB61060135212D1.SI47EBA2DE47044D0AA7C05F24AD4F42EB.VS141717906546900755654.1417179082; VID=2.VIB1DBEC9C6CD94162ACB61060135212D1.1417179082.VS141717906546900755654; NSID=2.SI47EBA2DE47044D0AA7C05F24AD4F42EB.1417179082.VIB1DBEC9C6CD94162ACB61060135212D1; T=TI138130450866706710769873257251497444628820234222703981199700765991; s_ppv=53; __CG=u%3A6208250296506778000%2Cs%3A1505183865%2Ct%3A1417179187815%2Cc%3A2%2Ck%3Awww.flipkart.com/30/77/1452%2Cf%3A0%2Ci%3A1; connect.sid=s%3AsMt6GmxeIzE45d0nKtsgQvNm.sea6W5znLeuulBNKyJu1%2FmvpO5xROchbo49GJMoHoFs; __utmt=1; __utma=143439159.1156779613.1390806906.1415709197.1417274947.45; __utmb=143439159.1.10.1417274947; __utmc=143439159; __utmz=143439159.1390806906.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)");
|
| 12760 |
manish.sha |
69 |
post.addHeader("User-agent", "Mozilla/4.0");
|
|
|
70 |
post.addHeader("Referer", "seller.flipkart.com");
|
| 9651 |
manish.sha |
71 |
HttpResponse response = client.execute(post);
|
|
|
72 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
|
|
73 |
String line = "";
|
|
|
74 |
Gson gson;
|
|
|
75 |
List<Order> orders = new ArrayList<Order>();
|
|
|
76 |
OrderItems new_orders;
|
|
|
77 |
HttpGet get_new;
|
| 12516 |
manish.sha |
78 |
|
| 9651 |
manish.sha |
79 |
long time;
|
|
|
80 |
int i=1;
|
|
|
81 |
while ((line = rd.readLine()) != null) {
|
|
|
82 |
System.out.println(line);
|
|
|
83 |
}
|
|
|
84 |
time = System.currentTimeMillis();
|
| 12516 |
manish.sha |
85 |
|
|
|
86 |
outer:while(true){
|
| 12488 |
manish.sha |
87 |
get_new = new HttpGet("https://seller.flipkart.com/dashboard/som/shipped_order_items?status=delivered&page="+i+"&page_size=50&_="+time);
|
| 13636 |
manish.sha |
88 |
get_new.addHeader("Cookie","__gads=ID=dfe0374cf04d1576:T=1381304511:S=ALNI_Ma2TpDrlF9_amkoqp3MOYJBaFAOUg; km_lv=x; S=d1t173VTuVxLMgd3in7R3mbHGNz0STqFkHgnidNrhKqBdz8wEKt%2BO9d%2B%2FRDHtf6fmq2ugaE7nZHV7zYSxOLcWBzq31A%3D%3D; __isReg=true; is_login=true; _ga=GA1.2.1156779613.1390806906; km_ai=m2z93iskuj81qiid; km_ni=m2z93iskuj81qiid; km_uq=; pincode=201301; __sonar=6631097455123118581; s_cc=true; s_sq=%5B%5BB%5D%5D; __utma=19769839.1733153395.1408690721.1416647806.1417179072.33; __utmc=19769839; __utmz=19769839.1415795608.26.5.utmcsr=savemoneyindia.com|utmccn=(referral)|utmcmd=referral|utmcct=/; SN=2.VIB1DBEC9C6CD94162ACB61060135212D1.SI47EBA2DE47044D0AA7C05F24AD4F42EB.VS141717906546900755654.1417179082; VID=2.VIB1DBEC9C6CD94162ACB61060135212D1.1417179082.VS141717906546900755654; NSID=2.SI47EBA2DE47044D0AA7C05F24AD4F42EB.1417179082.VIB1DBEC9C6CD94162ACB61060135212D1; T=TI138130450866706710769873257251497444628820234222703981199700765991; s_ppv=53; __CG=u%3A6208250296506778000%2Cs%3A1505183865%2Ct%3A1417179187815%2Cc%3A2%2Ck%3Awww.flipkart.com/30/77/1452%2Cf%3A0%2Ci%3A1; connect.sid=s%3AsMt6GmxeIzE45d0nKtsgQvNm.sea6W5znLeuulBNKyJu1%2FmvpO5xROchbo49GJMoHoFs; __utmt=1; __utma=143439159.1156779613.1390806906.1415709197.1417274947.45; __utmb=143439159.1.10.1417274947; __utmc=143439159; __utmz=143439159.1390806906.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)");
|
| 13621 |
manish.sha |
89 |
//get_new.addHeader("Cookie","__gads=ID=dfe0374cf04d1576:T=1381304511:S=ALNI_Ma2TpDrlF9_amkoqp3MOYJBaFAOUg; km_lv=x; S=d1t173VTuVxLMgd3in7R3mbHGNz0STqFkHgnidNrhKqBdz8wEKt%2BO9d%2B%2FRDHtf6fmq2ugaE7nZHV7zYSxOLcWBzq31A%3D%3D; __isReg=true; pincode=201301; __sonar=6631097455123118581; s_cc=true; s_sq=%5B%5BB%5D%5D; __utma=19769839.1733153395.1408690721.1416647806.1417179072.33; __utmc=19769839; __utmz=19769839.1415795608.26.5.utmcsr=savemoneyindia.com|utmccn=(referral)|utmcmd=referral|utmcct=/; SN=2.VIB1DBEC9C6CD94162ACB61060135212D1.SI47EBA2DE47044D0AA7C05F24AD4F42EB.VS141717906546900755654.1417179082; VID=2.VIB1DBEC9C6CD94162ACB61060135212D1.1417179082.VS141717906546900755654; NSID=2.SI47EBA2DE47044D0AA7C05F24AD4F42EB.1417179082.VIB1DBEC9C6CD94162ACB61060135212D1; T=TI138130450866706710769873257251497444628820234222703981199700765991; s_ppv=53; __CG=u%3A6208250296506778000%2Cs%3A1505183865%2Ct%3A1417179187815%2Cc%3A2%2Ck%3Awww.flipkart.com/30/77/1452%2Cf%3A0%2Ci%3A1; is_login=true; sellerId=m2z93iskuj81qiid; __utma=143439159.1156779613.1390806906.1417274947.1417519426.46; __utmb=143439159.4.10.1417519426; __utmc=143439159; __utmz=143439159.1390806906.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); _ga=GA1.2.1156779613.1390806906; km_ai=m2z93iskuj81qiid; km_ni=m2z93iskuj81qiid; km_vs=1; km_uq=");
|
| 9651 |
manish.sha |
90 |
response = client.execute(get_new);
|
|
|
91 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
|
|
92 |
line = "";
|
|
|
93 |
gson = new Gson();
|
| 12516 |
manish.sha |
94 |
|
| 12427 |
manish.sha |
95 |
JSONObject jsonDataObj = null;
|
|
|
96 |
line = rd.readLine();
|
| 12516 |
manish.sha |
97 |
|
| 12427 |
manish.sha |
98 |
JSONArray jsonObjArr = null;
|
| 12516 |
manish.sha |
99 |
|
| 12427 |
manish.sha |
100 |
if(line == null || line.isEmpty()){
|
| 12488 |
manish.sha |
101 |
if(i==120)
|
|
|
102 |
break;
|
|
|
103 |
i++;
|
|
|
104 |
continue;
|
| 9651 |
manish.sha |
105 |
}
|
| 12516 |
manish.sha |
106 |
|
| 12427 |
manish.sha |
107 |
jsonDataObj = new JSONObject(line);
|
|
|
108 |
jsonObjArr = new JSONArray(jsonDataObj.get("order_items").toString());
|
| 12516 |
manish.sha |
109 |
|
| 12427 |
manish.sha |
110 |
if(jsonObjArr==null || jsonObjArr.length()==0){
|
| 9651 |
manish.sha |
111 |
break;
|
|
|
112 |
}
|
| 12516 |
manish.sha |
113 |
|
| 12427 |
manish.sha |
114 |
if(jsonObjArr!=null && jsonObjArr.length()>0){
|
|
|
115 |
for(int k=0; k< jsonObjArr.length(); k++){
|
|
|
116 |
JSONObject jsonObj = null;
|
|
|
117 |
jsonObj = jsonObjArr.getJSONObject(k);
|
| 12516 |
manish.sha |
118 |
|
| 12427 |
manish.sha |
119 |
if(jsonObj!=null){
|
|
|
120 |
/*System.out.println("jsonObj..... "+ jsonObj);*/
|
|
|
121 |
if(minCreationDate > 0l && gotFlipkartDateFormat.parse(gotFlipkartDateFormat.format(minCreationDate)).getTime() <= gotFlipkartDateFormat.parse(jsonObj.get("created_date").toString()).getTime()){
|
|
|
122 |
List<String> delivered_dataList = new ArrayList<String>();
|
|
|
123 |
String externalId = jsonObj.get("external_id").toString();
|
|
|
124 |
String orderItemId = jsonObj.get("order_item_id").toString();
|
|
|
125 |
String modifiedDate = jsonObj.get("modified_date").toString();
|
|
|
126 |
delivered_dataList.add(externalId);
|
|
|
127 |
delivered_dataList.add(orderItemId);
|
| 12516 |
manish.sha |
128 |
|
| 12427 |
manish.sha |
129 |
delivered_dataList.add(ourDBDateFormat.format(gotFlipkartDateFormat.parse(modifiedDate).getTime()));
|
|
|
130 |
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());
|
|
|
131 |
deliveredOrderDataList.add(delivered_dataList);
|
|
|
132 |
}
|
| 12516 |
manish.sha |
133 |
else{
|
|
|
134 |
break outer;
|
|
|
135 |
}
|
| 12427 |
manish.sha |
136 |
}
|
|
|
137 |
}
|
|
|
138 |
}
|
| 12516 |
manish.sha |
139 |
|
| 9651 |
manish.sha |
140 |
i++;
|
|
|
141 |
}
|
| 12516 |
manish.sha |
142 |
|
| 12427 |
manish.sha |
143 |
System.out.println("deliveredOrderDataList size... "+deliveredOrderDataList.size());
|
| 9651 |
manish.sha |
144 |
if(deliveredOrderDataList!=null && deliveredOrderDataList.size()>0){
|
|
|
145 |
new TransactionClient().getClient().updateFlipkartOrdersStatus(deliveredOrderDataList);
|
|
|
146 |
}
|
| 12516 |
manish.sha |
147 |
|
| 9651 |
manish.sha |
148 |
} catch(Exception e){
|
|
|
149 |
e.printStackTrace();
|
| 12427 |
manish.sha |
150 |
mailer.sendSSLMessage(sendTo, "Error in Flipkart Order Status Recon", emailFromAddress, password, "<html><body><p>Please check log</p></body></html>");
|
| 9651 |
manish.sha |
151 |
}
|
|
|
152 |
}
|
|
|
153 |
}
|