[ 'driver' => 'sqlite', 'database' => ':memory:', 'prefix' => '', ], 'upstream_mirrors.connection' => 'business_mirror', 'upstream_mirrors.datasets' => [ 'operations_replica.rpt.fys_companyInfo' => $this->definition('fys_companyInfo', 'ops_fys_company_info'), 'operations_replica.rpt.fys_shopInfo' => $this->definition('fys_shopInfo', 'ops_fys_shop_info'), 'operations_replica.rpt.fys_TrademarkInfo' => $this->definition('fys_TrademarkInfo', 'ops_fys_trademark_info'), ], ]); DB::purge('business_mirror'); $this->createTables(); $mirror = new GenericBusinessMirrorRepository(app('db')); $this->repository = new BusinessInformationMirrorRepository( new BusinessMirrorDatasetRegistry(), $mirror, ); } public function test_it_reads_all_three_ready_mirrors_with_pagination_and_business_filters(): void { $connection = DB::connection('business_mirror'); $connection->table('ops_fys_company_info')->insert([ $this->company(1, '统一代码', '旧公司'), $this->company(2, '统一代码', '新公司'), $this->company(3, '其他代码', '其他公司'), ]); $connection->table('ops_fys_shop_info')->insert([ ['Id' => 8, 'openTime' => '2026-08-14 10:00:00', 'erpShopName' => '测试店', 'unifiedSocialCreditCode' => '统一代码', 'trademarkNumber' => 'TM', 'platform' => '天猫', 'responsibleDepartment' => '电商', 'shopHead' => '负责人', 'shopState' => '0', 'shopType' => '直营', 'channelType' => '线上'], ]); $connection->table('ops_fys_trademark_info')->insert([ ['Id' => 5, 'trademarkName' => '有效商标', 'internationalClassification' => '20', 'trademarkStatus' => '1', 'registrationDate' => '2020-01-01', 'termOfValidity' => '2030-01-01', 'remark' => null, 'isDelete' => 0], ['Id' => 6, 'trademarkName' => '已删除', 'internationalClassification' => '20', 'trademarkStatus' => '0', 'registrationDate' => null, 'termOfValidity' => null, 'remark' => null, 'isDelete' => 1], ]); $this->markReady(); $companies = $this->repository->paginate('company-information.read', 2, 2); $store = $this->repository->paginate('store-information.read', 1, 20); $trademarks = $this->repository->paginate('trademark-information.read', 1, 20); $this->assertSame(3, $companies['total']); $this->assertSame(1, $companies['data'][0]['id']); $this->assertSame('新公司', $store['data'][0]['company_name']); $this->assertSame(1, $trademarks['total']); $this->assertSame('有效商标', $trademarks['data'][0]['trademark_name']); } public function test_dataset_is_not_ready_until_initial_full_sync_is_marked_complete(): void { $this->assertFalse($this->repository->ready('company-information.read')); $this->markReady(['operations_replica.rpt.fys_companyInfo']); $this->assertTrue($this->repository->ready('company-information.read')); } private function createTables(): void { $schema = Schema::connection('business_mirror'); $schema->create('business_mirror_table_states', function (Blueprint $table): void { $table->string('dataset_key')->primary(); $table->dateTime('initial_completed_at')->nullable(); }); $schema->create('ops_fys_company_info', function (Blueprint $table): void { $table->integer('Id'); $table->string('unifiedSocialCreditCode')->nullable(); $table->string('businessLicenseName')->nullable(); $table->string('registeredCapital')->nullable(); $table->string('businessLicenseType')->nullable(); $table->dateTime('IncorporationDate')->nullable(); $table->string('legalRepresentative')->nullable(); $table->string('registeredAddress')->nullable(); $table->text('businessScope')->nullable(); $table->string('accountSerialNumber')->nullable(); $table->string('companyStatus')->nullable(); $table->string('financialManager')->nullable(); $table->string('supervisor')->nullable(); $table->string('taxCategoryAndType')->nullable(); }); $schema->create('ops_fys_shop_info', function (Blueprint $table): void { $table->integer('Id'); $table->dateTime('openTime')->nullable(); $table->string('erpShopName')->nullable(); $table->string('unifiedSocialCreditCode')->nullable(); $table->string('trademarkNumber')->nullable(); $table->string('platform')->nullable(); $table->string('responsibleDepartment')->nullable(); $table->string('shopHead')->nullable(); $table->string('shopState')->nullable(); $table->string('shopType')->nullable(); $table->string('channelType')->nullable(); }); $schema->create('ops_fys_trademark_info', function (Blueprint $table): void { $table->integer('Id'); $table->string('trademarkName')->nullable(); $table->string('internationalClassification')->nullable(); $table->string('trademarkStatus')->nullable(); $table->dateTime('registrationDate')->nullable(); $table->dateTime('termOfValidity')->nullable(); $table->text('remark')->nullable(); $table->integer('isDelete')->default(0); }); } private function markReady(?array $keys = null): void { $keys ??= array_keys((array) config('upstream_mirrors.datasets')); foreach ($keys as $key) { DB::connection('business_mirror')->table('business_mirror_table_states')->insert([ 'dataset_key' => $key, 'initial_completed_at' => '2026-08-14 12:00:00', ]); } } private function definition(string $object, string $target): array { return ['source_key' => 'operations_replica', 'schema' => 'rpt', 'object' => $object, 'target' => $target, 'keys' => ['Id']]; } private function company(int $id, string $code, string $name): array { return ['Id' => $id, 'unifiedSocialCreditCode' => $code, 'businessLicenseName' => $name, 'registeredCapital' => null, 'businessLicenseType' => null, 'IncorporationDate' => null, 'legalRepresentative' => null, 'registeredAddress' => null, 'businessScope' => null, 'accountSerialNumber' => null, 'companyStatus' => '0', 'financialManager' => null, 'supervisor' => null, 'taxCategoryAndType' => null]; } }