42 lines
1.5 KiB
PHP
42 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Facades\DB;
|
|
use App\Services\GesconImport\StabileEnrichmentService;
|
|
|
|
class GesconEnrichStabili extends Command
|
|
{
|
|
protected $signature = 'gescon:enrich-stabili {--path=/mnt/gescon-archives/gescon} {--limit=}';
|
|
protected $description = 'Arricchisce tutti (o i primi N) stabili importati.';
|
|
|
|
public function handle(): int
|
|
{
|
|
$path = $this->option('path');
|
|
$limit = $this->option('limit') ? (int)$this->option('limit') : null;
|
|
if (!\Schema::hasTable('stabili')) {
|
|
$this->error('Tabella stabili non presente.');
|
|
return 1;
|
|
}
|
|
$q = DB::table('stabili')->select('id', 'codice_stabile', 'denominazione');
|
|
if ($limit) $q->limit($limit);
|
|
$list = $q->get();
|
|
$svc = new StabileEnrichmentService();
|
|
$c = 0;
|
|
$cat = 0;
|
|
$ban = 0;
|
|
foreach ($list as $row) {
|
|
$code = $row->codice_stabile ?: $row->denominazione;
|
|
if (!$code) continue;
|
|
$res = $svc->enrich($code, $path);
|
|
$c++;
|
|
if (!empty($res['catasto'])) $cat++;
|
|
if (!empty($res['banca_inline'])) $ban++;
|
|
$this->line("#{$c} {$code} catasto=" . ($res['catasto'] ? 'Y' : '-') . " banca=" . ($res['banca_inline'] ? 'Y' : '-'));
|
|
}
|
|
$this->info("Completato: {$c} stabili, catasto arricchito {$cat}, banca inline {$ban}.");
|
|
return 0;
|
|
}
|
|
}
|