commit
6cdb64fb8b
@ -1 +1 @@
|
||||
Subproject commit 7ce9f14846f90b42777577774feb869f149da067
|
||||
Subproject commit 1667b0f4e205fc4ed7c690ab55b662087d61c277
|
@ -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,13 @@
|
||||
#more datasource-compose.yaml
|
||||
apiVersion: 1
|
||||
|
||||
datasources:
|
||||
- name: Prometheus
|
||||
type: prometheus
|
||||
access: proxy
|
||||
orgId: 1
|
||||
url: http://127.0.0.1:9091
|
||||
basicAuth: false
|
||||
isDefault: true
|
||||
version: 1
|
||||
editable: true
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,28 @@
|
||||
#more prometheus-compose.yml
|
||||
global:
|
||||
scrape_interval: 15s
|
||||
evaluation_interval: 15s
|
||||
external_labels:
|
||||
monitor: 'openIM-monitor'
|
||||
|
||||
scrape_configs:
|
||||
- job_name: 'prometheus'
|
||||
static_configs:
|
||||
- targets: ['localhost:9091']
|
||||
|
||||
- job_name: 'openIM-server'
|
||||
metrics_path: /metrics
|
||||
static_configs:
|
||||
- targets: ['localhost:10006']
|
||||
labels:
|
||||
group: 'cms-api'
|
||||
- targets: ['localhost:21400']
|
||||
labels:
|
||||
group: 'msg-transfer'
|
||||
|
||||
|
||||
- job_name: 'node'
|
||||
scrape_interval: 8s
|
||||
static_configs:
|
||||
- targets: ['localhost:9100']
|
||||
|
@ -0,0 +1,50 @@
|
||||
package apiThird
|
||||
|
||||
import (
|
||||
api "Open_IM/pkg/base_info"
|
||||
"Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
"Open_IM/pkg/utils"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func SetAppBadge(c *gin.Context) {
|
||||
var (
|
||||
req api.SetAppBadgeReq
|
||||
resp api.SetAppBadgeResp
|
||||
)
|
||||
if err := c.Bind(&req); err != nil {
|
||||
log.NewError("0", utils.GetSelfFuncName(), "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), req)
|
||||
|
||||
var ok bool
|
||||
var errInfo, opUserID string
|
||||
ok, opUserID, errInfo = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
errMsg := req.OperationID + " " + "GetUserIDFromToken failed " + errInfo + " token:" + c.Request.Header.Get("token")
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
if !token_verify.CheckAccess(opUserID, req.FromUserID) {
|
||||
log.NewError(req.OperationID, "CheckAccess false ", opUserID, req.FromUserID)
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "no permission"})
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), req, opUserID)
|
||||
err := db.DB.SetUserBadgeUnreadCountSum(req.FromUserID, int(req.AppUnreadCount))
|
||||
if err != nil {
|
||||
errMsg := req.OperationID + " " + "SetUserBadgeUnreadCountSum failed " + err.Error() + " token:" + c.Request.Header.Get("token")
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
resp.ErrCode = 500
|
||||
resp.ErrMsg = errMsg
|
||||
c.JSON(http.StatusInternalServerError, resp)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
return
|
||||
}
|
@ -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,14 @@
|
||||
package cms_api
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
)
|
||||
|
||||
func prometheusHandler() gin.HandlerFunc {
|
||||
h := promhttp.Handler()
|
||||
|
||||
return func(c *gin.Context) {
|
||||
h.ServeHTTP(c.Writer, c.Request)
|
||||
}
|
||||
}
|
@ -0,0 +1,85 @@
|
||||
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"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
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": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
ip := c.Request.Header.Get("X-Forward-For")
|
||||
if ip == "" {
|
||||
ip = c.ClientIP()
|
||||
}
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "IP: ", ip)
|
||||
user, err := imdb.GetUserIPLimit(req.UserID)
|
||||
if err != nil && !errors.Is(gorm.ErrRecordNotFound, err) {
|
||||
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})
|
||||
return
|
||||
}
|
||||
|
||||
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())
|
||||
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,75 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
rocksCache "Open_IM/pkg/common/db/rocks_cache"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbCache "Open_IM/pkg/proto/cache"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"errors"
|
||||
"strings"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type GroupMemberUserIDListHash struct {
|
||||
MemberListHash uint64
|
||||
UserIDList []string
|
||||
}
|
||||
|
||||
var CacheGroupMemberUserIDList = make(map[string]*GroupMemberUserIDListHash, 0)
|
||||
var CacheGroupMtx sync.RWMutex
|
||||
|
||||
func GetGroupMemberUserIDList(groupID string, operationID string) ([]string, error) {
|
||||
groupHashRemote, err := GetGroupMemberUserIDListHashFromRemote(groupID)
|
||||
if err != nil {
|
||||
CacheGroupMtx.Lock()
|
||||
defer CacheGroupMtx.Unlock()
|
||||
delete(CacheGroupMemberUserIDList, groupID)
|
||||
log.Error(operationID, "GetGroupMemberUserIDListHashFromRemote failed ", err.Error(), groupID)
|
||||
return nil, utils.Wrap(err, groupID)
|
||||
}
|
||||
|
||||
CacheGroupMtx.Lock()
|
||||
defer CacheGroupMtx.Unlock()
|
||||
groupInLocalCache, ok := CacheGroupMemberUserIDList[groupID]
|
||||
if ok && groupInLocalCache.MemberListHash == groupHashRemote {
|
||||
log.Debug(operationID, "in local cache ", groupID)
|
||||
return groupInLocalCache.UserIDList, nil
|
||||
}
|
||||
log.Debug(operationID, "not in local cache or hash changed", groupID, " remote hash ", groupHashRemote, " in cache ", ok)
|
||||
memberUserIDListRemote, err := GetGroupMemberUserIDListFromRemote(groupID, operationID)
|
||||
if err != nil {
|
||||
log.Error(operationID, "GetGroupMemberUserIDListFromRemote failed ", err.Error(), groupID)
|
||||
return nil, utils.Wrap(err, groupID)
|
||||
}
|
||||
CacheGroupMemberUserIDList[groupID] = &GroupMemberUserIDListHash{MemberListHash: groupHashRemote, UserIDList: memberUserIDListRemote}
|
||||
return memberUserIDListRemote, nil
|
||||
}
|
||||
|
||||
func GetGroupMemberUserIDListHashFromRemote(groupID string) (uint64, error) {
|
||||
return rocksCache.GetGroupMemberListHashFromCache(groupID)
|
||||
}
|
||||
|
||||
func GetGroupMemberUserIDListFromRemote(groupID string, operationID string) ([]string, error) {
|
||||
getGroupMemberIDListFromCacheReq := &pbCache.GetGroupMemberIDListFromCacheReq{OperationID: operationID, GroupID: groupID}
|
||||
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, operationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := operationID + "getcdv3.GetDefaultConn == nil"
|
||||
log.NewError(operationID, errMsg)
|
||||
return nil, errors.New("errMsg")
|
||||
}
|
||||
client := pbCache.NewCacheClient(etcdConn)
|
||||
cacheResp, err := client.GetGroupMemberIDListFromCache(context.Background(), getGroupMemberIDListFromCacheReq)
|
||||
if err != nil {
|
||||
log.NewError(operationID, "GetGroupMemberIDListFromCache rpc call failed ", err.Error())
|
||||
return nil, utils.Wrap(err, "GetGroupMemberIDListFromCache rpc call failed")
|
||||
}
|
||||
if cacheResp.CommonResp.ErrCode != 0 {
|
||||
errMsg := operationID + "GetGroupMemberIDListFromCache rpc logic call failed " + cacheResp.CommonResp.ErrMsg
|
||||
log.NewError(operationID, errMsg)
|
||||
return nil, errors.New("errMsg")
|
||||
}
|
||||
return cacheResp.UserIDList, 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"`
|
||||
}
|
||||
|
@ -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
|
||||
|
||||
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:"sendID"`
|
||||
RecvID string `json:"recvID"`
|
||||
GroupID string `json:"groupID"`
|
||||
SendTime string `json:"sendTime"`
|
||||
RequestPagination
|
||||
OperationID string `json:"operationID"`
|
||||
}
|
||||
|
||||
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"`
|
||||
SendID string `json:"sendID,omitempty"`
|
||||
RecvID string `json:"recvID,omitempty"`
|
||||
GroupID string `json:"groupID,omitempty"`
|
||||
ClientMsgID string `json:"clientMsgID,omitempty"`
|
||||
ServerMsgID string `json:"serverMsgID,omitempty"`
|
||||
SenderPlatformID int32 `json:"senderPlatformID,omitempty"`
|
||||
SenderNickname string `json:"senderNickname,omitempty"`
|
||||
SenderFaceURL string `json:"senderFaceURL,omitempty"`
|
||||
SessionType int32 `json:"sessionType,omitempty"`
|
||||
MsgFrom int32 `json:"msgFrom,omitempty"`
|
||||
ContentType int32 `json:"contentType,omitempty"`
|
||||
Content string `json:"content,omitempty"`
|
||||
Seq uint32 `json:"seq,omitempty"`
|
||||
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 {
|
||||
ChatLogs []ChatLog `json:"chat_logs"`
|
||||
ChatLogsNum int `json:"log_nums"`
|
||||
type GetChatLogsResp struct {
|
||||
ChatLogs []*ChatLog `json:"chatLogs"`
|
||||
ChatLogsNum int `json:"logNums"`
|
||||
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"`
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue