|
|
@@ -41,6 +41,7 @@ import java.io.File;
|
|
|
import java.io.FileInputStream;
|
|
|
import java.io.InputStream;
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.net.URLEncoder;
|
|
|
import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
@@ -167,7 +168,7 @@ public class WeatherController {
|
|
|
@PostMapping(value = "/downloadWeatherExcel")
|
|
|
@ApiOperationSupport(order = 13)
|
|
|
@ApiOperation(value = "客户端-下载天气台账excel模板")
|
|
|
- public ResponseEntity<Resource> downloadWeatherExcel(
|
|
|
+ public void downloadWeatherExcel(
|
|
|
@RequestParam String contractId,
|
|
|
@RequestParam String startTime,
|
|
|
@RequestParam String endTime,
|
|
|
@@ -212,17 +213,16 @@ public class WeatherController {
|
|
|
|
|
|
// 7. 写入字节流
|
|
|
workbook.write(outputStream);
|
|
|
- // 8. 构建字节数组资源
|
|
|
- ByteArrayResource resource = new ByteArrayResource(outputStream.toByteArray());
|
|
|
-
|
|
|
- // 9. 构建响应(解决中文文件名乱码问题)
|
|
|
- String fileName = new String("天气台账.xlsx".getBytes("UTF-8"), "ISO-8859-1");
|
|
|
-
|
|
|
- return ResponseEntity.ok()
|
|
|
- .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + fileName)
|
|
|
- .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_OCTET_STREAM_VALUE)
|
|
|
- .contentLength(resource.contentLength())
|
|
|
- .body(resource);
|
|
|
+ // 8. 设置响应头(核心)
|
|
|
+ String fileName = "天气台账.xlsx";
|
|
|
+ response.setCharacterEncoding("UTF-8");
|
|
|
+ response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
|
+ String encodedFileName = URLEncoder.encode(fileName, "UTF-8").replace("+", "%20");
|
|
|
+ response.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + encodedFileName);
|
|
|
+ // 9. 写入响应流
|
|
|
+ response.setContentLength(outputStream.size());
|
|
|
+ outputStream.writeTo(response.getOutputStream());
|
|
|
+ response.flushBuffer();
|
|
|
}
|
|
|
}
|
|
|
|