merge cms into v2.3.0release

pull/351/head
wangchuxiao 2 years ago
commit bdae1f10d4

@ -63,6 +63,7 @@ func main() {
userRouterGroup.POST("/get_all_users_uid", manage.GetAllUsersUid) //1
userRouterGroup.POST("/account_check", manage.AccountCheck) //1
// userRouterGroup.POST("/get_users_online_status", manage.GetUsersOnlineStatus) //1
userRouterGroup.POST("/get_users", user.GetUsers)
}
//friend routing group
friendRouterGroup := r.Group("/friend")

@ -8,6 +8,7 @@ import (
"strconv"
"Open_IM/pkg/common/config"
"github.com/gin-gonic/gin"
)

@ -12,6 +12,7 @@ import (
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/log"
"github.com/gin-gonic/gin"
)
@ -31,6 +32,7 @@ func main() {
authRouterGroup.POST("/password", register.SetPassword)
authRouterGroup.POST("/login", register.Login)
authRouterGroup.POST("/reset_password", register.ResetPassword)
authRouterGroup.POST("/check_login", register.CheckLoginLimit)
}
demoRouterGroup := r.Group("/auth")
{
@ -39,7 +41,10 @@ func main() {
demoRouterGroup.POST("/password", register.SetPassword)
demoRouterGroup.POST("/login", register.Login)
demoRouterGroup.POST("/reset_password", register.ResetPassword)
demoRouterGroup.POST("/check_login", register.CheckLoginLimit)
}
//deprecated
cmsRouterGroup := r.Group("/cms_admin")
{
cmsRouterGroup.POST("/generate_invitation_code", register.GenerateInvitationCode)

@ -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()
}

@ -3,7 +3,6 @@ package apiAuth
import (
api "Open_IM/pkg/base_info"
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/log"
"Open_IM/pkg/common/token_verify"
"Open_IM/pkg/grpc-etcdv3/getcdv3"
@ -67,17 +66,11 @@ func UserRegister(c *gin.Context) {
if reply.CommonResp.ErrCode != 0 {
errMsg := req.OperationID + " " + " UserRegister failed " + reply.CommonResp.ErrMsg + req.String()
log.NewError(req.OperationID, errMsg)
if reply.CommonResp.ErrCode == constant.RegisterLimit {
c.JSON(http.StatusOK, gin.H{"errCode": constant.RegisterLimit, "errMsg": "用户注册被限制"})
} else if reply.CommonResp.ErrCode == constant.InvitationError {
c.JSON(http.StatusOK, gin.H{"errCode": constant.InvitationError, "errMsg": "邀请码错误"})
} else {
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
}
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
return
}
pbDataToken := &rpc.UserTokenReq{Platform: params.Platform, FromUserID: params.UserID, OperationID: params.OperationID, LoginIp: params.CreateIp}
pbDataToken := &rpc.UserTokenReq{Platform: params.Platform, FromUserID: params.UserID, OperationID: params.OperationID}
replyToken, err := client.UserToken(context.Background(), pbDataToken)
if err != nil {
errMsg := req.OperationID + " " + " client.UserToken failed " + err.Error() + pbDataToken.String()

@ -11,6 +11,7 @@ import (
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
"Open_IM/pkg/utils"
"context"
"github.com/golang/protobuf/ptypes/wrappers"
"google.golang.org/grpc"

@ -23,49 +23,6 @@ import (
"github.com/gin-gonic/gin"
)
func DeleteUser(c *gin.Context) {
params := api.DeleteUsersReq{}
if err := c.BindJSON(&params); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
req := &rpc.DeleteUsersReq{}
utils.CopyStructFields(req, &params)
var ok bool
var errInfo string
ok, req.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.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
return
}
log.NewInfo(params.OperationID, "DeleteUser args ", req.String())
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName, req.OperationID)
if etcdConn == nil {
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
log.NewError(req.OperationID, errMsg)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
return
}
client := rpc.NewUserClient(etcdConn)
RpcResp, err := client.DeleteUsers(context.Background(), req)
if err != nil {
log.NewError(req.OperationID, "call delete users rpc server failed", err.Error())
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call delete users rpc server failed"})
return
}
resp := api.DeleteUsersResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}, FailedUserIDList: RpcResp.FailedUserIDList}
if len(RpcResp.FailedUserIDList) == 0 {
resp.FailedUserIDList = []string{}
}
log.NewInfo(req.OperationID, "DeleteUser api return", resp)
c.JSON(http.StatusOK, resp)
}
// @Summary 获取所有用户uid列表
// @Description 获取所有用户uid列表
// @Tags 用户相关

@ -456,3 +456,58 @@ func GetUsersOnlineStatus(c *gin.Context) {
log.NewInfo(req.OperationID, "GetUsersOnlineStatus api return", resp)
c.JSON(http.StatusOK, resp)
}
func GetUsers(c *gin.Context) {
var (
req api.GetUsersReq
resp api.GetUsersResp
reqPb rpc.GetUsersReq
)
if err := c.BindJSON(&req); err != nil {
log.NewError(req.OperationID, "Bind failed ", err.Error(), req)
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
var ok bool
var errInfo string
ok, _, 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": 500, "errMsg": errMsg})
return
}
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "req: ", req)
reqPb.OperationID = req.OperationID
reqPb.UserID = req.UserID
reqPb.UserName = req.UserName
reqPb.Pagination = &open_im_sdk.RequestPagination{ShowNumber: req.ShowNumber, PageNumber: req.PageNumber}
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName, 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
}
client := rpc.NewUserClient(etcdConn)
respPb, err := client.GetUsers(context.Background(), &reqPb)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), reqPb.String())
c.JSON(http.StatusBadRequest, gin.H{"errCode": 500, "errMsg": err.Error()})
return
}
for _, v := range respPb.UserList {
user := api.CMSUser{}
utils.CopyStructFields(&user, v.User)
user.IsBlock = v.IsBlock
resp.Data.UserList = append(resp.Data.UserList, &user)
}
resp.CommResp.ErrCode = respPb.CommonResp.ErrCode
resp.CommResp.ErrMsg = respPb.CommonResp.ErrMsg
resp.Data.TotalNum = respPb.TotalNums
resp.Data.CurrentPage = respPb.Pagination.CurrentPage
resp.Data.ShowNumber = respPb.Pagination.ShowNumber
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), resp)
c.JSON(http.StatusOK, resp)
return
}

@ -3,8 +3,6 @@ package admin
import (
apiStruct "Open_IM/pkg/cms_api_struct"
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/constant"
openIMHttp "Open_IM/pkg/common/http"
"Open_IM/pkg/common/log"
"Open_IM/pkg/grpc-etcdv3/getcdv3"
pbAdmin "Open_IM/pkg/proto/admin_cms"
@ -66,8 +64,8 @@ func AdminLogin(c *gin.Context) {
reqPb pbAdmin.AdminLoginReq
)
if err := c.BindJSON(&req); err != nil {
log.NewError("0", utils.GetSelfFuncName(), err.Error())
openIMHttp.RespHttp200(c, constant.ErrArgs, nil)
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
reqPb.Secret = req.Secret
@ -84,24 +82,24 @@ func AdminLogin(c *gin.Context) {
respPb, err := client.AdminLogin(context.Background(), &reqPb)
if err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "rpc failed", err.Error())
openIMHttp.RespHttp200(c, err, nil)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
return
}
resp.Token = respPb.Token
openIMHttp.RespHttp200(c, constant.OK, resp)
c.JSON(http.StatusOK, gin.H{"errCode": respPb.CommonResp.ErrCode, "errMsg": respPb.CommonResp.ErrMsg, "data": resp})
}
func AddUserRegisterAddFriendIDList(c *gin.Context) {
var (
req apiStruct.AddUserRegisterAddFriendIDListRequest
resp apiStruct.AddUserRegisterAddFriendIDListResponse
req apiStruct.AddUserRegisterAddFriendIDListRequest
// resp apiStruct.AddUserRegisterAddFriendIDListResponse
)
if err := c.BindJSON(&req); err != nil {
log.NewError("0", utils.GetSelfFuncName(), err.Error())
openIMHttp.RespHttp200(c, constant.ErrArgs, nil)
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), req)
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req:", req)
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImAdminCMSName, req.OperationID)
if etcdConn == nil {
errMsg := req.OperationID + "getcdv3.GetConn == nil"
@ -110,23 +108,24 @@ func AddUserRegisterAddFriendIDList(c *gin.Context) {
return
}
client := pbAdmin.NewAdminCMSClient(etcdConn)
_, err := client.AddUserRegisterAddFriendIDList(context.Background(), &pbAdmin.AddUserRegisterAddFriendIDListReq{OperationID: req.OperationID, UserIDList: req.UserIDList})
respPb, err := client.AddUserRegisterAddFriendIDList(context.Background(), &pbAdmin.AddUserRegisterAddFriendIDListReq{OperationID: req.OperationID, UserIDList: req.UserIDList})
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "rpc failed", err.Error())
openIMHttp.RespHttp200(c, err, nil)
c.JSON(http.StatusBadRequest, gin.H{"errCode": 500, "errMsg": err.Error()})
return
}
openIMHttp.RespHttp200(c, constant.OK, resp)
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp:", respPb.String())
c.JSON(http.StatusOK, gin.H{"errCode": respPb.CommonResp.ErrCode, "errMsg": respPb.CommonResp.ErrMsg})
}
func ReduceUserRegisterAddFriendIDList(c *gin.Context) {
var (
req apiStruct.ReduceUserRegisterAddFriendIDListRequest
resp apiStruct.ReduceUserRegisterAddFriendIDListResponse
req apiStruct.ReduceUserRegisterAddFriendIDListRequest
// resp apiStruct.ReduceUserRegisterAddFriendIDListResponse
)
if err := c.BindJSON(&req); err != nil {
log.NewError("0", utils.GetSelfFuncName(), err.Error())
openIMHttp.RespHttp200(c, constant.ErrArgs, nil)
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), req)
@ -138,13 +137,13 @@ func ReduceUserRegisterAddFriendIDList(c *gin.Context) {
return
}
client := pbAdmin.NewAdminCMSClient(etcdConn)
_, err := client.ReduceUserRegisterAddFriendIDList(context.Background(), &pbAdmin.ReduceUserRegisterAddFriendIDListReq{OperationID: req.OperationID, UserIDList: req.UserIDList, Operation: req.Operation})
respPb, err := client.ReduceUserRegisterAddFriendIDList(context.Background(), &pbAdmin.ReduceUserRegisterAddFriendIDListReq{OperationID: req.OperationID, UserIDList: req.UserIDList, Operation: req.Operation})
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "rpc failed", err.Error())
openIMHttp.RespHttp200(c, err, nil)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
return
}
openIMHttp.RespHttp200(c, constant.OK, resp)
c.JSON(http.StatusOK, gin.H{"errCode": respPb.CommonResp.ErrCode, "errMsg": respPb.CommonResp.ErrMsg})
}
func GetUserRegisterAddFriendIDList(c *gin.Context) {
@ -153,8 +152,8 @@ func GetUserRegisterAddFriendIDList(c *gin.Context) {
resp apiStruct.GetUserRegisterAddFriendIDListResponse
)
if err := c.BindJSON(&req); err != nil {
log.NewError("0", utils.GetSelfFuncName(), err.Error())
openIMHttp.RespHttp200(c, constant.ErrArgs, nil)
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), req)
@ -172,12 +171,12 @@ func GetUserRegisterAddFriendIDList(c *gin.Context) {
}})
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "rpc failed", err.Error())
openIMHttp.RespHttp200(c, err, nil)
c.JSON(http.StatusBadRequest, gin.H{"errCode": 500, "errMsg": err.Error()})
return
}
resp.Users = respPb.UserInfoList
resp.ShowNumber = int(respPb.Pagination.ShowNumber)
resp.CurrentPage = int(respPb.Pagination.CurrentPage)
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), resp)
openIMHttp.RespHttp200(c, constant.OK, resp)
c.JSON(http.StatusOK, gin.H{"errCode": respPb.CommonResp.ErrCode, "errMsg": respPb.CommonResp.ErrMsg, "data": resp})
}

@ -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})
}

@ -3,8 +3,6 @@ package group
import (
"Open_IM/pkg/cms_api_struct"
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/constant"
openIMHttp "Open_IM/pkg/common/http"
"Open_IM/pkg/common/log"
"Open_IM/pkg/grpc-etcdv3/getcdv3"
commonPb "Open_IM/pkg/proto/sdk_ws"
@ -18,51 +16,15 @@ import (
"github.com/gin-gonic/gin"
)
func GetGroupByID(c *gin.Context) {
var (
req cms_api_struct.GetGroupByIDRequest
resp cms_api_struct.GetGroupByIDResponse
reqPb pbGroup.GetGroupByIDReq
)
if err := c.ShouldBindQuery(&req); err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "ShouldBindQuery failed ", err.Error())
openIMHttp.RespHttp200(c, constant.ErrArgs, nil)
return
}
reqPb.OperationID = utils.OperationIDGenerator()
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "req: ", req)
reqPb.GroupID = req.GroupID
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName, 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
}
client := pbGroup.NewGroupClient(etcdConn)
respPb, err := client.GetGroupByID(context.Background(), &reqPb)
if err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "GetGroupById failed ", err.Error())
openIMHttp.RespHttp200(c, err, nil)
return
}
utils.CopyStructFields(&resp, respPb.CMSGroup.GroupInfo)
resp.GroupOwnerID = respPb.CMSGroup.GroupOwnerUserID
resp.GroupOwnerName = respPb.CMSGroup.GroupOwnerUserName
log.NewInfo("", utils.GetSelfFuncName(), "req: ", resp)
openIMHttp.RespHttp200(c, constant.OK, resp)
}
func GetGroups(c *gin.Context) {
var (
req cms_api_struct.GetGroupsRequest
resp cms_api_struct.GetGroupsResponse
reqPb pbGroup.GetGroupsReq
)
if err := c.ShouldBindQuery(&req); err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "ShouldBindQuery failed ", err.Error())
openIMHttp.RespHttp200(c, constant.ErrArgs, nil)
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
}
reqPb.OperationID = utils.OperationIDGenerator()
@ -76,11 +38,13 @@ func GetGroups(c *gin.Context) {
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
return
}
reqPb.GroupID = req.GroupID
reqPb.GroupName = req.GroupName
client := pbGroup.NewGroupClient(etcdConn)
respPb, err := client.GetGroups(context.Background(), &reqPb)
if err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "GetUserInfo failed ", err.Error())
openIMHttp.RespHttp200(c, err, nil)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
return
}
for _, v := range respPb.CMSGroups {
@ -91,95 +55,10 @@ func GetGroups(c *gin.Context) {
resp.Groups = append(resp.Groups, groupResp)
}
resp.GroupNums = int(respPb.GroupNum)
resp.CurrentPage = int(respPb.Pagination.PageNumber)
resp.CurrentPage = int(respPb.Pagination.CurrentPage)
resp.ShowNumber = int(respPb.Pagination.ShowNumber)
log.NewInfo("", utils.GetSelfFuncName(), "resp: ", resp)
openIMHttp.RespHttp200(c, constant.OK, resp)
}
func GetGroupByName(c *gin.Context) {
var (
req cms_api_struct.GetGroupRequest
resp cms_api_struct.GetGroupResponse
reqPb pbGroup.GetGroupReq
)
if err := c.ShouldBindQuery(&req); err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "ShouldBindQuery failed ", err.Error())
openIMHttp.RespHttp200(c, constant.ErrArgs, nil)
return
}
reqPb.OperationID = utils.OperationIDGenerator()
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "req: ", req)
reqPb.GroupName = req.GroupName
reqPb.Pagination = &commonPb.RequestPagination{}
utils.CopyStructFields(&reqPb.Pagination, req)
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName, 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
}
client := pbGroup.NewGroupClient(etcdConn)
respPb, err := client.GetGroup(context.Background(), &reqPb)
if err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "GetGroup failed", err.Error())
openIMHttp.RespHttp200(c, constant.ErrServer, nil)
return
}
for _, v := range respPb.CMSGroups {
groupResp := cms_api_struct.GroupResponse{}
utils.CopyStructFields(&groupResp, v.GroupInfo)
groupResp.GroupOwnerName = v.GroupOwnerUserName
groupResp.GroupOwnerID = v.GroupOwnerUserID
resp.Groups = append(resp.Groups, groupResp)
}
resp.CurrentPage = int(respPb.Pagination.PageNumber)
resp.ShowNumber = int(respPb.Pagination.ShowNumber)
resp.GroupNums = int(respPb.GroupNums)
log.NewInfo("", utils.GetSelfFuncName(), "resp: ", resp)
openIMHttp.RespHttp200(c, constant.OK, resp)
}
func CreateGroup(c *gin.Context) {
var (
req cms_api_struct.CreateGroupRequest
_ cms_api_struct.CreateGroupResponse
reqPb pbGroup.CreateGroupReq
)
if err := c.BindJSON(&req); err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "BindJSON failed ", err.Error())
openIMHttp.RespHttp200(c, constant.ErrArgs, nil)
return
}
reqPb.OperationID = utils.OperationIDGenerator()
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "req: ", req)
reqPb.GroupInfo = &commonPb.GroupInfo{}
reqPb.GroupInfo.GroupName = req.GroupName
reqPb.GroupInfo.CreatorUserID = req.GroupMasterId
reqPb.OwnerUserID = req.GroupMasterId
reqPb.OpUserID = req.GroupMasterId
for _, v := range req.GroupMembers {
reqPb.InitMemberList = append(reqPb.InitMemberList, &pbGroup.GroupAddMemberInfo{
UserID: v,
RoleLevel: 1,
})
}
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName, 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
}
client := pbGroup.NewGroupClient(etcdConn)
_, err := client.CreateGroup(context.Background(), &reqPb)
if err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "CreateGroup failed", err.Error())
openIMHttp.RespHttp200(c, constant.ErrServer, nil)
return
}
openIMHttp.RespHttp200(c, constant.OK, nil)
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
c.JSON(http.StatusOK, gin.H{"errCode": respPb.CommonResp.ErrCode, "errMsg": respPb.CommonResp.ErrMsg, "data": resp})
}
func GetGroupMembers(c *gin.Context) {
@ -188,9 +67,9 @@ func GetGroupMembers(c *gin.Context) {
reqPb pbGroup.GetGroupMembersCMSReq
resp cms_api_struct.GetGroupMembersResponse
)
if err := c.ShouldBindQuery(&req); err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "ShouldBindQuery failed ", err.Error())
openIMHttp.RespHttp200(c, constant.ErrArgs, nil)
if err := c.BindJSON(&req); err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "BindJSON failed ", err.Error())
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
reqPb.OperationID = utils.OperationIDGenerator()
@ -212,7 +91,7 @@ func GetGroupMembers(c *gin.Context) {
respPb, err := client.GetGroupMembersCMS(context.Background(), &reqPb)
if err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "GetGroupMembersCMS failed:", err.Error())
openIMHttp.RespHttp200(c, err, nil)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
return
}
resp.ResponsePagination = cms_api_struct.ResponsePagination{
@ -226,179 +105,5 @@ func GetGroupMembers(c *gin.Context) {
resp.GroupMembers = append(resp.GroupMembers, memberResp)
}
log.NewInfo("", utils.GetSelfFuncName(), "req: ", resp)
openIMHttp.RespHttp200(c, constant.OK, resp)
}
func AddGroupMembers(c *gin.Context) {
var (
req cms_api_struct.RemoveGroupMembersRequest
resp cms_api_struct.RemoveGroupMembersResponse
reqPb pbGroup.AddGroupMembersCMSReq
)
if err := c.BindJSON(&req); err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "BindJSON failed ", err.Error())
openIMHttp.RespHttp200(c, constant.ErrArgs, nil)
return
}
reqPb.OperationID = utils.OperationIDGenerator()
log.NewInfo("", utils.GetSelfFuncName(), "req: ", req)
reqPb.UserIDList = req.Members
reqPb.GroupID = req.GroupId
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName, 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
}
client := pbGroup.NewGroupClient(etcdConn)
respPb, err := client.AddGroupMembersCMS(context.Background(), &reqPb)
if err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "AddGroupMembersCMS failed", err.Error())
openIMHttp.RespHttp200(c, err, nil)
return
}
resp.Success = respPb.Success
resp.Failed = respPb.Failed
log.NewInfo("", utils.GetSelfFuncName(), "resp: ", resp)
openIMHttp.RespHttp200(c, constant.OK, resp)
}
func RemoveGroupMembers(c *gin.Context) {
var (
req cms_api_struct.RemoveGroupMembersRequest
resp cms_api_struct.RemoveGroupMembersResponse
reqPb pbGroup.RemoveGroupMembersCMSReq
)
if err := c.BindJSON(&req); err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "BindJSON failed ", err.Error())
openIMHttp.RespHttp200(c, constant.ErrArgs, nil)
return
}
reqPb.OperationID = utils.OperationIDGenerator()
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "req: ", req)
reqPb.UserIDList = req.Members
reqPb.GroupID = req.GroupId
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName, 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
}
client := pbGroup.NewGroupClient(etcdConn)
respPb, err := client.RemoveGroupMembersCMS(context.Background(), &reqPb)
if err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "RemoveGroupMembersCMS failed", err.Error())
openIMHttp.RespHttp200(c, err, nil)
return
}
resp.Success = respPb.Success
resp.Failed = respPb.Failed
log.NewInfo("", utils.GetSelfFuncName(), "req: ", resp)
openIMHttp.RespHttp200(c, constant.OK, resp)
}
func SetGroupOwner(c *gin.Context) {
var (
req cms_api_struct.SetGroupMasterRequest
_ cms_api_struct.SetGroupMasterResponse
reqPb pbGroup.OperateUserRoleReq
)
if err := c.BindJSON(&req); err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "BindJSON failed ", err.Error())
openIMHttp.RespHttp200(c, constant.ErrArgs, nil)
return
}
reqPb.OperationID = utils.OperationIDGenerator()
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "req: ", req)
reqPb.GroupID = req.GroupId
reqPb.UserID = req.UserId
reqPb.RoleLevel = constant.GroupOwner
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName, 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
}
client := pbGroup.NewGroupClient(etcdConn)
_, err := client.OperateUserRole(context.Background(), &reqPb)
if err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "DeleteGroup failed", err.Error())
openIMHttp.RespHttp200(c, constant.ErrServer, nil)
return
}
openIMHttp.RespHttp200(c, constant.OK, nil)
}
func SetGroupOrdinaryUsers(c *gin.Context) {
var (
req cms_api_struct.SetGroupMemberRequest
_ cms_api_struct.AdminLoginResponse
reqPb pbGroup.OperateUserRoleReq
)
if err := c.BindJSON(&req); err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "BindJSON failed ", err.Error())
openIMHttp.RespHttp200(c, constant.ErrArgs, nil)
return
}
reqPb.OperationID = utils.OperationIDGenerator()
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "req: ", req)
reqPb.GroupID = req.GroupId
reqPb.UserID = req.UserId
reqPb.RoleLevel = constant.GroupOrdinaryUsers
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName, 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
}
client := pbGroup.NewGroupClient(etcdConn)
_, err := client.OperateUserRole(context.Background(), &reqPb)
if err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "DeleteGroup failed", err.Error())
openIMHttp.RespHttp200(c, err, nil)
return
}
openIMHttp.RespHttp200(c, constant.OK, nil)
}
func AlterGroupInfo(c *gin.Context) {
var (
req cms_api_struct.AlterGroupInfoRequest
_ cms_api_struct.SetGroupMasterResponse
reqPb pbGroup.SetGroupInfoReq
)
reqPb.OperationID = utils.OperationIDGenerator()
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "req: ", req)
if err := c.BindJSON(&req); err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "BindJSON failed ", err.Error())
openIMHttp.RespHttp200(c, constant.ErrArgs, nil)
return
}
reqPb.OpUserID = c.MustGet("userID").(string)
reqPb.GroupInfoForSet = &commonPb.GroupInfoForSet{
GroupID: req.GroupID,
GroupName: req.GroupName,
Introduction: req.Introduction,
Notification: req.Notification,
FaceURL: req.ProfilePhoto,
}
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName, 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
}
client := pbGroup.NewGroupClient(etcdConn)
_, err := client.SetGroupInfo(context.Background(), &reqPb)
if err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "DeleteGroup failed", err.Error())
openIMHttp.RespHttp200(c, err, nil)
return
}
openIMHttp.RespHttp200(c, constant.OK, nil)
c.JSON(http.StatusOK, gin.H{"errCode": respPb.CommonResp.ErrCode, "errMsg": respPb.CommonResp.ErrMsg, "data": resp})
}

