Files
ai-agent/digital-human/dao/async_task_ref_dao.go
2026-06-10 15:29:21 +08:00

70 lines
1.9 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package dao
import (
"context"
"ai-agent/digital-human/consts/public"
"ai-agent/digital-human/model/entity"
"gitea.redpowerfuture.com/red-future/common/db/gfdb"
"github.com/gogf/gf/v2/database/gdb"
)
var AsyncTaskRef = &asyncTaskRefDao{}
type asyncTaskRefDao struct{}
func (d *asyncTaskRefDao) Insert(ctx context.Context, ref *entity.AsyncTaskRef) (id int64, err error) {
r, err := gfdb.DB(ctx).Model(ctx, public.TableNameAsyncTaskRef).Data(ref).Insert()
if err != nil {
return 0, err
}
return r.LastInsertId()
}
// ListPending 列出待处理任务绑定state=0/1
func (d *asyncTaskRefDao) ListPending(ctx context.Context, limit int) (list []*entity.AsyncTaskRef, err error) {
if limit <= 0 {
limit = 200
}
r, err := gfdb.DB(ctx).Model(ctx, public.TableNameAsyncTaskRef).
Where("deleted_at IS NULL").
// 业务侧只维护三态:生成中/成功/失败;绑定表仅用于“待同步列表”
WhereIn(entity.AsyncTaskRefCol.State, []int{0, 1}).
OrderAsc(entity.AsyncTaskRefCol.UpdatedAt).
Limit(limit).
All()
if err != nil {
return nil, err
}
err = r.Structs(&list)
return
}
func (d *asyncTaskRefDao) UpdateByTaskID(ctx context.Context, taskID string, data gdb.Map) (rows int64, err error) {
// 触发 gfdb 的 updateHook 自动填充 updater需要显式带 updater 字段
data[entity.AsyncTaskRefCol.Updater] = ""
r, err := gfdb.DB(ctx).Model(ctx, public.TableNameAsyncTaskRef).
Where(entity.AsyncTaskRefCol.TaskID, taskID).
Data(data).
Update()
if err != nil {
return 0, err
}
return r.RowsAffected()
}
func (d *asyncTaskRefDao) GetByTaskID(ctx context.Context, taskID string) (ref *entity.AsyncTaskRef, err error) {
r, err := gfdb.DB(ctx).Model(ctx, public.TableNameAsyncTaskRef).
Where(entity.AsyncTaskRefCol.TaskID, taskID).
One()
if err != nil {
return nil, err
}
if r.IsEmpty() {
return nil, nil
}
err = r.Struct(&ref)
return
}