mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-06-01 04:29:20 +08:00
errcode
This commit is contained in:
parent
4688767c51
commit
704b18d900
@ -3,7 +3,6 @@ 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"
|
||||||
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
|
||||||
"Open_IM/pkg/common/log"
|
"Open_IM/pkg/common/log"
|
||||||
promePkg "Open_IM/pkg/common/prometheus"
|
promePkg "Open_IM/pkg/common/prometheus"
|
||||||
"Open_IM/pkg/common/token_verify"
|
"Open_IM/pkg/common/token_verify"
|
||||||
@ -300,32 +299,23 @@ func (s *adminCMSServer) GetChatLogs(_ context.Context, req *pbAdminCMS.GetChatL
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *adminCMSServer) GetActiveGroup(_ context.Context, req *pbAdminCMS.GetActiveGroupReq) (*pbAdminCMS.GetActiveGroupResp, error) {
|
func (s *adminCMSServer) GetActiveGroup(_ context.Context, req *pbAdminCMS.GetActiveGroupReq) (*pbAdminCMS.GetActiveGroupResp, error) {
|
||||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req", req.String())
|
resp := &pbAdminCMS.GetActiveGroupResp{}
|
||||||
resp := &pbAdminCMS.GetActiveGroupResp{CommonResp: &pbAdminCMS.CommonResp{}}
|
|
||||||
fromTime, toTime, err := ParseTimeFromTo(req.StatisticsReq.From, req.StatisticsReq.To)
|
fromTime, toTime, err := ParseTimeFromTo(req.StatisticsReq.From, req.StatisticsReq.To)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "ParseTimeFromTo failed", err.Error())
|
return resp, err
|
||||||
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)
|
activeGroups, err := imdb.GetActiveGroups(fromTime, toTime, 12)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetActiveGroups failed", err.Error())
|
return resp, err
|
||||||
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
|
|
||||||
resp.CommonResp.ErrMsg = err.Error()
|
|
||||||
return resp, nil
|
|
||||||
}
|
}
|
||||||
for _, activeGroup := range activeGroups {
|
for _, activeGroup := range activeGroups {
|
||||||
resp.Groups = append(resp.Groups,
|
resp.Groups = append(resp.Groups,
|
||||||
&pbAdminCMS.GroupResp{
|
&pbAdminCMS.GroupResp{
|
||||||
GroupName: activeGroup.Name,
|
GroupName: activeGroup.Name,
|
||||||
GroupId: activeGroup.Id,
|
GroupID: activeGroup.Id,
|
||||||
MessageNum: int32(activeGroup.MessageNum),
|
MessageNum: int32(activeGroup.MessageNum),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), resp.String())
|
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -516,9 +506,9 @@ func (s *adminCMSServer) GetMessageStatistics(_ context.Context, req *pbAdminCMS
|
|||||||
resp.CommonResp.ErrMsg = err.Error()
|
resp.CommonResp.ErrMsg = err.Error()
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
privateMessageNum, err := imdb.GetPrivateMessageNum(fromTime, toTime.Add(time.Hour*24))
|
privateMessageNum, err := imdb.GetSingleChatMessageNum(fromTime, toTime.Add(time.Hour*24))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetPrivateMessageNum failed", err.Error())
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetSingleChatMessageNum failed", err.Error())
|
||||||
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
|
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
|
||||||
resp.CommonResp.ErrMsg = err.Error()
|
resp.CommonResp.ErrMsg = err.Error()
|
||||||
return resp, nil
|
return resp, nil
|
||||||
@ -542,7 +532,7 @@ func (s *adminCMSServer) GetMessageStatistics(_ context.Context, req *pbAdminCMS
|
|||||||
go func(wg *sync.WaitGroup, index int, v [2]time.Time) {
|
go func(wg *sync.WaitGroup, index int, v [2]time.Time) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
|
|
||||||
num, err := imdb.GetPrivateMessageNum(v[0], v[1])
|
num, err := imdb.GetSingleChatMessageNum(v[0], v[1])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetIncreaseGroupNum", v, err.Error())
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetIncreaseGroupNum", v, err.Error())
|
||||||
}
|
}
|
||||||
|
142
pkg/common/db/controller/admin_cms.go
Normal file
142
pkg/common/db/controller/admin_cms.go
Normal file
@ -0,0 +1,142 @@
|
|||||||
|
package controller
|
||||||
|
|
||||||
|
import (
|
||||||
|
"Open_IM/pkg/common/db/relation"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type AdminCMSInterface interface {
|
||||||
|
GetActiveUserNum(from, to time.Time) (num int64, err error)
|
||||||
|
GetIncreaseUserNum(from, to time.Time) (num int64, err error)
|
||||||
|
GetTotalUserNum() (num int64, err error)
|
||||||
|
GetTotalUserNumByDate(to time.Time) (num int64, err error)
|
||||||
|
GetSingleChatMessageNum(from, to time.Time) (num int64, err error)
|
||||||
|
GetGroupMessageNum(from, to time.Time) (num int64, err error)
|
||||||
|
GetIncreaseGroupNum(from, to time.Time) (num int64, err error)
|
||||||
|
GetTotalGroupNum() (num int64, err error)
|
||||||
|
GetGroupNum(to time.Time) (num int64, err error)
|
||||||
|
GetActiveGroups(from, to time.Time, limit int) (activeGroups []*relation.ActiveGroup, err error)
|
||||||
|
GetActiveUsers(from, to time.Time, limit int) (activeUsers []*relation.ActiveUser, err error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type AdminCMSController struct {
|
||||||
|
database AdminCMSDatabaseInterface
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewAdminCMSController(db *gorm.DB) AdminCMSInterface {
|
||||||
|
adminCMSController := &AdminCMSController{
|
||||||
|
database: newAdminCMSDatabase(db),
|
||||||
|
}
|
||||||
|
return adminCMSController
|
||||||
|
}
|
||||||
|
|
||||||
|
func newAdminCMSDatabase(db *gorm.DB) AdminCMSDatabaseInterface {
|
||||||
|
return &AdminCMSDatabase{Statistics: relation.NewStatistics(db)}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (admin *AdminCMSController) GetActiveUserNum(from, to time.Time) (num int64, err error) {
|
||||||
|
return admin.database.GetActiveUserNum(from, to)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (admin *AdminCMSController) GetIncreaseUserNum(from, to time.Time) (num int64, err error) {
|
||||||
|
return admin.database.GetIncreaseUserNum(from, to)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (admin *AdminCMSController) GetTotalUserNum() (num int64, err error) {
|
||||||
|
return admin.database.GetTotalUserNum()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (admin *AdminCMSController) GetTotalUserNumByDate(to time.Time) (num int64, err error) {
|
||||||
|
return admin.database.GetTotalUserNumByDate(to)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (admin *AdminCMSController) GetSingleChatMessageNum(from, to time.Time) (num int64, err error) {
|
||||||
|
return admin.GetSingleChatMessageNum(from, to)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (admin *AdminCMSController) GetGroupMessageNum(from, to time.Time) (num int64, err error) {
|
||||||
|
return admin.database.GetGroupMessageNum(from, to)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (admin *AdminCMSController) GetIncreaseGroupNum(from, to time.Time) (num int64, err error) {
|
||||||
|
return admin.database.GetIncreaseGroupNum(from, to)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (admin *AdminCMSController) GetTotalGroupNum() (num int64, err error) {
|
||||||
|
return admin.database.GetTotalGroupNum()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (admin *AdminCMSController) GetGroupNum(to time.Time) (num int64, err error) {
|
||||||
|
return admin.database.GetGroupNum(to)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (admin *AdminCMSController) GetActiveGroups(from, to time.Time, limit int) ([]*relation.ActiveGroup, error) {
|
||||||
|
return admin.database.GetActiveGroups(from, to, limit)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (admin *AdminCMSController) GetActiveUsers(from, to time.Time, limit int) (activeUsers []*relation.ActiveUser, err error) {
|
||||||
|
return admin.database.GetActiveUsers(from, to, limit)
|
||||||
|
}
|
||||||
|
|
||||||
|
type AdminCMSDatabaseInterface interface {
|
||||||
|
GetActiveUserNum(from, to time.Time) (num int64, err error)
|
||||||
|
GetIncreaseUserNum(from, to time.Time) (num int64, err error)
|
||||||
|
GetTotalUserNum() (num int64, err error)
|
||||||
|
GetTotalUserNumByDate(to time.Time) (num int64, err error)
|
||||||
|
GetSingleChatMessageNum(from, to time.Time) (num int64, err error)
|
||||||
|
GetGroupMessageNum(from, to time.Time) (num int64, err error)
|
||||||
|
GetIncreaseGroupNum(from, to time.Time) (num int64, err error)
|
||||||
|
GetTotalGroupNum() (num int64, err error)
|
||||||
|
GetGroupNum(to time.Time) (num int64, err error)
|
||||||
|
GetActiveGroups(from, to time.Time, limit int) ([]*relation.ActiveGroup, error)
|
||||||
|
GetActiveUsers(from, to time.Time, limit int) (activeUsers []*relation.ActiveUser, err error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type AdminCMSDatabase struct {
|
||||||
|
Statistics *relation.Statistics
|
||||||
|
}
|
||||||
|
|
||||||
|
func (admin *AdminCMSDatabase) GetActiveUserNum(from, to time.Time) (num int64, err error) {
|
||||||
|
return admin.Statistics.GetActiveUserNum(from, to)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (admin *AdminCMSDatabase) GetIncreaseUserNum(from, to time.Time) (num int64, err error) {
|
||||||
|
return admin.Statistics.GetIncreaseUserNum(from, to)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (admin *AdminCMSDatabase) GetTotalUserNum() (num int64, err error) {
|
||||||
|
return admin.Statistics.GetTotalUserNum()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (admin *AdminCMSDatabase) GetTotalUserNumByDate(to time.Time) (num int64, err error) {
|
||||||
|
return admin.Statistics.GetTotalUserNumByDate(to)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (admin *AdminCMSDatabase) GetSingleChatMessageNum(from, to time.Time) (num int64, err error) {
|
||||||
|
return admin.Statistics.GetSingleChatMessageNum(from, to)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (admin *AdminCMSDatabase) GetGroupMessageNum(from, to time.Time) (num int64, err error) {
|
||||||
|
return admin.Statistics.GetGroupMessageNum(from, to)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (admin *AdminCMSDatabase) GetIncreaseGroupNum(from, to time.Time) (num int64, err error) {
|
||||||
|
return admin.Statistics.GetIncreaseGroupNum(from, to)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (admin *AdminCMSDatabase) GetTotalGroupNum() (num int64, err error) {
|
||||||
|
return admin.Statistics.GetTotalGroupNum()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (admin *AdminCMSDatabase) GetGroupNum(to time.Time) (num int64, err error) {
|
||||||
|
return admin.Statistics.GetGroupNum(to)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (admin *AdminCMSDatabase) GetActiveGroups(from, to time.Time, limit int) ([]*relation.ActiveGroup, error) {
|
||||||
|
return admin.Statistics.GetActiveGroups(from, to, limit)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (admin *AdminCMSDatabase) GetActiveUsers(from, to time.Time, limit int) (activeUsers []*relation.ActiveUser, err error) {
|
||||||
|
return admin.Statistics.GetActiveUsers(from, to, limit)
|
||||||
|
}
|
@ -24,7 +24,7 @@ type GroupInterface interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type GroupController struct {
|
type GroupController struct {
|
||||||
database DataBase
|
database GroupDataBaseInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewGroupController(db *gorm.DB, rdb redis.UniversalClient, mgoDB *mongo.Client) GroupInterface {
|
func NewGroupController(db *gorm.DB, rdb redis.UniversalClient, mgoDB *mongo.Client) GroupInterface {
|
||||||
@ -56,7 +56,7 @@ func (g *GroupController) CreateSuperGroup(ctx context.Context, groupID string,
|
|||||||
return g.database.CreateSuperGroup(ctx, groupID, initMemberIDList)
|
return g.database.CreateSuperGroup(ctx, groupID, initMemberIDList)
|
||||||
}
|
}
|
||||||
|
|
||||||
type DataBase interface {
|
type GroupDataBaseInterface interface {
|
||||||
FindGroupsByID(ctx context.Context, groupIDs []string) (groups []*relation.Group, err error)
|
FindGroupsByID(ctx context.Context, groupIDs []string) (groups []*relation.Group, err error)
|
||||||
CreateGroup(ctx context.Context, groups []*relation.Group, groupMember []*relation.GroupMember) error
|
CreateGroup(ctx context.Context, groups []*relation.Group, groupMember []*relation.GroupMember) error
|
||||||
DeleteGroupByIDs(ctx context.Context, groupIDs []string) error
|
DeleteGroupByIDs(ctx context.Context, groupIDs []string) error
|
||||||
@ -75,7 +75,7 @@ type GroupDataBase struct {
|
|||||||
mongoDB *unrelation.SuperGroupMgoDB
|
mongoDB *unrelation.SuperGroupMgoDB
|
||||||
}
|
}
|
||||||
|
|
||||||
func newGroupDatabase(db *gorm.DB, rdb redis.UniversalClient, mgoDB *mongo.Client) DataBase {
|
func newGroupDatabase(db *gorm.DB, rdb redis.UniversalClient, mgoDB *mongo.Client) GroupDataBaseInterface {
|
||||||
groupDB := relation.NewGroupDB(db)
|
groupDB := relation.NewGroupDB(db)
|
||||||
groupMemberDB := relation.NewGroupMemberDB(db)
|
groupMemberDB := relation.NewGroupMemberDB(db)
|
||||||
groupRequestDB := relation.NewGroupRequest(db)
|
groupRequestDB := relation.NewGroupRequest(db)
|
||||||
|
@ -46,7 +46,7 @@ func (s *Statistics) GetTotalUserNumByDate(to time.Time) (num int64, err error)
|
|||||||
return num, err
|
return num, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Statistics) GetPrivateMessageNum(from, to time.Time) (num int64, err error) {
|
func (s *Statistics) GetSingleChatMessageNum(from, to time.Time) (num int64, err error) {
|
||||||
err = s.getChatLogModel().Where("send_time >= ? and send_time <= ? and session_type = ?", from, to, constant.SingleChatType).Count(&num).Error
|
err = s.getChatLogModel().Where("send_time >= ? and send_time <= ? and session_type = ?", from, to, constant.SingleChatType).Count(&num).Error
|
||||||
return num, err
|
return num, err
|
||||||
}
|
}
|
||||||
@ -71,18 +71,18 @@ func (s *Statistics) GetGroupNum(to time.Time) (num int64, err error) {
|
|||||||
return num, err
|
return num, err
|
||||||
}
|
}
|
||||||
|
|
||||||
type activeGroup struct {
|
type ActiveGroup struct {
|
||||||
Name string
|
Name string
|
||||||
Id string `gorm:"column:recv_id"`
|
ID string `gorm:"column:recv_id"`
|
||||||
MessageNum int `gorm:"column:message_num"`
|
MessageNum int `gorm:"column:message_num"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Statistics) GetActiveGroups(from, to time.Time, limit int) ([]*activeGroup, error) {
|
func (s *Statistics) GetActiveGroups(from, to time.Time, limit int) ([]*ActiveGroup, error) {
|
||||||
var activeGroups []*activeGroup
|
var activeGroups []*ActiveGroup
|
||||||
err := s.getChatLogModel().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
|
err := s.getChatLogModel().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 := Group{
|
group := Group{
|
||||||
GroupID: activeGroup.Id,
|
GroupID: activeGroup.ID,
|
||||||
}
|
}
|
||||||
s.getGroupModel().Where("group_id= ? ", group.GroupID).Find(&group)
|
s.getGroupModel().Where("group_id= ? ", group.GroupID).Find(&group)
|
||||||
activeGroup.Name = group.GroupName
|
activeGroup.Name = group.GroupName
|
||||||
@ -90,13 +90,13 @@ func (s *Statistics) GetActiveGroups(from, to time.Time, limit int) ([]*activeGr
|
|||||||
return activeGroups, err
|
return activeGroups, err
|
||||||
}
|
}
|
||||||
|
|
||||||
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 (s *Statistics) GetActiveUsers(from, to time.Time, limit int) (activeUsers []*activeUser, err error) {
|
func (s *Statistics) GetActiveUsers(from, to time.Time, limit int) (activeUsers []*ActiveUser, err error) {
|
||||||
err = s.getChatLogModel().Select("send_id, count(*) as message_num").Where("send_time >= ? and send_time <= ? and session_type in (?)", from, to, []int{constant.SingleChatType, constant.GroupChatType, constant.SuperGroupChatType}).Group("send_id").Limit(limit).Order("message_num DESC").Find(&activeUsers).Error
|
err = s.getChatLogModel().Select("send_id, count(*) as message_num").Where("send_time >= ? and send_time <= ? and session_type in (?)", from, to, []int{constant.SingleChatType, constant.GroupChatType, constant.SuperGroupChatType}).Group("send_id").Limit(limit).Order("message_num DESC").Find(&activeUsers).Error
|
||||||
for _, activeUser := range activeUsers {
|
for _, activeUser := range activeUsers {
|
||||||
user := User{
|
user := User{
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -92,7 +92,6 @@ message DateNumList {
|
|||||||
|
|
||||||
message GetMessageStatisticsReq {
|
message GetMessageStatisticsReq {
|
||||||
StatisticsReq StatisticsReq = 1;
|
StatisticsReq StatisticsReq = 1;
|
||||||
string OperationID = 2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -101,12 +100,10 @@ message GetMessageStatisticsResp {
|
|||||||
int32 GroupMessageNum = 2;
|
int32 GroupMessageNum = 2;
|
||||||
repeated DateNumList PrivateMessageNumList = 3;
|
repeated DateNumList PrivateMessageNumList = 3;
|
||||||
repeated DateNumList GroupMessageNumList = 4;
|
repeated DateNumList GroupMessageNumList = 4;
|
||||||
CommonResp commonResp = 5;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
message GetGroupStatisticsReq {
|
message GetGroupStatisticsReq {
|
||||||
StatisticsReq StatisticsReq = 1;
|
StatisticsReq StatisticsReq = 1;
|
||||||
string OperationID = 2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -115,7 +112,6 @@ message GetGroupStatisticsResp {
|
|||||||
int32 TotalGroupNum = 2;
|
int32 TotalGroupNum = 2;
|
||||||
repeated DateNumList IncreaseGroupNumList = 3;
|
repeated DateNumList IncreaseGroupNumList = 3;
|
||||||
repeated DateNumList TotalGroupNumList = 4;
|
repeated DateNumList TotalGroupNumList = 4;
|
||||||
CommonResp commonResp = 5;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
message GetUserStatisticsReq {
|
message GetUserStatisticsReq {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user