package entity import ( "context" "gorm.io/gorm" "yx-dataset-server/app/schema" ) // GetChatSessionDB 获取ChatSession存储 func GetChatSessionDB(ctx context.Context, defDB *gorm.DB) *gorm.DB { return getDBWithModel(ctx, defDB, ChatSession{}) } // SchemaChatSession ChatSession对象 type SchemaChatSession schema.ChatSession // ToChatSession 转换为ChatSession实体 func (a SchemaChatSession) ToChatSession() *ChatSession { item := &ChatSession{ RecordID: a.RecordID, Name: a.Name, UserId: a.UserId, AssistantId: a.AssistantId, RagChatId: a.RagChatId, RagSessionId: a.RagSessionId, CreatorId: a.CreatorId, } return item } // ToSchemaChatSession 转换为ChatSession对象 func (a ChatSession) ToSchemaChatSession() *schema.ChatSession { item := &schema.ChatSession{ RecordID: a.RecordID, Name: a.Name, UserId: a.UserId, AssistantId: a.AssistantId, RagChatId: a.RagChatId, RagSessionId: a.RagSessionId, CreatedAt: a.CreatedAt, CreatorId: a.CreatorId, } return item } // ChatSession ChatSession实体 type ChatSession struct { gorm.Model RecordID string `gorm:"column:record_id;size:32;index;"` // 记录id Name string `gorm:"column:name;size:30;"` // 名称 UserId string `gorm:"column:user_id;size:32;"` // 用户id AssistantId string `gorm:"column:assistant_id;size:32;index;"` // 助手id RagChatId string `gorm:"column:rag_chat_id;size:32"` // rag_chat_id RagSessionId string `gorm:"column:rag_session_id;size:32;"` // rag_session_id CreatorId string `gorm:"column:creator_id;size:32;index;"` // 创建人id } // ChatSessions ChatSession列表 type ChatSessions []*ChatSession // ToSchemaChatSessions 转换为ChatSession对象列表 func (a ChatSessions) ToSchemaChatSessions() []*schema.ChatSession { list := make([]*schema.ChatSession, len(a)) for i, item := range a { list[i] = item.ToSchemaChatSession() } return list }