|
@@ -1,8 +1,8 @@
|
|
|
package com.persagy.dmp.rwd.edit.controller;
|
|
|
|
|
|
-import com.persagy.dmp.rwd.edit.model.DownloadModel;
|
|
|
import com.persagy.dmp.rwd.edit.service.DownloadService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
import org.apache.poi.ss.usermodel.Workbook;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -13,7 +13,9 @@ import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.BufferedInputStream;
|
|
|
import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
import java.io.OutputStream;
|
|
|
import java.net.URLEncoder;
|
|
|
|
|
@@ -27,35 +29,35 @@ public class DownloadController {
|
|
|
@Autowired
|
|
|
private DownloadService downloadService;
|
|
|
|
|
|
- @GetMapping("/download")
|
|
|
- private void download(@RequestParam String type, HttpServletResponse response) {
|
|
|
- DownloadModel result = downloadService.download(type);
|
|
|
- if ("workbook".equalsIgnoreCase(result.getType())) {
|
|
|
- String fileName = result.getName();
|
|
|
- downloadWorkbook(response, fileName, result.getWorkbook());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
+ @GetMapping("/download")
|
|
|
+ private void download(@RequestParam String type, HttpServletResponse response) throws Exception {
|
|
|
+
|
|
|
+ InputStream resourceAsStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("siatic/file/批量上传变更记录模板.xlsx");
|
|
|
+ String fileName = "批量上传变更记录模板.xlsx";
|
|
|
+ InputStream inputStream = new BufferedInputStream(resourceAsStream);
|
|
|
+ @SuppressWarnings("resource")
|
|
|
+ HSSFWorkbook workbook = new HSSFWorkbook(inputStream);
|
|
|
+
|
|
|
+ fileName = new String(fileName.getBytes("UTF-8"), "ISO-8859-1");
|
|
|
+ response.setHeader("Content-disposition", "attachment; filename=" + fileName);
|
|
|
+ response.setContentType("application/vnd.ms-excel; charset=utf-8");
|
|
|
+ response.setCharacterEncoding("UTF-8");
|
|
|
+
|
|
|
+ OutputStream outputStream = response.getOutputStream();
|
|
|
+ workbook.write(outputStream);
|
|
|
+ outputStream.flush();
|
|
|
+ outputStream.close();
|
|
|
+ }
|
|
|
+
|
|
|
private void downloadWorkbook(HttpServletResponse resp, String fileName, Workbook workbook) {
|
|
|
OutputStream out = null;
|
|
|
try {
|