- 新增同会话+同工作流最近执行失败且参数一致时断点续跑逻辑 - exec_workflow/exec_chat 新增 error 字段存储原始错误,error_message 仅存友好提示 - 新增 UpdateExecChatReq 与 exec_chat_dao Update 方法 - 新增 GetLatestBySessionAndFlow 查询最近执行记录 - 修正 ListDates 分组与排序 SQL 表达式 - 新增 pipeline 配置结构,删除旧设计文档
73 lines
2.2 KiB
Go
73 lines
2.2 KiB
Go
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 ExecChatDao = &execChatDao{}
|
|
|
|
type execChatDao struct{}
|
|
|
|
func (d *execChatDao) Insert(ctx context.Context, req *sessionDto.CreateExecChatReq) (id int64, err error) {
|
|
var s = new(entity.ExecChat)
|
|
if err = gconv.Struct(req, &s); err != nil {
|
|
return
|
|
}
|
|
r, err := gfdb.DB(ctx, public.DbNameBlackDeacon).Model(ctx, public.TableNameExecChat).Insert(s)
|
|
if err != nil {
|
|
return
|
|
}
|
|
return r.LastInsertId()
|
|
}
|
|
|
|
func (d *execChatDao) Update(ctx context.Context, req *sessionDto.UpdateExecChatReq) (rows int64, err error) {
|
|
r, err := gfdb.DB(ctx, public.DbNameBlackDeacon).Model(ctx, public.TableNameExecChat).OmitEmpty().Data(&req).Where(entity.ExecChatCol.Id, req.Id).Update()
|
|
if err != nil {
|
|
return
|
|
}
|
|
return r.RowsAffected()
|
|
}
|
|
|
|
func (d *execChatDao) Delete(ctx context.Context, req *sessionDto.DeleteExecChatReq) (rows int64, err error) {
|
|
r, err := gfdb.DB(ctx, public.DbNameBlackDeacon).Model(ctx, public.TableNameExecChat).Where(entity.ExecChatCol.Id, req.Id).Delete()
|
|
if err != nil {
|
|
return
|
|
}
|
|
return r.RowsAffected()
|
|
}
|
|
|
|
func (d *execChatDao) List(ctx context.Context, creator string, page *beans.Page) (res []*entity.ExecChat, total int, err error) {
|
|
m := gfdb.DB(ctx, public.DbNameBlackDeacon).Model(ctx, public.TableNameExecChat).
|
|
Where(entity.ExecChatCol.Creator, creator)
|
|
m.OrderDesc(entity.ExecChatCol.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
|
|
}
|
|
|
|
// ListBySession 查询会话下普通对话执行记录(按创建时间倒序)
|
|
func (d *execChatDao) ListBySession(ctx context.Context, sessionId string) (res []*entity.ExecChat, err error) {
|
|
r, err := gfdb.DB(ctx, public.DbNameBlackDeacon).Model(ctx, public.TableNameExecChat).
|
|
Where(entity.ExecChatCol.SessionId, sessionId).
|
|
OrderDesc(entity.ExecChatCol.CreatedAt).
|
|
All()
|
|
if err != nil {
|
|
return
|
|
}
|
|
err = r.Structs(&res)
|
|
return
|
|
}
|