feat(admin-frontend): 新增节点自动上线托管能力
为节点新增 auto_online 字段与后台同步任务, 仅对开启托管的节点按在线状态自动同步前台显示。 管理端补齐单节点与批量开关、列表标识与统计, 并在自动上线启用时禁用手动显隐切换。 后端新增定时命令、保存校验、批量更新支持、 数据库迁移与单元测试,保证托管逻辑可落地。
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Server;
|
||||
|
||||
class ServerAutoOnlineService
|
||||
{
|
||||
public function sync(): array
|
||||
{
|
||||
$servers = Server::query()
|
||||
->where('auto_online', true)
|
||||
->get();
|
||||
|
||||
$result = [
|
||||
'total' => $servers->count(),
|
||||
'updated' => 0,
|
||||
'shown' => 0,
|
||||
'hidden' => 0,
|
||||
'unchanged' => 0,
|
||||
];
|
||||
|
||||
foreach ($servers as $server) {
|
||||
$shouldShow = (int) $server->available_status !== Server::STATUS_OFFLINE;
|
||||
|
||||
if ((bool) $server->show === $shouldShow) {
|
||||
$result['unchanged']++;
|
||||
continue;
|
||||
}
|
||||
|
||||
$server->show = $shouldShow;
|
||||
$server->save();
|
||||
|
||||
$result['updated']++;
|
||||
$shouldShow ? $result['shown']++ : $result['hidden']++;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user