58 lines
1.8 KiB
Go
58 lines
1.8 KiB
Go
package dao
|
|
|
|
import (
|
|
"context"
|
|
"rag/consts/public"
|
|
"rag/model/dto"
|
|
"rag/model/entity"
|
|
|
|
"gitea.com/red-future/common/db/gfdb"
|
|
"github.com/gogf/gf/v2/util/gconv"
|
|
)
|
|
|
|
var DocumentChunk = new(documentChunkDao)
|
|
|
|
type documentChunkDao struct{}
|
|
|
|
// BatchInsert 批量插入文件块
|
|
func (d *documentChunkDao) BatchInsert(ctx context.Context, req []*dto.VectorDocumentChunkMsg) (rows int64, err error) {
|
|
var res []*entity.DocumentChunk
|
|
if err = gconv.Structs(req, &res); err != nil {
|
|
return
|
|
}
|
|
r, err := gfdb.DB(ctx, public.DbNameVector).Model(ctx, public.TableNameDocumentChunk).Data(&res).Insert()
|
|
if err != nil {
|
|
return
|
|
}
|
|
return r.RowsAffected()
|
|
}
|
|
|
|
// Update 更新文件块
|
|
func (d *documentChunkDao) Update(ctx context.Context, req *dto.UpdateDocumentChunkReq) (rows int64, err error) {
|
|
model := gfdb.DB(ctx, public.DbNameVector).Model(ctx, public.TableNameDocumentChunk)
|
|
r, err := model.Data(&req).Where(entity.DocumentChunkCol.Id, req.Id).Update()
|
|
if err != nil {
|
|
return
|
|
}
|
|
return r.RowsAffected()
|
|
}
|
|
|
|
// List 文件块列表
|
|
func (d *documentChunkDao) List(ctx context.Context, req *dto.ListDocumentChunkReq, fields ...string) (res []*entity.DocumentChunk, total int, err error) {
|
|
model := gfdb.DB(ctx, public.DbNameVector).Model(ctx, public.TableNameDocumentChunk).Fields(fields).OmitEmpty().
|
|
Where(entity.DocumentChunkCol.DatasetId, req.DatasetId).
|
|
Where(entity.DocumentChunkCol.DocumentId, req.DocumentId).
|
|
Where(entity.DocumentChunkCol.Status, req.Status).
|
|
Where(entity.DocumentChunkCol.VectorStatus, req.VectorStatus).
|
|
OrderDesc(entity.DocumentChunkCol.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
|
|
}
|