package llm import ( "errors" "eta/eta_api/global" "eta/eta_api/utils" "time" ) type UserLlmChat struct { Id int `gorm:"primaryKey;autoIncrement;comment:会话主键"` UserId int `gorm:"comment:用户id"` ChatTitle string `gorm:"comment:会话标题"` IsDeleted int `gorm:"comment:是否删除"` CreatedTime time.Time `gorm:"comment:创建时间"` UpdateTime time.Time `gorm:"autoUpdateTime;comment:更新时间"` } func (u *UserLlmChat) TableName() string { return "user_llm_chat" } func (u *UserLlmChat) CreateChatSession() (err error) { o := global.DbMap[utils.DbNameAI] err = o.Create(u).Error return } func (u *UserLlmChat) RenameChatSession() (err error) { o := global.DbMap[utils.DbNameAI] var exists bool err = o.Model(&u).Select("1").Where("id = ?", u.Id).Scan(&exists).Error if err != nil { return } if !exists { err = errors.New("当前会话不存在") return } err = o.Select("chat_title").Updates(u).Error return } func GetUserChatList(userId int, monDay, toDay string) (chatList []UserLlmChat, err error) { o := global.DbMap[utils.DbNameAI] sql := `select ulc.id ,ulc.chat_title,ulc.created_time,COUNT(ucr.id) AS record_count from user_llm_chat ulc left join user_chat_record ucr ON ucr.chat_id = ulc.id where ulc.user_id=? and ? BETWEEN ? and ? GROUP BY ulc.id` err = o.Raw(sql, userId, utils.GenerateQuerySql(utils.ToDate, &utils.QueryParam{Column: "ulc.created_time"}), monDay, toDay).Find(&chatList).Error return }