commit
bdae1f10d4
@ -1,23 +0,0 @@
|
|||||||
.PHONY: all build run gotool install clean help
|
|
||||||
|
|
||||||
BINARY_NAME=open_im_message_cms
|
|
||||||
BIN_DIR=../../../bin/
|
|
||||||
|
|
||||||
all: gotool build
|
|
||||||
|
|
||||||
build:
|
|
||||||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s"
|
|
||||||
|
|
||||||
run:
|
|
||||||
@go run ./
|
|
||||||
|
|
||||||
gotool:
|
|
||||||
go fmt ./
|
|
||||||
go vet ./
|
|
||||||
|
|
||||||
install:
|
|
||||||
make build
|
|
||||||
mv ${BINARY_NAME} ${BIN_DIR}
|
|
||||||
|
|
||||||
clean:
|
|
||||||
@if [ -f ${BINARY_NAME} ] ; then rm ${BINARY_NAME} ; fi
|
|
@ -1,17 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
rpcMessageCMS "Open_IM/internal/rpc/message_cms"
|
|
||||||
"Open_IM/pkg/common/config"
|
|
||||||
"flag"
|
|
||||||
"fmt"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
defaultPorts := config.Config.RpcPort.OpenImMessageCmsPort[0]
|
|
||||||
rpcPort := flag.Int("port", defaultPorts, "rpc listening port")
|
|
||||||
flag.Parse()
|
|
||||||
fmt.Println("start msg cms rpc server, port: ", *rpcPort)
|
|
||||||
rpcServer := rpcMessageCMS.NewMessageCMSServer(*rpcPort)
|
|
||||||
rpcServer.Run()
|
|
||||||
}
|
|
@ -1,23 +0,0 @@
|
|||||||
.PHONY: all build run gotool install clean help
|
|
||||||
|
|
||||||
BINARY_NAME=open_im_statistics
|
|
||||||
BIN_DIR=../../../bin/
|
|
||||||
|
|
||||||
all: gotool build
|
|
||||||
|
|
||||||
build:
|
|
||||||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s"
|
|
||||||
|
|
||||||
run:
|
|
||||||
@go run ./
|
|
||||||
|
|
||||||
gotool:
|
|
||||||
go fmt ./
|
|
||||||
go vet ./
|
|
||||||
|
|
||||||
install:
|
|
||||||
make build
|
|
||||||
mv ${BINARY_NAME} ${BIN_DIR}
|
|
||||||
|
|
||||||
clean:
|
|
||||||
@if [ -f ${BINARY_NAME} ] ; then rm ${BINARY_NAME} ; fi
|
|
@ -1,17 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"Open_IM/internal/rpc/statistics"
|
|
||||||
"Open_IM/pkg/common/config"
|
|
||||||
"flag"
|
|
||||||
"fmt"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
defaultPorts := config.Config.RpcPort.OpenImStatisticsPort
|
|
||||||
rpcPort := flag.Int("port", defaultPorts[0], "rpc listening port")
|
|
||||||
flag.Parse()
|
|
||||||
fmt.Println("start statistics rpc server, port: ", *rpcPort)
|
|
||||||
rpcServer := statistics.NewStatisticsServer(*rpcPort)
|
|
||||||
rpcServer.Run()
|
|
||||||
}
|
|
@ -0,0 +1,63 @@
|
|||||||
|
package friend
|
||||||
|
|
||||||
|
import (
|
||||||
|
"Open_IM/pkg/cms_api_struct"
|
||||||
|
"Open_IM/pkg/common/config"
|
||||||
|
"Open_IM/pkg/common/log"
|
||||||
|
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||||
|
pbAdmin "Open_IM/pkg/proto/admin_cms"
|
||||||
|
pbCommon "Open_IM/pkg/proto/sdk_ws"
|
||||||
|
"Open_IM/pkg/utils"
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetUserFriends(c *gin.Context) {
|
||||||
|
var (
|
||||||
|
req cms_api_struct.GetFriendsReq
|
||||||
|
resp cms_api_struct.GetFriendsResp
|
||||||
|
reqPb pbAdmin.GetUserFriendsReq
|
||||||
|
)
|
||||||
|
if err := c.BindJSON(&req); err != nil {
|
||||||
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), "ShouldBindQuery failed ", err.Error())
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "req: ", req)
|
||||||
|
reqPb.Pagination = &pbCommon.RequestPagination{}
|
||||||
|
utils.CopyStructFields(&reqPb.Pagination, req)
|
||||||
|
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImAdminCMSName, reqPb.OperationID)
|
||||||
|
if etcdConn == nil {
|
||||||
|
errMsg := reqPb.OperationID + "getcdv3.GetDefaultConn == nil"
|
||||||
|
log.NewError(reqPb.OperationID, errMsg)
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
reqPb.OperationID = req.OperationID
|
||||||
|
reqPb.UserID = req.UserID
|
||||||
|
reqPb.FriendUserName = req.FriendUserName
|
||||||
|
reqPb.FriendUserID = req.FriendUserID
|
||||||
|
|
||||||
|
client := pbAdmin.NewAdminCMSClient(etcdConn)
|
||||||
|
respPb, err := client.GetUserFriends(context.Background(), &reqPb)
|
||||||
|
if err != nil {
|
||||||
|
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "GetUserInfo failed ", err.Error())
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for _, v := range respPb.FriendInfoList {
|
||||||
|
friend := &cms_api_struct.FriendInfo{}
|
||||||
|
utils.CopyStructFields(friend, v)
|
||||||
|
friend.Nickname = v.FriendUser.Nickname
|
||||||
|
friend.UserID = v.FriendUser.UserID
|
||||||
|
resp.FriendInfoList = append(resp.FriendInfoList, friend)
|
||||||
|
}
|
||||||
|
resp.FriendNums = respPb.FriendNums
|
||||||
|
resp.CurrentPage = int(respPb.Pagination.CurrentPage)
|
||||||
|
resp.ShowNumber = int(respPb.Pagination.ShowNumber)
|
||||||
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
|
||||||
|
c.JSON(http.StatusOK, gin.H{"errCode": respPb.CommonResp.ErrCode, "errMsg": respPb.CommonResp.ErrMsg, "data": resp})
|
||||||
|
}
|
@ -1,49 +0,0 @@
|
|||||||
package organization
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
)
|
|
||||||
|
|
||||||
func GetStaffs(c *gin.Context) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetOrganizations(c *gin.Context) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetSquads(c *gin.Context) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func AlterStaff(c *gin.Context) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func AddOrganization(c *gin.Context) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func InquireOrganization(g *gin.Context) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func AlterOrganization(c *gin.Context) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func DeleteOrganization(g *gin.Context) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetOrganizationSquads(c *gin.Context) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func AlterStaffsInfo(c *gin.Context) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func AddChildOrganization(c *gin.Context) {
|
|
||||||
|
|
||||||
}
|
|
@ -0,0 +1,81 @@
|
|||||||
|
package register
|
||||||
|
|
||||||
|
import (
|
||||||
|
"Open_IM/pkg/common/constant"
|
||||||
|
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||||
|
"Open_IM/pkg/common/log"
|
||||||
|
"Open_IM/pkg/utils"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
type CheckLoginLimitReq struct {
|
||||||
|
OperationID string `json:"operationID"`
|
||||||
|
UserID string `json:"userID"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type CheckLoginLimitResp struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func CheckLoginLimit(c *gin.Context) {
|
||||||
|
req := CheckLoginLimitReq{}
|
||||||
|
if err := c.BindJSON(&req); err != nil {
|
||||||
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), err.Error())
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": constant.ErrArgs, "errMsg": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ip := c.Request.Header.Get("X-Forward-For")
|
||||||
|
if ip == "" {
|
||||||
|
ip = c.ClientIP()
|
||||||
|
}
|
||||||
|
user, err := imdb.GetUserIPLimit(req.UserID)
|
||||||
|
if err != nil {
|
||||||
|
errMsg := req.OperationID + " imdb.GetUserByUserID failed " + err.Error() + req.UserID
|
||||||
|
log.NewError(req.OperationID, errMsg)
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": constant.ErrDB.ErrCode, "errMsg": errMsg})
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := imdb.UpdateIpReocord(req.UserID, ip); err != nil {
|
||||||
|
log.NewError(req.OperationID, err.Error(), req.UserID, ip)
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": constant.ErrDB.ErrCode, "errMsg": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var Limited bool
|
||||||
|
var LimitError error
|
||||||
|
Limited, LimitError = imdb.IsLimitLoginIp(ip)
|
||||||
|
if LimitError != nil {
|
||||||
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), LimitError, ip)
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": constant.ErrDB.ErrCode, "errMsg": LimitError})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if Limited {
|
||||||
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), Limited, ip, req.UserID)
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": constant.LoginLimit, "errMsg": "ip limited Login"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
Limited, LimitError = imdb.IsLimitUserLoginIp(user.UserID, ip)
|
||||||
|
if LimitError != nil {
|
||||||
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), LimitError, ip)
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": constant.ErrDB.ErrCode, "errMsg": LimitError})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if Limited {
|
||||||
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), Limited, ip, req.UserID)
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": constant.LoginLimit, "errMsg": "user ip limited Login"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
Limited, LimitError = imdb.UserIsBlock(user.UserID)
|
||||||
|
if LimitError != nil {
|
||||||
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), LimitError, user.UserID)
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": constant.ErrDB.ErrCode, "errMsg": LimitError})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if Limited {
|
||||||
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), Limited, ip, req.UserID)
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": constant.LoginLimit, "errMsg": "user is block"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusOK, gin.H{"errCode": 0, "errMsg": ""})
|
||||||
|
}
|
@ -1,182 +0,0 @@
|
|||||||
package messageCMS
|
|
||||||
|
|
||||||
import (
|
|
||||||
"Open_IM/pkg/common/config"
|
|
||||||
"Open_IM/pkg/common/constant"
|
|
||||||
"Open_IM/pkg/common/db"
|
|
||||||
errors "Open_IM/pkg/common/http"
|
|
||||||
"context"
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"Open_IM/pkg/common/log"
|
|
||||||
|
|
||||||
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"
|
|
||||||
|
|
||||||
"net"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"google.golang.org/grpc"
|
|
||||||
)
|
|
||||||
|
|
||||||
type messageCMSServer struct {
|
|
||||||
rpcPort int
|
|
||||||
rpcRegisterName string
|
|
||||||
etcdSchema string
|
|
||||||
etcdAddr []string
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewMessageCMSServer(port int) *messageCMSServer {
|
|
||||||
log.NewPrivateLog(constant.LogFileName)
|
|
||||||
return &messageCMSServer{
|
|
||||||
rpcPort: port,
|
|
||||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImMessageCMSName,
|
|
||||||
etcdSchema: config.Config.Etcd.EtcdSchema,
|
|
||||||
etcdAddr: config.Config.Etcd.EtcdAddr,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *messageCMSServer) Run() {
|
|
||||||
log.NewInfo("0", "messageCMS rpc start ")
|
|
||||||
|
|
||||||
listenIP := ""
|
|
||||||
if config.Config.ListenIP == "" {
|
|
||||||
listenIP = "0.0.0.0"
|
|
||||||
} else {
|
|
||||||
listenIP = config.Config.ListenIP
|
|
||||||
}
|
|
||||||
address := listenIP + ":" + strconv.Itoa(s.rpcPort)
|
|
||||||
|
|
||||||
//listener network
|
|
||||||
listener, err := net.Listen("tcp", address)
|
|
||||||
if err != nil {
|
|
||||||
panic("listening err:" + err.Error() + s.rpcRegisterName)
|
|
||||||
}
|
|
||||||
log.NewInfo("0", "listen network success, ", address, listener)
|
|
||||||
defer listener.Close()
|
|
||||||
//grpc server
|
|
||||||
srv := grpc.NewServer()
|
|
||||||
defer srv.GracefulStop()
|
|
||||||
//Service registers with etcd
|
|
||||||
pbMessageCMS.RegisterMessageCMSServer(srv, s)
|
|
||||||
rpcRegisterIP := config.Config.RpcRegisterIP
|
|
||||||
if config.Config.RpcRegisterIP == "" {
|
|
||||||
rpcRegisterIP, err = utils.GetLocalIP()
|
|
||||||
if err != nil {
|
|
||||||
log.Error("", "GetLocalIP failed ", err.Error())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
log.NewInfo("", "rpcRegisterIP", rpcRegisterIP)
|
|
||||||
err = getcdv3.RegisterEtcd(s.etcdSchema, strings.Join(s.etcdAddr, ","), rpcRegisterIP, s.rpcPort, s.rpcRegisterName, 10)
|
|
||||||
if err != nil {
|
|
||||||
log.NewError("0", "RegisterEtcd failed ", err.Error())
|
|
||||||
panic(utils.Wrap(err, "register message_cms module rpc to etcd err"))
|
|
||||||
}
|
|
||||||
err = srv.Serve(listener)
|
|
||||||
if err != nil {
|
|
||||||
log.NewError("0", "Serve failed ", err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
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, errors.WrapError(constant.ErrDB)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *messageCMSServer) GetChatLogs(_ context.Context, req *pbMessageCMS.GetChatLogsReq) (*pbMessageCMS.GetChatLogsResp, error) {
|
|
||||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "GetChatLogs", req.String())
|
|
||||||
resp := &pbMessageCMS.GetChatLogsResp{}
|
|
||||||
time, err := utils.TimeStringToTime(req.Date)
|
|
||||||
if err != nil {
|
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "time string parse error", err.Error())
|
|
||||||
}
|
|
||||||
chatLog := db.ChatLog{
|
|
||||||
Content: req.Content,
|
|
||||||
SendTime: time,
|
|
||||||
ContentType: req.ContentType,
|
|
||||||
SessionType: req.SessionType,
|
|
||||||
}
|
|
||||||
switch chatLog.SessionType {
|
|
||||||
case constant.SingleChatType:
|
|
||||||
chatLog.SendID = req.UserId
|
|
||||||
case constant.GroupChatType:
|
|
||||||
chatLog.RecvID = req.GroupId
|
|
||||||
chatLog.SendID = req.UserId
|
|
||||||
}
|
|
||||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "chat_log: ", chatLog)
|
|
||||||
nums, err := imdb.GetChatLogCount(chatLog)
|
|
||||||
resp.ChatLogsNum = int32(nums)
|
|
||||||
if err != nil {
|
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetChatLogCount", err.Error())
|
|
||||||
}
|
|
||||||
chatLogs, err := imdb.GetChatLog(chatLog, req.Pagination.PageNumber, req.Pagination.ShowNumber)
|
|
||||||
if err != nil {
|
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetChatLog", err.Error())
|
|
||||||
return resp, errors.WrapError(constant.ErrDB)
|
|
||||||
}
|
|
||||||
for _, chatLog := range chatLogs {
|
|
||||||
pbChatLog := &pbMessageCMS.ChatLogs{
|
|
||||||
SessionType: chatLog.SessionType,
|
|
||||||
ContentType: chatLog.ContentType,
|
|
||||||
SearchContent: req.Content,
|
|
||||||
WholeContent: chatLog.Content,
|
|
||||||
Date: chatLog.CreateTime.String(),
|
|
||||||
SenderNickName: chatLog.SenderNickname,
|
|
||||||
SenderId: chatLog.SendID,
|
|
||||||
}
|
|
||||||
if chatLog.SenderNickname == "" {
|
|
||||||
sendUser, err := imdb.GetUserByUserID(chatLog.SendID)
|
|
||||||
if err != nil {
|
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserByUserID failed", err.Error())
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
pbChatLog.SenderNickName = sendUser.Nickname
|
|
||||||
}
|
|
||||||
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.GetGroupInfoByGroupID(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
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *messageCMSServer) MassSendMessage(_ context.Context, req *pbMessageCMS.MassSendMessageReq) (*pbMessageCMS.MassSendMessageResp, error) {
|
|
||||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "MassSendMessage", req.String())
|
|
||||||
resp := &pbMessageCMS.MassSendMessageResp{}
|
|
||||||
return resp, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *messageCMSServer) WithdrawMessage(_ context.Context, req *pbMessageCMS.WithdrawMessageReq) (*pbMessageCMS.WithdrawMessageResp, error) {
|
|
||||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "WithdrawMessage", req.String())
|
|
||||||
resp := &pbMessageCMS.WithdrawMessageResp{}
|
|
||||||
return resp, nil
|
|
||||||
}
|
|
@ -1,399 +0,0 @@
|
|||||||
package statistics
|
|
||||||
|
|
||||||
import (
|
|
||||||
"Open_IM/pkg/common/config"
|
|
||||||
"Open_IM/pkg/common/constant"
|
|
||||||
"context"
|
|
||||||
"strconv"
|
|
||||||
"sync"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
//"Open_IM/pkg/common/constant"
|
|
||||||
//"Open_IM/pkg/common/db"
|
|
||||||
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
|
||||||
"Open_IM/pkg/common/log"
|
|
||||||
|
|
||||||
//cp "Open_IM/pkg/common/utils"
|
|
||||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
|
||||||
pbStatistics "Open_IM/pkg/proto/statistics"
|
|
||||||
|
|
||||||
//open_im_sdk "Open_IM/pkg/proto/sdk_ws"
|
|
||||||
"Open_IM/pkg/utils"
|
|
||||||
//"context"
|
|
||||||
errors "Open_IM/pkg/common/http"
|
|
||||||
"net"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"google.golang.org/grpc"
|
|
||||||
)
|
|
||||||
|
|
||||||
type statisticsServer struct {
|
|
||||||
rpcPort int
|
|
||||||
rpcRegisterName string
|
|
||||||
etcdSchema string
|
|
||||||
etcdAddr []string
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewStatisticsServer(port int) *statisticsServer {
|
|
||||||
log.NewPrivateLog(constant.LogFileName)
|
|
||||||
return &statisticsServer{
|
|
||||||
rpcPort: port,
|
|
||||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImStatisticsName,
|
|
||||||
etcdSchema: config.Config.Etcd.EtcdSchema,
|
|
||||||
etcdAddr: config.Config.Etcd.EtcdAddr,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *statisticsServer) Run() {
|
|
||||||
log.NewInfo("0", "Statistics rpc start ")
|
|
||||||
|
|
||||||
listenIP := ""
|
|
||||||
if config.Config.ListenIP == "" {
|
|
||||||
listenIP = "0.0.0.0"
|
|
||||||
} else {
|
|
||||||
listenIP = config.Config.ListenIP
|
|
||||||
}
|
|
||||||
address := listenIP + ":" + strconv.Itoa(s.rpcPort)
|
|
||||||
|
|
||||||
//listener network
|
|
||||||
listener, err := net.Listen("tcp", address)
|
|
||||||
if err != nil {
|
|
||||||
panic("listening err:" + err.Error() + s.rpcRegisterName)
|
|
||||||
}
|
|
||||||
log.NewInfo("0", "listen network success, ", address, listener)
|
|
||||||
defer listener.Close()
|
|
||||||
//grpc server
|
|
||||||
srv := grpc.NewServer()
|
|
||||||
defer srv.GracefulStop()
|
|
||||||
//Service registers with etcd
|
|
||||||
pbStatistics.RegisterUserServer(srv, s)
|
|
||||||
rpcRegisterIP := config.Config.RpcRegisterIP
|
|
||||||
if config.Config.RpcRegisterIP == "" {
|
|
||||||
rpcRegisterIP, err = utils.GetLocalIP()
|
|
||||||
if err != nil {
|
|
||||||
log.Error("", "GetLocalIP failed ", err.Error())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
err = getcdv3.RegisterEtcd(s.etcdSchema, strings.Join(s.etcdAddr, ","), rpcRegisterIP, s.rpcPort, s.rpcRegisterName, 10)
|
|
||||||
if err != nil {
|
|
||||||
log.NewError("0", "RegisterEtcd failed ", err.Error())
|
|
||||||
panic(utils.Wrap(err, "register statistics module rpc to etcd err"))
|
|
||||||
}
|
|
||||||
err = srv.Serve(listener)
|
|
||||||
if err != nil {
|
|
||||||
log.NewError("0", "Serve failed ", err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
log.NewInfo("0", "statistics rpc success")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *statisticsServer) GetActiveGroup(_ context.Context, req *pbStatistics.GetActiveGroupReq) (*pbStatistics.GetActiveGroupResp, error) {
|
|
||||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req", req.String())
|
|
||||||
resp := &pbStatistics.GetActiveGroupResp{}
|
|
||||||
fromTime, toTime, err := ParseTimeFromTo(req.StatisticsReq.From, req.StatisticsReq.To)
|
|
||||||
if err != nil {
|
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "ParseTimeFromTo failed", err.Error())
|
|
||||||
return resp, errors.WrapError(constant.ErrArgs)
|
|
||||||
}
|
|
||||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "time: ", fromTime, toTime)
|
|
||||||
activeGroups, err := imdb.GetActiveGroups(fromTime, toTime, 12)
|
|
||||||
if err != nil {
|
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetActiveGroups failed", err.Error())
|
|
||||||
return resp, errors.WrapError(constant.ErrDB)
|
|
||||||
}
|
|
||||||
for _, activeGroup := range activeGroups {
|
|
||||||
resp.Groups = append(resp.Groups,
|
|
||||||
&pbStatistics.GroupResp{
|
|
||||||
GroupName: activeGroup.Name,
|
|
||||||
GroupId: activeGroup.Id,
|
|
||||||
MessageNum: int32(activeGroup.MessageNum),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), resp.String())
|
|
||||||
return resp, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *statisticsServer) GetActiveUser(_ context.Context, req *pbStatistics.GetActiveUserReq) (*pbStatistics.GetActiveUserResp, error) {
|
|
||||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), req.String())
|
|
||||||
resp := &pbStatistics.GetActiveUserResp{}
|
|
||||||
fromTime, toTime, err := ParseTimeFromTo(req.StatisticsReq.From, req.StatisticsReq.To)
|
|
||||||
if err != nil {
|
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "ParseTimeFromTo failed", err.Error())
|
|
||||||
return resp, errors.WrapError(constant.ErrDB)
|
|
||||||
}
|
|
||||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "time: ", fromTime, toTime)
|
|
||||||
activeUsers, err := imdb.GetActiveUsers(fromTime, toTime, 12)
|
|
||||||
if err != nil {
|
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetActiveUsers failed", err.Error())
|
|
||||||
return resp, errors.WrapError(constant.ErrDB)
|
|
||||||
}
|
|
||||||
for _, activeUser := range activeUsers {
|
|
||||||
resp.Users = append(resp.Users,
|
|
||||||
&pbStatistics.UserResp{
|
|
||||||
UserId: activeUser.Id,
|
|
||||||
NickName: activeUser.Name,
|
|
||||||
MessageNum: int32(activeUser.MessageNum),
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), resp.String())
|
|
||||||
return resp, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func ParseTimeFromTo(from, to string) (time.Time, time.Time, error) {
|
|
||||||
var fromTime time.Time
|
|
||||||
var toTime time.Time
|
|
||||||
fromTime, err := utils.TimeStringToTime(from)
|
|
||||||
if err != nil {
|
|
||||||
return fromTime, toTime, err
|
|
||||||
}
|
|
||||||
toTime, err = utils.TimeStringToTime(to)
|
|
||||||
if err != nil {
|
|
||||||
return fromTime, toTime, err
|
|
||||||
}
|
|
||||||
return fromTime, toTime, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func isInOneMonth(from, to time.Time) bool {
|
|
||||||
return from.Month() == to.Month() && from.Year() == to.Year()
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetRangeDate(from, to time.Time) [][2]time.Time {
|
|
||||||
interval := to.Sub(from)
|
|
||||||
var times [][2]time.Time
|
|
||||||
switch {
|
|
||||||
// today
|
|
||||||
case interval == 0:
|
|
||||||
times = append(times, [2]time.Time{
|
|
||||||
from, from.Add(time.Hour * 24),
|
|
||||||
})
|
|
||||||
// days
|
|
||||||
case isInOneMonth(from, to):
|
|
||||||
for i := 0; ; i++ {
|
|
||||||
fromTime := from.Add(time.Hour * 24 * time.Duration(i))
|
|
||||||
toTime := from.Add(time.Hour * 24 * time.Duration(i+1))
|
|
||||||
if toTime.After(to.Add(time.Hour * 24)) {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
times = append(times, [2]time.Time{
|
|
||||||
fromTime, toTime,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
// month
|
|
||||||
case !isInOneMonth(from, to):
|
|
||||||
if to.Sub(from) < time.Hour*24*30 {
|
|
||||||
for i := 0; ; i++ {
|
|
||||||
fromTime := from.Add(time.Hour * 24 * time.Duration(i))
|
|
||||||
toTime := from.Add(time.Hour * 24 * time.Duration(i+1))
|
|
||||||
if toTime.After(to.Add(time.Hour * 24)) {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
times = append(times, [2]time.Time{
|
|
||||||
fromTime, toTime,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for i := 0; ; i++ {
|
|
||||||
if i == 0 {
|
|
||||||
fromTime := from
|
|
||||||
toTime := getFirstDateOfNextNMonth(fromTime, 1)
|
|
||||||
times = append(times, [2]time.Time{
|
|
||||||
fromTime, toTime,
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
fromTime := getFirstDateOfNextNMonth(from, i)
|
|
||||||
toTime := getFirstDateOfNextNMonth(fromTime, 1)
|
|
||||||
if toTime.After(to) {
|
|
||||||
toTime = to
|
|
||||||
times = append(times, [2]time.Time{
|
|
||||||
fromTime, toTime,
|
|
||||||
})
|
|
||||||
break
|
|
||||||
}
|
|
||||||
times = append(times, [2]time.Time{
|
|
||||||
fromTime, toTime,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return times
|
|
||||||
}
|
|
||||||
|
|
||||||
func getFirstDateOfNextNMonth(currentTime time.Time, n int) time.Time {
|
|
||||||
lastOfMonth := time.Date(currentTime.Year(), currentTime.Month(), 1, 0, 0, 0, 0, currentTime.Location()).AddDate(0, n, 0)
|
|
||||||
return lastOfMonth
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *statisticsServer) GetGroupStatistics(_ context.Context, req *pbStatistics.GetGroupStatisticsReq) (*pbStatistics.GetGroupStatisticsResp, error) {
|
|
||||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), req.String())
|
|
||||||
resp := &pbStatistics.GetGroupStatisticsResp{}
|
|
||||||
fromTime, toTime, err := ParseTimeFromTo(req.StatisticsReq.From, req.StatisticsReq.To)
|
|
||||||
if err != nil {
|
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupStatistics failed", err.Error())
|
|
||||||
return resp, errors.WrapError(constant.ErrArgs)
|
|
||||||
}
|
|
||||||
increaseGroupNum, err := imdb.GetIncreaseGroupNum(fromTime, toTime.Add(time.Hour*24))
|
|
||||||
if err != nil {
|
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetIncreaseGroupNum failed", err.Error(), fromTime, toTime)
|
|
||||||
return resp, errors.WrapError(constant.ErrDB)
|
|
||||||
}
|
|
||||||
totalGroupNum, err := imdb.GetTotalGroupNum()
|
|
||||||
if err != nil {
|
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
|
|
||||||
return resp, errors.WrapError(constant.ErrDB)
|
|
||||||
}
|
|
||||||
resp.IncreaseGroupNum = increaseGroupNum
|
|
||||||
resp.TotalGroupNum = totalGroupNum
|
|
||||||
times := GetRangeDate(fromTime, toTime)
|
|
||||||
log.NewDebug(req.OperationID, "times:", times)
|
|
||||||
wg := &sync.WaitGroup{}
|
|
||||||
resp.IncreaseGroupNumList = make([]*pbStatistics.DateNumList, len(times), len(times))
|
|
||||||
resp.TotalGroupNumList = make([]*pbStatistics.DateNumList, len(times), len(times))
|
|
||||||
wg.Add(len(times))
|
|
||||||
for i, v := range times {
|
|
||||||
go func(wg *sync.WaitGroup, index int, v [2]time.Time) {
|
|
||||||
defer wg.Done()
|
|
||||||
num, err := imdb.GetIncreaseGroupNum(v[0], v[1])
|
|
||||||
if err != nil {
|
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetIncreaseGroupNum", v, err.Error())
|
|
||||||
}
|
|
||||||
resp.IncreaseGroupNumList[index] = &pbStatistics.DateNumList{
|
|
||||||
Date: v[0].String(),
|
|
||||||
Num: num,
|
|
||||||
}
|
|
||||||
num, err = imdb.GetGroupNum(v[1])
|
|
||||||
if err != nil {
|
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetIncreaseGroupNum", v, err.Error())
|
|
||||||
}
|
|
||||||
resp.TotalGroupNumList[index] = &pbStatistics.DateNumList{
|
|
||||||
Date: v[0].String(),
|
|
||||||
Num: num,
|
|
||||||
}
|
|
||||||
}(wg, i, v)
|
|
||||||
}
|
|
||||||
wg.Wait()
|
|
||||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
|
|
||||||
return resp, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *statisticsServer) GetMessageStatistics(_ context.Context, req *pbStatistics.GetMessageStatisticsReq) (*pbStatistics.GetMessageStatisticsResp, error) {
|
|
||||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), req.String())
|
|
||||||
resp := &pbStatistics.GetMessageStatisticsResp{}
|
|
||||||
fromTime, toTime, err := ParseTimeFromTo(req.StatisticsReq.From, req.StatisticsReq.To)
|
|
||||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "times: ", fromTime, toTime)
|
|
||||||
if err != nil {
|
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "ParseTimeFromTo failed", err.Error())
|
|
||||||
return resp, errors.WrapError(constant.ErrArgs)
|
|
||||||
}
|
|
||||||
privateMessageNum, err := imdb.GetPrivateMessageNum(fromTime, toTime.Add(time.Hour*24))
|
|
||||||
if err != nil {
|
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetPrivateMessageNum failed", err.Error())
|
|
||||||
return resp, errors.WrapError(constant.ErrDB)
|
|
||||||
}
|
|
||||||
groupMessageNum, err := imdb.GetGroupMessageNum(fromTime, toTime.Add(time.Hour*24))
|
|
||||||
if err != nil {
|
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupMessageNum failed", err.Error())
|
|
||||||
return resp, errors.WrapError(constant.ErrDB)
|
|
||||||
}
|
|
||||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), privateMessageNum, groupMessageNum)
|
|
||||||
resp.PrivateMessageNum = privateMessageNum
|
|
||||||
resp.GroupMessageNum = groupMessageNum
|
|
||||||
times := GetRangeDate(fromTime, toTime)
|
|
||||||
resp.GroupMessageNumList = make([]*pbStatistics.DateNumList, len(times), len(times))
|
|
||||||
resp.PrivateMessageNumList = make([]*pbStatistics.DateNumList, len(times), len(times))
|
|
||||||
wg := &sync.WaitGroup{}
|
|
||||||
wg.Add(len(times))
|
|
||||||
for i, v := range times {
|
|
||||||
go func(wg *sync.WaitGroup, index int, v [2]time.Time) {
|
|
||||||
defer wg.Done()
|
|
||||||
|
|
||||||
num, err := imdb.GetPrivateMessageNum(v[0], v[1])
|
|
||||||
if err != nil {
|
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetIncreaseGroupNum", v, err.Error())
|
|
||||||
}
|
|
||||||
resp.PrivateMessageNumList[index] = &pbStatistics.DateNumList{
|
|
||||||
Date: v[0].String(),
|
|
||||||
Num: num,
|
|
||||||
}
|
|
||||||
num, err = imdb.GetGroupMessageNum(v[0], v[1])
|
|
||||||
if err != nil {
|
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetIncreaseGroupNum", v, err.Error())
|
|
||||||
}
|
|
||||||
resp.GroupMessageNumList[index] = &pbStatistics.DateNumList{
|
|
||||||
Date: v[0].String(),
|
|
||||||
Num: num,
|
|
||||||
}
|
|
||||||
}(wg, i, v)
|
|
||||||
}
|
|
||||||
wg.Wait()
|
|
||||||
return resp, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *statisticsServer) GetUserStatistics(_ context.Context, req *pbStatistics.GetUserStatisticsReq) (*pbStatistics.GetUserStatisticsResp, error) {
|
|
||||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
|
||||||
resp := &pbStatistics.GetUserStatisticsResp{}
|
|
||||||
fromTime, toTime, err := ParseTimeFromTo(req.StatisticsReq.From, req.StatisticsReq.To)
|
|
||||||
if err != nil {
|
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "ParseTimeFromTo failed", err.Error())
|
|
||||||
return resp, errors.WrapError(constant.ErrArgs)
|
|
||||||
}
|
|
||||||
activeUserNum, err := imdb.GetActiveUserNum(fromTime, toTime.Add(time.Hour*24))
|
|
||||||
if err != nil {
|
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetActiveUserNum failed", err.Error())
|
|
||||||
return resp, errors.WrapError(constant.ErrDB)
|
|
||||||
}
|
|
||||||
increaseUserNum, err := imdb.GetIncreaseUserNum(fromTime, toTime.Add(time.Hour*24))
|
|
||||||
if err != nil {
|
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetIncreaseUserNum failed", err.Error())
|
|
||||||
return resp, errors.WrapError(constant.ErrDB)
|
|
||||||
}
|
|
||||||
totalUserNum, err := imdb.GetTotalUserNum()
|
|
||||||
if err != nil {
|
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetTotalUserNum failed", err.Error())
|
|
||||||
return resp, errors.WrapError(constant.ErrDB)
|
|
||||||
}
|
|
||||||
resp.ActiveUserNum = activeUserNum
|
|
||||||
resp.TotalUserNum = totalUserNum
|
|
||||||
resp.IncreaseUserNum = increaseUserNum
|
|
||||||
times := GetRangeDate(fromTime, toTime)
|
|
||||||
resp.TotalUserNumList = make([]*pbStatistics.DateNumList, len(times), len(times))
|
|
||||||
resp.ActiveUserNumList = make([]*pbStatistics.DateNumList, len(times), len(times))
|
|
||||||
resp.IncreaseUserNumList = make([]*pbStatistics.DateNumList, len(times), len(times))
|
|
||||||
wg := &sync.WaitGroup{}
|
|
||||||
wg.Add(len(times))
|
|
||||||
for i, v := range times {
|
|
||||||
go func(wg *sync.WaitGroup, index int, v [2]time.Time) {
|
|
||||||
defer wg.Done()
|
|
||||||
num, err := imdb.GetActiveUserNum(v[0], v[1])
|
|
||||||
if err != nil {
|
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetIncreaseGroupNum", v, err.Error())
|
|
||||||
}
|
|
||||||
resp.ActiveUserNumList[index] = &pbStatistics.DateNumList{
|
|
||||||
Date: v[0].String(),
|
|
||||||
Num: num,
|
|
||||||
}
|
|
||||||
|
|
||||||
num, err = imdb.GetTotalUserNumByDate(v[1])
|
|
||||||
if err != nil {
|
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetTotalUserNumByDate", v, err.Error())
|
|
||||||
}
|
|
||||||
resp.TotalUserNumList[index] = &pbStatistics.DateNumList{
|
|
||||||
Date: v[0].String(),
|
|
||||||
Num: num,
|
|
||||||
}
|
|
||||||
num, err = imdb.GetIncreaseUserNum(v[0], v[1])
|
|
||||||
if err != nil {
|
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetIncreaseUserNum", v, err.Error())
|
|
||||||
}
|
|
||||||
resp.IncreaseUserNumList[index] = &pbStatistics.DateNumList{
|
|
||||||
Date: v[0].String(),
|
|
||||||
Num: num,
|
|
||||||
}
|
|
||||||
}(wg, i, v)
|
|
||||||
}
|
|
||||||
wg.Wait()
|
|
||||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
|
|
||||||
return resp, nil
|
|
||||||
}
|
|
@ -0,0 +1,11 @@
|
|||||||
|
package base_info
|
||||||
|
|
||||||
|
type RequestPagination struct {
|
||||||
|
PageNumber int `json:"pageNumber" binding:"required"`
|
||||||
|
ShowNumber int `json:"showNumber" binding:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ResponsePagination struct {
|
||||||
|
CurrentPage int `json:"currentPage"`
|
||||||
|
ShowNumber int `json:"showNumber"`
|
||||||
|
}
|
@ -1,16 +1,11 @@
|
|||||||
package cms_api_struct
|
package cms_api_struct
|
||||||
|
|
||||||
type RequestPagination struct {
|
type RequestPagination struct {
|
||||||
PageNumber int `form:"page_number" binding:"required"`
|
|
||||||
ShowNumber int `form:"show_number" binding:"required"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type RequestPaginationBody struct {
|
|
||||||
PageNumber int `json:"pageNumber" binding:"required"`
|
PageNumber int `json:"pageNumber" binding:"required"`
|
||||||
ShowNumber int `json:"showNumber" binding:"required"`
|
ShowNumber int `json:"showNumber" binding:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ResponsePagination struct {
|
type ResponsePagination struct {
|
||||||
CurrentPage int `json:"current_number" binding:"required"`
|
CurrentPage int `json:"currentPage"`
|
||||||
ShowNumber int `json:"show_number" binding:"required"`
|
ShowNumber int `json:"showNumber"`
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,25 @@
|
|||||||
|
package cms_api_struct
|
||||||
|
|
||||||
|
type GetFriendsReq struct {
|
||||||
|
OperationID string `json:"operationID"`
|
||||||
|
UserID string `json:"userID"`
|
||||||
|
FriendUserName string `json:"friendUserName"`
|
||||||
|
FriendUserID string `json:"friendUserID"`
|
||||||
|
RequestPagination
|
||||||
|
}
|
||||||
|
|
||||||
|
type FriendInfo struct {
|
||||||
|
OwnerUserID string `json:"ownerUserID"`
|
||||||
|
Remark string `json:"remark"`
|
||||||
|
CreateTime uint32 `json:"createTime"`
|
||||||
|
UserID string `json:"userID"`
|
||||||
|
Nickname string `json:"nickName"`
|
||||||
|
AddSource int32 `json:"addSource"`
|
||||||
|
OperatorUserID string `json:"operatorUserID"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetFriendsResp struct {
|
||||||
|
ResponsePagination
|
||||||
|
FriendInfoList []*FriendInfo `json:"friendInfoList"`
|
||||||
|
FriendNums int32 `json:"friendNums"`
|
||||||
|
}
|
@ -1,50 +1,48 @@
|
|||||||
package cms_api_struct
|
package cms_api_struct
|
||||||
|
|
||||||
type BroadcastRequest struct {
|
import (
|
||||||
Message string `json:"message"`
|
pbCommon "Open_IM/pkg/proto/sdk_ws"
|
||||||
}
|
)
|
||||||
|
|
||||||
type BroadcastResponse struct {
|
type GetChatLogsReq struct {
|
||||||
}
|
SessionType int `json:"sessionType"`
|
||||||
|
ContentType int `json:"contentType"`
|
||||||
type MassSendMassageRequest struct {
|
Content string `json:"content"`
|
||||||
Message string `json:"message"`
|
SendID string `json:"userID"`
|
||||||
Users []string `json:"users"`
|
RecvID string `json:"recvID"`
|
||||||
}
|
GroupID string `json:"groupID"`
|
||||||
|
SendTime string `json:"sendTime"`
|
||||||
type MassSendMassageResponse struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
type GetChatLogsRequest struct {
|
|
||||||
SessionType int `form:"session_type"`
|
|
||||||
ContentType int `form:"content_type"`
|
|
||||||
Content string `form:"content"`
|
|
||||||
UserId string `form:"user_id"`
|
|
||||||
GroupId string `form:"group_id"`
|
|
||||||
Date string `form:"date"`
|
|
||||||
|
|
||||||
RequestPagination
|
RequestPagination
|
||||||
|
OperationID string `json:"operationID"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ChatLog struct {
|
type ChatLog struct {
|
||||||
SessionType int `json:"session_type"`
|
SendID string `json:"sendID,omitempty"`
|
||||||
ContentType int `json:"content_type"`
|
RecvID string `json:"recvID,omitempty"`
|
||||||
SenderNickName string `json:"sender_nick_name"`
|
GroupID string `json:"groupID,omitempty"`
|
||||||
SenderId string `json:"sender_id"`
|
ClientMsgID string `json:"clientMsgID,omitempty"`
|
||||||
SearchContent string `json:"search_content"`
|
ServerMsgID string `json:"serverMsgID,omitempty"`
|
||||||
WholeContent string `json:"whole_content"`
|
SenderPlatformID int32 `json:"senderPlatformID,omitempty"`
|
||||||
|
SenderNickname string `json:"senderNickname,omitempty"`
|
||||||
ReceiverNickName string `json:"receiver_nick_name,omitempty"`
|
SenderFaceURL string `json:"senderFaceURL,omitempty"`
|
||||||
ReceiverID string `json:"receiver_id,omitempty"`
|
SessionType int32 `json:"sessionType,omitempty"`
|
||||||
|
MsgFrom int32 `json:"msgFrom,omitempty"`
|
||||||
GroupName string `json:"group_name,omitempty"`
|
ContentType int32 `json:"contentType,omitempty"`
|
||||||
GroupId string `json:"group_id,omitempty"`
|
Content string `json:"content,omitempty"`
|
||||||
|
Seq uint32 `json:"seq,omitempty"`
|
||||||
Date string `json:"date"`
|
SendTime int64 `json:"sendTime,omitempty"`
|
||||||
|
CreateTime int64 `json:"createTime,omitempty"`
|
||||||
|
Status int32 `json:"status,omitempty"`
|
||||||
|
Options map[string]bool `json:"options,omitempty"`
|
||||||
|
OfflinePushInfo *pbCommon.OfflinePushInfo `json:"offlinePushInfo,omitempty"`
|
||||||
|
AtUserIDList []string `json:"atUserIDList,omitempty"`
|
||||||
|
MsgDataList []byte `json:"msgDataList,omitempty"`
|
||||||
|
AttachedInfo string `json:"attachedInfo,omitempty"`
|
||||||
|
Ex string `json:"ex,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type GetChatLogsResponse struct {
|
type GetChatLogsResp struct {
|
||||||
ChatLogs []ChatLog `json:"chat_logs"`
|
ChatLogs []*ChatLog `json:"chatLogs"`
|
||||||
ChatLogsNum int `json:"log_nums"`
|
ChatLogsNum int `json:"logNums"`
|
||||||
ResponsePagination
|
ResponsePagination
|
||||||
}
|
}
|
||||||
|
@ -1,25 +0,0 @@
|
|||||||
package cms_api_struct
|
|
||||||
|
|
||||||
type GetStaffsResponse struct {
|
|
||||||
StaffsList []struct {
|
|
||||||
ProfilePhoto string `json:"profile_photo"`
|
|
||||||
NickName string `json:"nick_name"`
|
|
||||||
StaffId int `json:"staff_id"`
|
|
||||||
Position string `json:"position"`
|
|
||||||
EntryTime string `json:"entry_time"`
|
|
||||||
} `json:"staffs_list"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type GetOrganizationsResponse struct {
|
|
||||||
OrganizationList []struct {
|
|
||||||
OrganizationId int `json:"organization_id"`
|
|
||||||
OrganizationName string `json:"organization_name"`
|
|
||||||
} `json:"organization_list"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type SquadResponse struct {
|
|
||||||
SquadList []struct {
|
|
||||||
SquadId int `json:"squad_id"`
|
|
||||||
SquadName string `json:"squad_name"`
|
|
||||||
} `json:"squad_list"`
|
|
||||||
}
|
|
@ -1,43 +0,0 @@
|
|||||||
package http
|
|
||||||
|
|
||||||
import (
|
|
||||||
"Open_IM/pkg/common/constant"
|
|
||||||
"fmt"
|
|
||||||
"google.golang.org/grpc/codes"
|
|
||||||
"google.golang.org/grpc/status"
|
|
||||||
|
|
||||||
//"Open_IM/pkg/cms_api_struct"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
)
|
|
||||||
|
|
||||||
type BaseResp struct {
|
|
||||||
Code int32 `json:"code"`
|
|
||||||
ErrMsg string `json:"err_msg"`
|
|
||||||
Data interface{} `json:"data"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func RespHttp200(ctx *gin.Context, err error, data interface{}) {
|
|
||||||
var resp BaseResp
|
|
||||||
switch e := err.(type) {
|
|
||||||
case constant.ErrInfo:
|
|
||||||
resp.Code = e.ErrCode
|
|
||||||
resp.ErrMsg = e.ErrMsg
|
|
||||||
default:
|
|
||||||
s, ok := status.FromError(err)
|
|
||||||
if !ok {
|
|
||||||
fmt.Println("need grpc format error")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
resp.Code = int32(s.Code())
|
|
||||||
resp.ErrMsg = s.Message()
|
|
||||||
}
|
|
||||||
resp.Data = data
|
|
||||||
ctx.JSON(http.StatusOK, resp)
|
|
||||||
}
|
|
||||||
|
|
||||||
// warp error
|
|
||||||
func WrapError(err constant.ErrInfo) error {
|
|
||||||
return status.Error(codes.Code(err.ErrCode), err.ErrMsg)
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load Diff
@ -1,5 +0,0 @@
|
|||||||
syntax = "proto3";
|
|
||||||
package base;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,71 +0,0 @@
|
|||||||
syntax = "proto3";
|
|
||||||
import "Open_IM/pkg/proto/sdk_ws/ws.proto";
|
|
||||||
option go_package = "./message_cms;message_cms";
|
|
||||||
package message_cms;
|
|
||||||
|
|
||||||
message BoradcastMessageReq {
|
|
||||||
string Message = 1;
|
|
||||||
string OperationID = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
message BoradcastMessageResp {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
message MassSendMessageReq {
|
|
||||||
string Message = 1;
|
|
||||||
repeated string UserIds = 2;
|
|
||||||
string OperationID = 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
message MassSendMessageResp {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
message GetChatLogsReq {
|
|
||||||
string Content = 1;
|
|
||||||
string UserId = 2;
|
|
||||||
string GroupId = 3;
|
|
||||||
string Date = 4;
|
|
||||||
int32 SessionType = 5;
|
|
||||||
int32 ContentType = 6;
|
|
||||||
server_api_params.RequestPagination Pagination = 7;
|
|
||||||
string OperationID = 8;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
message ChatLogs {
|
|
||||||
int32 SessionType = 1;
|
|
||||||
int32 ContentType = 2;
|
|
||||||
string SenderNickName = 3;
|
|
||||||
string SenderId = 4;
|
|
||||||
string ReciverNickName = 5;
|
|
||||||
string ReciverId = 6;
|
|
||||||
string SearchContent = 7;
|
|
||||||
string WholeContent = 8;
|
|
||||||
string GroupId = 9;
|
|
||||||
string GroupName = 10;
|
|
||||||
string Date = 11;
|
|
||||||
}
|
|
||||||
|
|
||||||
message GetChatLogsResp {
|
|
||||||
repeated ChatLogs ChatLogs = 1;
|
|
||||||
server_api_params.ResponsePagination Pagination = 2;
|
|
||||||
int32 ChatLogsNum = 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
message WithdrawMessageReq {
|
|
||||||
string ServerMsgId = 1;
|
|
||||||
string OperationID = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
message WithdrawMessageResp {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
service messageCMS {
|
|
||||||
rpc BoradcastMessage(BoradcastMessageReq) returns(BoradcastMessageResp);
|
|
||||||
rpc MassSendMessage(MassSendMessageReq) returns(MassSendMessageResp);
|
|
||||||
rpc GetChatLogs(GetChatLogsReq) returns(GetChatLogsResp);
|
|
||||||
rpc WithdrawMessage(WithdrawMessageReq) returns(WithdrawMessageResp);
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,93 +0,0 @@
|
|||||||
syntax = "proto3";
|
|
||||||
// import "Open_IM/pkg/proto/sdk_ws/ws.proto";
|
|
||||||
option go_package = "./statistics;statistics";
|
|
||||||
package statistics;
|
|
||||||
|
|
||||||
message StatisticsReq {
|
|
||||||
string from = 1;
|
|
||||||
string to = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
message GetActiveUserReq{
|
|
||||||
StatisticsReq StatisticsReq = 1;
|
|
||||||
string OperationID = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
message UserResp{
|
|
||||||
string NickName = 1;
|
|
||||||
string UserId = 2;
|
|
||||||
int32 MessageNum = 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
message GetActiveUserResp {
|
|
||||||
repeated UserResp Users = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
message GetActiveGroupReq{
|
|
||||||
StatisticsReq StatisticsReq = 1;
|
|
||||||
string OperationID = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
message GroupResp {
|
|
||||||
string GroupName = 1;
|
|
||||||
string GroupId = 2;
|
|
||||||
int32 MessageNum = 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
message GetActiveGroupResp {
|
|
||||||
repeated GroupResp Groups = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
message DateNumList {
|
|
||||||
string Date = 1;
|
|
||||||
int32 Num = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
message GetMessageStatisticsReq {
|
|
||||||
StatisticsReq StatisticsReq = 1;
|
|
||||||
string OperationID = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
message GetMessageStatisticsResp {
|
|
||||||
int32 PrivateMessageNum = 1;
|
|
||||||
int32 GroupMessageNum = 2;
|
|
||||||
repeated DateNumList PrivateMessageNumList = 3;
|
|
||||||
repeated DateNumList GroupMessageNumList = 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
message GetGroupStatisticsReq {
|
|
||||||
StatisticsReq StatisticsReq = 1;
|
|
||||||
string OperationID = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
message GetGroupStatisticsResp {
|
|
||||||
int32 IncreaseGroupNum = 1;
|
|
||||||
int32 TotalGroupNum = 2;
|
|
||||||
repeated DateNumList IncreaseGroupNumList = 3;
|
|
||||||
repeated DateNumList TotalGroupNumList = 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
message GetUserStatisticsReq {
|
|
||||||
StatisticsReq StatisticsReq = 1;
|
|
||||||
string OperationID = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
message GetUserStatisticsResp {
|
|
||||||
int32 IncreaseUserNum = 1;
|
|
||||||
int32 ActiveUserNum = 2;
|
|
||||||
int32 TotalUserNum = 3;
|
|
||||||
repeated DateNumList IncreaseUserNumList = 4;
|
|
||||||
repeated DateNumList ActiveUserNumList = 5;
|
|
||||||
repeated DateNumList TotalUserNumList = 6;
|
|
||||||
}
|
|
||||||
|
|
||||||
service user {
|
|
||||||
rpc GetActiveUser(GetActiveUserReq) returns(GetActiveUserResp);
|
|
||||||
rpc GetActiveGroup(GetActiveGroupReq) returns(GetActiveGroupResp);
|
|
||||||
rpc GetMessageStatistics(GetMessageStatisticsReq) returns(GetMessageStatisticsResp);
|
|
||||||
rpc GetGroupStatistics(GetGroupStatisticsReq) returns(GetGroupStatisticsResp);
|
|
||||||
rpc GetUserStatistics(GetUserStatisticsReq) returns(GetUserStatisticsResp);
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue