mirror of
				https://github.com/TeaOSLab/EdgeAPI.git
				synced 2025-11-04 07:50:25 +08:00 
			
		
		
		
	增加一些表设计
This commit is contained in:
		
							
								
								
									
										65
									
								
								internal/db/models/http_firewall_rule_set_dao.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										65
									
								
								internal/db/models/http_firewall_rule_set_dao.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,65 @@
 | 
			
		||||
package models
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	_ "github.com/go-sql-driver/mysql"
 | 
			
		||||
	"github.com/iwind/TeaGo/Tea"
 | 
			
		||||
	"github.com/iwind/TeaGo/dbs"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
const (
 | 
			
		||||
	HTTPFirewallRuleSetStateEnabled  = 1 // 已启用
 | 
			
		||||
	HTTPFirewallRuleSetStateDisabled = 0 // 已禁用
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type HTTPFirewallRuleSetDAO dbs.DAO
 | 
			
		||||
 | 
			
		||||
func NewHTTPFirewallRuleSetDAO() *HTTPFirewallRuleSetDAO {
 | 
			
		||||
	return dbs.NewDAO(&HTTPFirewallRuleSetDAO{
 | 
			
		||||
		DAOObject: dbs.DAOObject{
 | 
			
		||||
			DB:     Tea.Env,
 | 
			
		||||
			Table:  "edgeHTTPFirewallRuleSets",
 | 
			
		||||
			Model:  new(HTTPFirewallRuleSet),
 | 
			
		||||
			PkName: "id",
 | 
			
		||||
		},
 | 
			
		||||
	}).(*HTTPFirewallRuleSetDAO)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
var SharedHTTPFirewallRuleSetDAO = NewHTTPFirewallRuleSetDAO()
 | 
			
		||||
 | 
			
		||||
// 启用条目
 | 
			
		||||
func (this *HTTPFirewallRuleSetDAO) EnableHTTPFirewallRuleSet(id uint32) error {
 | 
			
		||||
	_, err := this.Query().
 | 
			
		||||
		Pk(id).
 | 
			
		||||
		Set("state", HTTPFirewallRuleSetStateEnabled).
 | 
			
		||||
		Update()
 | 
			
		||||
	return err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 禁用条目
 | 
			
		||||
func (this *HTTPFirewallRuleSetDAO) DisableHTTPFirewallRuleSet(id uint32) error {
 | 
			
		||||
	_, err := this.Query().
 | 
			
		||||
		Pk(id).
 | 
			
		||||
		Set("state", HTTPFirewallRuleSetStateDisabled).
 | 
			
		||||
		Update()
 | 
			
		||||
	return err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 查找启用中的条目
 | 
			
		||||
func (this *HTTPFirewallRuleSetDAO) FindEnabledHTTPFirewallRuleSet(id uint32) (*HTTPFirewallRuleSet, error) {
 | 
			
		||||
	result, err := this.Query().
 | 
			
		||||
		Pk(id).
 | 
			
		||||
		Attr("state", HTTPFirewallRuleSetStateEnabled).
 | 
			
		||||
		Find()
 | 
			
		||||
	if result == nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	return result.(*HTTPFirewallRuleSet), err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 根据主键查找名称
 | 
			
		||||
func (this *HTTPFirewallRuleSetDAO) FindHTTPFirewallRuleSetName(id uint32) (string, error) {
 | 
			
		||||
	return this.Query().
 | 
			
		||||
		Pk(id).
 | 
			
		||||
		Result("name").
 | 
			
		||||
		FindStringCol("")
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user