From 3a706d3378aa3626501370352963883fd2783558 Mon Sep 17 00:00:00 2001 From: zhangzengfei <zhangzengfei@smartai.com> Date: 星期二, 28 十一月 2023 11:24:49 +0800 Subject: [PATCH] 添加appcenter,完善算法上传下载功能 --- system-service/models/node.go | 31 +++++++++++++++++++++++++++++-- 1 files changed, 29 insertions(+), 2 deletions(-) diff --git a/system-service/models/node.go b/system-service/models/node.go index 24d8af4..b24f926 100644 --- a/system-service/models/node.go +++ b/system-service/models/node.go @@ -22,6 +22,7 @@ IsDelete bool `gorm:"column:isDelete;default:0" json:"isDelete"` DeviceType string `gorm:"column:device_type" json:"device_type"` //璁惧鍨嬪彿` DriftState string `gorm:"column:drift_state" json:"drift_state"` //婕傜Щ鐘舵��, master,backup + Online bool `gorm:"column:online;default:1" json:"online"` //鍦ㄧ嚎鐘舵�� } func (Node) TableName() string { @@ -43,9 +44,35 @@ return nodes, nil } -func (n *Node) UpdateDriftStateByNodeId(driftState string, nodeId string) bool { +func (n *Node) FindNodes() (nodes []Node, err error) { + if err = db.Raw("select * from cluster_node").Scan(&nodes).Error; err != nil { + return nil, err + } + return nodes, nil +} + +func (n *Node) FindFirstNode() (node Node, err error) { + if err = db.Raw("select * from cluster_node where isDelete=0 order by create_time limit 1").Scan(&node).Error; err != nil { + return node, err + } + return node, nil +} + +func (n *Node) FindNodeById(id string) (node Node, err error) { + if err = db.Raw("select * from cluster_node where id=?", id).Scan(&node).Error; err != nil { + return node, err + } + return node, nil +} + +func (n *Node) UpdateDriftStateByNodeId(driftState string, nodeId string, sync bool) bool { var err error tx := GetDB().Begin() + if !sync { + GetDB().LogMode(false) + defer db.LogMode(true) + } + defer func() { if err != nil && tx != nil { logger.Error("updateDriftState err:", err) @@ -56,7 +83,7 @@ if err = tx.Exec("update "+n.TableName()+" set drift_state=? where id=?", driftState, nodeId).Error; err != nil { return false } - if err = tx.Exec("update "+n.TableName()+" set drift_state='backup' where id !=?", nodeId).Error; err != nil { + if err = tx.Exec("update "+n.TableName()+" set drift_state='slave' where id !=?", nodeId).Error; err != nil { return false } } else { -- Gitblit v1.8.0