star-cloud/app/Jobs/Machine/ProcessMachineError.php
sky121113 45b5ee5acd [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 目錄同步。
2026-04-21 16:35:20 +08:00

47 lines
1.2 KiB
PHP

<?php
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;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;
class ProcessMachineError implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $serialNo;
protected $payload;
/**
* Create a new job instance.
*/
public function __construct(string $serialNo, array $payload)
{
$this->serialNo = $serialNo;
$this->payload = $payload;
}
/**
* Execute the job.
*/
public function handle(MachineService $machineService): void
{
$machine = Machine::withoutGlobalScopes()->where('serial_no', $this->serialNo)->first();
if (!$machine) {
Log::warning("MQTT Error Report: Machine not found", ['serial_no' => $this->serialNo]);
return;
}
// 使用 MachineService 統一處理硬體代碼映射與記錄 (B013 核心邏輯)
$machineService->recordErrorLog($machine, $this->payload);
}
}