管理端全部功能跑通
This commit is contained in:
128
EdgeAPI/internal/db/models/httpdns_app_dao.go
Normal file
128
EdgeAPI/internal/db/models/httpdns_app_dao.go
Normal file
@@ -0,0 +1,128 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
"github.com/iwind/TeaGo/dbs"
|
||||
"github.com/iwind/TeaGo/types"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
HTTPDNSAppStateEnabled = 1
|
||||
HTTPDNSAppStateDisabled = 0
|
||||
HTTPDNSSNIModeFixedHide = "fixed_hide"
|
||||
)
|
||||
|
||||
type HTTPDNSAppDAO dbs.DAO
|
||||
|
||||
func NewHTTPDNSAppDAO() *HTTPDNSAppDAO {
|
||||
return dbs.NewDAO(&HTTPDNSAppDAO{
|
||||
DAOObject: dbs.DAOObject{
|
||||
DB: Tea.Env,
|
||||
Table: "edgeHTTPDNSApps",
|
||||
Model: new(HTTPDNSApp),
|
||||
PkName: "id",
|
||||
},
|
||||
}).(*HTTPDNSAppDAO)
|
||||
}
|
||||
|
||||
var SharedHTTPDNSAppDAO *HTTPDNSAppDAO
|
||||
|
||||
func init() {
|
||||
dbs.OnReady(func() {
|
||||
SharedHTTPDNSAppDAO = NewHTTPDNSAppDAO()
|
||||
})
|
||||
}
|
||||
|
||||
func (this *HTTPDNSAppDAO) CreateApp(tx *dbs.Tx, name string, appId string, primaryClusterId int64, backupClusterId int64, isOn bool, userId int64) (int64, error) {
|
||||
var op = NewHTTPDNSAppOperator()
|
||||
op.Name = name
|
||||
op.AppId = appId
|
||||
op.PrimaryClusterId = primaryClusterId
|
||||
op.BackupClusterId = backupClusterId
|
||||
op.IsOn = isOn
|
||||
op.UserId = userId
|
||||
op.SNIMode = HTTPDNSSNIModeFixedHide
|
||||
op.CreatedAt = time.Now().Unix()
|
||||
op.UpdatedAt = time.Now().Unix()
|
||||
op.State = HTTPDNSAppStateEnabled
|
||||
err := this.Save(tx, op)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return types.Int64(op.Id), nil
|
||||
}
|
||||
|
||||
func (this *HTTPDNSAppDAO) UpdateApp(tx *dbs.Tx, appDbId int64, name string, primaryClusterId int64, backupClusterId int64, isOn bool, userId int64) error {
|
||||
var op = NewHTTPDNSAppOperator()
|
||||
op.Id = appDbId
|
||||
op.Name = name
|
||||
op.PrimaryClusterId = primaryClusterId
|
||||
op.BackupClusterId = backupClusterId
|
||||
op.IsOn = isOn
|
||||
op.UserId = userId
|
||||
op.UpdatedAt = time.Now().Unix()
|
||||
return this.Save(tx, op)
|
||||
}
|
||||
|
||||
func (this *HTTPDNSAppDAO) DisableApp(tx *dbs.Tx, appDbId int64) error {
|
||||
_, err := this.Query(tx).
|
||||
Pk(appDbId).
|
||||
Set("state", HTTPDNSAppStateDisabled).
|
||||
Update()
|
||||
return err
|
||||
}
|
||||
|
||||
func (this *HTTPDNSAppDAO) FindEnabledApp(tx *dbs.Tx, appDbId int64) (*HTTPDNSApp, error) {
|
||||
one, err := this.Query(tx).
|
||||
Pk(appDbId).
|
||||
State(HTTPDNSAppStateEnabled).
|
||||
Find()
|
||||
if one == nil {
|
||||
return nil, err
|
||||
}
|
||||
return one.(*HTTPDNSApp), nil
|
||||
}
|
||||
|
||||
func (this *HTTPDNSAppDAO) FindEnabledAppWithAppId(tx *dbs.Tx, appId string) (*HTTPDNSApp, error) {
|
||||
one, err := this.Query(tx).
|
||||
State(HTTPDNSAppStateEnabled).
|
||||
Attr("appId", appId).
|
||||
Find()
|
||||
if one == nil {
|
||||
return nil, err
|
||||
}
|
||||
return one.(*HTTPDNSApp), nil
|
||||
}
|
||||
|
||||
func (this *HTTPDNSAppDAO) ListEnabledApps(tx *dbs.Tx, offset int64, size int64, keyword string) (result []*HTTPDNSApp, err error) {
|
||||
query := this.Query(tx).
|
||||
State(HTTPDNSAppStateEnabled).
|
||||
AscPk()
|
||||
if len(keyword) > 0 {
|
||||
query = query.Where("(name LIKE :kw OR appId LIKE :kw)").Param("kw", "%"+keyword+"%")
|
||||
}
|
||||
if size > 0 {
|
||||
query = query.Offset(offset).Limit(size)
|
||||
}
|
||||
_, err = query.Slice(&result).FindAll()
|
||||
return
|
||||
}
|
||||
|
||||
func (this *HTTPDNSAppDAO) CountEnabledApps(tx *dbs.Tx, keyword string) (int64, error) {
|
||||
query := this.Query(tx).State(HTTPDNSAppStateEnabled)
|
||||
if len(keyword) > 0 {
|
||||
query = query.Where("(name LIKE :kw OR appId LIKE :kw)").Param("kw", "%"+keyword+"%")
|
||||
}
|
||||
return query.Count()
|
||||
}
|
||||
|
||||
func (this *HTTPDNSAppDAO) FindAllEnabledApps(tx *dbs.Tx) (result []*HTTPDNSApp, err error) {
|
||||
_, err = this.Query(tx).
|
||||
State(HTTPDNSAppStateEnabled).
|
||||
AscPk().
|
||||
Slice(&result).
|
||||
FindAll()
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user