feat: sam_stat P0 도메인 집계 구현 (Phase 2)

- 영업(Sales), 재무(Finance), 생산(Production) 3개 도메인 구현
- 일간/월간 통계 테이블 6개 마이그레이션 생성
- 도메인별 StatService (SalesStatService, FinanceStatService, ProductionStatService)
- Daily/Monthly 6개 Eloquent 모델 생성
- StatAggregatorService에 도메인 서비스 매핑 활성화
- StatJobLog duration_ms abs() 처리
- 스케줄러 등록 (일간 02:00, 월간 1일 03:00)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-29 19:30:30 +09:00
parent c88048db67
commit e882d33de1
18 changed files with 972 additions and 9 deletions

View File

@@ -0,0 +1,26 @@
<?php
namespace App\Models\Stats\Daily;
use App\Models\Stats\BaseStatModel;
class StatFinanceDaily extends BaseStatModel
{
protected $table = 'stat_finance_daily';
protected $casts = [
'stat_date' => 'date',
'deposit_amount' => 'decimal:2',
'withdrawal_amount' => 'decimal:2',
'net_cashflow' => 'decimal:2',
'purchase_amount' => 'decimal:2',
'purchase_tax_amount' => 'decimal:2',
'receivable_balance' => 'decimal:2',
'payable_balance' => 'decimal:2',
'overdue_receivable' => 'decimal:2',
'bill_issued_amount' => 'decimal:2',
'bill_matured_amount' => 'decimal:2',
'card_transaction_amount' => 'decimal:2',
'bank_balance_total' => 'decimal:2',
];
}

View File

@@ -0,0 +1,21 @@
<?php
namespace App\Models\Stats\Daily;
use App\Models\Stats\BaseStatModel;
class StatProductionDaily extends BaseStatModel
{
protected $table = 'stat_production_daily';
protected $casts = [
'stat_date' => 'date',
'production_qty' => 'decimal:2',
'defect_qty' => 'decimal:2',
'defect_rate' => 'decimal:2',
'planned_hours' => 'decimal:2',
'actual_hours' => 'decimal:2',
'efficiency_rate' => 'decimal:2',
'delivery_rate' => 'decimal:2',
];
}

View File

@@ -0,0 +1,18 @@
<?php
namespace App\Models\Stats\Daily;
use App\Models\Stats\BaseStatModel;
class StatSalesDaily extends BaseStatModel
{
protected $table = 'stat_sales_daily';
protected $casts = [
'stat_date' => 'date',
'order_amount' => 'decimal:2',
'sales_amount' => 'decimal:2',
'sales_tax_amount' => 'decimal:2',
'shipment_amount' => 'decimal:2',
];
}

View File

@@ -0,0 +1,22 @@
<?php
namespace App\Models\Stats\Monthly;
use App\Models\Stats\BaseStatModel;
class StatFinanceMonthly extends BaseStatModel
{
protected $table = 'stat_finance_monthly';
protected $casts = [
'deposit_total' => 'decimal:2',
'withdrawal_total' => 'decimal:2',
'net_cashflow' => 'decimal:2',
'purchase_total' => 'decimal:2',
'card_total' => 'decimal:2',
'receivable_end' => 'decimal:2',
'payable_end' => 'decimal:2',
'bank_balance_end' => 'decimal:2',
'mom_cashflow_change' => 'decimal:2',
];
}

View File

@@ -0,0 +1,20 @@
<?php
namespace App\Models\Stats\Monthly;
use App\Models\Stats\BaseStatModel;
class StatProductionMonthly extends BaseStatModel
{
protected $table = 'stat_production_monthly';
protected $casts = [
'production_qty' => 'decimal:2',
'defect_qty' => 'decimal:2',
'avg_defect_rate' => 'decimal:2',
'avg_efficiency_rate' => 'decimal:2',
'avg_delivery_rate' => 'decimal:2',
'total_planned_hours' => 'decimal:2',
'total_actual_hours' => 'decimal:2',
];
}

View File

@@ -0,0 +1,20 @@
<?php
namespace App\Models\Stats\Monthly;
use App\Models\Stats\BaseStatModel;
class StatSalesMonthly extends BaseStatModel
{
protected $table = 'stat_sales_monthly';
protected $casts = [
'order_amount' => 'decimal:2',
'sales_amount' => 'decimal:2',
'shipment_amount' => 'decimal:2',
'avg_order_amount' => 'decimal:2',
'top_client_amount' => 'decimal:2',
'mom_growth_rate' => 'decimal:2',
'yoy_growth_rate' => 'decimal:2',
];
}

View File

@@ -26,7 +26,7 @@ public function markRunning(): void
public function markCompleted(int $recordsProcessed = 0): void
{
$durationMs = $this->started_at
? (int) now()->diffInMilliseconds($this->started_at)
? abs((int) now()->diffInMilliseconds($this->started_at))
: null;
$this->update([
@@ -40,7 +40,7 @@ public function markCompleted(int $recordsProcessed = 0): void
public function markFailed(string $errorMessage): void
{
$durationMs = $this->started_at
? (int) now()->diffInMilliseconds($this->started_at)
? abs((int) now()->diffInMilliseconds($this->started_at))
: null;
$this->update([