parent
92fc43cb3d
commit
3886d49b0a
@ -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()
|
||||
}
|
@ -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())
|
||||
return
|
||||
}
|
||||
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())
|
||||
return
|
||||
}
|
||||
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
|
||||
|
||||
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"`
|
||||
ShowNumber int `json:"showNumber" binding:"required"`
|
||||
}
|
||||
|
||||
type ResponsePagination struct {
|
||||
CurrentPage int `json:"current_number" binding:"required"`
|
||||
ShowNumber int `json:"show_number" binding:"required"`
|
||||
CurrentPage int `json:"currentPage"`
|
||||
ShowNumber int `json:"showNumber"`
|
||||
}
|
||||
|
@ -1,50 +1,22 @@
|
||||
package cms_api_struct
|
||||
|
||||
type BroadcastRequest struct {
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
type BroadcastResponse struct {
|
||||
}
|
||||
|
||||
type MassSendMassageRequest struct {
|
||||
Message string `json:"message"`
|
||||
Users []string `json:"users"`
|
||||
}
|
||||
|
||||
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"`
|
||||
|
||||
import (
|
||||
pbCommon "Open_IM/pkg/proto/sdk_ws"
|
||||
)
|
||||
|
||||
type GetChatLogsReq struct {
|
||||
SessionType int `json:"sessionType"`
|
||||
ContentType int `json:"contentType"`
|
||||
Content string `json:"content"`
|
||||
SendID string `json:"userID"`
|
||||
RecvID string `json:"recvID"`
|
||||
GroupID string `json:"groupID"`
|
||||
SendTime string `json:"sendTime"`
|
||||
RequestPagination
|
||||
}
|
||||
|
||||
type ChatLog struct {
|
||||
SessionType int `json:"session_type"`
|
||||
ContentType int `json:"content_type"`
|
||||
SenderNickName string `json:"sender_nick_name"`
|
||||
SenderId string `json:"sender_id"`
|
||||
SearchContent string `json:"search_content"`
|
||||
WholeContent string `json:"whole_content"`
|
||||
|
||||
ReceiverNickName string `json:"receiver_nick_name,omitempty"`
|
||||
ReceiverID string `json:"receiver_id,omitempty"`
|
||||
|
||||
GroupName string `json:"group_name,omitempty"`
|
||||
GroupId string `json:"group_id,omitempty"`
|
||||
|
||||
Date string `json:"date"`
|
||||
}
|
||||
|
||||
type GetChatLogsResponse struct {
|
||||
ChatLogs []ChatLog `json:"chat_logs"`
|
||||
ChatLogsNum int `json:"log_nums"`
|
||||
type GetChatLogsResp struct {
|
||||
ChatLogs []*pbCommon.MsgData `json:"chat_logs"`
|
||||
ChatLogsNum int `json:"log_nums"`
|
||||
ResponsePagination
|
||||
}
|
||||
|
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
@ -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
@ -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