From 49f05d334df6e26b8e2fa81ac9ecbe5aca698547 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Fri, 2 Sep 2022 12:01:10 +0800 Subject: [PATCH] cms --- internal/rpc/admin_cms/admin_cms.go | 2 +- .../db/mysql_model/im_mysql_model/message_cms.go | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/internal/rpc/admin_cms/admin_cms.go b/internal/rpc/admin_cms/admin_cms.go index 1590a502e..4a71cbc60 100644 --- a/internal/rpc/admin_cms/admin_cms.go +++ b/internal/rpc/admin_cms/admin_cms.go @@ -621,7 +621,7 @@ func (s *adminCMSServer) GetUserFriends(_ context.Context, req *pbAdminCMS.GetUs resp.FriendInfoList = append(resp.FriendInfoList, friendInfo) } log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String()) - return nil, nil + return resp, nil } func (s *adminCMSServer) GenerateInvitationCode(_ context.Context, req *pbAdminCMS.GenerateInvitationCodeReq) (*pbAdminCMS.GenerateInvitationCodeResp, error) { diff --git a/pkg/common/db/mysql_model/im_mysql_model/message_cms.go b/pkg/common/db/mysql_model/im_mysql_model/message_cms.go index 7e74c83c4..a32f1730b 100644 --- a/pkg/common/db/mysql_model/im_mysql_model/message_cms.go +++ b/pkg/common/db/mysql_model/im_mysql_model/message_cms.go @@ -12,6 +12,9 @@ func GetChatLog(chatLog db.ChatLog, pageNumber, showNumber int32) ([]db.ChatLog, var chatLogs []db.ChatLog db := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs"). Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1))) + if chatLog.SendTime.Unix() > 0 { + db = db.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)) } @@ -29,9 +32,7 @@ func GetChatLog(chatLog db.ChatLog, pageNumber, showNumber int32) ([]db.ChatLog, if chatLog.RecvID != "" { db = db.Where("recv_id = ?", chatLog.RecvID) } - if chatLog.SendTime.Unix() > 0 { - db = db.Where("send_time > ? and send_time < ?", chatLog.SendTime, chatLog.SendTime.AddDate(0, 0, 1)) - } + err := db.Find(&chatLogs).Error return chatLogs, err } @@ -39,6 +40,10 @@ func GetChatLog(chatLog db.ChatLog, pageNumber, showNumber int32) ([]db.ChatLog, 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 chatLog.Content != "" { db = db.Where(" content like ? ", fmt.Sprintf("%%%s%%", chatLog.Content)) } @@ -56,10 +61,6 @@ func GetChatLogCount(chatLog db.ChatLog) (int64, error) { if chatLog.RecvID != "" { db = db.Where("recv_id = ?", chatLog.RecvID) } - 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)) - } err := db.Count(&count).Error return count, err