fix(host): 防止主节点重复并修复 setMaster 权限

Clear all is_master flags before electing new master to prevent multiple master records. Fix setMaster annotation from @auth true to proper @NodeAnotation format so permission node is generated correctly.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
augushong
2026-05-26 18:28:42 +08:00
parent a47bbb2c6a
commit e558a97e91
2 changed files with 11 additions and 0 deletions

View File

@@ -10,4 +10,13 @@ use base\admin\controller\system\HostBase;
*/
class Host extends HostBase
{
/**
* 设置主节点.
*
* @\app\admin\service\annotation\NodeAnotation(title="设置主节点")
*/
public function setMaster()
{
return parent::setMaster();
}
}

View File

@@ -79,6 +79,8 @@ class HostServiceBase
// 主节点自动选举:若无在线主节点,当前节点自动成为主节点
$master = SystemHost::where('is_master', 1)->where('status', 1)->find();
if (empty($master)) {
// 先清除所有旧的主节点标记(含已离线的),避免出现多个 is_master=1
SystemHost::where('is_master', 1)->update(['is_master' => 0]);
$host->is_master = 1;
$host->save();
Log::info("节点 [{$nodeId}] 自动当选为主节点。");