1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
|
Connection conn = null;
Statement ss = null;
String dateStar11 = request.getParameter("Usermail");
String dateStar22 = request.getParameter("Password");
String url = "http://localhost:6968/withdraw/list/b005fd07f0";
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/lonaci_hub", "root", "jason");
ss = conn.createStatement();
PreparedStatement pst = conn.prepareStatement("Select * from code ORDER BY code DESC LIMIT 1");
ResultSet rs = pst.executeQuery();
if (rs.next()) {
Integer code = rs.getInt("code");
Date datee = new Date();
String DateJour = String.valueOf(datee);
SimpleDateFormat s = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy", Locale.US);
SimpleDateFormat ou = new SimpleDateFormat("ddMMyyyy");
SimpleDateFormat hh = new SimpleDateFormat("HHmmss");
Date d = s.parse(DateJour);
String formatJour = ou.format(d);
String formatHeure = hh.format(d);
// TODO Auto-generated method stub
System.out.println("************** doGet ************");
response.setContentType("text/csv; charset=UTF-8");
PrintWriter out = response.getWriter();
response.setDateHeader("Expires", 0);
StringBuffer fileNameFormat = new StringBuffer();
fileNameFormat.append("attachment; filename=Incription_vrac_employes_BulkPayee_" + formatJour + "_" + formatHeure);
fileNameFormat.append(".csv");
response.setHeader("Content-disposition", fileNameFormat.toString());
StringBuffer totalString = new StringBuffer();
StringBuffer header = new StringBuffer();
header.append("Mobile Number*");
header.append(";");
header.append("Unique Code*");
header.append(";");
header.append("User Type*");
StringBuffer body = new StringBuffer();
HttpClient client = HttpClientBuilder.create().build();
HttpPost post = new HttpPost(url);
//String USER_AGENT = "";
// add header
post.setHeader("User-Agent", "Mozilla/5.0");
List<NameValuePair> urlParameters = new ArrayList<NameValuePair>();
//urlParameters.add(new BasicNameValuePair("from", ""));
//urlParameters.add(new BasicNameValuePair("to", dateStar22));
urlParameters.add(new BasicNameValuePair("status", "pending"));
post.setEntity(new UrlEncodedFormEntity(urlParameters));
HttpResponse respons = client.execute(post);
System.out.println("Response Code : " + respons.getStatusLine().getStatusCode());
BufferedReader rd = new BufferedReader(new InputStreamReader(respons.getEntity().getContent()));
String resu = "";
StringBuffer result = new StringBuffer();
String line = "";
while ((line = rd.readLine()) != null) {
System.out.println(result.append(line));
resu += line;
}
rd.close();
String weatherResult = resu;
System.out.println(weatherResult);
// read the json file
JSONParser jsonParser = new JSONParser();
JSONArray array = (JSONArray) jsonParser.parse(weatherResult);
Iterator i = array.iterator();
int ii = code + 1;
while (i.hasNext()) {
JSONObject innerObj = (JSONObject) i.next();
System.out.println("transaction_id " + innerObj.get("transaction_id"));
String transaction_id = (String) innerObj.get("transaction_id");
System.out.println("number " + innerObj.get("number"));
String number = (String) innerObj.get("number");
System.out.println("cashout_account_number " + innerObj.get("cashout_account_number"));
String cashout_account_number = (String) innerObj.get("cashout_account_number");
System.out.println("created_at " + innerObj.get("created_at"));
String created_at = (String) innerObj.get("created_at");
System.out.println("paid_currency_id " + innerObj.get("paid_currency_id"));
Long paid_currency_id = (Long) innerObj.get("paid_currency_id");
System.out.println("transaction_amount " + innerObj.get("transaction_amount"));
Double transaction_amount = (Double) innerObj.get("transaction_amount");
System.out.println("fees " + innerObj.get("fees"));
Double fees = (Double) innerObj.get("fees");
System.out.println("payment_status " + innerObj.get("payment_status"));
Boolean payment_status = (Boolean) innerObj.get("payment_status");
System.out.println("transaction_type " + innerObj.get("transaction_type"));
Long transaction_type = (Long) innerObj.get("transaction_type");
if (transaction_type == 2 && cashout_account_number != null) {
String sql = ("INSERT INTO code (code, date) VALUES ('" + ii + "', NOW())");
ss.execute(sql);
body.append("\"\t"+cashout_account_number+"\""); // c'est ca que je veux formatter en text avant de mettre dans le fichier excel
body.append(";");
body.append(ii++);
body.append(";");
body.append("Subscriber");
body.append("\n");
}
}
totalString.append(header.toString());
totalString.append("\n");
totalString.append(body.toString());
out.write(totalString.toString());
}
} |
Partager