mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
add
This commit is contained in:
parent
0ed393b1a5
commit
fb396d9cf0
14
cmd/rpc/statistics/main.go
Normal file
14
cmd/rpc/statistics/main.go
Normal file
@ -0,0 +1,14 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"Open_IM/internal/rpc/user"
|
||||
"flag"
|
||||
)
|
||||
|
||||
func main() {
|
||||
rpcPort := flag.Int("port", 10100, "rpc listening port")
|
||||
flag.Parse()
|
||||
rpcServer := user.NewUserServer(*rpcPort)
|
||||
rpcServer.Run()
|
||||
}
|
||||
|
@ -7,18 +7,18 @@ import (
|
||||
)
|
||||
|
||||
// register
|
||||
func UserLogin(c *gin.Context) {
|
||||
func AdminLogin(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{"message": "someJSON", "status": 200})
|
||||
}
|
||||
|
||||
func UserRegister(c *gin.Context) {
|
||||
func AdminRegister(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{"message": "someJSON", "status": 200})
|
||||
}
|
||||
|
||||
func GetUserSettings(c *gin.Context) {
|
||||
func GetAdminSettings(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{"message": "someJSON", "status": 200})
|
||||
}
|
||||
|
||||
func AlterUserSettings(c *gin.Context) {
|
||||
func AlterAdminSettings(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{"message": "someJSON", "status": 200})
|
||||
}
|
||||
|
@ -18,6 +18,34 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func GetGroupById(c *gin.Context) {
|
||||
var (
|
||||
req cms_api_struct.GetGroupByIdRequest
|
||||
resp cms_api_struct.GetGroupByIdResponse
|
||||
reqPb pbGroup.GetGroupByIdReq
|
||||
)
|
||||
if err := c.ShouldBindQuery(&req); err != nil {
|
||||
log.NewError("0", "ShouldBindQuery failed ", err.Error())
|
||||
openIMHttp.RespHttp200(c, constant.ErrArgs, nil)
|
||||
return
|
||||
}
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
||||
client := pbGroup.NewGroupClient(etcdConn)
|
||||
respPb, err := client.GetGroupById(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(utils.GetSelfFuncName(), "GetUserInfo failed ", err.Error())
|
||||
openIMHttp.RespHttp200(c, constant.ErrServer, nil)
|
||||
return
|
||||
}
|
||||
resp.GroupMasterId = respPb.GroupInfo.OwnerUserID
|
||||
resp.GroupName = respPb.GroupInfo.GroupName
|
||||
resp.GroupID = respPb.GroupInfo.GroupID
|
||||
resp.CreateTime = (utils.UnixSecondToTime(int64(respPb.GroupInfo.CreateTime))).String()
|
||||
resp.ProfilePhoto = respPb.GroupInfo.FaceURL
|
||||
resp.GroupMasterName = respPb.GroupInfo.OwnerUserID
|
||||
openIMHttp.RespHttp200(c, constant.OK, nil)
|
||||
}
|
||||
|
||||
func GetGroups(c *gin.Context) {
|
||||
var (
|
||||
req cms_api_struct.GetGroupsRequest
|
||||
@ -57,7 +85,7 @@ func GetGroups(c *gin.Context) {
|
||||
openIMHttp.RespHttp200(c, constant.OK, resp)
|
||||
}
|
||||
|
||||
func GetGroup(c *gin.Context) {
|
||||
func GetGroupByName(c *gin.Context) {
|
||||
var (
|
||||
req cms_api_struct.GetGroupRequest
|
||||
resp cms_api_struct.GetGroupResponse
|
||||
@ -69,6 +97,8 @@ func GetGroup(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
reqPb.GroupName = req.GroupName
|
||||
reqPb.Pagination = &commonPb.RequestPagination{}
|
||||
utils.CopyStructFields(&reqPb.Pagination, req)
|
||||
fmt.Println(reqPb)
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
||||
client := pbGroup.NewGroupClient(etcdConn)
|
||||
@ -90,6 +120,8 @@ func GetGroup(c *gin.Context) {
|
||||
ProfilePhoto: v.FaceURL,
|
||||
})
|
||||
}
|
||||
resp.CurrentPage = int(respPb.Pagination.PageNumber)
|
||||
resp.ShowNumber = int(respPb.Pagination.ShowNumber)
|
||||
openIMHttp.RespHttp200(c, constant.OK, resp)
|
||||
}
|
||||
|
||||
@ -104,24 +136,30 @@ func CreateGroup(c *gin.Context) {
|
||||
openIMHttp.RespHttp200(c, constant.ErrArgs, nil)
|
||||
return
|
||||
}
|
||||
reqPb.GroupInfo = &commonPb.GroupInfo{}
|
||||
reqPb.GroupInfo.GroupName = req.GroupName
|
||||
reqPb.GroupInfo.CreatorUserID = ""
|
||||
reqPb.GroupInfo.CreatorUserID = req.GroupMasterId
|
||||
for _, v := range req.GroupMembers {
|
||||
reqPb.InitMemberList = append(reqPb.InitMemberList, &pbGroup.GroupAddMemberInfo{
|
||||
UserID: v,
|
||||
RoleLevel: 1,
|
||||
})
|
||||
}
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
||||
client := pbGroup.NewGroupClient(etcdConn)
|
||||
respPb, err := client.CreateGroup(context.Background(), &reqPb)
|
||||
_, err := client.CreateGroup(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError("s", "GetUserInfo failed ", err.Error())
|
||||
openIMHttp.RespHttp200(c, constant.ErrServer, nil)
|
||||
return
|
||||
}
|
||||
fmt.Println(respPb)
|
||||
openIMHttp.RespHttp200(c, constant.OK, resp)
|
||||
}
|
||||
|
||||
func BanGroupChat(c *gin.Context) {
|
||||
var (
|
||||
req cms_api_struct.BanGroupChatRequest
|
||||
reqPb pbGroup.BanGroupChatReq
|
||||
reqPb pbGroup.OperateGroupStatusReq
|
||||
)
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
log.NewError("0", "ShouldBindQuery failed ", err.Error())
|
||||
@ -129,9 +167,10 @@ func BanGroupChat(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
reqPb.GroupId = req.GroupId
|
||||
reqPb.Status = constant.GroupBanChat
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
||||
client := pbGroup.NewGroupClient(etcdConn)
|
||||
_, err := client.BanGroupChat(context.Background(), &reqPb)
|
||||
_, err := client.OperateGroupStatus(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError("s", "GetUserInfo failed ", err.Error())
|
||||
openIMHttp.RespHttp200(c, constant.ErrServer, nil)
|
||||
@ -144,7 +183,7 @@ func BanGroupChat(c *gin.Context) {
|
||||
func BanPrivateChat(c *gin.Context) {
|
||||
var (
|
||||
req cms_api_struct.BanPrivateChatRequest
|
||||
reqPb pbGroup.BanPrivateChatReq
|
||||
reqPb pbGroup.OperateGroupStatusReq
|
||||
)
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
@ -152,9 +191,10 @@ func BanPrivateChat(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
reqPb.GroupId = req.GroupId
|
||||
reqPb.Status = constant.GroupBanPrivateChat
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
||||
client := pbGroup.NewGroupClient(etcdConn)
|
||||
_, err := client.BanPrivateChat(context.Background(), &reqPb)
|
||||
_, err := client.OperateGroupStatus(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError("s", "GetUserInfo failed ", err.Error())
|
||||
openIMHttp.RespHttp200(c, constant.ErrServer, nil)
|
||||
@ -163,6 +203,53 @@ func BanPrivateChat(c *gin.Context) {
|
||||
openIMHttp.RespHttp200(c, constant.OK, nil)
|
||||
}
|
||||
|
||||
func OpenGroupChat(c *gin.Context) {
|
||||
var (
|
||||
req cms_api_struct.BanPrivateChatRequest
|
||||
reqPb pbGroup.OperateGroupStatusReq
|
||||
)
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
openIMHttp.RespHttp200(c, constant.ErrArgs, nil)
|
||||
return
|
||||
}
|
||||
reqPb.GroupId = req.GroupId
|
||||
reqPb.Status = constant.GroupOk
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
||||
client := pbGroup.NewGroupClient(etcdConn)
|
||||
_, err := client.OperateGroupStatus(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError("s", "GetUserInfo failed ", err.Error())
|
||||
openIMHttp.RespHttp200(c, constant.ErrServer, nil)
|
||||
return
|
||||
}
|
||||
openIMHttp.RespHttp200(c, constant.OK, nil)
|
||||
}
|
||||
|
||||
func OpenPrivateChat(c *gin.Context) {
|
||||
var (
|
||||
req cms_api_struct.BanPrivateChatRequest
|
||||
reqPb pbGroup.OperateGroupStatusReq
|
||||
)
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
openIMHttp.RespHttp200(c, constant.ErrArgs, nil)
|
||||
return
|
||||
}
|
||||
reqPb.GroupId = req.GroupId
|
||||
reqPb.Status = constant.GroupOk
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
||||
client := pbGroup.NewGroupClient(etcdConn)
|
||||
_, err := client.OperateGroupStatus(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError("s", "GetUserInfo failed ", err.Error())
|
||||
openIMHttp.RespHttp200(c, constant.ErrServer, nil)
|
||||
return
|
||||
}
|
||||
openIMHttp.RespHttp200(c, constant.OK, nil)
|
||||
}
|
||||
|
||||
|
||||
func GetGroupsMember(c *gin.Context) {
|
||||
var (
|
||||
req cms_api_struct.GetGroupMembersRequest
|
||||
@ -175,10 +262,6 @@ func GetGroupsMember(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
func InquireMember(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
func InquireGroup(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
@ -20,16 +20,16 @@ func NewGinRouter() *gin.Engine {
|
||||
router.Use(middleware.CorsHandler())
|
||||
adminRouterGroup := router.Group("/admin")
|
||||
{
|
||||
adminRouterGroup.POST("/register", admin.UserRegister)
|
||||
adminRouterGroup.POST("/login", admin.UserLogin)
|
||||
adminRouterGroup.GET("/get_user_settings", admin.GetUserSettings)
|
||||
adminRouterGroup.POST("/alter_user_settings", admin.AlterUserSettings)
|
||||
adminRouterGroup.POST("/register", admin.AdminRegister)
|
||||
adminRouterGroup.POST("/login", admin.AdminLogin)
|
||||
adminRouterGroup.GET("/get_user_settings", admin.GetAdminSettings)
|
||||
adminRouterGroup.POST("/alter_user_settings", admin.AlterAdminSettings)
|
||||
}
|
||||
statisticsRouterGroup := router.Group("/statistics")
|
||||
{
|
||||
statisticsRouterGroup.GET("/get_messages_statistics", statistics.MessagesStatistics)
|
||||
statisticsRouterGroup.GET("/get_users_statistics", statistics.UsersStatistics)
|
||||
statisticsRouterGroup.GET("/get_groups_statistics", statistics.GroupsStatistics)
|
||||
statisticsRouterGroup.GET("/get_messages_statistics", statistics.GetMessagesStatistics)
|
||||
statisticsRouterGroup.GET("/get_users_statistics", statistics.GetUsersStatistics)
|
||||
statisticsRouterGroup.GET("/get_groups_statistics", statistics.GetGroupsStatistics)
|
||||
statisticsRouterGroup.GET("/get_active_user", statistics.GetActiveUser)
|
||||
statisticsRouterGroup.GET("/get_active_group", statistics.GetActiveGroup)
|
||||
}
|
||||
@ -57,18 +57,20 @@ func NewGinRouter() *gin.Engine {
|
||||
}
|
||||
groupRouterGroup := router.Group("/group")
|
||||
{
|
||||
groupRouterGroup.GET("/get_group_by_id", group.GetGroupById)
|
||||
groupRouterGroup.GET("/get_groups", group.GetGroups)
|
||||
groupRouterGroup.GET("/get_group", group.GetGroup)
|
||||
groupRouterGroup.GET("/search_groups_member", group.GetGroupsMember)
|
||||
groupRouterGroup.GET("/get_group_by_name", group.GetGroupByName)
|
||||
groupRouterGroup.GET("/get_group_members", group.GetGroupsMember)
|
||||
groupRouterGroup.POST("/create_group", group.CreateGroup)
|
||||
groupRouterGroup.GET("/inquire_group", group.InquireGroup)
|
||||
groupRouterGroup.GET("/inquire_member_by_group", group.InquireMember)
|
||||
groupRouterGroup.POST("/add_members", group.AddMembers)
|
||||
groupRouterGroup.POST("/remove_user", group.RemoveUser)
|
||||
groupRouterGroup.POST("/ban_private_chat", group.BanPrivateChat)
|
||||
groupRouterGroup.POST("/remove_member", group.RemoveUser)
|
||||
groupRouterGroup.POST("/ban_group_private_chat", group.BanPrivateChat)
|
||||
groupRouterGroup.POST("/open_group_private_chat", group.OpenPrivateChat)
|
||||
groupRouterGroup.POST("/withdraw_message", group.Withdraw)
|
||||
groupRouterGroup.POST("/search_group_message", group.SearchMessage)
|
||||
groupRouterGroup.POST("/ban_group_chat", group.BanGroupChat)
|
||||
groupRouterGroup.POST("/open_group_chat", group.OpenGroupChat)
|
||||
}
|
||||
userRouterGroup := router.Group("/user")
|
||||
{
|
||||
|
@ -1,18 +1,24 @@
|
||||
package statistics
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/cms_api_struct"
|
||||
"github.com/gin-gonic/gin"
|
||||
statisticsPb "Open_IM/pkg/proto/statistics"
|
||||
)
|
||||
|
||||
func MessagesStatistics(c *gin.Context) {
|
||||
func GetMessagesStatistics(c *gin.Context) {
|
||||
var (
|
||||
req cms_api_struct.GetGroupMembersRequest
|
||||
resp cms_api_struct.GetGroupMembersResponse
|
||||
reqPb statisticsPb.GetMessageStatisticsReq
|
||||
)
|
||||
}
|
||||
|
||||
func GetUsersStatistics(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
func UsersStatistics(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
func GroupsStatistics(c *gin.Context) {
|
||||
func GetGroupsStatistics(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
|
@ -640,6 +640,28 @@ func (s *groupServer) TransferGroupOwner(_ context.Context, req *pbGroup.Transfe
|
||||
|
||||
}
|
||||
|
||||
func (s *groupServer) GetGroupById(_ context.Context, req *pbGroup.GetGroupByIdReq) (*pbGroup.GetGroupByIdResp, error) {
|
||||
log.NewInfo(req.OperationID, "GetGroup ", req.String())
|
||||
resp := &pbGroup.GetGroupByIdResp{}
|
||||
group, err := imdb.GetGroupsById(req.GroupId)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
resp.GroupInfo = &open_im_sdk.GroupInfo{
|
||||
GroupID: group.GroupID,
|
||||
GroupName: group.GroupName,
|
||||
FaceURL: group.FaceUrl,
|
||||
OwnerUserID: group.CreatorUserID,
|
||||
MemberCount: 0,
|
||||
Status: group.Status,
|
||||
CreatorUserID: group.CreatorUserID,
|
||||
GroupType: group.GroupType,
|
||||
}
|
||||
|
||||
resp.GroupInfo.CreatorUserID = group.CreatorUserID
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) GetGroup(_ context.Context, req *pbGroup.GetGroupReq) (*pbGroup.GetGroupResp, error) {
|
||||
log.NewInfo(req.OperationID, "GetGroup ", req.String())
|
||||
resp := &pbGroup.GetGroupResp{
|
||||
@ -649,6 +671,10 @@ func (s *groupServer) GetGroup(_ context.Context, req *pbGroup.GetGroupReq) (*pb
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp.Pagination = &open_im_sdk.RequestPagination{
|
||||
PageNumber: req.Pagination.PageNumber,
|
||||
ShowNumber: req.Pagination.ShowNumber,
|
||||
}
|
||||
for _, v := range groups {
|
||||
resp.GroupInfo = append(resp.GroupInfo, &open_im_sdk.GroupInfo{
|
||||
GroupID: v.GroupID,
|
||||
@ -659,7 +685,6 @@ func (s *groupServer) GetGroup(_ context.Context, req *pbGroup.GetGroupReq) (*pb
|
||||
CreatorUserID: v.CreatorUserID,
|
||||
})
|
||||
}
|
||||
utils.CopyStructFields(resp.GroupInfo, groups)
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@ -695,26 +720,17 @@ func (s *groupServer) GetGroups(_ context.Context, req *pbGroup.GetGroupsReq) (*
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) BanGroupChat(_ context.Context, req *pbGroup.BanGroupChatReq) (*pbGroup.BanGroupChatResp, error) {
|
||||
log.NewInfo(req.OperationID, "BanGroupChat ", req.String())
|
||||
resp := &pbGroup.BanGroupChatResp{}
|
||||
if err := imdb.BanGroupChat(req.GroupId); err != nil {
|
||||
return resp, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) BanPrivateChat(_ context.Context, req *pbGroup.BanPrivateChatReq) (*pbGroup.BanPrivateChatResp, error) {
|
||||
log.NewInfo(req.OperationID, "BanPrivateChat ", req.String())
|
||||
resp := &pbGroup.BanPrivateChatResp{}
|
||||
if err := imdb.BanPrivateChat(req.GroupId); err != nil {
|
||||
func (s *groupServer) OperateGroupStatus(_ context.Context, req *pbGroup.OperateGroupStatusReq) (*pbGroup.OperateGroupStatusResp, error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), req.String())
|
||||
resp := &pbGroup.OperateGroupStatusResp{}
|
||||
if err := imdb.OperateGroupStatus(req.GroupId, req.Status); err != nil {
|
||||
return resp, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) DeleteGroup(_ context.Context, req *pbGroup.DeleteGroupReq) (*pbGroup.DeleteGroupResp, error) {
|
||||
log.NewInfo(req.OperationID, "DeleteGroup ", req.String())
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), req.String())
|
||||
resp := &pbGroup.DeleteGroupResp{}
|
||||
if err := imdb.DeleteGroup(req.GroupId); err != nil {
|
||||
return resp, err
|
||||
@ -722,10 +738,10 @@ func (s *groupServer) DeleteGroup(_ context.Context, req *pbGroup.DeleteGroupReq
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) SetMaster(_ context.Context, req *pbGroup.SetMasterReq) (*pbGroup.SetMasterResp, error) {
|
||||
func (s *groupServer) OperateUserRole(_ context.Context, req *pbGroup.OperateUserRoleReq) (*pbGroup.OperateUserRoleResp, error) {
|
||||
log.NewInfo(req.OperationID, "DeleteGroup ", req.String())
|
||||
resp := &pbGroup.SetMasterResp{}
|
||||
if err := imdb.SetGroupMaster(req.UserId, req.GroupId); err != nil {
|
||||
resp := &pbGroup.OperateUserRoleResp{}
|
||||
if err := imdb.OperateGroupRole(req.UserId, req.GroupId, req.RoleLevel); err != nil {
|
||||
return resp, err
|
||||
}
|
||||
return resp, nil
|
||||
|
67
internal/rpc/statistics/statistics.go
Normal file
67
internal/rpc/statistics/statistics.go
Normal file
@ -0,0 +1,67 @@
|
||||
package statistics
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
//"Open_IM/pkg/common/constant"
|
||||
//"Open_IM/pkg/common/db"
|
||||
//imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"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"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
type statisticsServer struct {
|
||||
rpcPort int
|
||||
rpcRegisterName string
|
||||
etcdSchema string
|
||||
etcdAddr []string
|
||||
}
|
||||
|
||||
func NewStatisticsGroupServer(port int) *statisticsServer {
|
||||
log.NewPrivateLog("group")
|
||||
return &statisticsServer{
|
||||
rpcPort: port,
|
||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImGroupName,
|
||||
etcdSchema: config.Config.Etcd.EtcdSchema,
|
||||
etcdAddr: config.Config.Etcd.EtcdAddr,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *statisticsServer) Run() {
|
||||
log.NewInfo("0", "group rpc start ")
|
||||
ip := utils.ServerIP
|
||||
registerAddress := ip + ":" + strconv.Itoa(s.rpcPort)
|
||||
//listener network
|
||||
listener, err := net.Listen("tcp", registerAddress)
|
||||
if err != nil {
|
||||
log.NewError("0", "Listen failed ", err.Error(), registerAddress)
|
||||
return
|
||||
}
|
||||
log.NewInfo("0", "listen network success, ", registerAddress, listener)
|
||||
defer listener.Close()
|
||||
//grpc server
|
||||
srv := grpc.NewServer()
|
||||
defer srv.GracefulStop()
|
||||
//Service registers with etcd
|
||||
pbStatistics.RegisterUserServer(srv, s)
|
||||
err = getcdv3.RegisterEtcd(s.etcdSchema, strings.Join(s.etcdAddr, ","), ip, s.rpcPort, s.rpcRegisterName, 10)
|
||||
if err != nil {
|
||||
log.NewError("0", "RegisterEtcd failed ", err.Error())
|
||||
return
|
||||
}
|
||||
err = srv.Serve(listener)
|
||||
if err != nil {
|
||||
log.NewError("0", "Serve failed ", err.Error())
|
||||
return
|
||||
}
|
||||
log.NewInfo("0", "group rpc success")
|
||||
}
|
@ -250,11 +250,16 @@ func (s *userServer) GetUser(ctx context.Context, req *pbUser.GetUserReq) (*pbUs
|
||||
if err != nil {
|
||||
return resp, nil
|
||||
}
|
||||
isBlock, err := imdb.UserIsBlock(req.UserId)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
resp.User = &pbUser.User{
|
||||
ProfilePhoto: user.FaceURL,
|
||||
Nickname: user.Nickname,
|
||||
UserId: user.UserID,
|
||||
CreateTime: user.CreateTime.String(),
|
||||
IsBlock: isBlock,
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
@ -11,6 +11,14 @@ type GroupResponse struct {
|
||||
ProfilePhoto string `json:"profile_photo"`
|
||||
}
|
||||
|
||||
type GetGroupByIdRequest struct {
|
||||
GroupId string `form:"group_id" binding:"required"`
|
||||
}
|
||||
|
||||
type GetGroupByIdResponse struct {
|
||||
GroupResponse
|
||||
}
|
||||
|
||||
type GetGroupRequest struct {
|
||||
GroupName string `form:"group_name" binding:"required"`
|
||||
RequestPagination
|
||||
@ -86,4 +94,4 @@ type GetGroupMembersResponse struct {
|
||||
GroupMemberList []GroupMemberResponse `json:"group_member_list"`
|
||||
GroupMemberNums int `json:"group_member_nums"`
|
||||
ResponsePagination
|
||||
}
|
||||
}
|
@ -1,12 +1,12 @@
|
||||
package cms_api_struct
|
||||
|
||||
type StatisticsRequest struct {
|
||||
From string `json:"from"`
|
||||
To string `json:"to"`
|
||||
type GetStatisticsRequest struct {
|
||||
FromTime string `json:"from"`
|
||||
ToTime string `json:"to"`
|
||||
}
|
||||
|
||||
// 单聊
|
||||
type MessageStatisticsResponse struct {
|
||||
type GetMessageStatisticsResponse struct {
|
||||
PrivateMessageNum int `json:"private_message_num"`
|
||||
GroupMessageNum int `json:"group_message_num"`
|
||||
PrivateMessageNumList []struct {
|
||||
@ -20,7 +20,7 @@ type MessageStatisticsResponse struct {
|
||||
}
|
||||
|
||||
// 用户统计
|
||||
type UserStatisticsResponse struct {
|
||||
type GetUserStatisticsResponse struct {
|
||||
IncreaseUserNum int `json:"increase_user_num"`
|
||||
ActiveUserNum int `json:"active_user_num"`
|
||||
TotalUserNum int `json:"total_user_num"`
|
||||
@ -39,7 +39,7 @@ type UserStatisticsResponse struct {
|
||||
}
|
||||
|
||||
// 群聊统计
|
||||
type GroupMessageStatisticsResponse struct {
|
||||
type GetGroupMessageStatisticsResponse struct {
|
||||
IncreaseGroupNum int `json:"increase_group_num"`
|
||||
TotalGroupNum int `json:"total_group_num"`
|
||||
IncreaseGroupNumList []struct {
|
||||
@ -52,7 +52,7 @@ type GroupMessageStatisticsResponse struct {
|
||||
} `json:"total_group_num_list"`
|
||||
}
|
||||
|
||||
type ActiveUserStatisticsResponse struct {
|
||||
type GetActiveUserStatisticsResponse struct {
|
||||
ActiveUserList []struct {
|
||||
NickName string `json:"nick_name"`
|
||||
Id int `json:"id"`
|
||||
@ -60,7 +60,7 @@ type ActiveUserStatisticsResponse struct {
|
||||
} `json:"active_user_list"`
|
||||
}
|
||||
|
||||
type ActiveGroupStatisticsResponse struct {
|
||||
type GetActiveGroupStatisticsResponse struct {
|
||||
ActiveGroupList []struct {
|
||||
GroupNickName string `json:"group_nick_name"`
|
||||
GroupId int `json:"group_id"`
|
||||
|
@ -83,23 +83,18 @@ func GetGroups(pageNumber, showNumber int) ([]db.Group, error) {
|
||||
return groups, nil
|
||||
}
|
||||
|
||||
func BanGroupChat(groupId string) error {
|
||||
var group db.Group
|
||||
group.Status = constant.GroupBanChat
|
||||
|
||||
func OperateGroupStatus(groupId string, groupStatus int32) error {
|
||||
group := db.Group{
|
||||
GroupID: groupId,
|
||||
Status: groupStatus,
|
||||
}
|
||||
if err := SetGroupInfo(group); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func BanPrivateChat(groupId string) error {
|
||||
var group db.Group
|
||||
group.Status = constant.GroupBanPrivateChat
|
||||
if err := SetGroupInfo(group); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func DeleteGroup(groupId string) error {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
@ -114,7 +109,7 @@ func DeleteGroup(groupId string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func SetGroupMaster(userId, groupId string) error {
|
||||
func OperateGroupRole(userId, groupId string, roleLevel int32) error {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return err
|
||||
@ -123,6 +118,7 @@ func SetGroupMaster(userId, groupId string) error {
|
||||
groupMember := db.GroupMember{
|
||||
UserID: userId,
|
||||
GroupID: groupId,
|
||||
RoleLevel: roleLevel,
|
||||
}
|
||||
updateInfo := db.GroupMember{
|
||||
RoleLevel: constant.GroupOwner,
|
||||
@ -145,3 +141,18 @@ func GetGroupsCountNum() (int, error) {
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
func GetGroupsById(groupId string) (db.Group, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
group := db.Group{
|
||||
GroupID: groupId,
|
||||
}
|
||||
if err != nil {
|
||||
return group, err
|
||||
}
|
||||
dbConn.LogMode(true)
|
||||
if err := dbConn.Find(&group).First(&group).Error; err != nil {
|
||||
return group, err
|
||||
}
|
||||
return group, nil
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -222,31 +222,24 @@ message GetGroupMemberReq {
|
||||
string OperationID = 2;
|
||||
}
|
||||
|
||||
message BanGroupChatReq {
|
||||
string GroupId = 1;
|
||||
string OperationID = 2;
|
||||
message OperateGroupStatusReq {
|
||||
string GroupId = 1;
|
||||
int32 Status = 2;
|
||||
string OperationID = 3;
|
||||
}
|
||||
|
||||
message BanGroupChatResp {
|
||||
message OperateGroupStatusResp {
|
||||
|
||||
}
|
||||
|
||||
message BanPrivateChatReq {
|
||||
string GroupId = 1;
|
||||
string OperationID = 2;
|
||||
}
|
||||
|
||||
message BanPrivateChatResp {
|
||||
|
||||
}
|
||||
|
||||
message SetMasterReq {
|
||||
message OperateUserRoleReq {
|
||||
string GroupId = 1;
|
||||
string UserId = 2;
|
||||
string OperationID = 3;
|
||||
int32 RoleLevel = 3;
|
||||
string OperationID = 4;
|
||||
}
|
||||
|
||||
message SetMasterResp {
|
||||
message OperateUserRoleResp {
|
||||
|
||||
}
|
||||
|
||||
@ -259,6 +252,15 @@ message DeleteGroupResp {
|
||||
|
||||
}
|
||||
|
||||
message GetGroupByIdReq {
|
||||
string GroupId = 1;
|
||||
string OperationID = 2;
|
||||
}
|
||||
|
||||
message GetGroupByIdResp {
|
||||
server_api_params.GroupInfo GroupInfo = 1;
|
||||
}
|
||||
|
||||
service group{
|
||||
rpc createGroup(CreateGroupReq) returns(CreateGroupResp);
|
||||
rpc joinGroup(JoinGroupReq) returns(JoinGroupResp);
|
||||
@ -275,12 +277,11 @@ service group{
|
||||
rpc inviteUserToGroup(InviteUserToGroupReq) returns (InviteUserToGroupResp);
|
||||
rpc getGroupAllMember(GetGroupAllMemberReq) returns(GetGroupAllMemberResp);
|
||||
|
||||
|
||||
rpc GetGroupById(GetGroupByIdReq) returns(GetGroupByIdResp);
|
||||
rpc GetGroup(GetGroupReq) returns(GetGroupResp);
|
||||
rpc GetGroups(GetGroupsReq) returns(GetGroupsResp);
|
||||
rpc BanGroupChat(BanGroupChatReq) returns(BanGroupChatResp);
|
||||
rpc BanPrivateChat(BanPrivateChatReq) returns(BanPrivateChatResp);
|
||||
rpc SetMaster(SetMasterReq) returns(SetMasterResp);
|
||||
rpc OperateGroupStatus(OperateGroupStatusReq) returns(OperateGroupStatusResp);
|
||||
rpc OperateUserRole(OperateUserRoleReq) returns(OperateUserRoleResp);
|
||||
rpc DeleteGroup(DeleteGroupReq) returns(DeleteGroupResp);
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,9 @@
|
||||
|
||||
all_proto=(
|
||||
statistics/statistics.proto
|
||||
# auth/auth.proto
|
||||
# friend/friend.proto
|
||||
group/group.proto
|
||||
# group/group.proto
|
||||
# user/user.proto
|
||||
# chat/chat.proto
|
||||
# push/push.proto
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.26.0
|
||||
// protoc v3.19.3
|
||||
// protoc-gen-go v1.27.1
|
||||
// protoc v3.15.5
|
||||
// source: sdk_ws/ws.proto
|
||||
|
||||
package server_api_params
|
||||
|
1530
pkg/proto/statistics/statistics.pb.go
Normal file
1530
pkg/proto/statistics/statistics.pb.go
Normal file
File diff suppressed because it is too large
Load Diff
95
pkg/proto/statistics/statistics.proto
Normal file
95
pkg/proto/statistics/statistics.proto
Normal file
@ -0,0 +1,95 @@
|
||||
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{
|
||||
server_api_params.ResponsePagination Pagination = 1;
|
||||
string OperationID = 2;
|
||||
}
|
||||
|
||||
message UserResp{
|
||||
string NickName = 1;
|
||||
string UserId = 2;
|
||||
string MessageNum = 3;
|
||||
}
|
||||
|
||||
message GetActiveUserResp {
|
||||
repeated UserResp Users = 1;
|
||||
server_api_params.ResponsePagination Pagination = 2;
|
||||
}
|
||||
|
||||
message GetActiveGroupReq{
|
||||
server_api_params.ResponsePagination Pagination = 1;
|
||||
string OperationID = 2;
|
||||
}
|
||||
|
||||
message GroupResp {
|
||||
string GroupName = 1;
|
||||
string GroupId = 2;
|
||||
string MessageNum = 3;
|
||||
}
|
||||
|
||||
message GetActiveGroupResp {
|
||||
repeated GroupResp Groups = 1;
|
||||
server_api_params.ResponsePagination Pagination = 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;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user