mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-27 01:50:31 +08:00
数据看板中增加升级信息
This commit is contained in:
@@ -3,6 +3,7 @@ package models
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/utils"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
"github.com/iwind/TeaGo/dbs"
|
||||
@@ -38,7 +39,7 @@ func init() {
|
||||
})
|
||||
}
|
||||
|
||||
// 启用条目
|
||||
// EnableAPINode 启用条目
|
||||
func (this *APINodeDAO) EnableAPINode(tx *dbs.Tx, id int64) error {
|
||||
_, err := this.Query(tx).
|
||||
Pk(id).
|
||||
@@ -47,7 +48,7 @@ func (this *APINodeDAO) EnableAPINode(tx *dbs.Tx, id int64) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// 禁用条目
|
||||
// DisableAPINode 禁用条目
|
||||
func (this *APINodeDAO) DisableAPINode(tx *dbs.Tx, id int64) error {
|
||||
_, err := this.Query(tx).
|
||||
Pk(id).
|
||||
@@ -56,7 +57,7 @@ func (this *APINodeDAO) DisableAPINode(tx *dbs.Tx, id int64) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// 查找启用中的条目
|
||||
// FindEnabledAPINode 查找启用中的条目
|
||||
func (this *APINodeDAO) FindEnabledAPINode(tx *dbs.Tx, id int64) (*APINode, error) {
|
||||
result, err := this.Query(tx).
|
||||
Pk(id).
|
||||
@@ -68,7 +69,7 @@ func (this *APINodeDAO) FindEnabledAPINode(tx *dbs.Tx, id int64) (*APINode, erro
|
||||
return result.(*APINode), err
|
||||
}
|
||||
|
||||
// 根据ID和Secret查找节点
|
||||
// FindEnabledAPINodeWithUniqueIdAndSecret 根据ID和Secret查找节点
|
||||
func (this *APINodeDAO) FindEnabledAPINodeWithUniqueIdAndSecret(tx *dbs.Tx, uniqueId string, secret string) (*APINode, error) {
|
||||
one, err := this.Query(tx).
|
||||
State(APINodeStateEnabled).
|
||||
@@ -81,7 +82,7 @@ func (this *APINodeDAO) FindEnabledAPINodeWithUniqueIdAndSecret(tx *dbs.Tx, uniq
|
||||
return one.(*APINode), nil
|
||||
}
|
||||
|
||||
// 根据主键查找名称
|
||||
// FindAPINodeName 根据主键查找名称
|
||||
func (this *APINodeDAO) FindAPINodeName(tx *dbs.Tx, id int64) (string, error) {
|
||||
return this.Query(tx).
|
||||
Pk(id).
|
||||
@@ -89,7 +90,7 @@ func (this *APINodeDAO) FindAPINodeName(tx *dbs.Tx, id int64) (string, error) {
|
||||
FindStringCol("")
|
||||
}
|
||||
|
||||
// 创建API节点
|
||||
// CreateAPINode 创建API节点
|
||||
func (this *APINodeDAO) CreateAPINode(tx *dbs.Tx, name string, description string, httpJSON []byte, httpsJSON []byte, restIsOn bool, restHTTPJSON []byte, restHTTPSJSON []byte, accessAddrsJSON []byte, isOn bool) (nodeId int64, err error) {
|
||||
uniqueId, err := this.genUniqueId(tx)
|
||||
if err != nil {
|
||||
@@ -134,7 +135,7 @@ func (this *APINodeDAO) CreateAPINode(tx *dbs.Tx, name string, description strin
|
||||
return types.Int64(op.Id), nil
|
||||
}
|
||||
|
||||
// 修改API节点
|
||||
// UpdateAPINode 修改API节点
|
||||
func (this *APINodeDAO) UpdateAPINode(tx *dbs.Tx, nodeId int64, name string, description string, httpJSON []byte, httpsJSON []byte, restIsOn bool, restHTTPJSON []byte, restHTTPSJSON []byte, accessAddrsJSON []byte, isOn bool) error {
|
||||
if nodeId <= 0 {
|
||||
return errors.New("invalid nodeId")
|
||||
@@ -177,7 +178,7 @@ func (this *APINodeDAO) UpdateAPINode(tx *dbs.Tx, nodeId int64, name string, des
|
||||
return err
|
||||
}
|
||||
|
||||
// 列出所有可用API节点
|
||||
// FindAllEnabledAPINodes 列出所有可用API节点
|
||||
func (this *APINodeDAO) FindAllEnabledAPINodes(tx *dbs.Tx) (result []*APINode, err error) {
|
||||
_, err = this.Query(tx).
|
||||
Attr("clusterId", 0). // 非集群专用
|
||||
@@ -189,7 +190,7 @@ func (this *APINodeDAO) FindAllEnabledAPINodes(tx *dbs.Tx) (result []*APINode, e
|
||||
return
|
||||
}
|
||||
|
||||
// 列出所有可用而且启用的API节点
|
||||
// FindAllEnabledAndOnAPINodes 列出所有可用而且启用的API节点
|
||||
func (this *APINodeDAO) FindAllEnabledAndOnAPINodes(tx *dbs.Tx) (result []*APINode, err error) {
|
||||
_, err = this.Query(tx).
|
||||
Attr("clusterId", 0). // 非集群专用
|
||||
@@ -202,14 +203,14 @@ func (this *APINodeDAO) FindAllEnabledAndOnAPINodes(tx *dbs.Tx) (result []*APINo
|
||||
return
|
||||
}
|
||||
|
||||
// 计算API节点数量
|
||||
// CountAllEnabledAPINodes 计算API节点数量
|
||||
func (this *APINodeDAO) CountAllEnabledAPINodes(tx *dbs.Tx) (int64, error) {
|
||||
return this.Query(tx).
|
||||
State(APINodeStateEnabled).
|
||||
Count()
|
||||
}
|
||||
|
||||
// 列出单页的API节点
|
||||
// ListEnabledAPINodes 列出单页的API节点
|
||||
func (this *APINodeDAO) ListEnabledAPINodes(tx *dbs.Tx, offset int64, size int64) (result []*APINode, err error) {
|
||||
_, err = this.Query(tx).
|
||||
Attr("clusterId", 0). // 非集群专用
|
||||
@@ -223,7 +224,7 @@ func (this *APINodeDAO) ListEnabledAPINodes(tx *dbs.Tx, offset int64, size int64
|
||||
return
|
||||
}
|
||||
|
||||
// 根据主机名和端口获取ID
|
||||
// FindEnabledAPINodeIdWithAddr 根据主机名和端口获取ID
|
||||
func (this *APINodeDAO) FindEnabledAPINodeIdWithAddr(tx *dbs.Tx, protocol string, host string, port int) (int64, error) {
|
||||
addr := maps.Map{
|
||||
"protocol": protocol,
|
||||
@@ -250,7 +251,7 @@ func (this *APINodeDAO) FindEnabledAPINodeIdWithAddr(tx *dbs.Tx, protocol string
|
||||
return int64(one.(*APINode).Id), nil
|
||||
}
|
||||
|
||||
// 设置API节点状态
|
||||
// UpdateAPINodeStatus 设置API节点状态
|
||||
func (this *APINodeDAO) UpdateAPINodeStatus(tx *dbs.Tx, apiNodeId int64, statusJSON []byte) error {
|
||||
_, err := this.Query(tx).
|
||||
Pk(apiNodeId).
|
||||
@@ -275,3 +276,13 @@ func (this *APINodeDAO) genUniqueId(tx *dbs.Tx) (string, error) {
|
||||
return uniqueId, nil
|
||||
}
|
||||
}
|
||||
|
||||
// CountAllLowerVersionNodes 计算所有节点中低于某个版本的节点数量
|
||||
func (this *APINodeDAO) CountAllLowerVersionNodes(tx *dbs.Tx, version string) (int64, error) {
|
||||
return this.Query(tx).
|
||||
State(APINodeStateEnabled).
|
||||
Where("status IS NOT NULL").
|
||||
Where("(JSON_EXTRACT(status, '$.buildVersionCode') IS NULL OR JSON_EXTRACT(status, '$.buildVersionCode')<:version)").
|
||||
Param("version", utils.VersionToLong(version)).
|
||||
Count()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user