diff --git a/modules/EcommerceFinance/Services/DingProcessDetailMirrorSynchronizer.php b/modules/EcommerceFinance/Services/DingProcessDetailMirrorSynchronizer.php index 1d66108a..5f11a08b 100644 --- a/modules/EcommerceFinance/Services/DingProcessDetailMirrorSynchronizer.php +++ b/modules/EcommerceFinance/Services/DingProcessDetailMirrorSynchronizer.php @@ -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 [ diff --git a/tests/Unit/EcommerceFinance/DingProcessDetailMirrorSynchronizerTest.php b/tests/Unit/EcommerceFinance/DingProcessDetailMirrorSynchronizerTest.php index d02c9aaa..2d63744a 100644 --- a/tests/Unit/EcommerceFinance/DingProcessDetailMirrorSynchronizerTest.php +++ b/tests/Unit/EcommerceFinance/DingProcessDetailMirrorSynchronizerTest.php @@ -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 */ private function daifaScheme(): array {