This commit is contained in:
wangchuxiao
2022-02-09 16:22:58 +08:00
parent 43a9bba96f
commit 6de61cb214
14 changed files with 365 additions and 259 deletions
@@ -1,4 +1,4 @@
package message
package messageCMS
import (
"Open_IM/pkg/cms_api_struct"
@@ -7,6 +7,7 @@ import (
"Open_IM/pkg/common/log"
"Open_IM/pkg/grpc-etcdv3/getcdv3"
pbMessage "Open_IM/pkg/proto/message_cms"
pbCommon "Open_IM/pkg/proto/sdk_ws"
"Open_IM/pkg/utils"
"context"
"strings"
@@ -17,6 +18,17 @@ import (
)
func BroadcastMessage(c *gin.Context) {
var (
reqPb pbMessage.BoradcastMessageReq
)
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImMessageCMSName)
client := pbMessage.NewMessageCMSClient(etcdConn)
_, err := client.BoradcastMessage(context.Background(), &reqPb)
if err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "GetChatLogs rpc failed", err.Error())
openIMHttp.RespHttp200S(c, err, nil)
return
}
openIMHttp.RespHttp200(c, constant.OK, nil)
}
@@ -39,13 +51,17 @@ func GetChatLogs(c *gin.Context) {
openIMHttp.RespHttp200(c, constant.ErrArgs, resp)
return
}
reqPb.Pagination = &pbCommon.RequestPagination{
PageNumber: int32(req.PageNumber),
ShowNumber: int32(req.ShowNumber),
}
utils.CopyStructFields(&reqPb, &req)
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImStatisticsName)
client := pbMessage.NewMessageClient(etcdConn)
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImMessageCMSName)
client := pbMessage.NewMessageCMSClient(etcdConn)
respPb, err := client.GetChatLogs(context.Background(), &reqPb)
if err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "GetChatLogs rpc failed", err.Error())
openIMHttp.RespHttp200(c, constant.ErrServer, resp)
openIMHttp.RespHttp200S(c, constant.ErrServer, resp)
return
}
utils.CopyStructFields(&resp, &respPb)
+8 -7
View File
@@ -3,7 +3,7 @@ package cms_api
import (
"Open_IM/internal/cms_api/admin"
"Open_IM/internal/cms_api/group"
"Open_IM/internal/cms_api/message"
messageCMS "Open_IM/internal/cms_api/message_cms"
"Open_IM/internal/cms_api/middleware"
"Open_IM/internal/cms_api/organization"
"Open_IM/internal/cms_api/statistics"
@@ -46,12 +46,6 @@ func NewGinRouter() *gin.Engine {
organizationRouterGroup.PATCH("/alter_corps_info", organization.AlterStaffsInfo)
organizationRouterGroup.POST("/add_child_org", organization.AddChildOrganization)
}
messageRouterGroup := router.Group("/message")
{
messageRouterGroup.POST("/broadcast_message", message.BroadcastMessage)
messageRouterGroup.POST("/mass_send_message", message.MassSendMassage)
messageRouterGroup.POST("/withdraw_message", message.WithdrawMessage)
}
groupRouterGroup := router.Group("/group")
{
groupRouterGroup.GET("/get_group_by_id", group.GetGroupById)
@@ -89,5 +83,12 @@ func NewGinRouter() *gin.Engine {
friendRouterGroup.POST("/set_friend")
friendRouterGroup.POST("/remove_friend")
}
messageCMSRouterGroup := router.Group("/message")
{
messageCMSRouterGroup.GET("/get_chat_logs", messageCMS.GetChatLogs)
messageCMSRouterGroup.POST("/broadcast_message", messageCMS.BroadcastMessage)
messageCMSRouterGroup.POST("/mass_send_message", messageCMS.MassSendMassage)
messageCMSRouterGroup.POST("/withdraw_message", messageCMS.WithdrawMessage)
}
return baseRouter
}
-1
View File
@@ -70,7 +70,6 @@ func GetUsersByName(c *gin.Context) {
openIMHttp.RespHttp200(c, constant.ErrServer, nil)
return
}
fmt.Println(respPb)
utils.CopyStructFields(&resp.Users, respPb.Users)
resp.ShowNumber = int(respPb.Pagination.ShowNumber)
resp.CurrentPage = int(respPb.Pagination.CurrentPage)
+1 -1
View File
@@ -645,7 +645,7 @@ func (s *groupServer) GetGroupById(_ context.Context, req *pbGroup.GetGroupByIdR
resp := &pbGroup.GetGroupByIdResp{CMSGroup: &pbGroup.CMSGroup{
GroupInfo: &open_im_sdk.GroupInfo{},
}}
group, err := imdb.GetGroupsById(req.GroupId)
group, err := imdb.GetGroupById(req.GroupId)
if err != nil {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), err.Error())
return resp, err
+52 -12
View File
@@ -1,21 +1,21 @@
package MessageCMS
package messageCMS
import (
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/db"
"Open_IM/pkg/common/http"
"context"
//"Open_IM/pkg/common/constant"
//"Open_IM/pkg/common/db"
"Open_IM/pkg/common/log"
//cp "Open_IM/pkg/common/utils"
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
"Open_IM/pkg/grpc-etcdv3/getcdv3"
pbMessageCMS "Open_IM/pkg/proto/message_cms"
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
"Open_IM/pkg/utils"
//"context"
"net"
"strconv"
"strings"
@@ -31,17 +31,17 @@ type messageCMSServer struct {
}
func NewMessageCMSServer(port int) *messageCMSServer {
log.NewPrivateLog("Statistics")
log.NewPrivateLog("MessageCMS")
return &messageCMSServer{
rpcPort: port,
rpcRegisterName: config.Config.RpcRegisterName.OpenImStatisticsName,
rpcRegisterName: config.Config.RpcRegisterName.OpenImMessageCMSName,
etcdSchema: config.Config.Etcd.EtcdSchema,
etcdAddr: config.Config.Etcd.EtcdAddr,
}
}
func (s *messageCMSServer) Run() {
log.NewInfo("0", "Statistics rpc start ")
log.NewInfo("0", "messageCMS rpc start ")
ip := utils.ServerIP
registerAddress := ip + ":" + strconv.Itoa(s.rpcPort)
//listener network
@@ -56,7 +56,7 @@ func (s *messageCMSServer) Run() {
srv := grpc.NewServer()
defer srv.GracefulStop()
//Service registers with etcd
pbMessageCMS.RegisterMessageServer(srv, s)
pbMessageCMS.RegisterMessageCMSServer(srv, s)
err = getcdv3.RegisterEtcd(s.etcdSchema, strings.Join(s.etcdAddr, ","), ip, s.rpcPort, s.rpcRegisterName, 10)
if err != nil {
log.NewError("0", "RegisterEtcd failed ", err.Error())
@@ -67,13 +67,13 @@ func (s *messageCMSServer) Run() {
log.NewError("0", "Serve failed ", err.Error())
return
}
log.NewInfo("0", "statistics rpc success")
log.NewInfo("0", "message cms rpc success")
}
func (s *messageCMSServer) BoradcastMessage(_ context.Context, req *pbMessageCMS.BoradcastMessageReq) (*pbMessageCMS.BoradcastMessageResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "BoradcastMessage", req.String())
resp := &pbMessageCMS.BoradcastMessageResp{}
return resp, nil
return resp, http.WarpError(constant.ErrDB)
}
func (s *messageCMSServer) GetChatLogs(_ context.Context, req *pbMessageCMS.GetChatLogsReq) (*pbMessageCMS.GetChatLogsResp, error) {
@@ -82,6 +82,46 @@ func (s *messageCMSServer) GetChatLogs(_ context.Context, req *pbMessageCMS.GetC
chatLog := db.ChatLog{
Content: req.Content,
}
chatLogs, err := imdb.GetChatLog(chatLog, req.Pagination.ShowNumber, req.Pagination.PageNumber)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetChatLog", err.Error())
return resp, http.WarpError(constant.ErrDB)
}
for _, chatLog := range chatLogs {
pbChatLog := &pbMessageCMS.ChatLogs{
SessionType: chatLog.SessionType,
ContentType: chatLog.ContentType,
SenderNickName: chatLog.SenderNickname,
SenderId: chatLog.SendID,
SearchContent: req.Content,
WholeContent: chatLog.Content,
Date: chatLog.CreateTime.String(),
}
switch chatLog.SessionType {
case constant.SingleChatType:
recvUser, err := imdb.GetUserByUserID(chatLog.RecvID)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserByUserID failed", err.Error())
continue
}
pbChatLog.ReciverId = recvUser.UserID
pbChatLog.ReciverNickName = recvUser.Nickname
case constant.GroupChatType:
group, err := imdb.GetGroupById(chatLog.RecvID)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupById failed")
continue
}
pbChatLog.GroupId = group.GroupID
pbChatLog.GroupName = group.GroupName
}
resp.ChatLogs = append(resp.ChatLogs, pbChatLog)
}
resp.Pagination = &open_im_sdk.ResponsePagination{
CurrentPage: req.Pagination.PageNumber,
ShowNumber: req.Pagination.ShowNumber,
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp output: ", resp.String())
return resp, nil
}