Browse Source

现场部署一系列适配提交

wanger 1 month ago
parent
commit
c841a473a3

+ 9 - 4
onemap-modules/onemap-apply/src/main/java/com/onemap/apply/controller/sbjk/XzczghcgsbController.java

@@ -5,6 +5,7 @@ import com.onemap.apply.domain.cggl.CgscDto;
 import com.onemap.apply.domain.sbjk.TjpgsbDTO;
 import com.onemap.apply.domain.sbjk.XzczghcgsbDTO;
 import com.onemap.apply.service.sbjk.XzczghcgsbService;
+import com.onemap.apply.utils.ZipDownload;
 import com.onemap.common.core.utils.StringUtils;
 import com.onemap.common.core.utils.file.FileUtils;
 import com.onemap.common.core.web.controller.BaseController;
@@ -141,13 +142,17 @@ public class XzczghcgsbController extends BaseController {
 
             if (xzczghcgsbDTO != null) {
                 File file = new File(xzczghcgsbDTO.getFilePath());
-                if (!file.exists())
+                if (!file.exists()) {
                     throw new Exception();
+                }
                 // 下载名称
                 String downloadName = file.getName();
-                response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
-                FileUtils.setAttachmentResponseHeader(response, downloadName);
-                FileUtils.writeBytes(xzczghcgsbDTO.getFilePath(), response.getOutputStream());
+                ZipDownload.download(response, xzczghcgsbDTO.getFilePath(), downloadName);
+                // 下载名称
+//                String downloadName = file.getName();
+//                response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
+//                FileUtils.setAttachmentResponseHeader(response, downloadName);
+//                FileUtils.writeBytes(xzczghcgsbDTO.getFilePath(), response.getOutputStream());
             } else {
                 response.getWriter().println("没有找到结果文件");
             }

+ 6 - 2
onemap-modules/onemap-apply/src/main/java/com/onemap/apply/utils/ZipDownload.java

@@ -20,10 +20,14 @@ public class ZipDownload {
      */
     public static void download(HttpServletResponse response, String filepath, String name) {
         try {
-            response.setHeader("Content-Disposition", "attachment;filename=" + new String(name.getBytes("UTF-8"), "ISO-8859-1"));  // 需要编z码否则中文乱码
+            File file = new File(filepath);
+            String downloadName = file.getName();
+            downloadName = downloadName.toLowerCase().replace(".txt", ".zip");
+            response.setHeader("Content-Disposition", "attachment;filename=" + new String(downloadName.getBytes("UTF-8"), "ISO-8859-1"));  // 需要编z码否则中文乱码
+//            response.setHeader("Content-Disposition", "attachment;filename=" + downloadName);  // 需要编z码否则中文乱码
             response.setContentType("application/zip;charset=utf-8");
+            System.out.println("download-------" + downloadName);
             response.setCharacterEncoding("UTF-8");
-            File file = new File(filepath);
             if (file.length() >= Integer.MAX_VALUE) {
                 MappedBiggerFileReader reader = new MappedBiggerFileReader(filepath, 65536, response.getOutputStream());
                 while (reader.read() != -1) {