mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-05-23 21:39:22 +08:00
msg model
This commit is contained in:
parent
574ed54d6b
commit
5b0c2c8759
@ -0,0 +1,48 @@
|
|||||||
|
/*
|
||||||
|
** description("").
|
||||||
|
** copyright('tuoyun,www.tuoyun.net').
|
||||||
|
** author("fg,Gordon@tuoyun.net").
|
||||||
|
** time(2021/3/4 11:18).
|
||||||
|
*/
|
||||||
|
package im_mysql_msg_model
|
||||||
|
|
||||||
|
import (
|
||||||
|
"Open_IM/src/common/db"
|
||||||
|
pbMsg "Open_IM/src/proto/chat"
|
||||||
|
"Open_IM/src/utils"
|
||||||
|
"database/sql"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 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(msgData pbMsg.WSToMsgSvrChatMsg) error {
|
||||||
|
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
chatLog := ChatLog{
|
||||||
|
MsgId: msgData.MsgID,
|
||||||
|
SendID: msgData.SendID,
|
||||||
|
RecvID: msgData.RecvID,
|
||||||
|
SendTime: utils.UnixSecondToTime(msgData.SendTime),
|
||||||
|
SessionType: msgData.SessionType,
|
||||||
|
ContentType: msgData.ContentType,
|
||||||
|
MsgFrom: msgData.MsgFrom,
|
||||||
|
Content: msgData.Content,
|
||||||
|
SenderPlatformID: msgData.PlatformID,
|
||||||
|
}
|
||||||
|
return dbConn.Table("chat_log").Create(chatLog).Error
|
||||||
|
}
|
36
src/common/db/mysql_model/im_mysql_msg_model/hash_code.go
Normal file
36
src/common/db/mysql_model/im_mysql_msg_model/hash_code.go
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
package im_mysql_msg_model
|
||||||
|
|
||||||
|
import (
|
||||||
|
"Open_IM/src/common/config"
|
||||||
|
"Open_IM/src/common/db"
|
||||||
|
"hash/crc32"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
func getHashMsgDBAddr(userID string) string {
|
||||||
|
hCode := crc32.ChecksumIEEE([]byte(userID))
|
||||||
|
return config.Config.Mysql.DBAddress[hCode%uint32(len(config.Config.Mysql.DBAddress))]
|
||||||
|
}
|
||||||
|
|
||||||
|
func getHashMsgTableIndex(userID string) int {
|
||||||
|
hCode := crc32.ChecksumIEEE([]byte(userID))
|
||||||
|
return int(hCode % uint32(config.Config.Mysql.DBMsgTableNum))
|
||||||
|
}
|
||||||
|
|
||||||
|
func QueryUserMsgID(userID string) ([]string, error) {
|
||||||
|
dbAddress, dbTableIndex := getHashMsgDBAddr(userID), getHashMsgTableIndex(userID)
|
||||||
|
dbTableName := "receive" + strconv.Itoa(dbTableIndex)
|
||||||
|
|
||||||
|
dbConn, _ := db.DB.MysqlDB.GormDB(dbAddress, config.Config.Mysql.DBTableName)
|
||||||
|
|
||||||
|
var msgID string
|
||||||
|
var msgIDList []string
|
||||||
|
rows, _ := dbConn.Raw("select msg_id from ? where user_id = ?", dbTableName, userID).Rows()
|
||||||
|
defer rows.Close()
|
||||||
|
for rows.Next() {
|
||||||
|
rows.Scan(&msgID)
|
||||||
|
msgIDList = append(msgIDList, msgID)
|
||||||
|
}
|
||||||
|
|
||||||
|
return msgIDList, nil
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
** description("").
|
||||||
|
** copyright('tuoyun,www.tuoyun.net').
|
||||||
|
** author("fg,Gordon@tuoyun.net").
|
||||||
|
** time(2021/3/4 11:18).
|
||||||
|
*/
|
||||||
|
package im_mysql_msg_model
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Receive Inbox table structure
|
||||||
|
type Receive struct {
|
||||||
|
UserId string `gorm:"primary_key"` // 收件箱主键ID
|
||||||
|
Seq int64 `gorm:"primary_key"` // 收件箱主键ID
|
||||||
|
MsgId string
|
||||||
|
CreateTime *time.Time
|
||||||
|
}
|
||||||
|
|
||||||
|
//func InsertMessageToReceive(seq int64, userid, msgid string) error {
|
||||||
|
// conn := db.NewDbConnection()
|
||||||
|
// receive := Receive{
|
||||||
|
// UID: userid,
|
||||||
|
// Seq: seq,
|
||||||
|
// MsgId: msgid,
|
||||||
|
// }
|
||||||
|
// err := conn.Table("receive").Create(&receive).Error
|
||||||
|
// return err
|
||||||
|
//}
|
||||||
|
//func GetBiggestSeqFromReceive(userid string) (seq int64, err error) {
|
||||||
|
// //得到数据库的连接(并非真连接,调用时才连接,由gorm自动维护数据库连接池)
|
||||||
|
// conn := db.NewDbConnection()
|
||||||
|
// err = conn.Raw("select max(seq) from receive where user_id = ?", userid).Row().Scan(&seq)
|
||||||
|
// return seq, err
|
||||||
|
//}
|
Loading…
x
Reference in New Issue
Block a user