feat: sam_stat 통계 DB 인프라 구축 (Phase 1)
- sam_stat DB 연결 설정 (config/database.php, .env) - 메타 테이블 마이그레이션 (stat_definitions, stat_job_logs) - dim_date 차원 테이블 + DimDateSeeder (2020~2030, 4018건) - 기반 모델: BaseStatModel, StatDefinition, StatJobLog, DimDate - 집계 커맨드: stat:aggregate-daily, stat:aggregate-monthly - StatAggregatorService + StatDomainServiceInterface 골격 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
12
app/Models/Stats/BaseStatModel.php
Normal file
12
app/Models/Stats/BaseStatModel.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Stats;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
abstract class BaseStatModel extends Model
|
||||
{
|
||||
protected $connection = 'sam_stat';
|
||||
|
||||
protected $guarded = ['id'];
|
||||
}
|
||||
24
app/Models/Stats/Dimensions/DimDate.php
Normal file
24
app/Models/Stats/Dimensions/DimDate.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Stats\Dimensions;
|
||||
|
||||
use App\Models\Stats\BaseStatModel;
|
||||
|
||||
class DimDate extends BaseStatModel
|
||||
{
|
||||
protected $table = 'dim_date';
|
||||
|
||||
protected $primaryKey = 'date_key';
|
||||
|
||||
public $incrementing = false;
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
protected $keyType = 'string';
|
||||
|
||||
protected $casts = [
|
||||
'date_key' => 'date',
|
||||
'is_weekend' => 'boolean',
|
||||
'is_holiday' => 'boolean',
|
||||
];
|
||||
}
|
||||
14
app/Models/Stats/StatDefinition.php
Normal file
14
app/Models/Stats/StatDefinition.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Stats;
|
||||
|
||||
class StatDefinition extends BaseStatModel
|
||||
{
|
||||
protected $table = 'stat_definitions';
|
||||
|
||||
protected $casts = [
|
||||
'source_tables' => 'array',
|
||||
'config' => 'array',
|
||||
'is_active' => 'boolean',
|
||||
];
|
||||
}
|
||||
53
app/Models/Stats/StatJobLog.php
Normal file
53
app/Models/Stats/StatJobLog.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Stats;
|
||||
|
||||
class StatJobLog extends BaseStatModel
|
||||
{
|
||||
protected $table = 'stat_job_logs';
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
protected $casts = [
|
||||
'target_date' => 'date',
|
||||
'started_at' => 'datetime',
|
||||
'completed_at' => 'datetime',
|
||||
'created_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function markRunning(): void
|
||||
{
|
||||
$this->update([
|
||||
'status' => 'running',
|
||||
'started_at' => now(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function markCompleted(int $recordsProcessed = 0): void
|
||||
{
|
||||
$durationMs = $this->started_at
|
||||
? (int) now()->diffInMilliseconds($this->started_at)
|
||||
: null;
|
||||
|
||||
$this->update([
|
||||
'status' => 'completed',
|
||||
'records_processed' => $recordsProcessed,
|
||||
'completed_at' => now(),
|
||||
'duration_ms' => $durationMs,
|
||||
]);
|
||||
}
|
||||
|
||||
public function markFailed(string $errorMessage): void
|
||||
{
|
||||
$durationMs = $this->started_at
|
||||
? (int) now()->diffInMilliseconds($this->started_at)
|
||||
: null;
|
||||
|
||||
$this->update([
|
||||
'status' => 'failed',
|
||||
'error_message' => $errorMessage,
|
||||
'completed_at' => now(),
|
||||
'duration_ms' => $durationMs,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user