125 lines
3.6 KiB
Go
125 lines
3.6 KiB
Go
package dao
|
|
|
|
import (
|
|
"context"
|
|
"prompts-core/consts/public"
|
|
"prompts-core/model/entity"
|
|
|
|
"gitea.redpowerfuture.com/red-future/common/db/gfdb"
|
|
)
|
|
|
|
var ComposeSession = &composeSessionDao{}
|
|
|
|
type composeSessionDao struct{}
|
|
|
|
// Insert 插入
|
|
func (d *composeSessionDao) Insert(ctx context.Context, req *entity.ComposeSession) (id int64, err error) {
|
|
r, err := gfdb.DB(ctx, public.DbNameModelGateway).Model(ctx, public.TableNameComposeSession).
|
|
Insert(req)
|
|
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.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.Creator, req.Creator).
|
|
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.Creator, req.Creator).
|
|
Where(entity.ComposeSessionCol.SessionId, req.SessionId).
|
|
Delete()
|
|
if err != nil {
|
|
return
|
|
}
|
|
return r.RowsAffected()
|
|
}
|
|
|
|
// ListByIds 根据 ID 列表批量查询
|
|
func (d *composeSessionDao) ListByIds(ctx context.Context, ids []int64, creator, sessionId string) (list []*entity.ComposeSession, err error) {
|
|
if len(ids) == 0 {
|
|
return nil, nil
|
|
}
|
|
r, err := gfdb.DB(ctx, public.DbNameModelGateway).Model(ctx, public.TableNameComposeSession).
|
|
WhereIn(entity.ComposeSessionCol.Id, ids).
|
|
Where(entity.ComposeSessionCol.Creator, creator).
|
|
Where(entity.ComposeSessionCol.SessionId, sessionId).
|
|
All()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
err = r.Structs(&list)
|
|
return
|
|
}
|
|
|
|
// DeleteByIds 批量删除编排会话
|
|
func (d *composeSessionDao) DeleteByIds(ctx context.Context, ids []int64, creator, sessionId string) (int64, error) {
|
|
if len(ids) == 0 {
|
|
return 0, nil
|
|
}
|
|
r, err := gfdb.DB(ctx, public.DbNameModelGateway).Model(ctx, public.TableNameComposeSession).
|
|
WhereIn(entity.ComposeSessionCol.Id, ids).
|
|
Where(entity.ComposeSessionCol.Creator, creator).
|
|
Where(entity.ComposeSessionCol.SessionId, sessionId).
|
|
Delete()
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return r.RowsAffected()
|
|
}
|