by Robin at 20240621

This commit is contained in:
Leufolium 2024-06-21 19:51:55 +08:00
parent b83aab01a7
commit 41cf08be7c
7 changed files with 80 additions and 10 deletions

View File

@ -23,6 +23,9 @@ const (
AccountPunishment_BlockFromCreatingFreeZoneMoment = 1 // 禁止发免费空间贴
AccountPunishment_BlockFromCreatingPaidZoneMoment = 2 // 禁止发付费空间贴
AccountPunishment_BlockFromCreatingZoneMoment = 3 // 禁止发空间贴
AccountPunishment_BlockFromBeingSearched = 4 // 禁止被搜索到
AccountPunishment_BlockFromBeingDiscovered = 5 // 禁止在推荐被发现
AccountPunishment_BlockFromBeingSeenAtMoment = 6 // 禁止在广场被发现
)
const (

View File

@ -3753,6 +3753,27 @@ func (m *Mongo) GetAccountPunishmentListByMidAndType(ctx *gin.Context, mid int64
return accountpunishment, err
}
func (m *Mongo) GetAccountPunishmentListByType(ctx *gin.Context, typ int64) ([]*dbstruct.AccountPunishment, error) {
list := make([]*dbstruct.AccountPunishment, 0)
col := m.getColAccountPunishment()
query := qmgo.M{
"type": typ,
"status": qmgo.M{
"$ne": consts.AccountPunishment_Interrupted,
},
"end_time": qmgo.M{
"$gt": time.Now().Unix(),
},
"del_flag": 0,
}
err := col.Find(ctx, query).All(&list)
if err == qmgo.ErrNoSuchDocuments {
err = nil
return nil, err
}
return list, err
}
func (m *Mongo) GetTerminatedAccountPunishmentList(ctx *gin.Context, req *accountpunishmentproto.OpListTerminatedReq) ([]*dbstruct.AccountPunishment, error) {
list := make([]*dbstruct.AccountPunishment, 0)
col := m.getColAccountPunishment()

View File

@ -101,3 +101,12 @@ func (p *AccountPunishment) OpListByMidAndType(ctx *gin.Context, mid int64, typ
}
return accountpunishment, nil
}
func (p *AccountPunishment) OpListByType(ctx *gin.Context, typ int64) ([]*dbstruct.AccountPunishment, error) {
list, err := p.store.GetAccountPunishmentListByType(ctx, typ)
if err != nil {
logger.Error("GetAccountPunishmentListByType fail, err: %v", err)
return nil, err
}
return list, nil
}

View File

@ -268,7 +268,7 @@ func (s *Service) ConnectToVideoModeration() {
// 推荐服务数据库接口
func (s *Service) ConnectToStreamerRecommService(r *StreamerRecommService) {
r.SetStreamerRecommDbService(_DefaultMoment, _DefaultZoneMoment, _DefaultVas, _DefaultStreamer, _DefaultStreamerScore)
r.SetStreamerRecommDbService(_DefaultMoment, _DefaultZoneMoment, _DefaultVas, _DefaultStreamer, _DefaultStreamerScore, _DefaultAccountPunishment)
r.SetOut(func(mids []int64) error {
err := redis.GetRedisClient().Set(consts.RedisStreamerPrefix+"recomm_list", mids, 0)
if err != nil {

View File

@ -21,12 +21,13 @@ var (
)
type StreamerRecommService struct {
momentService *logic.Moment
zoneMomentService *logic.ZoneMoment
vasService *logic.Vas
streamerService *logic.Streamer
streamerScoreService *logic.StreamerScore
out func([]int64) error
momentService *logic.Moment
zoneMomentService *logic.ZoneMoment
vasService *logic.Vas
streamerService *logic.Streamer
streamerScoreService *logic.StreamerScore
accountpunishmentService *logic.AccountPunishment
out func([]int64) error
formula *apollostruct.StreamerScoreFormulaCfg
@ -38,12 +39,13 @@ func NewStreamerRecommService() *StreamerRecommService {
return new(StreamerRecommService)
}
func (s *StreamerRecommService) SetStreamerRecommDbService(moment *logic.Moment, zonemoment *logic.ZoneMoment, vas *logic.Vas, streamer *logic.Streamer, streamerScore *logic.StreamerScore) {
func (s *StreamerRecommService) SetStreamerRecommDbService(moment *logic.Moment, zonemoment *logic.ZoneMoment, vas *logic.Vas, streamer *logic.Streamer, streamerScore *logic.StreamerScore, accountpunishment *logic.AccountPunishment) {
s.momentService = moment
s.zoneMomentService = zonemoment
s.vasService = vas
s.streamerService = streamer
s.streamerScoreService = streamerScore
s.accountpunishmentService = accountpunishment
}
func (s *StreamerRecommService) SetOut(out func([]int64) error) {
@ -211,10 +213,25 @@ func (s *StreamerRecommService) save() {
// 推送
func (s *StreamerRecommService) push() error {
// 查找禁止在推荐被发现的主播,不将其加入推荐列
acctpunishments, err := _DefaultAccountPunishment.OpListByType(&gin.Context{}, consts.AccountPunishment_BlockFromBeingDiscovered)
if err != nil {
logger.Error("_DefaultAccountPunishment OpListByType fail, err: %v", err)
}
blockedMp := make(map[int64]*dbstruct.AccountPunishment)
for _, acctpunishment := range acctpunishments {
blockedMp[acctpunishment.GetMid()] = &dbstruct.AccountPunishment{}
}
list := make([]int64, 0)
l := make([]*dbstruct.StreamerScore, 0)
for i := len(s.scorelist) - 1; i >= 0; i-- {
v := s.scorelist[i]
if _, ok := blockedMp[v.Mid]; ok {
continue
}
list = append(list, v.Mid)
l = append(l, &dbstruct.StreamerScore{
Id: v.Mid,
@ -229,7 +246,7 @@ func (s *StreamerRecommService) push() error {
Score: v.Score,
})
}
err := _DefaultStreamerScore.OpSetStreamerScore(&gin.Context{}, l)
err = _DefaultStreamerScore.OpSetStreamerScore(&gin.Context{}, l)
if err != nil {
logger.Error("OpSetStreamerScore fail, err: %v", err)
}

View File

@ -461,6 +461,16 @@ func (s *CronService) ReloadMomentRecommList(ctx context.Context, param *xxl.Run
return fmt.Sprintf("OpGetMomentListByMids fail, err: %v", err)
}
// 查找禁止在广场被发现的主播,不将其加入推荐列
acctpunishments, err := _DefaultAccountPunishment.OpListByType(&gin.Context{}, consts.AccountPunishment_BlockFromBeingSeenAtMoment)
if err != nil {
logger.Error("_DefaultAccountPunishment OpListByType fail, err: %v", err)
}
blockedMp := make(map[int64]*dbstruct.AccountPunishment)
for _, acctpunishment := range acctpunishments {
blockedMp[acctpunishment.GetMid()] = &dbstruct.AccountPunishment{}
}
// 清缓存
if err := redis.GetRedisClient().Del(consts.RedisMomentPrefix + "recomm_list"); err != nil {
logger.Error("Del redis cache fail, err: %v", err)
@ -477,7 +487,10 @@ func (s *CronService) ReloadMomentRecommList(ctx context.Context, param *xxl.Run
// 加载缓存
for _, moment := range list {
id := util.DerefInt64(moment.Id)
if _, ok := blockedMp[moment.GetMid()]; ok {
continue
}
id := moment.GetId()
err := redis.GetRedisClient().RPush(consts.RedisMomentPrefix+"recomm_list", id)
if err != nil {
logger.Error("Redis cache fail, err: %v", err)

View File

@ -19,6 +19,13 @@ type AccountPunishment struct {
DelFlag *int64 `json:"del_flag" bson:"del_flag"` // 删除标记
}
func (p *AccountPunishment) GetMid() int64 {
if p == nil || p.Mid == nil {
return 0
}
return *p.Mid
}
func (p *AccountPunishment) GetEndTimeFormatString() string {
if p == nil || p.EndTime == nil {
return ""