fix: 隔离退款每日同步批次

退款每日批次完成后立即结束,不触发钉钉流程同步。
This commit is contained in:
renshen 2026-11-04 18:48:07 +08:00
parent 232ec8b200
commit f8e43d4e6e
2 changed files with 49 additions and 0 deletions

View File

@ -94,6 +94,12 @@ class SyncBusinessMirrors extends Command
));
}
// 每日退款专属批次只处理配置内的退款表,不能继续进入
// 通用入口附带的钉钉流程同步。
if ($dailyOnly) {
return $failed ? self::FAILURE : self::SUCCESS;
}
// 钉钉应付流程采用按流程聚合的专用镜像;接入同一入口后由现有
// 生产 cron 自动断点续传,避免额外维护一套调度脚本。
if ($requested === null && $dingPayableWorkflows !== null && ! app()->environment('testing')) {

View File

@ -10,6 +10,8 @@ use Modules\EcommerceFinance\Repositories\GenericBusinessMirrorRepository;
use Modules\EcommerceFinance\Repositories\ProductCatalogMirrorRepository;
use Modules\EcommerceFinance\Services\BusinessMirrorDatasetRegistry;
use Modules\EcommerceFinance\Services\BusinessMirrorSynchronizer;
use Modules\EcommerceFinance\Services\DingPayableWorkflowMirrorSynchronizer;
use Modules\EcommerceFinance\Services\DingProcessDetailMirrorSynchronizer;
use Tests\TestCase;
class BusinessMirrorScheduleTest extends TestCase
@ -233,4 +235,45 @@ class BusinessMirrorScheduleTest extends TestCase
'--max-batches' => 0,
])->assertSuccessful();
}
public function test_daily_only_does_not_enter_general_ding_workflow_sync(): void
{
config([
'upstream_mirrors.refresh_enabled' => true,
'upstream_mirrors.table_sync.daily_datasets' => ['daily-a'],
]);
$dataset = Mockery::mock(BusinessMirrorDataset::class);
$datasets = Mockery::mock(BusinessMirrorDatasetRegistry::class);
$datasets->shouldReceive('all')->once()->andReturn(['daily-a' => $dataset]);
$datasets->shouldReceive('scheduled')->once()->with('daily-a')->andReturn(true);
$datasets->shouldReceive('definitionValue')->with('daily-a', 'full_reconcile_hours', 0)->andReturn(0);
$mirror = Mockery::mock(GenericBusinessMirrorRepository::class);
$mirror->shouldReceive('state')->once()->with($dataset)->andReturn([
'initial_completed_at' => '2026-08-01 02:00:00',
'last_attempted_at' => '2026-08-15 01:00:00',
'status' => 'succeeded',
]);
$synchronizer = Mockery::mock(BusinessMirrorSynchronizer::class);
$synchronizer->shouldReceive('sync')
->once()
->with('daily-a', false, null, 0)
->andReturn(['status' => 'succeeded', 'batches' => 1, 'rows' => 1]);
$dingPayable = Mockery::mock(DingPayableWorkflowMirrorSynchronizer::class);
$dingPayable->shouldNotReceive('sync');
$dingDetails = Mockery::mock(DingProcessDetailMirrorSynchronizer::class);
$dingDetails->shouldNotReceive('sync');
$this->app->instance(BusinessMirrorDatasetRegistry::class, $datasets);
$this->app->instance(GenericBusinessMirrorRepository::class, $mirror);
$this->app->instance(BusinessMirrorSynchronizer::class, $synchronizer);
$this->app->instance(DingPayableWorkflowMirrorSynchronizer::class, $dingPayable);
$this->app->instance(DingProcessDetailMirrorSynchronizer::class, $dingDetails);
$this->app->instance('env', 'production');
$this->artisan('business-mirror:sync-tables', [
'--daily-only' => true,
'--max-batches' => 0,
])->assertSuccessful();
}
}