e_chat_session.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package entity
  2. import (
  3. "context"
  4. "gorm.io/gorm"
  5. "yx-dataset-server/app/schema"
  6. )
  7. // GetChatSessionDB 获取ChatSession存储
  8. func GetChatSessionDB(ctx context.Context, defDB *gorm.DB) *gorm.DB {
  9. return getDBWithModel(ctx, defDB, ChatSession{})
  10. }
  11. // SchemaChatSession ChatSession对象
  12. type SchemaChatSession schema.ChatSession
  13. // ToChatSession 转换为ChatSession实体
  14. func (a SchemaChatSession) ToChatSession() *ChatSession {
  15. item := &ChatSession{
  16. RecordID: a.RecordID,
  17. Name: a.Name,
  18. UserId: a.UserId,
  19. AssistantId: a.AssistantId,
  20. RagChatId: a.RagChatId,
  21. RagSessionId: a.RagSessionId,
  22. CreatorId: a.CreatorId,
  23. }
  24. return item
  25. }
  26. // ToSchemaChatSession 转换为ChatSession对象
  27. func (a ChatSession) ToSchemaChatSession() *schema.ChatSession {
  28. item := &schema.ChatSession{
  29. RecordID: a.RecordID,
  30. Name: a.Name,
  31. UserId: a.UserId,
  32. AssistantId: a.AssistantId,
  33. RagChatId: a.RagChatId,
  34. RagSessionId: a.RagSessionId,
  35. CreatedAt: a.CreatedAt,
  36. CreatorId: a.CreatorId,
  37. }
  38. return item
  39. }
  40. // ChatSession ChatSession实体
  41. type ChatSession struct {
  42. gorm.Model
  43. RecordID string `gorm:"column:record_id;size:32;index;"` // 记录id
  44. Name string `gorm:"column:name;size:30;"` // 名称
  45. UserId string `gorm:"column:user_id;size:32;"` // 用户id
  46. AssistantId string `gorm:"column:assistant_id;size:32;index;"` // 助手id
  47. RagChatId string `gorm:"column:rag_chat_id;size:32"` // rag_chat_id
  48. RagSessionId string `gorm:"column:rag_session_id;size:32;"` // rag_session_id
  49. CreatorId string `gorm:"column:creator_id;size:32;index;"` // 创建人id
  50. }
  51. // ChatSessions ChatSession列表
  52. type ChatSessions []*ChatSession
  53. // ToSchemaChatSessions 转换为ChatSession对象列表
  54. func (a ChatSessions) ToSchemaChatSessions() []*schema.ChatSession {
  55. list := make([]*schema.ChatSession, len(a))
  56. for i, item := range a {
  57. list[i] = item.ToSchemaChatSession()
  58. }
  59. return list
  60. }