mirror of
				https://github.com/TeaOSLab/EdgeAPI.git
				synced 2025-11-04 07:50:25 +08:00 
			
		
		
		
	节点状态中增加时间戳字段
This commit is contained in:
		@@ -1,6 +1,7 @@
 | 
			
		||||
package authority
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"encoding/json"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeAPI/internal/db/models"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeAPI/internal/errors"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeAPI/internal/utils"
 | 
			
		||||
@@ -188,13 +189,19 @@ func (this *AuthorityNodeDAO) GenUniqueId(tx *dbs.Tx) (string, error) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// UpdateNodeStatus 更改节点状态
 | 
			
		||||
func (this *AuthorityNodeDAO) UpdateNodeStatus(tx *dbs.Tx, nodeId int64, statusJSON []byte) error {
 | 
			
		||||
	if statusJSON == nil {
 | 
			
		||||
func (this *AuthorityNodeDAO) UpdateNodeStatus(tx *dbs.Tx, nodeId int64, nodeStatus *nodeconfigs.NodeStatus) error {
 | 
			
		||||
	if nodeStatus == nil {
 | 
			
		||||
		return nil
 | 
			
		||||
	}
 | 
			
		||||
	_, err := this.Query(tx).
 | 
			
		||||
 | 
			
		||||
	nodeStatusJSON, err := json.Marshal(nodeStatus)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	_, err = this.Query(tx).
 | 
			
		||||
		Pk(nodeId).
 | 
			
		||||
		Set("status", string(statusJSON)).
 | 
			
		||||
		Set("status", nodeStatusJSON).
 | 
			
		||||
		Update()
 | 
			
		||||
	return err
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -813,11 +813,20 @@ func (this *NodeDAO) CountAllEnabledNodesMatch(tx *dbs.Tx,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// UpdateNodeStatus 更改节点状态
 | 
			
		||||
func (this *NodeDAO) UpdateNodeStatus(tx *dbs.Tx, nodeId int64, statusJSON []byte) error {
 | 
			
		||||
	_, err := this.Query(tx).
 | 
			
		||||
func (this *NodeDAO) UpdateNodeStatus(tx *dbs.Tx, nodeId int64, nodeStatus *nodeconfigs.NodeStatus) error {
 | 
			
		||||
	if nodeStatus == nil {
 | 
			
		||||
		return nil
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	nodeStatusJSON, err := json.Marshal(nodeStatus)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	_, err = this.Query(tx).
 | 
			
		||||
		Pk(nodeId).
 | 
			
		||||
		Set("isActive", true).
 | 
			
		||||
		Set("status", string(statusJSON)).
 | 
			
		||||
		Set("status", nodeStatusJSON).
 | 
			
		||||
		Update()
 | 
			
		||||
	return err
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -339,13 +339,19 @@ func (this *NSNodeDAO) UpdateNodeIsInstalled(tx *dbs.Tx, nodeId int64, isInstall
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// UpdateNodeStatus 更改节点状态
 | 
			
		||||
func (this NSNodeDAO) UpdateNodeStatus(tx *dbs.Tx, nodeId int64, statusJSON []byte) error {
 | 
			
		||||
	if statusJSON == nil {
 | 
			
		||||
func (this NSNodeDAO) UpdateNodeStatus(tx *dbs.Tx, nodeId int64, nodeStatus *nodeconfigs.NodeStatus) error {
 | 
			
		||||
	if nodeStatus == nil {
 | 
			
		||||
		return nil
 | 
			
		||||
	}
 | 
			
		||||
	_, err := this.Query(tx).
 | 
			
		||||
 | 
			
		||||
	nodeStatusJSON, err := json.Marshal(nodeStatus)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	_, err = this.Query(tx).
 | 
			
		||||
		Pk(nodeId).
 | 
			
		||||
		Set("status", string(statusJSON)).
 | 
			
		||||
		Set("status", nodeStatusJSON).
 | 
			
		||||
		Update()
 | 
			
		||||
	return err
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -264,13 +264,19 @@ func (this *ReportNodeDAO) FindEnabledNodeIdWithUniqueId(tx *dbs.Tx, uniqueId st
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// UpdateNodeStatus 更改节点状态
 | 
			
		||||
func (this ReportNodeDAO) UpdateNodeStatus(tx *dbs.Tx, nodeId int64, statusJSON []byte) error {
 | 
			
		||||
	if statusJSON == nil {
 | 
			
		||||
func (this ReportNodeDAO) UpdateNodeStatus(tx *dbs.Tx, nodeId int64, nodeStatus *reporterconfigs.Status) error {
 | 
			
		||||
	if nodeStatus == nil {
 | 
			
		||||
		return nil
 | 
			
		||||
	}
 | 
			
		||||
	_, err := this.Query(tx).
 | 
			
		||||
 | 
			
		||||
	nodeStatusJSON, err := json.Marshal(nodeStatus)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	_, err = this.Query(tx).
 | 
			
		||||
		Pk(nodeId).
 | 
			
		||||
		Set("status", string(statusJSON)).
 | 
			
		||||
		Set("status", nodeStatusJSON).
 | 
			
		||||
		Update()
 | 
			
		||||
	return err
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -254,13 +254,19 @@ func (this *UserNodeDAO) GenUniqueId(tx *dbs.Tx) (string, error) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// UpdateNodeStatus 更改节点状态
 | 
			
		||||
func (this *UserNodeDAO) UpdateNodeStatus(tx *dbs.Tx, nodeId int64, statusJSON []byte) error {
 | 
			
		||||
	if len(statusJSON) == 0 {
 | 
			
		||||
func (this *UserNodeDAO) UpdateNodeStatus(tx *dbs.Tx, nodeId int64, nodeStatus *nodeconfigs.NodeStatus) error {
 | 
			
		||||
	if nodeStatus == nil {
 | 
			
		||||
		return nil
 | 
			
		||||
	}
 | 
			
		||||
	_, err := this.Query(tx).
 | 
			
		||||
 | 
			
		||||
	nodeStatusJSON, err := json.Marshal(nodeStatus)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	_, err = this.Query(tx).
 | 
			
		||||
		Pk(nodeId).
 | 
			
		||||
		Set("status", string(statusJSON)).
 | 
			
		||||
		Set("status", nodeStatusJSON).
 | 
			
		||||
		Update()
 | 
			
		||||
	return err
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -18,6 +18,7 @@ import (
 | 
			
		||||
	stringutil "github.com/iwind/TeaGo/utils/string"
 | 
			
		||||
	"io"
 | 
			
		||||
	"path/filepath"
 | 
			
		||||
	"time"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// NSNodeService 域名服务器节点服务
 | 
			
		||||
@@ -398,9 +399,18 @@ func (this *NSNodeService) UpdateNSNodeStatus(ctx context.Context, req *pb.Updat
 | 
			
		||||
		return nil, errors.New("'nodeId' should be greater than 0")
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	tx := this.NullTx()
 | 
			
		||||
	var tx = this.NullTx()
 | 
			
		||||
 | 
			
		||||
	err = models.SharedNSNodeDAO.UpdateNodeStatus(tx, nodeId, req.StatusJSON)
 | 
			
		||||
	// 修改时间戳
 | 
			
		||||
	var nodeStatus = &nodeconfigs.NodeStatus{}
 | 
			
		||||
	err = json.Unmarshal(req.StatusJSON, nodeStatus)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, errors.New("decode node status json failed: " + err.Error())
 | 
			
		||||
	}
 | 
			
		||||
	nodeStatus.UpdatedAt = time.Now().Unix()
 | 
			
		||||
 | 
			
		||||
	// 保存
 | 
			
		||||
	err = models.SharedNSNodeDAO.UpdateNodeStatus(tx, nodeId, nodeStatus)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -2,11 +2,14 @@ package services
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"context"
 | 
			
		||||
	"encoding/json"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeAPI/internal/db/models/authority"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeAPI/internal/errors"
 | 
			
		||||
	rpcutils "github.com/TeaOSLab/EdgeAPI/internal/rpc/utils"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
 | 
			
		||||
	"google.golang.org/grpc/metadata"
 | 
			
		||||
	"time"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type AuthorityNodeService struct {
 | 
			
		||||
@@ -223,9 +226,18 @@ func (this *AuthorityNodeService) UpdateAuthorityNodeStatus(ctx context.Context,
 | 
			
		||||
		return nil, errors.New("'nodeId' should be greater than 0")
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	tx := this.NullTx()
 | 
			
		||||
	var tx = this.NullTx()
 | 
			
		||||
 | 
			
		||||
	err = authority.SharedAuthorityNodeDAO.UpdateNodeStatus(tx, nodeId, req.StatusJSON)
 | 
			
		||||
	// 修改时间戳
 | 
			
		||||
	var nodeStatus = &nodeconfigs.NodeStatus{}
 | 
			
		||||
	err = json.Unmarshal(req.StatusJSON, nodeStatus)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, errors.New("decode node status json failed: " + err.Error())
 | 
			
		||||
	}
 | 
			
		||||
	nodeStatus.UpdatedAt = time.Now().Unix()
 | 
			
		||||
 | 
			
		||||
	// 保存
 | 
			
		||||
	err = authority.SharedAuthorityNodeDAO.UpdateNodeStatus(tx, nodeId, nodeStatus)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -10,6 +10,7 @@ import (
 | 
			
		||||
	"github.com/TeaOSLab/EdgeAPI/internal/errors"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeAPI/internal/goman"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeAPI/internal/installers"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeAPI/internal/remotelogs"
 | 
			
		||||
	rpcutils "github.com/TeaOSLab/EdgeAPI/internal/rpc/utils"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeAPI/internal/utils"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeAPI/internal/utils/numberutils"
 | 
			
		||||
@@ -21,7 +22,6 @@ import (
 | 
			
		||||
	"github.com/andybalholm/brotli"
 | 
			
		||||
	"github.com/iwind/TeaGo/dbs"
 | 
			
		||||
	"github.com/iwind/TeaGo/lists"
 | 
			
		||||
	"github.com/iwind/TeaGo/logs"
 | 
			
		||||
	"github.com/iwind/TeaGo/types"
 | 
			
		||||
	stringutil "github.com/iwind/TeaGo/utils/string"
 | 
			
		||||
	"io"
 | 
			
		||||
@@ -775,7 +775,7 @@ func (this *NodeService) FindCurrentNodeConfig(ctx context.Context, req *pb.Find
 | 
			
		||||
// UpdateNodeStatus 更新节点状态
 | 
			
		||||
func (this *NodeService) UpdateNodeStatus(ctx context.Context, req *pb.UpdateNodeStatusRequest) (*pb.RPCSuccess, error) {
 | 
			
		||||
	// 校验节点
 | 
			
		||||
	_, _, nodeId, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeNode)
 | 
			
		||||
	nodeId, err := this.ValidateNode(ctx)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
@@ -788,9 +788,18 @@ func (this *NodeService) UpdateNodeStatus(ctx context.Context, req *pb.UpdateNod
 | 
			
		||||
		return nil, errors.New("'nodeId' should be greater than 0")
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	tx := this.NullTx()
 | 
			
		||||
	var tx = this.NullTx()
 | 
			
		||||
 | 
			
		||||
	err = models.SharedNodeDAO.UpdateNodeStatus(tx, nodeId, req.StatusJSON)
 | 
			
		||||
	// 修改时间戳
 | 
			
		||||
	var nodeStatus = &nodeconfigs.NodeStatus{}
 | 
			
		||||
	err = json.Unmarshal(req.StatusJSON, nodeStatus)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, errors.New("decode node status json failed: " + err.Error())
 | 
			
		||||
	}
 | 
			
		||||
	nodeStatus.UpdatedAt = time.Now().Unix()
 | 
			
		||||
 | 
			
		||||
	// 保存
 | 
			
		||||
	err = models.SharedNodeDAO.UpdateNodeStatus(tx, nodeId, nodeStatus)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
@@ -825,7 +834,7 @@ func (this *NodeService) InstallNode(ctx context.Context, req *pb.InstallNodeReq
 | 
			
		||||
	goman.New(func() {
 | 
			
		||||
		err = installers.SharedNodeQueue().InstallNodeProcess(req.NodeId, false)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			logs.Println("[RPC]install node:" + err.Error())
 | 
			
		||||
			remotelogs.Error("NODE_SERVICE", "install node failed:"+err.Error())
 | 
			
		||||
		}
 | 
			
		||||
	})
 | 
			
		||||
 | 
			
		||||
@@ -865,7 +874,7 @@ func (this *NodeService) UpgradeNode(ctx context.Context, req *pb.UpgradeNodeReq
 | 
			
		||||
	goman.New(func() {
 | 
			
		||||
		err = installers.SharedNodeQueue().InstallNodeProcess(req.NodeId, true)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			logs.Println("[RPC]install node:" + err.Error())
 | 
			
		||||
			remotelogs.Error("NODE_SERVICE", "install node:"+err.Error())
 | 
			
		||||
		}
 | 
			
		||||
	})
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -2,11 +2,14 @@ package services
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"context"
 | 
			
		||||
	"encoding/json"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeAPI/internal/db/models"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeAPI/internal/errors"
 | 
			
		||||
	rpcutils "github.com/TeaOSLab/EdgeAPI/internal/rpc/utils"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
 | 
			
		||||
	"google.golang.org/grpc/metadata"
 | 
			
		||||
	"time"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type UserNodeService struct {
 | 
			
		||||
@@ -259,9 +262,18 @@ func (this *UserNodeService) UpdateUserNodeStatus(ctx context.Context, req *pb.U
 | 
			
		||||
		return nil, errors.New("'nodeId' should be greater than 0")
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	tx := this.NullTx()
 | 
			
		||||
	var tx = this.NullTx()
 | 
			
		||||
 | 
			
		||||
	err = models.SharedUserNodeDAO.UpdateNodeStatus(tx, nodeId, req.StatusJSON)
 | 
			
		||||
	// 修改时间戳
 | 
			
		||||
	var nodeStatus = &nodeconfigs.NodeStatus{}
 | 
			
		||||
	err = json.Unmarshal(req.StatusJSON, nodeStatus)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, errors.New("decode node status json failed: " + err.Error())
 | 
			
		||||
	}
 | 
			
		||||
	nodeStatus.UpdatedAt = time.Now().Unix()
 | 
			
		||||
 | 
			
		||||
	// 保存
 | 
			
		||||
	err = models.SharedUserNodeDAO.UpdateNodeStatus(tx, nodeId, nodeStatus)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user