user_chat_record.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package llm
  2. import (
  3. "eta/eta_api/global"
  4. "eta/eta_api/utils"
  5. "gorm.io/gorm"
  6. "gorm.io/gorm/clause"
  7. "time"
  8. )
  9. // UserChatRecord 定义用户聊天记录结构体
  10. type UserChatRecord struct {
  11. Id int `gorm:"primaryKey;autoIncrement;comment:主键"`
  12. ChatId int `gorm:"comment:会话id"`
  13. ChatUserType string `gorm:"type:enum('user','assistant');comment:用户方"`
  14. Content string `gorm:"content:内容"`
  15. SendTime time.Time `gorm:"comment:发送时间"`
  16. CreatedTime time.Time `gorm:"comment:创建时间"`
  17. UpdateTime time.Time `gorm:"autoUpdateTime;comment:更新时间"`
  18. }
  19. type UserChatRecordRedis struct {
  20. Id int
  21. ChatId int
  22. ChatUserType string
  23. Content string
  24. SendTime string
  25. }
  26. func (u *UserChatRecord) TableName() string {
  27. return "user_chat_record"
  28. }
  29. func BatchInsertRecords(list []*UserChatRecord) (err error) {
  30. o := global.DbMap[utils.DbNameAI]
  31. err = o.Clauses(clause.OnConflict{
  32. Columns: []clause.Column{{Name: "chat_id"}, {Name: "chat_user_type"}, {Name: "send_time"}},
  33. DoUpdates: clause.Assignments(map[string]interface{}{"update_time": gorm.Expr("VALUES(update_time)")}),
  34. }).CreateInBatches(list, utils.MultiAddNum).Error
  35. return
  36. }