mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-06-04 23:09:34 +08:00
get chat log do not need time
This commit is contained in:
parent
dce0e370cf
commit
8ac36526a8
@ -215,38 +215,47 @@ func (s *adminCMSServer) GetUserRegisterAddFriendIDList(_ context.Context, req *
|
||||
func (s *adminCMSServer) GetChatLogs(_ context.Context, req *pbAdminCMS.GetChatLogsReq) (*pbAdminCMS.GetChatLogsResp, error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "GetChatLogs", req.String())
|
||||
resp := &pbAdminCMS.GetChatLogsResp{CommonResp: &pbAdminCMS.CommonResp{}, Pagination: &server_api_params.ResponsePagination{}}
|
||||
time, err := utils.TimeStringToTime(req.SendTime)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "time string parse error", err.Error())
|
||||
resp.CommonResp.ErrCode = constant.ErrArgs.ErrCode
|
||||
resp.CommonResp.ErrMsg = err.Error()
|
||||
return resp, nil
|
||||
}
|
||||
chatLog := db.ChatLog{
|
||||
Content: req.Content,
|
||||
SendTime: time,
|
||||
ContentType: req.ContentType,
|
||||
SessionType: req.SessionType,
|
||||
RecvID: req.RecvID,
|
||||
SendID: req.SendID,
|
||||
}
|
||||
if req.SendTime != "" {
|
||||
sendTime, err := utils.TimeStringToTime(req.SendTime)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "time string parse error", err.Error(), req.SendTime)
|
||||
resp.CommonResp.ErrCode = constant.ErrArgs.ErrCode
|
||||
resp.CommonResp.ErrMsg = err.Error()
|
||||
return resp, nil
|
||||
}
|
||||
chatLog.SendTime = sendTime
|
||||
}
|
||||
nums, err := imdb.GetChatLogCount(chatLog)
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "chat_log: ", chatLog)
|
||||
|
||||
num, chatLogs, err := imdb.GetChatLog(&chatLog, req.Pagination.PageNumber, req.Pagination.ShowNumber, []int32{
|
||||
constant.Text,
|
||||
constant.Picture,
|
||||
constant.Voice,
|
||||
constant.Video,
|
||||
constant.File,
|
||||
constant.AtText,
|
||||
constant.Merger,
|
||||
constant.Card,
|
||||
constant.Location,
|
||||
constant.Custom,
|
||||
constant.Revoke,
|
||||
constant.Quote,
|
||||
constant.AdvancedText,
|
||||
constant.AdvancedRevoke,
|
||||
constant.CustomNotTriggerConversation,
|
||||
})
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetChatLogCount", err.Error(), chatLog)
|
||||
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
|
||||
resp.CommonResp.ErrMsg = err.Error()
|
||||
return resp, nil
|
||||
}
|
||||
resp.ChatLogsNum = int32(nums)
|
||||
chatLogs, err := imdb.GetChatLog(chatLog, req.Pagination.PageNumber, req.Pagination.ShowNumber)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetChatLog", err.Error(), chatLog)
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetChatLog", err.Error())
|
||||
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
|
||||
resp.CommonResp.ErrMsg = err.Error()
|
||||
return resp, nil
|
||||
}
|
||||
resp.ChatLogsNum = int32(num)
|
||||
for _, chatLog := range chatLogs {
|
||||
pbChatLog := &pbAdminCMS.ChatLog{}
|
||||
utils.CopyStructFields(pbChatLog, chatLog)
|
||||
@ -284,7 +293,6 @@ func (s *adminCMSServer) GetChatLogs(_ context.Context, req *pbAdminCMS.GetChatL
|
||||
CurrentPage: req.Pagination.PageNumber,
|
||||
ShowNumber: req.Pagination.ShowNumber,
|
||||
}
|
||||
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp output: ", resp.String())
|
||||
return resp, nil
|
||||
}
|
||||
|
@ -3,65 +3,42 @@ package im_mysql_model
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/utils"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func GetChatLog(chatLog db.ChatLog, pageNumber, showNumber int32) ([]db.ChatLog, error) {
|
||||
var chatLogs []db.ChatLog
|
||||
db := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs").
|
||||
Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1)))
|
||||
func GetChatLog(chatLog *db.ChatLog, pageNumber, showNumber int32, contentTypeList []int32) (int64, []db.ChatLog, error) {
|
||||
mdb := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs")
|
||||
if chatLog.SendTime.Unix() > 0 {
|
||||
db = db.Where("send_time > ? and send_time < ?", chatLog.SendTime, chatLog.SendTime.AddDate(0, 0, 1))
|
||||
mdb = mdb.Where("send_time > ? and send_time < ?", chatLog.SendTime, chatLog.SendTime.AddDate(0, 0, 1))
|
||||
}
|
||||
if chatLog.Content != "" {
|
||||
db = db.Where(" content like ? ", fmt.Sprintf("%%%s%%", chatLog.Content))
|
||||
mdb = mdb.Where(" content like ? ", fmt.Sprintf("%%%s%%", chatLog.Content))
|
||||
}
|
||||
if chatLog.SessionType == 1 {
|
||||
db = db.Where("session_type = ?", chatLog.SessionType)
|
||||
mdb = mdb.Where("session_type = ?", chatLog.SessionType)
|
||||
} else if chatLog.SessionType == 2 {
|
||||
db = db.Where("session_type in (?)", []int{constant.GroupChatType, constant.SuperGroupChatType})
|
||||
mdb = mdb.Where("session_type in (?)", []int{constant.GroupChatType, constant.SuperGroupChatType})
|
||||
}
|
||||
if chatLog.ContentType != 0 {
|
||||
db = db.Where("content_type = ?", chatLog.ContentType)
|
||||
mdb = mdb.Where("content_type = ?", chatLog.ContentType)
|
||||
}
|
||||
if chatLog.SendID != "" {
|
||||
db = db.Where("send_id = ?", chatLog.SendID)
|
||||
mdb = mdb.Where("send_id = ?", chatLog.SendID)
|
||||
}
|
||||
if chatLog.RecvID != "" {
|
||||
db = db.Where("recv_id = ?", chatLog.RecvID)
|
||||
mdb = mdb.Where("recv_id = ?", chatLog.RecvID)
|
||||
}
|
||||
if len(contentTypeList) > 0 {
|
||||
mdb = mdb.Where("content_type in (?)", contentTypeList)
|
||||
}
|
||||
|
||||
err := db.Find(&chatLogs).Error
|
||||
return chatLogs, err
|
||||
}
|
||||
|
||||
func GetChatLogCount(chatLog db.ChatLog) (int64, error) {
|
||||
var count int64
|
||||
db := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs")
|
||||
if chatLog.SendTime.Unix() > 0 {
|
||||
log.NewDebug("", utils.GetSelfFuncName(), chatLog.SendTime, chatLog.SendTime.AddDate(0, 0, 1))
|
||||
db = db.Where("send_time > ? and send_time < ?", chatLog.SendTime, chatLog.SendTime.AddDate(0, 0, 1))
|
||||
if err := mdb.Count(&count).Error; err != nil {
|
||||
return 0, nil, err
|
||||
}
|
||||
if chatLog.Content != "" {
|
||||
db = db.Where(" content like ? ", fmt.Sprintf("%%%s%%", chatLog.Content))
|
||||
var chatLogs []db.ChatLog
|
||||
mdb = mdb.Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1)))
|
||||
if err := mdb.Find(&chatLogs).Error; err != nil {
|
||||
return 0, nil, err
|
||||
}
|
||||
if chatLog.SessionType == 1 {
|
||||
db = db.Where("session_type = ?", chatLog.SessionType)
|
||||
} else if chatLog.SessionType == 2 {
|
||||
db = db.Where("session_type in (?)", []int{constant.GroupChatType, constant.SuperGroupChatType})
|
||||
}
|
||||
if chatLog.ContentType != 0 {
|
||||
db = db.Where("content_type = ?", chatLog.ContentType)
|
||||
}
|
||||
if chatLog.SendID != "" {
|
||||
db = db.Where("send_id = ?", chatLog.SendID)
|
||||
}
|
||||
if chatLog.RecvID != "" {
|
||||
db = db.Where("recv_id = ?", chatLog.RecvID)
|
||||
}
|
||||
|
||||
err := db.Count(&count).Error
|
||||
return count, err
|
||||
return count, chatLogs, nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user