diff --git a/app/Services/Equipment/EquipmentService.php b/app/Services/Equipment/EquipmentService.php index 7d736d5..6e883af 100644 --- a/app/Services/Equipment/EquipmentService.php +++ b/app/Services/Equipment/EquipmentService.php @@ -3,6 +3,7 @@ namespace App\Services\Equipment; use App\Models\Equipment\Equipment; +use App\Models\Equipment\EquipmentInspection; use App\Services\Service; use Illuminate\Contracts\Pagination\LengthAwarePaginator; use Illuminate\Support\Facades\DB; @@ -126,7 +127,37 @@ public function stats(): array $idle = Equipment::where('status', 'idle')->count(); $disposed = Equipment::where('status', 'disposed')->count(); - return compact('total', 'active', 'idle', 'disposed'); + // 설비 유형별 현황 + $typeDistribution = Equipment::where('status', '!=', 'disposed') + ->whereNotNull('equipment_type') + ->selectRaw('equipment_type, count(*) as count') + ->groupBy('equipment_type') + ->orderByDesc('count') + ->get() + ->toArray(); + + // 이번달 점검 현황 + $yearMonth = now()->format('Y-m'); + $targetCount = Equipment::where('status', 'active')->count(); + $completedCount = EquipmentInspection::where('year_month', $yearMonth)->distinct('equipment_id')->count('equipment_id'); + $issueCount = EquipmentInspection::where('year_month', $yearMonth) + ->where(function ($q) { + $q->whereNotNull('issue_note')->where('issue_note', '!=', ''); + }) + ->count(); + + return [ + 'total' => $total, + 'active' => $active, + 'idle' => $idle, + 'disposed' => $disposed, + 'type_distribution' => $typeDistribution, + 'inspection_stats' => [ + 'target_count' => $targetCount, + 'completed_count' => $completedCount, + 'issue_count' => $issueCount, + ], + ]; } public function options(): array