fix(knowledge): Fix the issue of ineffective pagination parameters in the image-based knowledge base (#831)
This commit is contained in:
@@ -236,8 +236,11 @@ func (dao *KnowledgeDocumentSliceDAO) FindSliceByCondition(ctx context.Context,
|
||||
|
||||
if opts.PageSize != 0 {
|
||||
do = do.Limit(int(opts.PageSize))
|
||||
do = do.Offset(int(opts.Sequence)).Order(s.Sequence.Asc())
|
||||
}
|
||||
if opts.Offset != 0 {
|
||||
do = do.Offset(int(opts.Offset))
|
||||
}
|
||||
do = do.Order(s.Sequence.Asc())
|
||||
if opts.NotEmpty != nil {
|
||||
if ptr.From(opts.NotEmpty) {
|
||||
do = do.Where(s.Content.Neq(""))
|
||||
@@ -319,3 +322,44 @@ func (dao *KnowledgeDocumentSliceDAO) GetLastSequence(ctx context.Context, docum
|
||||
}
|
||||
return resp.Sequence, nil
|
||||
}
|
||||
|
||||
func (dao *KnowledgeDocumentSliceDAO) ListPhotoSlice(ctx context.Context, opts *entity.WherePhotoSliceOpt) ([]*model.KnowledgeDocumentSlice, int64, error) {
|
||||
s := dao.Query.KnowledgeDocumentSlice
|
||||
do := s.WithContext(ctx)
|
||||
if opts.KnowledgeID != 0 {
|
||||
do = do.Where(s.KnowledgeID.Eq(opts.KnowledgeID))
|
||||
}
|
||||
if len(opts.DocumentIDs) != 0 {
|
||||
do = do.Where(s.DocumentID.In(opts.DocumentIDs...))
|
||||
}
|
||||
if ptr.From(opts.Limit) != 0 {
|
||||
do = do.Limit(int(ptr.From(opts.Limit)))
|
||||
}
|
||||
if ptr.From(opts.Offset) != 0 {
|
||||
do = do.Offset(int(ptr.From(opts.Offset)))
|
||||
}
|
||||
if opts.HasCaption != nil {
|
||||
if ptr.From(opts.HasCaption) {
|
||||
do = do.Where(s.Content.Neq(""))
|
||||
} else {
|
||||
do = do.Where(s.Content.Eq(""))
|
||||
}
|
||||
}
|
||||
do = do.Order(s.UpdatedAt.Desc())
|
||||
pos, err := do.Find()
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
total, err := do.Limit(-1).Offset(-1).Count()
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
return pos, total, nil
|
||||
}
|
||||
|
||||
func (dao *KnowledgeDocumentSliceDAO) BatchCreateWithTX(ctx context.Context, tx *gorm.DB, slices []*model.KnowledgeDocumentSlice) error {
|
||||
if len(slices) == 0 {
|
||||
return nil
|
||||
}
|
||||
return tx.WithContext(ctx).Debug().Model(&model.KnowledgeDocumentSlice{}).CreateInBatches(slices, 100).Error
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user