Commit 56fae1fa authored by jiaorz's avatar jiaorz

车辆统计导出bug

parent 782a04d9
......@@ -362,23 +362,24 @@ public class VehicleCountRecordBiz extends BaseBiz<VehicleCountRecordMapper, Veh
}
}
public String export(ExcelParamDto excelParamDto) {
public ObjectRestResponse export(ExcelParamDto excelParamDto) {
ExcelExport ee1 = new ExcelExport();
ee1.addSheetByArray(excelParamDto.getName(), excelParamDto.getData(), excelParamDto.getHeader());
String fileName = "/data/temp/"+ excelParamDto.getName() + ".xlsx";
String path = "/data/temp/"+ excelParamDto.getName() + ".xlsx";
OutputStream fis;
try {
fis = new FileOutputStream(fileName);
fis = new FileOutputStream(path);
ee1.getWorkbook().write(fis);
} catch (FileNotFoundException e) {
e.printStackTrace();
return ObjectRestResponse.createFailedResult(1002, "文件不存在");
} catch (IOException e) {
e.printStackTrace();
return ObjectRestResponse.createFailedResult(1002, "文件导出失败!");
}
return fileName;
return ObjectRestResponse.succ(path);
}
public void download(String path, HttpServletResponse response) {
public HttpServletResponse download(String path, HttpServletResponse response) {
try {
// path是指欲下载的文件的路径。
File file = new File(path);
......@@ -386,7 +387,6 @@ 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,6 +405,7 @@ public class VehicleCountRecordBiz extends BaseBiz<VehicleCountRecordMapper, Veh
} catch (IOException ex) {
ex.printStackTrace();
}
return response;
}
......
......@@ -29,11 +29,11 @@ public class VehicleCountRecordController {
@PostMapping("/app/unauth/export")
public ObjectRestResponse export(@RequestBody ExcelParamDto excelParamDto) {
return ObjectRestResponse.succ(vehicleCountRecordBiz.export(excelParamDto));
return vehicleCountRecordBiz.export(excelParamDto);
}
@PostMapping("/app/unauth/download")
public ObjectRestResponse download(String path, HttpServletResponse response) {
public ObjectRestResponse download(@RequestBody String path, HttpServletResponse response) {
vehicleCountRecordBiz.download(path, response);
return ObjectRestResponse.succ();
}
......
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