97 lines
2.6 KiB
Go
97 lines
2.6 KiB
Go
package dao
|
|
|
|
import (
|
|
"context"
|
|
"prompts-core/consts/public"
|
|
"prompts-core/model/entity"
|
|
|
|
"gitea.com/red-future/common/db/gfdb"
|
|
"github.com/gogf/gf/v2/util/gconv"
|
|
)
|
|
|
|
var ComposeSession = &composeSessionDao{}
|
|
|
|
type composeSessionDao struct{}
|
|
|
|
// Insert 插入
|
|
func (d *composeSessionDao) Insert(ctx context.Context, req *entity.ComposeSession) (id int64, err error) {
|
|
var m = new(entity.ComposeSession)
|
|
err = gconv.Struct(req, &m)
|
|
if err != nil {
|
|
return
|
|
}
|
|
r, err := gfdb.DB(ctx, public.DbNameModelGateway).Model(ctx, public.TableNameComposeSession).
|
|
Insert(m)
|
|
if err != nil {
|
|
return
|
|
}
|
|
return r.LastInsertId()
|
|
}
|
|
|
|
// Update 更新
|
|
func (d *composeSessionDao) Update(ctx context.Context, req *entity.ComposeSession) (rows int64, err error) {
|
|
r, err := gfdb.DB(ctx, public.DbNameModelGateway).Model(ctx, public.TableNameComposeSession).
|
|
OmitEmpty().
|
|
Data(&req).
|
|
Where(entity.ComposeSessionCol.Id, req.Id).
|
|
Update()
|
|
if err != nil {
|
|
return
|
|
}
|
|
return r.RowsAffected()
|
|
}
|
|
|
|
// List 查询编排会话列表
|
|
func (d *composeSessionDao) List(ctx context.Context, req *entity.ComposeSession, page, size int, fields ...string) (list []*entity.ComposeSession, total int, err error) {
|
|
if page <= 0 {
|
|
page = 1
|
|
}
|
|
if size <= 0 {
|
|
size = 10
|
|
}
|
|
model := gfdb.DB(ctx, public.DbNameModelGateway).Model(ctx, public.TableNameComposeSession).
|
|
Fields(fields).
|
|
OmitEmpty()
|
|
model.Where(entity.ComposeSessionCol.Creator, req.Creator)
|
|
model.Where(entity.ComposeSessionCol.SessionId, req.SessionId)
|
|
model.Where(entity.ComposeSessionCol.NodeId, req.NodeId)
|
|
model.OrderDesc(entity.ComposeSessionCol.CreatedAt)
|
|
model.Page(page, size)
|
|
r, total, err := model.AllAndCount(false)
|
|
if err != nil {
|
|
return
|
|
}
|
|
err = r.Structs(&list)
|
|
return
|
|
}
|
|
|
|
// Get 查询编排会话
|
|
func (d *composeSessionDao) Get(ctx context.Context, req *entity.ComposeSession, fields ...string) (m *entity.ComposeSession, err error) {
|
|
r, err := gfdb.DB(ctx, public.DbNameModelGateway).Model(ctx, public.TableNameComposeSession).
|
|
OmitEmpty().
|
|
Where(entity.ComposeSessionCol.Id, req.Id).
|
|
Where(entity.ComposeSessionCol.SessionId, req.SessionId).
|
|
Fields(fields).One()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if r.IsEmpty() {
|
|
return
|
|
}
|
|
err = r.Struct(&m)
|
|
return
|
|
}
|
|
|
|
// Delete 删除编排会话
|
|
func (d *composeSessionDao) Delete(ctx context.Context, req *entity.ComposeSession) (rows int64, err error) {
|
|
r, err := gfdb.DB(ctx, public.DbNameModelGateway).Model(ctx, public.TableNameComposeSession).
|
|
OmitEmpty().
|
|
Where(entity.ComposeSessionCol.Id, req.Id).
|
|
Where(entity.ComposeSessionCol.SessionId, req.SessionId).
|
|
Delete()
|
|
if err != nil {
|
|
return
|
|
}
|
|
return r.RowsAffected()
|
|
}
|