qin 1 year ago
parent
commit
ddd676e620

+ 14 - 2
src/main/java/com/poteviohealth/cgp/statistics/utils/ExcelUtils2.java

@@ -17,6 +17,7 @@ import org.springframework.stereotype.Component;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpServletResponse;
+import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -71,9 +72,10 @@ public class ExcelUtils2 implements ResourceLoaderAware {
             long t5 = System.currentTimeMillis();
             excelWriter.finish();
             outputStream.flush();
-            logger.info("size==="+is.available());
+            logger.info("size==="+resp.getBufferSize());
+            logger.info("getExportFileSize==="+getExportFileSize(template,list));
             logger.info("excelWriter time:" + (t5- t4));
-        } catch (IOException e) {
+        } catch (Exception e) {
             e.printStackTrace();
             throw new RuntimeException(e);
         } finally {
@@ -86,6 +88,16 @@ public class ExcelUtils2 implements ResourceLoaderAware {
         logger.info("export time:" + (System.currentTimeMillis() - begin));
     }
 
+    private static long getExportFileSize( Resource template,List<?> list) throws Exception{
+        InputStream is = template.getInputStream();
+        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+        ExcelWriter excelWriter = EasyExcel.write(byteArrayOutputStream).withTemplate(is).build();
+        WriteSheet writeSheet = EasyExcel.writerSheet().build();
+        excelWriter.write(list,writeSheet);
+        excelWriter.finish();
+        return byteArrayOutputStream.size();
+    }
+
     /**
      * 实体模型导出
      * @param response 响应类