引包目录名调整
This commit is contained in:
69
digital-human/dao/async_task_ref_dao.go
Normal file
69
digital-human/dao/async_task_ref_dao.go
Normal file
@@ -0,0 +1,69 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"ai-agent/digital-human/consts/public"
|
||||
"ai-agent/digital-human/model/entity"
|
||||
|
||||
"gitea.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
|
||||
}
|
||||
Reference in New Issue
Block a user