初始化项目
This commit is contained in:
91
dao/ad_source_dao.go
Normal file
91
dao/ad_source_dao.go
Normal file
@@ -0,0 +1,91 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"cidService/model/entity"
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
var (
|
||||
AdSource = adSourceDao{}
|
||||
)
|
||||
|
||||
type adSourceDao struct{}
|
||||
|
||||
// GetByName 根据名称获取广告源
|
||||
func (d *adSourceDao) GetByName(ctx context.Context, name string) (adSource *entity.AdSource, err error) {
|
||||
err = g.DB().Model("ad_sources").
|
||||
Where("name = ?", name).
|
||||
Scan(&adSource)
|
||||
return
|
||||
}
|
||||
|
||||
// GetAvailableSources 获取可用的广告源
|
||||
func (d *adSourceDao) GetAvailableSources(ctx context.Context) (list []*entity.AdSource, err error) {
|
||||
err = g.DB().Model("ad_sources").
|
||||
Where("status = ?", "active").
|
||||
Order("priority DESC, created_at ASC").
|
||||
Scan(&list)
|
||||
return
|
||||
}
|
||||
|
||||
// GetSourcesByProvider 根据提供商获取广告源
|
||||
func (d *adSourceDao) GetSourcesByProvider(ctx context.Context, provider string) (list []*entity.AdSource, err error) {
|
||||
err = g.DB().Model("ad_sources").
|
||||
Where("provider = ? AND status = ?", provider, "active").
|
||||
Order("priority DESC").
|
||||
Scan(&list)
|
||||
return
|
||||
}
|
||||
|
||||
// Create 创建广告源
|
||||
func (d *adSourceDao) Create(ctx context.Context, adSource *entity.AdSource) (id int64, err error) {
|
||||
result, err := g.DB().Model("ad_sources").Insert(adSource)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
id, err = result.LastInsertId()
|
||||
return
|
||||
}
|
||||
|
||||
// Update 更新广告源
|
||||
func (d *adSourceDao) Update(ctx context.Context, adSource *entity.AdSource) (affected int64, err error) {
|
||||
result, err := g.DB().Model("ad_sources").
|
||||
Where("id = ?", adSource.Id).
|
||||
Update(adSource)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result.RowsAffected()
|
||||
}
|
||||
|
||||
// Delete 删除广告源
|
||||
func (d *adSourceDao) Delete(ctx context.Context, id int64) (affected int64, err error) {
|
||||
result, err := g.DB().Model("ad_sources").
|
||||
Where("id = ?", id).
|
||||
Delete()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result.RowsAffected()
|
||||
}
|
||||
|
||||
// GetByID 根据ID获取广告源
|
||||
func (d *adSourceDao) GetByID(ctx context.Context, id int64) (adSource *entity.AdSource, err error) {
|
||||
err = g.DB().Model("ad_sources").
|
||||
Where("id = ?", id).
|
||||
Scan(&adSource)
|
||||
return
|
||||
}
|
||||
|
||||
// UpdateFields 更新广告源部分字段
|
||||
func (d *adSourceDao) UpdateFields(ctx context.Context, id int64, data *entity.AdSource) (affected int64, err error) {
|
||||
result, err := g.DB().Model("ad_sources").
|
||||
Where("id = ?", id).
|
||||
Update(data)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result.RowsAffected()
|
||||
}
|
||||
Reference in New Issue
Block a user