mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-08-19 11:22:07 +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) {
|
func (s *adminCMSServer) GetChatLogs(_ context.Context, req *pbAdminCMS.GetChatLogsReq) (*pbAdminCMS.GetChatLogsResp, error) {
|
||||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "GetChatLogs", req.String())
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "GetChatLogs", req.String())
|
||||||
resp := &pbAdminCMS.GetChatLogsResp{CommonResp: &pbAdminCMS.CommonResp{}, Pagination: &server_api_params.ResponsePagination{}}
|
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{
|
chatLog := db.ChatLog{
|
||||||
Content: req.Content,
|
Content: req.Content,
|
||||||
|
SendTime: time,
|
||||||
ContentType: req.ContentType,
|
ContentType: req.ContentType,
|
||||||
SessionType: req.SessionType,
|
SessionType: req.SessionType,
|
||||||
RecvID: req.RecvID,
|
RecvID: req.RecvID,
|
||||||
SendID: req.SendID,
|
SendID: req.SendID,
|
||||||
}
|
}
|
||||||
if req.SendTime != "" {
|
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "chat_log: ", chatLog)
|
||||||
sendTime, err := utils.TimeStringToTime(req.SendTime)
|
|
||||||
|
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 {
|
if err != nil {
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "time string parse error", err.Error(), req.SendTime)
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetChatLog", err.Error())
|
||||||
resp.CommonResp.ErrCode = constant.ErrArgs.ErrCode
|
|
||||||
resp.CommonResp.ErrMsg = err.Error()
|
|
||||||
return resp, nil
|
|
||||||
}
|
|
||||||
chatLog.SendTime = sendTime
|
|
||||||
}
|
|
||||||
nums, err := imdb.GetChatLogCount(chatLog)
|
|
||||||
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)
|
|
||||||
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
|
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
|
||||||
resp.CommonResp.ErrMsg = err.Error()
|
resp.CommonResp.ErrMsg = err.Error()
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
resp.ChatLogsNum = int32(num)
|
||||||
for _, chatLog := range chatLogs {
|
for _, chatLog := range chatLogs {
|
||||||
pbChatLog := &pbAdminCMS.ChatLog{}
|
pbChatLog := &pbAdminCMS.ChatLog{}
|
||||||
utils.CopyStructFields(pbChatLog, chatLog)
|
utils.CopyStructFields(pbChatLog, chatLog)
|
||||||
@ -284,7 +293,6 @@ func (s *adminCMSServer) GetChatLogs(_ context.Context, req *pbAdminCMS.GetChatL
|
|||||||
CurrentPage: req.Pagination.PageNumber,
|
CurrentPage: req.Pagination.PageNumber,
|
||||||
ShowNumber: req.Pagination.ShowNumber,
|
ShowNumber: req.Pagination.ShowNumber,
|
||||||
}
|
}
|
||||||
|
|
||||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp output: ", resp.String())
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp output: ", resp.String())
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
@ -3,65 +3,42 @@ package im_mysql_model
|
|||||||
import (
|
import (
|
||||||
"Open_IM/pkg/common/constant"
|
"Open_IM/pkg/common/constant"
|
||||||
"Open_IM/pkg/common/db"
|
"Open_IM/pkg/common/db"
|
||||||
"Open_IM/pkg/common/log"
|
|
||||||
"Open_IM/pkg/utils"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetChatLog(chatLog db.ChatLog, pageNumber, showNumber int32) ([]db.ChatLog, error) {
|
func GetChatLog(chatLog *db.ChatLog, pageNumber, showNumber int32, contentTypeList []int32) (int64, []db.ChatLog, error) {
|
||||||
var chatLogs []db.ChatLog
|
mdb := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs")
|
||||||
db := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs").
|
|
||||||
Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1)))
|
|
||||||
if chatLog.SendTime.Unix() > 0 {
|
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 != "" {
|
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 {
|
if chatLog.SessionType == 1 {
|
||||||
db = db.Where("session_type = ?", chatLog.SessionType)
|
mdb = mdb.Where("session_type = ?", chatLog.SessionType)
|
||||||
} else if chatLog.SessionType == 2 {
|
} 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 {
|
if chatLog.ContentType != 0 {
|
||||||
db = db.Where("content_type = ?", chatLog.ContentType)
|
mdb = mdb.Where("content_type = ?", chatLog.ContentType)
|
||||||
}
|
}
|
||||||
if chatLog.SendID != "" {
|
if chatLog.SendID != "" {
|
||||||
db = db.Where("send_id = ?", chatLog.SendID)
|
mdb = mdb.Where("send_id = ?", chatLog.SendID)
|
||||||
}
|
}
|
||||||
if chatLog.RecvID != "" {
|
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
|
var count int64
|
||||||
db := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs")
|
if err := mdb.Count(&count).Error; err != nil {
|
||||||
if chatLog.SendTime.Unix() > 0 {
|
return 0, nil, err
|
||||||
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 chatLog.Content != "" {
|
var chatLogs []db.ChatLog
|
||||||
db = db.Where(" content like ? ", fmt.Sprintf("%%%s%%", chatLog.Content))
|
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 {
|
return count, chatLogs, nil
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user