[FIX] 合併 feat/inventory-mqtt-resend:庫存效期管理 MQTT 下發逾時自動解鎖
1. slotsAjax 的 is_pending 僅計入 1 分鐘內的 pending reload_stock,逾時自動解鎖 2. updateSlot 重新下發時逾時舊指令標記 timeout、否則 superseded
This commit is contained in:
commit
fcff9a0fc6
@ -208,9 +208,12 @@ class MachineController extends AdminController
|
||||
->get();
|
||||
|
||||
// 取得該機台目前所有等待中的庫存更新指令 (Pending Commands)
|
||||
// 僅將「1 分鐘內」的 pending 視為鎖定中;超過 1 分鐘未收到機台回傳 (ACK)
|
||||
// 視為逾時,自動解除鎖定,讓使用者可重新編輯與重新下發 (與 dispense 逾時邏輯一致)
|
||||
$pendingSlotNos = \App\Models\Machine\RemoteCommand::where('machine_id', $machine->id)
|
||||
->where('command_type', 'reload_stock')
|
||||
->where('status', 'pending')
|
||||
->where('created_at', '>=', now()->subMinute())
|
||||
->get()
|
||||
->pluck('payload.slot_no')
|
||||
->flatten()
|
||||
|
||||
@ -510,10 +510,15 @@ class MachineService
|
||||
->first();
|
||||
|
||||
if ($pendingCommand) {
|
||||
// 直接覆蓋:將前一個尚未執行的指令標記為「已取代」
|
||||
// 重新下發時覆蓋前一筆尚未執行的指令。
|
||||
// 若舊指令已超過 1 分鐘未收到機台回傳 (ACK),視為逾時 (timeout);
|
||||
// 否則為使用者主動覆蓋 (superseded)。與 dispense 逾時邏輯一致。
|
||||
$isTimedOut = $pendingCommand->created_at->lt(now()->subMinute());
|
||||
$pendingCommand->update([
|
||||
'status' => 'superseded',
|
||||
'note' => __('Superseded by new command'),
|
||||
'status' => $isTimedOut ? 'timeout' : 'superseded',
|
||||
'note' => $isTimedOut
|
||||
? __('Superseded by new command (Timeout)')
|
||||
: __('Superseded by new command'),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user