Files
sam-api/app/Console/Commands/StatCheckKpiAlertsCommand.php

34 lines
902 B
PHP
Raw Normal View History

<?php
namespace App\Console\Commands;
use App\Services\Stats\KpiAlertService;
use Illuminate\Console\Command;
class StatCheckKpiAlertsCommand extends Command
{
protected $signature = 'stat:check-kpi-alerts';
protected $description = 'KPI 목표 대비 실적을 체크하고 미달 시 알림을 생성합니다';
public function handle(KpiAlertService $service): int
{
$this->info('KPI 알림 체크 시작...');
$result = $service->checkKpiAlerts();
$this->info("알림 생성: {$result['alerts_created']}");
if (! empty($result['errors'])) {
$this->warn('오류 발생:');
foreach ($result['errors'] as $error) {
$this->error(" - {$error}");
}
}
$this->info('KPI 알림 체크 완료.');
return empty($result['errors']) ? self::SUCCESS : self::FAILURE;
}
}