package session import ( "ai-agent/workflow/consts/public" sessionDto "ai-agent/workflow/model/dto/session" "ai-agent/workflow/model/entity" "context" "gitea.redpowerfuture.com/red-future/common/beans" "gitea.redpowerfuture.com/red-future/common/db/gfdb" "github.com/gogf/gf/v2/util/gconv" ) var SessionDao = &sessionDao{} type sessionDao struct{} func (d *sessionDao) Insert(ctx context.Context, req *sessionDto.CreateSessionReq) (id int64, err error) { var s = new(entity.Session) if err = gconv.Struct(req, &s); err != nil { return } r, err := gfdb.DB(ctx, public.DbNameBlackDeacon).Model(ctx, public.TableNameSession).Insert(s) if err != nil { return } return r.LastInsertId() } func (d *sessionDao) GetById(ctx context.Context, id string) (res *entity.Session, err error) { r, err := gfdb.DB(ctx, public.DbNameBlackDeacon).Model(ctx, public.TableNameSession). Where(entity.SessionCol.SessionId, id). One() if err != nil { return } err = r.Struct(&res) return } func (d *sessionDao) Delete(ctx context.Context, req *sessionDto.DeleteSessionReq) (rows int64, err error) { r, err := gfdb.DB(ctx, public.DbNameBlackDeacon).Model(ctx, public.TableNameSession).Where(entity.SessionCol.SessionId, req.SessionId).Delete() if err != nil { return } return r.RowsAffected() } func (d *sessionDao) List(ctx context.Context, creator string, page *beans.Page) (res []*entity.Session, total int, err error) { m := gfdb.DB(ctx, public.DbNameBlackDeacon).Model(ctx, public.TableNameSession). Where(entity.SessionCol.Creator, creator) m.OrderDesc(entity.SessionCol.CreatedAt) if page != nil { m.Page(int(page.PageNum), int(page.PageSize)) } r, total, err := m.AllAndCount(false) if err != nil { return } err = r.Structs(&res) return }