tomatozq 5 anni fa
parent
commit
cb547044d5

+ 16 - 1
src/main/java/com/jpsoft/smart/modules/base/controller/EmployeeInfoController.java

@@ -1,5 +1,6 @@
 package com.jpsoft.smart.modules.base.controller;
 
+import cn.hutool.core.date.DateTime;
 import com.github.pagehelper.Page;
 import com.jpsoft.smart.config.OSSConfig;
 import com.jpsoft.smart.modules.base.dto.EmployeeInfoDTO;
@@ -353,6 +354,11 @@ public class EmployeeInfoController {
 
             List<EmployeeInfo> employeeInfos = employeeInfoService.findByArray(ids.split(","));
 
+            String tmpdir = System.getProperty("java.io.tmpdir");
+            String tmpFilePath = tmpdir + File.separator + DateTime.now().toString("yyyyMMhddHHmmssSSS") + ".csv";
+
+            File tmpFile = new File(tmpFilePath);
+
             if(employeeInfos.size()>0) {
                 for (EmployeeInfo employeeInfo : employeeInfos) {
                     csvBuilder.append(employeeInfo.getId() + ",");
@@ -363,8 +369,13 @@ public class EmployeeInfoController {
                     csvBuilder.append(localPath + "\\照片\\" + employeeInfo.getId() + photoExt + "\r\n");
                 }
 
+                FileOutputStream fileOutput = new FileOutputStream(tmpFile);
+                byte[] data = csvBuilder.toString().getBytes("UTF-8");
+                fileOutput.write(data,0,data.length);
+                fileOutput.close();
+
                 Map<String, Object> fileMap = new HashMap<>();
-                fileMap.put("fileData", csvBuilder.toString().getBytes("UTF-8"));
+                fileMap.put("localPath", tmpFilePath);
                 fileMap.put("fileName", "人员名单.csv");
 
                 fileList.add(fileMap);
@@ -390,6 +401,10 @@ public class EmployeeInfoController {
 
             OSSUtil.batchDownload(fileList,output);
 
+            if(tmpFile.exists()){
+                tmpFile.delete();
+            }
+
             output.flush();
             output.close();
         }

+ 12 - 3
src/main/java/com/jpsoft/smart/modules/common/utils/OSSUtil.java

@@ -146,12 +146,21 @@ public class OSSUtil {
                             bis.close();
                         }
                     }
-                    else if(map.containsKey("fileData")){
+                    else if(map.containsKey("localPath")){
                         ZipEntry zipEntry = new ZipEntry(zipFile);
                         zos.putNextEntry(zipEntry);
 
-                        byte[] fileData = (byte[])map.get("fileData");
-                        zos.write(fileData,0,fileData.length);
+                        String localPath = (String)map.get("localPath");
+                        byte[] buffs = new byte[1024 * 10];
+
+                        InputStream bis = new BufferedInputStream(new FileInputStream(localPath));
+
+                        int read;
+                        while ((read = bis.read(buffs, 0, 1024 * 10)) != -1) {
+                            zos.write(buffs, 0, read);
+                        }
+
+                        bis.close();
                     }
                 }
                 catch(Exception ex){