@ -3,96 +3,27 @@ package messageCMS
import (
"Open_IM/pkg/cms_api_struct"
"Open_IM/pkg/common/config"
openIMHttp "Open_IM/pkg/common/http"
"Open_IM/pkg/common/log"
"Open_IM/pkg/grpc-etcdv3/getcdv3"
pbMessage "Open_IM/pkg/proto/message_cms"
pbAdminCMS "Open_IM/pkg/proto/admin_cms"
pbCommon "Open_IM/pkg/proto/sdk_ws"
"Open_IM/pkg/utils"
"context"
"net/http"
"strings"
"Open_IM/pkg/common/constant"
"github.com/gin-gonic/gin"
)
func BroadcastMessage(c *gin.Context) {
var (
reqPb pbMessage.BoradcastMessageReq
)
reqPb.OperationID = utils.OperationIDGenerator()
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImMessageCMSName, 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
}
client := pbMessage.NewMessageCMSClient(etcdConn)
_, err := client.BoradcastMessage(context.Background(), &reqPb)
if err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "GetChatLogs rpc failed", err.Error())
openIMHttp.RespHttp200(c, err, nil)
return
}
openIMHttp.RespHttp200(c, constant.OK, nil)
}
func MassSendMassage(c *gin.Context) {
var (
reqPb pbMessage.MassSendMessageReq
)
reqPb.OperationID = utils.OperationIDGenerator()
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImMessageCMSName, 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
}
client := pbMessage.NewMessageCMSClient(etcdConn)
_, err := client.MassSendMessage(context.Background(), &reqPb)
if err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "GetChatLogs rpc failed", err.Error())
openIMHttp.RespHttp200(c, err, nil)
return
}
openIMHttp.RespHttp200(c, constant.OK, nil)
}
func WithdrawMessage(c *gin.Context) {
var (
reqPb pbMessage.WithdrawMessageReq
)
reqPb.OperationID = utils.OperationIDGenerator()
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImMessageCMSName, 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
}
client := pbMessage.NewMessageCMSClient(etcdConn)
_, err := client.WithdrawMessage(context.Background(), &reqPb)
if err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "GetChatLogs rpc failed", err.Error())
openIMHttp.RespHttp200(c, err, nil)
return
}
openIMHttp.RespHttp200(c, constant.OK, nil)
}
func GetChatLogs(c *gin.Context) {
var (
req cms_api_struct.GetChatLogsRequest
resp cms_api_struct.GetChatLogsResponse
reqPb pbMessage.GetChatLogsReq
req cms_api_struct.GetChatLogsReq
resp cms_api_struct.GetChatLogsResp
reqPb pbAdminCMS.GetChatLogsReq
)
if err := c.ShouldBindQuery(&req); err != nil {
if err := c.Bind(&req); err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "ShouldBindQuery failed ", err.Error())
openIMHttp.RespHttp200(c, constant.ErrArgs, resp)
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
reqPb.Pagination = &pbCommon.RequestPagination{
@ -101,39 +32,28 @@ func GetChatLogs(c *gin.Context) {
}
utils.CopyStructFields(&reqPb, &req)
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "req: ", req)
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImMessageCMSName, reqPb.OperationID)
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
}
client := pbMessage.NewMessageCMSClient(etcdConn)
client := pbAdminCMS.NewAdminCMSClient(etcdConn)
respPb, err := client.GetChatLogs(context.Background(), &reqPb)
if err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "GetChatLogs rpc failed", err.Error())
openIMHttp.RespHttp200(c, err, resp)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
return
}
//utils.CopyStructFields(&resp, &respPb)
for _, chatLog := range respPb.ChatLogs {
resp.ChatLogs = append(resp.ChatLogs, cms_api_struct.ChatLog{
SessionType: int(chatLog.SessionType),
ContentType: int(chatLog.ContentType),
SenderNickName: chatLog.SenderNickName,
SenderId: chatLog.SenderId,
SearchContent: chatLog.SearchContent,
WholeContent: chatLog.WholeContent,
ReceiverNickName: chatLog.ReciverNickName,
ReceiverID: chatLog.ReciverId,
GroupName: chatLog.GroupName,
GroupId: chatLog.GroupId,
Date: chatLog.Date,
})
for _, v := range respPb.ChatLogs {
chatLog := cms_api_struct.ChatLog{}
utils.CopyStructFields(&chatLog, v)
resp.ChatLogs = append(resp.ChatLogs, &chatLog)
}
resp.ShowNumber = int(respPb.Pagination.ShowNumber)
resp.CurrentPage = int(respPb.Pagination.CurrentPage)
resp.ChatLogsNum = int(respPb.ChatLogsNum)
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "resp", resp)
openIMHttp.RespHttp200(c, constant.OK, resp)
c.JSON(http.StatusOK, gin.H{"errCode": respPb.CommonResp.ErrCode, "errMsg": respPb.CommonResp.ErrMsg, "data": resp})
}

@ -1,23 +1,23 @@
package middleware
import (
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/http"
"Open_IM/pkg/common/log"
"Open_IM/pkg/common/token_verify"
"Open_IM/pkg/utils"
"net/http"
"github.com/gin-gonic/gin"
)
func JWTAuth() gin.HandlerFunc {
return func(c *gin.Context) {
ok, userID, errInfo := token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), "")
log.NewInfo("0", utils.GetSelfFuncName(), "userID: ", userID)
// log.NewInfo("0", utils.GetSelfFuncName(), "userID: ", userID)
c.Set("userID", userID)
if !ok {
log.NewError("", "GetUserIDFromToken false ", c.Request.Header.Get("token"))
c.Abort()
http.RespHttp200(c, constant.ErrParseToken, nil)
c.JSON(http.StatusOK, gin.H{"errCode": 400, "errMsg": errInfo})
return
} else {
log.NewInfo("0", utils.GetSelfFuncName(), "failed: ", errInfo)

@ -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) {
}

@ -2,12 +2,13 @@ package cms_api
import (
"Open_IM/internal/cms_api/admin"
"Open_IM/internal/cms_api/friend"
"Open_IM/internal/cms_api/group"
messageCMS "Open_IM/internal/cms_api/message_cms"
"Open_IM/internal/cms_api/middleware"
"Open_IM/internal/cms_api/organization"
"Open_IM/internal/cms_api/statistics"
"Open_IM/internal/cms_api/user"
"Open_IM/internal/demo/register"
"github.com/gin-gonic/gin"
)
@ -24,65 +25,48 @@ func NewGinRouter() *gin.Engine {
adminRouterGroup.POST("/add_user_register_add_friend_id", admin.AddUserRegisterAddFriendIDList)
adminRouterGroup.POST("/reduce_user_register_reduce_friend_id", admin.ReduceUserRegisterAddFriendIDList)
adminRouterGroup.POST("/get_user_register_reduce_friend_id_list", admin.GetUserRegisterAddFriendIDList)
adminRouterGroup.POST("/generate_invitation_code", register.GenerateInvitationCode)
adminRouterGroup.POST("/query_invitation_code", register.QueryInvitationCode)
adminRouterGroup.POST("/get_invitation_codes", register.GetInvitationCodes)
adminRouterGroup.POST("/query_user_ip_limit_login", register.QueryUserIDLimitLogin)
adminRouterGroup.POST("/add_user_ip_limit_login", register.AddUserIPLimitLogin)
adminRouterGroup.POST("/remove_user_ip_limit_login", register.RemoveUserIPLimitLogin)
adminRouterGroup.POST("/query_ip_register", register.QueryIPRegister)
adminRouterGroup.POST("/add_ip_limit", register.AddIPLimit)
adminRouterGroup.POST("/remove_ip_Limit", register.RemoveIPLimit)
}
r2 := router.Group("")
r2.Use(middleware.JWTAuth())
statisticsRouterGroup := r2.Group("/statistics")
{
statisticsRouterGroup.GET("/get_messages_statistics", statistics.GetMessagesStatistics)
statisticsRouterGroup.GET("/get_user_statistics", statistics.GetUserStatistics)
statisticsRouterGroup.GET("/get_group_statistics", statistics.GetGroupStatistics)
statisticsRouterGroup.GET("/get_active_user", statistics.GetActiveUser)
statisticsRouterGroup.GET("/get_active_group", statistics.GetActiveGroup)
}
organizationRouterGroup := r2.Group("/organization")
{
organizationRouterGroup.GET("/get_staffs", organization.GetStaffs)
organizationRouterGroup.GET("/get_organizations", organization.GetOrganizations)
organizationRouterGroup.GET("/get_squad", organization.GetSquads)
organizationRouterGroup.POST("/add_organization", organization.AddOrganization)
organizationRouterGroup.POST("/alter_staff", organization.AlterStaff)
organizationRouterGroup.GET("/inquire_organization", organization.InquireOrganization)
organizationRouterGroup.POST("/alter_organization", organization.AlterOrganization)
organizationRouterGroup.POST("/delete_organization", organization.DeleteOrganization)
organizationRouterGroup.POST("/get_organization_squad", organization.GetOrganizationSquads)
organizationRouterGroup.PATCH("/alter_corps_info", organization.AlterStaffsInfo)
organizationRouterGroup.POST("/add_child_org", organization.AddChildOrganization)
statisticsRouterGroup.POST("/get_messages_statistics", statistics.GetMessagesStatistics)
statisticsRouterGroup.POST("/get_user_statistics", statistics.GetUserStatistics)
statisticsRouterGroup.POST("/get_group_statistics", statistics.GetGroupStatistics)
statisticsRouterGroup.POST("/get_active_user", statistics.GetActiveUser)
statisticsRouterGroup.POST("/get_active_group", statistics.GetActiveGroup)
}
groupRouterGroup := r2.Group("/group")
{
groupRouterGroup.GET("/get_group_by_id", group.GetGroupByID)
groupRouterGroup.GET("/get_groups", group.GetGroups)
groupRouterGroup.GET("/get_group_by_name", group.GetGroupByName)
groupRouterGroup.GET("/get_group_members", group.GetGroupMembers)
groupRouterGroup.POST("/create_group", group.CreateGroup)
groupRouterGroup.POST("/add_members", group.AddGroupMembers)
groupRouterGroup.POST("/remove_members", group.RemoveGroupMembers)
groupRouterGroup.POST("/get_members_in_group", group.GetGroupMembers)
groupRouterGroup.POST("/set_group_master", group.SetGroupOwner)
groupRouterGroup.POST("/set_group_ordinary_user", group.SetGroupOrdinaryUsers)
groupRouterGroup.POST("/alter_group_info", group.AlterGroupInfo)
groupRouterGroup.POST("/get_groups", group.GetGroups)
groupRouterGroup.POST("/get_group_members", group.GetGroupMembers)
}
userRouterGroup := r2.Group("/user")
{
userRouterGroup.POST("/resign", user.ResignUser)
userRouterGroup.GET("/get_user", user.GetUserById)
userRouterGroup.POST("/alter_user", user.AlterUser)
userRouterGroup.GET("/get_users", user.GetUsers)
userRouterGroup.POST("/add_user", user.AddUser)
userRouterGroup.POST("/unblock_user", user.UnblockUser)
userRouterGroup.POST("/block_user", user.BlockUser)
userRouterGroup.GET("/get_block_users", user.GetBlockUsers)
userRouterGroup.GET("/get_block_user", user.GetBlockUserById)
userRouterGroup.POST("/delete_user", user.DeleteUser)
userRouterGroup.GET("/get_users_by_name", user.GetUsersByName)
userRouterGroup.POST("/get_block_users", user.GetBlockUsers)
}
messageCMSRouterGroup := r2.Group("/message")
{
messageCMSRouterGroup.GET("/get_chat_logs", messageCMS.GetChatLogs)
messageCMSRouterGroup.POST("/broadcast_message", messageCMS.BroadcastMessage)
messageCMSRouterGroup.POST("/mass_send_message", messageCMS.MassSendMassage)
messageCMSRouterGroup.POST("/withdraw_message", messageCMS.WithdrawMessage)
messageCMSRouterGroup.POST("/get_chat_logs", messageCMS.GetChatLogs)
}
friendCMSRouterGroup := r2.Group("friend")
{
friendCMSRouterGroup.POST("/get_friends", friend.GetUserFriends)
}
return baseRouter
}

