Files
ai-agent/workflow/dao/flow/flow_segment_result_dao.go
T

58 lines
1.9 KiB
Go

package flow
import (
"ai-agent/workflow/consts/public"
"ai-agent/workflow/model/entity"
"context"
"gitea.redpowerfuture.com/red-future/common/db/gfdb"
)
var FlowSegmentResultDao = &flowSegmentResultDao{}
type flowSegmentResultDao struct{}
// Save 段成功后落库:唯一键 (execution_id, node_id, segment_index),冲突则更新
func (d *flowSegmentResultDao) Save(ctx context.Context, execId int64, nodeId string, segmentIndex int, videoKey, videoURL string) error {
rec := &entity.FlowSegmentResult{
ExecutionId: execId,
NodeId: nodeId,
SegmentIndex: segmentIndex,
VideoKey: videoKey,
VideoURL: videoURL,
}
_, err := gfdb.DB(ctx, public.DbNameBlackDeacon).
Model(ctx, public.TableNameFlowSegmentResult).
Data(rec).
OnConflict(entity.FlowSegmentResultCol.ExecutionId, entity.FlowSegmentResultCol.NodeId, entity.FlowSegmentResultCol.SegmentIndex).
Save()
return err
}
// ListByNode 返回该节点已成功段(段序号 → 视频引用)
func (d *flowSegmentResultDao) ListByNode(ctx context.Context, execId int64, nodeId string) (map[int]entity.SegmentRef, error) {
var list []*entity.FlowSegmentResult
err := gfdb.DB(ctx, public.DbNameBlackDeacon).
Model(ctx, public.TableNameFlowSegmentResult).
Where(entity.FlowSegmentResultCol.ExecutionId, execId).
Where(entity.FlowSegmentResultCol.NodeId, nodeId).
Scan(&list)
if err != nil {
return nil, err
}
m := make(map[int]entity.SegmentRef, len(list))
for _, r := range list {
m[r.SegmentIndex] = entity.SegmentRef{Key: r.VideoKey, URL: r.VideoURL}
}
return m, nil
}
// DeleteByExecution 清理指定执行的段结果(全新执行前清旧段 / 工作流执行成功后清理)
func (d *flowSegmentResultDao) DeleteByExecution(ctx context.Context, execId int64) error {
_, err := gfdb.DB(ctx, public.DbNameBlackDeacon).
Model(ctx, public.TableNameFlowSegmentResult).
Where(entity.FlowSegmentResultCol.ExecutionId, execId).
Delete()
return err
}