package flow import ( "ai-agent/workflow/consts/public" flowDto "ai-agent/workflow/model/dto/flow" "ai-agent/workflow/model/entity" "context" "gitea.redpowerfuture.com/red-future/common/db/gfdb" "github.com/gogf/gf/v2/util/gconv" ) var FlowExecutionDao = &flowExecutionDao{} type flowExecutionDao struct{} // Insert 创建执行记录 func (d *flowExecutionDao) Insert(ctx context.Context, req *flowDto.CreateFlowExecutionReq) (id int64, err error) { var flowExecution = new(entity.FlowExecution) err = gconv.Struct(req, &flowExecution) if err != nil { return } r, err := gfdb.DB(ctx, public.DbNameBlackDeacon).Model(ctx, public.TableNameFlowExecution).Insert(flowExecution) if err != nil { return } return r.LastInsertId() } func (d *flowExecutionDao) Update(ctx context.Context, req *flowDto.UpdateFlowExecutionReq) (rows int64, err error) { r, err := gfdb.DB(ctx, public.DbNameBlackDeacon).Model(ctx, public.TableNameFlowExecution).OmitEmpty().Data(&req).Where(entity.FlowExecutionCol.Id, req.Id).Update() if err != nil { return } return r.RowsAffected() } func (d *flowExecutionDao) Get(ctx context.Context, req *flowDto.GetFlowExecutionReq, fields ...string) (res *entity.FlowExecution, err error) { r, err := gfdb.DB(ctx, public.DbNameBlackDeacon).Model(ctx, public.TableNameFlowExecution).OmitEmpty(). Where(entity.FlowExecutionCol.Id, req.Id). Where(entity.FlowExecutionCol.SessionId, req.SessionId). Fields(fields).One() if err != nil { return } err = r.Struct(&res) return } func (d *flowExecutionDao) List(ctx context.Context, req *flowDto.ListFlowExecutionReq, fields ...string) (res []*entity.FlowExecution, total int, err error) { model := gfdb.DB(ctx, public.DbNameBlackDeacon).Model(ctx, public.TableNameFlowExecution).Fields(fields).OmitEmpty() model.Where(entity.FlowExecutionCol.Creator, req.Creator) model.OrderDesc(entity.FlowExecutionCol.CreatedAt) if req.Page != nil { model.Page(int(req.Page.PageNum), int(req.Page.PageSize)) } r, total, err := model.AllAndCount(false) if err != nil { return } err = r.Structs(&res) return }