From 08582261dbb6383546c51783698d4ddd73da20c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9C=A0=EB=B3=91=EC=B2=A0?= Date: Thu, 12 Mar 2026 18:47:39 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20[equipment]=20=EC=84=A4=EB=B9=84=20?= =?UTF-8?q?=ED=86=B5=EA=B3=84=20API=EC=97=90=20=EC=9C=A0=ED=98=95=EB=B3=84?= =?UTF-8?q?=20=EB=B6=84=ED=8F=AC=20=EB=B0=8F=20=EC=A0=90=EA=B2=80=20?= =?UTF-8?q?=ED=98=84=ED=99=A9=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 설비 유형별(equipment_type) 현황 집계 추가 - 이번달 점검 대상/완료/이슈 건수 통계 추가 Co-Authored-By: Claude Opus 4.6 --- app/Services/Equipment/EquipmentService.php | 33 ++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) 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