fix(解析器): 表头行整行格式污染时列范围按「非空表头」收缩
用户 Excel 表头行被整行格式化(整行实例化成 16384 个空单元格)时,货源/外观专利/集采 三处解析器按最大单元格列号展开列范围,每行数据被填充 1.6 万个占位空值,142KB 的 xlsx 生成 2.3GB 载荷,建任务 500(2026-09-26 生产事故:货源没跑出来.xlsx)。 - SimilarAsinExcelParser / AppearancePatentExcelParser / CollectDataService:列范围改为 只统计非空表头的最大列号,尾部空列不再生成占位列(中间空列占位行为保持不变) - 新增三处回归测试 + 事故样本(原样 + 集采关键词变体)
This commit is contained in:
+56
@@ -0,0 +1,56 @@
|
||||
package com.nanri.aiimage.modules.collectdata.service;
|
||||
|
||||
import com.nanri.aiimage.modules.collectdata.model.dto.CollectDataSourceFileDto;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
/**
|
||||
* 集采解析回归:表头行被整行格式污染时(行被实例化为 Excel 最大列数 16384 个空单元格,
|
||||
* 只有前 4 列有值),列范围必须收缩到最后一个非空表头,否则每行 extra 都被填充 1.6 万个
|
||||
* 占位空值,解析结果与载荷膨胀上千倍。样本来自 2026-09-26 生产事故(同源修复见
|
||||
* SimilarAsinExcelParser / AppearancePatentExcelParser)。
|
||||
*/
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class CollectDataHeaderPollutionTest {
|
||||
|
||||
@InjectMocks
|
||||
private CollectDataService service;
|
||||
|
||||
@Test
|
||||
void 表头行整行格式污染时行内不应出现上万占位列() throws Exception {
|
||||
URL url = getClass().getResource("/excel/header-row-format-pollution-keyword.xlsx");
|
||||
assertNotNull(url, "测试样本缺失");
|
||||
File file = new File(url.toURI());
|
||||
CollectDataSourceFileDto source = new CollectDataSourceFileDto();
|
||||
source.setFileKey("pollution-key");
|
||||
source.setOriginalFilename("header-row-format-pollution-keyword.xlsx");
|
||||
|
||||
Object parsed = ReflectionTestUtils.invokeMethod(service, "parseWorkbook", file, source);
|
||||
assertNotNull(parsed, "parseWorkbook 应返回结果");
|
||||
|
||||
Integer totalRows = (Integer) ReflectionTestUtils.invokeMethod(parsed, "totalRows");
|
||||
List<?> rows = (List<?>) ReflectionTestUtils.invokeMethod(parsed, "rows");
|
||||
assertNotNull(rows);
|
||||
System.out.println("[测试] totalRows=" + totalRows + " rows=" + rows.size());
|
||||
|
||||
assertEquals(2075, totalRows, "数据行数应与样本一致");
|
||||
Map<?, ?> extra = (Map<?, ?>) ReflectionTestUtils.invokeMethod(rows.get(0), "extra");
|
||||
assertNotNull(extra);
|
||||
// 样本表头 关键词/asin/国家/价格:关键词列为 keyword 不进 extra,其余 3 列进 extra
|
||||
assertEquals(3, extra.size(), "行内 extra 不应包含表头范围外的占位空列");
|
||||
assertFalse(extra.containsKey("列5"), "尾部空列不应生成占位列");
|
||||
assertFalse(extra.containsKey("列16384"), "尾部空列不应生成占位列");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user