...
|
...
|
@@ -3,8 +3,10 @@ package chat |
|
|
import (
|
|
|
"context"
|
|
|
"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/pkg/tool"
|
|
|
|
|
|
"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"
|
...
|
...
|
@@ -47,8 +49,45 @@ func (l *ChatSessionSearchLogic) ChatSessionSearch(req *types.ChatSessionSearchR |
|
|
|
|
|
total, dms, err = l.svcCtx.ChatSessionRepository.Find(l.ctx, conn, queryOptions)
|
|
|
list := make([]types.ChatSessionItem, 0)
|
|
|
for i := range dms {
|
|
|
list = append(list, NewTypesChatSession(dms[i]))
|
|
|
|
|
|
// 1.分组dataset document mapping
|
|
|
var datasetIds []int64
|
|
|
for _, session := range dms {
|
|
|
if session.Type == domain.TypeSparkDatasetChat && session.Metadata.DatasetId > 0 {
|
|
|
datasetIds = append(datasetIds, session.Metadata.DatasetId)
|
|
|
}
|
|
|
datasetIds = lo.Uniq(datasetIds)
|
|
|
}
|
|
|
var groupDocumentMappings map[int64][]*domain.ChatDatasetDocumentMapping
|
|
|
if len(datasetIds) > 0 {
|
|
|
_, documentMapping, _ := l.svcCtx.ChatDatasetDocumentMappingRepository.FindByDataset(l.ctx, conn, datasetIds...)
|
|
|
groupDocumentMappings = lo.GroupBy(documentMapping, func(item *domain.ChatDatasetDocumentMapping) int64 {
|
|
|
return item.DatasetId
|
|
|
})
|
|
|
}
|
|
|
|
|
|
// 2. 加载documents
|
|
|
lazyDocument := tool.NewLazyLoadService(l.svcCtx.ChatDocumentRepository.FindOne)
|
|
|
for i, session := range dms {
|
|
|
var documents []types.ChatDocumentItem
|
|
|
if session.Type == domain.TypeSparkDocumentsChat && len(session.Metadata.DocumentIds) > 0 {
|
|
|
for _, id := range session.Metadata.DocumentIds {
|
|
|
if document, _ := lazyDocument.Load(l.ctx, conn, id); document != nil {
|
|
|
documents = append(documents, types.NewTypesChatDocument(document))
|
|
|
}
|
|
|
}
|
|
|
} else if session.Type == domain.TypeSparkDatasetChat && session.Metadata.DatasetId > 0 {
|
|
|
if documentMapping, ok := groupDocumentMappings[session.Metadata.DatasetId]; ok {
|
|
|
lo.ForEach(documentMapping, func(item *domain.ChatDatasetDocumentMapping, index int) {
|
|
|
if document, _ := lazyDocument.Load(l.ctx, conn, item.DocumentId); document != nil {
|
|
|
documents = append(documents, types.NewTypesChatDocument(document))
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
typesSession := NewTypesChatSession(dms[i])
|
|
|
typesSession.Documents = documents
|
|
|
list = append(list, typesSession)
|
|
|
}
|
|
|
resp = &types.ChatSessionSearchResponse{
|
|
|
List: list,
|
...
|
...
|
|