by Robin at 20240604

This commit is contained in:
Leufolium 2024-06-04 12:16:17 +08:00
parent 3d2cc139d6
commit 10636fa6a4
3 changed files with 42 additions and 45 deletions

View File

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

View File

@ -10,6 +10,8 @@ import (
"service/library/logger"
"sort"
streamerproto "service/api/proto/streamer/proto"
"github.com/gin-gonic/gin"
)
@ -21,6 +23,7 @@ type StreamerRecommService struct {
momentService *logic.Moment
zoneMomentService *logic.ZoneMoment
vasService *logic.Vas
streamerService *logic.Streamer
out func([]int64) error
formula *apollostruct.StreamerScoreFormulaCfg
@ -33,10 +36,11 @@ func NewStreamerRecommService() *StreamerRecommService {
return new(StreamerRecommService)
}
func (s *StreamerRecommService) SetStreamerRecommDbService(moment *logic.Moment, zonemoment *logic.ZoneMoment, vas *logic.Vas) {
func (s *StreamerRecommService) SetStreamerRecommDbService(moment *logic.Moment, zonemoment *logic.ZoneMoment, vas *logic.Vas, streamer *logic.Streamer) {
s.momentService = moment
s.zoneMomentService = zonemoment
s.vasService = vas
s.streamerService = streamer
}
func (s *StreamerRecommService) SetOut(out func([]int64) error) {
@ -101,6 +105,21 @@ func (s *StreamerRecommService) init() error {
}
// 获取优先级
s.formula.CalPriority()
// 初始化主播的数据
list, err := s.streamerService.OpList(&gin.Context{}, &streamerproto.OpListReq{})
if err != nil {
logger.Error("Streamer OpList err: %v", err)
return err
}
for _, streamer := range list {
score := &StreamerScore{
Mid: streamer.GetMid(),
}
s.scores[streamer.GetMid()] = score
s.scorelist = append(s.scorelist, score)
}
return nil
}
@ -185,9 +204,10 @@ func (s *StreamerRecommService) push() error {
list := make([]int64, 0)
for i := len(s.scorelist) - 1; i >= 0; i-- {
v := s.scorelist[i]
logger.Info("%v得分:%v", v.Mid, v.Score)
logger.Info("%v得分:%v %v %v %v %v %v %v", v.Mid, v.Score, v.ZoneMomentCountInThreeDays, v.ZoneMomentCountInAMonth, v.IncomeInAWeek, v.NewZoneMemberCountInThreeDays, v.NewZoneMemberCountInAMonth, v.MomentCountInThreeDays)
list = append(list, v.Mid)
}
return s.out(list)
}
@ -201,14 +221,9 @@ func (s *StreamerRecommService) recvZoneMomentStatInfoInThreeDays(ctx *gin.Conte
}
for _, zmsi := range zoneMomentStatInfoList {
_, ok := s.scores[zmsi.GetMid()]
if !ok {
s.scores[zmsi.GetMid()] = &StreamerScore{
Mid: zmsi.GetMid(),
}
s.scorelist = append(s.scorelist, s.scores[zmsi.GetMid()])
if _, ok := s.scores[zmsi.GetMid()]; ok {
s.scores[zmsi.GetMid()].ZoneMomentCountInThreeDays = zmsi.GetCount()
}
s.scores[zmsi.GetMid()].ZoneMomentCountInThreeDays = zmsi.GetCount()
}
return
}
@ -222,14 +237,9 @@ func (s *StreamerRecommService) recvZoneMomentStatInfoInAMonth(ctx *gin.Context,
}
for _, zmsi := range zoneMomentStatInfoList {
_, ok := s.scores[zmsi.GetMid()]
if !ok {
s.scores[zmsi.GetMid()] = &StreamerScore{
Mid: zmsi.GetMid(),
}
s.scorelist = append(s.scorelist, s.scores[zmsi.GetMid()])
if _, ok := s.scores[zmsi.GetMid()]; ok {
s.scores[zmsi.GetMid()].ZoneMomentCountInAMonth = zmsi.GetCount()
}
s.scores[zmsi.GetMid()].ZoneMomentCountInAMonth = zmsi.GetCount()
}
return
}
@ -243,14 +253,9 @@ func (s *StreamerRecommService) recvStreamerProfitInAWeek(ctx *gin.Context, st,
}
for _, sp := range streamerProfitList {
_, ok := s.scores[sp.GetMid()]
if !ok {
s.scores[sp.GetMid()] = &StreamerScore{
Mid: sp.GetMid(),
}
s.scorelist = append(s.scorelist, s.scores[sp.GetMid()])
if _, ok := s.scores[sp.GetMid()]; ok {
s.scores[sp.GetMid()].IncomeInAWeek = sp.GetAmount()
}
s.scores[sp.GetMid()].IncomeInAWeek = sp.GetAmount()
}
return
}
@ -264,14 +269,9 @@ func (s *StreamerRecommService) recvZoneAdmissionInfoInThreeDays(ctx *gin.Contex
}
for _, zai := range zoneAdmissionInfoList {
_, ok := s.scores[zai.GetMid()]
if !ok {
s.scores[zai.GetMid()] = &StreamerScore{
Mid: zai.GetMid(),
}
s.scorelist = append(s.scorelist, s.scores[zai.GetMid()])
if _, ok := s.scores[zai.GetMid()]; ok {
s.scores[zai.GetMid()].NewZoneMemberCountInThreeDays = zai.GetNum()
}
s.scores[zai.GetMid()].NewZoneMemberCountInThreeDays = zai.GetNum()
}
return
}
@ -285,14 +285,9 @@ func (s *StreamerRecommService) recvZoneAdmissionInfoInAMonth(ctx *gin.Context,
}
for _, zai := range zoneAdmissionInfoList {
_, ok := s.scores[zai.GetMid()]
if !ok {
s.scores[zai.GetMid()] = &StreamerScore{
Mid: zai.GetMid(),
}
s.scorelist = append(s.scorelist, s.scores[zai.GetMid()])
if _, ok := s.scores[zai.GetMid()]; ok {
s.scores[zai.GetMid()].NewZoneMemberCountInAMonth = zai.GetNum()
}
s.scores[zai.GetMid()].NewZoneMemberCountInAMonth = zai.GetNum()
}
return
}
@ -306,14 +301,9 @@ func (s *StreamerRecommService) recvMomentStatInfoInThreeDays(ctx *gin.Context,
}
for _, msi := range momentStatInfoList {
_, ok := s.scores[msi.GetMid()]
if !ok {
s.scores[msi.GetMid()] = &StreamerScore{
Mid: msi.GetMid(),
}
s.scorelist = append(s.scorelist, s.scores[msi.GetMid()])
if _, ok := s.scores[msi.GetMid()]; ok {
s.scores[msi.GetMid()].MomentCountInThreeDays = msi.GetCount()
}
s.scores[msi.GetMid()].MomentCountInThreeDays = msi.GetCount()
}
return
}

View File

@ -26,3 +26,10 @@ type Streamer struct {
WechatContact *string `json:"wechat_contact"` // 微信联系方式
WechatCoinPrice *int64 `json:"wechat_coin_price"` // 微信金币价格
}
func (p *Streamer) GetMid() int64 {
if p == nil || p.Mid == nil {
return -1
}
return *p.Mid
}