| Line 1... |
Line 1... |
| 1 |
package in.shop2020.serving.services;
|
1 |
package in.shop2020.serving.services;
|
| 2 |
|
2 |
|
| 3 |
import java.io.BufferedReader;
|
3 |
import java.io.BufferedReader;
|
| - |
|
4 |
import java.io.File;
|
| 4 |
import java.io.IOException;
|
5 |
import java.io.IOException;
|
| 5 |
import java.io.InputStreamReader;
|
6 |
import java.io.InputStreamReader;
|
| 6 |
import java.util.ArrayList;
|
7 |
import java.util.ArrayList;
|
| - |
|
8 |
import java.util.Calendar;
|
| - |
|
9 |
import java.util.GregorianCalendar;
|
| 7 |
import java.util.List;
|
10 |
import java.util.List;
|
| 8 |
|
11 |
|
| 9 |
import in.shop2020.model.v1.order.FlipkartOrder;
|
12 |
import in.shop2020.model.v1.order.FlipkartOrder;
|
| 10 |
import in.shop2020.model.v1.order.TransactionServiceException;
|
13 |
import in.shop2020.model.v1.order.TransactionServiceException;
|
| 11 |
|
14 |
|
| 12 |
import in.shop2020.serving.model.Order;
|
15 |
import in.shop2020.serving.model.Order;
|
| 13 |
import in.shop2020.serving.model.OrderItems;
|
16 |
import in.shop2020.serving.model.OrderItems;
|
| 14 |
import in.shop2020.thrift.clients.TransactionClient;
|
17 |
import in.shop2020.thrift.clients.TransactionClient;
|
| - |
|
18 |
import in.shop2020.utils.GmailUtils;
|
| 15 |
|
19 |
|
| 16 |
import org.apache.http.HttpResponse;
|
20 |
import org.apache.http.HttpResponse;
|
| 17 |
import org.apache.http.NameValuePair;
|
21 |
import org.apache.http.NameValuePair;
|
| 18 |
import org.apache.http.client.HttpClient;
|
22 |
import org.apache.http.client.HttpClient;
|
| 19 |
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
23 |
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
| Line 28... |
Line 32... |
| 28 |
import org.json.JSONObject;
|
32 |
import org.json.JSONObject;
|
| 29 |
|
33 |
|
| 30 |
import com.google.gson.Gson;
|
34 |
import com.google.gson.Gson;
|
| 31 |
|
35 |
|
| 32 |
public class FlipkartHoldOrdersReconciliation{
|
36 |
public class FlipkartHoldOrdersReconciliation{
|
| - |
|
37 |
private static String sendTo[] = new String[]{ "sandeep.sachdeva@shop2020.in", "vikram.raghav@shop2020.in", "rajneesh.arora@shop2020.in",
|
| - |
|
38 |
"khushal.bhatia@shop2020.in","manoj.kumar@saholic.com","chaitnaya.vats@saholic.com",
|
| - |
|
39 |
"yukti.jain@shop2020.in","manish.sharma@shop2020.in","chandan.kumar@shop2020.in","ankush.dhingra@shop2020.in","anikendra.das@shop2020.in"};
|
| - |
|
40 |
private static java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd-HH:mm:ss");
|
| - |
|
41 |
private static Calendar cal=GregorianCalendar.getInstance();
|
| - |
|
42 |
private static String emailFromAddress = "build@shop2020.in";
|
| - |
|
43 |
private static String password = "cafe@nes";
|
| - |
|
44 |
private static GmailUtils mailer = new GmailUtils();
|
| - |
|
45 |
|
| 33 |
public static void main(String[] args) throws TException, TransactionServiceException, JSONException {
|
46 |
public static void main(String[] args) throws TException, TransactionServiceException, JSONException {
|
| 34 |
HttpClient client = new DefaultHttpClient();
|
47 |
HttpClient client = new DefaultHttpClient();
|
| 35 |
HttpPost post = new HttpPost("https://seller.flipkart.com/login");
|
48 |
HttpPost post = new HttpPost("https://seller.flipkart.com/login");
|
| 36 |
BufferedReader rd= null;
|
49 |
BufferedReader rd= null;
|
| 37 |
try {
|
50 |
try {
|
| Line 46... |
Line 59... |
| 46 |
HttpResponse response = client.execute(post);
|
59 |
HttpResponse response = client.execute(post);
|
| 47 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
60 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
| 48 |
String line = "";
|
61 |
String line = "";
|
| 49 |
HttpGet get_new;
|
62 |
HttpGet get_new;
|
| 50 |
|
63 |
|
| - |
|
64 |
List<FlipkartOrder> pendingOrderList = new ArrayList<FlipkartOrder>();
|
| - |
|
65 |
List<FlipkartOrder> acceptedOrderList = new ArrayList<FlipkartOrder>();
|
| - |
|
66 |
List<FlipkartOrder> cancelledOrderList = new ArrayList<FlipkartOrder>();
|
| - |
|
67 |
List<FlipkartOrder> errorOrderList = new ArrayList<FlipkartOrder>();
|
| - |
|
68 |
|
| 51 |
while ((line = rd.readLine()) != null) {
|
69 |
while ((line = rd.readLine()) != null) {
|
| 52 |
System.out.println(line);
|
70 |
System.out.println(line);
|
| 53 |
}
|
71 |
}
|
| 54 |
|
72 |
|
| 55 |
//https://seller.flipkart.com/order_management/search_order_items?order_id=OD40827062297&sellerId=m2z93iskuj81qiid
|
73 |
//https://seller.flipkart.com/order_management/search_order_items?order_id=OD40827062297&sellerId=m2z93iskuj81qiid
|
| 56 |
TransactionClient transactionServiceClient = new TransactionClient();
|
74 |
TransactionClient transactionServiceClient = new TransactionClient();
|
| 57 |
in.shop2020.model.v1.order.TransactionService.Client tClient = transactionServiceClient.getClient();
|
75 |
in.shop2020.model.v1.order.TransactionService.Client tClient = transactionServiceClient.getClient();
|
| 58 |
List<FlipkartOrder> pendingFkOrdersList = tClient.getVerificationPendingOrdersFK();
|
76 |
List<FlipkartOrder> pendingFkOrdersList = tClient.getVerificationPendingOrdersFK();
|
| 59 |
StringBuffer sb = new StringBuffer();
|
77 |
StringBuffer sb = new StringBuffer();
|
| - |
|
78 |
StringBuffer resB = new StringBuffer();
|
| 60 |
for(FlipkartOrder fkOrder : pendingFkOrdersList){
|
79 |
for(FlipkartOrder fkOrder : pendingFkOrdersList){
|
| 61 |
get_new = new HttpGet("https://seller.flipkart.com/order_management/search_order_items?order_id="+fkOrder.getFlipkartOrderId()+"&sellerId=m2z93iskuj81qiid");
|
80 |
get_new = new HttpGet("https://seller.flipkart.com/order_management/search_order_items?order_id="+fkOrder.getFlipkartOrderId()+"&sellerId=m2z93iskuj81qiid");
|
| 62 |
response = client.execute(get_new);
|
81 |
response = client.execute(get_new);
|
| 63 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
82 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
| 64 |
line = "";
|
83 |
line = "";
|
| Line 88... |
Line 107... |
| 88 |
if(jsonObj!=null){
|
107 |
if(jsonObj!=null){
|
| 89 |
System.out.println("jsonObj..... "+ jsonObj);
|
108 |
System.out.println("jsonObj..... "+ jsonObj);
|
| 90 |
if(jsonObj.get("status")!=null){
|
109 |
if(jsonObj.get("status")!=null){
|
| 91 |
String status = jsonObj.get("status").toString();
|
110 |
String status = jsonObj.get("status").toString();
|
| 92 |
if("on_hold".equalsIgnoreCase(status)){
|
111 |
if("on_hold".equalsIgnoreCase(status)){
|
| 93 |
|
112 |
pendingOrderList.add(fkOrder);
|
| 94 |
}
|
113 |
}
|
| 95 |
if("approved".equalsIgnoreCase(status)){
|
114 |
if("approved".equalsIgnoreCase(status)){
|
| 96 |
if(tClient ==null || !tClient.isAlive()){
|
115 |
if(tClient ==null || !tClient.isAlive()){
|
| 97 |
tClient = transactionServiceClient.getClient();
|
116 |
tClient = transactionServiceClient.getClient();
|
| 98 |
}
|
117 |
}
|
| 99 |
tClient.verifyOrder(fkOrder.getOrderId());
|
118 |
tClient.verifyOrder(fkOrder.getOrderId());
|
| 100 |
tClient.acceptOrder(fkOrder.getOrderId());
|
119 |
tClient.acceptOrder(fkOrder.getOrderId());
|
| - |
|
120 |
acceptedOrderList.add(fkOrder);
|
| 101 |
}
|
121 |
}
|
| 102 |
if("cancelled".equalsIgnoreCase(status)){
|
122 |
if("cancelled".equalsIgnoreCase(status)){
|
| 103 |
if(tClient ==null || !tClient.isAlive()){
|
123 |
if(tClient ==null || !tClient.isAlive()){
|
| 104 |
tClient = transactionServiceClient.getClient();
|
124 |
tClient = transactionServiceClient.getClient();
|
| 105 |
}
|
125 |
}
|
| 106 |
tClient.refundOrder(fkOrder.getOrderId(), "flipkart", "As per Buyer's Request");
|
126 |
tClient.refundOrder(fkOrder.getOrderId(), "flipkart", "As per Buyer's Request");
|
| - |
|
127 |
cancelledOrderList.add(fkOrder);
|
| 107 |
}
|
128 |
}
|
| 108 |
}else{
|
129 |
}else{
|
| 109 |
|
130 |
errorOrderList.add(fkOrder);
|
| 110 |
}
|
131 |
}
|
| 111 |
}
|
132 |
}
|
| 112 |
}
|
133 |
}
|
| 113 |
}
|
134 |
}
|
| 114 |
|
135 |
|
| - |
|
136 |
resB.append("Still Pending Orders:-\n");
|
| - |
|
137 |
for(FlipkartOrder order: pendingOrderList){
|
| - |
|
138 |
resB.append(order.getOrderId()+" "+ order.getFlipkartOrderId()+"\n");
|
| - |
|
139 |
}
|
| - |
|
140 |
resB.append("Accepeted Orders:-\n");
|
| - |
|
141 |
for(FlipkartOrder order: acceptedOrderList){
|
| - |
|
142 |
resB.append(order.getOrderId()+" "+ order.getFlipkartOrderId()+"\n");
|
| - |
|
143 |
}
|
| - |
|
144 |
resB.append("Cancelled Orders:-\n");
|
| - |
|
145 |
for(FlipkartOrder order: cancelledOrderList){
|
| - |
|
146 |
resB.append(order.getOrderId()+" "+ order.getFlipkartOrderId()+"\n");
|
| - |
|
147 |
}
|
| - |
|
148 |
resB.append("Response not found Orders:-\n");
|
| - |
|
149 |
for(FlipkartOrder order: errorOrderList){
|
| - |
|
150 |
resB.append(order.getOrderId()+" "+ order.getFlipkartOrderId()+"\n");
|
| - |
|
151 |
}
|
| - |
|
152 |
String emailSubjectTxt = " Flipkart Hold Order Reconcilaition Process "+sdf.format(cal.getTime());
|
| - |
|
153 |
mailer.sendSSLMessage(sendTo, emailSubjectTxt, resB.toString(), emailFromAddress, password, new ArrayList<File>());
|
| 115 |
System.out.println(sb.toString());
|
154 |
System.out.println(sb.toString());
|
| 116 |
} catch (IOException e) {
|
155 |
} catch (Exception e) {
|
| 117 |
e.printStackTrace();
|
156 |
e.printStackTrace();
|
| 118 |
}
|
157 |
}
|
| 119 |
}
|
158 |
}
|
| 120 |
}
|
159 |
}
|
| 121 |
|
160 |
|