fix(解析器): 表头行整行格式污染时列范围按「非空表头」收缩
用户 Excel 表头行被整行格式化(整行实例化成 16384 个空单元格)时,货源/外观专利/集采 三处解析器按最大单元格列号展开列范围,每行数据被填充 1.6 万个占位空值,142KB 的 xlsx 生成 2.3GB 载荷,建任务 500(2026-09-26 生产事故:货源没跑出来.xlsx)。 - SimilarAsinExcelParser / AppearancePatentExcelParser / CollectDataService:列范围改为 只统计非空表头的最大列号,尾部空列不再生成占位列(中间空列占位行为保持不变) - 新增三处回归测试 + 事故样本(原样 + 集采关键词变体)
This commit is contained in:
+11
-2
@@ -190,13 +190,22 @@ public class AppearancePatentExcelParser {
|
||||
values));
|
||||
}
|
||||
|
||||
/**
|
||||
* 有效表头列数:只统计「非空表头」的最大列索引 + 1。表头行被整行格式污染时(整行被实例化成
|
||||
* 上万空单元格),若按最大单元格列号展开,每行 values 都会被填充上万条占位空值,解析结果与
|
||||
* 载荷膨胀上千倍(同源事故见 SimilarAsinExcelParser,2026-09-26)。
|
||||
*/
|
||||
private int lastColumnCount(Map<Integer, String> rowMap) {
|
||||
if (rowMap == null || rowMap.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
int lastColumnCount = 0;
|
||||
for (Integer columnIndex : rowMap.keySet()) {
|
||||
if (columnIndex != null && columnIndex >= lastColumnCount) {
|
||||
for (Map.Entry<Integer, String> entry : rowMap.entrySet()) {
|
||||
Integer columnIndex = entry.getKey();
|
||||
if (columnIndex == null || columnIndex < 0 || normalize(entry.getValue()).isBlank()) {
|
||||
continue;
|
||||
}
|
||||
if (columnIndex >= lastColumnCount) {
|
||||
lastColumnCount = columnIndex + 1;
|
||||
}
|
||||
}
|
||||
|
||||
+12
-2
@@ -1896,12 +1896,22 @@ public class CollectDataService {
|
||||
if (headerMap == null || headerMap.isEmpty()) {
|
||||
throw new BusinessException("Excel 表头为空");
|
||||
}
|
||||
// 列范围只按「非空表头」计算:表头行被整行格式污染时(整行被实例化成上万空单元格),
|
||||
// 若按最大单元格列号展开,每行 extra 都会被填充上万条占位空值,解析结果与载荷膨胀上千倍
|
||||
// (同源事故见 SimilarAsinExcelParser)。尾部空列不再生成占位列。
|
||||
int lastCol = -1;
|
||||
for (Integer col : headerMap.keySet()) {
|
||||
if (col != null && col > lastCol) {
|
||||
for (Map.Entry<Integer, String> entry : headerMap.entrySet()) {
|
||||
Integer col = entry.getKey();
|
||||
if (col == null || col < 0 || normalize(entry.getValue()).isBlank()) {
|
||||
continue;
|
||||
}
|
||||
if (col > lastCol) {
|
||||
lastCol = col;
|
||||
}
|
||||
}
|
||||
if (lastCol < 0) {
|
||||
throw new BusinessException("Excel 表头为空");
|
||||
}
|
||||
for (int i = 0; i <= lastCol; i++) {
|
||||
String value = normalize(headerMap.getOrDefault(i, ""));
|
||||
headers.add(value.isBlank() ? "列" + (i + 1) : value);
|
||||
|
||||
+14
-1
@@ -120,12 +120,25 @@ public class SimilarAsinExcelParser {
|
||||
// EasyExcel 回调给出 列号 → 表头文本,与 POI Row 遍历等价(缺列一般为 null/空串)
|
||||
Map<String, Integer> map = new LinkedHashMap<>();
|
||||
List<String> headerNames = new ArrayList<>();
|
||||
// 列范围只按「非空表头」计算:表头行被整行格式污染时(如 A1:XFD1 整行被实例化成
|
||||
// 16384 个空单元格,只有前几列有值),若按最大单元格列号展开,headers 会撑到 16384 列,
|
||||
// 每行数据都被填充上万条占位空值,payload 膨胀上千倍(2026-09-26 生产事故:142KB 的
|
||||
// xlsx 生成 2.3GB 载荷,建任务 500)。尾部空列不再生成占位列。
|
||||
int lastCol = -1;
|
||||
for (Map.Entry<Integer, String> e : headerMapRaw.entrySet()) {
|
||||
if (e.getKey() != null && e.getKey() > lastCol) {
|
||||
if (e.getKey() == null || e.getKey() < 0) {
|
||||
continue;
|
||||
}
|
||||
if (normalize(e.getValue()).isBlank()) {
|
||||
continue;
|
||||
}
|
||||
if (e.getKey() > lastCol) {
|
||||
lastCol = e.getKey();
|
||||
}
|
||||
}
|
||||
if (lastCol < 0) {
|
||||
throw new BusinessException("Excel 表头为空");
|
||||
}
|
||||
for (int i = 0; i <= lastCol; i++) {
|
||||
String val = normalize(headerMapRaw.getOrDefault(i, ""));
|
||||
headerNames.add(val.isBlank() ? "列" + (i + 1) : val);
|
||||
|
||||
Reference in New Issue
Block a user