[FEAT] 實作維修管理模組與 RBAC 權限整合、多語系支援及 UI 優化
All checks were successful
star-cloud-deploy-demo / deploy-demo (push) Successful in 1m3s
All checks were successful
star-cloud-deploy-demo / deploy-demo (push) Successful in 1m3s
This commit is contained in:
@@ -106,6 +106,51 @@ class MachineService
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get machine utilization and OEE statistics for entire fleet.
|
||||
*/
|
||||
public function getFleetStats(string $date): array
|
||||
{
|
||||
$start = Carbon::parse($date)->startOfDay();
|
||||
$end = Carbon::parse($date)->endOfDay();
|
||||
|
||||
// 1. Online Count (Base on current status)
|
||||
$machines = Machine::all(); // This is filtered by TenantScoped
|
||||
$totalMachines = $machines->count();
|
||||
$onlineCount = $machines->where('status', 'online')->count();
|
||||
|
||||
$machineIds = $machines->pluck('id')->toArray();
|
||||
|
||||
// 2. Total Daily Sales (Sum of B600 logs across all authorized machines)
|
||||
$totalSales = MachineLog::whereIn('machine_id', $machineIds)
|
||||
->where('message', 'like', '%B600%')
|
||||
->whereBetween('created_at', [$start, $end])
|
||||
->count();
|
||||
|
||||
// 3. Average OEE (Simulated based on individual machine stats for performance)
|
||||
$totalOee = 0;
|
||||
$count = 0;
|
||||
|
||||
foreach ($machines as $machine) {
|
||||
$stats = $this->getUtilizationStats($machine, $date);
|
||||
$totalOee += $stats['overview']['oee'];
|
||||
$count++;
|
||||
}
|
||||
|
||||
$avgOee = ($count > 0) ? ($totalOee / $count) : 0;
|
||||
|
||||
return [
|
||||
'avgOee' => round($avgOee, 2),
|
||||
'onlineCount' => $onlineCount,
|
||||
'totalMachines' => $totalMachines,
|
||||
'totalSales' => $totalSales,
|
||||
'alertCount' => MachineLog::whereIn('machine_id', $machineIds)
|
||||
->where('level', 'error')
|
||||
->whereBetween('created_at', [$start, $end])
|
||||
->count()
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get machine utilization and OEE statistics.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user