同步 receiveSwitch 當 Error 把連線清除 20250605

This commit is contained in:
allen.yan 2025-06-05 09:28:21 +08:00
parent 39872d5aac
commit de64bf2d45
3 changed files with 13 additions and 7 deletions

View File

@ -8,7 +8,7 @@ use App\Enums\Traits\HasLabels;
* @OA\Schema( * @OA\Schema(
* schema="RoomStatus", * schema="RoomStatus",
* type="string", * type="string",
* enum={"active", "closed", "fire", "maintenance"}, * enum={"active", "closed", "fire", "error"},
* example="error" * example="error"
* ) * )
*/ */

View File

@ -305,10 +305,16 @@ class RoomControlController extends Controller
if (!$room) { if (!$room) {
return ApiResponse::error('房間不存在'); return ApiResponse::error('房間不存在');
} }
if($validated['command']==='error'){
$room->status=$validated['command']; $room->is_online=0;
$room->started_at=$validated['started_at']; $room->status=$validated['command'];
$room->ended_at=$validated['ended_at']; $room->started_at=null;
$room->ended_at=null;
}else{
$room->status=$validated['command'];
$room->started_at=$validated['started_at'];
$room->ended_at=$validated['ended_at'];
}
$room->save(); $room->save();
return ApiResponse::success($room); return ApiResponse::success($room);

View File

@ -10,7 +10,7 @@ use Illuminate\Foundation\Http\FormRequest;
* required={"branch_name", "room_name", "command"}, * required={"branch_name", "room_name", "command"},
* @OA\Property(property="branch_name", type="string", example="測試"), * @OA\Property(property="branch_name", type="string", example="測試"),
* @OA\Property(property="room_name", type="string", example="pc102"), * @OA\Property(property="room_name", type="string", example="pc102"),
* @OA\Property(property="command", type="string", enum={"active", "closed", "fire", "maintenance"}, example="active"), * @OA\Property(property="command", type="string", enum={"active", "closed", "fire", "error"}, example="active"),
* @OA\Property(property="started_at", type="string", nullable=true, example="2025-05-19 09:31:00"), * @OA\Property(property="started_at", type="string", nullable=true, example="2025-05-19 09:31:00"),
* @OA\Property(property="ended_at", type="string", nullable=true, example="2025-05-19 09:31:00") * @OA\Property(property="ended_at", type="string", nullable=true, example="2025-05-19 09:31:00")
* ) * )
@ -27,7 +27,7 @@ class SendRoomSwitchCommandRequest extends ApiRequest
return [ return [
'branch_name' => ['required','string','exists:branches,name'], 'branch_name' => ['required','string','exists:branches,name'],
'room_name' => ['required','string'], 'room_name' => ['required','string'],
'command' => ['required','in:active,closed,fire'], 'command' => ['required','in:active,closed,fire,error'],
'started_at'=> ['nullable','date_format:Y-m-d H:i:s'], 'started_at'=> ['nullable','date_format:Y-m-d H:i:s'],
'ended_at' => ['nullable','date_format:Y-m-d H:i:s'], 'ended_at' => ['nullable','date_format:Y-m-d H:i:s'],
]; ];