Commit fb2239d6 authored by jiaorz's avatar jiaorz

车辆统计导出bug

parent 56fae1fa
......@@ -366,20 +366,30 @@ public class VehicleCountRecordBiz extends BaseBiz<VehicleCountRecordMapper, Veh
ExcelExport ee1 = new ExcelExport();
ee1.addSheetByArray(excelParamDto.getName(), excelParamDto.getData(), excelParamDto.getHeader());
String path = "/data/temp/"+ excelParamDto.getName() + ".xlsx";
File file = new File(path);
if (!file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
return ObjectRestResponse.createFailedResult(1024, "文件写入失败!");
}
}
OutputStream fis;
try {
fis = new FileOutputStream(path);
ee1.getWorkbook().write(fis);
} catch (FileNotFoundException e) {
e.printStackTrace();
return ObjectRestResponse.createFailedResult(1002, "文件不存在");
return ObjectRestResponse.createFailedResult(1024, "文件不存在!");
} catch (IOException e) {
e.printStackTrace();
return ObjectRestResponse.createFailedResult(1002, "文件导出失败!");
return ObjectRestResponse.createFailedResult(1024, "文件写入失败!");
}
return ObjectRestResponse.succ(path);
}
public HttpServletResponse download(String path, HttpServletResponse response) {
public void download(String path, HttpServletResponse response) {
try {
// path是指欲下载的文件的路径。
File file = new File(path);
......@@ -387,6 +397,7 @@ public class VehicleCountRecordBiz extends BaseBiz<VehicleCountRecordMapper, Veh
String filename = file.getName();
// 取得文件的后缀名。
String ext = filename.substring(filename.lastIndexOf(".") + 1).toUpperCase();
// 以流的形式下载文件。
InputStream fis = new BufferedInputStream(new FileInputStream(path));
byte[] buffer = new byte[fis.available()];
......@@ -405,7 +416,6 @@ public class VehicleCountRecordBiz extends BaseBiz<VehicleCountRecordMapper, Veh
} catch (IOException ex) {
ex.printStackTrace();
}
return response;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment