// 导出接口,数据量太大无法一下子导出,所以分批导出
@Test
public void exportData() throws Exception{
String time1 = "2019-04-01 00:00:00|2019-04-05 00:00:00";
long time_now = System.currentTimeMillis();
// long time_now = 1530374400000L;
long time_2017 = 1483200000;
long day10 = 864000000;
// long day10 = 432000000;
long end = time_now;
long begin = end - day10;
while (true){
if (end/1000 < time_2017){
break;
}
String time = strToDateLong(begin) + "|" + strToDateLong(end);
String url = "http://xxxxx?createtime=custom&time=" + time + "&type=1&version=1&todo=export";
byte[] resualt = given().log().all()
.cookie("backend", "xxx")
.get(url).asByteArray()
;
String name = "xxx-免费版"+strToDate(begin) + "到" + strToDate(end) +".xls";
String file_name = "E:\\java\\vb\\ee\\" + name;
File file = new File(file_name);
FileOutputStream outputStream = new FileOutputStream(file);
outputStream.write(resualt);
outputStream.close();
end = begin;
begin = begin - day10;
}
}
public static String strToDateLong(long strDate) {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String date = df.format(strDate);
return date;
}
public static String strToDate(long strDate) {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
String date = df.format(strDate);
return date;
}