@ -3,15 +3,14 @@ package statistics
import (
"Open_IM/pkg/cms_api_struct"
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/constant"
openIMHttp "Open_IM/pkg/common/http"
"Open_IM/pkg/common/log"
"Open_IM/pkg/grpc-etcdv3/getcdv3"
pb "Open_IM/pkg/proto/statistics"
admin "Open_IM/pkg/proto/admin_cms"
"Open_IM/pkg/utils"
"context"
"net/http"
"strings"
"time"
"github.com/gin-gonic/gin"
)
@ -20,38 +19,40 @@ func GetMessagesStatistics(c *gin.Context) {
var (
req cms_api_struct.GetMessageStatisticsRequest
resp cms_api_struct.GetMessageStatisticsResponse
reqPb pb.GetMessageStatisticsReq
reqPb admin.GetMessageStatisticsReq
)
reqPb.StatisticsReq = &pb.StatisticsReq{}
if err := c.ShouldBindQuery(&req); err != nil {
log.NewError("0", utils.GetSelfFuncName(), "BindJSON failed ", err.Error())
openIMHttp.RespHttp200(c, constant.ErrArgs, nil)
reqPb.StatisticsReq = &admin.StatisticsReq{}
if err := c.BindJSON(&req); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "BindJSON failed ", err.Error())
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
reqPb.OperationID = utils.OperationIDGenerator()
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "req: ", req)
utils.CopyStructFields(&reqPb.StatisticsReq, &req)
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImStatisticsName, reqPb.OperationID)
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
}
client := pb.NewUserClient(etcdConn)
respPb, err := client.GetMessageStatistics(context.Background(), &reqPb)
client := admin.NewAdminCMSClient(etcdConn)
ctx, cancel := context.WithTimeout(context.TODO(), time.Second*100)
defer cancel()
respPb, err := client.GetMessageStatistics(ctx, &reqPb)
if err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "GetMessageStatistics failed", err.Error())
openIMHttp.RespHttp200(c, err, resp)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
// utils.CopyStructFields(&resp, respPb)
resp.GroupMessageNum = int(respPb.GroupMessageNum)
resp.PrivateMessageNum = int(respPb.PrivateMessageNum)
for _, v := range respPb.PrivateMessageNumList {
resp.PrivateMessageNumList = append(resp.PrivateMessageNumList, struct {
Date string "json:\"date\""
MessageNum int "json:\"message_num\""
MessageNum int "json:\"messageNum\""
}{
Date: v.Date,
MessageNum: int(v.Num),
@ -60,53 +61,54 @@ func GetMessagesStatistics(c *gin.Context) {
for _, v := range respPb.GroupMessageNumList {
resp.GroupMessageNumList = append(resp.GroupMessageNumList, struct {
Date string "json:\"date\""
MessageNum int "json:\"message_num\""
MessageNum int "json:\"messageNum\""
}{
Date: v.Date,
MessageNum: int(v.Num),
})
}
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
openIMHttp.RespHttp200(c, constant.OK, resp)
c.JSON(http.StatusOK, gin.H{"errCode": respPb.CommonResp.ErrCode, "errMsg": respPb.CommonResp.ErrMsg, "data": resp})
}
func GetUserStatistics(c *gin.Context) {
var (
req cms_api_struct.GetUserStatisticsRequest
resp cms_api_struct.GetUserStatisticsResponse
reqPb pb.GetUserStatisticsReq
reqPb admin.GetUserStatisticsReq
)
reqPb.StatisticsReq = &pb.StatisticsReq{}
if err := c.ShouldBindQuery(&req); err != nil {
log.NewError("0", utils.GetSelfFuncName(), "BindJSON failed ", err.Error())
openIMHttp.RespHttp200(c, constant.ErrArgs, nil)
reqPb.StatisticsReq = &admin.StatisticsReq{}
if err := c.BindJSON(&req); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "BindJSON failed ", err.Error())
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
reqPb.OperationID = utils.OperationIDGenerator()
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "req: ", req)
utils.CopyStructFields(&reqPb.StatisticsReq, &req)
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImStatisticsName, reqPb.OperationID)
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
}
client := pb.NewUserClient(etcdConn)
respPb, err := client.GetUserStatistics(context.Background(), &reqPb)
client := admin.NewAdminCMSClient(etcdConn)
ctx, cancel := context.WithTimeout(context.TODO(), time.Second*100)
defer cancel()
respPb, err := client.GetUserStatistics(ctx, &reqPb)
if err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "GetUserStatistics failed", err.Error())
openIMHttp.RespHttp200(c, err, nil)
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "GetUserStatistics failed", err.Error(), reqPb.String())
c.JSON(http.StatusBadRequest, gin.H{"errCode": 500, "errMsg": err.Error()})
return
}
// utils.CopyStructFields(&resp, respPb)
resp.ActiveUserNum = int(respPb.ActiveUserNum)
resp.IncreaseUserNum = int(respPb.IncreaseUserNum)
resp.TotalUserNum = int(respPb.TotalUserNum)
for _, v := range respPb.ActiveUserNumList {
resp.ActiveUserNumList = append(resp.ActiveUserNumList, struct {
Date string "json:\"date\""
ActiveUserNum int "json:\"active_user_num\""
ActiveUserNum int "json:\"activeUserNum\""
}{
Date: v.Date,
ActiveUserNum: int(v.Num),
@ -115,7 +117,7 @@ func GetUserStatistics(c *gin.Context) {
for _, v := range respPb.IncreaseUserNumList {
resp.IncreaseUserNumList = append(resp.IncreaseUserNumList, struct {
Date string "json:\"date\""
IncreaseUserNum int "json:\"increase_user_num\""
IncreaseUserNum int "json:\"increaseUserNum\""
}{
Date: v.Date,
IncreaseUserNum: int(v.Num),
@ -124,43 +126,45 @@ func GetUserStatistics(c *gin.Context) {
for _, v := range respPb.TotalUserNumList {
resp.TotalUserNumList = append(resp.TotalUserNumList, struct {
Date string "json:\"date\""
TotalUserNum int "json:\"total_user_num\""
TotalUserNum int "json:\"totalUserNum\""
}{
Date: v.Date,
TotalUserNum: int(v.Num),
})
}
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
openIMHttp.RespHttp200(c, constant.OK, resp)
c.JSON(http.StatusOK, gin.H{"errCode": respPb.CommonResp.ErrCode, "errMsg": respPb.CommonResp.ErrMsg, "data": resp})
}
func GetGroupStatistics(c *gin.Context) {
var (
req cms_api_struct.GetGroupStatisticsRequest
resp cms_api_struct.GetGroupStatisticsResponse
reqPb pb.GetGroupStatisticsReq
reqPb admin.GetGroupStatisticsReq
)
reqPb.StatisticsReq = &pb.StatisticsReq{}
if err := c.ShouldBindQuery(&req); err != nil {
log.NewError("0", "BindJSON failed ", err.Error())
openIMHttp.RespHttp200(c, constant.ErrArgs, nil)
reqPb.StatisticsReq = &admin.StatisticsReq{}
if err := c.BindJSON(&req); err != nil {
log.NewError(req.OperationID, "BindJSON failed ", err.Error())
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
reqPb.OperationID = utils.OperationIDGenerator()
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "req: ", req)
utils.CopyStructFields(&reqPb.StatisticsReq, &req)
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImStatisticsName, reqPb.OperationID)
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
}
client := pb.NewUserClient(etcdConn)
respPb, err := client.GetGroupStatistics(context.Background(), &reqPb)
client := admin.NewAdminCMSClient(etcdConn)
ctx, cancel := context.WithTimeout(context.TODO(), time.Second*100)
defer cancel()
respPb, err := client.GetGroupStatistics(ctx, &reqPb)
if err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "GetGroupStatistics failed", err.Error())
openIMHttp.RespHttp200(c, err, nil)
c.JSON(http.StatusBadRequest, gin.H{"errCode": 500, "errMsg": err.Error()})
return
}
// utils.CopyStructFields(&resp, respPb)
@ -170,7 +174,7 @@ func GetGroupStatistics(c *gin.Context) {
resp.IncreaseGroupNumList = append(resp.IncreaseGroupNumList,
struct {
Date string "json:\"date\""
IncreaseGroupNum int "json:\"increase_group_num\""
IncreaseGroupNum int "json:\"increaseGroupNum\""
}{
Date: v.Date,
IncreaseGroupNum: int(v.Num),
@ -180,7 +184,7 @@ func GetGroupStatistics(c *gin.Context) {
resp.TotalGroupNumList = append(resp.TotalGroupNumList,
struct {
Date string "json:\"date\""
TotalGroupNum int "json:\"total_group_num\""
TotalGroupNum int "json:\"totalGroupNum\""
}{
Date: v.Date,
TotalGroupNum: int(v.Num),
@ -188,77 +192,81 @@ func GetGroupStatistics(c *gin.Context) {
}
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
openIMHttp.RespHttp200(c, constant.OK, resp)
c.JSON(http.StatusOK, gin.H{"errCode": respPb.CommonResp.ErrCode, "errMsg": respPb.CommonResp.ErrMsg, "data": resp})
}
func GetActiveUser(c *gin.Context) {
var (
req cms_api_struct.GetActiveUserRequest
resp cms_api_struct.GetActiveUserResponse
reqPb pb.GetActiveUserReq
reqPb admin.GetActiveUserReq
)
reqPb.StatisticsReq = &pb.StatisticsReq{}
if err := c.ShouldBindQuery(&req); err != nil {
log.NewError("0", "BindJSON failed ", err.Error())
openIMHttp.RespHttp200(c, constant.ErrArgs, nil)
reqPb.StatisticsReq = &admin.StatisticsReq{}
if err := c.BindJSON(&req); err != nil {
log.NewError(req.OperationID, "BindJSON failed ", err.Error())
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
reqPb.OperationID = utils.OperationIDGenerator()
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "req: ", req)
utils.CopyStructFields(&reqPb.StatisticsReq, req)
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImStatisticsName, reqPb.OperationID)
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
}
client := pb.NewUserClient(etcdConn)
respPb, err := client.GetActiveUser(context.Background(), &reqPb)
client := admin.NewAdminCMSClient(etcdConn)
ctx, cancel := context.WithTimeout(context.TODO(), time.Second*100)
defer cancel()
respPb, err := client.GetActiveUser(ctx, &reqPb)
if err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "GetActiveUser failed ", err.Error())
openIMHttp.RespHttp200(c, err, nil)
c.JSON(http.StatusBadRequest, gin.H{"errCode": 500, "errMsg": err.Error()})
return
}
utils.CopyStructFields(&resp.ActiveUserList, respPb.Users)
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
openIMHttp.RespHttp200(c, constant.OK, resp)
c.JSON(http.StatusOK, gin.H{"errCode": respPb.CommonResp.ErrCode, "errMsg": respPb.CommonResp.ErrMsg, "data": resp})
}
func GetActiveGroup(c *gin.Context) {
var (
req cms_api_struct.GetActiveGroupRequest
resp cms_api_struct.GetActiveGroupResponse
reqPb pb.GetActiveGroupReq
reqPb admin.GetActiveGroupReq
)
reqPb.StatisticsReq = &pb.StatisticsReq{}
if err := c.ShouldBindQuery(&req); err != nil {
log.NewError("0", utils.GetSelfFuncName(), "BindJSON failed ", err.Error())
openIMHttp.RespHttp200(c, constant.ErrArgs, nil)
reqPb.StatisticsReq = &admin.StatisticsReq{}
if err := c.BindJSON(&req); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "BindJSON failed ", err.Error())
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
reqPb.OperationID = utils.OperationIDGenerator()
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "req: ", req)
utils.CopyStructFields(&reqPb.StatisticsReq, req)
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImStatisticsName, reqPb.OperationID)
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
}
client := pb.NewUserClient(etcdConn)
respPb, err := client.GetActiveGroup(context.Background(), &reqPb)
client := admin.NewAdminCMSClient(etcdConn)
ctx, cancel := context.WithTimeout(context.TODO(), time.Second*100)
defer cancel()
respPb, err := client.GetActiveGroup(ctx, &reqPb)
if err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "GetActiveGroup failed ", err.Error())
openIMHttp.RespHttp200(c, err, nil)
c.JSON(http.StatusBadRequest, gin.H{"errCode": 500, "errMsg": err.Error()})
return
}
for _, group := range respPb.Groups {
resp.ActiveGroupList = append(resp.ActiveGroupList, struct {
GroupName string "json:\"group_name\""
GroupId string "json:\"group_id\""
MessageNum int "json:\"message_num\""
GroupName string "json:\"groupName\""
GroupId string "json:\"groupID\""
MessageNum int "json:\"messageNum\""
}{
GroupName: group.GroupName,
GroupId: group.GroupId,
@ -266,5 +274,5 @@ func GetActiveGroup(c *gin.Context) {
})
}
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
openIMHttp.RespHttp200(c, constant.OK, resp)
c.JSON(http.StatusOK, gin.H{"errCode": respPb.CommonResp.ErrCode, "errMsg": respPb.CommonResp.ErrMsg, "data": resp})
}

@ -3,196 +3,18 @@ package user
import (
"Open_IM/pkg/cms_api_struct"
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/constant"
openIMHttp "Open_IM/pkg/common/http"
"Open_IM/pkg/common/log"
"Open_IM/pkg/grpc-etcdv3/getcdv3"
commonPb "Open_IM/pkg/proto/sdk_ws"
pb "Open_IM/pkg/proto/user"
"Open_IM/pkg/utils"
"context"
"fmt"
"net/http"
"strings"
"github.com/gin-gonic/gin"
)
func GetUserById(c *gin.Context) {
var (
req cms_api_struct.GetUserRequest
resp cms_api_struct.GetUserResponse
reqPb pb.GetUserByIdReq
)
if err := c.ShouldBindQuery(&req); err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "ShouldBindQuery failed ", err.Error())
openIMHttp.RespHttp200(c, constant.ErrArgs, nil)
return
}
reqPb.OperationID = utils.OperationIDGenerator()
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "req: ", req)
utils.CopyStructFields(&reqPb, &req)
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName, 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
}
client := pb.NewUserClient(etcdConn)
respPb, err := client.GetUserById(context.Background(), &reqPb)
if err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), err.Error())
openIMHttp.RespHttp200(c, err, nil)
return
}
if respPb.User.UserId == "" {
openIMHttp.RespHttp200(c, constant.OK, nil)
return
}
utils.CopyStructFields(&resp, respPb.User)
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
openIMHttp.RespHttp200(c, constant.OK, resp)
}
func GetUsersByName(c *gin.Context) {
var (
req cms_api_struct.GetUsersByNameRequest
resp cms_api_struct.GetUsersByNameResponse
reqPb pb.GetUsersByNameReq
)
reqPb.OperationID = utils.OperationIDGenerator()
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "req: ", req)
if err := c.ShouldBindQuery(&req); err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "ShouldBindQuery failed", err.Error())
openIMHttp.RespHttp200(c, constant.ErrArgs, nil)
return
}
reqPb.UserName = req.UserName
reqPb.Pagination = &commonPb.RequestPagination{
PageNumber: int32(req.PageNumber),
ShowNumber: int32(req.ShowNumber),
}
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName, 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
}
client := pb.NewUserClient(etcdConn)
respPb, err := client.GetUsersByName(context.Background(), &reqPb)
if err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "rpc", err.Error())
openIMHttp.RespHttp200(c, err, nil)
return
}
utils.CopyStructFields(&resp.Users, respPb.Users)
resp.ShowNumber = int(respPb.Pagination.ShowNumber)
resp.CurrentPage = int(respPb.Pagination.CurrentPage)
resp.UserNums = respPb.UserNums
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
openIMHttp.RespHttp200(c, constant.OK, resp)
}
func GetUsers(c *gin.Context) {
var (
req cms_api_struct.GetUsersRequest
resp cms_api_struct.GetUsersResponse
reqPb pb.GetUsersReq
)
reqPb.Pagination = &commonPb.RequestPagination{}
if err := c.ShouldBindQuery(&req); err != nil {
log.NewError("0", "ShouldBindQuery failed ", err.Error())
openIMHttp.RespHttp200(c, constant.ErrArgs, nil)
return
}
reqPb.OperationID = utils.OperationIDGenerator()
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "req: ", req)
utils.CopyStructFields(&reqPb.Pagination, &req)
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName, 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
}
client := pb.NewUserClient(etcdConn)
respPb, err := client.GetUsers(context.Background(), &reqPb)
if err != nil {
openIMHttp.RespHttp200(c, err, resp)
return
}
utils.CopyStructFields(&resp.Users, respPb.User)
resp.ShowNumber = int(respPb.Pagination.ShowNumber)
resp.CurrentPage = int(respPb.Pagination.CurrentPage)
resp.UserNums = respPb.UserNums
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
openIMHttp.RespHttp200(c, constant.OK, resp)
}
func ResignUser(c *gin.Context) {
var (
req cms_api_struct.ResignUserRequest
resp cms_api_struct.ResignUserResponse
reqPb pb.ResignUserReq
)
if err := c.ShouldBind(&req); err != nil {
log.NewError("0", "BindJSON failed ", err.Error())
c.JSON(http.StatusBadRequest, gin.H{"errCode": http.StatusBadRequest, "errMsg": err.Error()})
return
}
reqPb.OperationID = utils.OperationIDGenerator()
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "req: ", req)
utils.CopyStructFields(&reqPb, &req)
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName, 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
}
client := pb.NewUserClient(etcdConn)
_, err := client.ResignUser(context.Background(), &reqPb)
if err != nil {
openIMHttp.RespHttp200(c, err, resp)
}
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
openIMHttp.RespHttp200(c, constant.OK, resp)
}
func AlterUser(c *gin.Context) {
var (
req cms_api_struct.AlterUserRequest
resp cms_api_struct.AlterUserResponse
reqPb pb.AlterUserReq
)
if err := c.BindJSON(&req); err != nil {
log.NewError("0", "BindJSON failed ", err.Error())
openIMHttp.RespHttp200(c, constant.ErrArgs, resp)
return
}
reqPb.OperationID = utils.OperationIDGenerator()
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "req: ", req)
utils.CopyStructFields(&reqPb, &req)
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName, 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
}
client := pb.NewUserClient(etcdConn)
_, err := client.AlterUser(context.Background(), &reqPb)
if err != nil {
log.NewError(reqPb.OperationID, "microserver failed ", err.Error())
openIMHttp.RespHttp200(c, err, nil)
}
openIMHttp.RespHttp200(c, constant.OK, nil)
}
func AddUser(c *gin.Context) {
var (
req cms_api_struct.AddUserRequest
@ -200,7 +22,7 @@ func AddUser(c *gin.Context) {
)
if err := c.BindJSON(&req); err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "BindJSON failed ", err.Error())
openIMHttp.RespHttp200(c, constant.ErrArgs, nil)
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
reqPb.OperationID = utils.OperationIDGenerator()
@ -214,24 +36,23 @@ func AddUser(c *gin.Context) {
return
}
client := pb.NewUserClient(etcdConn)
_, err := client.AddUser(context.Background(), &reqPb)
respPb, err := client.AddUser(context.Background(), &reqPb)
if err != nil {
openIMHttp.RespHttp200(c, err, nil)
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), reqPb.String())
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
return
}
openIMHttp.RespHttp200(c, constant.OK, nil)
c.JSON(http.StatusOK, gin.H{"errCode": respPb.CommonResp.ErrCode, "errMsg": respPb.CommonResp.ErrMsg})
}
func BlockUser(c *gin.Context) {
var (
req cms_api_struct.BlockUserRequest
resp cms_api_struct.BlockUserResponse
reqPb pb.BlockUserReq
)
if err := c.BindJSON(&req); err != nil {
fmt.Println(err)
log.NewError("0", "BindJSON failed ", err.Error())
openIMHttp.RespHttp200(c, constant.ErrArgs, resp)
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
reqPb.OperationID = utils.OperationIDGenerator()
@ -245,13 +66,13 @@ func BlockUser(c *gin.Context) {
return
}
client := pb.NewUserClient(etcdConn)
fmt.Println(reqPb)
_, err := client.BlockUser(context.Background(), &reqPb)
respPb, err := client.BlockUser(context.Background(), &reqPb)
if err != nil {
openIMHttp.RespHttp200(c, err, resp)
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), reqPb.String())
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
return
}
openIMHttp.RespHttp200(c, constant.OK, resp)
c.JSON(http.StatusOK, gin.H{"errCode": respPb.CommonResp.ErrCode, "errMsg": respPb.CommonResp.ErrMsg})
}
func UnblockUser(c *gin.Context) {
@ -260,9 +81,9 @@ func UnblockUser(c *gin.Context) {
resp cms_api_struct.UnBlockUserResponse
reqPb pb.UnBlockUserReq
)
if err := c.ShouldBind(&req); err != nil {
log.NewError("0", "BindJSON failed ", err.Error())
openIMHttp.RespHttp200(c, constant.ErrArgs, resp)
if err := c.BindJSON(&req); err != nil {
log.NewError(req.OperationID, "BindJSON failed ", err.Error())
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
reqPb.OperationID = utils.OperationIDGenerator()
@ -276,13 +97,14 @@ func UnblockUser(c *gin.Context) {
return
}
client := pb.NewUserClient(etcdConn)
_, err := client.UnBlockUser(context.Background(), &reqPb)
respPb, err := client.UnBlockUser(context.Background(), &reqPb)
if err != nil {
openIMHttp.RespHttp200(c, err, resp)
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), err.Error(), reqPb.String())
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
return
}
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
openIMHttp.RespHttp200(c, constant.OK, resp)
c.JSON(http.StatusOK, gin.H{"errCode": respPb.CommonResp.ErrCode, "errMsg": respPb.CommonResp.ErrMsg})
}
func GetBlockUsers(c *gin.Context) {
@ -293,9 +115,9 @@ func GetBlockUsers(c *gin.Context) {
respPb *pb.GetBlockUsersResp
)
reqPb.Pagination = &commonPb.RequestPagination{}
if err := c.ShouldBindQuery(&req); err != nil {
if err := c.BindJSON(&req); err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "ShouldBindQuery failed ", err.Error())
openIMHttp.RespHttp200(c, constant.ErrArgs, resp)
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
reqPb.OperationID = utils.OperationIDGenerator()
@ -313,21 +135,18 @@ func GetBlockUsers(c *gin.Context) {
respPb, err := client.GetBlockUsers(context.Background(), &reqPb)
if err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "GetBlockUsers rpc", err.Error())
openIMHttp.RespHttp200(c, err, resp)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
return
}
for _, v := range respPb.BlockUsers {
resp.BlockUsers = append(resp.BlockUsers, cms_api_struct.BlockUser{
UserResponse: cms_api_struct.UserResponse{
UserId: v.User.UserId,
ProfilePhoto: v.User.ProfilePhoto,
Nickname: v.User.Nickname,
IsBlock: v.User.IsBlock,
Birth: v.User.Birth,
PhoneNumber: v.User.PhoneNumber,
Email: v.User.Email,
Gender: int(v.User.Gender),
CreateTime: v.User.CreateTime,
UserID: v.UserInfo.UserID,
FaceURL: v.UserInfo.FaceURL,
Nickname: v.UserInfo.Nickname,
PhoneNumber: v.UserInfo.PhoneNumber,
Email: v.UserInfo.Email,
Gender: int(v.UserInfo.Gender),
},
BeginDisableTime: v.BeginDisableTime,
EndDisableTime: v.EndDisableTime,
@ -337,70 +156,5 @@ func GetBlockUsers(c *gin.Context) {
resp.CurrentPage = int(respPb.Pagination.CurrentPage)
resp.UserNums = respPb.UserNums
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "req: ", resp)
openIMHttp.RespHttp200(c, constant.OK, resp)
}
func GetBlockUserById(c *gin.Context) {
var (
req cms_api_struct.GetBlockUserRequest
resp cms_api_struct.GetBlockUserResponse
reqPb pb.GetBlockUserByIdReq
)
if err := c.ShouldBindQuery(&req); err != nil {
log.NewError("0", "BindJSON failed ", err.Error())
openIMHttp.RespHttp200(c, constant.ErrArgs, nil)
return
}
reqPb.OperationID = utils.OperationIDGenerator()
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "req: ", req)
reqPb.UserId = req.UserId
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName, 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
}
client := pb.NewUserClient(etcdConn)
respPb, err := client.GetBlockUserById(context.Background(), &reqPb)
if err != nil {
log.NewError(reqPb.OperationID, "GetBlockUserById rpc failed ", err.Error())
openIMHttp.RespHttp200(c, err, nil)
return
}
resp.EndDisableTime = respPb.BlockUser.EndDisableTime
resp.BeginDisableTime = respPb.BlockUser.BeginDisableTime
utils.CopyStructFields(&resp, respPb.BlockUser.User)
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
openIMHttp.RespHttp200(c, constant.OK, resp)
}
func DeleteUser(c *gin.Context) {
var (
req cms_api_struct.DeleteUserRequest
reqPb pb.DeleteUserReq
)
if err := c.BindJSON(&req); err != nil {
log.NewError("0", "BindJSON failed ", err.Error())
openIMHttp.RespHttp200(c, constant.ErrArgs, nil)
return
}
reqPb.OperationID = utils.OperationIDGenerator()
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "req: ", req)
reqPb.UserId = req.UserId
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName, 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
}
client := pb.NewUserClient(etcdConn)
_, err := client.DeleteUser(context.Background(), &reqPb)
if err != nil {
log.NewError(reqPb.OperationID, "DeleteUser rpc failed ", err.Error())
openIMHttp.RespHttp200(c, err, nil)
return
}
openIMHttp.RespHttp200(c, constant.OK, nil)
c.JSON(http.StatusOK, gin.H{"errCode": respPb.CommonResp.ErrCode, "errMsg": respPb.CommonResp.ErrMsg, "data": resp})
}

@ -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": ""})
}

@ -7,7 +7,9 @@ import (
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
"Open_IM/pkg/common/log"
"Open_IM/pkg/utils"
"github.com/gin-gonic/gin"
//"github.com/jinzhu/gorm"
"net/http"
"time"
@ -141,7 +143,7 @@ func QueryUserIDLimitLogin(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"errCode": 0, "errMsg": "", "data": resp})
return
}
c.JSON(http.StatusOK, gin.H{"errCode": 0, "errMsg": "", "data": resp})
c.JSON(http.StatusOK, gin.H{"errCode": 0, "errMsg": "", "data": gin.H{"limit": resp}})
}
type AddUserIPLimitLoginReq struct {
@ -163,8 +165,8 @@ func AddUserIPLimitLogin(c *gin.Context) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req:", req)
userIp := db.UserIpLimit{UserID: req.UserID, Ip: req.IP}
err := imdb.UpdateUserInfo(db.User{
UserID: req.UserID,
LoginLimit: 1,
UserID: req.UserID,
// LoginLimit: 1,
})
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.UserID)

