by Robin at 20241017

This commit is contained in:
Leufolium 2024-10-17 16:30:32 +08:00
parent 9d9209be23
commit 9ebe86919d
5 changed files with 57 additions and 15 deletions

View File

@ -6322,6 +6322,25 @@ func (m *Mongo) GetAndUpdateNotifBcstVers(ctx *gin.Context, objType int64) (vers
return &versInstance, err
}
func (m *Mongo) GetNotifBcstVers(ctx *gin.Context, objType int64) (vers *dbstruct.NotifBcstVers, err error) {
col := m.getColNotifBcstVers()
id := ""
if objType == consts.Notification_ObjType_AllStreamer {
id = "all_streamer"
} else if objType == consts.Notification_ObjType_AllUser {
id = "all_user"
}
vers = &dbstruct.NotifBcstVers{}
err = col.Find(ctx, qmgo.M{"_id": id}).One(vers)
if err == qmgo.ErrNoSuchDocuments {
err = nil
return nil, err
}
return vers, err
}
// 通知广播接收版本号表
func (m *Mongo) GetAndUpdateNotifBcstReceiveVers(ctx *gin.Context, mid int64, vers int64) (receiveVers *dbstruct.NotifBcstReceiveVers, err error) {
col := m.getColNotifBcstReceiveVers()

View File

@ -45,7 +45,7 @@ func (p *NotifBcst) OpDeleteByIds(ctx *gin.Context, ids []int64) error {
return nil
}
func (p *NotifBcst) OpListByByVersRange(ctx *gin.Context, vers_lb, vers_ub, offset, limit int64) ([]*dbstruct.NotifBcst, error) {
func (p *NotifBcst) OpListByVersRange(ctx *gin.Context, vers_lb, vers_ub, offset, limit int64) ([]*dbstruct.NotifBcst, error) {
list, err := p.store.GetNotifBcstListByVersRange(ctx, vers_lb, vers_ub, offset, limit)
if err != nil {
logger.Error("GetNotificationListByMid fail, err: %v", err)

View File

@ -19,6 +19,15 @@ func NewZoneNotifBcstVers(store *dao.Store) (a *NotifBcstVers) {
return
}
func (p *NotifBcstVers) GetNotifBcstVers(ctx *gin.Context, objType int64) (*dbstruct.NotifBcstVers, error) {
vers, err := p.store.GetNotifBcstVers(ctx, objType)
if err != nil {
logger.Error("GetNotifBcstVers fail, err: %v", err)
return nil, err
}
return vers, err
}
func (p *NotifBcstVers) GetAndUpdateNotifBcstVers(ctx *gin.Context, objType int64) (*dbstruct.NotifBcstVers, error) {
vers, err := p.store.GetAndUpdateNotifBcstVers(ctx, objType)
if err != nil {

View File

@ -1,5 +1,12 @@
package service
import (
"service/api/consts"
"service/library/logger"
"github.com/gin-gonic/gin"
)
var DefaultNotifBcstCenter *NotifBcstCenter
// 全局广播消息中心
@ -9,16 +16,6 @@ func NewNotifBcstCenter() *NotifBcstCenter {
return new(NotifBcstCenter)
}
// 获取主播全局广播消息中心版本号
func (s *NotifBcstCenter) GetStreamerNotifBcstCenterVers() (int64, error) {
}
// 获取用户全局消息中心版本号
func (s *NotifBcstCenter) GetUserNotifBcstCenterVers() (int64, error) {
}
// 写入一条主播全局广播消息
func (s *NotifBcstCenter) BcstANotifToAllStreamers() error {
@ -35,14 +32,28 @@ func (s *NotifBcstCenter) BcstANotifToAllStreamersAndUsers() error {
}
// 主播获取全局广播消息
func (s *NotifBcstCenter) ReceiveAllBcstedNotifsAsStreamer(mid int64) error {
// 获取该主播已接收的全局广播版本号
func (s *NotifBcstCenter) ReceiveAllBcstedNotifsAsStreamer(ctx *gin.Context, mid int64) error {
// 获取当前主播全局广播的版本号
notifBcstVers, err := _DefaultNotifBcstVers.GetNotifBcstVers(ctx, consts.Notification_ObjType_AllStreamer)
if err != nil {
logger.Error("GetNotifBcstVers fail, err: %v", err)
return err
}
// 获取该主播已接收的全局广播版本号
notifBcstReceiveVers, err := _DefaultNotifBcstVers.GetAndUpdateNotifBcstReceiveVers(ctx, mid, notifBcstVers.Vers)
if err != nil {
logger.Error("GetAndUpdateNotifBcstReceiveVers fail, err: %v", err)
return err
}
// 如果版本号一致,则认为无需再接收新的广播
if notifBcstReceiveVers.Vers == notifBcstVers.Vers {
return nil
}
// 如果版本号不一致看,则接收新广播的消息
// 如果版本号不一致,则接收新广播的消息
_DefaultNotifBcst.OpListByVersRange(ctx, notifBcstReceiveVers.Vers, notifBcstVers.Vers-1, 0, 1000)
}
// 用户获取全局广播消息

View File

@ -153,6 +153,9 @@ var (
_DefaultAutoResponseCreateTimes *logic.AutoResponseCreateTimes
_DefaultNotification *logic.Notification
_DefaultRavenIQTest *logic.RavenIQTest
_DefaultNotifBcstVers *logic.NotifBcstVers
_DefaultNotifBcst *logic.NotifBcst
_DefaultNotifReceive *logic.NotifReceive
)
type Service struct {