|
|
|
@ -44,9 +44,6 @@ func NewRedis() *redis.Client {
|
|
|
|
|
return redisInstance |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
type Task struct { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func NewTask() { |
|
|
|
|
for { |
|
|
|
|
redisClient := NewRedis() |
|
|
|
@ -78,18 +75,19 @@ func NewTask() {
|
|
|
|
|
roomClientV2, err := client.GetRoomClientV2(ctx) |
|
|
|
|
//roomClientV2, err := client.GetRoomClientLocalV2("127.0.0.1:9001")
|
|
|
|
|
if err != nil { |
|
|
|
|
return |
|
|
|
|
fmt.Println("获取房间服务失败:", err.Error()) |
|
|
|
|
continue |
|
|
|
|
} |
|
|
|
|
roomRsp, err := roomClientV2.GetRoom(ctx, &v2.GetRoomReq{ |
|
|
|
|
RoomId: roomId, |
|
|
|
|
}) |
|
|
|
|
if err != nil { |
|
|
|
|
fmt.Println("获取房间失败:", err.Error()) |
|
|
|
|
continue |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 忽略下播的房间和广场房间
|
|
|
|
|
if roomRsp.Status != v2.RoomStatus_RoomStatusUp || roomRsp.RoomType == v2.RoomType_Hall { |
|
|
|
|
return |
|
|
|
|
continue |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 获取房间
|
|
|
|
@ -98,12 +96,14 @@ func NewTask() {
|
|
|
|
|
|
|
|
|
|
liveClientV2, err := client.GetLiveClient(ctx) |
|
|
|
|
if err != nil { |
|
|
|
|
fmt.Println("获取直播服务失败:", err.Error()) |
|
|
|
|
continue |
|
|
|
|
} |
|
|
|
|
defaultHotValueResp, err := liveClientV2.GetDefaultHotValueList(ctx, &livev1.GetDefaultHotValueListReq{ |
|
|
|
|
RoomList: []int64{roomId}, |
|
|
|
|
}) |
|
|
|
|
if err != nil { |
|
|
|
|
fmt.Println("获取热度默认值失败:", err.Error()) |
|
|
|
|
continue |
|
|
|
|
} |
|
|
|
|
if len(defaultHotValueResp.Items) != 0 { |
|
|
|
@ -115,10 +115,10 @@ func NewTask() {
|
|
|
|
|
StatusList: []int32{1}, |
|
|
|
|
}) |
|
|
|
|
if err != nil { |
|
|
|
|
fmt.Println("获取在线总数失败:", err.Error()) |
|
|
|
|
continue |
|
|
|
|
} |
|
|
|
|
currentOnlineTotal = onlineCountRsp.Total |
|
|
|
|
|
|
|
|
|
// 一天之前的时间
|
|
|
|
|
//todayMinutesSecond := (now.Unix() - 10*60) * 1000
|
|
|
|
|
todayMinutes := jtime.TimeTimestamp(jtime.SecondsAgoTime(now, -(86400))) |
|
|
|
@ -130,14 +130,16 @@ func NewTask() {
|
|
|
|
|
// 获取房间总流水
|
|
|
|
|
giftClient, err := client.GetGiftClient(ctx) |
|
|
|
|
if err != nil { |
|
|
|
|
return |
|
|
|
|
fmt.Println("获取礼物服务失败:", err.Error()) |
|
|
|
|
continue |
|
|
|
|
} |
|
|
|
|
giftRsp, err := giftClient.QueryGiveRoomGift(ctx, &giftv1.QueryGiveRoomGiftReq{ |
|
|
|
|
RoomIdList: []int64{roomId}, |
|
|
|
|
CreateAtStart: &startTime, |
|
|
|
|
}) |
|
|
|
|
if err != nil { |
|
|
|
|
return |
|
|
|
|
fmt.Println("获取礼物数据失败:", err.Error()) |
|
|
|
|
continue |
|
|
|
|
} |
|
|
|
|
amountTotal = giftRsp.TotalAmountDiamond + giftRsp.TotalAmountGoldCoins |
|
|
|
|
|
|
|
|
@ -148,10 +150,10 @@ func NewTask() {
|
|
|
|
|
Deleted: true, |
|
|
|
|
}) |
|
|
|
|
if err != nil { |
|
|
|
|
return |
|
|
|
|
fmt.Println("获取一天总人数失败:", err.Error()) |
|
|
|
|
continue |
|
|
|
|
} |
|
|
|
|
todayOnlineTotal = lastOnlineCountRsp.Total |
|
|
|
|
|
|
|
|
|
// 初始热度值 + (一个小时内总人数 * 10 + 一个星期内总流水) - 时间段内((十分钟之前总数 - 现在总人数) + (十分钟之前总流水 - 总流水【一个星期内】)) = 热度值
|
|
|
|
|
// 总人数【一天内】+(实时在线人数/总人数)* 10 = 人数热度值
|
|
|
|
|
// 总流水【一个星期内】 * 10 = 流水热度值
|
|
|
|
@ -166,11 +168,12 @@ func NewTask() {
|
|
|
|
|
//usecase.logger.Info("十分钟之前总流水:", lastAmountTotal)
|
|
|
|
|
//usecase.logger.Info("热度值:", v)
|
|
|
|
|
|
|
|
|
|
err = redisClient.HSet(ctx, hotKey, redis.Z{ |
|
|
|
|
err = redisClient.ZAdd(ctx, hotKey, redis.Z{ |
|
|
|
|
Member: roomId, |
|
|
|
|
Score: float64(v), |
|
|
|
|
}).Err() |
|
|
|
|
if err != nil { |
|
|
|
|
fmt.Println("写入热度值失败:", err.Error()) |
|
|
|
|
continue |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -186,5 +189,5 @@ func NewTask() {
|
|
|
|
|
continue |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fmt.Println("结束") |
|
|
|
|
} |
|
|
|
|