@ -8,6 +8,7 @@ import (
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
http2 "Open_IM/pkg/common/http"
"Open_IM/pkg/common/log"
"Open_IM/pkg/common/token_verify"
pbFriend "Open_IM/pkg/proto/friend"
"Open_IM/pkg/utils"
"encoding/json"
@ -41,28 +42,33 @@ func SetPassword(c *gin.Context) {
c.JSON(http.StatusBadRequest, gin.H{"errCode": constant.FormattingError, "errMsg": err.Error()})
return
}
ip := c.Request.Header.Get("X-Forward-For")
if ip == "" {
ip = c.ClientIP()
}
log.NewDebug(params.OperationID, utils.GetSelfFuncName(), "ip:", ip)
Limited, LimitError := imdb.IsLimitRegisterIp(ip)
if LimitError != nil {
log.Error(params.OperationID, utils.GetSelfFuncName(), LimitError, ip)
c.JSON(http.StatusBadRequest, gin.H{"errCode": constant.ErrDB.ErrCode, "errMsg": LimitError.Error()})
return
}
if Limited {
c.JSON(http.StatusBadRequest, gin.H{"errCode": constant.RegisterLimit, "errMsg": "limited"})
return
}
ok, opUserID, _ := token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), params.OperationID)
if !ok || !utils.IsContain(opUserID, config.Config.Manager.AppManagerUid) {
Limited, LimitError := imdb.IsLimitRegisterIp(ip)
if LimitError != nil {
log.Error(params.OperationID, utils.GetSelfFuncName(), LimitError, ip)
c.JSON(http.StatusBadRequest, gin.H{"errCode": constant.ErrDB.ErrCode, "errMsg": LimitError.Error()})
return
}
if Limited {
c.JSON(http.StatusBadRequest, gin.H{"errCode": constant.RegisterLimit, "errMsg": "limited"})
return
}
}
openIMRegisterReq := api.UserRegisterReq{}
var account string
if params.Email != "" {
account = params.Email
openIMRegisterReq.Email = params.Email
} else if params.PhoneNumber != "" {
account = params.PhoneNumber
openIMRegisterReq.PhoneNumber = params.PhoneNumber
} else {
account = params.UserID
}
@ -84,7 +90,7 @@ func SetPassword(c *gin.Context) {
if config.Config.Demo.NeedInvitationCode && params.InvitationCode != "" {
err := imdb.CheckInvitationCode(params.InvitationCode)
if err != nil {
c.JSON(http.StatusOK, gin.H{"errCode": constant.InvitationError, "errMsg": "邀请码错误"})
c.JSON(http.StatusOK, gin.H{"errCode": constant.InvitationError, "errMsg": "InvitationCode error"})
return
}
}
@ -99,18 +105,13 @@ func SetPassword(c *gin.Context) {
} else {
userID = params.UserID
}
url := config.Config.Demo.ImAPIURL + "/auth/user_register"
openIMRegisterReq := api.UserRegisterReq{}
openIMRegisterReq.OperationID = params.OperationID
openIMRegisterReq.Platform = params.Platform
openIMRegisterReq.UserID = userID
openIMRegisterReq.Nickname = params.Nickname
openIMRegisterReq.Secret = config.Config.Secret
openIMRegisterReq.FaceURL = params.FaceURL
openIMRegisterReq.CreateIp = ip
openIMRegisterReq.LastLoginIp = ip
openIMRegisterReq.InvitationCode = params.InvitationCode
openIMRegisterResp := api.UserRegisterResp{}
log.NewDebug(params.OperationID, utils.GetSelfFuncName(), "register req:", openIMRegisterReq)
bMsg, err := http2.Post(url, openIMRegisterReq, 2)
@ -124,14 +125,10 @@ func SetPassword(c *gin.Context) {
log.NewError(params.OperationID, "request openIM register error", account, "err", "resp: ", openIMRegisterResp.ErrCode)
if err != nil {
log.NewError(params.OperationID, utils.GetSelfFuncName(), err.Error())
}
if openIMRegisterResp.ErrCode == constant.RegisterLimit {
c.JSON(http.StatusOK, gin.H{"errCode": constant.RegisterLimit, "errMsg": "用户注册被限制"})
return
} else if openIMRegisterResp.ErrCode == constant.InvitationError {
c.JSON(http.StatusOK, gin.H{"errCode": constant.InvitationError, "errMsg": "邀请码错误"})
c.JSON(http.StatusOK, gin.H{"errCode": constant.RegisterFailed, "errMsg": "register limit"})
return
} else {
}
if openIMRegisterResp.ErrCode != 0 {
c.JSON(http.StatusOK, gin.H{"errCode": constant.RegisterFailed, "errMsg": "register failed: " + openIMRegisterResp.ErrMsg})
return
}
@ -150,8 +147,11 @@ func SetPassword(c *gin.Context) {
imdb.FinishInvitationCode(params.InvitationCode, userID)
}
}
if err := imdb.InsertIpRecord(userID, ip); err != nil {
log.NewError(params.OperationID, utils.GetSelfFuncName(), userID, ip, err.Error())
}
log.Info(params.OperationID, "end setPassword", account, params.Password)
log.Info(params.OperationID, "end setuserInfo", account, params.Password)
// demo onboarding
if params.UserID == "" && config.Config.Demo.OnboardProcess {
select {
@ -168,6 +168,7 @@ func SetPassword(c *gin.Context) {
}
}
// register add friend
select {
case ChImportFriend <- &pbFriend.ImportFriendReq{
OperationID: params.OperationID,

@ -3,8 +3,8 @@ package admin_cms
import (
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/db"
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
openIMHttp "Open_IM/pkg/common/http"
"Open_IM/pkg/common/log"
"Open_IM/pkg/common/token_verify"
"Open_IM/pkg/grpc-etcdv3/getcdv3"
@ -12,11 +12,15 @@ import (
server_api_params "Open_IM/pkg/proto/sdk_ws"
"Open_IM/pkg/utils"
"context"
"errors"
"net"
"strconv"
"strings"
"sync"
"time"
"google.golang.org/grpc"
"gorm.io/gorm"
)
type adminCMSServer struct {
@ -81,23 +85,26 @@ func (s *adminCMSServer) Run() {
func (s *adminCMSServer) AdminLogin(_ context.Context, req *pbAdminCMS.AdminLoginReq) (*pbAdminCMS.AdminLoginResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
resp := &pbAdminCMS.AdminLoginResp{}
resp := &pbAdminCMS.AdminLoginResp{CommonResp: &pbAdminCMS.CommonResp{}}
for i, adminID := range config.Config.Manager.AppManagerUid {
if adminID == req.AdminID && config.Config.Manager.Secrets[i] == req.Secret {
token, expTime, err := token_verify.CreateToken(adminID, constant.SingleChatType)
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "generate token success", "token: ", token, "expTime:", expTime)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "generate token failed", "adminID: ", adminID, err.Error())
return resp, openIMHttp.WrapError(constant.ErrTokenUnknown)
resp.CommonResp.ErrCode = constant.ErrTokenUnknown.ErrCode
resp.CommonResp.ErrMsg = err.Error()
return resp, nil
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "generate token success", "token: ", token, "expTime:", expTime)
resp.Token = token
break
}
}
if resp.Token == "" {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "failed")
return resp, openIMHttp.WrapError(constant.ErrTokenMalformed)
resp.CommonResp.ErrCode = constant.ErrTokenUnknown.ErrCode
resp.CommonResp.ErrMsg = constant.ErrTokenMalformed.ErrMsg
return resp, nil
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
return resp, nil
@ -105,10 +112,12 @@ func (s *adminCMSServer) AdminLogin(_ context.Context, req *pbAdminCMS.AdminLogi
func (s *adminCMSServer) AddUserRegisterAddFriendIDList(_ context.Context, req *pbAdminCMS.AddUserRegisterAddFriendIDListReq) (*pbAdminCMS.AddUserRegisterAddFriendIDListResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
resp := &pbAdminCMS.AddUserRegisterAddFriendIDListResp{}
resp := &pbAdminCMS.AddUserRegisterAddFriendIDListResp{CommonResp: &pbAdminCMS.CommonResp{}}
if err := imdb.AddUserRegisterAddFriendIDList(req.UserIDList...); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.UserIDList)
return resp, openIMHttp.WrapError(constant.ErrDB)
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
resp.CommonResp.ErrMsg = err.Error()
return resp, nil
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", req.String())
return resp, nil
@ -116,16 +125,20 @@ func (s *adminCMSServer) AddUserRegisterAddFriendIDList(_ context.Context, req *
func (s *adminCMSServer) ReduceUserRegisterAddFriendIDList(_ context.Context, req *pbAdminCMS.ReduceUserRegisterAddFriendIDListReq) (*pbAdminCMS.ReduceUserRegisterAddFriendIDListResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
resp := &pbAdminCMS.ReduceUserRegisterAddFriendIDListResp{}
resp := &pbAdminCMS.ReduceUserRegisterAddFriendIDListResp{CommonResp: &pbAdminCMS.CommonResp{}}
if req.Operation == 0 {
if err := imdb.ReduceUserRegisterAddFriendIDList(req.UserIDList...); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.UserIDList)
return resp, openIMHttp.WrapError(constant.ErrDB)
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
resp.CommonResp.ErrMsg = err.Error()
return resp, nil
}
} else {
if err := imdb.DeleteAllRegisterAddFriendIDList(); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.UserIDList)
return resp, openIMHttp.WrapError(constant.ErrDB)
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
resp.CommonResp.ErrMsg = err.Error()
return resp, nil
}
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", req.String())
@ -134,16 +147,19 @@ func (s *adminCMSServer) ReduceUserRegisterAddFriendIDList(_ context.Context, re
func (s *adminCMSServer) GetUserRegisterAddFriendIDList(_ context.Context, req *pbAdminCMS.GetUserRegisterAddFriendIDListReq) (*pbAdminCMS.GetUserRegisterAddFriendIDListResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
resp := &pbAdminCMS.GetUserRegisterAddFriendIDListResp{UserInfoList: []*server_api_params.UserInfo{}}
resp := &pbAdminCMS.GetUserRegisterAddFriendIDListResp{CommonResp: &pbAdminCMS.CommonResp{}}
userIDList, err := imdb.GetRegisterAddFriendList(req.Pagination.ShowNumber, req.Pagination.PageNumber)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
return resp, openIMHttp.WrapError(constant.ErrDB)
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
resp.CommonResp.ErrMsg = err.Error()
return resp, nil
}
userList, err := imdb.GetUsersByUserIDList(userIDList)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), userIDList)
return resp, openIMHttp.WrapError(constant.ErrDB)
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
resp.CommonResp.ErrMsg = err.Error()
return resp, nil
}
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), userList, userIDList)
resp.Pagination = &server_api_params.ResponsePagination{
@ -154,3 +170,500 @@ func (s *adminCMSServer) GetUserRegisterAddFriendIDList(_ context.Context, req *
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", req.String())
return resp, nil
}
func (s *adminCMSServer) GetChatLogs(_ context.Context, req *pbAdminCMS.GetChatLogsReq) (*pbAdminCMS.GetChatLogsResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "GetChatLogs", req.String())
resp := &pbAdminCMS.GetChatLogsResp{CommonResp: &pbAdminCMS.CommonResp{}, Pagination: &server_api_params.ResponsePagination{}}
time, err := utils.TimeStringToTime(req.SendTime)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "time string parse error", err.Error())
resp.CommonResp.ErrCode = constant.ErrArgs.ErrCode
resp.CommonResp.ErrMsg = err.Error()
return resp, nil
}
chatLog := db.ChatLog{
Content: req.Content,
SendTime: time,
ContentType: req.ContentType,
SessionType: req.SessionType,
RecvID: req.RecvID,
SendID: req.SendID,
}
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "chat_log: ", chatLog)
nums, err := imdb.GetChatLogCount(chatLog)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetChatLogCount", err.Error())
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
resp.CommonResp.ErrMsg = err.Error()
return resp, nil
}
resp.ChatLogsNum = int32(nums)
chatLogs, err := imdb.GetChatLog(chatLog, req.Pagination.PageNumber, req.Pagination.ShowNumber)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetChatLog", err.Error())
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
resp.CommonResp.ErrMsg = err.Error()
return resp, nil
}
for _, chatLog := range chatLogs {
pbChatLog := &pbAdminCMS.ChatLog{}
utils.CopyStructFields(pbChatLog, chatLog)
pbChatLog.SendTime = chatLog.SendTime.Unix()
pbChatLog.CreateTime = chatLog.CreateTime.Unix()
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.SenderNickname = recvUser.Nickname
case constant.GroupChatType, constant.SuperGroupChatType:
group, err := imdb.GetGroupInfoByGroupID(chatLog.RecvID)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupById failed")
continue
}
pbChatLog.RecvID = group.GroupID
pbChatLog.GroupName = group.GroupName
}
resp.ChatLogs = append(resp.ChatLogs, pbChatLog)
}
resp.Pagination = &server_api_params.ResponsePagination{
CurrentPage: req.Pagination.PageNumber,
ShowNumber: req.Pagination.ShowNumber,
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp output: ", resp.String())
return resp, nil
}
func (s *adminCMSServer) GetActiveGroup(_ context.Context, req *pbAdminCMS.GetActiveGroupReq) (*pbAdminCMS.GetActiveGroupResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req", req.String())
resp := &pbAdminCMS.GetActiveGroupResp{CommonResp: &pbAdminCMS.CommonResp{}}
fromTime, toTime, err := ParseTimeFromTo(req.StatisticsReq.From, req.StatisticsReq.To)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "ParseTimeFromTo failed", err.Error())
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
resp.CommonResp.ErrMsg = err.Error()
return resp, nil
}
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())
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
resp.CommonResp.ErrMsg = err.Error()
return resp, nil
}
for _, activeGroup := range activeGroups {
resp.Groups = append(resp.Groups,
&pbAdminCMS.GroupResp{
GroupName: activeGroup.Name,
GroupId: activeGroup.Id,
MessageNum: int32(activeGroup.MessageNum),
})
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), resp.String())
return resp, nil
}
func (s *adminCMSServer) GetActiveUser(_ context.Context, req *pbAdminCMS.GetActiveUserReq) (*pbAdminCMS.GetActiveUserResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), req.String())
resp := &pbAdminCMS.GetActiveUserResp{CommonResp: &pbAdminCMS.CommonResp{}}
fromTime, toTime, err := ParseTimeFromTo(req.StatisticsReq.From, req.StatisticsReq.To)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "ParseTimeFromTo failed", err.Error())
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
resp.CommonResp.ErrMsg = err.Error()
return resp, nil
}
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())
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
resp.CommonResp.ErrMsg = err.Error()
return resp, nil
}
for _, activeUser := range activeUsers {
resp.Users = append(resp.Users,
&pbAdminCMS.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 *adminCMSServer) GetGroupStatistics(_ context.Context, req *pbAdminCMS.GetGroupStatisticsReq) (*pbAdminCMS.GetGroupStatisticsResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), req.String())
resp := &pbAdminCMS.GetGroupStatisticsResp{CommonResp: &pbAdminCMS.CommonResp{}}
fromTime, toTime, err := ParseTimeFromTo(req.StatisticsReq.From, req.StatisticsReq.To)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupStatistics failed", err.Error())
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
resp.CommonResp.ErrMsg = err.Error()
return resp, nil
}
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)
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
resp.CommonResp.ErrMsg = err.Error()
return resp, nil
}
totalGroupNum, err := imdb.GetTotalGroupNum()
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
resp.CommonResp.ErrMsg = err.Error()
return resp, nil
}
resp.IncreaseGroupNum = increaseGroupNum
resp.TotalGroupNum = totalGroupNum
times := GetRangeDate(fromTime, toTime)
log.NewDebug(req.OperationID, "times:", times)
wg := &sync.WaitGroup{}
resp.IncreaseGroupNumList = make([]*pbAdminCMS.DateNumList, len(times), len(times))
resp.TotalGroupNumList = make([]*pbAdminCMS.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] = &pbAdminCMS.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] = &pbAdminCMS.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 *adminCMSServer) GetMessageStatistics(_ context.Context, req *pbAdminCMS.GetMessageStatisticsReq) (*pbAdminCMS.GetMessageStatisticsResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), req.String())
resp := &pbAdminCMS.GetMessageStatisticsResp{CommonResp: &pbAdminCMS.CommonResp{}}
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())
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
resp.CommonResp.ErrMsg = err.Error()
return resp, nil
}
privateMessageNum, err := imdb.GetPrivateMessageNum(fromTime, toTime.Add(time.Hour*24))
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetPrivateMessageNum failed", err.Error())
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
resp.CommonResp.ErrMsg = err.Error()
return resp, nil
}
groupMessageNum, err := imdb.GetGroupMessageNum(fromTime, toTime.Add(time.Hour*24))
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupMessageNum failed", err.Error())
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
resp.CommonResp.ErrMsg = err.Error()
return resp, nil
}
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), privateMessageNum, groupMessageNum)
resp.PrivateMessageNum = privateMessageNum
resp.GroupMessageNum = groupMessageNum
times := GetRangeDate(fromTime, toTime)
resp.GroupMessageNumList = make([]*pbAdminCMS.DateNumList, len(times), len(times))
resp.PrivateMessageNumList = make([]*pbAdminCMS.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] = &pbAdminCMS.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] = &pbAdminCMS.DateNumList{
Date: v[0].String(),
Num: num,
}
}(wg, i, v)
}
wg.Wait()
return resp, nil
}
func (s *adminCMSServer) GetUserStatistics(_ context.Context, req *pbAdminCMS.GetUserStatisticsReq) (*pbAdminCMS.GetUserStatisticsResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
resp := &pbAdminCMS.GetUserStatisticsResp{CommonResp: &pbAdminCMS.CommonResp{}}
fromTime, toTime, err := ParseTimeFromTo(req.StatisticsReq.From, req.StatisticsReq.To)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "ParseTimeFromTo failed", err.Error())
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
resp.CommonResp.ErrMsg = err.Error()
return resp, nil
}
activeUserNum, err := imdb.GetActiveUserNum(fromTime, toTime.Add(time.Hour*24))
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetActiveUserNum failed", err.Error())
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
resp.CommonResp.ErrMsg = err.Error()
return resp, nil
}
increaseUserNum, err := imdb.GetIncreaseUserNum(fromTime, toTime.Add(time.Hour*24))
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetIncreaseUserNum failed", err.Error())
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
resp.CommonResp.ErrMsg = err.Error()
return resp, nil
}
totalUserNum, err := imdb.GetTotalUserNum()
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetTotalUserNum failed", err.Error())
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
resp.CommonResp.ErrMsg = err.Error()
return resp, nil
}
resp.ActiveUserNum = activeUserNum
resp.TotalUserNum = totalUserNum
resp.IncreaseUserNum = increaseUserNum
times := GetRangeDate(fromTime, toTime)
resp.TotalUserNumList = make([]*pbAdminCMS.DateNumList, len(times), len(times))
resp.ActiveUserNumList = make([]*pbAdminCMS.DateNumList, len(times), len(times))
resp.IncreaseUserNumList = make([]*pbAdminCMS.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] = &pbAdminCMS.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] = &pbAdminCMS.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] = &pbAdminCMS.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 *adminCMSServer) GetUserFriends(_ context.Context, req *pbAdminCMS.GetUserFriendsReq) (*pbAdminCMS.GetUserFriendsResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
resp := &pbAdminCMS.GetUserFriendsResp{CommonResp: &pbAdminCMS.CommonResp{}, Pagination: &server_api_params.ResponsePagination{CurrentPage: req.Pagination.PageNumber, ShowNumber: req.Pagination.ShowNumber}}
var friendList []*imdb.FriendUser
var err error
if req.FriendUserID != "" {
friend, err := imdb.GetFriendByIDCMS(req.UserID, req.FriendUserID)
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err, req.UserID, req.FriendUserID)
return resp, nil
}
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.UserID, req.FriendUserID)
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
resp.CommonResp.ErrMsg = err.Error()
return resp, nil
}
friendList = append(friendList, friend)
resp.FriendNums = 1
} else {
var count int64
friendList, count, err = imdb.GetUserFriendsCMS(req.UserID, req.FriendUserName, req.Pagination.PageNumber, req.Pagination.ShowNumber)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.UserID, req.FriendUserName, req.Pagination.PageNumber, req.Pagination.ShowNumber)
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
resp.CommonResp.ErrMsg = err.Error()
return resp, nil
}
resp.FriendNums = int32(count)
}
for _, v := range friendList {
friendInfo := &server_api_params.FriendInfo{}
userInfo := &server_api_params.UserInfo{UserID: v.FriendUserID, Nickname: v.Nickname}
utils.CopyStructFields(friendInfo, v)
friendInfo.FriendUser = userInfo
resp.FriendInfoList = append(resp.FriendInfoList, friendInfo)
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
return resp, nil
}
func (s *adminCMSServer) GenerateInvitationCode(_ context.Context, req *pbAdminCMS.GenerateInvitationCodeReq) (*pbAdminCMS.GenerateInvitationCodeResp, error) {
return nil, nil
}
func (s *adminCMSServer) GetInvitationCodes(_ context.Context, req *pbAdminCMS.GetInvitationCodesReq) (*pbAdminCMS.GetInvitationCodesResp, error) {
return nil, nil
}
func (s *adminCMSServer) QueryIPRegister(_ context.Context, req *pbAdminCMS.QueryIPRegisterReq) (*pbAdminCMS.QueryIPRegisterResp, error) {
return nil, nil
}
func (s *adminCMSServer) AddIPLimit(_ context.Context, req *pbAdminCMS.AddIPLimitReq) (*pbAdminCMS.AddIPLimitResp, error) {
return nil, nil
}
func (s *adminCMSServer) RemoveIPLimit(_ context.Context, req *pbAdminCMS.RemoveIPLimitReq) (*pbAdminCMS.RemoveIPLimitResp, error) {
return nil, nil
}
func (s *adminCMSServer) QueryUserIDIPLimitLogin(_ context.Context, req *pbAdminCMS.QueryUserIDIPLimitLoginReq) (*pbAdminCMS.QueryUserIDIPLimitLoginResp, error) {
return nil, nil
}
func (s *adminCMSServer) AddUserIPLimitLogin(_ context.Context, req *pbAdminCMS.AddUserIPLimitLoginReq) (*pbAdminCMS.AddUserIPLimitLoginResp, error) {
return nil, nil
}
func (s *adminCMSServer) RemoveUserIPLimit(_ context.Context, req *pbAdminCMS.RemoveUserIPLimitReq) (*pbAdminCMS.RemoveUserIPLimitResp, error) {
return nil, nil
}
func (s *adminCMSServer) GetClientInitConfig(_ context.Context, req *pbAdminCMS.GetClientInitConfigReq) (*pbAdminCMS.GetClientInitConfigResp, error) {
return nil, nil
}
func (s *adminCMSServer) SetClientInitConfig(_ context.Context, req *pbAdminCMS.SetClientInitConfigReq) (*pbAdminCMS.SetClientInitConfigResp, error) {
return nil, nil
}

@ -29,43 +29,24 @@ func (rpc *rpcAuth) UserRegister(_ context.Context, req *pbAuth.UserRegisterReq)
user.Birth = utils.UnixSecondToTime(int64(req.UserInfo.Birth))
}
log.Debug(req.OperationID, "copy ", user, req.UserInfo)
Limited, LimitError := imdb.IsLimitRegisterIp(req.UserInfo.CreateIp)
if LimitError != nil {
return &pbAuth.UserRegisterResp{CommonResp: &pbAuth.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: LimitError.Error()}}, nil
}
if Limited {
return &pbAuth.UserRegisterResp{CommonResp: &pbAuth.CommonResp{ErrCode: constant.RegisterLimit, ErrMsg: "Register Limit"}}, nil
}
err := imdb.UserRegister(user)
if err != nil {
if err == constant.InvitationMsg {
return &pbAuth.UserRegisterResp{CommonResp: &pbAuth.CommonResp{ErrCode: constant.InvitationError, ErrMsg: "邀请码错误"}}, nil
}
errMsg := req.OperationID + " imdb.UserRegister failed " + err.Error() + user.UserID
log.NewError(req.OperationID, errMsg, user)
return &pbAuth.UserRegisterResp{CommonResp: &pbAuth.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}}, nil
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc return ", pbAuth.UserRegisterResp{CommonResp: &pbAuth.CommonResp{}})
return &pbAuth.UserRegisterResp{CommonResp: &pbAuth.CommonResp{}}, nil
}
func (rpc *rpcAuth) UserToken(_ context.Context, req *pbAuth.UserTokenReq) (*pbAuth.UserTokenResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc args ", req.String())
_, err := imdb.GetUserByUserID(req.FromUserID)
if err != nil {
errMsg := req.OperationID + " imdb.GetUserByUserID failed " + err.Error() + req.FromUserID
log.NewError(req.OperationID, errMsg)
return &pbAuth.UserTokenResp{CommonResp: &pbAuth.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}}, nil
}
tokens, expTime, err := token_verify.CreateToken(req.FromUserID, int(req.Platform))
if err != nil {
errMsg := req.OperationID + " token_verify.CreateToken failed " + err.Error() + req.FromUserID + utils.Int32ToString(req.Platform)
log.NewError(req.OperationID, errMsg)
return &pbAuth.UserTokenResp{CommonResp: &pbAuth.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}}, nil
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc return ", pbAuth.UserTokenResp{CommonResp: &pbAuth.CommonResp{}, Token: tokens, ExpiredTime: expTime})
return &pbAuth.UserTokenResp{CommonResp: &pbAuth.CommonResp{}, Token: tokens, ExpiredTime: expTime}, nil
}

