fix: 终版导入不再阻断重复内容行

This commit is contained in:
苏木 2026-11-05 09:19:57 +08:00
parent 825a9a1964
commit 0c5dbd48c6
4 changed files with 38 additions and 10 deletions

View File

@ -201,12 +201,6 @@ class PayablesFinalImportRunner
}
$key = $this->store->key($dataset, $normalized);
if (isset($records[$key])) {
$message = '第 ' . ($firstRow + $line - 1) . ' 行与前一行内容重复。';
$this->fail($meta, $line - 1, $created, $updated, $message);
throw ValidationException::withMessages(['import' => $message]);
}
$records[$key] = $normalized;
$processed++;

View File

@ -97,10 +97,6 @@ class PayablesFinalImporter
$key = $store->key($storeDataset, $values);
}
if (isset($records[$key])) {
throw ValidationException::withMessages(['import' => "第 {$line} 行与前一行内容重复。"]);
}
$records[$key] = $values;
if (count($records) > self::MAX_ROWS) {

View File

@ -93,6 +93,25 @@ class PayablesFinalImportRunnerTest extends FeatureTestCase
$this->assertDirectoryDoesNotExist($runner->storagePath() . '/' . $prepared['token'], '完成后应删除缓存');
}
public function test_runner_does_not_block_import_when_rows_have_identical_content(): void
{
$row = '2026-09,RK-1,CG-1,2026-09-08,供应商甲,X-1,P-1,规格甲,2,10,20,9,18,SC-1,备注甲,华东仓,顺丰,SF-1,未发出,对账人甲';
$file = UploadedFile::fake()->createWithContent(
'duplicate.csv',
"\xEF\xBB\xBF" . implode(',', self::HEADER) . "\n{$row}\n{$row}\n",
);
$runner = app(PayablesFinalImportRunner::class);
$fields = app(PayablesFinalRegistry::class)->fields('supplier-payables-final', 'payment-reconciliation');
$dataset = 'final:supplier:payment-reconciliation';
$prepared = $runner->prepare($file, $fields, $dataset, (int) $this->company->id, (int) $this->user->id);
$progress = $runner->process($prepared['token'], 0, 10);
$this->assertTrue($progress['done']);
$this->assertSame(1, $progress['created']);
$this->assertCount(1, app(SupplierPayableOverrideStore::class)->listRows($dataset, (int) $this->company->id));
}
public function test_import_endpoints_accept_uploads_and_chunks(): void
{
$file = UploadedFile::fake()->createWithContent(

View File

@ -318,6 +318,25 @@ class SupplierPayableFinalPagesTest extends FeatureTestCase
$this->assertSame(['created' => 4500, 'updated' => 0, 'rows' => 4500], $result);
}
public function test_final_import_does_not_reject_identical_rows(): void
{
$row = '2026-09,RK-1,CG-1,2026-09-08,供应商甲,X-1,P-1,规格甲,2,10,20,9,18,SC-1,备注甲,华东仓,顺丰,SF-1,未发出,对账人甲';
$file = UploadedFile::fake()->createWithContent(
'payment-reconciliation.csv',
"\xEF\xBB\xBF月份,入库单号,采购单号,日期,供应商,货号,商品编码,规格名称,数量,单价,金额,预估单价,预估金额,供应商商品编码,备注,仓库名称,快递名称,快递单号,未发出,对账人\n{$row}\n{$row}\n",
);
$result = app(PayablesFinalImporter::class)->import(
app(PayablesFinalRegistry::class)->fields('supplier-payables-final', 'payment-reconciliation'),
'final:supplier:payment-reconciliation',
$file,
(int) $this->company->id,
(int) $this->user->id,
);
$this->assertSame(['created' => 1, 'updated' => 0, 'rows' => 1], $result);
}
public function test_final_import_stops_at_the_row_limit_without_writing(): void
{
$lines = ['月份,入库单号,采购单号,日期,供应商,货号,商品编码,规格名称,数量,单价,金额,预估单价,预估金额,供应商商品编码,备注,仓库名称,快递名称,快递单号,未发出,对账人'];