23 lines
772 B
PHP
23 lines
772 B
PHP
<?php
|
|
|
|
namespace App\Services\Mne;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
final class SectorResolver
|
|
{
|
|
public const VERSION = 1;
|
|
|
|
public function resolve(int $legacyId): ?string
|
|
{
|
|
$id = DB::table('mne.sector_links as l')->join('public.sectors as s', 's.id', '=', 'l.sector_id')
|
|
->where('l.sector_id', $legacyId)->where('l.resolver_version', self::VERSION)
|
|
->where('l.status', 'active')->where('s.is_active', true)->whereNull('s.deleted_at')
|
|
->whereColumn('l.source_code', 's.slug')->where('l.valid_from', '<=', now())
|
|
->where(fn ($q) => $q->whereNull('l.valid_until')->orWhere('l.valid_until', '>', now()))
|
|
->value('l.canonical_sector_id');
|
|
|
|
return is_string($id) ? $id : null;
|
|
}
|
|
}
|