Merge remote-tracking branch 'origin/main' into feature/dodo-trademark-classification-digits

This commit is contained in:
WuYongJie 2026-11-09 16:33:08 +08:00
commit 8682455a41
2 changed files with 66 additions and 6 deletions

View File

@ -16,6 +16,7 @@ use Throwable;
class UpstreamBusinessInformation
{
private const SOURCE = 'operations_replica';
private const COMPANY_ESTABLISHMENT_YEAR_FLOOR = 2000;
public function __construct(
private readonly UpstreamQueryCacheFactory $caches,
@ -1066,14 +1067,18 @@ SQL);
private function mapCompany(array $row): array
{
$row = $this->toUtf8($row);
$row['establishment_date'] = $this->date($row['establishment_date'] ?? null);
$companyStatus = trim((string) ($row['company_status'] ?? ''));
$row['company_status'] = match ($companyStatus) {
'0', '正常' => '正常',
'1', '注销', '已注销' => '已注销',
default => $companyStatus !== '' ? $companyStatus : null,
};
$row['establishment_date'] = $this->companyEstablishmentDate(
$row['establishment_date'] ?? null,
$row['company_status'] === '已注销',
);
$row['subscribed_at'] = $this->date($row['subscribed_at'] ?? null);
$row['city'] = RegisteredAddressCity::parse($row['registered_address'] ?? null);
$row['company_status'] = match ((string) ($row['company_status'] ?? '')) {
'0' => '正常',
'1' => '已注销',
default => $row['company_status'] ?? null,
};
$businessType = trim((string) ($row['business_registration_type'] ?? ''));
$row['business_registration_type'] = in_array($businessType, ['核定', '个人独资企业'], true)
? $businessType
@ -1082,6 +1087,30 @@ SQL);
return $row;
}
private function companyEstablishmentDate(mixed $value, bool $deregistered): ?string
{
if ($deregistered) {
return '/';
}
if ($value === null || trim((string) $value) === '') {
return null;
}
// 上游用 1900-01-01 表示未知成立日期;公司资料不展示 2000 年前或非法日期。
$date = substr(trim((string) $value), 0, 10);
if (! preg_match('/^(\d{4})-(\d{2})-(\d{2})$/', $date, $parts)) {
return '/';
}
[, $year, $month, $day] = array_map('intval', $parts);
if ($year < self::COMPANY_ESTABLISHMENT_YEAR_FLOOR || ! checkdate($month, $day, $year)) {
return '/';
}
return $date;
}
private function mapStore(array $row): array
{
$row = $this->toUtf8($row);

View File

@ -230,6 +230,37 @@ class UpstreamBusinessInformationTest extends TestCase
$this->assertSame([], $trademarkCards->all());
}
public function test_company_registration_date_is_hidden_for_deregistered_and_invalid_pre_2000_values(): void
{
$mirror = Mockery::mock(BusinessInformationMirrorRepository::class);
$mirror->shouldReceive('ready')->once()->with('company-information.read')->andReturnTrue();
$mirror->shouldReceive('paginate')->once()->with('company-information.read', 1, 50, [])->andReturn([
'data' => [
['id' => 1, 'company_status' => '1', 'establishment_date' => '2024-04-28'],
['id' => 2, 'company_status' => '已注销', 'establishment_date' => null],
['id' => 3, 'company_status' => '0', 'establishment_date' => '1900-01-01'],
['id' => 4, 'company_status' => '正常', 'establishment_date' => '1999-12-31'],
['id' => 5, 'company_status' => '0', 'establishment_date' => '2000-01-01'],
['id' => 6, 'company_status' => null, 'establishment_date' => null],
],
'total' => 6,
]);
$items = (new UpstreamBusinessInformation(
Mockery::mock(UpstreamQueryCacheFactory::class),
$mirror,
null,
))->paginate('company-management', 'basic-information', 50)->items();
$this->assertSame('已注销', $items[0]->company_status);
$this->assertSame('/', $items[0]->establishment_date);
$this->assertSame('/', $items[1]->establishment_date);
$this->assertSame('/', $items[2]->establishment_date);
$this->assertSame('/', $items[3]->establishment_date);
$this->assertSame('2000-01-01', $items[4]->establishment_date);
$this->assertNull($items[5]->establishment_date);
}
public function test_bootstrap_without_mirror_explains_shared_connection_instead_of_requesting_upstream_credentials(): void
{
config(['system_database.mode' => 'bootstrap', 'upstreams.local_configuration.enabled' => false]);