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("/get_all_users_uid", manage.GetAllUsersUid) //1
userRouterGroup.POST("/account_check", manage.AccountCheck) //1 userRouterGroup.POST("/account_check", manage.AccountCheck) //1
// userRouterGroup.POST("/get_users_online_status", manage.GetUsersOnlineStatus) //1 // userRouterGroup.POST("/get_users_online_status", manage.GetUsersOnlineStatus) //1
userRouterGroup.POST("/get_users", user.GetUsers)
} }
//friend routing group //friend routing group
friendRouterGroup := r.Group("/friend") friendRouterGroup := r.Group("/friend")

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

@ -12,6 +12,7 @@ import (
"Open_IM/pkg/common/config" "Open_IM/pkg/common/config"
"Open_IM/pkg/common/constant" "Open_IM/pkg/common/constant"
"Open_IM/pkg/common/log" "Open_IM/pkg/common/log"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
@ -31,6 +32,7 @@ func main() {
authRouterGroup.POST("/password", register.SetPassword) authRouterGroup.POST("/password", register.SetPassword)
authRouterGroup.POST("/login", register.Login) authRouterGroup.POST("/login", register.Login)
authRouterGroup.POST("/reset_password", register.ResetPassword) authRouterGroup.POST("/reset_password", register.ResetPassword)
authRouterGroup.POST("/check_login", register.CheckLoginLimit)
} }
demoRouterGroup := r.Group("/auth") demoRouterGroup := r.Group("/auth")
{ {
@ -39,7 +41,10 @@ func main() {
demoRouterGroup.POST("/password", register.SetPassword) demoRouterGroup.POST("/password", register.SetPassword)
demoRouterGroup.POST("/login", register.Login) demoRouterGroup.POST("/login", register.Login)
demoRouterGroup.POST("/reset_password", register.ResetPassword) demoRouterGroup.POST("/reset_password", register.ResetPassword)
demoRouterGroup.POST("/check_login", register.CheckLoginLimit)
} }
//deprecated
cmsRouterGroup := r.Group("/cms_admin") cmsRouterGroup := r.Group("/cms_admin")
{ {
cmsRouterGroup.POST("/generate_invitation_code", register.GenerateInvitationCode) 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 ( import (
api "Open_IM/pkg/base_info" api "Open_IM/pkg/base_info"
"Open_IM/pkg/common/config" "Open_IM/pkg/common/config"
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/log" "Open_IM/pkg/common/log"
"Open_IM/pkg/common/token_verify" "Open_IM/pkg/common/token_verify"
"Open_IM/pkg/grpc-etcdv3/getcdv3" "Open_IM/pkg/grpc-etcdv3/getcdv3"
@ -67,17 +66,11 @@ func UserRegister(c *gin.Context) {
if reply.CommonResp.ErrCode != 0 { if reply.CommonResp.ErrCode != 0 {
errMsg := req.OperationID + " " + " UserRegister failed " + reply.CommonResp.ErrMsg + req.String() errMsg := req.OperationID + " " + " UserRegister failed " + reply.CommonResp.ErrMsg + req.String()
log.NewError(req.OperationID, errMsg) 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 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) replyToken, err := client.UserToken(context.Background(), pbDataToken)
if err != nil { if err != nil {
errMsg := req.OperationID + " " + " client.UserToken failed " + err.Error() + pbDataToken.String() 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_sdk "Open_IM/pkg/proto/sdk_ws"
"Open_IM/pkg/utils" "Open_IM/pkg/utils"
"context" "context"
"github.com/golang/protobuf/ptypes/wrappers" "github.com/golang/protobuf/ptypes/wrappers"
"google.golang.org/grpc" "google.golang.org/grpc"

@ -23,49 +23,6 @@ import (
"github.com/gin-gonic/gin" "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列表 // @Summary 获取所有用户uid列表
// @Description 获取所有用户uid列表 // @Description 获取所有用户uid列表
// @Tags 用户相关 // @Tags 用户相关

@ -456,3 +456,58 @@ func GetUsersOnlineStatus(c *gin.Context) {
log.NewInfo(req.OperationID, "GetUsersOnlineStatus api return", resp) log.NewInfo(req.OperationID, "GetUsersOnlineStatus api return", resp)
c.JSON(http.StatusOK, 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 ( import (
apiStruct "Open_IM/pkg/cms_api_struct" apiStruct "Open_IM/pkg/cms_api_struct"
"Open_IM/pkg/common/config" "Open_IM/pkg/common/config"
"Open_IM/pkg/common/constant"
openIMHttp "Open_IM/pkg/common/http"
"Open_IM/pkg/common/log" "Open_IM/pkg/common/log"
"Open_IM/pkg/grpc-etcdv3/getcdv3" "Open_IM/pkg/grpc-etcdv3/getcdv3"
pbAdmin "Open_IM/pkg/proto/admin_cms" pbAdmin "Open_IM/pkg/proto/admin_cms"
@ -66,8 +64,8 @@ func AdminLogin(c *gin.Context) {
reqPb pbAdmin.AdminLoginReq reqPb pbAdmin.AdminLoginReq
) )
if err := c.BindJSON(&req); err != nil { if err := c.BindJSON(&req); err != nil {
log.NewError("0", utils.GetSelfFuncName(), err.Error()) log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
openIMHttp.RespHttp200(c, constant.ErrArgs, nil) c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return return
} }
reqPb.Secret = req.Secret reqPb.Secret = req.Secret
@ -84,24 +82,24 @@ func AdminLogin(c *gin.Context) {
respPb, err := client.AdminLogin(context.Background(), &reqPb) respPb, err := client.AdminLogin(context.Background(), &reqPb)
if err != nil { if err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "rpc failed", err.Error()) 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 return
} }
resp.Token = respPb.Token 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) { func AddUserRegisterAddFriendIDList(c *gin.Context) {
var ( var (
req apiStruct.AddUserRegisterAddFriendIDListRequest req apiStruct.AddUserRegisterAddFriendIDListRequest
resp apiStruct.AddUserRegisterAddFriendIDListResponse // resp apiStruct.AddUserRegisterAddFriendIDListResponse
) )
if err := c.BindJSON(&req); err != nil { if err := c.BindJSON(&req); err != nil {
log.NewError("0", utils.GetSelfFuncName(), err.Error()) log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
openIMHttp.RespHttp200(c, constant.ErrArgs, nil) c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return 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) etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImAdminCMSName, req.OperationID)
if etcdConn == nil { if etcdConn == nil {
errMsg := req.OperationID + "getcdv3.GetConn == nil" errMsg := req.OperationID + "getcdv3.GetConn == nil"
@ -110,23 +108,24 @@ func AddUserRegisterAddFriendIDList(c *gin.Context) {
return return
} }
client := pbAdmin.NewAdminCMSClient(etcdConn) 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 { if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "rpc failed", err.Error()) 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 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) { func ReduceUserRegisterAddFriendIDList(c *gin.Context) {
var ( var (
req apiStruct.ReduceUserRegisterAddFriendIDListRequest req apiStruct.ReduceUserRegisterAddFriendIDListRequest
resp apiStruct.ReduceUserRegisterAddFriendIDListResponse // resp apiStruct.ReduceUserRegisterAddFriendIDListResponse
) )
if err := c.BindJSON(&req); err != nil { if err := c.BindJSON(&req); err != nil {
log.NewError("0", utils.GetSelfFuncName(), err.Error()) log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
openIMHttp.RespHttp200(c, constant.ErrArgs, nil) c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return return
} }
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), req) log.NewInfo(req.OperationID, utils.GetSelfFuncName(), req)
@ -138,13 +137,13 @@ func ReduceUserRegisterAddFriendIDList(c *gin.Context) {
return return
} }
client := pbAdmin.NewAdminCMSClient(etcdConn) 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 { if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "rpc failed", err.Error()) 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 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) { func GetUserRegisterAddFriendIDList(c *gin.Context) {
@ -153,8 +152,8 @@ func GetUserRegisterAddFriendIDList(c *gin.Context) {
resp apiStruct.GetUserRegisterAddFriendIDListResponse resp apiStruct.GetUserRegisterAddFriendIDListResponse
) )
if err := c.BindJSON(&req); err != nil { if err := c.BindJSON(&req); err != nil {
log.NewError("0", utils.GetSelfFuncName(), err.Error()) log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
openIMHttp.RespHttp200(c, constant.ErrArgs, nil) c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return return
} }
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), req) log.NewInfo(req.OperationID, utils.GetSelfFuncName(), req)
@ -172,12 +171,12 @@ func GetUserRegisterAddFriendIDList(c *gin.Context) {
}}) }})
if err != nil { if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "rpc failed", err.Error()) 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 return
} }
resp.Users = respPb.UserInfoList resp.Users = respPb.UserInfoList
resp.ShowNumber = int(respPb.Pagination.ShowNumber) resp.ShowNumber = int(respPb.Pagination.ShowNumber)
resp.CurrentPage = int(respPb.Pagination.CurrentPage) resp.CurrentPage = int(respPb.Pagination.CurrentPage)
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), resp) 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 ( import (
"Open_IM/pkg/cms_api_struct" "Open_IM/pkg/cms_api_struct"
"Open_IM/pkg/common/config" "Open_IM/pkg/common/config"
"Open_IM/pkg/common/constant"
openIMHttp "Open_IM/pkg/common/http"
"Open_IM/pkg/common/log" "Open_IM/pkg/common/log"
"Open_IM/pkg/grpc-etcdv3/getcdv3" "Open_IM/pkg/grpc-etcdv3/getcdv3"
commonPb "Open_IM/pkg/proto/sdk_ws" commonPb "Open_IM/pkg/proto/sdk_ws"
@ -18,51 +16,15 @@ import (
"github.com/gin-gonic/gin" "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) { func GetGroups(c *gin.Context) {
var ( var (
req cms_api_struct.GetGroupsRequest req cms_api_struct.GetGroupsRequest
resp cms_api_struct.GetGroupsResponse resp cms_api_struct.GetGroupsResponse
reqPb pbGroup.GetGroupsReq reqPb pbGroup.GetGroupsReq
) )
if err := c.ShouldBindQuery(&req); err != nil { if err := c.BindJSON(&req); err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "ShouldBindQuery failed ", err.Error()) log.NewError(req.OperationID, utils.GetSelfFuncName(), "ShouldBindQuery failed ", err.Error())
openIMHttp.RespHttp200(c, constant.ErrArgs, nil) c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return return
} }
reqPb.OperationID = utils.OperationIDGenerator() reqPb.OperationID = utils.OperationIDGenerator()
@ -76,11 +38,13 @@ func GetGroups(c *gin.Context) {
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg}) c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
return return
} }
reqPb.GroupID = req.GroupID
reqPb.GroupName = req.GroupName
client := pbGroup.NewGroupClient(etcdConn) client := pbGroup.NewGroupClient(etcdConn)
respPb, err := client.GetGroups(context.Background(), &reqPb) respPb, err := client.GetGroups(context.Background(), &reqPb)
if err != nil { if err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "GetUserInfo failed ", err.Error()) 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 return
} }
for _, v := range respPb.CMSGroups { for _, v := range respPb.CMSGroups {
@ -91,95 +55,10 @@ func GetGroups(c *gin.Context) {
resp.Groups = append(resp.Groups, groupResp) resp.Groups = append(resp.Groups, groupResp)
} }
resp.GroupNums = int(respPb.GroupNum) resp.GroupNums = int(respPb.GroupNum)
resp.CurrentPage = int(respPb.Pagination.PageNumber) resp.CurrentPage = int(respPb.Pagination.CurrentPage)
resp.ShowNumber = int(respPb.Pagination.ShowNumber) resp.ShowNumber = int(respPb.Pagination.ShowNumber)
log.NewInfo("", utils.GetSelfFuncName(), "resp: ", resp) log.NewInfo(req.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 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)
} }
func GetGroupMembers(c *gin.Context) { func GetGroupMembers(c *gin.Context) {
@ -188,9 +67,9 @@ func GetGroupMembers(c *gin.Context) {
reqPb pbGroup.GetGroupMembersCMSReq reqPb pbGroup.GetGroupMembersCMSReq
resp cms_api_struct.GetGroupMembersResponse resp cms_api_struct.GetGroupMembersResponse
) )
if err := c.ShouldBindQuery(&req); err != nil { if err := c.BindJSON(&req); err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "ShouldBindQuery failed ", err.Error()) 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 return
} }
reqPb.OperationID = utils.OperationIDGenerator() reqPb.OperationID = utils.OperationIDGenerator()
@ -212,7 +91,7 @@ func GetGroupMembers(c *gin.Context) {
respPb, err := client.GetGroupMembersCMS(context.Background(), &reqPb) respPb, err := client.GetGroupMembersCMS(context.Background(), &reqPb)
if err != nil { if err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "GetGroupMembersCMS failed:", err.Error()) 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 return
} }
resp.ResponsePagination = cms_api_struct.ResponsePagination{ resp.ResponsePagination = cms_api_struct.ResponsePagination{
@ -226,179 +105,5 @@ func GetGroupMembers(c *gin.Context) {
resp.GroupMembers = append(resp.GroupMembers, memberResp) resp.GroupMembers = append(resp.GroupMembers, memberResp)
} }
log.NewInfo("", utils.GetSelfFuncName(), "req: ", resp) log.NewInfo("", utils.GetSelfFuncName(), "req: ", resp)
openIMHttp.RespHttp200(c, constant.OK, resp) c.JSON(http.StatusOK, gin.H{"errCode": respPb.CommonResp.ErrCode, "errMsg": respPb.CommonResp.ErrMsg, "data": 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)
} }

