mirror of
				https://github.com/TeaOSLab/EdgeAPI.git
				synced 2025-11-04 16:00:24 +08:00 
			
		
		
		
	[边缘节点]可以同时通过关键词搜索集群和节点
This commit is contained in:
		@@ -167,16 +167,25 @@ func (this *NodeClusterDAO) UpdateCluster(clusterId int64, name string, grantId
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 计算所有集群数量
 | 
			
		||||
func (this *NodeClusterDAO) CountAllEnabledClusters() (int64, error) {
 | 
			
		||||
	return this.Query().
 | 
			
		||||
		State(NodeClusterStateEnabled).
 | 
			
		||||
		Count()
 | 
			
		||||
func (this *NodeClusterDAO) CountAllEnabledClusters(keyword string) (int64, error) {
 | 
			
		||||
	query := this.Query().
 | 
			
		||||
		State(NodeClusterStateEnabled)
 | 
			
		||||
	if len(keyword) > 0 {
 | 
			
		||||
		query.Where("(name LIKE :keyword OR dnsName like :keyword)").
 | 
			
		||||
			Param("keyword", "%"+keyword+"%")
 | 
			
		||||
	}
 | 
			
		||||
	return query.Count()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 列出单页集群
 | 
			
		||||
func (this *NodeClusterDAO) ListEnabledClusters(offset, size int64) (result []*NodeCluster, err error) {
 | 
			
		||||
	_, err = this.Query().
 | 
			
		||||
		State(NodeClusterStateEnabled).
 | 
			
		||||
func (this *NodeClusterDAO) ListEnabledClusters(keyword string, offset, size int64) (result []*NodeCluster, err error) {
 | 
			
		||||
	query := this.Query().
 | 
			
		||||
		State(NodeClusterStateEnabled)
 | 
			
		||||
	if len(keyword) > 0 {
 | 
			
		||||
		query.Where("(name LIKE :keyword OR dnsName like :keyword)").
 | 
			
		||||
			Param("keyword", "%"+keyword+"%")
 | 
			
		||||
	}
 | 
			
		||||
	_, err = query.
 | 
			
		||||
		Offset(offset).
 | 
			
		||||
		Limit(size).
 | 
			
		||||
		Slice(&result).
 | 
			
		||||
 
 | 
			
		||||
@@ -5,8 +5,8 @@ import (
 | 
			
		||||
	"encoding/json"
 | 
			
		||||
	"errors"
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeAPI/internal/rpc"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeAPI/internal/utils/numberutils"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
 | 
			
		||||
	_ "github.com/go-sql-driver/mysql"
 | 
			
		||||
@@ -557,7 +557,7 @@ func (this *ServerDAO) UpdateServerReverseProxy(serverId int64, config []byte) e
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 计算所有可用服务数量
 | 
			
		||||
func (this *ServerDAO) CountAllEnabledServersMatch(groupId int64, keyword string, userId int64, clusterId int64, auditingFlag rpc.BoolFlag) (int64, error) {
 | 
			
		||||
func (this *ServerDAO) CountAllEnabledServersMatch(groupId int64, keyword string, userId int64, clusterId int64, auditingFlag configutils.BoolState) (int64, error) {
 | 
			
		||||
	query := this.Query().
 | 
			
		||||
		State(ServerStateEnabled)
 | 
			
		||||
	if groupId > 0 {
 | 
			
		||||
@@ -574,7 +574,7 @@ func (this *ServerDAO) CountAllEnabledServersMatch(groupId int64, keyword string
 | 
			
		||||
	if clusterId > 0 {
 | 
			
		||||
		query.Attr("clusterId", clusterId)
 | 
			
		||||
	}
 | 
			
		||||
	if auditingFlag == rpc.BoolFlagTrue {
 | 
			
		||||
	if auditingFlag == configutils.BoolStateYes {
 | 
			
		||||
		query.Attr("isAuditing", true)
 | 
			
		||||
	}
 | 
			
		||||
	return query.Count()
 | 
			
		||||
 
 | 
			
		||||
@@ -1,9 +0,0 @@
 | 
			
		||||
package rpc
 | 
			
		||||
 | 
			
		||||
type BoolFlag = int32
 | 
			
		||||
 | 
			
		||||
const (
 | 
			
		||||
	BoolFlagNone  BoolFlag = 0
 | 
			
		||||
	BoolFlagTrue  BoolFlag = 1
 | 
			
		||||
	BoolFlagFalse BoolFlag = 2
 | 
			
		||||
)
 | 
			
		||||
@@ -162,12 +162,16 @@ func (this *NodeService) ListEnabledNodesMatch(ctx context.Context, req *pb.List
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	dnsDomainId := int64(clusterDNS.DnsDomainId)
 | 
			
		||||
 | 
			
		||||
	dnsDomainId := int64(0)
 | 
			
		||||
	domainRoutes := []*dnsclients.Route{}
 | 
			
		||||
	if clusterDNS.DnsDomainId > 0 {
 | 
			
		||||
		domainRoutes, err = models.SharedDNSDomainDAO.FindDomainRoutes(dnsDomainId)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return nil, err
 | 
			
		||||
	if clusterDNS != nil {
 | 
			
		||||
		dnsDomainId = int64(clusterDNS.DnsDomainId)
 | 
			
		||||
		if clusterDNS.DnsDomainId > 0 {
 | 
			
		||||
			domainRoutes, err = models.SharedDNSDomainDAO.FindDomainRoutes(dnsDomainId)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				return nil, err
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@@ -285,7 +289,6 @@ func (this *NodeService) FindAllEnabledNodesWithClusterId(ctx context.Context, r
 | 
			
		||||
		// TODO 检查权限
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	nodes, err := models.SharedNodeDAO.FindAllEnabledNodesWithClusterId(req.NodeClusterId)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
 
 | 
			
		||||
@@ -221,7 +221,7 @@ func (this *NodeClusterService) CountAllEnabledNodeClusters(ctx context.Context,
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	count, err := models.SharedNodeClusterDAO.CountAllEnabledClusters()
 | 
			
		||||
	count, err := models.SharedNodeClusterDAO.CountAllEnabledClusters(req.Keyword)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
@@ -236,7 +236,7 @@ func (this *NodeClusterService) ListEnabledNodeClusters(ctx context.Context, req
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	clusters, err := models.SharedNodeClusterDAO.ListEnabledClusters(req.Offset, req.Size)
 | 
			
		||||
	clusters, err := models.SharedNodeClusterDAO.ListEnabledClusters(req.Keyword, req.Offset, req.Size)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -10,6 +10,7 @@ import (
 | 
			
		||||
	"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
 | 
			
		||||
	"github.com/iwind/TeaGo/logs"
 | 
			
		||||
	"github.com/iwind/TeaGo/maps"
 | 
			
		||||
	"github.com/iwind/TeaGo/types"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type ServerService struct {
 | 
			
		||||
@@ -454,7 +455,7 @@ func (this *ServerService) CountAllEnabledServersMatch(ctx context.Context, req
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	count, err := models.SharedServerDAO.CountAllEnabledServersMatch(req.GroupId, req.Keyword, req.UserId, req.ClusterId, req.AuditingFlag)
 | 
			
		||||
	count, err := models.SharedServerDAO.CountAllEnabledServersMatch(req.GroupId, req.Keyword, req.UserId, req.ClusterId, types.Int8(req.AuditingFlag))
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -3,9 +3,9 @@ package services
 | 
			
		||||
import (
 | 
			
		||||
	"context"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeAPI/internal/db/models"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeAPI/internal/rpc"
 | 
			
		||||
	rpcutils "github.com/TeaOSLab/EdgeAPI/internal/rpc/utils"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeAPI/internal/utils"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
 | 
			
		||||
	timeutil "github.com/iwind/TeaGo/utils/time"
 | 
			
		||||
	"time"
 | 
			
		||||
@@ -283,7 +283,7 @@ func (this *UserService) ComposeUserDashboard(ctx context.Context, req *pb.Compo
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// 网站数量
 | 
			
		||||
	countServers, err := models.SharedServerDAO.CountAllEnabledServersMatch(0, "", req.UserId, 0, rpc.BoolFlagNone)
 | 
			
		||||
	countServers, err := models.SharedServerDAO.CountAllEnabledServersMatch(0, "", req.UserId, 0, configutils.BoolStateAll)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user