package com.youotech.tl_cons_credit_rating;

/*
* @Title:TestZScore
* @Description:tl_cons_credit_rating com.youotech.tl_cons_credit_rating
* @Author:gigi gao
* @Version: v1.0
* @CreateDate:2020/5/12 13:35
* @Copyright © 2019-2020
*/

import com.alibaba.fastjson.JSONObject;
import org.apache.http.HttpEntity;
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.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;

import java.util.ArrayList;
import java.util.List;

public class TestZScore {

public static void main(String[] args) {
// String filePath = "D:\\一户一策6月明细.xlsx";
// InputStream fis = null;
// try {
// fis = new FileInputStream(filePath);
// Workbook workbook = null;
// if (filePath.endsWith(".xlsx")) {
// workbook = new XSSFWorkbook(fis);
// } else if (filePath.endsWith(".xls") || filePath.endsWith(".et")) {
// workbook = new HSSFWorkbook(fis);
// }
// fis.close();
// /* 读EXCEL文字内容 */
// // 获取第一个sheet表,也可使用sheet表名获取
// Sheet sheet = workbook.getSheetAt(0);
// // 获取行
// Iterator<Row> rows = sheet.rowIterator();
// Row row;
// Cell cell;
//
// DateFormat df = new DateFormat();
//
// List<C_CONS_One_Cons_One_Policy> list = new ArrayList<>();
// int j = 0;
//
// while (rows.hasNext()) {
// row = rows.next();
// j++;
// if (j == 1) {
// continue;
// }
// // 获取单元格
// Iterator<Cell> cells = row.cellIterator();
// C_CONS_One_Cons_One_Policy obj = new C_CONS_One_Cons_One_Policy();
// int i = 0;
// while (cells.hasNext()) {
// i++;
// cell = cells.next();
// String cellValue = POIUtil.getCellValue(cell);
// // System.out.print(cellValue + "******");
// if (i == 1) {
// obj.setORGNO(cellValue);
// }
// if (i == 2) {
// obj.setCONSNO(cellValue);
// }
// if (i == 3) {
// obj.setCONSNAME(cellValue);
// }
// if (i == 4) {
// obj.setRISK_DESC(cellValue);
// }
// if (i == 5) {
// obj.setRISK_LEVEL(cellValue);
// }
// if (i == 6) {
// obj.setCHANGE_DESC(cellValue);
// }
// if (i == 7) {
// obj.setFEE_PERSON(cellValue);
// }
// if (i == 8) {
// obj.setMONTHLY_AVG_FEE(Double.parseDouble(cellValue));
// }
// if (i == 9) {
// obj.setONE_CONS_ONE_POLICY_PLAN(cellValue);
// }
// }
// list.add(obj);
// }
// System.out.println("******************" + list.size() + "******************");
// c_cons_one_cons_one_policyService.insertBatch(list);
// } catch (FileNotFoundException e) {
// e.printStackTrace();
// } catch (IOException e) {
// e.printStackTrace();
// } finally {
// if (null != fis) {
// try {
// fis.close();
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
// }

try {
HttpClient client = new DefaultHttpClient(); //构建一个Client
HttpPost post = new HttpPost("http://119.23.59.186:18889/api/Account/Login"); //构建一个POST请求
// 构建表单参数

List<NameValuePair> formParams = new ArrayList<NameValuePair>();
formParams.add(new BasicNameValuePair("UserID", "******"));
formParams.add(new BasicNameValuePair("Password", "123456"));
formParams.add(new BasicNameValuePair("client", "0"));
formParams.add(new BasicNameValuePair("Language", "cn"));
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formParams, "UTF-8");//将表单参数转化为“实体”
post.setEntity(entity); //将“实体“设置到POST请求里

HttpResponse response = client.execute(post);//提交POST请求
HttpEntity result = response.getEntity();//拿到返回的HttpResponse的"实体"
String content = EntityUtils.toString(result);
//用httpcore.jar提供的工具类将"实体"转化为字符串打印到控制台
System.out.println("************************************开始************************************");
System.out.println(content);
String jsonObject = content.replace("\\", "").substring(1);
jsonObject = jsonObject.substring(0, jsonObject.length() - 1);
JSONObject jsonObject2 = JSONObject.parseObject(jsonObject);
JsonRootBean mm = JSONObject.toJavaObject(jsonObject2, JsonRootBean.class);

System.out.println("************************************结束************************************");

HttpPost post2 = new HttpPost("http://ip:port/api/Monitor/ChartYGDL");
post2.setHeader("Authorization", "Bearer " + mm.getToken());
post2.setHeader("Token", mm.getToken());

List<NameValuePair> formParams2 = new ArrayList<NameValuePair>();
formParams2.add(new BasicNameValuePair("PrivAddr", "%2FEnergy%2Fygdl.html"));
formParams2.add(new BasicNameValuePair("ammeterID", ""));
formParams2.add(new BasicNameValuePair("areaID", "0"));
formParams2.add(new BasicNameValuePair("dateType", "mi15"));
formParams2.add(new BasicNameValuePair("endTime", "2020-08-20 00:00"));
formParams2.add(new BasicNameValuePair("endTime2", ""));
formParams2.add(new BasicNameValuePair("isCompare", "false"));
formParams2.add(new BasicNameValuePair("startTime", "2020-08-19 00:00"));
formParams2.add(new BasicNameValuePair("startTime2", ""));
formParams2.add(new BasicNameValuePair("valueType", "SJZ"));
UrlEncodedFormEntity entity2 = new UrlEncodedFormEntity(formParams2, "UTF-8");//将表单参数转化为“实体”
post2.setEntity(entity2); //将“实体“设置到POST请求里
HttpResponse response2 = client.execute(post2);//提交POST请求
HttpEntity result2 = response2.getEntity();//拿到返回的HttpResponse的"实体"
String content2 = EntityUtils.toString(result2);
//用httpcore.jar提供的工具类将"实体"转化为字符串打印
content2 = content2.replace("\\", "").substring(1);
content2 = content2.substring(0, content2.length() - 1);
System.out.println(content2);
} catch (Exception e) {
e.printStackTrace();
}
}
}