From 3dce8d3343933a75849ece0a8dc5df2ff8ba0ffd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E6=9C=A8?= <594326199@qq.com> Date: Thu, 5 Nov 2026 09:20:27 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=E7=BB=88=E7=89=88=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=E4=B8=8D=E5=86=8D=E9=98=BB=E6=96=AD=E9=87=8D=E5=A4=8D=E5=86=85?= =?UTF-8?q?=E5=AE=B9=E8=A1=8C=20(#877)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 移除终版普通导入和大文件分片导入的重复内容异常判断。 Co-authored-by: 苏木 <594326199@qq.com> Co-committed-by: 苏木 <594326199@qq.com> --- .../Services/PayablesFinalImportRunner.php | 6 ------ .../Services/PayablesFinalImporter.php | 4 ---- .../PayablesFinalImportRunnerTest.php | 19 +++++++++++++++++++ .../SupplierPayableFinalPagesTest.php | 19 +++++++++++++++++++ 4 files changed, 38 insertions(+), 10 deletions(-) diff --git a/modules/EcommerceFinance/Services/PayablesFinalImportRunner.php b/modules/EcommerceFinance/Services/PayablesFinalImportRunner.php index c574bd39..1fb91903 100644 --- a/modules/EcommerceFinance/Services/PayablesFinalImportRunner.php +++ b/modules/EcommerceFinance/Services/PayablesFinalImportRunner.php @@ -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++; diff --git a/modules/EcommerceFinance/Services/PayablesFinalImporter.php b/modules/EcommerceFinance/Services/PayablesFinalImporter.php index 2dd761c3..004bd71d 100644 --- a/modules/EcommerceFinance/Services/PayablesFinalImporter.php +++ b/modules/EcommerceFinance/Services/PayablesFinalImporter.php @@ -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) { diff --git a/tests/Feature/Business/PayablesFinalImportRunnerTest.php b/tests/Feature/Business/PayablesFinalImportRunnerTest.php index 0c2cd7dc..9eeb72e2 100644 --- a/tests/Feature/Business/PayablesFinalImportRunnerTest.php +++ b/tests/Feature/Business/PayablesFinalImportRunnerTest.php @@ -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( diff --git a/tests/Feature/Business/SupplierPayableFinalPagesTest.php b/tests/Feature/Business/SupplierPayableFinalPagesTest.php index e7a2ab01..954453f1 100644 --- a/tests/Feature/Business/SupplierPayableFinalPagesTest.php +++ b/tests/Feature/Business/SupplierPayableFinalPagesTest.php @@ -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 = ['月份,入库单号,采购单号,日期,供应商,货号,商品编码,规格名称,数量,单价,金额,预估单价,预估金额,供应商商品编码,备注,仓库名称,快递名称,快递单号,未发出,对账人']; -- 2.47.2 From 6595ed77081604039cc6a7d911070358acdb2c9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E6=9C=A8?= <594326199@qq.com> Date: Thu, 5 Nov 2026 09:35:08 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=E8=B0=83=E6=95=B4=E7=BB=88=E7=89=88?= =?UTF-8?q?=E5=AF=BC=E5=85=A5=E4=B8=8A=E4=BC=A0=E9=87=8D=E8=AF=95=E9=99=90?= =?UTF-8?q?=E6=B5=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Providers/Route.php | 5 +++++ config/app.php | 1 + routes/admin.php | 2 +- .../Business/PayablesFinalImportRunnerTest.php | 18 ++++++++++++++++++ 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/app/Providers/Route.php b/app/Providers/Route.php index ebf2851d..b3066c78 100644 --- a/app/Providers/Route.php +++ b/app/Providers/Route.php @@ -320,6 +320,11 @@ class Route extends Provider return Limit::perMinute(config('app.throttles.import')); }); + RateLimiter::for('import-upload', function (Request $request) { + return Limit::perMinute(config('app.throttles.import_upload')) + ->by($request->user()?->id ?: $request->ip()); + }); + RateLimiter::for('email', function (Request $request) { return [ Limit::perDay(config('app.throttles.email.month'), 30), diff --git a/config/app.php b/config/app.php index d935a57c..561f064f 100644 --- a/config/app.php +++ b/config/app.php @@ -29,6 +29,7 @@ return [ 'api' => env('APP_THROTTLES_API', '60'), 'oauth' => env('APP_THROTTLES_OAUTH', '60'), 'import' => env('APP_THROTTLES_IMPORT', '1'), + 'import_upload' => env('APP_THROTTLES_IMPORT_UPLOAD', '10'), 'dcr' => env('APP_THROTTLES_DCR', '60'), 'email' => [ 'minute' => env('APP_THROTTLES_EMAIL_MINUTE', '5'), diff --git a/routes/admin.php b/routes/admin.php index c0dcf5b4..1471d0ad 100644 --- a/routes/admin.php +++ b/routes/admin.php @@ -411,7 +411,7 @@ foreach ($payablesFinalDatasets as $finalSection => $finalDatasets) { ->middleware('import') ->defaults('dataset', $dataset)->defaults('finalSection', $finalSection)->name('import'); Route::post('import-upload', [PayablesFinalActions::class, 'importUpload']) - ->middleware('import') + ->middleware('throttle:import-upload') ->defaults('dataset', $dataset)->defaults('finalSection', $finalSection)->name('import.upload'); Route::post('import-chunk', [PayablesFinalActions::class, 'importChunk']) ->defaults('dataset', $dataset)->defaults('finalSection', $finalSection)->name('import.chunk'); diff --git a/tests/Feature/Business/PayablesFinalImportRunnerTest.php b/tests/Feature/Business/PayablesFinalImportRunnerTest.php index 9eeb72e2..6157659d 100644 --- a/tests/Feature/Business/PayablesFinalImportRunnerTest.php +++ b/tests/Feature/Business/PayablesFinalImportRunnerTest.php @@ -143,6 +143,24 @@ class PayablesFinalImportRunnerTest extends FeatureTestCase ->assertStatus(422); } + public function test_import_upload_allows_a_retry_within_one_minute(): void + { + $content = "\xEF\xBB\xBF" . implode(',', self::HEADER) . "\n2026-09,RK-1,CG-1,2026-09-08,供应商甲,X-1,P-1,规格甲,2,10,20,9,18,SC-1,备注甲,华东仓,顺丰,SF-1,未发出,对账人甲\n"; + $runner = app(PayablesFinalImportRunner::class); + + $first = $this->loginAs()->postJson(route('business.supplier-payables-final.payment-reconciliation.import.upload'), [ + 'import' => UploadedFile::fake()->createWithContent('first.csv', $content), + ]); + $second = $this->loginAs()->postJson(route('business.supplier-payables-final.payment-reconciliation.import.upload'), [ + 'import' => UploadedFile::fake()->createWithContent('second.csv', $content), + ]); + + $first->assertOk(); + $second->assertOk(); + $runner->delete((string) $first->json('token')); + $runner->delete((string) $second->json('token')); + } + public function test_final_page_wires_the_chunked_import_endpoints(): void { $this->loginAs() -- 2.47.2