fix(对账单): 修复 Excel 空行导致上传卡死

自闭合空行现在会正确推进 XMLReader,避免同一空行无限重复读取。
Co-authored-by: 苏木 <594326199@qq.com>
Co-committed-by: 苏木 <594326199@qq.com>
This commit is contained in:
苏木 2026-11-26 15:31:21 +08:00 committed by sumu
parent 1e823e299b
commit f0df43e2f2
2 changed files with 30 additions and 0 deletions

View File

@ -136,6 +136,10 @@ class PayablesWorkbookStreamReader
$depth = $reader->depth;
$empty = $reader->isEmptyElement;
if ($empty) {
// A self-closing <row/> must be consumed before the outer loop
// evaluates the current node again, otherwise this row repeats forever.
$reader->read();
return $cells;
}

View File

@ -66,6 +66,27 @@ class PayablesFinalImportRunnerTest extends FeatureTestCase
}
}
public function test_stream_reader_advances_past_self_closing_empty_xlsx_rows(): void
{
$path = $this->makeXlsxFile([
self::HEADER,
['2026-10', 'RK-1', '921979', '2026-10-10', '亿之航', 'DSG004820', 'DSG004820N1019V01', '款式四', '30', '83.5', '2505'],
[],
['2026-10', 'RK-2', '941828', '2026-10-10', '亿之航', 'DSG004820', 'DSG004820N1019V01', '款式四', '30', '83.5', '2505'],
]);
try {
$reader = PayablesWorkbookStreamReader::forFile($path, 'xlsx');
$rows = iterator_to_array($reader->rows(0), true);
$this->assertSame([1, 2, 3, 4], array_keys($rows));
$this->assertSame([], $rows[3]);
$this->assertSame('RK-2', $rows[4][1]);
} finally {
@unlink($path);
}
}
public function test_stream_reader_reads_gbk_csv(): void
{
$content = mb_convert_encoding(implode(',', self::HEADER) . "\n2026-09,RK-9,CG-9,2026-09-08,供应商九,X-9,P-9,规格甲,2,10,20,9,18,SC-1,备注甲,华东仓,顺丰,SF-9,未发出,对账人甲\n", 'GBK', 'UTF-8');
@ -246,6 +267,11 @@ class PayablesFinalImportRunnerTest extends FeatureTestCase
$sheet = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><sheetData>';
foreach ($rows as $rowIndex => $row) {
if ($row === []) {
$sheet .= '<row r="' . ($rowIndex + 1) . '"/>';
continue;
}
$sheet .= '<row r="' . ($rowIndex + 1) . '">';
foreach ($row as $columnIndex => $value) {
$cell = chr(65 + $columnIndex) . ($rowIndex + 1);