hotfix: 修复终版导入上传限流误拦截 #878
@ -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),
|
||||
|
||||
@ -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'),
|
||||
|
||||
@ -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++;
|
||||
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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');
|
||||
|
||||
@ -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(
|
||||
@ -124,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()
|
||||
|
||||
@ -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 = ['月份,入库单号,采购单号,日期,供应商,货号,商品编码,规格名称,数量,单价,金额,预估单价,预估金额,供应商商品编码,备注,仓库名称,快递名称,快递单号,未发出,对账人'];
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user