Commit d1b17ea7 authored by jiaorz's avatar jiaorz

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

parents 8fd1d17c c8646562
...@@ -24,12 +24,11 @@ import org.joda.time.format.DateTimeFormat; ...@@ -24,12 +24,11 @@ import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter; import org.joda.time.format.DateTimeFormatter;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.io.FileNotFoundException; import javax.servlet.http.HttpServletResponse;
import java.io.FileOutputStream; import java.io.*;
import java.io.IOException;
import java.io.OutputStream;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
...@@ -87,6 +86,7 @@ public class VehicleCountRecordBiz extends BaseBiz<VehicleCountRecordMapper, Veh ...@@ -87,6 +86,7 @@ public class VehicleCountRecordBiz extends BaseBiz<VehicleCountRecordMapper, Veh
* *
* @return * @return
*/ */
@Scheduled(cron = "59 59 23 * * ?")
public void addAll() { public void addAll() {
Long nowTime = getDayStart(); Long nowTime = getDayStart();
Long lastTime = nowTime + 24 * 3600 * 1000 - 1; Long lastTime = nowTime + 24 * 3600 * 1000 - 1;
...@@ -362,14 +362,31 @@ public class VehicleCountRecordBiz extends BaseBiz<VehicleCountRecordMapper, Veh ...@@ -362,14 +362,31 @@ public class VehicleCountRecordBiz extends BaseBiz<VehicleCountRecordMapper, Veh
} }
} }
public void export(ExcelParamDto excelParamDto) { public void export(HttpServletResponse response, 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());
OutputStream fis; OutputStream fis;
try { try {
fis = new FileOutputStream("D:\\" + excelParamDto.getName() + ".xlsx"); fis = new FileOutputStream( "/data/temp/"+ excelParamDto.getName() + ".xlsx");
ee1.getWorkbook().write(fis); ee1.getWorkbook().write(fis);
// 下载本地文件
String fileName = excelParamDto.getName() + ".xlsx"; // 文件的默认保存名
// 读到流中
InputStream inStream = new FileInputStream("d:/" + fileName);// 文件的存放路径
// 设置输出的格式
response.reset();
response.setContentType("bin");
response.addHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
// 循环取出流中的数据
byte[] b = new byte[100];
int len;
try {
while ((len = inStream.read(b)) > 0)
response.getOutputStream().write(b, 0, len);
inStream.close();
} catch (IOException e) {
e.printStackTrace();
}
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
e.printStackTrace(); e.printStackTrace();
} catch (IOException e) { } catch (IOException e) {
......
...@@ -7,6 +7,8 @@ import com.xxfc.platform.vehicle.pojo.ExcelParamDto; ...@@ -7,6 +7,8 @@ import com.xxfc.platform.vehicle.pojo.ExcelParamDto;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
@RestController @RestController
@RequestMapping(value = "/vehicleCount") @RequestMapping(value = "/vehicleCount")
public class VehicleCountRecordController { public class VehicleCountRecordController {
...@@ -26,8 +28,8 @@ public class VehicleCountRecordController { ...@@ -26,8 +28,8 @@ public class VehicleCountRecordController {
} }
@PostMapping("/app/unauth/export") @PostMapping("/app/unauth/export")
public ObjectRestResponse export(@RequestBody ExcelParamDto excelParamDto) { public ObjectRestResponse export(HttpServletResponse response, @RequestBody ExcelParamDto excelParamDto) {
vehicleCountRecordBiz.export(excelParamDto); vehicleCountRecordBiz.export(response, excelParamDto);
return ObjectRestResponse.succ(); 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