@ -6,8 +6,7 @@ import (
"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/db/rocks_cache"
"Open_IM/pkg/common/http"
rocksCache "Open_IM/pkg/common/db/rocks_cache"
"Open_IM/pkg/common/log"
"Open_IM/pkg/common/token_verify"
cp "Open_IM/pkg/common/utils"
@ -19,12 +18,15 @@ import (
pbUser "Open_IM/pkg/proto/user"
"Open_IM/pkg/utils"
"context"
"google.golang.org/grpc"
"errors"
"math/big"
"net"
"strconv"
"strings"
"time"
"google.golang.org/grpc"
"gorm.io/gorm"
)
type groupServer struct {
@ -121,7 +123,7 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR
err := imdb.InsertIntoGroup(groupInfo)
if err != nil {
log.NewError(req.OperationID, "InsertIntoGroup failed, ", err.Error(), groupInfo)
return &pbGroup.CreateGroupResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, http.WrapError(constant.ErrDB)
return &pbGroup.CreateGroupResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil
}
var okUserIDList []string
resp := &pbGroup.CreateGroupResp{GroupInfo: &open_im_sdk.GroupInfo{}}
@ -131,7 +133,7 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR
us, err = imdb.GetUserByUserID(req.OwnerUserID)
if err != nil {
log.NewError(req.OperationID, "GetUserByUserID failed ", err.Error(), req.OwnerUserID)
return &pbGroup.CreateGroupResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, http.WrapError(constant.ErrDB)
return &pbGroup.CreateGroupResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil
}
//to group member
groupMember = db.GroupMember{GroupID: groupId, RoleLevel: constant.GroupOwner, OperatorUserID: req.OpUserID, JoinSource: constant.JoinByInvitation, InviterUserID: req.OpUserID}
@ -139,7 +141,7 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR
err = imdb.InsertIntoGroupMember(groupMember)
if err != nil {
log.NewError(req.OperationID, "InsertIntoGroupMember failed ", err.Error(), groupMember)
return &pbGroup.CreateGroupResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, http.WrapError(constant.ErrDB)
return &pbGroup.CreateGroupResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil
}
}
@ -316,7 +318,7 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite
resp.Id2ResultList = append(resp.Id2ResultList, &resultNode)
continue
log.NewError(req.OperationID, "InsertIntoGroupRequest failed ", err.Error(), groupRequest)
// log.NewError(req.OperationID, "InsertIntoGroupRequest failed ", err.Error(), groupRequest)
// return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
} else {
var resultNode pbGroup.Id2Result
@ -827,7 +829,6 @@ func (s *groupServer) GetGroupsInfo(ctx context.Context, req *pbGroup.GetGroupsI
func (s *groupServer) GroupApplicationResponse(_ context.Context, req *pbGroup.GroupApplicationResponseReq) (*pbGroup.GroupApplicationResponseResp, error) {
log.NewInfo(req.OperationID, "GroupApplicationResponse args ", req.String())
groupRequest := db.GroupRequest{}
utils.CopyStructFields(&groupRequest, req)
groupRequest.UserID = req.FromUserID
@ -1162,7 +1163,7 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInf
group, err := imdb.GetGroupInfoByGroupID(req.GroupInfoForSet.GroupID)
if err != nil {
log.NewError(req.OperationID, "GetGroupInfoByGroupID failed ", err.Error(), req.GroupInfoForSet.GroupID)
return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, http.WrapError(constant.ErrDB)
return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil
}
if group.Status == constant.GroupStatusDismissed {
@ -1199,7 +1200,7 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInf
m["need_verification"] = req.GroupInfoForSet.NeedVerification.Value
if err := imdb.UpdateGroupInfoDefaultZero(req.GroupInfoForSet.GroupID, m); err != nil {
log.NewError(req.OperationID, "UpdateGroupInfoDefaultZero failed ", err.Error(), m)
return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, http.WrapError(constant.ErrDB)
return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
}
}
if req.GroupInfoForSet.LookMemberInfo != nil {
@ -1208,7 +1209,7 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInf
m["look_member_info"] = req.GroupInfoForSet.LookMemberInfo.Value
if err := imdb.UpdateGroupInfoDefaultZero(req.GroupInfoForSet.GroupID, m); err != nil {
log.NewError(req.OperationID, "UpdateGroupInfoDefaultZero failed ", err.Error(), m)
return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, http.WrapError(constant.ErrDB)
return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
}
}
if req.GroupInfoForSet.ApplyMemberFriend != nil {
@ -1217,7 +1218,7 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInf
m["apply_member_friend"] = req.GroupInfoForSet.ApplyMemberFriend.Value
if err := imdb.UpdateGroupInfoDefaultZero(req.GroupInfoForSet.GroupID, m); err != nil {
log.NewError(req.OperationID, "UpdateGroupInfoDefaultZero failed ", err.Error(), m)
return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, http.WrapError(constant.ErrDB)
return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
}
}
//
@ -1234,11 +1235,11 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInf
err = imdb.SetGroupInfo(groupInfo)
if err != nil {
log.NewError(req.OperationID, "SetGroupInfo failed ", err.Error(), groupInfo)
return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, http.WrapError(constant.ErrDB)
return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
}
if err := rocksCache.DelGroupInfoFromCache(req.GroupInfoForSet.GroupID); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "DelGroupInfoFromCache failed ", err.Error(), req.GroupInfoForSet.GroupID)
return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, http.WrapError(constant.ErrDB)
return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
}
log.NewInfo(req.OperationID, "SetGroupInfo rpc return ", pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{}})
@ -1252,7 +1253,7 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInf
if etcdConn == nil {
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
log.NewError(req.OperationID, errMsg)
return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrInternal.ErrCode, ErrMsg: errMsg}}, http.WrapError(constant.ErrInternal)
return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrInternal.ErrCode, ErrMsg: errMsg}}, nil
}
client := pbCache.NewCacheClient(etcdConn)
cacheResp, err := client.GetGroupMemberIDListFromCache(context.Background(), getGroupMemberIDListFromCacheReq)
@ -1281,7 +1282,7 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInf
if etcdConn == nil {
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
log.NewError(req.OperationID, errMsg)
return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrInternal.ErrCode, ErrMsg: errMsg}}, http.WrapError(constant.ErrInternal)
return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrInternal.ErrCode, ErrMsg: errMsg}}, nil
}
nClient := pbConversation.NewConversationClient(nEtcdConn)
conversationReply, err := nClient.ModifyConversationField(context.Background(), &conversationReq)
@ -1336,154 +1337,81 @@ func (s *groupServer) TransferGroupOwner(_ context.Context, req *pbGroup.Transfe
}
func (s *groupServer) GetGroupByID(_ context.Context, req *pbGroup.GetGroupByIDReq) (*pbGroup.GetGroupByIDResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
resp := &pbGroup.GetGroupByIDResp{CMSGroup: &pbGroup.CMSGroup{
GroupInfo: &open_im_sdk.GroupInfo{},
}}
group, err := imdb.GetGroupInfoByGroupID(req.GroupID)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupById error", err.Error())
return resp, http.WrapError(constant.ErrDB)
}
utils.CopyStructFields(resp.CMSGroup.GroupInfo, group)
groupMember, err := imdb.GetGroupOwnerInfoByGroupID(group.GroupID)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupMaster", err.Error())
return resp, http.WrapError(constant.ErrDB)
}
groupMemberNum, err := imdb.GetGroupMemberNumByGroupID(req.GroupID)
if err == nil {
resp.CMSGroup.GroupInfo.MemberCount = uint32(groupMemberNum)
} else {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
}
resp.CMSGroup.GroupOwnerUserName = groupMember.Nickname
resp.CMSGroup.GroupOwnerUserID = groupMember.UserID
resp.CMSGroup.GroupInfo.CreatorUserID = group.CreatorUserID
resp.CMSGroup.GroupInfo.CreateTime = uint32(group.CreateTime.Unix())
utils.CopyStructFields(resp.CMSGroup.GroupInfo, group)
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
return resp, nil
}
func (s *groupServer) GetGroup(_ context.Context, req *pbGroup.GetGroupReq) (*pbGroup.GetGroupResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
resp := &pbGroup.GetGroupResp{
CMSGroups: []*pbGroup.CMSGroup{},
}
groups, err := imdb.GetGroupsByName(req.GroupName, req.Pagination.PageNumber, req.Pagination.ShowNumber)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupsByName error", req.String(), req.GroupName, req.Pagination.PageNumber, req.Pagination.ShowNumber)
return resp, http.WrapError(constant.ErrDB)
}
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "groups", groups)
nums, err := imdb.GetGroupsCountNum(db.Group{GroupName: req.GroupName})
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupsCountNum error", err.Error(), req.GroupName)
return resp, http.WrapError(constant.ErrDB)
}
resp.GroupNums = nums
resp.Pagination = &open_im_sdk.RequestPagination{
PageNumber: req.Pagination.PageNumber,
ShowNumber: req.Pagination.ShowNumber,
}
for _, v := range groups {
group := &pbGroup.CMSGroup{GroupInfo: &open_im_sdk.GroupInfo{}}
utils.CopyStructFields(group.GroupInfo, v)
groupMember, err := imdb.GetGroupOwnerInfoByGroupID(v.GroupID)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupMaster error", err.Error())
continue
}
group.GroupInfo.CreateTime = uint32(v.CreateTime.Unix())
group.GroupOwnerUserID = groupMember.UserID
group.GroupOwnerUserName = groupMember.Nickname
resp.CMSGroups = append(resp.CMSGroups, group)
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
return resp, nil
}
func (s *groupServer) GetGroups(_ context.Context, req *pbGroup.GetGroupsReq) (*pbGroup.GetGroupsResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "GetGroups ", req.String())
resp := &pbGroup.GetGroupsResp{
CommonResp: &pbGroup.CommonResp{},
CMSGroups: []*pbGroup.CMSGroup{},
Pagination: &open_im_sdk.RequestPagination{},
Pagination: &open_im_sdk.ResponsePagination{CurrentPage: req.Pagination.PageNumber, ShowNumber: req.Pagination.ShowNumber},
}
groups, err := imdb.GetGroups(int(req.Pagination.PageNumber), int(req.Pagination.ShowNumber))
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroups error", err.Error())
return resp, http.WrapError(constant.ErrDB)
}
resp.GroupNum, err = imdb.GetGroupsCountNum(db.Group{})
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupsCountNum error", err.Error())
return resp, http.WrapError(constant.ErrDB)
}
resp.Pagination.PageNumber = req.Pagination.PageNumber
resp.Pagination.ShowNumber = req.Pagination.ShowNumber
for _, v := range groups {
group := &pbGroup.CMSGroup{GroupInfo: &open_im_sdk.GroupInfo{}}
utils.CopyStructFields(group.GroupInfo, v)
groupMember, err := imdb.GetGroupOwnerInfoByGroupID(v.GroupID)
if req.GroupID != "" {
groupInfoDB, err := imdb.GetGroupInfoByGroupID(req.GroupID)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupMaster failed", err.Error(), v)
continue
if errors.Is(err, gorm.ErrRecordNotFound) {
return resp, nil
}
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
resp.CommonResp.ErrMsg = err.Error()
return resp, nil
}
group.GroupInfo.CreateTime = uint32(v.CreateTime.Unix())
group.GroupOwnerUserID = groupMember.UserID
group.GroupOwnerUserName = groupMember.Nickname
resp.CMSGroups = append(resp.CMSGroups, group)
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "GetGroups ", resp.String())
return resp, nil
}
func (s *groupServer) OperateUserRole(_ context.Context, req *pbGroup.OperateUserRoleReq) (*pbGroup.OperateUserRoleResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "args:", req.String())
resp := &pbGroup.OperateUserRoleResp{}
oldOwnerUserID, err := imdb.GetGroupOwnerInfoByGroupID(req.GroupID)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupMaster failed", err.Error())
return resp, http.WrapError(constant.ErrDB)
}
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName, req.OperationID)
if etcdConn == nil {
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
log.NewError(req.OperationID, errMsg)
return resp, http.WrapError(constant.ErrInternal)
}
client := pbGroup.NewGroupClient(etcdConn)
var reqPb pbGroup.TransferGroupOwnerReq
reqPb.OperationID = req.OperationID
reqPb.NewOwnerUserID = req.UserID
reqPb.GroupID = req.GroupID
reqPb.OpUserID = "cms admin"
reqPb.OldOwnerUserID = oldOwnerUserID.UserID
reply, err := client.TransferGroupOwner(context.Background(), &reqPb)
if reply.CommonResp.ErrCode != 0 || err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "TransferGroupOwner rpc failed")
resp.GroupNum = 1
groupInfo := &open_im_sdk.GroupInfo{}
utils.CopyStructFields(groupInfo, groupInfoDB)
groupMember, err := imdb.GetGroupOwnerInfoByGroupID(req.GroupID)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
resp.CommonResp.ErrMsg = err.Error()
return resp, nil
}
resp.CMSGroups = append(resp.CMSGroups, &pbGroup.CMSGroup{GroupInfo: groupInfo, GroupOwnerUserName: groupMember.Nickname, GroupOwnerUserID: groupMember.UserID})
} else {
groups, err := imdb.GetGroupsByName(req.GroupName, req.Pagination.PageNumber, req.Pagination.ShowNumber)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupsByName error", req.String(), req.GroupName, req.Pagination.PageNumber, req.Pagination.ShowNumber)
}
for _, v := range groups {
group := &pbGroup.CMSGroup{GroupInfo: &open_im_sdk.GroupInfo{}}
utils.CopyStructFields(group.GroupInfo, v)
groupMember, err := imdb.GetGroupOwnerInfoByGroupID(v.GroupID)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupOwnerInfoByGroupID failed", err.Error(), v)
continue
}
group.GroupInfo.CreateTime = uint32(v.CreateTime.Unix())
group.GroupOwnerUserID = groupMember.UserID
group.GroupOwnerUserName = groupMember.Nickname
resp.CMSGroups = append(resp.CMSGroups, group)
}
resp.GroupNum, err = imdb.GetGroupsCountNum(db.Group{GroupName: req.GroupName})
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupsCountNum error", err.Error())
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
resp.CommonResp.ErrMsg = err.Error()
return resp, nil
}
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "GetGroups resp", resp.String())
return resp, nil
}
func (s *groupServer) GetGroupMembersCMS(_ context.Context, req *pbGroup.GetGroupMembersCMSReq) (*pbGroup.GetGroupMembersCMSResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "args:", req.String())
resp := &pbGroup.GetGroupMembersCMSResp{}
resp := &pbGroup.GetGroupMembersCMSResp{CommonResp: &pbGroup.CommonResp{}}
groupMembers, err := imdb.GetGroupMembersByGroupIdCMS(req.GroupID, req.UserName, req.Pagination.ShowNumber, req.Pagination.PageNumber)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupMembersByGroupIdCMS Error", err.Error())
return resp, http.WrapError(constant.ErrDB)
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
resp.CommonResp.ErrMsg = err.Error()
return resp, nil
}
groupMembersCount, err := imdb.GetGroupMembersCount(req.GroupID, req.UserName)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupMembersCMS Error", err.Error())
return resp, http.WrapError(constant.ErrDB)
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
resp.CommonResp.ErrMsg = err.Error()
return resp, nil
}
log.NewInfo(req.OperationID, groupMembersCount)
resp.MemberNums = int32(groupMembersCount)
@ -1502,151 +1430,6 @@ func (s *groupServer) GetGroupMembersCMS(_ context.Context, req *pbGroup.GetGrou
return resp, nil
}
func (s *groupServer) RemoveGroupMembersCMS(_ context.Context, req *pbGroup.RemoveGroupMembersCMSReq) (*pbGroup.RemoveGroupMembersCMSResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "args:", req.String())
resp := &pbGroup.RemoveGroupMembersCMSResp{}
for _, userId := range req.UserIDList {
err := imdb.DeleteGroupMemberByGroupIDAndUserID(req.GroupID, userId)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
resp.Failed = append(resp.Failed, userId)
} else {
resp.Success = append(resp.Success, userId)
}
}
reqKick := &pbGroup.KickGroupMemberReq{
GroupID: req.GroupID,
KickedUserIDList: resp.Success,
Reason: "admin kick",
OperationID: req.OperationID,
OpUserID: req.OpUserID,
}
var reqPb pbUser.SetConversationReq
var c pbConversation.Conversation
for _, v := range resp.Success {
reqPb.OperationID = req.OperationID
c.OwnerUserID = v
c.ConversationID = utils.GetConversationIDBySessionType(req.GroupID, constant.GroupChatType)
c.ConversationType = constant.GroupChatType
c.GroupID = req.GroupID
c.IsNotInGroup = true
reqPb.Conversation = &c
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName, req.OperationID)
if etcdConn == nil {
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
log.NewError(req.OperationID, errMsg)
return resp, http.WrapError(constant.ErrInternal)
}
client := pbUser.NewUserClient(etcdConn)
respPb, err := client.SetConversation(context.Background(), &reqPb)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "SetConversation rpc failed, ", reqPb.String(), err.Error(), v)
} else {
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "SetConversation success", respPb.String(), v)
}
}
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.OperationID)
if etcdConn == nil {
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
log.NewError(req.OperationID, errMsg)
return resp, http.WrapError(constant.ErrDB)
}
cacheClient := pbCache.NewCacheClient(etcdConn)
cacheResp, err := cacheClient.DelGroupMemberIDListFromCache(context.Background(), &pbCache.DelGroupMemberIDListFromCacheReq{
GroupID: req.GroupID,
OperationID: req.OperationID,
})
if err != nil {
log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc call failed ", err.Error())
return resp, http.WrapError(constant.ErrDB)
}
if cacheResp.CommonResp.ErrCode != 0 {
log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc logic call failed ", cacheResp.String())
return resp, http.WrapError(constant.ErrDB)
}
if err := rocksCache.DelGroupMemberListHashFromCache(req.GroupID); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
}
if err := rocksCache.DelGroupMemberNumFromCache(req.GroupID); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
}
for _, userID := range resp.Success {
if err := rocksCache.DelGroupMemberInfoFromCache(req.GroupID, userID); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID, userID)
}
}
chat.MemberKickedNotification(reqKick, resp.Success)
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
return resp, nil
}
func (s *groupServer) AddGroupMembersCMS(_ context.Context, req *pbGroup.AddGroupMembersCMSReq) (*pbGroup.AddGroupMembersCMSResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "args:", req.String())
resp := &pbGroup.AddGroupMembersCMSResp{}
for _, userId := range req.UserIDList {
if isExist := imdb.IsExistGroupMember(req.GroupID, userId); isExist {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "user is exist in group", userId, req.GroupID)
resp.Failed = append(resp.Failed, userId)
continue
}
user, err := imdb.GetUserByUserID(userId)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserByUserID", err.Error())
resp.Failed = append(resp.Failed, userId)
continue
}
groupMember := db.GroupMember{
GroupID: req.GroupID,
UserID: userId,
Nickname: user.Nickname,
FaceURL: "",
RoleLevel: 1,
JoinTime: time.Time{},
JoinSource: constant.JoinByAdmin,
OperatorUserID: "CmsAdmin",
Ex: "",
}
if err := imdb.InsertIntoGroupMember(groupMember); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "InsertIntoGroupMember failed", req.String())
resp.Failed = append(resp.Failed, userId)
} else {
resp.Success = append(resp.Success, userId)
}
}
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.OperationID)
if etcdConn == nil {
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
log.NewError(req.OperationID, errMsg)
return resp, http.WrapError(constant.ErrDB)
}
cacheClient := pbCache.NewCacheClient(etcdConn)
cacheResp, err := cacheClient.DelGroupMemberIDListFromCache(context.Background(), &pbCache.DelGroupMemberIDListFromCacheReq{
GroupID: req.GroupID,
OperationID: req.OperationID,
})
if err != nil {
log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc call failed ", err.Error())
return resp, http.WrapError(constant.ErrDB)
}
if cacheResp.CommonResp.ErrCode != 0 {
log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc logic call failed ", cacheResp.String())
return resp, http.WrapError(constant.ErrDB)
}
if err := rocksCache.DelGroupMemberListHashFromCache(req.GroupID); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
}
if err := rocksCache.DelGroupMemberNumFromCache(req.GroupID); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
}
chat.MemberInvitedNotification(req.OperationID, req.GroupID, req.OpUserID, "admin add you to group", resp.Success)
return resp, nil
}
func (s *groupServer) GetUserReqApplicationList(_ context.Context, req *pbGroup.GetUserReqApplicationListReq) (*pbGroup.GetUserReqApplicationListResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
resp := &pbGroup.GetUserReqApplicationListResp{}

@ -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
}

@ -7,7 +7,6 @@ import (
"Open_IM/pkg/common/db"
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
rocksCache "Open_IM/pkg/common/db/rocks_cache"
errors "Open_IM/pkg/common/http"
"Open_IM/pkg/common/log"
"Open_IM/pkg/common/token_verify"
"Open_IM/pkg/grpc-etcdv3/getcdv3"
@ -17,12 +16,13 @@ import (
pbUser "Open_IM/pkg/proto/user"
"Open_IM/pkg/utils"
"context"
"errors"
"net"
"strconv"
"strings"
"time"
"google.golang.org/grpc"
"gorm.io/gorm"
)
type userServer struct {
@ -335,27 +335,6 @@ func (s *userServer) SetRecvMsgOpt(ctx context.Context, req *pbUser.SetRecvMsgOp
return resp, nil
}
func (s *userServer) DeleteUsers(_ context.Context, req *pbUser.DeleteUsersReq) (*pbUser.DeleteUsersResp, error) {
log.NewInfo(req.OperationID, "DeleteUsers args ", req.String())
if !token_verify.IsManagerUserID(req.OpUserID) {
log.NewError(req.OperationID, "IsManagerUserID false ", req.OpUserID)
return &pbUser.DeleteUsersResp{CommonResp: &pbUser.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, FailedUserIDList: req.DeleteUserIDList}, nil
}
var common pbUser.CommonResp
resp := pbUser.DeleteUsersResp{CommonResp: &common}
for _, userID := range req.DeleteUserIDList {
i := imdb.DeleteUser(userID)
if i == 0 {
log.NewError(req.OperationID, "delete user error", userID)
common.ErrCode = 201
common.ErrMsg = "some uid deleted failed"
resp.FailedUserIDList = append(resp.FailedUserIDList, userID)
}
}
log.NewInfo(req.OperationID, "DeleteUsers rpc return ", resp.String())
return &resp, nil
}
func (s *userServer) GetAllUserID(_ context.Context, req *pbUser.GetAllUserIDReq) (*pbUser.GetAllUserIDResp, error) {
log.NewInfo(req.OperationID, "GetAllUserID args ", req.String())
if !token_verify.IsManagerUserID(req.OpUserID) {
@ -543,270 +522,180 @@ func (s *userServer) SyncJoinedGroupMemberNickname(userID string, newNickname, o
}
}
func (s *userServer) GetUsersByName(ctx context.Context, req *pbUser.GetUsersByNameReq) (*pbUser.GetUsersByNameResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req:", req.String())
resp := &pbUser.GetUsersByNameResp{}
users, err := imdb.GetUserByName(req.UserName, req.Pagination.ShowNumber, req.Pagination.PageNumber)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserByName failed", err.Error())
return resp, errors.WrapError(constant.ErrDB)
}
for _, user := range users {
isBlock, err := imdb.UserIsBlock(user.UserID)
func (s *userServer) GetUsers(ctx context.Context, req *pbUser.GetUsersReq) (*pbUser.GetUsersResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
resp := &pbUser.GetUsersResp{CommonResp: &pbUser.CommonResp{}, Pagination: &sdkws.ResponsePagination{CurrentPage: req.Pagination.PageNumber, ShowNumber: req.Pagination.ShowNumber}}
if req.UserID != "" {
userDB, err := imdb.GetUserByUserID(req.UserID)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
continue
if errors.Is(err, gorm.ErrRecordNotFound) {
return resp, nil
}
log.NewError(req.OperationID, utils.GetSelfFuncName(), req.UserID, err.Error())
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
resp.CommonResp.ErrMsg = constant.ErrDB.ErrMsg
return resp, nil
}
resp.Users = append(resp.Users, &pbUser.User{
ProfilePhoto: user.FaceURL,
Nickname: user.Nickname,
UserId: user.UserID,
CreateTime: user.CreateTime.Format("2006-01-02 15:04:05"),
CreateIp: user.CreateIp,
IsBlock: isBlock,
Birth: user.Birth.Format("2006-01-02"),
PhoneNumber: user.PhoneNumber,
Email: user.Email,
LastLoginIp: user.LastLoginIp,
LastLoginTime: user.LastLoginTime.Format("2006-01-02 15:04:05"),
LoginTimes: user.LoginTimes,
Gender: user.Gender,
LoginLimit: user.LoginLimit,
})
}
user := db.User{Nickname: req.UserName}
userNums, err := imdb.GetUsersCount(user)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "", err.Error())
return resp, errors.WrapError(constant.ErrDB)
}
resp.UserNums = userNums
resp.Pagination = &sdkws.ResponsePagination{
CurrentPage: req.Pagination.PageNumber,
ShowNumber: req.Pagination.ShowNumber,
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
return resp, nil
}
func (s *userServer) GetUserById(ctx context.Context, req *pbUser.GetUserByIdReq) (*pbUser.GetUserByIdResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req:", req.String())
resp := &pbUser.GetUserByIdResp{User: &pbUser.User{}}
user, err := imdb.GetUserByUserID(req.UserId)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
return resp, errors.WrapError(constant.ErrDB)
user := pbUser.CmsUser{User: &sdkws.UserInfo{}}
utils.CopyStructFields(&user.User, userDB)
user.User.CreateTime = uint32(userDB.CreateTime.Unix())
resp.UserList = append(resp.UserList, &user)
resp.TotalNums = 1
} else if req.UserName != "" {
usersDB, err := imdb.GetUserByName(req.UserName, req.Pagination.ShowNumber, req.Pagination.PageNumber)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), req.UserName, req.Pagination.ShowNumber, req.Pagination.PageNumber, err.Error())
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
resp.CommonResp.ErrMsg = constant.ErrDB.ErrMsg
return resp, nil
}
resp.TotalNums, err = imdb.GetUsersCount(req.UserName)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), req.UserName, err.Error())
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
resp.CommonResp.ErrMsg = err.Error()
return resp, nil
}
for _, userDB := range usersDB {
var user sdkws.UserInfo
utils.CopyStructFields(&user, userDB)
user.CreateTime = uint32(userDB.CreateTime.Unix())
resp.UserList = append(resp.UserList, &pbUser.CmsUser{User: &user})
}
} else {
usersDB, err := imdb.GetUsers(req.Pagination.ShowNumber, req.Pagination.PageNumber)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUsers failed", req.Pagination.ShowNumber, req.Pagination.PageNumber, err.Error())
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
resp.CommonResp.ErrMsg = err.Error()
return resp, nil
}
resp.TotalNums, err = imdb.GetTotalUserNum()
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
resp.CommonResp.ErrMsg = err.Error()
return resp, nil
}
for _, userDB := range usersDB {
var user sdkws.UserInfo
utils.CopyStructFields(&user, userDB)
user.CreateTime = uint32(userDB.CreateTime.Unix())
resp.UserList = append(resp.UserList, &pbUser.CmsUser{User: &user})
}
}
isBlock, err := imdb.UserIsBlock(req.UserId)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "req", req.String())
return resp, errors.WrapError(constant.ErrDB)
}
resp.User = &pbUser.User{
ProfilePhoto: user.FaceURL,
Nickname: user.Nickname,
UserId: user.UserID,
CreateTime: user.CreateTime.Format("2006-01-02 15:04:05"),
CreateIp: user.CreateIp,
IsBlock: isBlock,
Birth: user.Birth.Format("2006-01-02"),
PhoneNumber: user.PhoneNumber,
Email: user.Email,
LastLoginIp: user.LastLoginIp,
LastLoginTime: user.LastLoginTime.Format("2006-01-02 15:04:05"),
LoginTimes: user.LoginTimes,
Gender: user.Gender,
LoginLimit: user.LoginLimit,
var userIDList []string
for _, v := range resp.UserList {
userIDList = append(userIDList, v.User.UserID)
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
return resp, nil
}
func (s *userServer) GetUsers(ctx context.Context, req *pbUser.GetUsersReq) (*pbUser.GetUsersResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
resp := &pbUser.GetUsersResp{User: []*pbUser.User{}}
users, err := imdb.GetUsers(req.Pagination.ShowNumber, req.Pagination.PageNumber)
isBlockUser, err := imdb.UsersIsBlock(userIDList)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUsers failed", err.Error())
return resp, errors.WrapError(constant.ErrDB)
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), userIDList)
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
resp.CommonResp.ErrMsg = err.Error()
return resp, nil
}
for _, v := range users {
isBlock, err := imdb.UserIsBlock(v.UserID)
if err == nil {
registerIP := ""
registerInfo, err := imdb.GetRegisterInfo(v.UserID)
if registerInfo != nil && err == nil {
registerIP = registerInfo.RegisterIP
}
user := &pbUser.User{
ProfilePhoto: v.FaceURL,
UserId: v.UserID,
CreateTime: v.CreateTime.Format("2006-01-02 15:04:05"),
CreateIp: v.CreateIp,
Nickname: v.Nickname,
Birth: v.Birth.Format("2006-01-02"),
PhoneNumber: v.PhoneNumber,
Email: v.Email,
IsBlock: isBlock,
LastLoginIp: v.LastLoginIp,
LastLoginTime: v.LastLoginTime.Format("2006-01-02 15:04:05"),
LoginTimes: v.LoginTimes,
Gender: v.Gender,
LoginLimit: v.LoginLimit,
RegisterIp: registerIP,
}
resp.User = append(resp.User, user)
} else {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "UserIsBlock failed", err.Error())
for _, v := range resp.UserList {
if utils.IsContain(v.User.UserID, isBlockUser) {
v.IsBlock = true
}
}
user := db.User{}
nums, err := imdb.GetUsersCount(user)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUsersCount failed", err.Error(), user)
return resp, errors.WrapError(constant.ErrDB)
}
resp.UserNums = nums
resp.Pagination = &sdkws.ResponsePagination{ShowNumber: req.Pagination.ShowNumber, CurrentPage: req.Pagination.PageNumber}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
return resp, nil
}
func (s *userServer) ResignUser(ctx context.Context, req *pbUser.ResignUserReq) (*pbUser.ResignUserResp, error) {
log.NewInfo(req.OperationID, "ResignUser args ", req.String())
return &pbUser.ResignUserResp{}, nil
}
func (s *userServer) AlterUser(ctx context.Context, req *pbUser.AlterUserReq) (*pbUser.AlterUserResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
resp := &pbUser.AlterUserResp{}
birth, _ := time.ParseInLocation("2006-01-02", req.Birth, time.Local)
gender, gendererr := strconv.Atoi(req.Gender)
if gendererr != nil {
gender = 0
}
user := db.User{
PhoneNumber: req.PhoneNumber,
Nickname: req.Nickname,
Email: req.Email,
UserID: req.UserId,
Gender: int32(gender),
FaceURL: req.Photo,
Birth: birth,
}
if err := imdb.UpdateUserInfo(user); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "UpdateUserInfo", err.Error())
return resp, errors.WrapError(constant.ErrDB)
}
chat.UserInfoUpdatedNotification(req.OperationID, req.UserId, req.OpUserId)
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
return resp, nil
}
func (s *userServer) AddUser(ctx context.Context, req *pbUser.AddUserReq) (*pbUser.AddUserResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
resp := &pbUser.AddUserResp{}
err := imdb.AddUser(req.UserId, req.PhoneNumber, req.Name, req.Email, req.Gender, req.Photo, req.Birth)
resp := &pbUser.AddUserResp{CommonResp: &pbUser.CommonResp{}}
err := imdb.AddUser(req.UserInfo.UserID, req.UserInfo.PhoneNumber, req.UserInfo.Nickname, req.UserInfo.Email, req.UserInfo.Gender, req.UserInfo.FaceURL, req.UserInfo.Birth)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "AddUser", err.Error())
return resp, errors.WrapError(constant.ErrDB)
log.NewError(req.OperationID, utils.GetSelfFuncName(), "AddUser", err.Error(), req.String())
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
resp.CommonResp.ErrMsg = err.Error()
return resp, nil
}
return resp, nil
}
func (s *userServer) BlockUser(ctx context.Context, req *pbUser.BlockUserReq) (*pbUser.BlockUserResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
resp := &pbUser.BlockUserResp{}
err := imdb.BlockUser(req.UserId, req.EndDisableTime)
resp := &pbUser.BlockUserResp{CommonResp: &pbUser.CommonResp{}}
err := imdb.BlockUser(req.UserID, req.EndDisableTime)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "BlockUser", err.Error())
return resp, errors.WrapError(constant.ErrDB)
log.NewError(req.OperationID, utils.GetSelfFuncName(), "BlockUser", err.Error(), req.UserID, req.EndDisableTime)
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
resp.CommonResp.ErrMsg = err.Error()
return resp, nil
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
return resp, nil
}
func (s *userServer) UnBlockUser(ctx context.Context, req *pbUser.UnBlockUserReq) (*pbUser.UnBlockUserResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
resp := &pbUser.UnBlockUserResp{}
err := imdb.UnBlockUser(req.UserId)
resp := &pbUser.UnBlockUserResp{CommonResp: &pbUser.CommonResp{}}
err := imdb.UnBlockUser(req.UserID)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "unBlockUser", err.Error())
return resp, errors.WrapError(constant.ErrDB)
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
resp.CommonResp.ErrMsg = err.Error()
return resp, nil
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
return resp, nil
}
func (s *userServer) GetBlockUsers(ctx context.Context, req *pbUser.GetBlockUsersReq) (*pbUser.GetBlockUsersResp, error) {
func (s *userServer) GetBlockUsers(ctx context.Context, req *pbUser.GetBlockUsersReq) (resp *pbUser.GetBlockUsersResp, err error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
resp := &pbUser.GetBlockUsersResp{}
blockUsers, err := imdb.GetBlockUsers(req.Pagination.ShowNumber, req.Pagination.PageNumber)
if err != nil {
log.Error(req.OperationID, utils.GetSelfFuncName(), "GetBlockUsers", err.Error())
return resp, errors.WrapError(constant.ErrDB)
resp = &pbUser.GetBlockUsersResp{CommonResp: &pbUser.CommonResp{}, Pagination: &sdkws.ResponsePagination{ShowNumber: req.Pagination.ShowNumber, CurrentPage: req.Pagination.PageNumber}}
var blockUsers []imdb.BlockUserInfo
if req.UserID != "" {
blockUser, err := imdb.GetBlockUserByID(req.UserID)
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return resp, nil
}
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.UserID)
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
resp.CommonResp.ErrMsg = err.Error()
return resp, nil
}
blockUsers = append(blockUsers, blockUser)
resp.UserNums = 1
} else {
blockUsers, err = imdb.GetBlockUsers(req.Pagination.ShowNumber, req.Pagination.PageNumber)
if err != nil {
log.Error(req.OperationID, utils.GetSelfFuncName(), "GetBlockUsers", err.Error(), req.Pagination.ShowNumber, req.Pagination.PageNumber)
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
resp.CommonResp.ErrMsg = err.Error()
return resp, nil
}
nums, err := imdb.GetBlockUsersNumCount()
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetBlockUsersNumCount failed", err.Error())
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
resp.CommonResp.ErrMsg = err.Error()
return resp, nil
}
resp.UserNums = nums
}
for _, v := range blockUsers {
resp.BlockUsers = append(resp.BlockUsers, &pbUser.BlockUser{
User: &pbUser.User{
ProfilePhoto: v.User.FaceURL,
Nickname: v.User.Nickname,
UserId: v.User.UserID,
IsBlock: true,
Birth: v.User.Birth.Format("2006-01-02"),
PhoneNumber: v.User.PhoneNumber,
Email: v.User.Email,
Gender: v.User.Gender,
UserInfo: &sdkws.UserInfo{
FaceURL: v.User.FaceURL,
Nickname: v.User.Nickname,
UserID: v.User.UserID,
PhoneNumber: v.User.PhoneNumber,
Email: v.User.Email,
Gender: v.User.Gender,
},
BeginDisableTime: (v.BeginDisableTime).String(),
EndDisableTime: (v.EndDisableTime).String(),
})
}
resp.Pagination = &sdkws.ResponsePagination{}
resp.Pagination.ShowNumber = req.Pagination.ShowNumber
resp.Pagination.CurrentPage = req.Pagination.PageNumber
nums, err := imdb.GetBlockUsersNumCount()
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetBlockUsersNumCount failed", err.Error())
return resp, errors.WrapError(constant.ErrDB)
}
resp.UserNums = nums
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
return resp, nil
}
func (s *userServer) GetBlockUserById(_ context.Context, req *pbUser.GetBlockUserByIdReq) (*pbUser.GetBlockUserByIdResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
resp := &pbUser.GetBlockUserByIdResp{}
user, err := imdb.GetBlockUserById(req.UserId)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetBlockUserById", err)
return resp, errors.WrapError(constant.ErrDB)
}
resp.BlockUser = &pbUser.BlockUser{
User: &pbUser.User{
ProfilePhoto: user.User.FaceURL,
Nickname: user.User.Nickname,
UserId: user.User.UserID,
IsBlock: true,
Birth: user.User.Birth.Format("2006-01-02"),
PhoneNumber: user.User.PhoneNumber,
Email: user.User.Email,
Gender: user.User.Gender,
},
BeginDisableTime: (user.BeginDisableTime).String(),
EndDisableTime: (user.EndDisableTime).String(),
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", req.String())
return resp, nil
}
func (s *userServer) DeleteUser(_ context.Context, req *pbUser.DeleteUserReq) (*pbUser.DeleteUserResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), req.String())
resp := &pbUser.DeleteUserResp{}
if row := imdb.DeleteUser(req.UserId); row == 0 {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "delete failed", "delete rows:", row)
return resp, errors.WrapError(constant.ErrDB)
}
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"`
}

