mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-24 10:22:36 +08:00
cms
This commit is contained in:
parent
a4b95cb7cf
commit
c2831e6676
@ -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"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ 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)
|
||||||
@ -43,7 +43,7 @@ func GetChatLogs(c *gin.Context) {
|
|||||||
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())
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 400, "errMsg": err.Error()})
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for _, v := range respPb.ChatLogs {
|
for _, v := range respPb.ChatLogs {
|
||||||
|
@ -296,7 +296,7 @@ func (s *adminCMSServer) GetActiveUser(_ context.Context, req *pbAdminCMS.GetAct
|
|||||||
for _, activeUser := range activeUsers {
|
for _, activeUser := range activeUsers {
|
||||||
resp.Users = append(resp.Users,
|
resp.Users = append(resp.Users,
|
||||||
&pbAdminCMS.UserResp{
|
&pbAdminCMS.UserResp{
|
||||||
UserId: activeUser.Id,
|
UserId: activeUser.ID,
|
||||||
NickName: activeUser.Name,
|
NickName: activeUser.Name,
|
||||||
MessageNum: int32(activeUser.MessageNum),
|
MessageNum: int32(activeUser.MessageNum),
|
||||||
},
|
},
|
||||||
|
@ -13,6 +13,7 @@ type GetChatLogsReq struct {
|
|||||||
GroupID string `json:"groupID"`
|
GroupID string `json:"groupID"`
|
||||||
SendTime string `json:"sendTime"`
|
SendTime string `json:"sendTime"`
|
||||||
RequestPagination
|
RequestPagination
|
||||||
|
OperationID string `json:"operationID"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type GetChatLogsResp struct {
|
type GetChatLogsResp struct {
|
||||||
|
@ -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,7 +176,7 @@ 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"`
|
AppMangerLevel int32 `gorm:"column:app_manger_level"`
|
||||||
GlobalRecvMsgOpt int32 `gorm:"column:global_recv_msg_opt"`
|
GlobalRecvMsgOpt int32 `gorm:"column:global_recv_msg_opt"`
|
||||||
InvitationCode string `gorm:"column:invitation_code"`
|
InvitationCode string `gorm:"column:invitation_code"`
|
||||||
@ -232,7 +232,7 @@ type ChatLog struct {
|
|||||||
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;;index:session_type" json:"sessionType"`
|
SessionType int32 `gorm:"column:session_type;index:session_type" json:"sessionType"`
|
||||||
MsgFrom int32 `gorm:"column:msg_from" json:"msgFrom"`
|
MsgFrom int32 `gorm:"column:msg_from" json:"msgFrom"`
|
||||||
ContentType int32 `gorm:"column:content_type;index:content_type" json:"contentType"`
|
ContentType int32 `gorm:"column:content_type;index:content_type" json:"contentType"`
|
||||||
Content string `gorm:"column:content;type:varchar(3000);index:search" json:"content"`
|
Content string `gorm:"column:content;type:varchar(3000);index:search" json:"content"`
|
||||||
|
@ -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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user