From 8b7610369a3faf90143ae31b60d5a0058bd8e8d2 Mon Sep 17 00:00:00 2001
From: zhizhijie <zhizhijie@users.noreply.gitee.com>
Date: 星期二, 08 九月 2026 14:51:01 +0800
Subject: [PATCH] feat: 汇总大表版式统一——数值0.00/排名整数/列宽自适应/去底色(7月8月母版+还原源+applyDonorNumberFormat)

---
 traffic-audit-server/src/main/java/com/trafficaudit/reportexport/service/ReportExportService.java |   27 +++++++++++++++++++++++++++
 1 files changed, 27 insertions(+), 0 deletions(-)

diff --git a/traffic-audit-server/src/main/java/com/trafficaudit/reportexport/service/ReportExportService.java b/traffic-audit-server/src/main/java/com/trafficaudit/reportexport/service/ReportExportService.java
index 9fdb6f2..dce943c 100644
--- a/traffic-audit-server/src/main/java/com/trafficaudit/reportexport/service/ReportExportService.java
+++ b/traffic-audit-server/src/main/java/com/trafficaudit/reportexport/service/ReportExportService.java
@@ -44,6 +44,7 @@
 import org.apache.poi.hssf.usermodel.HSSFSheet;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.ss.util.CellRangeAddress;
+import org.apache.poi.openxml4j.util.ZipSecureFile;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.STCellType;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
@@ -3213,6 +3214,8 @@
         if (template == null) {
             throw new RuntimeException("鏈壘鍒版眹鎬昏〃姣嶇増銆�" + year + "骞�" + month + "鏈堥亾璺繍杈撻噺姹囨�昏〃.xlsx銆嬶紙docs/鐢熸垚姹囨�诲ぇ琛級");
         }
+        double savedZipRatio = ZipSecureFile.getMinInflateRatio();
+        ZipSecureFile.setMinInflateRatio(0.0001); // 鏂扮増姣嶇増 styles.xml 鐢� openpyxl 楂樺帇缂╋紙0.0099<0.01锛夎Е鍙� POI Zip-bomb 璇姤锛岃鍙栧悗杩樺師
         try (InputStream in = new FileInputStream(template);
              XSSFWorkbook wb = new XSSFWorkbook(in)) {
             File donor = resolveSummaryDonor(year, month);
@@ -3233,6 +3236,8 @@
             if (!wb.getCTWorkbook().isSetCalcPr()) wb.getCTWorkbook().addNewCalcPr();
             wb.getCTWorkbook().getCalcPr().setFullCalcOnLoad(true); // 杩樺師/鏀瑰啓鍏紡鍚庢墦寮�鍗抽噸绠�
             return toBytes(wb);
+        } finally {
+            ZipSecureFile.setMinInflateRatio(savedZipRatio);
         }
     }
 
@@ -3526,12 +3531,15 @@
             if (ds == null) continue;
             Sheet bs = wb.getSheet(ds.getSheetName());
             if (bs == null) continue;
+            // 涓彛寰勬帓鍚嶉〉 A..H 闄堟棫宸﹀潡宸蹭簬 2026-09-09 鎷嶆澘鏁村潡鍒犻櫎锛氳鍖哄煙姘镐笉浠庡浠芥瘝鐗堝洖濉紝閬垮厤鈥滅敓鎴愬張澶嶆椿鈥�
+            boolean skipMidRankLeftBlock = "涓彛寰勬帓鍚�".equals(ds.getSheetName());
             for (int r = ds.getFirstRowNum(); r <= ds.getLastRowNum(); r++) {
                 Row dr = ds.getRow(r);
                 if (dr == null) continue;
                 Row br = bs.getRow(r);
                 for (Cell dc : dr) {
                     if (dc == null) continue;
+                    if (skipMidRankLeftBlock && dc.getColumnIndex() < 8) continue;
                     CellType t = dc.getCellType();
                     if (t == CellType.BLANK) continue;
                     String dtx = summaryCellText(dc);
@@ -3543,6 +3551,7 @@
                     Cell tc = (bc != null) ? bc : tr.getCell(dc.getColumnIndex());
                     if (tc == null) tc = tr.createCell(dc.getColumnIndex());
                     tc.setBlank();
+                    applyDonorNumberFormat(wb, tc, dc);
                     if (t == CellType.FORMULA) {
                         String f = dc.getCellFormula();
                         if (f != null) tc.setCellFormula(f);
@@ -3560,6 +3569,24 @@
         return restored;
     }
 
+    /** 杩樺師鍥炲~鏃跺悓姝� donor锛堝凡鍋氱増寮忕粺涓�锛夌殑鏁板瓧鏍煎紡锛屼繚璇佸悓姣�/鏁板��/鎺掑悕鏍兼樉绀烘牸寮忎笌姣嶇増涓�鑷� */
+    private void applyDonorNumberFormat(XSSFWorkbook wb, Cell dst, Cell src) {
+        if (wb == null || dst == null || src == null) return;
+        try {
+            String fmt = src.getCellStyle().getDataFormatString();
+            if (fmt == null || fmt.isEmpty() || "General".equalsIgnoreCase(fmt)) return;
+            org.apache.poi.ss.usermodel.DataFormat df = wb.createDataFormat();
+            short idx = df.getFormat(fmt);
+            CellStyle cur = dst.getCellStyle();
+            if (cur != null && idx == cur.getDataFormat()) return;
+            CellStyle ns = wb.createCellStyle();
+            if (cur != null) ns.cloneStyleFrom(cur);
+            ns.setDataFormat(idx);
+            dst.setCellStyle(ns);
+        } catch (Exception ignore) {
+            // 涓埆鏍煎紡寮傚父涓嶉樆濉炶繕鍘�
+        }
+    }
     /** 鍗曞厓鏍煎唴瀹规枃鏈寲锛堝叕寮忓甫 = 鍓嶇紑锛夛紝鐢ㄤ簬璺ㄧ翱姣斿 */
     private String summaryCellText(Cell c) {
         if (c == null) return null;

--
Gitblit v1.9.1