Rev 13621 | Rev 13640 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
package in.shop2020.serving.services;import java.io.BufferedReader;import java.io.BufferedWriter;import java.io.File;import java.io.FileWriter;import java.io.IOException;import java.io.InputStreamReader;import java.text.SimpleDateFormat;import java.util.ArrayList;import java.util.Calendar;import java.util.Date;import java.util.GregorianCalendar;import java.util.List;import java.util.concurrent.TimeUnit;import in.shop2020.model.v1.order.FlipkartOrder;import in.shop2020.model.v1.order.TransactionServiceException;import in.shop2020.serving.model.Order;import in.shop2020.serving.model.OrderItems;import in.shop2020.thrift.clients.TransactionClient;import in.shop2020.utils.GmailUtils;import org.apache.commons.lang.StringUtils;import org.apache.http.HttpResponse;import org.apache.http.NameValuePair;import org.apache.http.client.HttpClient;import org.apache.http.client.entity.UrlEncodedFormEntity;import org.apache.http.client.methods.HttpGet;import org.apache.http.client.methods.HttpPost;import org.apache.http.impl.client.DefaultHttpClient;import org.apache.http.message.BasicNameValuePair;import org.apache.thrift.TException;import org.apache.thrift.transport.TTransportException;import org.json.JSONArray;import org.json.JSONException;import org.json.JSONObject;import com.google.gson.Gson;public class FlipkartHoldOrdersReconciliation{private static String sendTo[] = new String[]{ "sandeep.sachdeva@shop2020.in", "eng@shop2020.in" ,"khushal.bhatia@shop2020.in","manoj.kumar@saholic.com","chaitnaya.vats@saholic.com","yukti.jain@shop2020.in","chandan.kumar@shop2020.in","ankush.dhingra@shop2020.in"};//private static String sendTo1[] = new String[]{"manish.sharma@shop2020.in"};private static java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");private static Calendar cal=GregorianCalendar.getInstance();private static String emailFromAddress = "build-staging@shop2020.in";private static String password = "shop2020";private static GmailUtils mailer = new GmailUtils();public static void main(String[] args) throws IOException{File file = new File("/home/manish/alerts/fkhold.txt");BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(file));HttpClient client = new DefaultHttpClient();HttpPost post = new HttpPost("https://seller.flipkart.com/login");BufferedReader rd= null;try {List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();nameValuePairs.add(new BasicNameValuePair("authName","flipkart"));nameValuePairs.add(new BasicNameValuePair("username","flipkart-support@saholic.com"));nameValuePairs.add(new BasicNameValuePair("password","bestmobiledeals2010"));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)");post.addHeader("User-agent", "Mozilla/4.0");post.addHeader("Referer", "seller.flipkart.com");post.setEntity(new UrlEncodedFormEntity(nameValuePairs,"utf-8"));HttpResponse response = client.execute(post);rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));String line = "";HttpGet get_new;List<FlipkartOrder> pendingOrderList = new ArrayList<FlipkartOrder>();List<FlipkartOrder> acceptedOrderList = new ArrayList<FlipkartOrder>();List<FlipkartOrder> cancelledOrderList = new ArrayList<FlipkartOrder>();List<FlipkartOrder> errorOrderList = new ArrayList<FlipkartOrder>();while ((line = rd.readLine()) != null) {System.out.println(line);}//https://seller.flipkart.com/order_management/search_order_items?order_id=OD40827062297&sellerId=m2z93iskuj81qiidTransactionClient transactionServiceClient = new TransactionClient();in.shop2020.model.v1.order.TransactionService.Client tClient = transactionServiceClient.getClient();List<FlipkartOrder> pendingFkOrdersList = tClient.getVerificationPendingOrdersFK();StringBuffer sb = new StringBuffer();StringBuffer resB = new StringBuffer();for(FlipkartOrder fkOrder : pendingFkOrdersList){get_new = new HttpGet("https://seller.flipkart.com/order_management/search_order_items?order_id="+fkOrder.getFlipkartOrderId()+"&sellerId=m2z93iskuj81qiid");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)");response = client.execute(get_new);rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));line = "";line = rd.readLine();System.out.println("Response... "+line);JSONObject jsonDataObj = null;JSONArray jsonObjArr = null;if(line == null || line.isEmpty()){sb.append("Flipkart Order Id -"+ fkOrder.getFlipkartOrderId()+" Response - "+line);sb.append("\n");continue;} else if (!line.startsWith("{")){sb.append("Flipkart Order Id -"+ fkOrder.getFlipkartOrderId()+" Response - "+line);sb.append("\n");continue;}else{jsonDataObj = new JSONObject(line);}if(jsonDataObj!=null){jsonObjArr = new JSONArray(jsonDataObj.get("items").toString());}if(jsonObjArr!=null && jsonObjArr.length()>0){JSONObject jsonObj = null;jsonObj = jsonObjArr.getJSONObject(0);if(jsonObj!=null){if(jsonObj.get("status")!=null){String status = jsonObj.get("status").toString();String statusLabel = jsonObj.get("statusLabel").toString();if("on_hold".equalsIgnoreCase(status) || "On hold".equalsIgnoreCase(statusLabel)){pendingOrderList.add(fkOrder);}if("approved".equalsIgnoreCase(status) || "Approved".equalsIgnoreCase(statusLabel) || "confirmed".equalsIgnoreCase(statusLabel)){if(tClient ==null || !tClient.isAlive()){tClient = transactionServiceClient.getClient();}tClient.verifyOrder(fkOrder.getOrderId());tClient.acceptOrder(fkOrder.getOrderId());acceptedOrderList.add(fkOrder);}if("cancelled".equalsIgnoreCase(status) || "Cancelled".equalsIgnoreCase(statusLabel)){if(tClient ==null || !tClient.isAlive()){tClient = transactionServiceClient.getClient();}tClient.refundOrder(fkOrder.getOrderId(), "flipkart", "As per Buyer's Request");cancelledOrderList.add(fkOrder);}}else{errorOrderList.add(fkOrder);}}}Thread.sleep(3000);}resB.append("Still Pending Orders:-\n");System.out.println("Still Pending Orders:-");for(FlipkartOrder order: pendingOrderList){resB.append(order.getOrderId()+" "+ order.getFlipkartOrderId()+"\n");System.out.println(order.getOrderId()+" "+ order.getFlipkartOrderId());}resB.append("Accepeted Orders:-\n");System.out.println("Accepeted Orders:-");for(FlipkartOrder order: acceptedOrderList){resB.append(order.getOrderId()+" "+ order.getFlipkartOrderId()+"\n");System.out.println(order.getOrderId()+" "+ order.getFlipkartOrderId());}resB.append("Cancelled Orders:-\n");System.out.println("Cancelled Orders:-");for(FlipkartOrder order: cancelledOrderList){resB.append(order.getOrderId()+" "+ order.getFlipkartOrderId()+"\n");System.out.println(order.getOrderId()+" "+ order.getFlipkartOrderId());}resB.append("Response not found Orders:-\n");System.out.println("Response not found Orders:-");for(FlipkartOrder order: errorOrderList){resB.append(order.getOrderId()+" "+ order.getFlipkartOrderId()+"\n");System.out.println(order.getOrderId()+" "+ order.getFlipkartOrderId());}String emailSubjectTxt = " Flipkart Hold Order Reconcilaition Process "+sdf.format(cal.getTime());mailer.sendSSLMessage(sendTo, emailSubjectTxt, resB.toString(), emailFromAddress, password, new ArrayList<File>());System.out.println(sb.toString());bufferedWriter.write(StringUtils.join(new String[] {"FlipkartHoldUpdationDate",sdf.format(new Date())}, '\t'));bufferedWriter.close();} catch (Exception e) {e.printStackTrace();try{mailer.sendSSLMessage(sendTo, "Error in Hold Order Recon Process", "Please inform Engineering Team", emailFromAddress, password, new ArrayList<File>());}catch (Exception e1) {e1.printStackTrace();}}}}