From 5b41c8896ef7850be2672e45b69bb58e149729ec Mon Sep 17 00:00:00 2001
From: xyc <jc_xiong@hotmail.com>
Date: 星期二, 01 十二月 2026 09:03:48 +0800
Subject: [PATCH] feat(货运统计): 完善台账核查与轨迹里程管理功能
---
traffic-audit-server/src/main/java/com/trafficaudit/reportexport/service/ReportExportService.java | 38 +++++++++++++++++++++++++++++++++++---
1 files changed, 35 insertions(+), 3 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 2cbeaf0..9c81f65 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
@@ -42,6 +42,7 @@
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.CellType;
+import org.apache.poi.ss.usermodel.DataFormat;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.IndexedColors;
@@ -5607,6 +5608,34 @@
return last == 0.0 ? 0.0 : (cur - last) / last;
}
+ /** Force a data format while preserving all other cell style attributes. */
+ static int smSetPercentFormat(Sheet sh, int firstRow0, int lastRow0, int col0, String format) {
+ if (sh == null || format == null || format.trim().isEmpty()) return 0;
+ DataFormat dataFormat = sh.getWorkbook().createDataFormat();
+ short formatIndex = dataFormat.getFormat(format);
+ Map<Short, CellStyle> convertedStyles = new HashMap<>();
+ int changed = 0;
+ for (int r = firstRow0; r <= lastRow0; r++) {
+ Row row = sh.getRow(r);
+ if (row == null) continue;
+ Cell cell = row.getCell(col0);
+ if (cell == null) continue;
+ CellStyle current = cell.getCellStyle();
+ if (current != null && format.equals(current.getDataFormatString())) continue;
+ short sourceStyle = current == null ? -1 : current.getIndex();
+ CellStyle converted = convertedStyles.get(sourceStyle);
+ if (converted == null) {
+ converted = sh.getWorkbook().createCellStyle();
+ if (current != null) converted.cloneStyleFrom(current);
+ converted.setDataFormat(formatIndex);
+ convertedStyles.put(sourceStyle, converted);
+ }
+ cell.setCellStyle(converted);
+ changed++;
+ }
+ return changed;
+ }
+
/** 鍐欏�硷細鍏紡鏍间笉鍔紙淇濈暀姣嶇増鍏紡锛屾墦寮�鍗抽噸绠楋級锛�0 涓斿師涓虹┖鏍煎垯涓嶆柊澧� */
private int smSetVal(Sheet sh, int r0, int c0, double v) {
Row row = sh.getRow(r0);
@@ -5688,7 +5717,7 @@
}
/** 鍩庡競鍒嗗競宸為〉锛�4 鍧楋紙绱瀹㈣繍閲�/绱鍛ㄨ浆閲�/褰撴湀瀹㈣繍閲�/褰撴湀鍛ㄨ浆閲忥級锛屾瘡鍧� 鍏ㄧ渷 1 琛� + 17 甯傚窞 */
- private int smWriteCityByRegion(XSSFWorkbook wb, int month,
+ int smWriteCityByRegion(XSSFWorkbook wb, int month,
Map<String, double[]> curCum, Map<String, double[]> lastCum,
Map<String, double[]> curMon, Map<String, double[]> lastMon) {
Sheet sh = wb.getSheet("鍩庡競鍒嗗競宸�");
@@ -5700,8 +5729,8 @@
int n = 0;
n += smWriteCityByRegionBlock(sh, 4, true, curCum, lastCum);
n += smWriteCityByRegionBlock(sh, 26, false, curCum, lastCum);
- n += smWriteCityByRegionBlock(sh, 49, true, curMon, lastMon);
- n += smWriteCityByRegionBlock(sh, 71, false, curMon, lastMon);
+ n += smWriteCityByRegionBlock(sh, 48, true, curMon, lastMon);
+ n += smWriteCityByRegionBlock(sh, 70, false, curMon, lastMon);
return n;
}
@@ -5773,6 +5802,9 @@
n += smSetVal(sh, rows[i] + 9, 5, v[1]);
n += smSetVal(sh, rows[i] + 9, 6, v[3]);
}
+ // Older templates may retain an integer format on the monthly turnover YoY cells.
+ // Enforce the format here so generated workbooks remain correct even when the expansion source is stale.
+ smSetPercentFormat(sh, 11, 15, 6, "0.00%");
return n;
}
--
Gitblit v1.9.1