This commit is contained in:
wangchuxiao
2023-01-31 18:55:22 +08:00
parent 467d44adc6
commit 4c931fba5c
11 changed files with 491 additions and 181 deletions
+8 -6
View File
@@ -2,7 +2,6 @@ package relation
import (
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/db"
pbMsg "Open_IM/pkg/proto/msg"
server_api_params "Open_IM/pkg/proto/sdk_ws"
"Open_IM/pkg/utils"
@@ -37,7 +36,11 @@ func (ChatLog) TableName() string {
return "chat_logs"
}
func InsertMessageToChatLog(msg pbMsg.MsgDataToMQ) error {
func NewChatLog(db *gorm.DB) *ChatLog {
return &ChatLog{DB: db}
}
func (c *ChatLog) Create(msg pbMsg.MsgDataToMQ) error {
chatLog := new(ChatLog)
copier.Copy(chatLog, msg.MsgData)
switch msg.MsgData.SessionType {
@@ -61,12 +64,11 @@ func InsertMessageToChatLog(msg pbMsg.MsgDataToMQ) error {
}
chatLog.CreateTime = utils.UnixMillSecondToTime(msg.MsgData.CreateTime)
chatLog.SendTime = utils.UnixMillSecondToTime(msg.MsgData.SendTime)
log.NewDebug("test", "this is ", chatLog)
return db.DB.MysqlDB.DefaultGormDB().Table("chat_logs").Create(chatLog).Error
return c.DB.Create(chatLog).Error
}
func GetChatLog(chatLog *ChatLog, pageNumber, showNumber int32, contentTypeList []int32) (int64, []ChatLog, error) {
mdb := ChatLogDB.Table("chat_logs")
func (c *ChatLog) GetChatLog(chatLog *ChatLog, pageNumber, showNumber int32, contentTypeList []int32) (int64, []ChatLog, error) {
mdb := c.DB.Model(chatLog)
if chatLog.SendTime.Unix() > 0 {
mdb = mdb.Where("send_time > ? and send_time < ?", chatLog.SendTime, chatLog.SendTime.AddDate(0, 0, 1))
}
-50
View File
@@ -1,50 +0,0 @@
package relation
import (
"gorm.io/gorm"
"time"
)
var AppDB *gorm.DB
type AppVersion struct {
Version string `gorm:"column:version;size:64" json:"version"`
Type int `gorm:"column:type;primary_key" json:"type"`
UpdateTime int `gorm:"column:update_time" json:"update_time"`
ForceUpdate bool `gorm:"column:force_update" json:"force_update"`
FileName string `gorm:"column:file_name" json:"file_name"`
YamlName string `gorm:"column:yaml_name" json:"yaml_name"`
UpdateLog string `gorm:"column:update_log" json:"update_log"`
}
func (AppVersion) TableName() string {
return "app_version"
}
func UpdateAppVersion(appType int, version string, forceUpdate bool, fileName, yamlName, updateLog string) error {
updateTime := int(time.Now().Unix())
app := AppVersion{
Version: version,
Type: appType,
UpdateTime: updateTime,
FileName: fileName,
YamlName: yamlName,
ForceUpdate: forceUpdate,
UpdateLog: updateLog,
}
result := AppDB.Model(AppVersion{}).Where("type = ?", appType).Updates(map[string]interface{}{"force_update": forceUpdate,
"version": version, "update_time": int(time.Now().Unix()), "file_name": fileName, "yaml_name": yamlName, "type": appType, "update_log": updateLog})
if result.Error != nil {
return result.Error
}
if result.RowsAffected == 0 {
err := AppDB.Create(&app).Error
return err
}
return nil
}
func GetNewestVersion(appType int) (*AppVersion, error) {
app := AppVersion{}
return &app, AppDB.Model(AppVersion{}).First(&app, appType).Error
}