傳後台 room 資料同步 20250605
This commit is contained in:
parent
7d16775378
commit
42338c62b4
@ -32,18 +32,13 @@ class CheckRoomOnlineStatus extends Command
|
||||
$room->is_online = false;
|
||||
$room->status = RoomStatus::Error;
|
||||
$room->save();
|
||||
|
||||
$response = (new MachineStatusForwarder(
|
||||
$branch->external_ip ?? '',
|
||||
'/api/room/receiveSwitch',
|
||||
[
|
||||
'branch_name' => $branch->name,
|
||||
'room_name' => $room->type->value.$room->name,
|
||||
'command' => 'error',
|
||||
]
|
||||
))->forward();
|
||||
$this->info("Room [{$room->name}] marked as offline (no recent MachineStatus)");
|
||||
}
|
||||
$response = (new MachineStatusForwarder(
|
||||
$branch->external_ip ?? '',
|
||||
'/api/room/receiveSwitch',
|
||||
$room->toArray()
|
||||
))->forward();
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -200,8 +200,15 @@ class RoomControlController extends Controller
|
||||
$room->is_online=1;
|
||||
$room->touch(); // 更新 updated_at
|
||||
$room->save();
|
||||
$response = (
|
||||
new MachineStatusForwarder(
|
||||
$branch->external_ip ?? '',
|
||||
'/api/room/receiveSwitch',
|
||||
$room->toArray()
|
||||
)
|
||||
)->forward();
|
||||
}
|
||||
|
||||
|
||||
return ApiResponse::success([
|
||||
'data' => MachineStatus::create($validated),
|
||||
]);
|
||||
@ -309,7 +316,11 @@ class RoomControlController extends Controller
|
||||
$room->started_at=$validated['started_at'];
|
||||
$room->ended_at=$validated['ended_at'];
|
||||
$room->save();
|
||||
$response = (new MachineStatusForwarder($branch->external_ip, "/api/room/receiveSwitch", $validated))->forward();
|
||||
$response = (new MachineStatusForwarder(
|
||||
$branch->external_ip,
|
||||
"/api/room/receiveSwitch",
|
||||
$room->toArray()
|
||||
))->forward();
|
||||
return $validated['command']==='error' ? ApiResponse::error('機房控制失敗') : ApiResponse::success($room);
|
||||
}
|
||||
}
|
||||
|
@ -27,9 +27,7 @@ class MachineStatusForwarder
|
||||
$parsed = parse_url($this->externalUrl);
|
||||
$hostParts = explode('.', $parsed['host']);
|
||||
|
||||
$mainDomain = count($hostParts) >= 3
|
||||
? implode('.', array_slice($hostParts, 1))
|
||||
: $parsed['host'];
|
||||
$mainDomain = implode('.', array_slice($hostParts, 1));
|
||||
|
||||
$mainDomainUrl = "{$parsed['scheme']}://{$mainDomain}";
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user