@ -93,3 +93,39 @@ type CheckMsgIsSendSuccessResp struct {
CommResp
Status int32 `json:"status"`
}
type GetUsersReq struct {
OperationID string `json:"operationID" binding:"required"`
UserName string `json:"userName"`
UserID string `json:"userID"`
PageNumber int32 `json:"pageNumber" binding:"required"`
ShowNumber int32 `json:"showNumber" binding:"required"`
}
type CMSUser struct {
UserID string `json:"userID"`
Nickname string `json:"nickname"`
FaceURL string `json:"faceURL"`
Gender int32 `json:"gender"`
PhoneNumber string `json:"phoneNumber"`
Birth uint32 `json:"birth"`
Email string `json:"email"`
Ex string `json:"ex"`
CreateIp string `json:"createIp"`
CreateTime uint32 `json:"createTime"`
LastLoginIp string `json:"LastLoginIp"`
LastLoginTime uint32 `json:"LastLoginTime"`
AppMangerLevel int32 `json:"appMangerLevel"`
GlobalRecvMsgOpt int32 `json:"globalRecvMsgOpt"`
IsBlock bool `json:"isBlock"`
}
type GetUsersResp struct {
CommResp
Data struct {
UserList []*CMSUser `json:"userList"`
TotalNum int32 `json:"totalNum"`
CurrentPage int32 `json:"currentPage"`
ShowNumber int32 `json:"showNumber"`
} `json:"data"`
}

@ -7,21 +7,16 @@ import (
)
type ApiUserInfo struct {
UserID string `json:"userID" binding:"required,min=1,max=64" swaggo:"true,用户ID,"`
Nickname string `json:"nickname" binding:"omitempty,min=1,max=64" swaggo:"true,my id,19"`
FaceURL string `json:"faceURL" binding:"omitempty,max=1024"`
Gender int32 `json:"gender" binding:"omitempty,oneof=0 1 2"`
PhoneNumber string `json:"phoneNumber" binding:"omitempty,max=32"`
Birth uint32 `json:"birth" binding:"omitempty"`
Email string `json:"email" binding:"omitempty,max=64"`
CreateIp string `json:"createIp" binding:"omitempty,max=15"`
CreateTime int64 `json:"createTime"`
LastLoginIp string `json:"LastLoginIp" binding:"omitempty,max=15"`
LastLoginTime int64 `json:"lastLoginTime"`
LoginTimes int32 `json:"loginTimes" binding:"omitempty"`
LoginLimit int32 `json:"loginLimit" binding:"omitempty"`
Ex string `json:"ex" binding:"omitempty,max=1024"`
InvitationCode string `json:"invitationCode" binding:"omitempty"`
UserID string `json:"userID" binding:"required,min=1,max=64" swaggo:"true,用户ID,"`
Nickname string `json:"nickname" binding:"omitempty,min=1,max=64" swaggo:"true,my id,19"`
FaceURL string `json:"faceURL" binding:"omitempty,max=1024"`
Gender int32 `json:"gender" binding:"omitempty,oneof=0 1 2"`
PhoneNumber string `json:"phoneNumber" binding:"omitempty,max=32"`
Birth uint32 `json:"birth" binding:"omitempty"`
Email string `json:"email" binding:"omitempty,max=64"`
CreateTime int64 `json:"createTime"`
LoginLimit int32 `json:"loginLimit" binding:"omitempty"`
Ex string `json:"ex" binding:"omitempty,max=1024"`
}
//type Conversation struct {

