@@ -18,9 +18,8 @@ package dao
1818
1919import (
2020 "fmt"
21+ "ragflow/internal/entity"
2122 "strings"
22-
23- "ragflow/internal/model"
2423)
2524
2625// ChatDAO chat data access object
@@ -32,10 +31,10 @@ func NewChatDAO() *ChatDAO {
3231}
3332
3433// ListByTenantID list chats by tenant ID
35- func (dao * ChatDAO ) ListByTenantID (tenantID string , status string ) ([]* model .Chat , error ) {
36- var chats []* model .Chat
34+ func (dao * ChatDAO ) ListByTenantID (tenantID string , status string ) ([]* entity .Chat , error ) {
35+ var chats []* entity .Chat
3736
38- query := DB .Model (& model .Chat {}).
37+ query := DB .Model (& entity .Chat {}).
3938 Where ("tenant_id = ?" , tenantID )
4039
4140 if status != "" {
@@ -51,12 +50,12 @@ func (dao *ChatDAO) ListByTenantID(tenantID string, status string) ([]*model.Cha
5150}
5251
5352// ListByTenantIDs list chats by tenant IDs with pagination and filtering
54- func (dao * ChatDAO ) ListByTenantIDs (tenantIDs []string , userID string , page , pageSize int , orderby string , desc bool , keywords string ) ([]* model .Chat , int64 , error ) {
55- var chats []* model .Chat
53+ func (dao * ChatDAO ) ListByTenantIDs (tenantIDs []string , userID string , page , pageSize int , orderby string , desc bool , keywords string ) ([]* entity .Chat , int64 , error ) {
54+ var chats []* entity .Chat
5655 var total int64
5756
5857 // Build query with join to user table for nickname and avatar
59- query := DB .Model (& model .Chat {}).
58+ query := DB .Model (& entity .Chat {}).
6059 Select (`
6160 dialog.*,
6261 user.nickname,
@@ -103,11 +102,11 @@ func (dao *ChatDAO) ListByTenantIDs(tenantIDs []string, userID string, page, pag
103102}
104103
105104// ListByOwnerIDs list chats by owner IDs with filtering (manual pagination)
106- func (dao * ChatDAO ) ListByOwnerIDs (ownerIDs []string , userID string , orderby string , desc bool , keywords string ) ([]* model .Chat , int64 , error ) {
107- var chats []* model .Chat
105+ func (dao * ChatDAO ) ListByOwnerIDs (ownerIDs []string , userID string , orderby string , desc bool , keywords string ) ([]* entity .Chat , int64 , error ) {
106+ var chats []* entity .Chat
108107
109108 // Build query with join to user table
110- query := DB .Model (& model .Chat {}).
109+ query := DB .Model (& entity .Chat {}).
111110 Select (`
112111 dialog.*,
113112 user.nickname,
@@ -142,8 +141,8 @@ func (dao *ChatDAO) ListByOwnerIDs(ownerIDs []string, userID string, orderby str
142141}
143142
144143// GetByID gets chat by ID
145- func (dao * ChatDAO ) GetByID (id string ) (* model .Chat , error ) {
146- var chat model .Chat
144+ func (dao * ChatDAO ) GetByID (id string ) (* entity .Chat , error ) {
145+ var chat entity .Chat
147146 err := DB .Where ("id = ?" , id ).First (& chat ).Error
148147 if err != nil {
149148 return nil , err
@@ -152,8 +151,8 @@ func (dao *ChatDAO) GetByID(id string) (*model.Chat, error) {
152151}
153152
154153// GetByIDAndStatus gets chat by ID and status
155- func (dao * ChatDAO ) GetByIDAndStatus (id string , status string ) (* model .Chat , error ) {
156- var chat model .Chat
154+ func (dao * ChatDAO ) GetByIDAndStatus (id string , status string ) (* entity .Chat , error ) {
155+ var chat entity .Chat
157156 err := DB .Where ("id = ? AND status = ?" , id , status ).First (& chat ).Error
158157 if err != nil {
159158 return nil , err
@@ -164,20 +163,20 @@ func (dao *ChatDAO) GetByIDAndStatus(id string, status string) (*model.Chat, err
164163// GetExistingNames gets existing dialog names for a tenant
165164func (dao * ChatDAO ) GetExistingNames (tenantID string , status string ) ([]string , error ) {
166165 var names []string
167- err := DB .Model (& model .Chat {}).
166+ err := DB .Model (& entity .Chat {}).
168167 Where ("tenant_id = ? AND status = ?" , tenantID , status ).
169168 Pluck ("name" , & names ).Error
170169 return names , err
171170}
172171
173172// Create creates a new chat/dialog
174- func (dao * ChatDAO ) Create (chat * model .Chat ) error {
173+ func (dao * ChatDAO ) Create (chat * entity .Chat ) error {
175174 return DB .Create (chat ).Error
176175}
177176
178177// UpdateByID updates a chat by ID
179178func (dao * ChatDAO ) UpdateByID (id string , updates map [string ]interface {}) error {
180- return DB .Model (& model .Chat {}).Where ("id = ?" , id ).Updates (updates ).Error
179+ return DB .Model (& entity .Chat {}).Where ("id = ?" , id ).Updates (updates ).Error
181180}
182181
183182// UpdateManyByID updates multiple chats by ID (batch update)
@@ -207,7 +206,7 @@ func (dao *ChatDAO) UpdateManyByID(updates []map[string]interface{}) error {
207206 }
208207 }
209208
210- if err := tx .Model (& model .Chat {}).Where ("id = ?" , id ).Updates (updatesWithoutID ).Error ; err != nil {
209+ if err := tx .Model (& entity .Chat {}).Where ("id = ?" , id ).Updates (updatesWithoutID ).Error ; err != nil {
211210 tx .Rollback ()
212211 return err
213212 }
@@ -218,14 +217,14 @@ func (dao *ChatDAO) UpdateManyByID(updates []map[string]interface{}) error {
218217
219218// DeleteByTenantID deletes all chats by tenant ID (hard delete)
220219func (dao * ChatDAO ) DeleteByTenantID (tenantID string ) (int64 , error ) {
221- result := DB .Unscoped ().Where ("tenant_id = ?" , tenantID ).Delete (& model .Chat {})
220+ result := DB .Unscoped ().Where ("tenant_id = ?" , tenantID ).Delete (& entity .Chat {})
222221 return result .RowsAffected , result .Error
223222}
224223
225224// GetAllDialogIDsByTenantID gets all dialog IDs by tenant ID
226225func (dao * ChatDAO ) GetAllDialogIDsByTenantID (tenantID string ) ([]string , error ) {
227226 var dialogIDs []string
228- err := DB .Model (& model .Chat {}).
227+ err := DB .Model (& entity .Chat {}).
229228 Where ("tenant_id = ?" , tenantID ).
230229 Pluck ("id" , & dialogIDs ).Error
231230 return dialogIDs , err
0 commit comments