- 新增操作日志表(asynch_op_log)及对应DAO,记录任务创建等操作的审计信息 - 新增任务分页查询接口(ListTask)及对应DTO、Service和DAO方法 - 优化模型调用失败重试逻辑:支持配置重试排队策略(插队到队首或队尾) - 新增临时文件存储机制,当模型调用成功但OSS上传失败时,下次仅重试OSS上传 - 模型配置新增retry_queue_max_seconds字段,控制失败重试排队策略 - 更新数据库表结构(asynch_models、asynch_task、新增asynch_op_log)及同步更新SQL - 配置文件调整:超时单位改为秒,更新服务地址和轮询间隔 - 修复模型列表查询支持按名称模糊搜索
92 lines
2.3 KiB
Go
92 lines
2.3 KiB
Go
package dao
|
||
|
||
import (
|
||
"context"
|
||
|
||
"model-asynch/consts/public"
|
||
"model-asynch/model/entity"
|
||
|
||
"gitea.com/red-future/common/db/gfdb"
|
||
"github.com/gogf/gf/v2/util/gconv"
|
||
)
|
||
|
||
var Model = &modelDao{}
|
||
|
||
type modelDao struct{}
|
||
|
||
func (d *modelDao) Insert(ctx context.Context, m *entity.AsynchModel) (id int64, err error) {
|
||
r, err := gfdb.DB(ctx).Model(ctx, public.TableNameModel).Data(m).Insert()
|
||
if err != nil {
|
||
return 0, err
|
||
}
|
||
return r.LastInsertId()
|
||
}
|
||
|
||
func (d *modelDao) UpdateByID(ctx context.Context, id int64, data map[string]any) (rows int64, err error) {
|
||
// 触发 gfdb 的 updateHook 自动填充 updater,需要显式带 updater 字段
|
||
data[entity.AsynchModelCol.Updater] = ""
|
||
r, err := gfdb.DB(ctx).Model(ctx, public.TableNameModel).
|
||
Where(entity.AsynchModelCol.Id, id).
|
||
Data(data).
|
||
Update()
|
||
if err != nil {
|
||
return 0, err
|
||
}
|
||
return r.RowsAffected()
|
||
}
|
||
|
||
func (d *modelDao) DeleteByID(ctx context.Context, id int64) (rows int64, err error) {
|
||
r, err := gfdb.DB(ctx).Model(ctx, public.TableNameModel).
|
||
Where(entity.AsynchModelCol.Id, id).
|
||
Delete()
|
||
if err != nil {
|
||
return 0, err
|
||
}
|
||
return r.RowsAffected()
|
||
}
|
||
|
||
func (d *modelDao) GetByModelName(ctx context.Context, modelName string) (m *entity.AsynchModel, err error) {
|
||
r, err := gfdb.DB(ctx).Model(ctx, public.TableNameModel).
|
||
Where(entity.AsynchModelCol.ModelName, modelName).
|
||
One()
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
if r.IsEmpty() {
|
||
return nil, nil
|
||
}
|
||
err = r.Struct(&m)
|
||
return
|
||
}
|
||
|
||
func (d *modelDao) GetByID(ctx context.Context, id int64) (m *entity.AsynchModel, err error) {
|
||
r, err := gfdb.DB(ctx).Model(ctx, public.TableNameModel).
|
||
Where(entity.AsynchModelCol.Id, id).
|
||
One()
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
if r.IsEmpty() {
|
||
return nil, nil
|
||
}
|
||
err = r.Struct(&m)
|
||
return
|
||
}
|
||
|
||
func (d *modelDao) List(ctx context.Context, pageNum, pageSize int, modelNameLike string) (list []*entity.AsynchModel, total int64, err error) {
|
||
model := gfdb.DB(ctx).Model(ctx, public.TableNameModel).Where("deleted_at IS NULL").OrderDesc(entity.AsynchModelCol.CreatedAt)
|
||
if modelNameLike != "" {
|
||
model = model.WhereLike(entity.AsynchModelCol.ModelName, "%"+modelNameLike+"%")
|
||
}
|
||
if pageNum > 0 && pageSize > 0 {
|
||
model = model.Page(pageNum, pageSize)
|
||
}
|
||
r, totalInt, err := model.AllAndCount(false)
|
||
if err != nil {
|
||
return nil, 0, err
|
||
}
|
||
total = gconv.Int64(totalInt)
|
||
err = r.Structs(&list)
|
||
return
|
||
}
|