From 89a0e7cd7ec202e57e6971e27559b85c3c971aaf Mon Sep 17 00:00:00 2001
From: zhizhijie <zhizhijie@users.noreply.gitee.com>
Date: 星期一, 12 十月 2026 16:00:43 +0800
Subject: [PATCH] docs(交接): 记录 9 月导入核验与出表抽查结果、仍缺数据清单
---
traffic-audit-server/src/main/java/com/trafficaudit/reportexport/layout/SummaryLayoutExpander.java | 52 ++++++++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 48 insertions(+), 4 deletions(-)
diff --git a/traffic-audit-server/src/main/java/com/trafficaudit/reportexport/layout/SummaryLayoutExpander.java b/traffic-audit-server/src/main/java/com/trafficaudit/reportexport/layout/SummaryLayoutExpander.java
index 2f98afa..6d3b317 100644
--- a/traffic-audit-server/src/main/java/com/trafficaudit/reportexport/layout/SummaryLayoutExpander.java
+++ b/traffic-audit-server/src/main/java/com/trafficaudit/reportexport/layout/SummaryLayoutExpander.java
@@ -3,6 +3,7 @@
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
+import org.apache.poi.ss.usermodel.FormulaEvaluator;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.util.CellRangeAddress;
@@ -80,6 +81,7 @@
if (sh == null || expanded.contains(sh.getSheetName())) continue;
shiftQualifiedRefs(sh, insertColOf);
}
+ recalcAndCache(wb);
int titleFixed = applyTitles(wb, year, targetMonth);
if (titleFixed > 0) {
log.info("鎵╁垪锛氭爣棰樻寜 {}骞磠}鏈� 閲嶅啓 {} 鏍�", year, targetMonth, titleFixed);
@@ -96,6 +98,7 @@
/** 鍙妸 7 涓爣棰橀〉鐨勬爣棰樻寜缁欏畾鏈熸閲嶅啓锛堢敤浜庝慨姝f瘝鐗堥噷婊炲悗鐨勬爣棰橈級銆� */
public byte[] fixTitles(byte[] source, int year, int month) {
try (XSSFWorkbook wb = new XSSFWorkbook(new ByteArrayInputStream(source))) {
+ recalcAndCache(wb);
int n = applyTitles(wb, year, month);
wb.setForceFormulaRecalculation(true);
ByteArrayOutputStream out = new ByteArrayOutputStream();
@@ -104,6 +107,17 @@
return out.toByteArray();
} catch (Exception e) {
throw new IllegalStateException("姹囨�诲ぇ琛ㄦ爣棰樹慨姝eけ璐�: " + e.getMessage(), e);
+ }
+ }
+
+ /** 鏁存湰閲嶇畻骞舵妸缁撴灉鍐欏叆缂撳瓨鍊硷細鍚﹀垯姣嶇増閲屽彧鏈夊叕寮忔病鏈夊�硷紝鍚庣画璇诲彇浼氭妸绌哄�煎綋 0锛�2026-10-12 淇級 */
+ private void recalcAndCache(XSSFWorkbook wb) {
+ try {
+ FormulaEvaluator ev = wb.getCreationHelper().createFormulaEvaluator();
+ ev.clearAllCachedResultValues();
+ ev.evaluateAll();
+ } catch (Exception e) {
+ log.warn("鎵╁垪锛氭暣鏈噸绠楁湭瀹屾垚锛堝叕寮忎粛鍦紝Excel 鎵撳紑浼氬啀绠楋級锛歿}", e.getMessage());
}
}
@@ -208,8 +222,8 @@
if (headerRows.contains(r)) continue;
Row row = sh.getRow(r);
if (row == null) continue;
- cloneDataCell(row, srcVal, insertCol, shiftable, insertCol);
- cloneDataCell(row, srcYoy, insertCol + 1, shiftable, insertCol);
+ cloneDataCell(row, srcVal, insertCol, shiftable);
+ cloneYoyCell(row, srcYoy, insertCol + 1, insertCol, lastYearSameMonth + 2);
}
// 5) 绱鍒楄ˉ褰撴湀椤癸紱绱鍚屾瘮鍒嗘瘝琛ュ幓骞村悓鏈堝垪
int cumCol = insertCol + 2, cumYoyCol = insertCol + 3;
@@ -348,17 +362,47 @@
}
}
- private void cloneDataCell(Row row, int srcCol, int dstCol, Set<String> shiftable, int insertCol) {
+ private void cloneDataCell(Row row, int srcCol, int dstCol, Set<String> shiftable) {
Cell s = row.getCell(srcCol);
if (s == null) return;
Cell d = getOrCreate(row, dstCol);
d.setBlank();
d.setCellStyle(s.getCellStyle());
if (s.getCellType() == CellType.FORMULA) {
- d.setCellFormula(shiftRefs(s.getCellFormula(), insertCol, shiftable));
+ d.setCellFormula(shiftRefsAll(s.getCellFormula(), shiftable));
}
}
+ /** 褰撴湀鍚屾瘮鍒楋細涓嶅厠闅嗕笂鏈堝叕寮忥紝鐩存帴鎸夈�屾湰鏈堝�� / 鍘诲勾鍚屾湀 鈭� 1銆嶉噸鍐欙紙鍘诲勾鍚屾湀鍒楀凡鎸夎〃澶村畾浣嶏級 */
+ private void cloneYoyCell(Row row, int srcCol, int dstCol, int valCol0, int denCol0) {
+ Cell s = row.getCell(srcCol);
+ if (s == null) return;
+ Cell d = getOrCreate(row, dstCol);
+ d.setBlank();
+ d.setCellStyle(s.getCellStyle());
+ if (s.getCellType() == CellType.FORMULA) {
+ int excelRow = row.getRowNum() + 1;
+ d.setCellFormula(colLetter(valCol0) + excelRow + "/" + colLetter(denCol0) + excelRow + "-1");
+ }
+ }
+
+ /** 鐩稿澶嶅埗鐢ㄧ殑骞崇Щ锛氭妸鏈〉/宸叉墿鍒楅〉鐨勫紩鐢ㄦ暣浣� +2锛堜笉鍋氬垪鍙烽槇鍊煎垽鏂級 */
+ private String shiftRefsAll(String formula, Set<String> shiftable) {
+ Matcher m = REF.matcher(formula);
+ StringBuffer sb = new StringBuffer();
+ while (m.find()) {
+ String sheet = m.group(2) != null ? m.group(2) : m.group(3);
+ if ((sheet != null && !shiftable.contains(sheet)) || isFunctionName(formula, m)) {
+ m.appendReplacement(sb, Matcher.quoteReplacement(m.group(0)));
+ continue;
+ }
+ int colIdx = colIndex(m.group(5));
+ m.appendReplacement(sb, Matcher.quoteReplacement(rebuild(m, sheet, colIdx + 2)));
+ }
+ m.appendTail(sb);
+ return sb.toString();
+ }
+
private void shiftAllRefs(Sheet sh, int insertCol, Set<String> shiftable) {
for (int r = 0; r <= sh.getLastRowNum(); r++) {
Row row = sh.getRow(r);
--
Gitblit v1.9.1