feat: 新增主动拉取与多类型回调功能
- 新增 ActivePull 实体、DAO、DTO 及 Service,支持主动拉取任务管理 - 新增 ComposeCallback、VideoCallback、HttpNodeCallback 多类型回调接口 - FlowExecution 增加 NodeGroupId 和 TotalTokens 字段,支持节点组追踪与 Token 统计 - ExecutedNodes 结构由字符串列表改为包含执行状态的节点对象列表 - 重构回调通知机制,统一 Notify 函数调用 - 优化输出项类型判断逻辑,新增文件类型标识
This commit is contained in:
102
workflow/dao/pull/active_pull_dao.go
Normal file
102
workflow/dao/pull/active_pull_dao.go
Normal file
@@ -0,0 +1,102 @@
|
||||
package pull
|
||||
|
||||
import (
|
||||
"ai-agent/workflow/consts/public"
|
||||
pullDto "ai-agent/workflow/model/dto/pull"
|
||||
"ai-agent/workflow/model/entity"
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"gitea.com/red-future/common/db/gfdb"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
var ActivePullDao = &activePullDao{}
|
||||
|
||||
type activePullDao struct{}
|
||||
|
||||
// Insert 创建执行记录
|
||||
func (d *activePullDao) Insert(ctx context.Context, req *pullDto.CreateActivePullReq) (id int64, err error) {
|
||||
var activePull = new(entity.ActivePull)
|
||||
err = gconv.Struct(req, &activePull)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
r, err := gfdb.DB(ctx, public.DbNameBlackDeacon).Model(ctx, public.TableNameActivePull).Insert(activePull)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.LastInsertId()
|
||||
}
|
||||
|
||||
func (d *activePullDao) Update(ctx context.Context, req *pullDto.UpdateActivePullReq) (rows int64, err error) {
|
||||
r, err := gfdb.DB(ctx, public.DbNameBlackDeacon).Model(ctx, public.TableNameActivePull).OmitEmpty().Data(&req).Where(entity.ActivePullCol.Id, req.Id).Update()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.RowsAffected()
|
||||
}
|
||||
|
||||
func (d *activePullDao) Delete(ctx context.Context, req *pullDto.DeleteActivePullReq) (rows int64, err error) {
|
||||
r, err := gfdb.DB(ctx, public.DbNameBlackDeacon).Model(ctx, public.TableNameActivePull).Where(entity.ActivePullCol.Id, req.Id).Delete()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.RowsAffected()
|
||||
}
|
||||
|
||||
func (d *activePullDao) List(ctx context.Context, req *pullDto.ListActivePullReq, fields ...string) (res []*entity.ActivePull, total int, err error) {
|
||||
model := gfdb.DB(ctx, public.DbNameBlackDeacon).Model(ctx, public.TableNameActivePull).Fields(fields).OmitEmpty()
|
||||
model.OrderDesc(entity.ActivePullCol.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
|
||||
}
|
||||
|
||||
func (d *activePullDao) ListNative(ctx context.Context, req *pullDto.ListActivePullReq, fields ...string) (res []*entity.ActivePull, total int, err error) {
|
||||
db := gfdb.DB(ctx, public.DbNameBlackDeacon)
|
||||
|
||||
// Select fields
|
||||
selectFields := "*"
|
||||
if len(fields) > 0 {
|
||||
selectFields = strings.Join(fields, ",")
|
||||
}
|
||||
|
||||
// Build count query first for total
|
||||
countSql := fmt.Sprintf("SELECT COUNT(*) FROM %s WHERE deleted_at is null", "black_deacon_"+public.TableNameActivePull)
|
||||
countResult, err := db.GetAll(ctx, countSql)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
if len(countResult) > 0 {
|
||||
total = countResult[0]["COUNT(*)"].Int()
|
||||
}
|
||||
|
||||
// Build data query with native SQL
|
||||
sql := fmt.Sprintf("SELECT %s FROM %s WHERE deleted_at is null ORDER BY created_at DESC", selectFields, "black_deacon_"+public.TableNameActivePull)
|
||||
if req.Page != nil && req.Page.PageNum > 0 && req.Page.PageSize > 0 {
|
||||
offset := (req.Page.PageNum - 1) * req.Page.PageSize
|
||||
sql += fmt.Sprintf(" LIMIT %d OFFSET %d", req.Page.PageSize, offset)
|
||||
}
|
||||
|
||||
// Execute query with GetAll
|
||||
result, err := db.GetAll(ctx, sql)
|
||||
if err != nil {
|
||||
return nil, total, err
|
||||
}
|
||||
|
||||
// Scan to entity slice
|
||||
var models []*entity.ActivePull
|
||||
if err = result.Structs(&models); err != nil {
|
||||
return nil, total, err
|
||||
}
|
||||
|
||||
return models, total, nil
|
||||
}
|
||||
Reference in New Issue
Block a user