feat: [equipment] 설비 통계 API에 유형별 분포 및 점검 현황 추가
- 설비 유형별(equipment_type) 현황 집계 추가 - 이번달 점검 대상/완료/이슈 건수 통계 추가 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user