@ -1,10 +1,14 @@
package cms_api_struct
import server_api_params "Open_IM/pkg/proto/sdk_ws"
import (
"Open_IM/pkg/base_info"
server_api_params "Open_IM/pkg/proto/sdk_ws"
)
type AdminLoginRequest struct {
AdminName string `json:"admin_name" binding:"required"`
Secret string `json:"secret" binding:"required"`
AdminName string `json:"adminID" binding:"required"`
Secret string `json:"secret" binding:"required"`
OperationID string `json:"operationID" binding:"required"`
}
type AdminLoginResponse struct {
@ -30,10 +34,10 @@ type ReduceUserRegisterAddFriendIDListResponse struct {
type GetUserRegisterAddFriendIDListRequest struct {
OperationID string `json:"operationID" binding:"required"`
RequestPaginationBody
base_info.RequestPagination
}
type GetUserRegisterAddFriendIDListResponse struct {
Users []*server_api_params.UserInfo `json:"users"`
ResponsePagination
base_info.ResponsePagination
}

@ -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,9 +1,8 @@
package cms_api_struct
type GroupResponse struct {
GroupOwnerName string `json:"GroupOwnerName"`
GroupOwnerID string `json:"GroupOwnerID"`
//*server_api_params.GroupInfo
GroupOwnerName string `json:"GroupOwnerName"`
GroupOwnerID string `json:"GroupOwnerID"`
GroupID string `json:"groupID"`
GroupName string `json:"groupName"`
Notification string `json:"notification"`
@ -23,27 +22,11 @@ type GroupResponse struct {
NotificationUserID string `json:"notificationUserID"`
}
type GetGroupByIDRequest struct {
GroupID string `form:"groupID" binding:"required"`
}
type GetGroupByIDResponse struct {
GroupResponse
}
type GetGroupRequest struct {
GroupName string `form:"groupName" binding:"required"`
RequestPagination
}
type GetGroupResponse struct {
Groups []GroupResponse `json:"groups"`
GroupNums int `json:"groupNums"`
ResponsePagination
}
type GetGroupsRequest struct {
RequestPagination
OperationID string `json:"operationID" binding:"required"`
GroupID string `json:"groupID"`
GroupName string `json:"groupName"`
}
type GetGroupsResponse struct {
@ -52,55 +35,10 @@ type GetGroupsResponse struct {
ResponsePagination
}
type CreateGroupRequest struct {
GroupName string `json:"groupName" binding:"required"`
GroupMasterId string `json:"groupOwnerID" binding:"required"`
GroupMembers []string `json:"groupMembers" binding:"required"`
}
type CreateGroupResponse struct {
}
type SetGroupMasterRequest struct {
GroupId string `json:"groupID" binding:"required"`
UserId string `json:"userID" binding:"required"`
}
type SetGroupMasterResponse struct {
}
type SetGroupMemberRequest struct {
GroupId string `json:"groupID" binding:"required"`
UserId string `json:"userID" binding:"required"`
}
type SetGroupMemberRespones struct {
}
type BanGroupChatRequest struct {
GroupId string `json:"groupID" binding:"required"`
}
type BanGroupChatResponse struct {
}
type BanPrivateChatRequest struct {
GroupId string `json:"groupID" binding:"required"`
}
type BanPrivateChatResponse struct {
}
type DeleteGroupRequest struct {
GroupId string `json:"groupID" binding:"required"`
}
type DeleteGroupResponse struct {
}
type GetGroupMembersRequest struct {
GroupID string `form:"groupID" binding:"required"`
UserName string `form:"userName"`
GroupID string `form:"groupID" binding:"required"`
UserName string `form:"userName"`
OperationID string `json:"operationID" binding:"required"`
RequestPagination
}
@ -124,41 +62,3 @@ type GetGroupMembersResponse struct {
ResponsePagination
MemberNums int `json:"memberNums"`
}
type GroupMemberRequest struct {
GroupId string `json:"groupID" binding:"required"`
Members []string `json:"members" binding:"required"`
}
type GroupMemberOperateResponse struct {
Success []string `json:"success"`
Failed []string `json:"failed"`
}
type AddGroupMembersRequest struct {
GroupMemberRequest
}
type AddGroupMembersResponse struct {
GroupMemberOperateResponse
}
type RemoveGroupMembersRequest struct {
GroupMemberRequest
}
type RemoveGroupMembersResponse struct {
GroupMemberOperateResponse
}
type AlterGroupInfoRequest struct {
GroupID string `json:"groupID"`
GroupName string `json:"groupName"`
Notification string `json:"notification"`
Introduction string `json:"introduction"`
ProfilePhoto string `json:"profilePhoto"`
GroupType int `json:"groupType"`
}
type AlterGroupInfoResponse struct {
}

@ -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:"userID"`
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"`
}

@ -1,8 +1,9 @@
package cms_api_struct
type GetStatisticsRequest struct {
From string `form:"from" binding:"required"`
To string `form:"to" binding:"required"`
From string `json:"from" binding:"required"`
To string `json:"to" binding:"required"`
OperationID string `json:"operationID" binding:"required"`
}
type GetMessageStatisticsRequest struct {
@ -10,16 +11,16 @@ type GetMessageStatisticsRequest struct {
}
type GetMessageStatisticsResponse struct {
PrivateMessageNum int `json:"private_message_num"`
GroupMessageNum int `json:"group_message_num"`
PrivateMessageNum int `json:"privateMessageNum"`
GroupMessageNum int `json:"groupMessageNum"`
PrivateMessageNumList []struct {
Date string `json:"date"`
MessageNum int `json:"message_num"`
} `json:"private_message_num_list"`
MessageNum int `json:"messageNum"`
} `json:"privateMessageNumList"`
GroupMessageNumList []struct {
Date string `json:"date"`
MessageNum int `json:"message_num"`
} `json:"group_message_num_list"`
MessageNum int `json:"messageNum"`
} `json:"groupMessageNumList"`
}
type GetUserStatisticsRequest struct {
@ -27,21 +28,21 @@ type GetUserStatisticsRequest struct {
}
type GetUserStatisticsResponse struct {
IncreaseUserNum int `json:"increase_user_num"`
ActiveUserNum int `json:"active_user_num"`
TotalUserNum int `json:"total_user_num"`
IncreaseUserNum int `json:"increaseUserNum"`
ActiveUserNum int `json:"activeUserNum"`
TotalUserNum int `json:"totalUserNum"`
IncreaseUserNumList []struct {
Date string `json:"date"`
IncreaseUserNum int `json:"increase_user_num"`
} `json:"increase_user_num_list"`
IncreaseUserNum int `json:"increaseUserNum"`
} `json:"increaseUserNumList"`
ActiveUserNumList []struct {
Date string `json:"date"`
ActiveUserNum int `json:"active_user_num"`
} `json:"active_user_num_list"`
ActiveUserNum int `json:"activeUserNum"`
} `json:"activeUserNumList"`
TotalUserNumList []struct {
Date string `json:"date"`
TotalUserNum int `json:"total_user_num"`
} `json:"total_user_num_list"`
TotalUserNum int `json:"totalUserNum"`
} `json:"totalUserNumList"`
}
type GetGroupStatisticsRequest struct {
@ -50,16 +51,16 @@ type GetGroupStatisticsRequest struct {
// 群聊统计
type GetGroupStatisticsResponse struct {
IncreaseGroupNum int `json:"increase_group_num"`
TotalGroupNum int `json:"total_group_num"`
IncreaseGroupNum int `json:"increaseGroupNum"`
TotalGroupNum int `json:"totalGroupNum"`
IncreaseGroupNumList []struct {
Date string `json:"date"`
IncreaseGroupNum int `json:"increase_group_num"`
} `json:"increase_group_num_list"`
IncreaseGroupNum int `json:"increaseGroupNum"`
} `json:"increaseGroupNumList"`
TotalGroupNumList []struct {
Date string `json:"date"`
TotalGroupNum int `json:"total_group_num"`
} `json:"total_group_num_list"`
TotalGroupNum int `json:"totalGroupNum"`
} `json:"totalGroupNumList"`
}
type GetActiveUserRequest struct {
@ -69,10 +70,10 @@ type GetActiveUserRequest struct {
type GetActiveUserResponse struct {
ActiveUserList []struct {
NickName string `json:"nick_name"`
UserId string `json:"user_id"`
MessageNum int `json:"message_num"`
} `json:"active_user_list"`
NickName string `json:"nickName"`
UserId string `json:"userID"`
MessageNum int `json:"messageNum"`
} `json:"activeUserList"`
}
type GetActiveGroupRequest struct {
@ -82,8 +83,8 @@ type GetActiveGroupRequest struct {
type GetActiveGroupResponse struct {
ActiveGroupList []struct {
GroupName string `json:"group_name"`
GroupId string `json:"group_id"`
MessageNum int `json:"message_num"`
} `json:"active_group_list"`
GroupName string `json:"groupName"`
GroupId string `json:"groupID"`
MessageNum int `json:"messageNum"`
} `json:"activeGroupList"`
}

@ -1,79 +1,31 @@
package cms_api_struct
type UserResponse struct {
ProfilePhoto string `json:"profile_photo"`
Nickname string `json:"nick_name"`
UserId string `json:"user_id"`
CreateTime string `json:"create_time,omitempty"`
CreateIp string `json:"create_ip,omitempty"`
LastLoginTime string `json:"last_login_time,omitempty"`
LastLoginIp string `json:"last_login_ip,omitempty"`
LoginTimes int32 `json:"login_times"`
LoginLimit int32 `json:"login_limit"`
IsBlock bool `json:"is_block"`
PhoneNumber string `json:"phone_number"`
FaceURL string `json:"faceURL"`
Nickname string `json:"nickName"`
UserID string `json:"userID"`
CreateTime string `json:"createTime,omitempty"`
CreateIp string `json:"createIp,omitempty"`
LastLoginTime string `json:"lastLoginTime,omitempty"`
LastLoginIp string `json:"lastLoginIP,omitempty"`
LoginTimes int32 `json:"loginTimes"`
LoginLimit int32 `json:"loginLimit"`
IsBlock bool `json:"isBlock"`
PhoneNumber string `json:"phoneNumber"`
Email string `json:"email"`
Birth string `json:"birth"`
Gender int `json:"gender"`
}
type GetUserRequest struct {
UserId string `form:"user_id" binding:"required"`
}
type GetUserResponse struct {
UserResponse
}
type GetUsersRequest struct {
RequestPagination
}
type GetUsersResponse struct {
Users []*UserResponse `json:"users"`
ResponsePagination
UserNums int32 `json:"user_nums"`
}
type GetUsersByNameRequest struct {
UserName string `form:"user_name" binding:"required"`
RequestPagination
}
type GetUsersByNameResponse struct {
Users []*UserResponse `json:"users"`
ResponsePagination
UserNums int32 `json:"user_nums"`
}
type ResignUserRequest struct {
UserId string `json:"user_id"`
}
type ResignUserResponse struct {
}
type AlterUserRequest struct {
UserId string `json:"user_id" binding:"required"`
Nickname string `json:"nickname"`
PhoneNumber string `json:"phone_number" validate:"len=11"`
Email string `json:"email"`
Birth string `json:"birth"`
Gender string `json:"gender"`
Photo string `json:"photo"`
}
type AlterUserResponse struct {
}
type AddUserRequest struct {
PhoneNumber string `json:"phone_number" binding:"required"`
UserId string `json:"user_id" binding:"required"`
OperationID string `json:"operationID" binding:"required"`
PhoneNumber string `json:"phoneNumber" binding:"required"`
UserId string `json:"userID" binding:"required"`
Name string `json:"name" binding:"required"`
Email string `json:"email"`
Birth string `json:"birth"`
Gender string `json:"gender"`
Photo string `json:"photo"`
FaceURL string `json:"faceURL"`
}
type AddUserResponse struct {
@ -81,46 +33,34 @@ type AddUserResponse struct {
type BlockUser struct {
UserResponse
BeginDisableTime string `json:"begin_disable_time"`
EndDisableTime string `json:"end_disable_time"`
BeginDisableTime string `json:"beginDisableTime"`
EndDisableTime string `json:"endDisableTime"`
}
type BlockUserRequest struct {
UserId string `json:"user_id" binding:"required"`
EndDisableTime string `json:"end_disable_time" binding:"required"`
OperationID string `json:"operationID" binding:"required"`
UserID string `json:"userID" binding:"required"`
EndDisableTime string `json:"endDisableTime" binding:"required"`
}
type BlockUserResponse struct {
}
type UnblockUserRequest struct {
UserId string `json:"user_id" binding:"required"`
OperationID string `json:"operationID" binding:"required"`
UserID string `json:"userID" binding:"required"`
}
type UnBlockUserResponse struct {
}
type GetBlockUsersRequest struct {
OperationID string `json:"operationID" binding:"required"`
RequestPagination
}
type GetBlockUsersResponse struct {
BlockUsers []BlockUser `json:"block_users"`
BlockUsers []BlockUser `json:"blockUsers"`
ResponsePagination
UserNums int32 `json:"user_nums"`
}
type GetBlockUserRequest struct {
UserId string `form:"user_id" binding:"required"`
}
type GetBlockUserResponse struct {
BlockUser
}
type DeleteUserRequest struct {
UserId string `json:"user_id" binding:"required"`
}
type DeleteUserResponse struct {
UserNums int32 `json:"userNums"`
}

@ -15,7 +15,7 @@ type Register struct {
type Invitation struct {
InvitationCode string `gorm:"column:invitation_code;primary_key;type:varchar(32)"`
CreateTime time.Time `gorm:"column:create_time"`
UserID string `gorm:"column:user_id"`
UserID string `gorm:"column:user_id;index:userID"`
LastTime time.Time `gorm:"column:last_time"`
Status int32 `gorm:"column:status"`
}
@ -92,7 +92,7 @@ type Group struct {
Notification string `gorm:"column:notification;size:255" json:"notification"`
Introduction string `gorm:"column:introduction;size:255" json:"introduction"`
FaceURL string `gorm:"column:face_url;size:255" json:"faceURL"`
CreateTime time.Time `gorm:"column:create_time"`
CreateTime time.Time `gorm:"column:create_time;index:create_time"`
Ex string `gorm:"column:ex" json:"ex;size:1024" json:"ex"`
Status int32 `gorm:"column:status"`
CreatorUserID string `gorm:"column:creator_user_id;size:64"`
@ -176,16 +176,20 @@ type User struct {
Birth time.Time `gorm:"column:birth"`
Email string `gorm:"column:email;size:64"`
Ex string `gorm:"column:ex;size:1024"`
CreateTime time.Time `gorm:"column:create_time"`
CreateIp string `gorm:"column:create_ip;size:15"`
LastLoginTime time.Time `gorm:"column:last_login_time"`
LastLoginIp string `gorm:"column:last_login_ip;size:15"`
LoginTimes int32 `gorm:"column:login_times"`
LoginLimit int32 `gorm:"column:login_limit"`
CreateTime time.Time `gorm:"column:create_time;index:create_time"`
AppMangerLevel int32 `gorm:"column:app_manger_level"`
GlobalRecvMsgOpt int32 `gorm:"column:global_recv_msg_opt"`
InvitationCode string `gorm:"column:invitation_code"`
status int32 `gorm:"column:status"`
status int32 `gorm:"column:status"`
}
type UserIpRecord struct {
UserID string `gorm:"column:user_id;primary_key;size:64"`
CreateIp string `gorm:"column:create_ip;size:15"`
LastLoginTime time.Time `gorm:"column:last_login_time"`
LastLoginIp string `gorm:"column:last_login_ip;size:15"`
LoginTimes int32 `gorm:"column:login_times"`
LoginLimit int32 `gorm:"column:login_limit"`
}
type IpLimit struct {
@ -223,17 +227,17 @@ type Black struct {
type ChatLog struct {
ServerMsgID string `gorm:"column:server_msg_id;primary_key;type:char(64)" json:"serverMsgID"`
ClientMsgID string `gorm:"column:client_msg_id;type:char(64)" json:"clientMsgID"`
SendID string `gorm:"column:send_id;type:char(64)" json:"sendID"`
RecvID string `gorm:"column:recv_id;type:char(64)" json:"recvID"`
SendID string `gorm:"column:send_id;type:char(64);index:send_id,priority:2" json:"sendID"`
RecvID string `gorm:"column:recv_id;type:char(64);index:recv_id,priority:2" json:"recvID"`
SenderPlatformID int32 `gorm:"column:sender_platform_id" json:"senderPlatformID"`
SenderNickname string `gorm:"column:sender_nick_name;type:varchar(255)" json:"senderNickname"`
SenderFaceURL string `gorm:"column:sender_face_url;type:varchar(255)" json:"senderFaceURL"`
SessionType int32 `gorm:"column:session_type" json:"sessionType"`
SenderFaceURL string `gorm:"column:sender_face_url;type:varchar(255);" json:"senderFaceURL"`
SessionType int32 `gorm:"column:session_type;index:session_type,priority:2;index:session_type_alone" json:"sessionType"`
MsgFrom int32 `gorm:"column:msg_from" json:"msgFrom"`
ContentType int32 `gorm:"column:content_type" json:"contentType"`
ContentType int32 `gorm:"column:content_type;index:content_type,priority:2;index:content_type_alone" json:"contentType"`
Content string `gorm:"column:content;type:varchar(3000)" json:"content"`
Status int32 `gorm:"column:status" json:"status"`
SendTime time.Time `gorm:"column:send_time" json:"sendTime"`
SendTime time.Time `gorm:"column:send_time;index:sendTime;index:content_type,priority:1;index:session_type,priority:1;index:recv_id,priority:1;index:send_id,priority:1" json:"sendTime"`
CreateTime time.Time `gorm:"column:create_time" json:"createTime"`
Ex string `gorm:"column:ex;type:varchar(1024)" json:"ex"`
}

@ -56,7 +56,7 @@ func initMysqlDB() {
Writer{},
logger.Config{
SlowThreshold: 200 * time.Millisecond, // Slow SQL threshold
LogLevel: logger.Error, // Log level
LogLevel: logger.Info, // Log level
IgnoreRecordNotFoundError: true, // Ignore ErrRecordNotFound error for logger
Colorful: true, // Disable color
},

@ -3,6 +3,7 @@ package im_mysql_model
import (
"Open_IM/pkg/common/db"
"errors"
_ "gorm.io/gorm"
)
@ -74,3 +75,10 @@ func DeleteAllRegisterAddFriendIDList() error {
err := db.DB.MysqlDB.DefaultGormDB().Where("1 = 1").Delete(&db.RegisterAddFriend{}).Error
return err
}
func GetUserIPLimit(userID string) (db.UserIpLimit, error) {
var limit db.UserIpLimit
limit.UserID = userID
err := db.DB.MysqlDB.DefaultGormDB().Model(&db.UserIpLimit{}).Take(&limit).Error
return limit, err
}

@ -2,8 +2,10 @@ package im_mysql_model
import (
"Open_IM/pkg/common/db"
_ "github.com/jinzhu/gorm/dialects/mysql"
"fmt"
"time"
_ "github.com/jinzhu/gorm/dialects/mysql"
)
func InsertToFriend(toInsertFollow *db.Friend) error {
@ -51,3 +53,34 @@ func UpdateFriendComment(OwnerUserID, FriendUserID, Remark string) error {
func DeleteSingleFriendInfo(OwnerUserID, FriendUserID string) error {
return db.DB.MysqlDB.DefaultGormDB().Table("friends").Where("owner_user_id=? and friend_user_id=?", OwnerUserID, FriendUserID).Delete(db.Friend{}).Error
}
type FriendUser struct {
db.Friend
Nickname string `gorm:"column:name;size:255"`
}
func GetUserFriendsCMS(ownerUserID, friendUserName string, pageNumber, showNumber int32) (friendUserList []*FriendUser, count int64, err error) {
db := db.DB.MysqlDB.DefaultGormDB().Table("friends").
Select("friends.*, users.name").
Where("friends.owner_user_id=?", ownerUserID).Limit(int(showNumber)).
Joins("left join users on friends.friend_user_id = users.user_id").
Offset(int(showNumber * (pageNumber - 1)))
if friendUserName != "" {
db = db.Where("users.name like ?", fmt.Sprintf("%%%s%%", friendUserName))
}
if err = db.Count(&count).Error; err != nil {
return
}
err = db.Find(&friendUserList).Error
return
}
func GetFriendByIDCMS(ownerUserID, friendUserID string) (friendUser *FriendUser, err error) {
friendUser = &FriendUser{}
err = db.DB.MysqlDB.DefaultGormDB().Table("friends").
Select("friends.*, users.name").
Where("friends.owner_user_id=? and friends.friend_user_id=?", ownerUserID, friendUserID).
Joins("left join users on friends.friend_user_id = users.user_id").
Take(friendUser).Error
return friendUser, err
}

@ -1,9 +1,11 @@
package im_mysql_model
import (
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/db"
"Open_IM/pkg/utils"
"fmt"
"time"
)
@ -54,7 +56,7 @@ type GroupWithNum struct {
func GetGroupsByName(groupName string, pageNumber, showNumber int32) ([]GroupWithNum, error) {
var groups []GroupWithNum
err := db.DB.MysqlDB.DefaultGormDB().Table("groups").Select("groups.*, (select count(*) from group_members where group_members.group_id=groups.group_id) as num").
Where(fmt.Sprintf(" name like '%%%s%%' ", groupName)).Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1))).Find(&groups).Error
Where(" name like ? and status != ?", fmt.Sprintf("%%%s%%", groupName), constant.GroupStatusDismissed).Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1))).Find(&groups).Error
return groups, err
}
@ -80,7 +82,7 @@ func OperateGroupStatus(groupId string, groupStatus int32) error {
func GetGroupsCountNum(group db.Group) (int32, error) {
var count int64
if err := db.DB.MysqlDB.DefaultGormDB().Table("groups").Where(fmt.Sprintf(" name like '%%%s%%' ", group.GroupName)).Count(&count).Error; err != nil {
if err := db.DB.MysqlDB.DefaultGormDB().Table("groups").Where(" name like ? ", fmt.Sprintf("%%%s%%", group.GroupName)).Count(&count).Error; err != nil {
return 0, err
}
return int32(count), nil

@ -74,3 +74,15 @@ func GetRegisterUserNum(ip string) ([]string, error) {
err := db.DB.MysqlDB.DefaultGormDB().Model(&db.Register{}).Where("register_ip=?", ip).Pluck("user_id", &userIDList).Error
return userIDList, err
}
func InsertIpRecord(userID, createIp string) error {
record := &db.UserIpRecord{UserID: userID, CreateIp: createIp, LastLoginTime: time.Now(), LoginTimes: 1}
err := db.DB.MysqlDB.DefaultGormDB().Model(&db.UserIpRecord{}).Create(record).Error
return err
}
func UpdateIpReocord(userID, ip string) error {
record := &db.UserIpRecord{UserID: userID, LastLoginIp: ip, LastLoginTime: time.Now()}
err := db.DB.MysqlDB.DefaultGormDB().Model(&db.UserIpRecord{}).Updates(record).Updates("login_times = login_times + 1").Error
return err
}

@ -1,6 +1,7 @@
package im_mysql_model
import (
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/db"
"Open_IM/pkg/common/log"
"Open_IM/pkg/utils"
@ -10,10 +11,17 @@ import (
func GetChatLog(chatLog db.ChatLog, pageNumber, showNumber int32) ([]db.ChatLog, error) {
var chatLogs []db.ChatLog
db := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs").
Where(fmt.Sprintf(" content like '%%%s%%'", chatLog.Content)).
Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1)))
if chatLog.SessionType != 0 {
if chatLog.SendTime.Unix() > 0 {
db = db.Where("send_time > ? and send_time < ?", chatLog.SendTime, chatLog.SendTime.AddDate(0, 0, 1))
}
if chatLog.Content != "" {
db = db.Where(" content like ? ", fmt.Sprintf("%%%s%%", chatLog.Content))
}
if chatLog.SessionType == 1 {
db = db.Where("session_type = ?", chatLog.SessionType)
} else if chatLog.SessionType == 2 {
db = db.Where("content_type in (?)", []int{constant.GroupChatType, constant.SuperGroupChatType})
}
if chatLog.ContentType != 0 {
db = db.Where("content_type = ?", chatLog.ContentType)
@ -24,23 +32,28 @@ func GetChatLog(chatLog db.ChatLog, pageNumber, showNumber int32) ([]db.ChatLog,
if chatLog.RecvID != "" {
db = db.Where("recv_id = ?", chatLog.RecvID)
}
if chatLog.SendTime.Unix() > 0 {
db = db.Where("send_time > ? and send_time < ?", chatLog.SendTime, chatLog.SendTime.AddDate(0, 0, 1))
}
err := db.Find(&chatLogs).Error
return chatLogs, err
}
func GetChatLogCount(chatLog db.ChatLog) (int64, error) {
var chatLogs []db.ChatLog
var count int64
db := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs").
Where(fmt.Sprintf(" content like '%%%s%%'", chatLog.Content))
db := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs")
if chatLog.SendTime.Unix() > 0 {
log.NewDebug("", utils.GetSelfFuncName(), chatLog.SendTime, chatLog.SendTime.AddDate(0, 0, 1))
db = db.Where("send_time > ? and send_time < ?", chatLog.SendTime, chatLog.SendTime.AddDate(0, 0, 1))
}
if chatLog.Content != "" {
db = db.Where(" content like ? ", fmt.Sprintf("%%%s%%", chatLog.Content))
}
if chatLog.SessionType != 0 {
db = db.Where("session_type = ?", chatLog.SessionType)
}
if chatLog.ContentType != 0 {
if chatLog.ContentType == 1 {
db = db.Where("content_type = ?", chatLog.ContentType)
} else if chatLog.ContentType == 2 {
db = db.Where("content_type in (?)", []int{constant.GroupChatType, constant.SuperGroupChatType})
}
if chatLog.SendID != "" {
db = db.Where("send_id = ?", chatLog.SendID)
@ -48,11 +61,7 @@ func GetChatLogCount(chatLog db.ChatLog) (int64, error) {
if chatLog.RecvID != "" {
db = db.Where("recv_id = ?", chatLog.RecvID)
}
if chatLog.SendTime.Unix() > 0 {
log.NewDebug("", utils.GetSelfFuncName(), chatLog.SendTime, chatLog.SendTime.AddDate(0, 0, 1))
db = db.Where("send_time > ? and send_time < ?", chatLog.SendTime, chatLog.SendTime.AddDate(0, 0, 1))
}
err := db.Find(&chatLogs).Count(&count).Error
err := db.Count(&count).Error
return count, err
}

@ -1,13 +1,14 @@
package im_mysql_model
import (
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/db"
"time"
)
func GetActiveUserNum(from, to time.Time) (int32, error) {
var num int64
err := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs").Select("count(distinct(send_id))").Where("create_time >= ? and create_time <= ?", from, to).Count(&num).Error
err := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs").Select("count(distinct(send_id))").Where("send_time >= ? and send_time <= ?", from, to).Count(&num).Error
return int32(num), err
}
@ -31,13 +32,13 @@ func GetTotalUserNumByDate(to time.Time) (int32, error) {
func GetPrivateMessageNum(from, to time.Time) (int32, error) {
var num int64
err := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs").Where("create_time >= ? and create_time <= ? and session_type = ?", from, to, 1).Count(&num).Error
err := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs").Where("send_time >= ? and send_time <= ? and session_type = ?", from, to, 1).Count(&num).Error
return int32(num), err
}
func GetGroupMessageNum(from, to time.Time) (int32, error) {
var num int64
err := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs").Where("create_time >= ? and create_time <= ? and session_type = ?", from, to, 2).Count(&num).Error
err := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs").Where("send_time >= ? and send_time <= ? and session_type = ?", from, to, 2).Count(&num).Error
return int32(num), err
}
@ -67,7 +68,7 @@ type activeGroup struct {
func GetActiveGroups(from, to time.Time, limit int) ([]*activeGroup, error) {
var activeGroups []*activeGroup
err := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs").Select("recv_id, count(*) as message_num").Where("create_time >= ? and create_time <= ? and session_type = ?", from, to, 2).Group("recv_id").Limit(limit).Order("message_num DESC").Find(&activeGroups).Error
err := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs").Select("recv_id, count(*) as message_num").Where("send_time >= ? and send_time <= ? and session_type in (?)", from, to, []int{constant.GroupChatType, constant.SuperGroupChatType}).Group("recv_id").Limit(limit).Order("message_num DESC").Find(&activeGroups).Error
for _, activeGroup := range activeGroups {
group := db.Group{
GroupID: activeGroup.Id,
@ -80,18 +81,21 @@ func GetActiveGroups(from, to time.Time, limit int) ([]*activeGroup, error) {
type activeUser struct {
Name string
Id string `gorm:"column:send_id"`
ID string `gorm:"column:send_id"`
MessageNum int `gorm:"column:message_num"`
}
func GetActiveUsers(from, to time.Time, limit int) ([]*activeUser, error) {
var activeUsers []*activeUser
err := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs").Select("send_id, count(*) as message_num").Where("create_time >= ? and create_time <= ? and session_type = ?", from, to, 1).Group("send_id").Limit(limit).Order("message_num DESC").Find(&activeUsers).Error
err := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs").Select("send_id, count(*) as message_num").Where("send_time >= ? and send_time <= ? and session_type = ?", from, to, constant.SingleChatType).Group("send_id").Limit(limit).Order("message_num DESC").Find(&activeUsers).Error
for _, activeUser := range activeUsers {
user := db.User{
UserID: activeUser.Id,
UserID: activeUser.ID,
}
err = db.DB.MysqlDB.DefaultGormDB().Table("users").Select("user_id, name").Find(&user).Error
if err != nil {
continue
}
db.DB.MysqlDB.DefaultGormDB().Table("users").Select("user_id, name").Find(&user)
activeUser.Name = user.Nickname
}
return activeUsers, err

@ -11,14 +11,14 @@ func InsertInToUserBlackList(black db.Black) error {
return db.DB.MysqlDB.DefaultGormDB().Table("blacks").Create(black).Error
}
//type Black struct {
// OwnerUserID string `gorm:"column:owner_user_id;primaryKey;"`
// BlockUserID string `gorm:"column:block_user_id;primaryKey;"`
// CreateTime time.Time `gorm:"column:create_time"`
// AddSource int32 `gorm:"column:add_source"`
// OperatorUserID int32 `gorm:"column:operator_user_id"`
// Ex string `gorm:"column:ex"`
//}
// type Black struct {
// OwnerUserID string `gorm:"column:owner_user_id;primaryKey;"`
// BlockUserID string `gorm:"column:block_user_id;primaryKey;"`
// CreateTime time.Time `gorm:"column:create_time"`
// AddSource int32 `gorm:"column:add_source"`
// OperatorUserID int32 `gorm:"column:operator_user_id"`
// Ex string `gorm:"column:ex"`
// }
func CheckBlack(ownerUserID, blockUserID string) error {
var black db.Black

@ -43,9 +43,6 @@ func UserRegister(user db.User) error {
if user.Birth.Unix() < 0 {
user.Birth = utils.UnixSecondToTime(0)
}
user.LastLoginTime = time.Now()
user.LoginTimes = 0
user.LastLoginIp = user.CreateIp
err := db.DB.MysqlDB.DefaultGormDB().Table("users").Create(&user).Error
if err != nil {
return err
@ -124,31 +121,21 @@ func GetUsers(showNumber, pageNumber int32) ([]db.User, error) {
return users, err
}
func AddUser(userId string, phoneNumber string, name string, email string, gender string, photo string, birth string) error {
_gender, _err := strconv.Atoi(gender)
if _err != nil {
_gender = 0
}
_birth, _err := time.ParseInLocation("2006-01-02", birth, time.Local)
func AddUser(userID string, phoneNumber string, name string, email string, gender int32, faceURL string, birth uint32) error {
_birth, _err := time.ParseInLocation("2006-01-02", strconv.Itoa(int(birth)), time.Local)
if _err != nil {
_birth = time.Now()
}
user := db.User{
UserID: userId,
Nickname: name,
FaceURL: photo,
Gender: int32(_gender),
PhoneNumber: phoneNumber,
Birth: _birth,
Email: email,
Ex: "",
CreateTime: time.Now(),
CreateIp: "",
LastLoginTime: time.Now(),
LastLoginIp: "",
LoginTimes: 0,
LoginLimit: 0,
InvitationCode: "",
UserID: userID,
Nickname: name,
FaceURL: faceURL,
Gender: gender,
PhoneNumber: phoneNumber,
Birth: _birth,
Email: email,
Ex: "",
CreateTime: time.Now(),
}
result := db.DB.MysqlDB.DefaultGormDB().Table("users").Create(&user)
return result.Error
@ -163,8 +150,13 @@ func UserIsBlock(userId string) (bool, error) {
return false, nil
}
func BlockUser(userId, endDisableTime string) error {
user, err := GetUserByUserID(userId)
func UsersIsBlock(userIDList []string) (inBlockUserIDList []string, err error) {
err = db.DB.MysqlDB.DefaultGormDB().Table("black_lists").Where("uid in (?) and end_disable_time > now()", userIDList).Pluck("uid", &inBlockUserIDList).Error
return inBlockUserIDList, err
}
func BlockUser(userID, endDisableTime string) error {
user, err := GetUserByUserID(userID)
if err != nil || user.UserID == "" {
return err
}
@ -176,34 +168,34 @@ func BlockUser(userId, endDisableTime string) error {
return constant.ErrDB
}
var blockUser db.BlackList
db.DB.MysqlDB.DefaultGormDB().Table("black_lists").Where("uid=?", userId).First(&blockUser)
db.DB.MysqlDB.DefaultGormDB().Table("black_lists").Where("uid=?", userID).First(&blockUser)
if blockUser.UserId != "" {
db.DB.MysqlDB.DefaultGormDB().Model(&blockUser).Where("uid=?", blockUser.UserId).Update("end_disable_time", end)
if user.LoginLimit != 2 {
db.DB.MysqlDB.DefaultGormDB().Table("users").Where("user_id=?", blockUser.UserId).Update("login_limit", 2)
}
// if user.LoginLimit != 2 {
// db.DB.MysqlDB.DefaultGormDB().Table("users").Where("user_id=?", blockUser.UserId).Update("login_limit", 2)
// }
return nil
}
blockUser = db.BlackList{
UserId: userId,
UserId: userID,
BeginDisableTime: time.Now(),
EndDisableTime: end,
}
result := db.DB.MysqlDB.DefaultGormDB().Create(&blockUser)
if result.Error == nil {
if user.LoginLimit != 2 {
db.DB.MysqlDB.DefaultGormDB().Table("users").Where("user_id=?", blockUser.UserId).Update("login_limit", 2)
}
// if user.LoginLimit != 2 {
// db.DB.MysqlDB.DefaultGormDB().Table("users").Where("user_id=?", blockUser.UserId).Update("login_limit", 2)
// }
}
return result.Error
}
func UnBlockUser(userId string) error {
err := db.DB.MysqlDB.DefaultGormDB().Where("uid=?", userId).Delete(&db.BlackList{}).Error
func UnBlockUser(userID string) error {
err := db.DB.MysqlDB.DefaultGormDB().Where("uid=?", userID).Delete(&db.BlackList{}).Error
if err != nil {
return err
}
return db.DB.MysqlDB.DefaultGormDB().Table("users").Where("user_id=?", userId).Update("login_limit", 0).Error
return db.DB.MysqlDB.DefaultGormDB().Table("users").Where("user_id=?", userID).Update("login_limit", 0).Error
}
type BlockUserInfo struct {
@ -212,7 +204,7 @@ type BlockUserInfo struct {
EndDisableTime time.Time
}
func GetBlockUserById(userId string) (BlockUserInfo, error) {
func GetBlockUserByID(userId string) (BlockUserInfo, error) {
var blockUserInfo BlockUserInfo
blockUser := db.BlackList{
UserId: userId,
@ -267,13 +259,13 @@ func GetBlockUsers(showNumber, pageNumber int32) ([]BlockUserInfo, error) {
func GetUserByName(userName string, showNumber, pageNumber int32) ([]db.User, error) {
var users []db.User
err := db.DB.MysqlDB.DefaultGormDB().Table("users").Where(fmt.Sprintf(" name like '%%%s%%' ", userName)).Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1))).Find(&users).Error
err := db.DB.MysqlDB.DefaultGormDB().Table("users").Where(" name like ?", fmt.Sprintf("%%%s%%", userName)).Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1))).Find(&users).Error
return users, err
}
func GetUsersCount(user db.User) (int32, error) {
func GetUsersCount(userName string) (int32, error) {
var count int64
if err := db.DB.MysqlDB.DefaultGormDB().Table("users").Where(fmt.Sprintf(" name like '%%%s%%' ", user.Nickname)).Count(&count).Error; err != nil {
if err := db.DB.MysqlDB.DefaultGormDB().Table("users").Where(" name like ? ", fmt.Sprintf("%%%s%%", userName)).Count(&count).Error; err != nil {
return 0, err
}
return int32(count), nil

@ -75,7 +75,10 @@ func GetFriendIDListFromCache(userID string) ([]string, error) {
return "", utils.Wrap(err, "")
}
bytes, err := json.Marshal(friendIDList)
return string(bytes), utils.Wrap(err, "")
if err != nil {
return "", utils.Wrap(err, "")
}
return string(bytes), nil
}
friendIDListStr, err := db.DB.Rc.Fetch(friendRelationCache+userID, time.Second*30*60, getFriendIDList)
if err != nil {
@ -98,7 +101,10 @@ func GetBlackListFromCache(userID string) ([]string, error) {
return "", utils.Wrap(err, "")
}
bytes, err := json.Marshal(blackIDList)
return string(bytes), utils.Wrap(err, "")
if err != nil {
return "", utils.Wrap(err, "")
}
return string(bytes), nil
}
blackIDListStr, err := db.DB.Rc.Fetch(blackListCache+userID, time.Second*30*60, getBlackIDList)
if err != nil {
@ -120,7 +126,10 @@ func GetJoinedGroupIDListFromCache(userID string) ([]string, error) {
return "", utils.Wrap(err, "")
}
bytes, err := json.Marshal(joinedGroupList)
return string(bytes), utils.Wrap(err, "")
if err != nil {
return "", utils.Wrap(err, "")
}
return string(bytes), nil
}
joinedGroupIDListStr, err := db.DB.Rc.Fetch(joinedGroupListCache+userID, time.Second*30*60, getJoinedGroupIDList)
if err != nil {
@ -155,7 +164,10 @@ func GetGroupMemberIDListFromCache(groupID string) ([]string, error) {
}
}
bytes, err := json.Marshal(groupMemberIDList)
return string(bytes), utils.Wrap(err, "")
if err != nil {
return "", utils.Wrap(err, "")
}
return string(bytes), nil
}
groupIDListStr, err := db.DB.Rc.Fetch(groupCache+groupID, time.Second*30*60, f)
if err != nil {
@ -178,7 +190,10 @@ func GetUserInfoFromCache(userID string) (*db.User, error) {
return "", utils.Wrap(err, "")
}
bytes, err := json.Marshal(userInfo)
return string(bytes), utils.Wrap(err, "")
if err != nil {
return "", utils.Wrap(err, "")
}
return string(bytes), nil
}
userInfoStr, err := db.DB.Rc.Fetch(userInfoCache+userID, time.Second*30*60, getUserInfo)
if err != nil {
@ -200,7 +215,10 @@ func GetGroupMemberInfoFromCache(groupID, userID string) (*db.GroupMember, error
return "", utils.Wrap(err, "")
}
bytes, err := json.Marshal(groupMemberInfo)
return string(bytes), utils.Wrap(err, "")
if err != nil {
return "", utils.Wrap(err, "")
}
return string(bytes), nil
}
groupMemberInfoStr, err := db.DB.Rc.Fetch(groupMemberInfoCache+groupID+"-"+userID, time.Second*30*60, getGroupMemberInfo)
if err != nil {
@ -266,7 +284,10 @@ func GetAllGroupMembersInfoFromCache(groupID string) ([]*db.GroupMember, error)
return "", utils.Wrap(err, "")
}
bytes, err := json.Marshal(groupMembers)
return string(bytes), utils.Wrap(err, "")
if err != nil {
return "", utils.Wrap(err, "")
}
return string(bytes), nil
}
groupMembersStr, err := db.DB.Rc.Fetch(groupAllMemberInfoCache+groupID, time.Second*30*60, getGroupMemberInfo)
if err != nil {
@ -288,7 +309,10 @@ func GetGroupInfoFromCache(groupID string) (*db.Group, error) {
return "", utils.Wrap(err, "")
}
bytes, err := json.Marshal(groupInfo)
return string(bytes), utils.Wrap(err, "")
if err != nil {
return "", utils.Wrap(err, "")
}
return string(bytes), nil
}
groupInfoStr, err := db.DB.Rc.Fetch(groupInfoCache+groupID, time.Second*30*60, getGroupInfo)
if err != nil {
@ -310,7 +334,10 @@ func GetAllFriendsInfoFromCache(userID string) ([]*db.Friend, error) {
return "", utils.Wrap(err, "")
}
bytes, err := json.Marshal(friendInfoList)
return string(bytes), utils.Wrap(err, "")
if err != nil {
return "", utils.Wrap(err, "")
}
return string(bytes), nil
}
allFriendInfoStr, err := db.DB.Rc.Fetch(allFriendInfoCache+userID, time.Second*30*60, getAllFriendInfo)
if err != nil {
@ -332,7 +359,10 @@ func GetAllDepartmentsFromCache() ([]db.Department, error) {
return "", utils.Wrap(err, "")
}
bytes, err := json.Marshal(departmentList)
return string(bytes), utils.Wrap(err, "")
if err != nil {
return "", utils.Wrap(err, "")
}
return string(bytes), nil
}
allDepartmentsStr, err := db.DB.Rc.Fetch(allDepartmentCache, time.Second*30*60, getAllDepartments)
if err != nil {
@ -354,7 +384,10 @@ func GetAllDepartmentMembersFromCache() ([]db.DepartmentMember, error) {
return "", utils.Wrap(err, "")
}
bytes, err := json.Marshal(departmentMembers)
return string(bytes), utils.Wrap(err, "")
if err != nil {
return "", utils.Wrap(err, "")
}
return string(bytes), nil
}
allDepartmentMembersStr, err := db.DB.Rc.Fetch(allDepartmentMemberCache, time.Second*30*60, getAllDepartmentMembers)
if err != nil {
@ -379,7 +412,10 @@ func GetJoinedSuperGroupListFromCache(userID string) ([]string, error) {
return "", errors.New("GroupIDList == 0")
}
bytes, err := json.Marshal(userToSuperGroup.GroupIDList)
return string(bytes), utils.Wrap(err, "")
if err != nil {
return "", utils.Wrap(err, "")
}
return string(bytes), nil
}
joinedSuperGroupListStr, err := db.DB.Rc.Fetch(joinedSuperGroupListCache+userID, time.Second*30*60, getJoinedSuperGroupIDList)
if err != nil {
@ -445,7 +481,10 @@ func GetUserConversationIDListFromCache(userID string) ([]string, error) {
}
log.NewDebug("", utils.GetSelfFuncName(), conversationIDList)
bytes, err := json.Marshal(conversationIDList)
return string(bytes), utils.Wrap(err, "")
if err != nil {
return "", utils.Wrap(err, "")
}
return string(bytes), nil
}
conversationIDListStr, err := db.DB.Rc.Fetch(conversationIDListCache+userID, time.Second*30*60, getConversationIDList)
var conversationIDList []string

@ -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)
}

@ -42,7 +42,7 @@ func loggerInit(moduleName string) *Logger {
}
writer := bufio.NewWriter(src)
logger.SetOutput(writer)
//logger.SetOutput(os.Stdout)
// logger.SetOutput(os.Stdout)
//Log Console Print Style Setting
logger.SetFormatter(&nested.Formatter{
TimestampFormat: "2006-01-02 15:04:05.000",

File diff suppressed because it is too large Load Diff

@ -3,15 +3,22 @@ option go_package = "./admin_cms;admin_cms";
import "Open_IM/pkg/proto/sdk_ws/ws.proto";
package admin_cms;
message CommonResp {
int32 errCode = 1;
string errMsg = 2;
}
message AdminLoginReq {
string OperationID = 1;
string AdminID = 2;
string Secret = 3;
string operationID = 1;
string adminID = 2;
string secret = 3;
}
message AdminLoginResp {
string token = 1;
CommonResp commonResp = 2;
}
message AddUserRegisterAddFriendIDListReq {
@ -20,7 +27,7 @@ message AddUserRegisterAddFriendIDListReq {
}
message AddUserRegisterAddFriendIDListResp {
CommonResp commonResp = 1;
}
message ReduceUserRegisterAddFriendIDListReq {
@ -30,17 +37,278 @@ message ReduceUserRegisterAddFriendIDListReq {
}
message ReduceUserRegisterAddFriendIDListResp {
CommonResp commonResp = 1;
}
message GetUserRegisterAddFriendIDListReq {
string operationID = 1;
server_api_params.RequestPagination Pagination = 2;
server_api_params.RequestPagination pagination = 2;
}
message GetUserRegisterAddFriendIDListResp {
repeated server_api_params.UserInfo UserInfoList = 1;
repeated server_api_params.UserInfo userInfoList = 1;
server_api_params.ResponsePagination pagination = 2;
CommonResp commonResp = 3;
}
message GetChatLogsReq {
string content = 1;
string sendID = 2;
string recvID = 3;
string sendTime = 4;
int32 sessionType = 5;
int32 contentType = 6;
server_api_params.RequestPagination pagination = 7;
string operationID = 8;
}
message ChatLog {
string serverMsgID = 1;
string clientMsgID = 2;
string sendID = 3;
string recvID = 4;
string groupID = 5;
string recvNickname = 6;
int32 senderPlatformID = 7;
string senderNickname = 8;
string senderFaceURL = 9;
string groupName = 10;
int32 sessionType = 11;
int32 msgFrom = 12;
int32 contentType = 13;
string content = 14;
int32 status = 15;
int64 sendTime = 16;
int64 createTime = 17;
string ex = 18;
}
message GetChatLogsResp {
repeated ChatLog chatLogs = 1;
server_api_params.ResponsePagination pagination = 2;
int32 chatLogsNum = 3;
CommonResp commonResp = 4;
}
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;
CommonResp commonResp = 2;
}
message GetActiveGroupReq{
StatisticsReq statisticsReq = 1;
string operationID = 2;
}
message GroupResp {
string GroupName = 1;
string GroupId = 2;
int32 MessageNum = 3;
CommonResp commonResp = 4;
}
message GetActiveGroupResp {
repeated GroupResp Groups = 1;
CommonResp commonResp = 2;
}
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;
CommonResp commonResp = 5;
}
message GetGroupStatisticsReq {
StatisticsReq StatisticsReq = 1;
string OperationID = 2;
}
message GetGroupStatisticsResp {
int32 IncreaseGroupNum = 1;
int32 TotalGroupNum = 2;
repeated DateNumList IncreaseGroupNumList = 3;
repeated DateNumList TotalGroupNumList = 4;
CommonResp commonResp = 5;
}
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;
CommonResp commonResp = 7;
}
message GenerateInvitationCodeReq {
string operationID = 1;
int32 codeLen = 2;
int32 codeNum = 3;
}
message GenerateInvitationCodeResp {
CommonResp commonResp = 1;
}
message GetInvitationCodesReq {
string operationID = 1;
string code = 2;
int32 status = 3;
server_api_params.RequestPagination pagination = 4;
}
message invitationCode {
string invitationCode = 1;
int32 createTime = 2;
int32 lastTime = 3;
string userID = 4;
int32 status = 5;
}
message GetInvitationCodesResp {
repeated invitationCode invitationCodes = 1;
server_api_params.ResponsePagination Pagination = 2;
CommonResp commonResp = 3;
}
message QueryIPRegisterReq {
string operationID = 1;
string IP = 2;
}
message QueryIPRegisterResp {
string IP = 1;
int32 RegisterNum = 2;
int32 Status = 3;
repeated string userIDList = 4;
CommonResp commonResp = 5;
}
message AddIPLimitReq {
string operationID = 1;
string IP = 2;
int32 limitTime = 3;
}
message AddIPLimitResp {
CommonResp commonResp = 1;
}
message RemoveIPLimitReq {
string operationID = 1;
string IP = 2;
}
message RemoveIPLimitResp {
CommonResp commonResp = 1;
}
message QueryUserIDIPLimitLoginReq {
string operationID = 1;
string userID = 2;
}
message UserIPLimit {
string userID = 1;
string IP = 2;
int32 createTime = 3;
}
message QueryUserIDIPLimitLoginResp {
repeated UserIPLimit UserIPLimits = 1;
CommonResp commonResp = 2;
}
message AddUserIPLimitLoginReq {
string userID = 1;
string operationID = 2;
string IP = 3;
}
message AddUserIPLimitLoginResp {
CommonResp commonResp = 1;
}
message RemoveUserIPLimitReq {
string userID = 1;
string operationID = 2;
string IP = 3;
}
message RemoveUserIPLimitResp {
CommonResp commonResp = 1;
}
message GetClientInitConfigReq {
string operationID = 1;
}
message GetClientInitConfigResp {
CommonResp commonResp = 1;
}
message SetClientInitConfigReq {
string operationID = 1;
string discoverPageURL = 2;
}
message SetClientInitConfigResp {
CommonResp commonResp = 1;
}
message GetUserFriendsReq {
string operationID = 1;
string userID = 2;
string friendUserID = 3;
string friendUserName = 4;
server_api_params.RequestPagination pagination = 5;
}
message GetUserFriendsResp {
server_api_params.ResponsePagination pagination = 1;
repeated server_api_params.FriendInfo friendInfoList = 2;
int32 friendNums = 3;
CommonResp commonResp = 4;
}
service adminCMS {
@ -48,4 +316,28 @@ service adminCMS {
rpc AddUserRegisterAddFriendIDList(AddUserRegisterAddFriendIDListReq) returns(AddUserRegisterAddFriendIDListResp);
rpc ReduceUserRegisterAddFriendIDList(ReduceUserRegisterAddFriendIDListReq) returns(ReduceUserRegisterAddFriendIDListResp);
rpc GetUserRegisterAddFriendIDList(GetUserRegisterAddFriendIDListReq) returns(GetUserRegisterAddFriendIDListResp);
rpc GetChatLogs(GetChatLogsReq) returns(GetChatLogsResp);
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);
rpc GenerateInvitationCode(GenerateInvitationCodeReq) returns(GenerateInvitationCodeResp);
rpc GetInvitationCodes(GetInvitationCodesReq) returns(GetInvitationCodesResp);
rpc QueryIPRegister(QueryIPRegisterReq) returns(QueryIPRegisterResp);
rpc AddIPLimit(AddIPLimitReq) returns(AddIPLimitResp);
rpc RemoveIPLimit(RemoveIPLimitReq) returns(RemoveIPLimitResp);
rpc QueryUserIDIPLimitLogin(QueryUserIDIPLimitLoginReq) returns(QueryUserIDIPLimitLoginResp);
rpc AddUserIPLimitLogin(AddUserIPLimitLoginReq) returns(AddUserIPLimitLoginResp);
rpc RemoveUserIPLimit(RemoveUserIPLimitReq) returns(RemoveUserIPLimitResp);
rpc GetClientInitConfig(GetClientInitConfigReq) returns(GetClientInitConfigResp);
rpc SetClientInitConfig(SetClientInitConfigReq) returns(SetClientInitConfigResp);
rpc GetUserFriends(GetUserFriendsReq) returns(GetUserFriendsResp);
}

@ -1,5 +0,0 @@
syntax = "proto3";
package base;

File diff suppressed because it is too large Load Diff

@ -219,27 +219,19 @@ message CMSGroup {
string GroupOwnerUserID = 3;
}
message GetGroupReq {
string GroupName = 1;
server_api_params.RequestPagination Pagination = 2;
string OperationID = 3;
}
message GetGroupResp {
repeated CMSGroup CMSGroups = 1;
server_api_params.RequestPagination Pagination = 2;
int32 GroupNums = 3;
}
message GetGroupsReq {
server_api_params.RequestPagination Pagination = 1;
string OperationID = 2;
string GroupName = 2;
string GroupID = 3;
string OperationID = 4;
}
message GetGroupsResp {
repeated CMSGroup CMSGroups = 1;
server_api_params.RequestPagination Pagination = 2;
server_api_params.ResponsePagination Pagination = 2;
int32 GroupNum = 3;
CommonResp commonResp = 4;
}
message GetGroupMemberReq {
@ -247,26 +239,6 @@ message GetGroupMemberReq {
string OperationID = 2;
}
message OperateUserRoleReq {
string GroupID = 1;
string UserID = 2;
int32 RoleLevel = 3;
string OperationID = 4;
}
message OperateUserRoleResp {
}
message GetGroupByIDReq {
string GroupID = 1;
string OperationID = 2;
}
message GetGroupByIDResp {
CMSGroup CMSGroup = 1;
}
message GetGroupMembersCMSReq {
string GroupID = 1;
string UserName = 2;
@ -278,30 +250,7 @@ message GetGroupMembersCMSResp {
repeated server_api_params.GroupMemberFullInfo members = 1;
server_api_params.ResponsePagination Pagination = 2;
int32 MemberNums = 3;
}
message RemoveGroupMembersCMSReq {
string GroupID = 1;
repeated string UserIDList = 2;
string OperationID = 3;
string OpUserID = 4;
}
message RemoveGroupMembersCMSResp {
repeated string success = 1;
repeated string failed = 2;
}
message AddGroupMembersCMSReq {
string GroupID = 1;
repeated string UserIDList = 2;
string OperationID = 3;
string OpUserID = 4;
}
message AddGroupMembersCMSResp {
repeated string success = 1;
repeated string failed = 2;
CommonResp commonResp = 4;
}
message DismissGroupReq{
@ -444,13 +393,9 @@ service group{
rpc inviteUserToGroup(InviteUserToGroupReq) returns (InviteUserToGroupResp);
rpc getGroupAllMember(GetGroupAllMemberReq) returns(GetGroupAllMemberResp);
rpc GetGroupByID(GetGroupByIDReq) returns(GetGroupByIDResp);
rpc GetGroup(GetGroupReq) returns(GetGroupResp);
rpc GetGroups(GetGroupsReq) returns(GetGroupsResp);
rpc OperateUserRole(OperateUserRoleReq) returns(OperateUserRoleResp);
rpc GetGroupMembersCMS(GetGroupMembersCMSReq) returns(GetGroupMembersCMSResp);
rpc RemoveGroupMembersCMS(RemoveGroupMembersCMSReq) returns(RemoveGroupMembersCMSResp);
rpc AddGroupMembersCMS(AddGroupMembersCMSReq) returns(AddGroupMembersCMSResp);
rpc DismissGroup(DismissGroupReq) returns(DismissGroupResp);
rpc MuteGroupMember(MuteGroupMemberReq) returns(MuteGroupMemberResp);
@ -459,7 +404,6 @@ service group{
rpc CancelMuteGroup(CancelMuteGroupReq) returns(CancelMuteGroupResp);
rpc SetGroupMemberNickname(SetGroupMemberNicknameReq) returns (SetGroupMemberNicknameResp);
rpc GetJoinedSuperGroupList(GetJoinedSuperGroupListReq) returns (GetJoinedSuperGroupListResp);
rpc GetSuperGroupsInfo(GetSuperGroupsInfoReq) returns (GetSuperGroupsInfoResp);
rpc SetGroupMemberInfo(SetGroupMemberInfoReq) returns (SetGroupMemberInfoResp);

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

@ -72,15 +72,9 @@ message UserInfo{
uint32 birth = 6;
string email = 7;
string ex = 8;
string createIp = 9;
uint32 createTime = 10;
string LastLoginIp =11;
uint32 LastLoginTime = 12;
int32 LoginTimes = 13;
int32 LoginLimit = 14;
int32 appMangerLevel = 15;
int32 globalRecvMsgOpt = 16;
string invitationCode = 17;
uint32 createTime = 9;
int32 appMangerLevel = 10;
int32 globalRecvMsgOpt = 11;
}
message FriendInfo{

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

@ -9,16 +9,6 @@ message CommonResp{
string errMsg = 2;
}
message DeleteUsersReq{
repeated string DeleteUserIDList = 2;
string OpUserID = 3;
string OperationID = 4;
}
message DeleteUsersResp{
CommonResp CommonResp = 1;
repeated string FailedUserIDList = 2;
}
message GetAllUserIDReq{
@ -143,94 +133,29 @@ message BatchSetConversationsResp{
repeated string Failed = 3;
}
message ResignUserReq{
string UserId = 1;
string OperationID = 2;
}
message ResignUserResp{
CommonResp commonResp = 1;
}
message GetUserByIdReq{
string UserId = 1;
string OperationID = 2;
}
message User{
string ProfilePhoto = 1;
string Nickname = 2;
string UserId = 3;
string CreateTime = 4;
string PhoneNumber = 5;
string Email = 6;
string Birth = 7;
string CreateIp = 8;
string LastLoginTime = 9;
string LastLoginIp = 10;
int32 LoginTimes = 11;
int32 Gender = 12;
int32 LoginLimit = 13;
bool IsBlock = 14;
string RegisterIp = 15;
}
message GetUserByIdResp{
CommonResp CommonResp = 1;
User user = 2;
}
message GetUsersByNameReq {
string UserName = 1;
server_api_params.RequestPagination Pagination = 2;
string OperationID = 3;
}
message GetUsersByNameResp {
repeated User users = 1;
server_api_params.ResponsePagination Pagination = 2;
int32 UserNums = 3;
}
message AlterUserReq{
string UserId = 1;
string OperationID = 2;
string PhoneNumber = 3;
string Nickname = 4;
string Email = 5;
string Gender = 6;
string Birth =7;
string Photo = 8;
string OpUserId = 9;
}
message AlterUserResp{
CommonResp CommonResp = 1;
message GetUsersReq {
string operationID = 1;
server_api_params.RequestPagination pagination = 2;
string userName = 3;
string userID = 4;
}
message GetUsersReq {
string OperationID = 1;
server_api_params.RequestPagination Pagination = 2;
string UserName = 3;
message CmsUser {
server_api_params.UserInfo user = 1;
bool isBlock = 2;
}
message GetUsersResp{
CommonResp CommonResp = 1;
repeated User user = 2;
CommonResp commonResp = 1;
repeated CmsUser userList = 2;
server_api_params.ResponsePagination Pagination = 3;
int32 UserNums = 4;
int32 totalNums = 4;
}
message AddUserReq{
string OperationID = 1;
string PhoneNumber = 2;
string UserId = 3;
string name = 4;
string Email = 5;
string Gender = 6;
string Birth =7;
string Photo = 8;
string OpUserId = 9;
server_api_params.UserInfo userInfo = 1;
string operationID = 2;
}
message AddUserResp{
@ -239,10 +164,10 @@ message AddUserResp{
message BlockUserReq{
string UserId = 1;
string EndDisableTime = 2;
string OperationID = 3;
string OpUserId = 4;
string userID = 1;
string endDisableTime = 2;
string operationID = 3;
string opUserID = 4;
}
message BlockUserResp{
@ -250,9 +175,9 @@ message BlockUserResp{
}
message UnBlockUserReq{
string UserId = 1;
string OperationID = 2;
string OpUserId = 3;
string userID = 1;
string operationID = 2;
string opUserID = 3;
}
message UnBlockUserResp{
@ -260,13 +185,14 @@ message UnBlockUserResp{
}
message GetBlockUsersReq{
server_api_params.RequestPagination Pagination = 1;
string OperationID = 2;
int32 BlockUserNum = 3;
server_api_params.RequestPagination pagination = 1;
string operationID = 2;
string userID = 3;
int32 totalBlockUserNum = 4;
}
message BlockUser {
User User = 1;
server_api_params.UserInfo UserInfo = 1;
string BeginDisableTime = 2;
string EndDisableTime = 3;
}
@ -278,24 +204,6 @@ message GetBlockUsersResp{
int32 UserNums = 4;
}
message GetBlockUserByIdReq {
string User_id = 1;
string OperationID = 2;
}
message GetBlockUserByIdResp {
BlockUser BlockUser = 2;
}
message DeleteUserReq {
string User_id = 1;
string OperationID = 2;
string OpUserId = 3;
}
message DeleteUserResp {
CommonResp CommonResp = 1;
}
@ -303,7 +211,6 @@ service user {
rpc GetUserInfo(GetUserInfoReq) returns(GetUserInfoResp);
rpc UpdateUserInfo(UpdateUserInfoReq) returns(UpdateUserInfoResp);
rpc SetGlobalRecvMessageOpt(SetGlobalRecvMessageOptReq) returns(SetGlobalRecvMessageOptResp);
rpc DeleteUsers(DeleteUsersReq)returns(DeleteUsersResp);
rpc GetAllUserID(GetAllUserIDReq)returns(GetAllUserIDResp);
rpc AccountCheck(AccountCheckReq)returns(AccountCheckResp);
@ -314,15 +221,13 @@ service user {
rpc SetConversation(SetConversationReq)returns(SetConversationResp);
rpc SetRecvMsgOpt(SetRecvMsgOptReq)returns(SetRecvMsgOptResp);
rpc GetUserById(GetUserByIdReq) returns (GetUserByIdResp);
rpc GetUsersByName(GetUsersByNameReq) returns (GetUsersByNameResp);
rpc ResignUser(ResignUserReq) returns (ResignUserResp);
rpc AlterUser(AlterUserReq) returns (AlterUserResp);
rpc GetUsers(GetUsersReq) returns (GetUsersResp);
rpc AddUser(AddUserReq) returns (AddUserResp);
rpc BlockUser(BlockUserReq) returns (BlockUserResp);
rpc UnBlockUser(UnBlockUserReq) returns (UnBlockUserResp);
rpc GetBlockUsers(GetBlockUsersReq) returns (GetBlockUsersResp);
rpc GetBlockUserById(GetBlockUserByIdReq) returns (GetBlockUserByIdResp);
rpc DeleteUser(DeleteUserReq) returns (DeleteUserResp);
}

@ -16,8 +16,6 @@ service_port_name=(
openImGroupPort
openImAuthPort
openImPushPort
openImStatisticsPort
openImMessageCmsPort
openImAdminCmsPort
openImOfficePort
openImOrganizationPort

@ -46,8 +46,6 @@ service_source_root=(
../cmd/rpc/open_im_group/
../cmd/rpc/open_im_auth/
../cmd/rpc/open_im_admin_cms/
../cmd/rpc/open_im_message_cms/
../cmd/rpc/open_im_statistics/
../cmd/rpc/open_im_office/
../cmd/rpc/open_im_organization/
../cmd/rpc/open_im_conversation/
@ -71,8 +69,6 @@ service_names=(
open_im_group
open_im_auth
open_im_admin_cms
open_im_message_cms
open_im_statistics
open_im_office
open_im_organization
open_im_conversation

@ -15,8 +15,6 @@ service_filename=(
open_im_group
open_im_auth
open_im_admin_cms
open_im_message_cms
open_im_statistics
${msg_name}
open_im_office
open_im_organization
@ -35,8 +33,6 @@ service_port_name=(
openImGroupPort
openImAuthPort
openImAdminCmsPort
openImMessageCmsPort
openImStatisticsPort
openImMessagePort
openImOfficePort
openImOrganizationPort

Loading…
Cancel
Save