chat log model update

pull/131/head
Gordon 3 years ago
parent 3c64d84980
commit 911100923f

@ -165,3 +165,22 @@ type Black struct {
OperatorUserID string `gorm:"column:operator_user_id;size:64"`
Ex string `gorm:"column:ex;size:1024"`
}
type ChatLog struct {
ServerMsgID string `gorm:"column:server_msg_id;primary_key;type:char(64)" json:"serverMsgID"`
ClientMsgID string `gorm:"column:client_msg_id;type:char(64)" json:"clientMsgID"`
SendID string `gorm:"column:send_id;type:char(64)" json:"sendID"`
RecvID string `gorm:"column:recv_id;type:char(64)" json:"recvID"`
SenderPlatformID int32 `gorm:"column:sender_platform_id" json:"senderPlatformID"`
SenderNickname string `gorm:"column:sender_nick_name;type:varchar(255)" json:"senderNickname"`
SenderFaceURL string `gorm:"column:sender_face_url;type:varchar(255)" json:"senderFaceURL"`
SessionType int32 `gorm:"column:session_type" json:"sessionType"`
MsgFrom int32 `gorm:"column:msg_from" json:"msgFrom"`
ContentType int32 `gorm:"column:content_type" json:"contentType"`
Content string `gorm:"column:content;type:varchar(1000)" json:"content"`
Status int32 `gorm:"column:status" json:"status"`
Seq uint32 `gorm:"column:seq;index:index_seq;default:0" json:"seq"`
SendTime time.Time `gorm:"column:send_time" json:"sendTime"`
CreateTime time.Time `gorm:"column:create_time" json:"createTime"`
Ex string `gorm:"column:ex;type:varchar(1024)" json:"ex"`
}

@ -58,7 +58,7 @@ func initMysqlDB() {
&GroupMember{},
&GroupRequest{},
&User{},
&Black{})
&Black{}, &ChatLog{})
db.Set("gorm:table_options", "CHARSET=utf8")
//

@ -11,45 +11,24 @@ import (
"Open_IM/pkg/common/db"
pbMsg "Open_IM/pkg/proto/chat"
"Open_IM/pkg/utils"
"database/sql"
"time"
"github.com/jinzhu/copier"
)
// ChatLog Chat information table structure
type ChatLog struct {
MsgId string `gorm:"primary_key"` // Chat history primary key ID
SendID string `gorm:"column:send_id"` // Send ID
RecvID string `gorm:"column:recv_id"` //Receive ID
SendTime time.Time `gorm:"column:send_time"` // Send time
SessionType int32 `gorm:"column:session_type"` // Session type
ContentType int32 `gorm:"column:content_type"` // Message content type
MsgFrom int32 `gorm:"column:msg_from"` // Source, user, system
Content string `gorm:"column:content"` // Chat content
SenderPlatformID int32 `gorm:"column:sender_platform_id"` //The sender's platform ID
Remark sql.NullString `gorm:"column:remark"` // remark
}
func InsertMessageToChatLog(msg pbMsg.MsgDataToMQ) error {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err
}
chatLog := ChatLog{
MsgId: msg.MsgData.ServerMsgID,
SendID: msg.MsgData.SendID,
SendTime: utils.UnixNanoSecondToTime(msg.MsgData.SendTime),
SessionType: msg.MsgData.SessionType,
ContentType: msg.MsgData.ContentType,
MsgFrom: msg.MsgData.MsgFrom,
Content: string(msg.MsgData.Content),
SenderPlatformID: msg.MsgData.SenderPlatformID,
}
chatLog := new(db.ChatLog)
copier.Copy(chatLog, msg.MsgData)
switch msg.MsgData.SessionType {
case constant.GroupChatType:
chatLog.RecvID = msg.MsgData.GroupID
case constant.SingleChatType:
chatLog.RecvID = msg.MsgData.RecvID
}
chatLog.Content = string(msg.MsgData.Content)
chatLog.CreateTime = utils.UnixNanoSecondToTime(msg.MsgData.CreateTime)
chatLog.SendTime = utils.UnixNanoSecondToTime(msg.MsgData.SendTime)
return dbConn.Table("chat_log").Create(chatLog).Error
}

Loading…
Cancel
Save