mirror of
				https://github.com/TeaOSLab/EdgeAPI.git
				synced 2025-11-04 07:50:25 +08:00 
			
		
		
		
	检查域名是否存在时同时检查泛域名
This commit is contained in:
		@@ -1880,8 +1880,8 @@ func (this *ServerDAO) CheckPortIsUsing(tx *dbs.Tx, clusterId int64, protocolFam
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ExistServerNameInCluster 检查ServerName是否已存在
 | 
			
		||||
func (this *ServerDAO) ExistServerNameInCluster(tx *dbs.Tx, clusterId int64, serverName string, excludeServerId int64) (bool, error) {
 | 
			
		||||
	query := this.Query(tx).
 | 
			
		||||
func (this *ServerDAO) ExistServerNameInCluster(tx *dbs.Tx, clusterId int64, serverName string, excludeServerId int64, supportWildcard bool) (bool, error) {
 | 
			
		||||
	var query = this.Query(tx).
 | 
			
		||||
		Attr("clusterId", clusterId).
 | 
			
		||||
		Where("(JSON_CONTAINS(serverNames, :jsonQuery1) OR JSON_CONTAINS(serverNames, :jsonQuery2))").
 | 
			
		||||
		Param("jsonQuery1", maps.Map{"name": serverName}.AsJSON()).
 | 
			
		||||
@@ -1890,7 +1890,38 @@ func (this *ServerDAO) ExistServerNameInCluster(tx *dbs.Tx, clusterId int64, ser
 | 
			
		||||
		query.Neq("id", excludeServerId)
 | 
			
		||||
	}
 | 
			
		||||
	query.State(ServerStateEnabled)
 | 
			
		||||
	return query.Exist()
 | 
			
		||||
	exists, err := query.Exist()
 | 
			
		||||
	if err != nil || exists {
 | 
			
		||||
		return exists, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if supportWildcard {
 | 
			
		||||
		var countPieces = strings.Count(serverName, ".")
 | 
			
		||||
		for {
 | 
			
		||||
			var index = strings.Index(serverName, ".")
 | 
			
		||||
			if index > 0 {
 | 
			
		||||
				serverName = serverName[index+1:]
 | 
			
		||||
				var search = strings.Repeat("*.", countPieces-strings.Count(serverName, ".")) + serverName
 | 
			
		||||
				var query = this.Query(tx).
 | 
			
		||||
					Attr("clusterId", clusterId).
 | 
			
		||||
					Where("(JSON_CONTAINS(serverNames, :jsonQuery1) OR JSON_CONTAINS(serverNames, :jsonQuery2))").
 | 
			
		||||
					Param("jsonQuery1", maps.Map{"name": search}.AsJSON()).
 | 
			
		||||
					Param("jsonQuery2", maps.Map{"subNames": search}.AsJSON())
 | 
			
		||||
				if excludeServerId > 0 {
 | 
			
		||||
					query.Neq("id", excludeServerId)
 | 
			
		||||
				}
 | 
			
		||||
				query.State(ServerStateEnabled)
 | 
			
		||||
				exists, err = query.Exist()
 | 
			
		||||
				if err != nil || exists {
 | 
			
		||||
					return exists, err
 | 
			
		||||
				}
 | 
			
		||||
			} else {
 | 
			
		||||
				break
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return false, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// GenDNSName 生成DNS Name
 | 
			
		||||
 
 | 
			
		||||
@@ -1707,9 +1707,9 @@ func (this *ServerService) CheckServerNameDuplicationInNodeCluster(ctx context.C
 | 
			
		||||
 | 
			
		||||
	var tx = this.NullTx()
 | 
			
		||||
 | 
			
		||||
	duplicatedServerNames := []string{}
 | 
			
		||||
	var duplicatedServerNames = []string{}
 | 
			
		||||
	for _, serverName := range req.ServerNames {
 | 
			
		||||
		exist, err := models.SharedServerDAO.ExistServerNameInCluster(tx, req.NodeClusterId, serverName, req.ExcludeServerId)
 | 
			
		||||
		exist, err := models.SharedServerDAO.ExistServerNameInCluster(tx, req.NodeClusterId, serverName, req.ExcludeServerId, req.SupportWildcard)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return nil, err
 | 
			
		||||
		}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user