feat: sam_stat P2 도메인 + 통계 API + 대시보드 전환 (Phase 4)
- 4.1: stat_project_monthly + ProjectStatService (건설/프로젝트 월간) - 4.2: stat_system_daily + SystemStatService (API/감사/FCM/파일/결재) - 4.3: stat_events, stat_snapshots + StatEventService + StatEventObserver - 4.4: StatController (summary/daily/monthly/alerts) + StatQueryService + FormRequest 3개 + routes/stats.php - 4.5: DashboardService sam_stat 우선 조회 + 원본 DB 폴백 패턴 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
74
app/Services/Stats/StatEventService.php
Normal file
74
app/Services/Stats/StatEventService.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Stats;
|
||||
|
||||
use App\Models\Stats\StatEvent;
|
||||
use App\Models\Stats\StatSnapshot;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class StatEventService
|
||||
{
|
||||
/**
|
||||
* 통계 이벤트 기록
|
||||
*/
|
||||
public function recordEvent(
|
||||
int $tenantId,
|
||||
string $domain,
|
||||
string $eventType,
|
||||
string $entityType,
|
||||
int $entityId,
|
||||
?array $payload = null
|
||||
): void {
|
||||
try {
|
||||
StatEvent::create([
|
||||
'tenant_id' => $tenantId,
|
||||
'domain' => $domain,
|
||||
'event_type' => $eventType,
|
||||
'entity_type' => $entityType,
|
||||
'entity_id' => $entityId,
|
||||
'payload' => $payload,
|
||||
'occurred_at' => now(),
|
||||
]);
|
||||
} catch (\Throwable $e) {
|
||||
Log::warning('stat_event 기록 실패', [
|
||||
'tenant_id' => $tenantId,
|
||||
'domain' => $domain,
|
||||
'event_type' => $eventType,
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 스냅샷 저장
|
||||
*/
|
||||
public function saveSnapshot(
|
||||
int $tenantId,
|
||||
string $domain,
|
||||
string $snapshotDate,
|
||||
array $data,
|
||||
string $snapshotType = 'daily'
|
||||
): void {
|
||||
try {
|
||||
StatSnapshot::updateOrCreate(
|
||||
[
|
||||
'tenant_id' => $tenantId,
|
||||
'snapshot_date' => $snapshotDate,
|
||||
'domain' => $domain,
|
||||
'snapshot_type' => $snapshotType,
|
||||
],
|
||||
[
|
||||
'data' => $data,
|
||||
'created_at' => now(),
|
||||
]
|
||||
);
|
||||
} catch (\Throwable $e) {
|
||||
Log::warning('stat_snapshot 저장 실패', [
|
||||
'tenant_id' => $tenantId,
|
||||
'domain' => $domain,
|
||||
'snapshot_date' => $snapshotDate,
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user