| 9651 |
manish.sha |
1 |
package in.shop2020;
|
|
|
2 |
|
|
|
3 |
import in.shop2020.model.v1.order.Order;
|
|
|
4 |
import in.shop2020.model.v1.order.OrderSource;
|
|
|
5 |
import in.shop2020.model.v1.order.OrderStatus;
|
|
|
6 |
import in.shop2020.model.v1.order.SnapdealOrder;
|
|
|
7 |
import in.shop2020.thrift.clients.TransactionClient;
|
|
|
8 |
|
|
|
9 |
import java.io.BufferedReader;
|
|
|
10 |
import java.io.IOException;
|
|
|
11 |
import java.io.InputStreamReader;
|
|
|
12 |
import java.io.UnsupportedEncodingException;
|
|
|
13 |
import java.text.SimpleDateFormat;
|
|
|
14 |
import java.util.ArrayList;
|
|
|
15 |
import java.util.Date;
|
|
|
16 |
import java.util.List;
|
|
|
17 |
|
|
|
18 |
import org.apache.http.HttpResponse;
|
|
|
19 |
import org.apache.http.NameValuePair;
|
|
|
20 |
import org.apache.http.client.ClientProtocolException;
|
|
|
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;
|
|
|
27 |
import org.apache.http.params.HttpParams;
|
|
|
28 |
import org.json.JSONArray;
|
|
|
29 |
import org.json.JSONException;
|
|
|
30 |
import org.json.JSONObject;
|
|
|
31 |
import org.slf4j.Logger;
|
|
|
32 |
import org.slf4j.LoggerFactory;
|
|
|
33 |
|
|
|
34 |
public class SnapdealOrderStatusReconciliation{
|
|
|
35 |
private static Logger logger;
|
|
|
36 |
|
|
|
37 |
public static void main(String[] args) throws UnsupportedEncodingException{
|
|
|
38 |
logger = LoggerFactory.getLogger(SnapdealOrderStatusReconciliation.class);
|
|
|
39 |
List<OrderStatus> statuses = new ArrayList<OrderStatus>();
|
|
|
40 |
statuses.add(OrderStatus.SHIPPED_FROM_WH);
|
|
|
41 |
statuses.add(OrderStatus.SHIPPED_TO_LOGST);
|
|
|
42 |
|
|
|
43 |
List<List<String>> deliveredOrderDataList = new ArrayList<List<String>>();
|
|
|
44 |
long minCreationDate = 0l;
|
|
|
45 |
TransactionClient tsc = null;
|
|
|
46 |
try {
|
|
|
47 |
tsc = new TransactionClient();
|
|
|
48 |
minCreationDate = tsc.getClient().getMinCreatedTimeStampUndeliveredOrdersForSource(OrderSource.SNAPDEAL.getValue());
|
|
|
49 |
} catch (Exception e) {
|
|
|
50 |
logger.error("Unable to establish connection to the transaction service while getting Minimum Order Created Timstamp for Undelivered Orders ", e);
|
| 9730 |
manish.sha |
51 |
}//Dec 14, 2013 12:00:00 AM 1383291412000l
|
| 9651 |
manish.sha |
52 |
|
|
|
53 |
SimpleDateFormat snapdealDateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
54 |
SimpleDateFormat gotSnapdealDateFormat = new SimpleDateFormat("MMM dd, yyyy HH:mm:ss aaa");
|
|
|
55 |
SimpleDateFormat ourDBDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
56 |
String startDate= "";
|
|
|
57 |
if(minCreationDate > 0l){
|
|
|
58 |
startDate = snapdealDateFormat.format(new Date(minCreationDate));
|
|
|
59 |
}
|
|
|
60 |
else{
|
|
|
61 |
startDate = snapdealDateFormat.format(new Date(System.currentTimeMillis()));
|
|
|
62 |
}
|
|
|
63 |
logger.info("Snapdeal Order Recon Start Date .. "+startDate);
|
|
|
64 |
startDate = startDate.replace("-", "%2F");
|
|
|
65 |
|
|
|
66 |
String endDate = snapdealDateFormat.format(new Date(System.currentTimeMillis()));
|
|
|
67 |
logger.info("Snapdeal Order Recon End Date .. "+endDate);
|
|
|
68 |
endDate = endDate.replace("-", "%2F");
|
|
|
69 |
|
|
|
70 |
|
|
|
71 |
HttpClient client = new DefaultHttpClient();
|
|
|
72 |
HttpPost post = new HttpPost("http://shipping.snapdeal.com/login_security_check?spring-security-redirect=http://shipping.snapdeal.com/vendor/product-shipment/shippingDashboard&");
|
|
|
73 |
HttpGet get;
|
|
|
74 |
BufferedReader rd= null;
|
| 9731 |
manish.sha |
75 |
|
| 9651 |
manish.sha |
76 |
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
|
|
|
77 |
nameValuePairs.add(new BasicNameValuePair("j_username",
|
|
|
78 |
"khushal.bhatia@saholic.com"));
|
|
|
79 |
nameValuePairs.add(new BasicNameValuePair("j_password",
|
|
|
80 |
"s@h0l1c"));
|
|
|
81 |
post.setEntity(new UrlEncodedFormEntity(nameValuePairs,"utf-8"));
|
|
|
82 |
HttpResponse response = null;
|
|
|
83 |
try {
|
|
|
84 |
response = client.execute(post);
|
| 9700 |
manish.sha |
85 |
} catch (Exception e) {
|
|
|
86 |
logger.error("Unable to get Http Response for snapdeal seller portal login", e);
|
| 9651 |
manish.sha |
87 |
}
|
|
|
88 |
try {
|
|
|
89 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
| 9700 |
manish.sha |
90 |
} catch (Exception e1) {
|
|
|
91 |
logger.error("Unable to read Http Response for snapdeal seller portal login", e1);
|
|
|
92 |
}
|
| 9731 |
manish.sha |
93 |
|
| 9651 |
manish.sha |
94 |
String line = "";
|
|
|
95 |
try {
|
|
|
96 |
while ((line = rd.readLine()) != null) {
|
|
|
97 |
System.out.println(line);
|
|
|
98 |
}
|
| 9700 |
manish.sha |
99 |
} catch (Exception e) {
|
|
|
100 |
logger.error("Unable to extract Http Response for snapdeal seller portal login", e);
|
| 9651 |
manish.sha |
101 |
}
|
|
|
102 |
|
|
|
103 |
//http://shipping.snapdeal.com/vendor/ONESHIP/product-shipment/shippedData/fetch/?shippedStartDate=2014%2F01%2F01&shippedEndDate=2014%2F01%2F08&specialPanelAccess=&statusCode=COURIER_DELIVERED&statusColumn=deliveredOn&dispatchCategoryId=0&sCode=COURIER_DELIVERED
|
|
|
104 |
|
|
|
105 |
logger.info("Getting Delivery Information for DropShip Snapdeal Orders");
|
| 9730 |
manish.sha |
106 |
String dropshipUrl = "http://shipping.snapdeal.com/vendor/DROPSHIP/product-shipment/shippedData/fetch/?shippedStartDate="+startDate+"&shippedEndDate="+endDate+"&specialPanelAccess=&statusCode=COURIER_DELIVERED&statusColumn=deliveredOn&dispatchCategoryId=0&sCode=COURIER_DELIVERED";
|
|
|
107 |
logger.info("Drop Ship Url "+dropshipUrl);
|
| 9731 |
manish.sha |
108 |
|
| 9730 |
manish.sha |
109 |
get = new HttpGet(dropshipUrl);
|
| 9651 |
manish.sha |
110 |
|
|
|
111 |
try {
|
|
|
112 |
response = client.execute(get);
|
| 9700 |
manish.sha |
113 |
} catch (Exception e) {
|
|
|
114 |
logger.error("Unable to get Http Response for snapdeal dropship delivered orders", e);
|
|
|
115 |
}
|
| 9651 |
manish.sha |
116 |
|
|
|
117 |
try {
|
|
|
118 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
| 9700 |
manish.sha |
119 |
} catch (Exception e) {
|
|
|
120 |
logger.error("Unable to read Http Response for snapdeal dropship delivered orders", e);
|
|
|
121 |
}
|
| 9651 |
manish.sha |
122 |
|
|
|
123 |
JSONArray jsonDataShip = null;
|
|
|
124 |
String line1 = "";
|
|
|
125 |
try {
|
|
|
126 |
while ((line1 = rd.readLine()) != null) {
|
|
|
127 |
if(line1.contains("jsonString")){
|
|
|
128 |
String jsonString = line1.substring(line1.indexOf("["), line1.indexOf("'/>"));
|
| 9719 |
manish.sha |
129 |
logger.info("Response get from SnapDeal DropShip.. ");
|
| 9651 |
manish.sha |
130 |
jsonDataShip = new JSONArray(jsonString);
|
|
|
131 |
break;
|
|
|
132 |
}
|
|
|
133 |
}
|
| 9700 |
manish.sha |
134 |
} catch (Exception e) {
|
|
|
135 |
logger.error("Unable to extract Http Response for snapdeal dropship delivered orders", e);
|
|
|
136 |
}
|
| 9651 |
manish.sha |
137 |
|
|
|
138 |
if(jsonDataShip!=null && jsonDataShip.length()>0){
|
|
|
139 |
for(int i=0; i< jsonDataShip.length(); i++){
|
|
|
140 |
JSONObject jsonObj = null;
|
|
|
141 |
try {
|
|
|
142 |
jsonObj = jsonDataShip.getJSONObject(i);
|
|
|
143 |
|
|
|
144 |
if(jsonObj!=null){
|
| 9719 |
manish.sha |
145 |
//System.out.println(jsonObj);
|
| 9651 |
manish.sha |
146 |
String subOrderCode =(String) jsonObj.get("suborderCode");
|
|
|
147 |
String referenceNumber =(String) jsonObj.get("referenceNumber");
|
|
|
148 |
String deliveryDate =(String) jsonObj.get("deliveredOn");
|
| 9719 |
manish.sha |
149 |
//System.out.println("Snapdeal Dropship Order Details...suborderCode... "+subOrderCode+" ...referenceNumber... "+ referenceNumber+ " ...deliveryDate... "+ deliveryDate);
|
| 9700 |
manish.sha |
150 |
logger.info("Snapdeal Dropship Order Details...suborderCode... "+subOrderCode+" ...referenceNumber... "+ referenceNumber+ " ...deliveryDate... "+ deliveryDate);
|
| 9651 |
manish.sha |
151 |
deliveryDate = ourDBDateFormat.format(gotSnapdealDateFormat.parse(deliveryDate).getTime());
|
|
|
152 |
List<String> deliveredOrdelList = new ArrayList<String>();
|
|
|
153 |
deliveredOrdelList.add(referenceNumber);
|
|
|
154 |
deliveredOrdelList.add(subOrderCode);
|
|
|
155 |
deliveredOrdelList.add(deliveryDate);
|
|
|
156 |
deliveredOrderDataList.add(deliveredOrdelList);
|
|
|
157 |
}
|
|
|
158 |
} catch (Exception e) {
|
| 9700 |
manish.sha |
159 |
logger.error("Unable to add delivered order details for updation regarding snapdeal dropship delivered orders", e);
|
| 9651 |
manish.sha |
160 |
}
|
|
|
161 |
}
|
|
|
162 |
}
|
|
|
163 |
|
|
|
164 |
logger.info("Getting Delivery Information for OneShip Snapdeal Orders");
|
| 9730 |
manish.sha |
165 |
String oneShipUrl = "http://shipping.snapdeal.com/vendor/ONESHIP/product-shipment/shippedData/fetch/?shippedStartDate="+startDate+"&shippedEndDate="+endDate+"&specialPanelAccess=&statusCode=COURIER_DELIVERED&statusColumn=deliveredOn&dispatchCategoryId=0&sCode=COURIER_DELIVERED";
|
|
|
166 |
logger.info("One Ship Url "+oneShipUrl);
|
| 9731 |
manish.sha |
167 |
|
| 9730 |
manish.sha |
168 |
get = new HttpGet(oneShipUrl);
|
| 9731 |
manish.sha |
169 |
|
| 9651 |
manish.sha |
170 |
try {
|
|
|
171 |
response = client.execute(get);
|
| 9700 |
manish.sha |
172 |
} catch (Exception e) {
|
|
|
173 |
logger.error("Unable to get Http Response for snapdeal oneship delivered orders", e);
|
|
|
174 |
}
|
| 9651 |
manish.sha |
175 |
|
|
|
176 |
try {
|
|
|
177 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
| 9700 |
manish.sha |
178 |
} catch (Exception e) {
|
|
|
179 |
logger.error("Unable to read Http Response for snapdeal oneship delivered orders", e);
|
|
|
180 |
}
|
| 9651 |
manish.sha |
181 |
|
|
|
182 |
try {
|
|
|
183 |
while ((line1 = rd.readLine()) != null) {
|
|
|
184 |
if(line1.contains("jsonString")){
|
|
|
185 |
String jsonString = line1.substring(line1.indexOf("["), line1.indexOf("'/>"));
|
| 9719 |
manish.sha |
186 |
logger.info("Response get from SnapDeal OneShip.. ");
|
| 9651 |
manish.sha |
187 |
jsonDataShip = new JSONArray(jsonString);
|
|
|
188 |
break;
|
|
|
189 |
}
|
|
|
190 |
}
|
| 9700 |
manish.sha |
191 |
} catch (Exception e) {
|
|
|
192 |
logger.error("Unable to extract Http Response for snapdeal oneship delivered orders", e);
|
|
|
193 |
}
|
| 9731 |
manish.sha |
194 |
|
| 9651 |
manish.sha |
195 |
if(jsonDataShip!=null && jsonDataShip.length()>0){
|
|
|
196 |
for(int i=0; i< jsonDataShip.length(); i++){
|
|
|
197 |
JSONObject jsonObj = null;
|
|
|
198 |
try {
|
|
|
199 |
jsonObj = jsonDataShip.getJSONObject(i);
|
|
|
200 |
|
|
|
201 |
if(jsonObj!=null){
|
| 9719 |
manish.sha |
202 |
//System.out.println(jsonObj);
|
| 9651 |
manish.sha |
203 |
String subOrderCode =(String) jsonObj.get("suborderCode");
|
|
|
204 |
String referenceNumber =(String) jsonObj.get("referenceNumber");
|
|
|
205 |
String deliveryDate =(String) jsonObj.get("deliveredOn");
|
| 9719 |
manish.sha |
206 |
//System.out.println("Snapdeal Oneship Order Details...suborderCode... "+subOrderCode+" ...referenceNumber... "+ referenceNumber+ " ...deliveryDate... "+ deliveryDate);
|
| 9700 |
manish.sha |
207 |
logger.info("Snapdeal Oneship Order Details...suborderCode... "+subOrderCode+" ...referenceNumber... "+ referenceNumber+ " ...deliveryDate... "+ deliveryDate);
|
| 9651 |
manish.sha |
208 |
deliveryDate = ourDBDateFormat.format(gotSnapdealDateFormat.parse(deliveryDate).getTime());
|
|
|
209 |
List<String> deliveredOrdelList = new ArrayList<String>();
|
|
|
210 |
deliveredOrdelList.add(referenceNumber);
|
|
|
211 |
deliveredOrdelList.add(subOrderCode);
|
|
|
212 |
deliveredOrdelList.add(deliveryDate);
|
|
|
213 |
|
|
|
214 |
deliveredOrderDataList.add(deliveredOrdelList);
|
|
|
215 |
}
|
|
|
216 |
} catch (Exception e) {
|
| 9700 |
manish.sha |
217 |
logger.error("Unable to add delivered order details for updation regarding snapdeal oneship delivered orders", e);
|
| 9651 |
manish.sha |
218 |
}
|
|
|
219 |
}
|
|
|
220 |
}
|
| 9731 |
manish.sha |
221 |
|
|
|
222 |
if(deliveredOrderDataList!=null && deliveredOrderDataList.size()>0){
|
| 9732 |
manish.sha |
223 |
logger.info("Delivered Orders Size .. "+deliveredOrderDataList.size());
|
| 9731 |
manish.sha |
224 |
try{
|
|
|
225 |
new TransactionClient().getClient().updateSnapdealOrdersStatus(deliveredOrderDataList);
|
|
|
226 |
} catch(Exception e){
|
|
|
227 |
logger.error("Unable to update delivery information for snapdeal orders", e);
|
| 9651 |
manish.sha |
228 |
}
|
|
|
229 |
}
|
| 9731 |
manish.sha |
230 |
|
| 9651 |
manish.sha |
231 |
}
|
|
|
232 |
}
|