@ -3,96 +3,27 @@ package messageCMS
import ( import (
"Open_IM/pkg/cms_api_struct" "Open_IM/pkg/cms_api_struct"
"Open_IM/pkg/common/config" "Open_IM/pkg/common/config"
openIMHttp "Open_IM/pkg/common/http"
"Open_IM/pkg/common/log" "Open_IM/pkg/common/log"
"Open_IM/pkg/grpc-etcdv3/getcdv3" "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" pbCommon "Open_IM/pkg/proto/sdk_ws"
"Open_IM/pkg/utils" "Open_IM/pkg/utils"
"context" "context"
"net/http" "net/http"
"strings" "strings"
"Open_IM/pkg/common/constant"
"github.com/gin-gonic/gin" "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) { func GetChatLogs(c *gin.Context) {
var ( var (
req cms_api_struct.GetChatLogsRequest req cms_api_struct.GetChatLogsReq
resp cms_api_struct.GetChatLogsResponse resp cms_api_struct.GetChatLogsResp
reqPb pbMessage.GetChatLogsReq 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()) 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 return
} }
reqPb.Pagination = &pbCommon.RequestPagination{ reqPb.Pagination = &pbCommon.RequestPagination{
@ -101,39 +32,28 @@ func GetChatLogs(c *gin.Context) {
} }
utils.CopyStructFields(&reqPb, &req) utils.CopyStructFields(&reqPb, &req)
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "req: ", 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 { if etcdConn == nil {
errMsg := reqPb.OperationID + "getcdv3.GetDefaultConn == nil" errMsg := reqPb.OperationID + "getcdv3.GetDefaultConn == nil"
log.NewError(reqPb.OperationID, errMsg) log.NewError(reqPb.OperationID, errMsg)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg}) c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
return return
} }
client := pbMessage.NewMessageCMSClient(etcdConn) client := pbAdminCMS.NewAdminCMSClient(etcdConn)
respPb, err := client.GetChatLogs(context.Background(), &reqPb) respPb, err := client.GetChatLogs(context.Background(), &reqPb)
if err != nil { if err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "GetChatLogs rpc failed", err.Error()) 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 return
} }
//utils.CopyStructFields(&resp, &respPb) for _, v := range respPb.ChatLogs {
for _, chatLog := range respPb.ChatLogs { chatLog := cms_api_struct.ChatLog{}
resp.ChatLogs = append(resp.ChatLogs, cms_api_struct.ChatLog{ utils.CopyStructFields(&chatLog, v)
SessionType: int(chatLog.SessionType), resp.ChatLogs = append(resp.ChatLogs, &chatLog)
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,
})
} }
resp.ShowNumber = int(respPb.Pagination.ShowNumber) resp.ShowNumber = int(respPb.Pagination.ShowNumber)
resp.CurrentPage = int(respPb.Pagination.CurrentPage) resp.CurrentPage = int(respPb.Pagination.CurrentPage)
resp.ChatLogsNum = int(respPb.ChatLogsNum) resp.ChatLogsNum = int(respPb.ChatLogsNum)
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "resp", resp) 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 package middleware
import ( import (
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/http"
"Open_IM/pkg/common/log" "Open_IM/pkg/common/log"
"Open_IM/pkg/common/token_verify" "Open_IM/pkg/common/token_verify"
"Open_IM/pkg/utils" "Open_IM/pkg/utils"
"net/http"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
func JWTAuth() gin.HandlerFunc { func JWTAuth() gin.HandlerFunc {
return func(c *gin.Context) { return func(c *gin.Context) {
ok, userID, errInfo := token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), "") 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) c.Set("userID", userID)
if !ok { if !ok {
log.NewError("", "GetUserIDFromToken false ", c.Request.Header.Get("token")) log.NewError("", "GetUserIDFromToken false ", c.Request.Header.Get("token"))
c.Abort() c.Abort()
http.RespHttp200(c, constant.ErrParseToken, nil) c.JSON(http.StatusOK, gin.H{"errCode": 400, "errMsg": errInfo})
return return
} else { } else {
log.NewInfo("0", utils.GetSelfFuncName(), "failed: ", errInfo) 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 ( import (
"Open_IM/internal/cms_api/admin" "Open_IM/internal/cms_api/admin"
"Open_IM/internal/cms_api/friend"
"Open_IM/internal/cms_api/group" "Open_IM/internal/cms_api/group"
messageCMS "Open_IM/internal/cms_api/message_cms" messageCMS "Open_IM/internal/cms_api/message_cms"
"Open_IM/internal/cms_api/middleware" "Open_IM/internal/cms_api/middleware"
"Open_IM/internal/cms_api/organization"
"Open_IM/internal/cms_api/statistics" "Open_IM/internal/cms_api/statistics"
"Open_IM/internal/cms_api/user" "Open_IM/internal/cms_api/user"
"Open_IM/internal/demo/register"
"github.com/gin-gonic/gin" "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("/add_user_register_add_friend_id", admin.AddUserRegisterAddFriendIDList)
adminRouterGroup.POST("/reduce_user_register_reduce_friend_id", admin.ReduceUserRegisterAddFriendIDList) adminRouterGroup.POST("/reduce_user_register_reduce_friend_id", admin.ReduceUserRegisterAddFriendIDList)
adminRouterGroup.POST("/get_user_register_reduce_friend_id_list", admin.GetUserRegisterAddFriendIDList) 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 := router.Group("")
r2.Use(middleware.JWTAuth()) r2.Use(middleware.JWTAuth())
statisticsRouterGroup := r2.Group("/statistics") statisticsRouterGroup := r2.Group("/statistics")
{ {
statisticsRouterGroup.GET("/get_messages_statistics", statistics.GetMessagesStatistics) statisticsRouterGroup.POST("/get_messages_statistics", statistics.GetMessagesStatistics)
statisticsRouterGroup.GET("/get_user_statistics", statistics.GetUserStatistics) statisticsRouterGroup.POST("/get_user_statistics", statistics.GetUserStatistics)
statisticsRouterGroup.GET("/get_group_statistics", statistics.GetGroupStatistics) statisticsRouterGroup.POST("/get_group_statistics", statistics.GetGroupStatistics)
statisticsRouterGroup.GET("/get_active_user", statistics.GetActiveUser) statisticsRouterGroup.POST("/get_active_user", statistics.GetActiveUser)
statisticsRouterGroup.GET("/get_active_group", statistics.GetActiveGroup) statisticsRouterGroup.POST("/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)
} }
groupRouterGroup := r2.Group("/group") groupRouterGroup := r2.Group("/group")
{ {
groupRouterGroup.GET("/get_group_by_id", group.GetGroupByID) groupRouterGroup.POST("/get_groups", group.GetGroups)
groupRouterGroup.GET("/get_groups", group.GetGroups) groupRouterGroup.POST("/get_group_members", group.GetGroupMembers)
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)
} }
userRouterGroup := r2.Group("/user") 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("/add_user", user.AddUser)
userRouterGroup.POST("/unblock_user", user.UnblockUser) userRouterGroup.POST("/unblock_user", user.UnblockUser)
userRouterGroup.POST("/block_user", user.BlockUser) userRouterGroup.POST("/block_user", user.BlockUser)
userRouterGroup.GET("/get_block_users", user.GetBlockUsers) userRouterGroup.POST("/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)
} }
messageCMSRouterGroup := r2.Group("/message") messageCMSRouterGroup := r2.Group("/message")
{ {
messageCMSRouterGroup.GET("/get_chat_logs", messageCMS.GetChatLogs) messageCMSRouterGroup.POST("/get_chat_logs", messageCMS.GetChatLogs)
messageCMSRouterGroup.POST("/broadcast_message", messageCMS.BroadcastMessage) }
messageCMSRouterGroup.POST("/mass_send_message", messageCMS.MassSendMassage) friendCMSRouterGroup := r2.Group("friend")
messageCMSRouterGroup.POST("/withdraw_message", messageCMS.WithdrawMessage) {
friendCMSRouterGroup.POST("/get_friends", friend.GetUserFriends)
} }
return baseRouter return baseRouter
} }

@ -3,15 +3,14 @@ package statistics
import ( import (
"Open_IM/pkg/cms_api_struct" "Open_IM/pkg/cms_api_struct"
"Open_IM/pkg/common/config" "Open_IM/pkg/common/config"
"Open_IM/pkg/common/constant"
openIMHttp "Open_IM/pkg/common/http"
"Open_IM/pkg/common/log" "Open_IM/pkg/common/log"
"Open_IM/pkg/grpc-etcdv3/getcdv3" "Open_IM/pkg/grpc-etcdv3/getcdv3"
pb "Open_IM/pkg/proto/statistics" admin "Open_IM/pkg/proto/admin_cms"
"Open_IM/pkg/utils" "Open_IM/pkg/utils"
"context" "context"
"net/http" "net/http"
"strings" "strings"
"time"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
@ -20,38 +19,40 @@ func GetMessagesStatistics(c *gin.Context) {
var ( var (
req cms_api_struct.GetMessageStatisticsRequest req cms_api_struct.GetMessageStatisticsRequest
resp cms_api_struct.GetMessageStatisticsResponse resp cms_api_struct.GetMessageStatisticsResponse
reqPb pb.GetMessageStatisticsReq reqPb admin.GetMessageStatisticsReq
) )
reqPb.StatisticsReq = &pb.StatisticsReq{} reqPb.StatisticsReq = &admin.StatisticsReq{}
if err := c.ShouldBindQuery(&req); err != nil { if err := c.BindJSON(&req); err != nil {
log.NewError("0", utils.GetSelfFuncName(), "BindJSON failed ", err.Error()) log.NewError(req.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 return
} }
reqPb.OperationID = utils.OperationIDGenerator() reqPb.OperationID = utils.OperationIDGenerator()
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "req: ", req) log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "req: ", req)
utils.CopyStructFields(&reqPb.StatisticsReq, &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 { if etcdConn == nil {
errMsg := reqPb.OperationID + "getcdv3.GetDefaultConn == nil" errMsg := reqPb.OperationID + "getcdv3.GetDefaultConn == nil"
log.NewError(reqPb.OperationID, errMsg) log.NewError(reqPb.OperationID, errMsg)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg}) c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
return return
} }
client := pb.NewUserClient(etcdConn) client := admin.NewAdminCMSClient(etcdConn)
respPb, err := client.GetMessageStatistics(context.Background(), &reqPb) ctx, cancel := context.WithTimeout(context.TODO(), time.Second*100)
defer cancel()
respPb, err := client.GetMessageStatistics(ctx, &reqPb)
if err != nil { if err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "GetMessageStatistics failed", err.Error()) 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 return
} }
// utils.CopyStructFields(&resp, respPb)
resp.GroupMessageNum = int(respPb.GroupMessageNum) resp.GroupMessageNum = int(respPb.GroupMessageNum)
resp.PrivateMessageNum = int(respPb.PrivateMessageNum) resp.PrivateMessageNum = int(respPb.PrivateMessageNum)
for _, v := range respPb.PrivateMessageNumList { for _, v := range respPb.PrivateMessageNumList {
resp.PrivateMessageNumList = append(resp.PrivateMessageNumList, struct { resp.PrivateMessageNumList = append(resp.PrivateMessageNumList, struct {
Date string "json:\"date\"" Date string "json:\"date\""
MessageNum int "json:\"message_num\"" MessageNum int "json:\"messageNum\""
}{ }{
Date: v.Date, Date: v.Date,
MessageNum: int(v.Num), MessageNum: int(v.Num),
@ -60,53 +61,54 @@ func GetMessagesStatistics(c *gin.Context) {
for _, v := range respPb.GroupMessageNumList { for _, v := range respPb.GroupMessageNumList {
resp.GroupMessageNumList = append(resp.GroupMessageNumList, struct { resp.GroupMessageNumList = append(resp.GroupMessageNumList, struct {
Date string "json:\"date\"" Date string "json:\"date\""
MessageNum int "json:\"message_num\"" MessageNum int "json:\"messageNum\""
}{ }{
Date: v.Date, Date: v.Date,
MessageNum: int(v.Num), MessageNum: int(v.Num),
}) })
} }
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "resp: ", resp) 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) { func GetUserStatistics(c *gin.Context) {
var ( var (
req cms_api_struct.GetUserStatisticsRequest req cms_api_struct.GetUserStatisticsRequest
resp cms_api_struct.GetUserStatisticsResponse resp cms_api_struct.GetUserStatisticsResponse
reqPb pb.GetUserStatisticsReq reqPb admin.GetUserStatisticsReq
) )
reqPb.StatisticsReq = &pb.StatisticsReq{} reqPb.StatisticsReq = &admin.StatisticsReq{}
if err := c.ShouldBindQuery(&req); err != nil { if err := c.BindJSON(&req); err != nil {
log.NewError("0", utils.GetSelfFuncName(), "BindJSON failed ", err.Error()) log.NewError(req.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 return
} }
reqPb.OperationID = utils.OperationIDGenerator() reqPb.OperationID = utils.OperationIDGenerator()
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "req: ", req) log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "req: ", req)
utils.CopyStructFields(&reqPb.StatisticsReq, &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 { if etcdConn == nil {
errMsg := reqPb.OperationID + "getcdv3.GetDefaultConn == nil" errMsg := reqPb.OperationID + "getcdv3.GetDefaultConn == nil"
log.NewError(reqPb.OperationID, errMsg) log.NewError(reqPb.OperationID, errMsg)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg}) c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
return return
} }
client := pb.NewUserClient(etcdConn) client := admin.NewAdminCMSClient(etcdConn)
respPb, err := client.GetUserStatistics(context.Background(), &reqPb) ctx, cancel := context.WithTimeout(context.TODO(), time.Second*100)
defer cancel()
respPb, err := client.GetUserStatistics(ctx, &reqPb)
if err != nil { if err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "GetUserStatistics failed", err.Error()) log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "GetUserStatistics failed", err.Error(), reqPb.String())
openIMHttp.RespHttp200(c, err, nil) c.JSON(http.StatusBadRequest, gin.H{"errCode": 500, "errMsg": err.Error()})
return return
} }
// utils.CopyStructFields(&resp, respPb)
resp.ActiveUserNum = int(respPb.ActiveUserNum) resp.ActiveUserNum = int(respPb.ActiveUserNum)
resp.IncreaseUserNum = int(respPb.IncreaseUserNum) resp.IncreaseUserNum = int(respPb.IncreaseUserNum)
resp.TotalUserNum = int(respPb.TotalUserNum) resp.TotalUserNum = int(respPb.TotalUserNum)
for _, v := range respPb.ActiveUserNumList { for _, v := range respPb.ActiveUserNumList {
resp.ActiveUserNumList = append(resp.ActiveUserNumList, struct { resp.ActiveUserNumList = append(resp.ActiveUserNumList, struct {
Date string "json:\"date\"" Date string "json:\"date\""
ActiveUserNum int "json:\"active_user_num\"" ActiveUserNum int "json:\"activeUserNum\""
}{ }{
Date: v.Date, Date: v.Date,
ActiveUserNum: int(v.Num), ActiveUserNum: int(v.Num),
@ -115,7 +117,7 @@ func GetUserStatistics(c *gin.Context) {
for _, v := range respPb.IncreaseUserNumList { for _, v := range respPb.IncreaseUserNumList {
resp.IncreaseUserNumList = append(resp.IncreaseUserNumList, struct { resp.IncreaseUserNumList = append(resp.IncreaseUserNumList, struct {
Date string "json:\"date\"" Date string "json:\"date\""
IncreaseUserNum int "json:\"increase_user_num\"" IncreaseUserNum int "json:\"increaseUserNum\""
}{ }{
Date: v.Date, Date: v.Date,
IncreaseUserNum: int(v.Num), IncreaseUserNum: int(v.Num),
@ -124,43 +126,45 @@ func GetUserStatistics(c *gin.Context) {
for _, v := range respPb.TotalUserNumList { for _, v := range respPb.TotalUserNumList {
resp.TotalUserNumList = append(resp.TotalUserNumList, struct { resp.TotalUserNumList = append(resp.TotalUserNumList, struct {
Date string "json:\"date\"" Date string "json:\"date\""
TotalUserNum int "json:\"total_user_num\"" TotalUserNum int "json:\"totalUserNum\""
}{ }{
Date: v.Date, Date: v.Date,
TotalUserNum: int(v.Num), TotalUserNum: int(v.Num),
}) })
} }
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "resp: ", resp) 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) { func GetGroupStatistics(c *gin.Context) {
var ( var (
req cms_api_struct.GetGroupStatisticsRequest req cms_api_struct.GetGroupStatisticsRequest
resp cms_api_struct.GetGroupStatisticsResponse resp cms_api_struct.GetGroupStatisticsResponse
reqPb pb.GetGroupStatisticsReq reqPb admin.GetGroupStatisticsReq
) )
reqPb.StatisticsReq = &pb.StatisticsReq{} reqPb.StatisticsReq = &admin.StatisticsReq{}
if err := c.ShouldBindQuery(&req); err != nil { if err := c.BindJSON(&req); err != nil {
log.NewError("0", "BindJSON failed ", err.Error()) log.NewError(req.OperationID, "BindJSON failed ", err.Error())
openIMHttp.RespHttp200(c, constant.ErrArgs, nil) c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return return
} }
reqPb.OperationID = utils.OperationIDGenerator() reqPb.OperationID = utils.OperationIDGenerator()
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "req: ", req) log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "req: ", req)
utils.CopyStructFields(&reqPb.StatisticsReq, &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 { if etcdConn == nil {
errMsg := reqPb.OperationID + "getcdv3.GetDefaultConn == nil" errMsg := reqPb.OperationID + "getcdv3.GetDefaultConn == nil"
log.NewError(reqPb.OperationID, errMsg) log.NewError(reqPb.OperationID, errMsg)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg}) c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
return return
} }
client := pb.NewUserClient(etcdConn) client := admin.NewAdminCMSClient(etcdConn)
respPb, err := client.GetGroupStatistics(context.Background(), &reqPb) ctx, cancel := context.WithTimeout(context.TODO(), time.Second*100)
defer cancel()
respPb, err := client.GetGroupStatistics(ctx, &reqPb)
if err != nil { if err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "GetGroupStatistics failed", err.Error()) 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 return
} }
// utils.CopyStructFields(&resp, respPb) // utils.CopyStructFields(&resp, respPb)
@ -170,7 +174,7 @@ func GetGroupStatistics(c *gin.Context) {
resp.IncreaseGroupNumList = append(resp.IncreaseGroupNumList, resp.IncreaseGroupNumList = append(resp.IncreaseGroupNumList,
struct { struct {
Date string "json:\"date\"" Date string "json:\"date\""
IncreaseGroupNum int "json:\"increase_group_num\"" IncreaseGroupNum int "json:\"increaseGroupNum\""
}{ }{
Date: v.Date, Date: v.Date,
IncreaseGroupNum: int(v.Num), IncreaseGroupNum: int(v.Num),
@ -180,7 +184,7 @@ func GetGroupStatistics(c *gin.Context) {
resp.TotalGroupNumList = append(resp.TotalGroupNumList, resp.TotalGroupNumList = append(resp.TotalGroupNumList,
struct { struct {
Date string "json:\"date\"" Date string "json:\"date\""
TotalGroupNum int "json:\"total_group_num\"" TotalGroupNum int "json:\"totalGroupNum\""
}{ }{
Date: v.Date, Date: v.Date,
TotalGroupNum: int(v.Num), TotalGroupNum: int(v.Num),
@ -188,77 +192,81 @@ func GetGroupStatistics(c *gin.Context) {
} }
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "resp: ", resp) 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) { func GetActiveUser(c *gin.Context) {
var ( var (
req cms_api_struct.GetActiveUserRequest req cms_api_struct.GetActiveUserRequest
resp cms_api_struct.GetActiveUserResponse resp cms_api_struct.GetActiveUserResponse
reqPb pb.GetActiveUserReq reqPb admin.GetActiveUserReq
) )
reqPb.StatisticsReq = &pb.StatisticsReq{} reqPb.StatisticsReq = &admin.StatisticsReq{}
if err := c.ShouldBindQuery(&req); err != nil { if err := c.BindJSON(&req); err != nil {
log.NewError("0", "BindJSON failed ", err.Error()) log.NewError(req.OperationID, "BindJSON failed ", err.Error())
openIMHttp.RespHttp200(c, constant.ErrArgs, nil) c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return return
} }
reqPb.OperationID = utils.OperationIDGenerator() reqPb.OperationID = utils.OperationIDGenerator()
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "req: ", req) log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "req: ", req)
utils.CopyStructFields(&reqPb.StatisticsReq, 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 { if etcdConn == nil {
errMsg := reqPb.OperationID + "getcdv3.GetDefaultConn == nil" errMsg := reqPb.OperationID + "getcdv3.GetDefaultConn == nil"
log.NewError(reqPb.OperationID, errMsg) log.NewError(reqPb.OperationID, errMsg)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg}) c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
return return
} }
client := pb.NewUserClient(etcdConn) client := admin.NewAdminCMSClient(etcdConn)
respPb, err := client.GetActiveUser(context.Background(), &reqPb) ctx, cancel := context.WithTimeout(context.TODO(), time.Second*100)
defer cancel()
respPb, err := client.GetActiveUser(ctx, &reqPb)
if err != nil { if err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "GetActiveUser failed ", err.Error()) 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 return
} }
utils.CopyStructFields(&resp.ActiveUserList, respPb.Users) utils.CopyStructFields(&resp.ActiveUserList, respPb.Users)
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "resp: ", resp) 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) { func GetActiveGroup(c *gin.Context) {
var ( var (
req cms_api_struct.GetActiveGroupRequest req cms_api_struct.GetActiveGroupRequest
resp cms_api_struct.GetActiveGroupResponse resp cms_api_struct.GetActiveGroupResponse
reqPb pb.GetActiveGroupReq reqPb admin.GetActiveGroupReq
) )
reqPb.StatisticsReq = &pb.StatisticsReq{} reqPb.StatisticsReq = &admin.StatisticsReq{}
if err := c.ShouldBindQuery(&req); err != nil { if err := c.BindJSON(&req); err != nil {
log.NewError("0", utils.GetSelfFuncName(), "BindJSON failed ", err.Error()) log.NewError(req.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 return
} }
reqPb.OperationID = utils.OperationIDGenerator() reqPb.OperationID = utils.OperationIDGenerator()
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "req: ", req) log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "req: ", req)
utils.CopyStructFields(&reqPb.StatisticsReq, 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 { if etcdConn == nil {
errMsg := reqPb.OperationID + "getcdv3.GetDefaultConn == nil" errMsg := reqPb.OperationID + "getcdv3.GetDefaultConn == nil"
log.NewError(reqPb.OperationID, errMsg) log.NewError(reqPb.OperationID, errMsg)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg}) c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
return return
} }
client := pb.NewUserClient(etcdConn) client := admin.NewAdminCMSClient(etcdConn)
respPb, err := client.GetActiveGroup(context.Background(), &reqPb) ctx, cancel := context.WithTimeout(context.TODO(), time.Second*100)
defer cancel()
respPb, err := client.GetActiveGroup(ctx, &reqPb)
if err != nil { if err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "GetActiveGroup failed ", err.Error()) 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 return
} }
for _, group := range respPb.Groups { for _, group := range respPb.Groups {
resp.ActiveGroupList = append(resp.ActiveGroupList, struct { resp.ActiveGroupList = append(resp.ActiveGroupList, struct {
GroupName string "json:\"group_name\"" GroupName string "json:\"groupName\""
GroupId string "json:\"group_id\"" GroupId string "json:\"groupID\""
MessageNum int "json:\"message_num\"" MessageNum int "json:\"messageNum\""
}{ }{
GroupName: group.GroupName, GroupName: group.GroupName,
GroupId: group.GroupId, GroupId: group.GroupId,
@ -266,5 +274,5 @@ func GetActiveGroup(c *gin.Context) {
}) })
} }
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "resp: ", resp) 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 ( import (
"Open_IM/pkg/cms_api_struct" "Open_IM/pkg/cms_api_struct"
"Open_IM/pkg/common/config" "Open_IM/pkg/common/config"
"Open_IM/pkg/common/constant"
openIMHttp "Open_IM/pkg/common/http"
"Open_IM/pkg/common/log" "Open_IM/pkg/common/log"
"Open_IM/pkg/grpc-etcdv3/getcdv3" "Open_IM/pkg/grpc-etcdv3/getcdv3"
commonPb "Open_IM/pkg/proto/sdk_ws" commonPb "Open_IM/pkg/proto/sdk_ws"
pb "Open_IM/pkg/proto/user" pb "Open_IM/pkg/proto/user"
"Open_IM/pkg/utils" "Open_IM/pkg/utils"
"context" "context"
"fmt"
"net/http" "net/http"
"strings" "strings"
"github.com/gin-gonic/gin" "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) { func AddUser(c *gin.Context) {
var ( var (
req cms_api_struct.AddUserRequest req cms_api_struct.AddUserRequest
@ -200,7 +22,7 @@ func AddUser(c *gin.Context) {
) )
if err := c.BindJSON(&req); err != nil { if err := c.BindJSON(&req); err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "BindJSON failed ", err.Error()) 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 return
} }
reqPb.OperationID = utils.OperationIDGenerator() reqPb.OperationID = utils.OperationIDGenerator()
@ -214,24 +36,23 @@ func AddUser(c *gin.Context) {
return return
} }
client := pb.NewUserClient(etcdConn) client := pb.NewUserClient(etcdConn)
_, err := client.AddUser(context.Background(), &reqPb) respPb, err := client.AddUser(context.Background(), &reqPb)
if err != nil { 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 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) { func BlockUser(c *gin.Context) {
var ( var (
req cms_api_struct.BlockUserRequest req cms_api_struct.BlockUserRequest
resp cms_api_struct.BlockUserResponse
reqPb pb.BlockUserReq reqPb pb.BlockUserReq
) )
if err := c.BindJSON(&req); err != nil { if err := c.BindJSON(&req); err != nil {
fmt.Println(err) log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
log.NewError("0", "BindJSON failed ", err.Error()) c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
openIMHttp.RespHttp200(c, constant.ErrArgs, resp)
return return
} }
reqPb.OperationID = utils.OperationIDGenerator() reqPb.OperationID = utils.OperationIDGenerator()
@ -245,13 +66,13 @@ func BlockUser(c *gin.Context) {
return return
} }
client := pb.NewUserClient(etcdConn) client := pb.NewUserClient(etcdConn)
fmt.Println(reqPb) respPb, err := client.BlockUser(context.Background(), &reqPb)
_, err := client.BlockUser(context.Background(), &reqPb)
if err != nil { 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 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) { func UnblockUser(c *gin.Context) {
@ -260,9 +81,9 @@ func UnblockUser(c *gin.Context) {
resp cms_api_struct.UnBlockUserResponse resp cms_api_struct.UnBlockUserResponse
reqPb pb.UnBlockUserReq reqPb pb.UnBlockUserReq
) )
if err := c.ShouldBind(&req); err != nil { if err := c.BindJSON(&req); err != nil {
log.NewError("0", "BindJSON failed ", err.Error()) log.NewError(req.OperationID, "BindJSON failed ", err.Error())
openIMHttp.RespHttp200(c, constant.ErrArgs, resp) c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return return
} }
reqPb.OperationID = utils.OperationIDGenerator() reqPb.OperationID = utils.OperationIDGenerator()
@ -276,13 +97,14 @@ func UnblockUser(c *gin.Context) {
return return
} }
client := pb.NewUserClient(etcdConn) client := pb.NewUserClient(etcdConn)
_, err := client.UnBlockUser(context.Background(), &reqPb) respPb, err := client.UnBlockUser(context.Background(), &reqPb)
if err != nil { 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 return
} }
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "resp: ", resp) 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) { func GetBlockUsers(c *gin.Context) {
@ -293,9 +115,9 @@ func GetBlockUsers(c *gin.Context) {
respPb *pb.GetBlockUsersResp respPb *pb.GetBlockUsersResp
) )
reqPb.Pagination = &commonPb.RequestPagination{} 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()) 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 return
} }
reqPb.OperationID = utils.OperationIDGenerator() reqPb.OperationID = utils.OperationIDGenerator()
@ -313,21 +135,18 @@ func GetBlockUsers(c *gin.Context) {
respPb, err := client.GetBlockUsers(context.Background(), &reqPb) respPb, err := client.GetBlockUsers(context.Background(), &reqPb)
if err != nil { if err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "GetBlockUsers rpc", err.Error()) 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 return
} }
for _, v := range respPb.BlockUsers { for _, v := range respPb.BlockUsers {
resp.BlockUsers = append(resp.BlockUsers, cms_api_struct.BlockUser{ resp.BlockUsers = append(resp.BlockUsers, cms_api_struct.BlockUser{
UserResponse: cms_api_struct.UserResponse{ UserResponse: cms_api_struct.UserResponse{
UserId: v.User.UserId, UserID: v.UserInfo.UserID,
ProfilePhoto: v.User.ProfilePhoto, FaceURL: v.UserInfo.FaceURL,
Nickname: v.User.Nickname, Nickname: v.UserInfo.Nickname,
IsBlock: v.User.IsBlock, PhoneNumber: v.UserInfo.PhoneNumber,
Birth: v.User.Birth, Email: v.UserInfo.Email,
PhoneNumber: v.User.PhoneNumber, Gender: int(v.UserInfo.Gender),
Email: v.User.Email,
Gender: int(v.User.Gender),
CreateTime: v.User.CreateTime,
}, },
BeginDisableTime: v.BeginDisableTime, BeginDisableTime: v.BeginDisableTime,
EndDisableTime: v.EndDisableTime, EndDisableTime: v.EndDisableTime,
@ -337,70 +156,5 @@ func GetBlockUsers(c *gin.Context) {
resp.CurrentPage = int(respPb.Pagination.CurrentPage) resp.CurrentPage = int(respPb.Pagination.CurrentPage)
resp.UserNums = respPb.UserNums resp.UserNums = respPb.UserNums
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "req: ", resp) log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "req: ", resp)
openIMHttp.RespHttp200(c, constant.OK, resp) c.JSON(http.StatusOK, gin.H{"errCode": respPb.CommonResp.ErrCode, "errMsg": respPb.CommonResp.ErrMsg, "data": 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)
} }

@ -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" imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
"Open_IM/pkg/common/log" "Open_IM/pkg/common/log"
"Open_IM/pkg/utils" "Open_IM/pkg/utils"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
//"github.com/jinzhu/gorm" //"github.com/jinzhu/gorm"
"net/http" "net/http"
"time" "time"
@ -141,7 +143,7 @@ func QueryUserIDLimitLogin(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"errCode": 0, "errMsg": "", "data": resp}) c.JSON(http.StatusOK, gin.H{"errCode": 0, "errMsg": "", "data": resp})
return 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 { type AddUserIPLimitLoginReq struct {
@ -164,7 +166,7 @@ func AddUserIPLimitLogin(c *gin.Context) {
userIp := db.UserIpLimit{UserID: req.UserID, Ip: req.IP} userIp := db.UserIpLimit{UserID: req.UserID, Ip: req.IP}
err := imdb.UpdateUserInfo(db.User{ err := imdb.UpdateUserInfo(db.User{
UserID: req.UserID, UserID: req.UserID,
LoginLimit: 1, // LoginLimit: 1,
}) })
if err != nil { if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.UserID) 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" imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
http2 "Open_IM/pkg/common/http" http2 "Open_IM/pkg/common/http"
"Open_IM/pkg/common/log" "Open_IM/pkg/common/log"
"Open_IM/pkg/common/token_verify"
pbFriend "Open_IM/pkg/proto/friend" pbFriend "Open_IM/pkg/proto/friend"
"Open_IM/pkg/utils" "Open_IM/pkg/utils"
"encoding/json" "encoding/json"
@ -41,12 +42,14 @@ func SetPassword(c *gin.Context) {
c.JSON(http.StatusBadRequest, gin.H{"errCode": constant.FormattingError, "errMsg": err.Error()}) c.JSON(http.StatusBadRequest, gin.H{"errCode": constant.FormattingError, "errMsg": err.Error()})
return return
} }
ip := c.Request.Header.Get("X-Forward-For") ip := c.Request.Header.Get("X-Forward-For")
if ip == "" { if ip == "" {
ip = c.ClientIP() ip = c.ClientIP()
} }
log.NewDebug(params.OperationID, utils.GetSelfFuncName(), "ip:", ip) log.NewDebug(params.OperationID, utils.GetSelfFuncName(), "ip:", ip)
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) Limited, LimitError := imdb.IsLimitRegisterIp(ip)
if LimitError != nil { if LimitError != nil {
log.Error(params.OperationID, utils.GetSelfFuncName(), LimitError, ip) log.Error(params.OperationID, utils.GetSelfFuncName(), LimitError, ip)
@ -57,12 +60,15 @@ func SetPassword(c *gin.Context) {
c.JSON(http.StatusBadRequest, gin.H{"errCode": constant.RegisterLimit, "errMsg": "limited"}) c.JSON(http.StatusBadRequest, gin.H{"errCode": constant.RegisterLimit, "errMsg": "limited"})
return return
} }
}
openIMRegisterReq := api.UserRegisterReq{}
var account string var account string
if params.Email != "" { if params.Email != "" {
account = params.Email account = params.Email
openIMRegisterReq.Email = params.Email
} else if params.PhoneNumber != "" { } else if params.PhoneNumber != "" {
account = params.PhoneNumber account = params.PhoneNumber
openIMRegisterReq.PhoneNumber = params.PhoneNumber
} else { } else {
account = params.UserID account = params.UserID
} }
@ -84,7 +90,7 @@ func SetPassword(c *gin.Context) {
if config.Config.Demo.NeedInvitationCode && params.InvitationCode != "" { if config.Config.Demo.NeedInvitationCode && params.InvitationCode != "" {
err := imdb.CheckInvitationCode(params.InvitationCode) err := imdb.CheckInvitationCode(params.InvitationCode)
if err != nil { 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 return
} }
} }
@ -99,18 +105,13 @@ func SetPassword(c *gin.Context) {
} else { } else {
userID = params.UserID userID = params.UserID
} }
url := config.Config.Demo.ImAPIURL + "/auth/user_register" url := config.Config.Demo.ImAPIURL + "/auth/user_register"
openIMRegisterReq := api.UserRegisterReq{}
openIMRegisterReq.OperationID = params.OperationID openIMRegisterReq.OperationID = params.OperationID
openIMRegisterReq.Platform = params.Platform openIMRegisterReq.Platform = params.Platform
openIMRegisterReq.UserID = userID openIMRegisterReq.UserID = userID
openIMRegisterReq.Nickname = params.Nickname openIMRegisterReq.Nickname = params.Nickname
openIMRegisterReq.Secret = config.Config.Secret openIMRegisterReq.Secret = config.Config.Secret
openIMRegisterReq.FaceURL = params.FaceURL openIMRegisterReq.FaceURL = params.FaceURL
openIMRegisterReq.CreateIp = ip
openIMRegisterReq.LastLoginIp = ip
openIMRegisterReq.InvitationCode = params.InvitationCode
openIMRegisterResp := api.UserRegisterResp{} openIMRegisterResp := api.UserRegisterResp{}
log.NewDebug(params.OperationID, utils.GetSelfFuncName(), "register req:", openIMRegisterReq) log.NewDebug(params.OperationID, utils.GetSelfFuncName(), "register req:", openIMRegisterReq)
bMsg, err := http2.Post(url, openIMRegisterReq, 2) 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) log.NewError(params.OperationID, "request openIM register error", account, "err", "resp: ", openIMRegisterResp.ErrCode)
if err != nil { if err != nil {
log.NewError(params.OperationID, utils.GetSelfFuncName(), err.Error()) log.NewError(params.OperationID, utils.GetSelfFuncName(), err.Error())
} c.JSON(http.StatusOK, gin.H{"errCode": constant.RegisterFailed, "errMsg": "register limit"})
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": "邀请码错误"})
return return
} else { }
if openIMRegisterResp.ErrCode != 0 {
c.JSON(http.StatusOK, gin.H{"errCode": constant.RegisterFailed, "errMsg": "register failed: " + openIMRegisterResp.ErrMsg}) c.JSON(http.StatusOK, gin.H{"errCode": constant.RegisterFailed, "errMsg": "register failed: " + openIMRegisterResp.ErrMsg})
return return
} }
@ -150,8 +147,11 @@ func SetPassword(c *gin.Context) {
imdb.FinishInvitationCode(params.InvitationCode, userID) 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 // demo onboarding
if params.UserID == "" && config.Config.Demo.OnboardProcess { if params.UserID == "" && config.Config.Demo.OnboardProcess {
select { select {
@ -168,6 +168,7 @@ func SetPassword(c *gin.Context) {
} }
} }
// register add friend
select { select {
case ChImportFriend <- &pbFriend.ImportFriendReq{ case ChImportFriend <- &pbFriend.ImportFriendReq{
OperationID: params.OperationID, OperationID: params.OperationID,

@ -3,8 +3,8 @@ package admin_cms
import ( import (
"Open_IM/pkg/common/config" "Open_IM/pkg/common/config"
"Open_IM/pkg/common/constant" "Open_IM/pkg/common/constant"
"Open_IM/pkg/common/db"
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model" 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/log"
"Open_IM/pkg/common/token_verify" "Open_IM/pkg/common/token_verify"
"Open_IM/pkg/grpc-etcdv3/getcdv3" "Open_IM/pkg/grpc-etcdv3/getcdv3"
@ -12,11 +12,15 @@ import (
server_api_params "Open_IM/pkg/proto/sdk_ws" server_api_params "Open_IM/pkg/proto/sdk_ws"
"Open_IM/pkg/utils" "Open_IM/pkg/utils"
"context" "context"
"errors"
"net" "net"
"strconv" "strconv"
"strings" "strings"
"sync"
"time"
"google.golang.org/grpc" "google.golang.org/grpc"
"gorm.io/gorm"
) )
type adminCMSServer struct { type adminCMSServer struct {
@ -81,23 +85,26 @@ func (s *adminCMSServer) Run() {
func (s *adminCMSServer) AdminLogin(_ context.Context, req *pbAdminCMS.AdminLoginReq) (*pbAdminCMS.AdminLoginResp, error) { func (s *adminCMSServer) AdminLogin(_ context.Context, req *pbAdminCMS.AdminLoginReq) (*pbAdminCMS.AdminLoginResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String()) 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 { for i, adminID := range config.Config.Manager.AppManagerUid {
if adminID == req.AdminID && config.Config.Manager.Secrets[i] == req.Secret { if adminID == req.AdminID && config.Config.Manager.Secrets[i] == req.Secret {
token, expTime, err := token_verify.CreateToken(adminID, constant.SingleChatType) 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 { if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "generate token failed", "adminID: ", adminID, err.Error()) 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 resp.Token = token
break break
} }
} }
if resp.Token == "" { if resp.Token == "" {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "failed") 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()) log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
return resp, nil 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) { func (s *adminCMSServer) AddUserRegisterAddFriendIDList(_ context.Context, req *pbAdminCMS.AddUserRegisterAddFriendIDListReq) (*pbAdminCMS.AddUserRegisterAddFriendIDListResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String()) 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 { if err := imdb.AddUserRegisterAddFriendIDList(req.UserIDList...); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.UserIDList) 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()) log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", req.String())
return resp, nil 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) { func (s *adminCMSServer) ReduceUserRegisterAddFriendIDList(_ context.Context, req *pbAdminCMS.ReduceUserRegisterAddFriendIDListReq) (*pbAdminCMS.ReduceUserRegisterAddFriendIDListResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String()) log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
resp := &pbAdminCMS.ReduceUserRegisterAddFriendIDListResp{} resp := &pbAdminCMS.ReduceUserRegisterAddFriendIDListResp{CommonResp: &pbAdminCMS.CommonResp{}}
if req.Operation == 0 { if req.Operation == 0 {
if err := imdb.ReduceUserRegisterAddFriendIDList(req.UserIDList...); err != nil { if err := imdb.ReduceUserRegisterAddFriendIDList(req.UserIDList...); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.UserIDList) 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 { } else {
if err := imdb.DeleteAllRegisterAddFriendIDList(); err != nil { if err := imdb.DeleteAllRegisterAddFriendIDList(); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.UserIDList) 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()) 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) { func (s *adminCMSServer) GetUserRegisterAddFriendIDList(_ context.Context, req *pbAdminCMS.GetUserRegisterAddFriendIDListReq) (*pbAdminCMS.GetUserRegisterAddFriendIDListResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String()) 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) userIDList, err := imdb.GetRegisterAddFriendList(req.Pagination.ShowNumber, req.Pagination.PageNumber)
if err != nil { if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error()) 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) userList, err := imdb.GetUsersByUserIDList(userIDList)
if err != nil { if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), userIDList) resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
return resp, openIMHttp.WrapError(constant.ErrDB) resp.CommonResp.ErrMsg = err.Error()
return resp, nil
} }
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), userList, userIDList) log.NewDebug(req.OperationID, utils.GetSelfFuncName(), userList, userIDList)
resp.Pagination = &server_api_params.ResponsePagination{ 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()) log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", req.String())
return resp, nil 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)) user.Birth = utils.UnixSecondToTime(int64(req.UserInfo.Birth))
} }
log.Debug(req.OperationID, "copy ", user, req.UserInfo) 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) err := imdb.UserRegister(user)
if err != nil { 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 errMsg := req.OperationID + " imdb.UserRegister failed " + err.Error() + user.UserID
log.NewError(req.OperationID, errMsg, user) log.NewError(req.OperationID, errMsg, user)
return &pbAuth.UserRegisterResp{CommonResp: &pbAuth.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}}, nil 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{}}) log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc return ", pbAuth.UserRegisterResp{CommonResp: &pbAuth.CommonResp{}})
return &pbAuth.UserRegisterResp{CommonResp: &pbAuth.CommonResp{}}, nil return &pbAuth.UserRegisterResp{CommonResp: &pbAuth.CommonResp{}}, nil
} }
func (rpc *rpcAuth) UserToken(_ context.Context, req *pbAuth.UserTokenReq) (*pbAuth.UserTokenResp, error) { func (rpc *rpcAuth) UserToken(_ context.Context, req *pbAuth.UserTokenReq) (*pbAuth.UserTokenResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc args ", req.String()) 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)) tokens, expTime, err := token_verify.CreateToken(req.FromUserID, int(req.Platform))
if err != nil { if err != nil {
errMsg := req.OperationID + " token_verify.CreateToken failed " + err.Error() + req.FromUserID + utils.Int32ToString(req.Platform) errMsg := req.OperationID + " token_verify.CreateToken failed " + err.Error() + req.FromUserID + utils.Int32ToString(req.Platform)
log.NewError(req.OperationID, errMsg) log.NewError(req.OperationID, errMsg)
return &pbAuth.UserTokenResp{CommonResp: &pbAuth.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}}, nil 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}) 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 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/constant"
"Open_IM/pkg/common/db" "Open_IM/pkg/common/db"
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model" imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
"Open_IM/pkg/common/db/rocks_cache" rocksCache "Open_IM/pkg/common/db/rocks_cache"
"Open_IM/pkg/common/http"
"Open_IM/pkg/common/log" "Open_IM/pkg/common/log"
"Open_IM/pkg/common/token_verify" "Open_IM/pkg/common/token_verify"
cp "Open_IM/pkg/common/utils" cp "Open_IM/pkg/common/utils"
@ -19,12 +18,15 @@ import (
pbUser "Open_IM/pkg/proto/user" pbUser "Open_IM/pkg/proto/user"
"Open_IM/pkg/utils" "Open_IM/pkg/utils"
"context" "context"
"google.golang.org/grpc" "errors"
"math/big" "math/big"
"net" "net"
"strconv" "strconv"
"strings" "strings"
"time" "time"
"google.golang.org/grpc"
"gorm.io/gorm"
) )
type groupServer struct { type groupServer struct {
@ -121,7 +123,7 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR
err := imdb.InsertIntoGroup(groupInfo) err := imdb.InsertIntoGroup(groupInfo)
if err != nil { if err != nil {
log.NewError(req.OperationID, "InsertIntoGroup failed, ", err.Error(), groupInfo) 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 var okUserIDList []string
resp := &pbGroup.CreateGroupResp{GroupInfo: &open_im_sdk.GroupInfo{}} 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) us, err = imdb.GetUserByUserID(req.OwnerUserID)
if err != nil { if err != nil {
log.NewError(req.OperationID, "GetUserByUserID failed ", err.Error(), req.OwnerUserID) 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 //to group member
groupMember = db.GroupMember{GroupID: groupId, RoleLevel: constant.GroupOwner, OperatorUserID: req.OpUserID, JoinSource: constant.JoinByInvitation, InviterUserID: req.OpUserID} 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) err = imdb.InsertIntoGroupMember(groupMember)
if err != nil { if err != nil {
log.NewError(req.OperationID, "InsertIntoGroupMember failed ", err.Error(), groupMember) 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) resp.Id2ResultList = append(resp.Id2ResultList, &resultNode)
continue 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 // return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
} else { } else {
var resultNode pbGroup.Id2Result 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) { func (s *groupServer) GroupApplicationResponse(_ context.Context, req *pbGroup.GroupApplicationResponseReq) (*pbGroup.GroupApplicationResponseResp, error) {
log.NewInfo(req.OperationID, "GroupApplicationResponse args ", req.String()) log.NewInfo(req.OperationID, "GroupApplicationResponse args ", req.String())
groupRequest := db.GroupRequest{} groupRequest := db.GroupRequest{}
utils.CopyStructFields(&groupRequest, req) utils.CopyStructFields(&groupRequest, req)
groupRequest.UserID = req.FromUserID 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) group, err := imdb.GetGroupInfoByGroupID(req.GroupInfoForSet.GroupID)
if err != nil { if err != nil {
log.NewError(req.OperationID, "GetGroupInfoByGroupID failed ", err.Error(), req.GroupInfoForSet.GroupID) 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 { 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 m["need_verification"] = req.GroupInfoForSet.NeedVerification.Value
if err := imdb.UpdateGroupInfoDefaultZero(req.GroupInfoForSet.GroupID, m); err != nil { if err := imdb.UpdateGroupInfoDefaultZero(req.GroupInfoForSet.GroupID, m); err != nil {
log.NewError(req.OperationID, "UpdateGroupInfoDefaultZero failed ", err.Error(), m) 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 { 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 m["look_member_info"] = req.GroupInfoForSet.LookMemberInfo.Value
if err := imdb.UpdateGroupInfoDefaultZero(req.GroupInfoForSet.GroupID, m); err != nil { if err := imdb.UpdateGroupInfoDefaultZero(req.GroupInfoForSet.GroupID, m); err != nil {
log.NewError(req.OperationID, "UpdateGroupInfoDefaultZero failed ", err.Error(), m) 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 { 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 m["apply_member_friend"] = req.GroupInfoForSet.ApplyMemberFriend.Value
if err := imdb.UpdateGroupInfoDefaultZero(req.GroupInfoForSet.GroupID, m); err != nil { if err := imdb.UpdateGroupInfoDefaultZero(req.GroupInfoForSet.GroupID, m); err != nil {
log.NewError(req.OperationID, "UpdateGroupInfoDefaultZero failed ", err.Error(), m) 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) err = imdb.SetGroupInfo(groupInfo)
if err != nil { if err != nil {
log.NewError(req.OperationID, "SetGroupInfo failed ", err.Error(), groupInfo) 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 { if err := rocksCache.DelGroupInfoFromCache(req.GroupInfoForSet.GroupID); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "DelGroupInfoFromCache failed ", err.Error(), req.GroupInfoForSet.GroupID) 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{}}) 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 { if etcdConn == nil {
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil" errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
log.NewError(req.OperationID, errMsg) 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) client := pbCache.NewCacheClient(etcdConn)
cacheResp, err := client.GetGroupMemberIDListFromCache(context.Background(), getGroupMemberIDListFromCacheReq) cacheResp, err := client.GetGroupMemberIDListFromCache(context.Background(), getGroupMemberIDListFromCacheReq)
@ -1281,7 +1282,7 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInf
if etcdConn == nil { if etcdConn == nil {
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil" errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
log.NewError(req.OperationID, errMsg) 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) nClient := pbConversation.NewConversationClient(nEtcdConn)
conversationReply, err := nClient.ModifyConversationField(context.Background(), &conversationReq) 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) { func (s *groupServer) GetGroups(_ context.Context, req *pbGroup.GetGroupsReq) (*pbGroup.GetGroupsResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String()) log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "GetGroups ", req.String())
resp := &pbGroup.GetGroupByIDResp{CMSGroup: &pbGroup.CMSGroup{ resp := &pbGroup.GetGroupsResp{
GroupInfo: &open_im_sdk.GroupInfo{}, CommonResp: &pbGroup.CommonResp{},
}} CMSGroups: []*pbGroup.CMSGroup{},
group, err := imdb.GetGroupInfoByGroupID(req.GroupID) Pagination: &open_im_sdk.ResponsePagination{CurrentPage: req.Pagination.PageNumber, ShowNumber: req.Pagination.ShowNumber},
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) if req.GroupID != "" {
groupMember, err := imdb.GetGroupOwnerInfoByGroupID(group.GroupID) groupInfoDB, err := imdb.GetGroupInfoByGroupID(req.GroupID)
if err != nil { if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupMaster", err.Error()) if errors.Is(err, gorm.ErrRecordNotFound) {
return resp, http.WrapError(constant.ErrDB) return resp, nil
} }
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) 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.CMSGroup.GroupOwnerUserName = groupMember.Nickname resp.GroupNum = 1
resp.CMSGroup.GroupOwnerUserID = groupMember.UserID groupInfo := &open_im_sdk.GroupInfo{}
resp.CMSGroup.GroupInfo.CreatorUserID = group.CreatorUserID utils.CopyStructFields(groupInfo, groupInfoDB)
resp.CMSGroup.GroupInfo.CreateTime = uint32(group.CreateTime.Unix()) groupMember, err := imdb.GetGroupOwnerInfoByGroupID(req.GroupID)
utils.CopyStructFields(resp.CMSGroup.GroupInfo, group) if err != nil {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String()) log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
resp.CommonResp.ErrMsg = err.Error()
return resp, nil 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{},
} }
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) groups, err := imdb.GetGroupsByName(req.GroupName, req.Pagination.PageNumber, req.Pagination.ShowNumber)
if err != nil { if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupsByName error", req.String(), req.GroupName, req.Pagination.PageNumber, req.Pagination.ShowNumber) 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 { for _, v := range groups {
group := &pbGroup.CMSGroup{GroupInfo: &open_im_sdk.GroupInfo{}} group := &pbGroup.CMSGroup{GroupInfo: &open_im_sdk.GroupInfo{}}
utils.CopyStructFields(group.GroupInfo, v) utils.CopyStructFields(group.GroupInfo, v)
groupMember, err := imdb.GetGroupOwnerInfoByGroupID(v.GroupID) groupMember, err := imdb.GetGroupOwnerInfoByGroupID(v.GroupID)
if err != nil { if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupMaster error", err.Error()) log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupOwnerInfoByGroupID failed", err.Error(), v)
continue continue
} }
group.GroupInfo.CreateTime = uint32(v.CreateTime.Unix()) group.GroupInfo.CreateTime = uint32(v.CreateTime.Unix())
group.GroupOwnerUserID = groupMember.UserID group.GroupOwnerUserID = groupMember.UserID
group.GroupOwnerUserName = groupMember.Nickname group.GroupOwnerUserName = groupMember.Nickname
resp.CMSGroups = append(resp.CMSGroups, group) resp.CMSGroups = append(resp.CMSGroups, group)
} }
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String()) resp.GroupNum, err = imdb.GetGroupsCountNum(db.Group{GroupName: req.GroupName})
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{
CMSGroups: []*pbGroup.CMSGroup{},
Pagination: &open_im_sdk.RequestPagination{},
}
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 { if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupsCountNum error", err.Error()) log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupsCountNum error", err.Error())
return resp, http.WrapError(constant.ErrDB) resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
} resp.CommonResp.ErrMsg = err.Error()
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 err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupMaster 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)
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "GetGroups ", resp.String())
return resp, nil 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")
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
} }
} }
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "GetGroups resp", resp.String())
return resp, nil return resp, nil
} }
func (s *groupServer) GetGroupMembersCMS(_ context.Context, req *pbGroup.GetGroupMembersCMSReq) (*pbGroup.GetGroupMembersCMSResp, error) { func (s *groupServer) GetGroupMembersCMS(_ context.Context, req *pbGroup.GetGroupMembersCMSReq) (*pbGroup.GetGroupMembersCMSResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "args:", req.String()) 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) groupMembers, err := imdb.GetGroupMembersByGroupIdCMS(req.GroupID, req.UserName, req.Pagination.ShowNumber, req.Pagination.PageNumber)
if err != nil { if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupMembersByGroupIdCMS Error", err.Error()) 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) groupMembersCount, err := imdb.GetGroupMembersCount(req.GroupID, req.UserName)
if err != nil { if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupMembersCMS Error", err.Error()) 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) log.NewInfo(req.OperationID, groupMembersCount)
resp.MemberNums = int32(groupMembersCount) resp.MemberNums = int32(groupMembersCount)
@ -1502,151 +1430,6 @@ func (s *groupServer) GetGroupMembersCMS(_ context.Context, req *pbGroup.GetGrou
return resp, nil 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) { func (s *groupServer) GetUserReqApplicationList(_ context.Context, req *pbGroup.GetUserReqApplicationListReq) (*pbGroup.GetUserReqApplicationListResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String()) log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
resp := &pbGroup.GetUserReqApplicationListResp{} 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" "Open_IM/pkg/common/db"
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model" imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
rocksCache "Open_IM/pkg/common/db/rocks_cache" rocksCache "Open_IM/pkg/common/db/rocks_cache"
errors "Open_IM/pkg/common/http"
"Open_IM/pkg/common/log" "Open_IM/pkg/common/log"
"Open_IM/pkg/common/token_verify" "Open_IM/pkg/common/token_verify"
"Open_IM/pkg/grpc-etcdv3/getcdv3" "Open_IM/pkg/grpc-etcdv3/getcdv3"
@ -17,12 +16,13 @@ import (
pbUser "Open_IM/pkg/proto/user" pbUser "Open_IM/pkg/proto/user"
"Open_IM/pkg/utils" "Open_IM/pkg/utils"
"context" "context"
"errors"
"net" "net"
"strconv" "strconv"
"strings" "strings"
"time"
"google.golang.org/grpc" "google.golang.org/grpc"
"gorm.io/gorm"
) )
type userServer struct { type userServer struct {
@ -335,27 +335,6 @@ func (s *userServer) SetRecvMsgOpt(ctx context.Context, req *pbUser.SetRecvMsgOp
return resp, nil 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) { func (s *userServer) GetAllUserID(_ context.Context, req *pbUser.GetAllUserIDReq) (*pbUser.GetAllUserIDResp, error) {
log.NewInfo(req.OperationID, "GetAllUserID args ", req.String()) log.NewInfo(req.OperationID, "GetAllUserID args ", req.String())
if !token_verify.IsManagerUserID(req.OpUserID) { if !token_verify.IsManagerUserID(req.OpUserID) {
@ -543,217 +522,172 @@ func (s *userServer) SyncJoinedGroupMemberNickname(userID string, newNickname, o
} }
} }
func (s *userServer) GetUsersByName(ctx context.Context, req *pbUser.GetUsersByNameReq) (*pbUser.GetUsersByNameResp, error) { func (s *userServer) GetUsers(ctx context.Context, req *pbUser.GetUsersReq) (*pbUser.GetUsersResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req:", req.String()) log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
resp := &pbUser.GetUsersByNameResp{} resp := &pbUser.GetUsersResp{CommonResp: &pbUser.CommonResp{}, Pagination: &sdkws.ResponsePagination{CurrentPage: req.Pagination.PageNumber, ShowNumber: req.Pagination.ShowNumber}}
users, err := imdb.GetUserByName(req.UserName, req.Pagination.ShowNumber, req.Pagination.PageNumber) if req.UserID != "" {
userDB, err := imdb.GetUserByUserID(req.UserID)
if err != nil { if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserByName failed", err.Error()) if errors.Is(err, gorm.ErrRecordNotFound) {
return resp, errors.WrapError(constant.ErrDB) return resp, nil
} }
for _, user := range users { log.NewError(req.OperationID, utils.GetSelfFuncName(), req.UserID, err.Error())
isBlock, err := imdb.UserIsBlock(user.UserID) resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
if err != nil { resp.CommonResp.ErrMsg = constant.ErrDB.ErrMsg
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error()) return resp, nil
continue
} }
resp.Users = append(resp.Users, &pbUser.User{
ProfilePhoto: user.FaceURL, user := pbUser.CmsUser{User: &sdkws.UserInfo{}}
Nickname: user.Nickname, utils.CopyStructFields(&user.User, userDB)
UserId: user.UserID, user.User.CreateTime = uint32(userDB.CreateTime.Unix())
CreateTime: user.CreateTime.Format("2006-01-02 15:04:05"), resp.UserList = append(resp.UserList, &user)
CreateIp: user.CreateIp, resp.TotalNums = 1
IsBlock: isBlock, } else if req.UserName != "" {
Birth: user.Birth.Format("2006-01-02"), usersDB, err := imdb.GetUserByName(req.UserName, req.Pagination.ShowNumber, req.Pagination.PageNumber)
PhoneNumber: user.PhoneNumber, if err != nil {
Email: user.Email, log.NewError(req.OperationID, utils.GetSelfFuncName(), req.UserName, req.Pagination.ShowNumber, req.Pagination.PageNumber, err.Error())
LastLoginIp: user.LastLoginIp, resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
LastLoginTime: user.LastLoginTime.Format("2006-01-02 15:04:05"), resp.CommonResp.ErrMsg = constant.ErrDB.ErrMsg
LoginTimes: user.LoginTimes, return resp, nil
Gender: user.Gender,
LoginLimit: user.LoginLimit,
})
} }
user := db.User{Nickname: req.UserName} resp.TotalNums, err = imdb.GetUsersCount(req.UserName)
userNums, err := imdb.GetUsersCount(user)
if err != nil { if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "", err.Error()) log.NewError(req.OperationID, utils.GetSelfFuncName(), req.UserName, err.Error())
return resp, errors.WrapError(constant.ErrDB) resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
resp.CommonResp.ErrMsg = err.Error()
return resp, nil
} }
resp.UserNums = userNums for _, userDB := range usersDB {
resp.Pagination = &sdkws.ResponsePagination{ var user sdkws.UserInfo
CurrentPage: req.Pagination.PageNumber, utils.CopyStructFields(&user, userDB)
ShowNumber: req.Pagination.ShowNumber, user.CreateTime = uint32(userDB.CreateTime.Unix())
resp.UserList = append(resp.UserList, &pbUser.CmsUser{User: &user})
} }
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp) } 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 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)
}
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,
} }
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String()) resp.TotalNums, err = imdb.GetTotalUserNum()
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)
if err != nil { if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUsers failed", err.Error()) log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
return resp, errors.WrapError(constant.ErrDB) resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
resp.CommonResp.ErrMsg = err.Error()
return resp, nil
} }
for _, userDB := range usersDB {
for _, v := range users { var user sdkws.UserInfo
isBlock, err := imdb.UserIsBlock(v.UserID) utils.CopyStructFields(&user, userDB)
if err == nil { user.CreateTime = uint32(userDB.CreateTime.Unix())
registerIP := "" resp.UserList = append(resp.UserList, &pbUser.CmsUser{User: &user})
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())
} }
} }
user := db.User{} var userIDList []string
nums, err := imdb.GetUsersCount(user) for _, v := range resp.UserList {
if err != nil { userIDList = append(userIDList, v.User.UserID)
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUsersCount failed", err.Error(), user)
return resp, errors.WrapError(constant.ErrDB)
} }
resp.UserNums = nums isBlockUser, err := imdb.UsersIsBlock(userIDList)
resp.Pagination = &sdkws.ResponsePagination{ShowNumber: req.Pagination.ShowNumber, CurrentPage: req.Pagination.PageNumber} if err != nil {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String()) log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), userIDList)
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
resp.CommonResp.ErrMsg = err.Error()
return resp, nil 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) { for _, v := range resp.UserList {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String()) if utils.IsContain(v.User.UserID, isBlockUser) {
resp := &pbUser.AlterUserResp{} v.IsBlock = true
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()) log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
return resp, nil return resp, nil
} }
func (s *userServer) AddUser(ctx context.Context, req *pbUser.AddUserReq) (*pbUser.AddUserResp, error) { func (s *userServer) AddUser(ctx context.Context, req *pbUser.AddUserReq) (*pbUser.AddUserResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String()) log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
resp := &pbUser.AddUserResp{} resp := &pbUser.AddUserResp{CommonResp: &pbUser.CommonResp{}}
err := imdb.AddUser(req.UserId, req.PhoneNumber, req.Name, req.Email, req.Gender, req.Photo, req.Birth) 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 { if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "AddUser", err.Error()) log.NewError(req.OperationID, utils.GetSelfFuncName(), "AddUser", err.Error(), req.String())
return resp, errors.WrapError(constant.ErrDB) resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
resp.CommonResp.ErrMsg = err.Error()
return resp, nil
} }
return resp, nil return resp, nil
} }
func (s *userServer) BlockUser(ctx context.Context, req *pbUser.BlockUserReq) (*pbUser.BlockUserResp, error) { func (s *userServer) BlockUser(ctx context.Context, req *pbUser.BlockUserReq) (*pbUser.BlockUserResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String()) log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
resp := &pbUser.BlockUserResp{} resp := &pbUser.BlockUserResp{CommonResp: &pbUser.CommonResp{}}
err := imdb.BlockUser(req.UserId, req.EndDisableTime) err := imdb.BlockUser(req.UserID, req.EndDisableTime)
if err != nil { if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "BlockUser", err.Error()) log.NewError(req.OperationID, utils.GetSelfFuncName(), "BlockUser", err.Error(), req.UserID, req.EndDisableTime)
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 return resp, nil
} }
func (s *userServer) UnBlockUser(ctx context.Context, req *pbUser.UnBlockUserReq) (*pbUser.UnBlockUserResp, error) { func (s *userServer) UnBlockUser(ctx context.Context, req *pbUser.UnBlockUserReq) (*pbUser.UnBlockUserResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String()) log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
resp := &pbUser.UnBlockUserResp{} resp := &pbUser.UnBlockUserResp{CommonResp: &pbUser.CommonResp{}}
err := imdb.UnBlockUser(req.UserId) err := imdb.UnBlockUser(req.UserID)
if err != nil { if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "unBlockUser", err.Error()) 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 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()) log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
resp := &pbUser.GetBlockUsersResp{} resp = &pbUser.GetBlockUsersResp{CommonResp: &pbUser.CommonResp{}, Pagination: &sdkws.ResponsePagination{ShowNumber: req.Pagination.ShowNumber, CurrentPage: req.Pagination.PageNumber}}
blockUsers, err := imdb.GetBlockUsers(req.Pagination.ShowNumber, req.Pagination.PageNumber) var blockUsers []imdb.BlockUserInfo
if req.UserID != "" {
blockUser, err := imdb.GetBlockUserByID(req.UserID)
if err != nil { if err != nil {
log.Error(req.OperationID, utils.GetSelfFuncName(), "GetBlockUsers", err.Error()) if errors.Is(err, gorm.ErrRecordNotFound) {
return resp, errors.WrapError(constant.ErrDB) 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 { for _, v := range blockUsers {
resp.BlockUsers = append(resp.BlockUsers, &pbUser.BlockUser{ resp.BlockUsers = append(resp.BlockUsers, &pbUser.BlockUser{
User: &pbUser.User{ UserInfo: &sdkws.UserInfo{
ProfilePhoto: v.User.FaceURL, FaceURL: v.User.FaceURL,
Nickname: v.User.Nickname, Nickname: v.User.Nickname,
UserId: v.User.UserID, UserID: v.User.UserID,
IsBlock: true,
Birth: v.User.Birth.Format("2006-01-02"),
PhoneNumber: v.User.PhoneNumber, PhoneNumber: v.User.PhoneNumber,
Email: v.User.Email, Email: v.User.Email,
Gender: v.User.Gender, Gender: v.User.Gender,
@ -762,51 +696,6 @@ func (s *userServer) GetBlockUsers(ctx context.Context, req *pbUser.GetBlockUser
EndDisableTime: (v.EndDisableTime).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) log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
return resp, nil 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 CommResp
Status int32 `json:"status"` 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"`
}

@ -14,14 +14,9 @@ type ApiUserInfo struct {
PhoneNumber string `json:"phoneNumber" binding:"omitempty,max=32"` PhoneNumber string `json:"phoneNumber" binding:"omitempty,max=32"`
Birth uint32 `json:"birth" binding:"omitempty"` Birth uint32 `json:"birth" binding:"omitempty"`
Email string `json:"email" binding:"omitempty,max=64"` Email string `json:"email" binding:"omitempty,max=64"`
CreateIp string `json:"createIp" binding:"omitempty,max=15"`
CreateTime int64 `json:"createTime"` 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"` LoginLimit int32 `json:"loginLimit" binding:"omitempty"`
Ex string `json:"ex" binding:"omitempty,max=1024"` Ex string `json:"ex" binding:"omitempty,max=1024"`
InvitationCode string `json:"invitationCode" binding:"omitempty"`
} }
//type Conversation struct { //type Conversation struct {

@ -1,10 +1,14 @@
package cms_api_struct 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 { type AdminLoginRequest struct {
AdminName string `json:"admin_name" binding:"required"` AdminName string `json:"adminID" binding:"required"`
Secret string `json:"secret" binding:"required"` Secret string `json:"secret" binding:"required"`
OperationID string `json:"operationID" binding:"required"`
} }
type AdminLoginResponse struct { type AdminLoginResponse struct {
@ -30,10 +34,10 @@ type ReduceUserRegisterAddFriendIDListResponse struct {
type GetUserRegisterAddFriendIDListRequest struct { type GetUserRegisterAddFriendIDListRequest struct {
OperationID string `json:"operationID" binding:"required"` OperationID string `json:"operationID" binding:"required"`
RequestPaginationBody base_info.RequestPagination
} }
type GetUserRegisterAddFriendIDListResponse struct { type GetUserRegisterAddFriendIDListResponse struct {
Users []*server_api_params.UserInfo `json:"users"` Users []*server_api_params.UserInfo `json:"users"`
ResponsePagination base_info.ResponsePagination
} }

@ -1,16 +1,11 @@
package cms_api_struct package cms_api_struct
type RequestPagination struct { type RequestPagination struct {
PageNumber int `form:"page_number" binding:"required"`
ShowNumber int `form:"show_number" binding:"required"`
}
type RequestPaginationBody struct {
PageNumber int `json:"pageNumber" binding:"required"` PageNumber int `json:"pageNumber" binding:"required"`
ShowNumber int `json:"showNumber" binding:"required"` ShowNumber int `json:"showNumber" binding:"required"`
} }
type ResponsePagination struct { type ResponsePagination struct {
CurrentPage int `json:"current_number" binding:"required"` CurrentPage int `json:"currentPage"`
ShowNumber int `json:"show_number" binding:"required"` ShowNumber int `json:"showNumber"`
} }

@ -0,0 +1,25 @@
package cms_api_struct
type GetFriendsReq struct {
OperationID string `json:"operationID"`
UserID string `json:"userID"`
FriendUserName string `json:"friendUserName"`
FriendUserID string `json:"friendUserID"`
RequestPagination
}
type FriendInfo struct {
OwnerUserID string `json:"ownerUserID"`
Remark string `json:"remark"`
CreateTime uint32 `json:"createTime"`
UserID string `json:"userID"`
Nickname string `json:"nickName"`
AddSource int32 `json:"addSource"`
OperatorUserID string `json:"operatorUserID"`
}
type GetFriendsResp struct {
ResponsePagination
FriendInfoList []*FriendInfo `json:"friendInfoList"`
FriendNums int32 `json:"friendNums"`
}

@ -3,7 +3,6 @@ package cms_api_struct
type GroupResponse struct { type GroupResponse struct {
GroupOwnerName string `json:"GroupOwnerName"` GroupOwnerName string `json:"GroupOwnerName"`
GroupOwnerID string `json:"GroupOwnerID"` GroupOwnerID string `json:"GroupOwnerID"`
//*server_api_params.GroupInfo
GroupID string `json:"groupID"` GroupID string `json:"groupID"`
GroupName string `json:"groupName"` GroupName string `json:"groupName"`
Notification string `json:"notification"` Notification string `json:"notification"`
@ -23,27 +22,11 @@ type GroupResponse struct {
NotificationUserID string `json:"notificationUserID"` 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 { type GetGroupsRequest struct {
RequestPagination RequestPagination
OperationID string `json:"operationID" binding:"required"`
GroupID string `json:"groupID"`
GroupName string `json:"groupName"`
} }
type GetGroupsResponse struct { type GetGroupsResponse struct {
@ -52,55 +35,10 @@ type GetGroupsResponse struct {
ResponsePagination 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 { type GetGroupMembersRequest struct {
GroupID string `form:"groupID" binding:"required"` GroupID string `form:"groupID" binding:"required"`
UserName string `form:"userName"` UserName string `form:"userName"`
OperationID string `json:"operationID" binding:"required"`
RequestPagination RequestPagination
} }
@ -124,41 +62,3 @@ type GetGroupMembersResponse struct {
ResponsePagination ResponsePagination
MemberNums int `json:"memberNums"` 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 package cms_api_struct
type BroadcastRequest struct { import (
Message string `json:"message"` pbCommon "Open_IM/pkg/proto/sdk_ws"
} )
type BroadcastResponse struct { type GetChatLogsReq struct {
} SessionType int `json:"sessionType"`
ContentType int `json:"contentType"`
type MassSendMassageRequest struct { Content string `json:"content"`
Message string `json:"message"` SendID string `json:"userID"`
Users []string `json:"users"` RecvID string `json:"recvID"`
} GroupID string `json:"groupID"`
SendTime string `json:"sendTime"`
type MassSendMassageResponse struct {
}
type GetChatLogsRequest struct {
SessionType int `form:"session_type"`
ContentType int `form:"content_type"`
Content string `form:"content"`
UserId string `form:"user_id"`
GroupId string `form:"group_id"`
Date string `form:"date"`
RequestPagination RequestPagination
OperationID string `json:"operationID"`
} }
type ChatLog struct { type ChatLog struct {
SessionType int `json:"session_type"` SendID string `json:"sendID,omitempty"`
ContentType int `json:"content_type"` RecvID string `json:"recvID,omitempty"`
SenderNickName string `json:"sender_nick_name"` GroupID string `json:"groupID,omitempty"`
SenderId string `json:"sender_id"` ClientMsgID string `json:"clientMsgID,omitempty"`
SearchContent string `json:"search_content"` ServerMsgID string `json:"serverMsgID,omitempty"`
WholeContent string `json:"whole_content"` SenderPlatformID int32 `json:"senderPlatformID,omitempty"`
SenderNickname string `json:"senderNickname,omitempty"`
ReceiverNickName string `json:"receiver_nick_name,omitempty"` SenderFaceURL string `json:"senderFaceURL,omitempty"`
ReceiverID string `json:"receiver_id,omitempty"` SessionType int32 `json:"sessionType,omitempty"`
MsgFrom int32 `json:"msgFrom,omitempty"`
GroupName string `json:"group_name,omitempty"` ContentType int32 `json:"contentType,omitempty"`
GroupId string `json:"group_id,omitempty"` Content string `json:"content,omitempty"`
Seq uint32 `json:"seq,omitempty"`
Date string `json:"date"` SendTime int64 `json:"sendTime,omitempty"`
CreateTime int64 `json:"createTime,omitempty"`
Status int32 `json:"status,omitempty"`
Options map[string]bool `json:"options,omitempty"`
OfflinePushInfo *pbCommon.OfflinePushInfo `json:"offlinePushInfo,omitempty"`
AtUserIDList []string `json:"atUserIDList,omitempty"`
MsgDataList []byte `json:"msgDataList,omitempty"`
AttachedInfo string `json:"attachedInfo,omitempty"`
Ex string `json:"ex,omitempty"`
} }
type GetChatLogsResponse struct { type GetChatLogsResp struct {
ChatLogs []ChatLog `json:"chat_logs"` ChatLogs []*ChatLog `json:"chatLogs"`
ChatLogsNum int `json:"log_nums"` ChatLogsNum int `json:"logNums"`
ResponsePagination ResponsePagination
} }

@ -1,25 +0,0 @@
package cms_api_struct
type GetStaffsResponse struct {
StaffsList []struct {
ProfilePhoto string `json:"profile_photo"`
NickName string `json:"nick_name"`
StaffId int `json:"staff_id"`
Position string `json:"position"`
EntryTime string `json:"entry_time"`
} `json:"staffs_list"`
}
type GetOrganizationsResponse struct {
OrganizationList []struct {
OrganizationId int `json:"organization_id"`
OrganizationName string `json:"organization_name"`
} `json:"organization_list"`
}
type SquadResponse struct {
SquadList []struct {
SquadId int `json:"squad_id"`
SquadName string `json:"squad_name"`
} `json:"squad_list"`
}

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

@ -1,79 +1,31 @@
package cms_api_struct package cms_api_struct
type UserResponse struct { type UserResponse struct {
ProfilePhoto string `json:"profile_photo"` FaceURL string `json:"faceURL"`
Nickname string `json:"nick_name"` Nickname string `json:"nickName"`
UserId string `json:"user_id"` UserID string `json:"userID"`
CreateTime string `json:"create_time,omitempty"` CreateTime string `json:"createTime,omitempty"`
CreateIp string `json:"create_ip,omitempty"` CreateIp string `json:"createIp,omitempty"`
LastLoginTime string `json:"last_login_time,omitempty"` LastLoginTime string `json:"lastLoginTime,omitempty"`
LastLoginIp string `json:"last_login_ip,omitempty"` LastLoginIp string `json:"lastLoginIP,omitempty"`
LoginTimes int32 `json:"login_times"` LoginTimes int32 `json:"loginTimes"`
LoginLimit int32 `json:"login_limit"` LoginLimit int32 `json:"loginLimit"`
IsBlock bool `json:"is_block"` IsBlock bool `json:"isBlock"`
PhoneNumber string `json:"phone_number"` PhoneNumber string `json:"phoneNumber"`
Email string `json:"email"` Email string `json:"email"`
Birth string `json:"birth"` Birth string `json:"birth"`
Gender int `json:"gender"` 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 { type AddUserRequest struct {
PhoneNumber string `json:"phone_number" binding:"required"` OperationID string `json:"operationID" binding:"required"`
UserId string `json:"user_id" binding:"required"` PhoneNumber string `json:"phoneNumber" binding:"required"`
UserId string `json:"userID" binding:"required"`
Name string `json:"name" binding:"required"` Name string `json:"name" binding:"required"`
Email string `json:"email"` Email string `json:"email"`
Birth string `json:"birth"` Birth string `json:"birth"`
Gender string `json:"gender"` Gender string `json:"gender"`
Photo string `json:"photo"` FaceURL string `json:"faceURL"`
} }
type AddUserResponse struct { type AddUserResponse struct {
@ -81,46 +33,34 @@ type AddUserResponse struct {
type BlockUser struct { type BlockUser struct {
UserResponse UserResponse
BeginDisableTime string `json:"begin_disable_time"` BeginDisableTime string `json:"beginDisableTime"`
EndDisableTime string `json:"end_disable_time"` EndDisableTime string `json:"endDisableTime"`
} }
type BlockUserRequest struct { type BlockUserRequest struct {
UserId string `json:"user_id" binding:"required"` OperationID string `json:"operationID" binding:"required"`
EndDisableTime string `json:"end_disable_time" binding:"required"` UserID string `json:"userID" binding:"required"`
EndDisableTime string `json:"endDisableTime" binding:"required"`
} }
type BlockUserResponse struct { type BlockUserResponse struct {
} }
type UnblockUserRequest 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 UnBlockUserResponse struct {
} }
type GetBlockUsersRequest struct { type GetBlockUsersRequest struct {
OperationID string `json:"operationID" binding:"required"`
RequestPagination RequestPagination
} }
type GetBlockUsersResponse struct { type GetBlockUsersResponse struct {
BlockUsers []BlockUser `json:"block_users"` BlockUsers []BlockUser `json:"blockUsers"`
ResponsePagination ResponsePagination
UserNums int32 `json:"user_nums"` UserNums int32 `json:"userNums"`
}
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 {
} }

@ -15,7 +15,7 @@ type Register struct {
type Invitation struct { type Invitation struct {
InvitationCode string `gorm:"column:invitation_code;primary_key;type:varchar(32)"` InvitationCode string `gorm:"column:invitation_code;primary_key;type:varchar(32)"`
CreateTime time.Time `gorm:"column:create_time"` 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"` LastTime time.Time `gorm:"column:last_time"`
Status int32 `gorm:"column:status"` Status int32 `gorm:"column:status"`
} }
@ -92,7 +92,7 @@ type Group struct {
Notification string `gorm:"column:notification;size:255" json:"notification"` Notification string `gorm:"column:notification;size:255" json:"notification"`
Introduction string `gorm:"column:introduction;size:255" json:"introduction"` Introduction string `gorm:"column:introduction;size:255" json:"introduction"`
FaceURL string `gorm:"column:face_url;size:255" json:"faceURL"` 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"` Ex string `gorm:"column:ex" json:"ex;size:1024" json:"ex"`
Status int32 `gorm:"column:status"` Status int32 `gorm:"column:status"`
CreatorUserID string `gorm:"column:creator_user_id;size:64"` CreatorUserID string `gorm:"column:creator_user_id;size:64"`
@ -176,16 +176,20 @@ type User struct {
Birth time.Time `gorm:"column:birth"` Birth time.Time `gorm:"column:birth"`
Email string `gorm:"column:email;size:64"` Email string `gorm:"column:email;size:64"`
Ex string `gorm:"column:ex;size:1024"` Ex string `gorm:"column:ex;size:1024"`
CreateTime time.Time `gorm:"column:create_time"` 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"`
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"` CreateIp string `gorm:"column:create_ip;size:15"`
LastLoginTime time.Time `gorm:"column:last_login_time"` LastLoginTime time.Time `gorm:"column:last_login_time"`
LastLoginIp string `gorm:"column:last_login_ip;size:15"` LastLoginIp string `gorm:"column:last_login_ip;size:15"`
LoginTimes int32 `gorm:"column:login_times"` LoginTimes int32 `gorm:"column:login_times"`
LoginLimit int32 `gorm:"column:login_limit"` LoginLimit int32 `gorm:"column:login_limit"`
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"`
} }
type IpLimit struct { type IpLimit struct {
@ -223,17 +227,17 @@ type Black struct {
type ChatLog struct { type ChatLog struct {
ServerMsgID string `gorm:"column:server_msg_id;primary_key;type:char(64)" json:"serverMsgID"` 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"` ClientMsgID string `gorm:"column:client_msg_id;type:char(64)" json:"clientMsgID"`
SendID string `gorm:"column:send_id;type:char(64)" json:"sendID"` 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)" json:"recvID"` 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"` SenderPlatformID int32 `gorm:"column:sender_platform_id" json:"senderPlatformID"`
SenderNickname string `gorm:"column:sender_nick_name;type:varchar(255)" json:"senderNickname"` SenderNickname string `gorm:"column:sender_nick_name;type:varchar(255)" json:"senderNickname"`
SenderFaceURL string `gorm:"column:sender_face_url;type:varchar(255)" json:"senderFaceURL"` SenderFaceURL string `gorm:"column:sender_face_url;type:varchar(255);" json:"senderFaceURL"`
SessionType int32 `gorm:"column:session_type" json:"sessionType"` 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"` 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"` Content string `gorm:"column:content;type:varchar(3000)" json:"content"`
Status int32 `gorm:"column:status" json:"status"` 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"` CreateTime time.Time `gorm:"column:create_time" json:"createTime"`
Ex string `gorm:"column:ex;type:varchar(1024)" json:"ex"` Ex string `gorm:"column:ex;type:varchar(1024)" json:"ex"`
} }

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

@ -3,6 +3,7 @@ package im_mysql_model
import ( import (
"Open_IM/pkg/common/db" "Open_IM/pkg/common/db"
"errors" "errors"
_ "gorm.io/gorm" _ "gorm.io/gorm"
) )
@ -74,3 +75,10 @@ func DeleteAllRegisterAddFriendIDList() error {
err := db.DB.MysqlDB.DefaultGormDB().Where("1 = 1").Delete(&db.RegisterAddFriend{}).Error err := db.DB.MysqlDB.DefaultGormDB().Where("1 = 1").Delete(&db.RegisterAddFriend{}).Error
return err 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 ( import (
"Open_IM/pkg/common/db" "Open_IM/pkg/common/db"
_ "github.com/jinzhu/gorm/dialects/mysql" "fmt"
"time" "time"
_ "github.com/jinzhu/gorm/dialects/mysql"
) )
func InsertToFriend(toInsertFollow *db.Friend) error { func InsertToFriend(toInsertFollow *db.Friend) error {
@ -51,3 +53,34 @@ func UpdateFriendComment(OwnerUserID, FriendUserID, Remark string) error {
func DeleteSingleFriendInfo(OwnerUserID, FriendUserID 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 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 package im_mysql_model
import ( import (
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/db" "Open_IM/pkg/common/db"
"Open_IM/pkg/utils" "Open_IM/pkg/utils"
"fmt" "fmt"
"time" "time"
) )
@ -54,7 +56,7 @@ type GroupWithNum struct {
func GetGroupsByName(groupName string, pageNumber, showNumber int32) ([]GroupWithNum, error) { func GetGroupsByName(groupName string, pageNumber, showNumber int32) ([]GroupWithNum, error) {
var groups []GroupWithNum 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"). 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 return groups, err
} }
@ -80,7 +82,7 @@ func OperateGroupStatus(groupId string, groupStatus int32) error {
func GetGroupsCountNum(group db.Group) (int32, error) { func GetGroupsCountNum(group db.Group) (int32, error) {
var count int64 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 0, err
} }
return int32(count), nil 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 err := db.DB.MysqlDB.DefaultGormDB().Model(&db.Register{}).Where("register_ip=?", ip).Pluck("user_id", &userIDList).Error
return userIDList, err 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 package im_mysql_model
import ( import (
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/db" "Open_IM/pkg/common/db"
"Open_IM/pkg/common/log" "Open_IM/pkg/common/log"
"Open_IM/pkg/utils" "Open_IM/pkg/utils"
@ -10,10 +11,17 @@ import (
func GetChatLog(chatLog db.ChatLog, pageNumber, showNumber int32) ([]db.ChatLog, error) { func GetChatLog(chatLog db.ChatLog, pageNumber, showNumber int32) ([]db.ChatLog, error) {
var chatLogs []db.ChatLog var chatLogs []db.ChatLog
db := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs"). db := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs").
Where(fmt.Sprintf(" content like '%%%s%%'", chatLog.Content)).
Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1))) 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) 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 { if chatLog.ContentType != 0 {
db = db.Where("content_type = ?", chatLog.ContentType) db = db.Where("content_type = ?", chatLog.ContentType)
@ -24,23 +32,28 @@ func GetChatLog(chatLog db.ChatLog, pageNumber, showNumber int32) ([]db.ChatLog,
if chatLog.RecvID != "" { if chatLog.RecvID != "" {
db = db.Where("recv_id = ?", 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 err := db.Find(&chatLogs).Error
return chatLogs, err return chatLogs, err
} }
func GetChatLogCount(chatLog db.ChatLog) (int64, error) { func GetChatLogCount(chatLog db.ChatLog) (int64, error) {
var chatLogs []db.ChatLog
var count int64 var count int64
db := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs"). db := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs")
Where(fmt.Sprintf(" content like '%%%s%%'", chatLog.Content)) 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 { if chatLog.SessionType != 0 {
db = db.Where("session_type = ?", chatLog.SessionType) db = db.Where("session_type = ?", chatLog.SessionType)
} }
if chatLog.ContentType != 0 { if chatLog.ContentType == 1 {
db = db.Where("content_type = ?", chatLog.ContentType) 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 != "" { if chatLog.SendID != "" {
db = db.Where("send_id = ?", chatLog.SendID) db = db.Where("send_id = ?", chatLog.SendID)
@ -48,11 +61,7 @@ func GetChatLogCount(chatLog db.ChatLog) (int64, error) {
if chatLog.RecvID != "" { if chatLog.RecvID != "" {
db = db.Where("recv_id = ?", 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 return count, err
} }

@ -1,13 +1,14 @@
package im_mysql_model package im_mysql_model
import ( import (
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/db" "Open_IM/pkg/common/db"
"time" "time"
) )
func GetActiveUserNum(from, to time.Time) (int32, error) { func GetActiveUserNum(from, to time.Time) (int32, error) {
var num int64 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 return int32(num), err
} }
@ -31,13 +32,13 @@ func GetTotalUserNumByDate(to time.Time) (int32, error) {
func GetPrivateMessageNum(from, to time.Time) (int32, error) { func GetPrivateMessageNum(from, to time.Time) (int32, error) {
var num int64 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 return int32(num), err
} }
func GetGroupMessageNum(from, to time.Time) (int32, error) { func GetGroupMessageNum(from, to time.Time) (int32, error) {
var num int64 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 return int32(num), err
} }
@ -67,7 +68,7 @@ type activeGroup struct {
func GetActiveGroups(from, to time.Time, limit int) ([]*activeGroup, error) { func GetActiveGroups(from, to time.Time, limit int) ([]*activeGroup, error) {
var activeGroups []*activeGroup 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 { for _, activeGroup := range activeGroups {
group := db.Group{ group := db.Group{
GroupID: activeGroup.Id, GroupID: activeGroup.Id,
@ -80,18 +81,21 @@ func GetActiveGroups(from, to time.Time, limit int) ([]*activeGroup, error) {
type activeUser struct { type activeUser struct {
Name string Name string
Id string `gorm:"column:send_id"` ID string `gorm:"column:send_id"`
MessageNum int `gorm:"column:message_num"` MessageNum int `gorm:"column:message_num"`
} }
func GetActiveUsers(from, to time.Time, limit int) ([]*activeUser, error) { func GetActiveUsers(from, to time.Time, limit int) ([]*activeUser, error) {
var activeUsers []*activeUser 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 { for _, activeUser := range activeUsers {
user := db.User{ 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 activeUser.Name = user.Nickname
} }
return activeUsers, err return activeUsers, err

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

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

@ -75,7 +75,10 @@ func GetFriendIDListFromCache(userID string) ([]string, error) {
return "", utils.Wrap(err, "") return "", utils.Wrap(err, "")
} }
bytes, err := json.Marshal(friendIDList) 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) friendIDListStr, err := db.DB.Rc.Fetch(friendRelationCache+userID, time.Second*30*60, getFriendIDList)
if err != nil { if err != nil {
@ -98,7 +101,10 @@ func GetBlackListFromCache(userID string) ([]string, error) {
return "", utils.Wrap(err, "") return "", utils.Wrap(err, "")
} }
bytes, err := json.Marshal(blackIDList) 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) blackIDListStr, err := db.DB.Rc.Fetch(blackListCache+userID, time.Second*30*60, getBlackIDList)
if err != nil { if err != nil {
@ -120,7 +126,10 @@ func GetJoinedGroupIDListFromCache(userID string) ([]string, error) {
return "", utils.Wrap(err, "") return "", utils.Wrap(err, "")
} }
bytes, err := json.Marshal(joinedGroupList) 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) joinedGroupIDListStr, err := db.DB.Rc.Fetch(joinedGroupListCache+userID, time.Second*30*60, getJoinedGroupIDList)
if err != nil { if err != nil {
@ -155,7 +164,10 @@ func GetGroupMemberIDListFromCache(groupID string) ([]string, error) {
} }
} }
bytes, err := json.Marshal(groupMemberIDList) 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) groupIDListStr, err := db.DB.Rc.Fetch(groupCache+groupID, time.Second*30*60, f)
if err != nil { if err != nil {
@ -178,7 +190,10 @@ func GetUserInfoFromCache(userID string) (*db.User, error) {
return "", utils.Wrap(err, "") return "", utils.Wrap(err, "")
} }
bytes, err := json.Marshal(userInfo) 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) userInfoStr, err := db.DB.Rc.Fetch(userInfoCache+userID, time.Second*30*60, getUserInfo)
if err != nil { if err != nil {
@ -200,7 +215,10 @@ func GetGroupMemberInfoFromCache(groupID, userID string) (*db.GroupMember, error
return "", utils.Wrap(err, "") return "", utils.Wrap(err, "")
} }
bytes, err := json.Marshal(groupMemberInfo) 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) groupMemberInfoStr, err := db.DB.Rc.Fetch(groupMemberInfoCache+groupID+"-"+userID, time.Second*30*60, getGroupMemberInfo)
if err != nil { if err != nil {
@ -266,7 +284,10 @@ func GetAllGroupMembersInfoFromCache(groupID string) ([]*db.GroupMember, error)
return "", utils.Wrap(err, "") return "", utils.Wrap(err, "")
} }
bytes, err := json.Marshal(groupMembers) 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) groupMembersStr, err := db.DB.Rc.Fetch(groupAllMemberInfoCache+groupID, time.Second*30*60, getGroupMemberInfo)
if err != nil { if err != nil {
@ -288,7 +309,10 @@ func GetGroupInfoFromCache(groupID string) (*db.Group, error) {
return "", utils.Wrap(err, "") return "", utils.Wrap(err, "")
} }
bytes, err := json.Marshal(groupInfo) 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) groupInfoStr, err := db.DB.Rc.Fetch(groupInfoCache+groupID, time.Second*30*60, getGroupInfo)
if err != nil { if err != nil {
@ -310,7 +334,10 @@ func GetAllFriendsInfoFromCache(userID string) ([]*db.Friend, error) {
return "", utils.Wrap(err, "") return "", utils.Wrap(err, "")
} }
bytes, err := json.Marshal(friendInfoList) 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) allFriendInfoStr, err := db.DB.Rc.Fetch(allFriendInfoCache+userID, time.Second*30*60, getAllFriendInfo)
if err != nil { if err != nil {
@ -332,7 +359,10 @@ func GetAllDepartmentsFromCache() ([]db.Department, error) {
return "", utils.Wrap(err, "") return "", utils.Wrap(err, "")
} }
bytes, err := json.Marshal(departmentList) 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) allDepartmentsStr, err := db.DB.Rc.Fetch(allDepartmentCache, time.Second*30*60, getAllDepartments)
if err != nil { if err != nil {
@ -354,7 +384,10 @@ func GetAllDepartmentMembersFromCache() ([]db.DepartmentMember, error) {
return "", utils.Wrap(err, "") return "", utils.Wrap(err, "")
} }
bytes, err := json.Marshal(departmentMembers) 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) allDepartmentMembersStr, err := db.DB.Rc.Fetch(allDepartmentMemberCache, time.Second*30*60, getAllDepartmentMembers)
if err != nil { if err != nil {
@ -379,7 +412,10 @@ func GetJoinedSuperGroupListFromCache(userID string) ([]string, error) {
return "", errors.New("GroupIDList == 0") return "", errors.New("GroupIDList == 0")
} }
bytes, err := json.Marshal(userToSuperGroup.GroupIDList) 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) joinedSuperGroupListStr, err := db.DB.Rc.Fetch(joinedSuperGroupListCache+userID, time.Second*30*60, getJoinedSuperGroupIDList)
if err != nil { if err != nil {
@ -445,7 +481,10 @@ func GetUserConversationIDListFromCache(userID string) ([]string, error) {
} }
log.NewDebug("", utils.GetSelfFuncName(), conversationIDList) log.NewDebug("", utils.GetSelfFuncName(), conversationIDList)
bytes, err := json.Marshal(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) conversationIDListStr, err := db.DB.Rc.Fetch(conversationIDListCache+userID, time.Second*30*60, getConversationIDList)
var conversationIDList []string 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) writer := bufio.NewWriter(src)
logger.SetOutput(writer) logger.SetOutput(writer)
//logger.SetOutput(os.Stdout) // logger.SetOutput(os.Stdout)
//Log Console Print Style Setting //Log Console Print Style Setting
logger.SetFormatter(&nested.Formatter{ logger.SetFormatter(&nested.Formatter{
TimestampFormat: "2006-01-02 15:04:05.000", 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"; import "Open_IM/pkg/proto/sdk_ws/ws.proto";
package admin_cms; package admin_cms;
message CommonResp {
int32 errCode = 1;
string errMsg = 2;
}
message AdminLoginReq { message AdminLoginReq {
string OperationID = 1; string operationID = 1;
string AdminID = 2; string adminID = 2;
string Secret = 3; string secret = 3;
} }
message AdminLoginResp { message AdminLoginResp {
string token = 1; string token = 1;
CommonResp commonResp = 2;
} }
message AddUserRegisterAddFriendIDListReq { message AddUserRegisterAddFriendIDListReq {
@ -20,7 +27,7 @@ message AddUserRegisterAddFriendIDListReq {
} }
message AddUserRegisterAddFriendIDListResp { message AddUserRegisterAddFriendIDListResp {
CommonResp commonResp = 1;
} }
message ReduceUserRegisterAddFriendIDListReq { message ReduceUserRegisterAddFriendIDListReq {
@ -30,17 +37,278 @@ message ReduceUserRegisterAddFriendIDListReq {
} }
message ReduceUserRegisterAddFriendIDListResp { message ReduceUserRegisterAddFriendIDListResp {
CommonResp commonResp = 1;
} }
message GetUserRegisterAddFriendIDListReq { message GetUserRegisterAddFriendIDListReq {
string operationID = 1; string operationID = 1;
server_api_params.RequestPagination Pagination = 2; server_api_params.RequestPagination pagination = 2;
} }
message GetUserRegisterAddFriendIDListResp { 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; 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 { service adminCMS {
@ -48,4 +316,28 @@ service adminCMS {
rpc AddUserRegisterAddFriendIDList(AddUserRegisterAddFriendIDListReq) returns(AddUserRegisterAddFriendIDListResp); rpc AddUserRegisterAddFriendIDList(AddUserRegisterAddFriendIDListReq) returns(AddUserRegisterAddFriendIDListResp);
rpc ReduceUserRegisterAddFriendIDList(ReduceUserRegisterAddFriendIDListReq) returns(ReduceUserRegisterAddFriendIDListResp); rpc ReduceUserRegisterAddFriendIDList(ReduceUserRegisterAddFriendIDListReq) returns(ReduceUserRegisterAddFriendIDListResp);
rpc GetUserRegisterAddFriendIDList(GetUserRegisterAddFriendIDListReq) returns(GetUserRegisterAddFriendIDListResp); 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; 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 { message GetGroupsReq {
server_api_params.RequestPagination Pagination = 1; server_api_params.RequestPagination Pagination = 1;
string OperationID = 2; string GroupName = 2;
string GroupID = 3;
string OperationID = 4;
} }
message GetGroupsResp { message GetGroupsResp {
repeated CMSGroup CMSGroups = 1; repeated CMSGroup CMSGroups = 1;
server_api_params.RequestPagination Pagination = 2; server_api_params.ResponsePagination Pagination = 2;
int32 GroupNum = 3; int32 GroupNum = 3;
CommonResp commonResp = 4;
} }
message GetGroupMemberReq { message GetGroupMemberReq {
@ -247,26 +239,6 @@ message GetGroupMemberReq {
string OperationID = 2; 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 { message GetGroupMembersCMSReq {
string GroupID = 1; string GroupID = 1;
string UserName = 2; string UserName = 2;
@ -278,30 +250,7 @@ message GetGroupMembersCMSResp {
repeated server_api_params.GroupMemberFullInfo members = 1; repeated server_api_params.GroupMemberFullInfo members = 1;
server_api_params.ResponsePagination Pagination = 2; server_api_params.ResponsePagination Pagination = 2;
int32 MemberNums = 3; int32 MemberNums = 3;
} CommonResp commonResp = 4;
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;
} }
message DismissGroupReq{ message DismissGroupReq{
@ -444,13 +393,9 @@ service group{
rpc inviteUserToGroup(InviteUserToGroupReq) returns (InviteUserToGroupResp); rpc inviteUserToGroup(InviteUserToGroupReq) returns (InviteUserToGroupResp);
rpc getGroupAllMember(GetGroupAllMemberReq) returns(GetGroupAllMemberResp); rpc getGroupAllMember(GetGroupAllMemberReq) returns(GetGroupAllMemberResp);
rpc GetGroupByID(GetGroupByIDReq) returns(GetGroupByIDResp);
rpc GetGroup(GetGroupReq) returns(GetGroupResp);
rpc GetGroups(GetGroupsReq) returns(GetGroupsResp); rpc GetGroups(GetGroupsReq) returns(GetGroupsResp);
rpc OperateUserRole(OperateUserRoleReq) returns(OperateUserRoleResp);
rpc GetGroupMembersCMS(GetGroupMembersCMSReq) returns(GetGroupMembersCMSResp); rpc GetGroupMembersCMS(GetGroupMembersCMSReq) returns(GetGroupMembersCMSResp);
rpc RemoveGroupMembersCMS(RemoveGroupMembersCMSReq) returns(RemoveGroupMembersCMSResp);
rpc AddGroupMembersCMS(AddGroupMembersCMSReq) returns(AddGroupMembersCMSResp);
rpc DismissGroup(DismissGroupReq) returns(DismissGroupResp); rpc DismissGroup(DismissGroupReq) returns(DismissGroupResp);
rpc MuteGroupMember(MuteGroupMemberReq) returns(MuteGroupMemberResp); rpc MuteGroupMember(MuteGroupMemberReq) returns(MuteGroupMemberResp);
@ -459,7 +404,6 @@ service group{
rpc CancelMuteGroup(CancelMuteGroupReq) returns(CancelMuteGroupResp); rpc CancelMuteGroup(CancelMuteGroupReq) returns(CancelMuteGroupResp);
rpc SetGroupMemberNickname(SetGroupMemberNicknameReq) returns (SetGroupMemberNicknameResp); rpc SetGroupMemberNickname(SetGroupMemberNicknameReq) returns (SetGroupMemberNicknameResp);
rpc GetJoinedSuperGroupList(GetJoinedSuperGroupListReq) returns (GetJoinedSuperGroupListResp); rpc GetJoinedSuperGroupList(GetJoinedSuperGroupListReq) returns (GetJoinedSuperGroupListResp);
rpc GetSuperGroupsInfo(GetSuperGroupsInfoReq) returns (GetSuperGroupsInfoResp); rpc GetSuperGroupsInfo(GetSuperGroupsInfoReq) returns (GetSuperGroupsInfoResp);
rpc SetGroupMemberInfo(SetGroupMemberInfoReq) returns (SetGroupMemberInfoResp); 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; uint32 birth = 6;
string email = 7; string email = 7;
string ex = 8; string ex = 8;
string createIp = 9; uint32 createTime = 9;
uint32 createTime = 10; int32 appMangerLevel = 10;
string LastLoginIp =11; int32 globalRecvMsgOpt = 11;
uint32 LastLoginTime = 12;
int32 LoginTimes = 13;
int32 LoginLimit = 14;
int32 appMangerLevel = 15;
int32 globalRecvMsgOpt = 16;
string invitationCode = 17;
} }
message FriendInfo{ 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; 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{ message GetAllUserIDReq{
@ -143,94 +133,29 @@ message BatchSetConversationsResp{
repeated string Failed = 3; repeated string Failed = 3;
} }
message ResignUserReq{
string UserId = 1;
string OperationID = 2;
}
message ResignUserResp{
CommonResp commonResp = 1;
}
message GetUserByIdReq{ message GetUsersReq {
string UserId = 1; string operationID = 1;
string OperationID = 2; server_api_params.RequestPagination pagination = 2;
} string userName = 3;
string userID = 4;
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 { message CmsUser {
string OperationID = 1; server_api_params.UserInfo user = 1;
server_api_params.RequestPagination Pagination = 2; bool isBlock = 2;
string UserName = 3;
} }
message GetUsersResp{ message GetUsersResp{
CommonResp CommonResp = 1; CommonResp commonResp = 1;
repeated User user = 2; repeated CmsUser userList = 2;
server_api_params.ResponsePagination Pagination = 3; server_api_params.ResponsePagination Pagination = 3;
int32 UserNums = 4; int32 totalNums = 4;
} }
message AddUserReq{ message AddUserReq{
string OperationID = 1; server_api_params.UserInfo userInfo = 1;
string PhoneNumber = 2; string operationID = 2;
string UserId = 3;
string name = 4;
string Email = 5;
string Gender = 6;
string Birth =7;
string Photo = 8;
string OpUserId = 9;
} }
message AddUserResp{ message AddUserResp{
@ -239,10 +164,10 @@ message AddUserResp{
message BlockUserReq{ message BlockUserReq{
string UserId = 1; string userID = 1;
string EndDisableTime = 2; string endDisableTime = 2;
string OperationID = 3; string operationID = 3;
string OpUserId = 4; string opUserID = 4;
} }
message BlockUserResp{ message BlockUserResp{
@ -250,9 +175,9 @@ message BlockUserResp{
} }
message UnBlockUserReq{ message UnBlockUserReq{
string UserId = 1; string userID = 1;
string OperationID = 2; string operationID = 2;
string OpUserId = 3; string opUserID = 3;
} }
message UnBlockUserResp{ message UnBlockUserResp{
@ -260,13 +185,14 @@ message UnBlockUserResp{
} }
message GetBlockUsersReq{ message GetBlockUsersReq{
server_api_params.RequestPagination Pagination = 1; server_api_params.RequestPagination pagination = 1;
string OperationID = 2; string operationID = 2;
int32 BlockUserNum = 3; string userID = 3;
int32 totalBlockUserNum = 4;
} }
message BlockUser { message BlockUser {
User User = 1; server_api_params.UserInfo UserInfo = 1;
string BeginDisableTime = 2; string BeginDisableTime = 2;
string EndDisableTime = 3; string EndDisableTime = 3;
} }
@ -278,24 +204,6 @@ message GetBlockUsersResp{
int32 UserNums = 4; 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 GetUserInfo(GetUserInfoReq) returns(GetUserInfoResp);
rpc UpdateUserInfo(UpdateUserInfoReq) returns(UpdateUserInfoResp); rpc UpdateUserInfo(UpdateUserInfoReq) returns(UpdateUserInfoResp);
rpc SetGlobalRecvMessageOpt(SetGlobalRecvMessageOptReq) returns(SetGlobalRecvMessageOptResp); rpc SetGlobalRecvMessageOpt(SetGlobalRecvMessageOptReq) returns(SetGlobalRecvMessageOptResp);
rpc DeleteUsers(DeleteUsersReq)returns(DeleteUsersResp);
rpc GetAllUserID(GetAllUserIDReq)returns(GetAllUserIDResp); rpc GetAllUserID(GetAllUserIDReq)returns(GetAllUserIDResp);
rpc AccountCheck(AccountCheckReq)returns(AccountCheckResp); rpc AccountCheck(AccountCheckReq)returns(AccountCheckResp);
@ -314,15 +221,13 @@ service user {
rpc SetConversation(SetConversationReq)returns(SetConversationResp); rpc SetConversation(SetConversationReq)returns(SetConversationResp);
rpc SetRecvMsgOpt(SetRecvMsgOptReq)returns(SetRecvMsgOptResp); 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 GetUsers(GetUsersReq) returns (GetUsersResp);
rpc AddUser(AddUserReq) returns (AddUserResp); rpc AddUser(AddUserReq) returns (AddUserResp);
rpc BlockUser(BlockUserReq) returns (BlockUserResp); rpc BlockUser(BlockUserReq) returns (BlockUserResp);
rpc UnBlockUser(UnBlockUserReq) returns (UnBlockUserResp); rpc UnBlockUser(UnBlockUserReq) returns (UnBlockUserResp);
rpc GetBlockUsers(GetBlockUsersReq) returns (GetBlockUsersResp); rpc GetBlockUsers(GetBlockUsersReq) returns (GetBlockUsersResp);
rpc GetBlockUserById(GetBlockUserByIdReq) returns (GetBlockUserByIdResp);
rpc DeleteUser(DeleteUserReq) returns (DeleteUserResp);
} }

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

@ -46,8 +46,6 @@ service_source_root=(
../cmd/rpc/open_im_group/ ../cmd/rpc/open_im_group/
../cmd/rpc/open_im_auth/ ../cmd/rpc/open_im_auth/
../cmd/rpc/open_im_admin_cms/ ../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_office/
../cmd/rpc/open_im_organization/ ../cmd/rpc/open_im_organization/
../cmd/rpc/open_im_conversation/ ../cmd/rpc/open_im_conversation/
@ -71,8 +69,6 @@ service_names=(
open_im_group open_im_group
open_im_auth open_im_auth
open_im_admin_cms open_im_admin_cms
open_im_message_cms
open_im_statistics
open_im_office open_im_office
open_im_organization open_im_organization
open_im_conversation open_im_conversation

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

Loading…
Cancel
Save