From c242bbbd60f851cbe3d4dce81e9f515cd1db53d5 Mon Sep 17 00:00:00 2001 From: junleea <354425203@qq.com> Date: Tue, 25 Mar 2025 15:12:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=AD=98=E4=BC=9A=E8=AF=9D?= =?UTF-8?q?=E8=83=8C=E6=99=AF=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dao/im.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) 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 }