修复存会话背景问题
This commit is contained in:
parent
746df74b83
commit
c242bbbd60
11
dao/im.go
11
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
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue