diff --git a/.agents/skills/mqtt-communication-specs/SKILL.md b/.agents/skills/mqtt-communication-specs/SKILL.md index ad4f076..979f8a3 100644 --- a/.agents/skills/mqtt-communication-specs/SKILL.md +++ b/.agents/skills/mqtt-communication-specs/SKILL.md @@ -124,17 +124,18 @@ Mqtt3Client client = MqttClient.builder() > [!NOTE] > 為了降低傳輸開銷,目前僅要求上報 **韌體版本** 與 **溫度**。其餘狀態如連線/斷線已透過 LWT 與 $SYS 事件處理。 -### 3.2 異常上報 (Error/Event) - `machine/{id}/error` -比照原 B013 邏輯。 +### 3.2 異常與錯誤上報 (B013) +當機台發生硬體故障(如卡貨、通訊中斷)時,發布至此 Topic。 -```json -{ - "tid": 12, - "error_code": "0403", - "log": "Slot jammed at slot 12", - "timestamp": "2026-04-14T09:05:00+08:00" -} -``` +- **Topic**: `machine/{serial_no}/error` +- **Payload (JSON)**: + ```json + { + "tid": 12, + "error_code": "0403" + } + ``` + *(註:`error_code` 應遵循 `MachineService::ERROR_CODE_MAP` 定義,雲端將自動轉換為對應語言標籤。`tid` 為貨道或任務 ID。)* ### 3.3 雲端指令 (Downstream Commands) - `machine/{id}/command` 這是雲端主動下發給機台的訊息,取代原本 B010 Response 的輪詢等待。 diff --git a/app/Jobs/Machine/ProcessMachineError.php b/app/Jobs/Machine/ProcessMachineError.php index 732b47f..0b927d6 100644 --- a/app/Jobs/Machine/ProcessMachineError.php +++ b/app/Jobs/Machine/ProcessMachineError.php @@ -3,6 +3,8 @@ namespace App\Jobs\Machine; use App\Models\Machine\Machine; +use App\Services\Machine\MachineService; + use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; @@ -29,7 +31,7 @@ class ProcessMachineError implements ShouldQueue /** * Execute the job. */ - public function handle(): void + public function handle(MachineService $machineService): void { $machine = Machine::withoutGlobalScopes()->where('serial_no', $this->serialNo)->first(); @@ -38,18 +40,7 @@ class ProcessMachineError implements ShouldQueue return; } - $message = $this->payload['message'] ?? 'Unknown error'; - $errorCode = $this->payload['error_code'] ?? 'E000'; - $level = $this->payload['level'] ?? 'error'; - - // 記錄到機台日誌 (使用翻譯友善格式) - ProcessStateLog::dispatch( - $machine->id, - $machine->company_id, - "Error: :message (:code)", - $level, - ['message' => __($message), 'code' => $errorCode], - 'error' - ); + // 使用 MachineService 統一處理硬體代碼映射與記錄 (B013 核心邏輯) + $machineService->recordErrorLog($machine, $this->payload); } }