fix: 保留流程定点同步水位 #682

Merged
yueyang merged 1 commits from fix/yueyang-preserve-process-sync-watermarks into main 2026-10-27 12:26:46 +08:00
2 changed files with 46 additions and 0 deletions

View File

@ -205,6 +205,9 @@ class DingProcessDetailMirrorSynchronizer
$extracted['metrics']['approval_api_cursor'] = (string) (
$cursor['approval_api_cursor'] ?? ''
);
$extracted['metrics']['scheme_high_watermark'] = (int) (
$cursor['scheme_high_watermark'] ?? 0
);
if ($dryRun) {
return [

View File

@ -396,6 +396,49 @@ class DingProcessDetailMirrorSynchronizerTest extends TestCase
->table('ding_process_payment_mirror')->count());
}
public function test_business_id_sync_preserves_incremental_watermarks(): void
{
$workflow = [
'processInstanceId' => 'process-preserve-cursors',
'processCode' => 'PROC-ACF09A14-B094-46B1-A9E2-8BB1F4E1FDCF',
'businessId' => '202610151743000310228',
'title' => '李斯提交的线上代发业务报销',
'status' => 'RUNNING',
'originatorUserId' => 'user-1',
'joinAt' => '2026-10-15 17:44:06',
'updateAt' => '2026-10-15 17:44:06',
];
$this->query->workflows = [$workflow];
$this->query->scheme = [
'收款费用明细' => json_encode([[
'rowValue' => [['label' => '代发订单金额', 'value' => '100.00']],
]], JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR),
'收款合计' => 100,
'付款明细' => '[]',
];
$this->query->schemeHighWatermark = 500;
$this->synchronizer->sync(true);
$state = DB::connection('business_mirror')
->table('business_mirror_table_states')
->first();
$cursor = json_decode((string) $state->cursor, true);
$cursor['scheme_high_watermark'] = 500;
$cursor['approval_api_cursor'] = 'api-cursor-500';
DB::connection('business_mirror')
->table('business_mirror_table_states')
->update(['cursor' => json_encode($cursor, JSON_UNESCAPED_UNICODE)]);
$this->synchronizer->syncBusinessIds(['202610151743000310228']);
$state = DB::connection('business_mirror')
->table('business_mirror_table_states')
->first();
$cursor = json_decode((string) $state->cursor, true);
$this->assertSame(500, (int) $cursor['scheme_high_watermark']);
$this->assertSame('api-cursor-500', $cursor['approval_api_cursor']);
}
/** @return array<string,mixed> */
private function daifaScheme(): array
{