[RELEASE] 晉升 demo 至 main 正式環境:修復 APK 部署準備中預約排程機台統計

This commit is contained in:
sky121113 2026-05-29 11:09:02 +08:00
commit 577a0b739e

View File

@ -29,10 +29,30 @@ class ApkVersionController extends AdminController
->with('machine')
->get();
// 撈取所有還沒執行的 OTA 預約排程
$pendingSchedules = \App\Models\Machine\OtaSchedule::where('status', 'pending')->get();
// 蒐集所有預約機台 ID一次性撈出以避免 N+1
$allScheduledMachineIds = [];
foreach ($pendingSchedules as $sch) {
if (is_array($sch->target_value)) {
$allScheduledMachineIds = array_merge($allScheduledMachineIds, $sch->target_value);
}
}
$allScheduledMachineIds = array_unique(array_filter($allScheduledMachineIds));
$scheduledMachinesMap = [];
if (count($allScheduledMachineIds) > 0) {
$scheduledMachinesMap = \App\Models\Machine\Machine::whereIn('id', $allScheduledMachineIds)
->get()
->keyBy('id');
}
foreach ($versions as $version) {
$pending = [];
$completed = [];
// 1. 已排入指令(已發送或執行中)的 RemoteCommand
foreach ($commands as $cmd) {
$cmdVersionCode = $cmd->payload['version_code'] ?? null;
if ($cmdVersionCode == $version->version_code) {
@ -44,6 +64,20 @@ class ApkVersionController extends AdminController
}
}
// 2. 還沒有執行的預約排程中的機台
foreach ($pendingSchedules as $sch) {
if ($sch->apk_version_id == $version->id) {
$machineIds = $sch->target_value;
if (is_array($machineIds)) {
foreach ($machineIds as $mId) {
if (isset($scheduledMachinesMap[$mId])) {
$pending[] = $scheduledMachinesMap[$mId];
}
}
}
}
}
$version->pending_machines = collect($pending)->filter()->unique('id');
$version->completed_machines = collect($completed)->filter()->unique('id');
}