From de64bf2d45a2eeef5c7451f9d9852ce4aefd44b4 Mon Sep 17 00:00:00 2001 From: "allen.yan" Date: Thu, 5 Jun 2025 09:28:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8C=E6=AD=A5=20receiveSwitch=20=E7=95=B6?= =?UTF-8?q?=20Error=20=E6=8A=8A=E9=80=A3=E7=B7=9A=E6=B8=85=E9=99=A4=202025?= =?UTF-8?q?0605?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Enums/RoomStatus.php | 2 +- app/Http/Controllers/RoomControlController.php | 14 ++++++++++---- app/Http/Requests/SendRoomSwitchCommandRequest.php | 4 ++-- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/app/Enums/RoomStatus.php b/app/Enums/RoomStatus.php index 72ae246..3339443 100644 --- a/app/Enums/RoomStatus.php +++ b/app/Enums/RoomStatus.php @@ -8,7 +8,7 @@ use App\Enums\Traits\HasLabels; * @OA\Schema( * schema="RoomStatus", * type="string", - * enum={"active", "closed", "fire", "maintenance"}, + * enum={"active", "closed", "fire", "error"}, * example="error" * ) */ diff --git a/app/Http/Controllers/RoomControlController.php b/app/Http/Controllers/RoomControlController.php index 9403583..cd35a74 100644 --- a/app/Http/Controllers/RoomControlController.php +++ b/app/Http/Controllers/RoomControlController.php @@ -305,10 +305,16 @@ class RoomControlController extends Controller if (!$room) { return ApiResponse::error('房間不存在'); } - - $room->status=$validated['command']; - $room->started_at=$validated['started_at']; - $room->ended_at=$validated['ended_at']; + if($validated['command']==='error'){ + $room->is_online=0; + $room->status=$validated['command']; + $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(); return ApiResponse::success($room); diff --git a/app/Http/Requests/SendRoomSwitchCommandRequest.php b/app/Http/Requests/SendRoomSwitchCommandRequest.php index 049d84a..07b8bcc 100644 --- a/app/Http/Requests/SendRoomSwitchCommandRequest.php +++ b/app/Http/Requests/SendRoomSwitchCommandRequest.php @@ -10,7 +10,7 @@ use Illuminate\Foundation\Http\FormRequest; * required={"branch_name", "room_name", "command"}, * @OA\Property(property="branch_name", type="string", example="測試"), * @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="ended_at", type="string", nullable=true, example="2025-05-19 09:31:00") * ) @@ -27,7 +27,7 @@ class SendRoomSwitchCommandRequest extends ApiRequest return [ 'branch_name' => ['required','string','exists:branches,name'], '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'], 'ended_at' => ['nullable','date_format:Y-m-d H:i:s'], ];