| 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"));
|
| 12857 |
manish.sha |
68 |
post.addHeader("Cookie","T=TI138130450866706710769873257251497444628820234222703981199700765991; __gads=ID=dfe0374cf04d1576:T=1381304511:S=ALNI_Ma2TpDrlF9_amkoqp3MOYJBaFAOUg; km_lv=x; __sonar=6631097455123118581; __isReg=true; connect.sid=s%3AWwlGdtrLzj38cMjvZPI6ib5J.YUhinXC189untGw58i2CE9k7BGgKQJs9L%2BVIYPIW9Ok; is_login=true; sellerId=m2z93iskuj81qiid; __utma=143439159.1156779613.1390806906.1412575623.1412581840.30; __utmc=143439159; __utmz=143439159.1390806906.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); pincode=110001; S=d1t17uBGP%2FSlPrRt2tpUnAFVMIP3X6vbS8VVSIjMrWMoY2HMx3d4ZaG7UZNIW4uhS2vEDllnTlWndGOX15%2FPyLnmgnw%3D%3D; __utma=19769839.1733153395.1408690721.1412603997.1412663006.15; __utmb=19769839.3.10.1412663006; __utmc=19769839; __utmz=19769839.1409028689.3.2.utmcsr=savemoneyindia.com|utmccn=(referral)|utmcmd=referral|utmcct=/; s_cc=true; gpv_pn=Homepage; gpv_pn_t=no%20value; s_sq=%5B%5BB%5D%5D; s_ppv=14; SN=2.VI4876EB87B4D54359BF5BDC59495E6FAC.SIC5C9F56B37DA4EE59E2226123257E3B6.VS141266300525440480188.1412663034; VID=2.VI4876EB87B4D54359BF5BDC59495E6FAC.1412663034.VS141266300525440480188; NSID=2.SIC5C9F56B37DA4EE59E2226123257E3B6.1412663034.VI4876EB87B4D54359BF5BDC59495E6FAC; _ga=GA1.2.1156779613.1390806906; kvcd=1412663072574; km_ai=m2z93iskuj81qiid; km_ni=m2z93iskuj81qiid; km_vs=1; km_uq=");
|
| 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);
|
| 12857 |
manish.sha |
88 |
//get_new.addHeader("Cookie","T=TI141147280750274359991498309202525657388536723248248488328249492067; __sonar=16983180403917152637; __gads=ID=c15eba68f7f44861:T=1411472817:S=ALNI_MYyU0QfJ923BqkcDhqFlRpZxMcA8w; cmp_id=hp_dotd_4_DOTDOnBajajMixerGrinder_Sep23.|1414064820638; S=d1t16GpsIdt0JTsYuFF%2FMaE7jTGYozxMXM5a3ktJD24TBohceobkUv8l4GDr4KNLkLs5BOgnhsqkZNQRh2Lzrx%2B77zQ%3D%3D; km_lv=x; __utma=19769839.1065606807.1411472808.1411472808.1411624009.2; __utmc=19769839; __utmz=19769839.1411472808.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); s_cc=true; s_sq=%5B%5BB%5D%5D; prd_day=2|1411645620637; s_ppv=21; SN=2.VI89D3B4F7B5534B3C9EADE3BBD925875A.SI05ED43E07EAF40E9B4F265F5F2B1074D.VS141162400679268773093.1411624676; VID=2.VI89D3B4F7B5534B3C9EADE3BBD925875A.1411624676.VS141162400679268773093; NSID=2.SI05ED43E07EAF40E9B4F265F5F2B1074D.1411624676.VI89D3B4F7B5534B3C9EADE3BBD925875A; connect.sid=s%3AaUlfUN00goYPkqRHXtAbM6Nh.EBDDk9%2F0rQDXGb%2B23IEJ4QgrAgKFpXU%2FLOjuQyxJo44; is_login=true; sellerId=m2z93iskuj81qiid; __utma=143439159.1617147053.1411568832.1411568832.1411624688.2; __utmb=143439159.17.10.1411624688; __utmc=143439159; __utmz=143439159.1411568832.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); _ga=GA1.2.1617147053.1411568832; _gat=1; kvcd=1411627978463; km_ai=m2z93iskuj81qiid; km_ni=m2z93iskuj81qiid; km_vs=1; km_uq=");
|
|
|
89 |
get_new.addHeader("Cookie","T=TI138130450866706710769873257251497444628820234222703981199700765991; __gads=ID=dfe0374cf04d1576:T=1381304511:S=ALNI_Ma2TpDrlF9_amkoqp3MOYJBaFAOUg; km_lv=x; __sonar=6631097455123118581; __isReg=true; connect.sid=s%3AWwlGdtrLzj38cMjvZPI6ib5J.YUhinXC189untGw58i2CE9k7BGgKQJs9L%2BVIYPIW9Ok; is_login=true; sellerId=m2z93iskuj81qiid; __utma=143439159.1156779613.1390806906.1412575623.1412581840.30; __utmc=143439159; __utmz=143439159.1390806906.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); pincode=110001; S=d1t17uBGP%2FSlPrRt2tpUnAFVMIP3X6vbS8VVSIjMrWMoY2HMx3d4ZaG7UZNIW4uhS2vEDllnTlWndGOX15%2FPyLnmgnw%3D%3D; __utma=19769839.1733153395.1408690721.1412603997.1412663006.15; __utmb=19769839.3.10.1412663006; __utmc=19769839; __utmz=19769839.1409028689.3.2.utmcsr=savemoneyindia.com|utmccn=(referral)|utmcmd=referral|utmcct=/; s_cc=true; gpv_pn=Homepage; gpv_pn_t=no%20value; s_sq=%5B%5BB%5D%5D; s_ppv=14; SN=2.VI4876EB87B4D54359BF5BDC59495E6FAC.SIC5C9F56B37DA4EE59E2226123257E3B6.VS141266300525440480188.1412663034; VID=2.VI4876EB87B4D54359BF5BDC59495E6FAC.1412663034.VS141266300525440480188; NSID=2.SIC5C9F56B37DA4EE59E2226123257E3B6.1412663034.VI4876EB87B4D54359BF5BDC59495E6FAC; _ga=GA1.2.1156779613.1390806906; kvcd=1412663072574; 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 |
}
|