103 lines
2.7 KiB
PHP
103 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Stats;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class StatAlert extends Model
|
|
{
|
|
protected $connection = 'sam_stat';
|
|
|
|
protected $table = 'stat_alerts';
|
|
|
|
public $timestamps = false;
|
|
|
|
protected $fillable = [
|
|
'is_read',
|
|
'is_resolved',
|
|
'resolved_at',
|
|
];
|
|
|
|
protected $casts = [
|
|
'current_value' => 'decimal:2',
|
|
'threshold_value' => 'decimal:2',
|
|
'is_read' => 'boolean',
|
|
'is_resolved' => 'boolean',
|
|
'resolved_at' => 'datetime',
|
|
'created_at' => 'datetime',
|
|
];
|
|
|
|
/**
|
|
* 심각도 라벨
|
|
*/
|
|
public function getSeverityLabelAttribute(): string
|
|
{
|
|
return match ($this->severity) {
|
|
'critical' => '긴급',
|
|
'warning' => '경고',
|
|
'info' => '정보',
|
|
default => $this->severity,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* 심각도 색상 클래스
|
|
*/
|
|
public function getSeverityColorAttribute(): string
|
|
{
|
|
return match ($this->severity) {
|
|
'critical' => 'text-red-600 bg-red-100',
|
|
'warning' => 'text-yellow-600 bg-yellow-100',
|
|
'info' => 'text-blue-600 bg-blue-100',
|
|
default => 'text-gray-600 bg-gray-100',
|
|
};
|
|
}
|
|
|
|
/**
|
|
* 도메인 라벨
|
|
*/
|
|
public function getDomainLabelAttribute(): string
|
|
{
|
|
return match ($this->domain) {
|
|
'backup' => '백업',
|
|
'sales' => '매출',
|
|
'finance' => '재무',
|
|
'production' => '생산',
|
|
'system' => '시스템',
|
|
default => $this->domain,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* AI 분석용 요약 텍스트
|
|
*/
|
|
public function getAiAnalysisSummaryAttribute(): string
|
|
{
|
|
$lines = [];
|
|
$lines[] = '=== SAM 시스템 알림 분석 요청 ===';
|
|
$lines[] = '';
|
|
$lines[] = "■ 심각도: {$this->severity} ({$this->severity_label})";
|
|
$lines[] = "■ 도메인: {$this->domain} ({$this->domain_label})";
|
|
$lines[] = "■ 알림 유형: {$this->alert_type}";
|
|
$lines[] = "■ 제목: {$this->title}";
|
|
$lines[] = "■ 발생 시간: {$this->created_at?->format('Y-m-d H:i:s')}";
|
|
|
|
if ($this->message) {
|
|
$lines[] = '';
|
|
$lines[] = '■ 상세 메시지:';
|
|
$lines[] = $this->message;
|
|
}
|
|
|
|
if ($this->current_value || $this->threshold_value) {
|
|
$lines[] = '';
|
|
$lines[] = "■ 현재값: {$this->current_value}";
|
|
$lines[] = "■ 임계값: {$this->threshold_value}";
|
|
}
|
|
|
|
$lines[] = '';
|
|
$lines[] = '위 시스템 알림의 원인과 해결 방법을 분석해주세요.';
|
|
|
|
return implode("\n", $lines);
|
|
}
|
|
}
|