Commit 161933a8 authored by jiaorz's avatar jiaorz

Merge branch 'master-count-vehicle' into base-modify

parents 45d4fe50 56fae1fa
...@@ -362,23 +362,24 @@ public class VehicleCountRecordBiz extends BaseBiz<VehicleCountRecordMapper, Veh ...@@ -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(); ExcelExport ee1 = new ExcelExport();
ee1.addSheetByArray(excelParamDto.getName(), excelParamDto.getData(), excelParamDto.getHeader()); ee1.addSheetByArray(excelParamDto.getName(), excelParamDto.getData(), excelParamDto.getHeader());
String fileName = "/data/temp/"+ excelParamDto.getName() + ".xlsx"; String path = "/data/temp/"+ excelParamDto.getName() + ".xlsx";
OutputStream fis; OutputStream fis;
try { try {
fis = new FileOutputStream(fileName); fis = new FileOutputStream(path);
ee1.getWorkbook().write(fis); ee1.getWorkbook().write(fis);
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
e.printStackTrace(); e.printStackTrace();
return ObjectRestResponse.createFailedResult(1002, "文件不存在");
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
return ObjectRestResponse.createFailedResult(1002, "文件导出失败!");
} }
return fileName; return ObjectRestResponse.succ(path);
} }
public HttpServletResponse download(String path, HttpServletResponse response) {
public void download(String path, HttpServletResponse response) {
try { try {
// path是指欲下载的文件的路径。 // path是指欲下载的文件的路径。
File file = new File(path); File file = new File(path);
...@@ -386,7 +387,6 @@ public class VehicleCountRecordBiz extends BaseBiz<VehicleCountRecordMapper, Veh ...@@ -386,7 +387,6 @@ public class VehicleCountRecordBiz extends BaseBiz<VehicleCountRecordMapper, Veh
String filename = file.getName(); String filename = file.getName();
// 取得文件的后缀名。 // 取得文件的后缀名。
String ext = filename.substring(filename.lastIndexOf(".") + 1).toUpperCase(); String ext = filename.substring(filename.lastIndexOf(".") + 1).toUpperCase();
// 以流的形式下载文件。 // 以流的形式下载文件。
InputStream fis = new BufferedInputStream(new FileInputStream(path)); InputStream fis = new BufferedInputStream(new FileInputStream(path));
byte[] buffer = new byte[fis.available()]; byte[] buffer = new byte[fis.available()];
...@@ -405,6 +405,7 @@ public class VehicleCountRecordBiz extends BaseBiz<VehicleCountRecordMapper, Veh ...@@ -405,6 +405,7 @@ public class VehicleCountRecordBiz extends BaseBiz<VehicleCountRecordMapper, Veh
} catch (IOException ex) { } catch (IOException ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
return response;
} }
......
...@@ -29,7 +29,7 @@ public class VehicleCountRecordController { ...@@ -29,7 +29,7 @@ public class VehicleCountRecordController {
@PostMapping("/app/unauth/export") @PostMapping("/app/unauth/export")
public ObjectRestResponse export(@RequestBody ExcelParamDto excelParamDto) { public ObjectRestResponse export(@RequestBody ExcelParamDto excelParamDto) {
return ObjectRestResponse.succ(vehicleCountRecordBiz.export(excelParamDto)); return vehicleCountRecordBiz.export(excelParamDto);
} }
@PostMapping("/app/unauth/download") @PostMapping("/app/unauth/download")
......
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