fix(解析器): 表头行整行格式污染时列范围按「非空表头」收缩

用户 Excel 表头行被整行格式化(整行实例化成 16384 个空单元格)时,货源/外观专利/集采
三处解析器按最大单元格列号展开列范围,每行数据被填充 1.6 万个占位空值,142KB 的 xlsx
生成 2.3GB 载荷,建任务 500(2026-09-26 生产事故:货源没跑出来.xlsx)。

- SimilarAsinExcelParser / AppearancePatentExcelParser / CollectDataService:列范围改为
  只统计非空表头的最大列号,尾部空列不再生成占位列(中间空列占位行为保持不变)
- 新增三处回归测试 + 事故样本(原样 + 集采关键词变体)
This commit is contained in:
2026-09-26 20:43:52 +08:00
parent 17ee7d293d
commit b9ed336510
8 changed files with 132 additions and 5 deletions
@@ -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);