99 lines
2.8 KiB
Go
99 lines
2.8 KiB
Go
package dao
|
|
|
|
import (
|
|
"context"
|
|
"prompts-core/consts/public"
|
|
"prompts-core/model/entity"
|
|
|
|
"gitea.redpowerfuture.com/red-future/common/db/gfdb"
|
|
"github.com/gogf/gf/v2/util/gconv"
|
|
)
|
|
|
|
var ProviderProtocol = &providerProtocolDao{}
|
|
|
|
type providerProtocolDao struct{}
|
|
|
|
// Insert 新增协议配置
|
|
func (d *providerProtocolDao) Insert(ctx context.Context, req *entity.ProviderProtocol) (id int64, err error) {
|
|
var m = new(entity.ProviderProtocol)
|
|
err = gconv.Struct(req, &m)
|
|
if err != nil {
|
|
return
|
|
}
|
|
r, err := gfdb.DB(ctx, public.DbNameModelGateway).Model(ctx, public.TableNameProviderProtocol).
|
|
Insert(m)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return r.LastInsertId()
|
|
}
|
|
|
|
// Get 查询协议配置
|
|
func (d *providerProtocolDao) Get(ctx context.Context, req *entity.ProviderProtocol, fields ...string) (res *entity.ProviderProtocol, err error) {
|
|
r, err := gfdb.DB(ctx, public.DbNameModelGateway).Model(ctx, public.TableNameProviderProtocol).
|
|
NoTenantId(ctx).
|
|
OmitEmpty().
|
|
Where(entity.ProviderProtocolCol.Id, req.Id).
|
|
Where(entity.ProviderProtocolCol.ProviderName, req.ProviderName). //主要是根据运营商查询
|
|
Where(entity.ProviderProtocolCol.Status, 1).
|
|
Fields(fields).One()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if r.IsEmpty() {
|
|
return nil, nil
|
|
}
|
|
err = r.Struct(&res)
|
|
return
|
|
}
|
|
|
|
// List 列表查询
|
|
func (d *providerProtocolDao) List(ctx context.Context, req *entity.ProviderProtocol, page, size int, fields ...string) (list []*entity.ProviderProtocol, total int, err error) {
|
|
if page <= 0 {
|
|
page = 1
|
|
}
|
|
if size <= 0 {
|
|
size = 10
|
|
}
|
|
model := gfdb.DB(ctx, public.DbNameModelGateway).Model(ctx, public.TableNameProviderProtocol).
|
|
Fields(fields).
|
|
OmitEmpty()
|
|
model.Where(entity.ProviderProtocolCol.ProviderName, req.ProviderName)
|
|
model.Where(entity.ProviderProtocolCol.Status, req.Status)
|
|
model.OrderDesc(entity.ProviderProtocolCol.CreatedAt)
|
|
model.Page(page, size)
|
|
r, total, err := model.AllAndCount(false)
|
|
if err != nil {
|
|
return
|
|
}
|
|
err = r.Structs(&list)
|
|
return
|
|
}
|
|
|
|
// Update 更新协议配置
|
|
func (d *providerProtocolDao) Update(ctx context.Context, req *entity.ProviderProtocol) (rows int64, err error) {
|
|
r, err := gfdb.DB(ctx, public.DbNameModelGateway).Model(ctx, public.TableNameProviderProtocol).
|
|
OmitEmpty().
|
|
Where(entity.ProviderProtocolCol.Id, req.Id).
|
|
Data(req).
|
|
Update()
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return r.RowsAffected()
|
|
}
|
|
|
|
// Delete 软删除协议配置
|
|
func (d *providerProtocolDao) Delete(ctx context.Context, id int64) (rows int64, err error) {
|
|
r, err := gfdb.DB(ctx, public.DbNameModelGateway).Model(ctx, public.TableNameProviderProtocol).
|
|
Where(entity.ProviderProtocolCol.Id, id).
|
|
Data(map[string]any{
|
|
entity.ProviderProtocolCol.DeletedAt: "NOW()",
|
|
}).
|
|
Update()
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return r.RowsAffected()
|
|
}
|