diff --git a/dao/im.go b/dao/im.go index be25d3e..180d907 100644 --- a/dao/im.go +++ b/dao/im.go @@ -2,7 +2,9 @@ package dao import ( "StuAcaWorksAI/proto" + "encoding/json" "gorm.io/gorm" + "log" ) type Session struct { @@ -57,10 +59,15 @@ func FindSessionByUserID(userID int) []Session { // 更新会话的名字 func UpdateSessionByID(id int, userId int, name string, context []int) error { var res *gorm.DB + contextJson, err := json.Marshal(context) + if err != nil { + log.Println("update session json marshal error:", err) + } + if proto.Config.SERVER_SQL_LOG { - res = DB.Debug().Model(&Session{}).Where("id = ? AND user_id = ?", id, userId).Updates(Session{Name: name, Context: context}) + res = DB.Debug().Model(&Session{}).Where("id = ? AND user_id = ?", id, userId).Updates(Session{Name: name}).Update("context", contextJson) } else { - res = DB.Model(&Session{}).Where("id = ? AND user_id = ?", id, userId).Updates(Session{Name: name, Context: context}) + res = DB.Model(&Session{}).Where("id = ? AND user_id = ?", id, userId).Updates(Session{Name: name, Context: nil}).Update("context", contextJson) } return res.Error }