作者 yangfu

feat: 2.0 稳定搜索优化

... ... @@ -5,6 +5,7 @@ import (
"fmt"
"github.com/samber/lo"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
... ... @@ -31,10 +32,13 @@ func (l *ChatDatasetSearchLogic) ChatDatasetSearch(req *types.ChatDatasetSearchR
conn = l.svcCtx.DefaultDBConn()
dms []*domain.ChatDataset
total int64
token = contextdata.GetUserTokenFromCtx(l.ctx)
)
queryOptions := domain.NewQueryOptions().WithOffsetLimit(req.Page, req.Size).
WithKV("status", req.Status)
WithKV("status", req.Status).
WithKV("companyId", token.CompanyId).
WithKV("userId", token.UserId)
if req.Name != "" {
queryOptions.WithKV("name", fmt.Sprintf("%%%v%%", req.Name))
}
... ...
... ... @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
... ... @@ -30,11 +31,14 @@ func (l *ChatDocumentSearchLogic) ChatDocumentSearch(req *types.ChatDocumentSear
conn = l.svcCtx.DefaultDBConn()
dms []*domain.ChatDocument
total int64
token = contextdata.GetUserTokenFromCtx(l.ctx)
)
queryOptions := domain.NewQueryOptions().WithOffsetLimit(req.Page, req.Size).
WithKV("fileType", req.FileType).
WithKV("status", req.Status)
WithKV("status", req.Status).
WithKV("companyId", token.CompanyId).
WithKV("userId", token.UserId)
if req.Name != "" {
queryOptions.WithKV("name", fmt.Sprintf("%%%v%%", req.Name))
}
... ...
... ... @@ -141,6 +141,12 @@ func (repository *ChatDatasetRepository) Find(ctx context.Context, conn transact
)
queryFunc := func() (interface{}, error) {
tx = tx.Model(&ms).Order("id desc")
if v, ok := queryOptions["companyId"]; ok {
tx.Where("company_id = ?", v)
}
if v, ok := queryOptions["userId"]; ok {
tx.Where("user_id = ?", v)
}
if v, ok := queryOptions["name"]; ok {
tx.Where("name like ?", v)
}
... ...
... ... @@ -141,6 +141,12 @@ func (repository *ChatDocumentRepository) Find(ctx context.Context, conn transac
)
queryFunc := func() (interface{}, error) {
tx = tx.Model(&ms).Order("id desc")
if v, ok := queryOptions["companyId"]; ok {
tx.Where("company_id = ?", v)
}
if v, ok := queryOptions["userId"]; ok {
tx.Where("user_id = ?", v)
}
if v, ok := queryOptions["name"]; ok {
tx.Where("name like ?", v)
}
... ...