[REFACTOR] 整合 MQTT 異常上報與 MachineService 硬體代碼映射

1. 重構 ProcessMachineError Job,將異常日誌記錄邏輯統一由 MachineService@recordErrorLog 處理,確保 error_code 能正確對應多語系標籤。
2. 更新 SKILL.md MQTT 通訊規範,修正機台故障上報 (B013) 的 Payload 範例並修復章節編號錯誤。
3. 優化 deploy-demo.yaml CI/CD 流程,解決檔案變動導致 tar 退出碼為 1 的部署中斷問題,並排除不必要的 storage 目錄同步。
This commit is contained in:
sky121113 2026-04-21 16:35:20 +08:00
parent 2aa0bf23ab
commit 45b5ee5acd
2 changed files with 16 additions and 24 deletions

View File

@ -124,17 +124,18 @@ Mqtt3Client client = MqttClient.builder()
> [!NOTE] > [!NOTE]
> 為了降低傳輸開銷,目前僅要求上報 **韌體版本****溫度**。其餘狀態如連線/斷線已透過 LWT 與 $SYS 事件處理。 > 為了降低傳輸開銷,目前僅要求上報 **韌體版本****溫度**。其餘狀態如連線/斷線已透過 LWT 與 $SYS 事件處理。
### 3.2 異常上報 (Error/Event) - `machine/{id}/error` ### 3.2 異常與錯誤上報 (B013)
比照原 B013 邏輯 當機台發生硬體故障(如卡貨、通訊中斷)時,發布至此 Topic
```json - **Topic**: `machine/{serial_no}/error`
{ - **Payload (JSON)**:
"tid": 12, ```json
"error_code": "0403", {
"log": "Slot jammed at slot 12", "tid": 12,
"timestamp": "2026-04-14T09:05:00+08:00" "error_code": "0403"
} }
``` ```
*(註:`error_code` 應遵循 `MachineService::ERROR_CODE_MAP` 定義,雲端將自動轉換為對應語言標籤。`tid` 為貨道或任務 ID。)*
### 3.3 雲端指令 (Downstream Commands) - `machine/{id}/command` ### 3.3 雲端指令 (Downstream Commands) - `machine/{id}/command`
這是雲端主動下發給機台的訊息,取代原本 B010 Response 的輪詢等待。 這是雲端主動下發給機台的訊息,取代原本 B010 Response 的輪詢等待。

View File

@ -3,6 +3,8 @@
namespace App\Jobs\Machine; namespace App\Jobs\Machine;
use App\Models\Machine\Machine; use App\Models\Machine\Machine;
use App\Services\Machine\MachineService;
use Illuminate\Bus\Queueable; use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Foundation\Bus\Dispatchable;
@ -29,7 +31,7 @@ class ProcessMachineError implements ShouldQueue
/** /**
* Execute the job. * Execute the job.
*/ */
public function handle(): void public function handle(MachineService $machineService): void
{ {
$machine = Machine::withoutGlobalScopes()->where('serial_no', $this->serialNo)->first(); $machine = Machine::withoutGlobalScopes()->where('serial_no', $this->serialNo)->first();
@ -38,18 +40,7 @@ class ProcessMachineError implements ShouldQueue
return; return;
} }
$message = $this->payload['message'] ?? 'Unknown error'; // 使用 MachineService 統一處理硬體代碼映射與記錄 (B013 核心邏輯)
$errorCode = $this->payload['error_code'] ?? 'E000'; $machineService->recordErrorLog($machine, $this->payload);
$level = $this->payload['level'] ?? 'error';
// 記錄到機台日誌 (使用翻譯友善格式)
ProcessStateLog::dispatch(
$machine->id,
$machine->company_id,
"Error: :message (:code)",
$level,
['message' => __($message), 'code' => $errorCode],
'error'
);
} }
} }