|
@@ -1,5 +1,6 @@
|
|
|
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.ss.usermodel.Workbook;
|
|
@@ -12,7 +13,8 @@ import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
-import java.io.*;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.OutputStream;
|
|
|
import java.net.URLEncoder;
|
|
|
|
|
|
@Slf4j
|
|
@@ -25,36 +27,35 @@ public class DownloadController {
|
|
|
@Autowired
|
|
|
private DownloadService downloadService;
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
@GetMapping("/download")
|
|
|
- private void download(@RequestParam String type, HttpServletResponse response) throws Exception {
|
|
|
-
|
|
|
- InputStream resourceAsStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("siatic/file/批量上传变更记录模板.xlsx");
|
|
|
- InputStream fis = new BufferedInputStream(resourceAsStream);
|
|
|
- byte[] buffer = new byte[fis.available()];
|
|
|
- fis.read(buffer);
|
|
|
- fis.close();
|
|
|
-
|
|
|
- response.reset();
|
|
|
-
|
|
|
- response.setHeader("Content-Disposition", "attachment;filename=" + java.net.URLEncoder.encode("批量导入标准模板.xls", "utf-8"));
|
|
|
-
|
|
|
- response.addHeader("Content-Length", "" + buffer.length);
|
|
|
- OutputStream toClient = new BufferedOutputStream(response.getOutputStream());
|
|
|
- response.setContentType("application/vnd.ms-excel; charset=utf-8");
|
|
|
- toClient.write(buffer);
|
|
|
- toClient.flush();
|
|
|
- toClient.close();
|
|
|
+ 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());
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
private void downloadWorkbook(HttpServletResponse resp, String fileName, Workbook workbook) {
|
|
|
OutputStream out = null;
|
|
|
try {
|
|
@@ -62,7 +63,7 @@ public class DownloadController {
|
|
|
String resultFileName = URLEncoder.encode(fileName, "UTF-8");
|
|
|
resp.setCharacterEncoding("UTF-8");
|
|
|
resp.setHeader("Content-disposition", "attachment; filename=" + resultFileName);
|
|
|
- resp.setContentType("application/msexcel");
|
|
|
+ resp.setContentType("application/vnd.ms-excel; charset=utf-8");
|
|
|
out = resp.getOutputStream();
|
|
|
workbook.write(out);
|
|
|
out.flush();
|