Create & Init Project...

This commit is contained in:
2019-04-22 18:49:16 +08:00
commit fc4fa37393
25440 changed files with 4054998 additions and 0 deletions

View File

@@ -0,0 +1,77 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
"go_test",
)
go_library(
name = "go_default_library",
srcs = [
"doc.go",
"index.go",
"relation.go",
],
importpath = "go-common/app/interface/live/app-interface/service/v1",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/interface/live/app-interface/api/http/v1:go_default_library",
"//app/interface/live/app-interface/conf:go_default_library",
"//app/interface/live/app-interface/dao:go_default_library",
"//app/interface/live/app-interface/service/v1/relation:go_default_library",
"//app/service/live/av/api/liverpc/v1:go_default_library",
"//app/service/live/live_user/api/liverpc/v1:go_default_library",
"//app/service/live/relation/api/liverpc/v1:go_default_library",
"//app/service/live/relation/api/liverpc/v2:go_default_library",
"//app/service/live/room/api/liverpc/v1:go_default_library",
"//app/service/live/room/api/liverpc/v2:go_default_library",
"//app/service/live/room_ex/api/liverpc/v1:go_default_library",
"//app/service/live/third_api/bvc:go_default_library",
"//app/service/live/userext/api/liverpc/v1:go_default_library",
"//app/service/main/account/model:go_default_library",
"//app/service/main/account/rpc/client:go_default_library",
"//library/ecode:go_default_library",
"//library/log:go_default_library",
"//library/net/http/blademaster:go_default_library",
"//library/net/metadata:go_default_library",
"//library/net/rpc/liverpc:go_default_library",
"//library/net/rpc/liverpc/context:go_default_library",
"//library/sync/errgroup:go_default_library",
"//library/xstr:go_default_library",
"//vendor/github.com/bitly/go-simplejson:go_default_library",
"//vendor/github.com/pkg/errors:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [
":package-srcs",
"//app/interface/live/app-interface/service/v1/app_conf:all-srcs",
"//app/interface/live/app-interface/service/v1/relation:all-srcs",
],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)
go_test(
name = "go_default_test",
srcs = ["index_test.go"],
embed = [":go_default_library"],
tags = ["automanaged"],
deps = [
"//app/interface/live/app-interface/api/http/v1:go_default_library",
"//app/interface/live/app-interface/conf:go_default_library",
"//library/net/http/blademaster:go_default_library",
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
],
)

View File

@@ -0,0 +1,35 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = ["app_conf.go"],
importpath = "go-common/app/interface/live/app-interface/service/v1/app_conf",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/interface/live/app-interface/api/http/v1:go_default_library",
"//app/interface/live/app-interface/conf:go_default_library",
"//app/service/live/resource/sdk:go_default_library",
"//library/ecode:go_default_library",
"//library/log:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,56 @@
package v1
import (
"context"
v1appconfpb "go-common/app/interface/live/app-interface/api/http/v1"
"go-common/app/interface/live/app-interface/conf"
titansSdk "go-common/app/service/live/resource/sdk"
"go-common/library/ecode"
"go-common/library/log"
)
//AppConfService struct
type AppConfService struct {
conf *conf.Config
}
// NewAppConfService init
func NewAppConfService(c *conf.Config) (s *AppConfService) {
s = &AppConfService{
conf: c,
}
InitTitan()
return s
}
//GetConf 获取移动端配置
func (s *AppConfService) GetConf(ctx context.Context, req *v1appconfpb.GetConfReq) (resp *v1appconfpb.GetConfResp, err error) {
value, ok := s.conf.AppConf[req.GetKey()]
if !ok {
log.Error("[AppConf] GetConf Key err: %s", req.GetKey())
return nil, ecode.AppConfKeyErr
}
resp = &v1appconfpb.GetConfResp{
Value: value,
}
conf, terr := titansSdk.Get(req.GetKey())
if terr != nil {
log.Error("[AppConf] GetConf titansSdk.Get err: %+v", err)
}
if conf != "" {
resp.Value = conf
}
return
}
//InitTitan 初始化kv配置
func InitTitan() {
conf := &titansSdk.Config{
TreeId: 61019,
Expire: 1,
}
titansSdk.Init(conf)
}

View File

@@ -0,0 +1,9 @@
// Copyright 2018 The BILLI Live Engineer. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package v1 为粉版App、直播App端提供卡片聚合接口,展示直播首页、关注二级页信息
// 关注模块文档 http://info.bilibili.co/display/live/APP+5.34
// 首页模块文档 http://info.bilibili.co/pages/viewpage.action?pageId=11546573
//
package v1

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,43 @@
package v1
import (
"context"
"flag"
"testing"
. "github.com/smartystreets/goconvey/convey"
api "go-common/app/interface/live/app-interface/api/http/v1"
"go-common/app/interface/live/app-interface/conf"
bm "go-common/library/net/http/blademaster"
)
var (
s *Service
)
func init() {
flag.Set("conf", "../../cmd/test.toml")
var err error
if err = conf.Init(); err != nil {
panic(err)
}
s = New(conf.Conf)
}
// go test -test.v -test.run TestGetAllList
func TestGetAllList(t *testing.T) {
Convey("TestGetAllList", t, func() {
res, err := s.GetAllList(&bm.Context{Context: context.TODO()}, &api.GetAllListReq{})
t.Logf("%v", res)
So(err, ShouldBeNil)
})
}
func TestChange(t *testing.T) {
Convey("TestChange", t, func() {
res, err := s.Change(&bm.Context{Context: context.TODO()}, &api.ChangeReq{})
t.Logf("%v", res)
So(err, ShouldBeNil)
})
}

View File

@@ -0,0 +1,928 @@
package v1
import (
"context"
"math"
"strconv"
"time"
"go-common/library/sync/errgroup"
"github.com/pkg/errors"
v1pb "go-common/app/interface/live/app-interface/api/http/v1"
"go-common/app/interface/live/app-interface/conf"
"go-common/app/interface/live/app-interface/dao"
relationT "go-common/app/interface/live/app-interface/service/v1/relation"
avV1 "go-common/app/service/live/av/api/liverpc/v1"
relationV1 "go-common/app/service/live/relation/api/liverpc/v1"
roomV1 "go-common/app/service/live/room/api/liverpc/v1"
roomExV1 "go-common/app/service/live/room_ex/api/liverpc/v1"
playurlbvc "go-common/app/service/live/third_api/bvc"
userExV1 "go-common/app/service/live/userext/api/liverpc/v1"
accountM "go-common/app/service/main/account/model"
actmdl "go-common/app/service/main/account/model"
account "go-common/app/service/main/account/rpc/client"
"go-common/library/ecode"
"go-common/library/log"
"go-common/library/net/rpc/liverpc"
liveConText "go-common/library/net/rpc/liverpc/context"
rpcCtx "go-common/library/net/rpc/liverpc/context"
)
// RelationService struct
type RelationService struct {
conf *conf.Config
accountRPC *account.Service3
// optionally add other properties here, such as dao
// dao *dao.Dao
}
// NewRelationService init
func NewRelationService(c *conf.Config) (s *RelationService) {
s = &RelationService{
conf: c,
accountRPC: account.New3(nil),
}
return s
}
const (
// RoomStatusLive ...
RoomStatusLive = 1
// MobileIndexBadgeColorDefault ...
MobileIndexBadgeColorDefault = "#FB9E60"
)
// UnliveAnchor ... implementation
// 直播二级页暂未开播接口
func (s *RelationService) UnliveAnchor(ctx context.Context, req *v1pb.UnLiveAnchorReq) (resp *v1pb.UnLiveAnchorResp, err error) {
resp = &v1pb.UnLiveAnchorResp{}
config := conf.GetDummyUidConf()
if config == relationT.DummyUIDEnable {
dummyHeader := &liverpc.Header{Uid: relationT.RParseInt(req.Buyaofangqizhiliao, relationT.SelfUID)}
ctx = liveConText.WithHeader(ctx, dummyHeader)
}
MakeUnLiveDefaultResult(resp)
uid := relationT.GetUIDFromHeader(ctx)
if uid <= 0 && config == 0 {
return
}
wg, _ := errgroup.WithContext(ctx)
pass, page, pageSize, uid, err := CheckUnLiveAnchorParams(ctx, req)
if !pass {
log.Error("[UnLiveAnchor]CheckParamsError,page:%d,pageSize:%d,uid:%d", page, pageSize, uid)
return
}
relationInfo, groupList, mapUfos2Rolaids, mapRolaids2Ufos, setRolaids, err := GetAttentionListAndGroup(ctx)
if err != nil {
log.Error("[LiveAnchor]get_attentionList_rpc_error")
return
}
// 获取有效(曾经直播过)主播,剪枝roomIDs
lastLiveTime, _ := relationT.GetLastLiveTime(ctx, setRolaids)
alienableRolaids, liberateInfo, sorted := FilterEverLived(lastLiveTime)
alienableUfos := GetUID(mapRolaids2Ufos, alienableRolaids)
roomExReq := &roomExV1.RoomNewsMultiGetReq{RoomIds: alienableRolaids, IsDecoded: 1}
roomParams := &roomV1.RoomGetStatusInfoByUidsReq{Uids: groupList["all"], FilterOffline: 0}
userInfo := make(map[int64]*accountM.Card)
roomResp := make(map[int64]*roomV1.RoomGetStatusInfoByUidsResp_RoomInfo)
roomExResp := make(map[int64]*roomExV1.RoomNewsMultiGetResp_Data)
userfcResp := make(map[int64]*relationV1.FeedGetUserFcBatchResp_RelationList)
// room
wg.Go(func() error {
roomResp, err = relationT.GetRoomInfo(ctx, roomParams)
return err
})
// user信息
wg.Go(func() error {
userInfo, err = s.GetUserInfoData(ctx, alienableUfos)
return err
})
// roomEx
wg.Go(func() error {
roomExResp, err = relationT.GetRoomNewsInfo(ctx, roomExReq)
return err
})
// fansNum
wg.Go(func() error {
userfcResp, err = GetUserFc(ctx, alienableUfos)
return err
})
waitErr := wg.Wait()
if waitErr != nil {
log.Error("[UnLiveAnchor][step2] rpc error: %s", waitErr)
return
}
mapSp := make(map[int64]bool)
normalSp := make(map[int64]bool)
for _, v := range groupList["special"] {
mapSp[v] = true
}
for _, v := range groupList["normal"] {
normalSp[v] = true
}
specialRoomed, normalRoomed := s.GroupByRule(ctx, mapSp, normalSp, liberateInfo, sorted, mapRolaids2Ufos)
specialUID := GetUID(mapRolaids2Ufos, specialRoomed)
normalUID := GetUID(mapRolaids2Ufos, normalRoomed)
liveDesc, newsDesc := CalcTimeLine(liberateInfo, roomExResp)
LiveCount := CountLiveRooms(roomResp)
resp.Rooms = AdaptField(roomResp, userfcResp, userInfo, roomExResp, relationInfo, specialUID, normalUID, mapUfos2Rolaids, liveDesc, newsDesc)
resp.TotalCount = int64(len(resp.Rooms))
resp.NoRoomCount = int64(len(setRolaids) - int(resp.TotalCount) - int(LiveCount))
resp.Rooms = UnLiveAnchorSlice(resp.Rooms, page, pageSize)
if (page * pageSize) >= resp.TotalCount {
resp.HasMore = 0
} else {
resp.HasMore = 1
}
return
}
// CountLiveRooms 计算正在直播数目
func CountLiveRooms(input map[int64]*roomV1.RoomGetStatusInfoByUidsResp_RoomInfo) (count int) {
if len(input) <= 0 {
count = 0
return
}
for _, v := range input {
if v.LiveStatus == RoomStatusLive {
count++
}
}
return
}
// CheckUnLiveAnchorParams implementation
// 入参校验
func CheckUnLiveAnchorParams(ctx context.Context, req *v1pb.UnLiveAnchorReq) (pass bool, page int64, pageSize int64, uid int64, err error) {
if req == nil {
pass = false
return
}
config := conf.GetDummyUidConf()
uid = relationT.GetUIDFromHeader(ctx)
if uid == 0 && config == 0 {
err = errors.WithMessage(ecode.NeedLogIn, "GET SEA PATROL FAIL")
pass = false
return
}
page = req.Page
pageSize = req.Pagesize
if page <= 0 || pageSize <= 0 {
pass = false
log.Error("CallRelationUnLiveAnchorParamsCheckError|page:%d,pageSize:%d", page, pageSize)
err = errors.WithMessage(ecode.UnliveAnchorReqParamsError, "GET SEA PATROL FAIL")
return
}
pass = true
return
}
// CheckLiveAnchorParams implementation
// 入参校验
func CheckLiveAnchorParams(ctx context.Context, req *v1pb.LiveAnchorReq) (sortRule int64, filterRule int64, uid int64, err error) {
if req == nil {
err = ecode.LiveAnchorReqParamsNil
return
}
sortRule = req.SortRule
filterRule = req.FilterRule
uid = relationT.GetUIDFromHeader(ctx)
config := conf.GetDummyUidConf()
if uid == 0 && config == 0 {
err = errors.WithMessage(ecode.NeedLogIn, "GET SEA PATROL FAIL")
return
}
if sortRule < 0 || filterRule < 0 {
log.Error("CallRelationLiveAnchorParamsCheckError|page:%d,pageSize:%d", sortRule, filterRule)
err = errors.WithMessage(ecode.LiveAnchorReqParamsError, "GET SEA PATROL FAIL")
return
}
return
}
// UnLiveAnchorSlice implementation
// 分页逻辑
func UnLiveAnchorSlice(req []*v1pb.UnLiveAnchorResp_Rooms, page int64, pageSize int64) (resp []*v1pb.UnLiveAnchorResp_Rooms) {
resp = make([]*v1pb.UnLiveAnchorResp_Rooms, 0)
start := (page - 1) * pageSize
end := start + pageSize
length := int64(len(req))
if start >= length {
return
}
if end >= length {
resp = req[start:]
} else {
resp = req[start:end]
}
return
}
// MakeUnLiveDefaultResult implementation
// 缺省返回
func MakeUnLiveDefaultResult(resp *v1pb.UnLiveAnchorResp) {
if resp != nil {
resp.HasMore = 0
resp.NoRoomCount = 0
resp.TotalCount = 0
resp.Rooms = make([]*v1pb.UnLiveAnchorResp_Rooms, 0)
}
}
// GroupByRule implementation
// 按照规则排序,组间按照特别关注优先,组内按照上次关播时间倒序
func (s *RelationService) GroupByRule(ctx context.Context, special map[int64]bool, normal map[int64]bool,
liberate map[int64]int64, sorted relationT.PairList, mapRolaids2Ufos map[int64]int64) (specialRoomed []int64, normalRoomed []int64) {
specialRoomed = make([]int64, 0)
normalRoomed = make([]int64, 0)
if len(liberate) == 0 || liberate == nil {
return
}
for _, v := range sorted {
if _, ok := special[mapRolaids2Ufos[v.Key]]; ok {
specialRoomed = append(specialRoomed, v.Key)
} else {
normalRoomed = append(normalRoomed, v.Key)
}
}
return
}
// AdaptField implementation
// 填充逻辑
func AdaptField(roomInfo map[int64]*roomV1.RoomGetStatusInfoByUidsResp_RoomInfo,
fansInfo map[int64]*relationV1.FeedGetUserFcBatchResp_RelationList,
userResult map[int64]*accountM.Card,
roomedInfo map[int64]*roomExV1.RoomNewsMultiGetResp_Data,
relationInfo map[int64]*relationV1.BaseInfoGetFollowTypeResp_UidInfo,
specialUID []int64, normalUID []int64,
mapUfos2Rolaids map[int64]int64, liveDesc map[int64]string, newsDesc map[int64]string) (resp []*v1pb.UnLiveAnchorResp_Rooms) {
var item []*v1pb.UnLiveAnchorResp_Rooms
resp = make([]*v1pb.UnLiveAnchorResp_Rooms, 0)
if len(specialUID) > 0 {
item = FireField(roomInfo, fansInfo, userResult, roomedInfo, relationInfo, specialUID, mapUfos2Rolaids, liveDesc, newsDesc)
resp = append(resp, item...)
}
if len(normalUID) > 0 {
item = FireField(roomInfo, fansInfo, userResult, roomedInfo, relationInfo, normalUID, mapUfos2Rolaids, liveDesc, newsDesc)
resp = append(resp, item...)
}
return
}
// CalcTimeLine ...
// 计算时间规则
func CalcTimeLine(liberateInfo map[int64]int64,
roomNewsInfo map[int64]*roomExV1.RoomNewsMultiGetResp_Data) (liveDesc map[int64]string, newsDesc map[int64]string) {
liveDesc, newsDesc = TimeLineRule(liberateInfo, roomNewsInfo)
return
}
// TimeLineRule ...
// 计算时间规则
func TimeLineRule(liberateInfo map[int64]int64, roomNewsInfo map[int64]*roomExV1.RoomNewsMultiGetResp_Data) (liveDesc map[int64]string, newsDesc map[int64]string) {
liveDesc = make(map[int64]string)
newsDesc = make(map[int64]string)
if len(liberateInfo) <= 0 {
return
}
for livedRoomed, lastLiveTime := range liberateInfo {
now := time.Now()
currentYear, currentMonth, currentDay := now.Date()
currentLocation := now.Location()
firstOfMonth := time.Date(currentYear, 1, 1, 0, 0, 0, 0, currentLocation)
thisYearUnixTimeStamp := firstOfMonth.Unix()
todayUnixTimeStamp := time.Date(currentYear, currentMonth, currentDay, 0, 0, 0, 0, currentLocation).Unix()
today24 := math.Abs(float64(todayUnixTimeStamp - lastLiveTime))
liveTime := math.Abs(float64(now.Unix() - lastLiveTime))
if lastLiveTime == 0 {
liveDesc[livedRoomed] = "上次"
}
if liveTime < 60 {
liveDesc[livedRoomed] = "刚刚"
} else if liveTime >= 60 && liveTime < 3600 {
text := int(math.Floor(liveTime / 60))
liveDesc[livedRoomed] = strconv.Itoa(text) + "分钟前"
} else if liveTime >= 3600 && liveTime < 86400 {
text := int(math.Floor(liveTime / 3600))
liveDesc[livedRoomed] = strconv.Itoa(text) + "小时前"
} else if liveTime >= 86400 && today24 <= 86400 {
liveDesc[livedRoomed] = "昨天"
} else if liveTime >= 86400 && lastLiveTime >= thisYearUnixTimeStamp {
tm := time.Unix(lastLiveTime, 0)
text := tm.Format("1-2")
liveDesc[livedRoomed] = text
} else {
if lastLiveTime < thisYearUnixTimeStamp && liveTime >= 86400 {
tm := time.Unix(lastLiveTime, 0)
text := tm.Format("2006-1-2")
liveDesc[livedRoomed] = text
} else {
tm := time.Unix(lastLiveTime, 0)
text := tm.Format("2006-1-2")
liveDesc[livedRoomed] = text
}
}
}
if len(roomNewsInfo) <= 0 {
return
}
for livedRoomed, lastNewsTime := range roomNewsInfo {
lastLiveTimeStr := lastNewsTime.Ctime
now := time.Now()
timeFmt, _ := time.ParseInLocation("2006-01-02 15:04:05", lastLiveTimeStr, time.Local)
lastLiveTime := timeFmt.Unix()
currentYear, currentMonth, currentDay := now.Date()
currentLocation := now.Location()
todayUnixTimeStamp := time.Date(currentYear, currentMonth, currentDay, 0, 0, 0, 0, currentLocation).Unix()
today24 := math.Abs(float64(todayUnixTimeStamp - lastLiveTime))
liveTime := math.Abs(float64(now.Unix() - lastLiveTime))
if lastLiveTime == 0 {
newsDesc[livedRoomed] = ""
}
if liveTime < 60 {
newsDesc[livedRoomed] = "刚刚"
} else if liveTime >= 60 && liveTime < 3600 {
text := int(math.Floor(liveTime / 60))
newsDesc[livedRoomed] = strconv.Itoa(text) + "分钟前"
} else if liveTime >= 3600 && liveTime < 86400 {
text := int(math.Floor(liveTime / 3600))
newsDesc[livedRoomed] = strconv.Itoa(text) + "小时前"
} else if liveTime >= 86400 && today24 <= 86400 {
newsDesc[livedRoomed] = "昨天"
}
}
return
}
// FireField ...
// 适配返回值
func FireField(roomInfo map[int64]*roomV1.RoomGetStatusInfoByUidsResp_RoomInfo,
fansInfo map[int64]*relationV1.FeedGetUserFcBatchResp_RelationList,
userResult map[int64]*accountM.Card,
roomedInfo map[int64]*roomExV1.RoomNewsMultiGetResp_Data,
relationInfo map[int64]*relationV1.BaseInfoGetFollowTypeResp_UidInfo,
ufos []int64,
mapUfos2Rolaids map[int64]int64, liveDesc map[int64]string, newsDesc map[int64]string) (resp []*v1pb.UnLiveAnchorResp_Rooms) {
for _, v := range ufos {
item := v1pb.UnLiveAnchorResp_Rooms{}
roomID, roomIDExist := mapUfos2Rolaids[v]
if !roomIDExist {
continue
}
roomItem := roomInfo[v]
userItem := userResult[v]
fansItem := fansInfo[v]
relationItem := relationInfo[v]
roomedItem := roomedInfo[roomID]
roomNewsDesc := newsDesc[roomID]
liveDescItem := liveDesc[roomID]
roomNewsContent := ""
roomNewsDescText := ""
if roomItem == nil || userItem == nil || relationItem == nil {
continue
}
if roomItem.LiveStatus == RoomStatusLive {
continue
}
if roomedItem != nil {
roomNewsContent = roomedItem.NewsContent
roomNewsDescText = roomNewsDesc
}
item.Roomid = roomItem.RoomId
item.Uid = roomItem.Uid
item.Uname = userItem.Name
item.Face = userItem.Face
item.LiveStatus = roomItem.LiveStatus
item.Area = roomItem.Area
item.AreaName = roomItem.AreaName
item.AreaV2Id = roomItem.AreaV2Id
item.AreaV2Name = roomItem.AreaV2Name
item.AreaV2ParentId = roomItem.AreaV2ParentId
item.AreaV2ParentName = roomItem.AreaV2ParentName
item.BroadcastType = roomItem.BroadcastType
item.Link = relationT.LiveDomain + strconv.Itoa(int(roomID)) + relationT.BoastURL + strconv.Itoa(int(item.BroadcastType))
item.OfficialVerify = int64(relationT.RoleMap(userItem.Official.Role))
item.Attentions = fansItem.Fc
item.SpecialAttention = relationItem.Special
item.AnnouncementContent = roomNewsContent
item.AnnouncementTime = roomNewsDescText
item.LiveDesc = liveDescItem
resp = append(resp, &item)
}
return
}
// LiveFireField ...
// 适配返回值
func LiveFireField(roomInfo map[int64]*roomV1.RoomGetStatusInfoByUidsResp_RoomInfo,
roomPendentInfo map[int64]*roomV1.RoomPendantGetPendantByIdsResp_Result,
userResult map[int64]*accountM.Card,
pkIDInfo map[string]int64, playURLInfo map[int64]*playurlbvc.PlayUrlItem,
relationInfo map[int64]*relationV1.BaseInfoGetFollowTypeResp_UidInfo,
ufos []int64, mapUfos2Rolaids map[int64]int64) (resp []*v1pb.LiveAnchorResp_Rooms) {
for _, v := range ufos {
item := v1pb.LiveAnchorResp_Rooms{}
roomID, roomIDExist := mapUfos2Rolaids[v]
if !roomIDExist {
continue
}
roomItem := roomInfo[v]
roomPendentItem := roomPendentInfo[roomID]
userItem := userResult[v]
relationItem := relationInfo[v]
pkItem := pkIDInfo[strconv.Itoa(int(roomID))]
playURLItem := playURLInfo[roomID]
if roomItem == nil || userItem == nil || relationItem == nil {
continue
}
PlayURL := ""
PlayURL265 := ""
PlayURLAcc := make([]int64, 0)
PlayURLCur := 0
PendentRu := ""
PendentRuColor := ""
PendentRuPic := ""
if playURLItem != nil {
PlayURL = playURLItem.Url["h264"]
PlayURL265 = playURLItem.Url["h265"]
PlayURLAcc = playURLItem.AcceptQuality
PlayURLCur = int(playURLItem.CurrentQuality)
}
if roomPendentItem != nil {
PendentRu = roomPendentItem.Value
PendentRuColor = roomPendentItem.BgColor
PendentRuPic = roomPendentItem.BgPic
}
if PendentRuColor == "" {
PendentRuColor = MobileIndexBadgeColorDefault
}
item.Roomid = roomItem.RoomId
item.Uid = roomItem.Uid
item.Uname = userItem.Name
item.Face = userItem.Face
item.Title = roomItem.Title
item.LiveTagName = roomItem.AreaV2Name
item.LiveTime = roomItem.LiveTime
item.Online = roomItem.Online
item.Playurl = PlayURL
item.AcceptQuality = PlayURLAcc
item.CurrentQuality = int64(PlayURLCur)
item.PkId = pkItem
item.Area = roomItem.Area
item.AreaName = roomItem.AreaName
item.AreaV2Id = roomItem.AreaV2Id
item.PlayUrlH265 = PlayURL265
item.AreaV2Name = roomItem.AreaV2Name
item.AreaV2ParentId = roomItem.AreaV2ParentId
item.AreaV2ParentName = roomItem.AreaV2ParentName
item.BroadcastType = roomItem.BroadcastType
item.Link = relationT.LiveDomain + strconv.Itoa(int(roomID)) + relationT.BoastURL + strconv.Itoa(int(item.BroadcastType))
item.OfficialVerify = int64(relationT.RoleMap(userItem.Official.Role))
item.SpecialAttention = relationItem.Special
item.PendentRu = PendentRu
item.PendentRuColor = PendentRuColor
item.PendentRuPic = PendentRuPic
if len(roomItem.CoverFromUser) == 0 {
item.Cover = roomItem.Keyframe
} else {
item.Cover = roomItem.CoverFromUser
}
resp = append(resp, &item)
}
return
}
// GroupUfos ...
// 按照关注类型分组
func GroupUfos(input map[int64]*relationV1.BaseInfoGetFollowTypeResp_UidInfo) (resp map[string][]int64, err error) {
if input == nil {
return nil, nil
}
resp = make(map[string][]int64)
for k, v := range input {
if v.Special == 0 {
resp["normal"] = append(resp["normal"], k)
} else {
resp["special"] = append(resp["special"], k)
}
resp["all"] = append(resp["all"], k)
}
return resp, nil
}
// GetUID ...
// 获取uid
func GetUID(idsMap map[int64]int64, input []int64) (resp []int64) {
if idsMap == nil || input == nil {
return nil
}
for _, v := range input {
resp = append(resp, idsMap[int64(v)])
}
return resp
}
// FilterEverLived ...
// 过滤未开播
func FilterEverLived(lastLiveTime map[string]string) (rolaids []int64, lifetime map[int64]int64, sorted relationT.PairList) {
rolaids = make([]int64, 0)
lifetime = make(map[int64]int64)
for roomed, v := range lastLiveTime {
timeFmt, _ := time.ParseInLocation("2006-01-02 15:04:05", v, time.Local)
if !timeFmt.IsZero() {
if mid, err := strconv.ParseInt(roomed, 10, 64); err == nil {
lifetime[mid] = timeFmt.Unix()
rolaids = append(rolaids, mid)
}
}
}
sorted = make([]relationT.Pair, 0)
sorted = relationT.SortMap(lifetime)
return rolaids, lifetime, sorted
}
// GetLastAnchorLiveTime ...
// 获取上一个主播信息
func GetLastAnchorLiveTime(lastLiveTime map[string]string) (rolaids []int64, lifetime map[int64]int64, sorted relationT.PairList) {
rolaids = make([]int64, 0)
lifetime = make(map[int64]int64)
for roomed, v := range lastLiveTime {
timeFmt, _ := time.ParseInLocation("2006-01-02 15:04:05", v, time.Local)
if mid, err := strconv.ParseInt(roomed, 10, 64); err == nil {
lifetime[mid] = timeFmt.Unix()
rolaids = append(rolaids, mid)
}
}
sorted = make([]relationT.Pair, 0)
sorted = relationT.SortMap(lifetime)
return rolaids, lifetime, sorted
}
// MakeLiveAnchorDefaultResult ...
// 正在直播默认返回
func MakeLiveAnchorDefaultResult(resp *v1pb.LiveAnchorResp) {
if resp != nil {
resp.TotalCount = 0
// [历史原因]cardType只能为1,否则客户端报错,见 https://www.tapd.cn/20082211/prong/stories/view/1120082211001086997
resp.CardType = relationT.App533CardType
resp.BigCardType = 0
resp.Rooms = make([]*v1pb.LiveAnchorResp_Rooms, 0)
}
}
// GetAttentionListAndGroup ...
// 关注分组
func GetAttentionListAndGroup(ctx context.Context) (relationInfo map[int64]*relationV1.BaseInfoGetFollowTypeResp_UidInfo, groupList map[string][]int64,
mapUfos2Rolaids map[int64]int64, mapRolaids2Ufos map[int64]int64, setRolaids []int64, attentionErr error) {
relationTimeout := conf.GetTimeout("relation", 200)
attentionErr = nil
attentionData, attentionErr := dao.RelationApi.V1BaseInfo.GetFollowType(
rpcCtx.WithTimeout(ctx, time.Duration(relationTimeout)*time.Millisecond),
&relationV1.BaseInfoGetFollowTypeReq{})
if attentionErr != nil || attentionData == nil {
attentionErr = ecode.AttentionListRPCError
return
}
relationInfo = attentionData.Data
groupList, _ = GroupUfos(attentionData.Data)
// 转换ids
mapUfos2Rolaids, err := relationT.UIDs2roomIDs(ctx, groupList["all"])
if err != nil {
attentionErr = ecode.RoomGetRoomIDCodeRPCError
return
}
mapRolaids2Ufos, setRolaids = TransRoomedUUID(mapUfos2Rolaids)
return
}
// TransRoomedUUID ...
// 转换ids
func TransRoomedUUID(mapUfos2Rolaids map[int64]int64) (mapRolaids2Ufos map[int64]int64, setRolaids []int64) {
mapRolaids2Ufos = make(map[int64]int64)
for k, v := range mapUfos2Rolaids {
mapRolaids2Ufos[v] = k
}
setRolaids = make([]int64, 0)
for _, v := range mapUfos2Rolaids {
setRolaids = append(setRolaids, v)
}
return
}
// AdaptLivingField ...
// 填充逻辑
func AdaptLivingField(roomInfo map[int64]*roomV1.RoomGetStatusInfoByUidsResp_RoomInfo,
roomPendentInfo map[int64]*roomV1.RoomPendantGetPendantByIdsResp_Result,
userResult map[int64]*accountM.Card,
relationInfo map[int64]*relationV1.BaseInfoGetFollowTypeResp_UidInfo,
pkIDInfo map[string]int64, playURLInfo map[int64]*playurlbvc.PlayUrlItem, specialUID []int64, normalUID []int64,
mapUfos2Rolaids map[int64]int64) (resp []*v1pb.LiveAnchorResp_Rooms) {
var item []*v1pb.LiveAnchorResp_Rooms
resp = make([]*v1pb.LiveAnchorResp_Rooms, 0)
normalResp := make([]*v1pb.LiveAnchorResp_Rooms, 0)
if len(specialUID) > 0 {
item = LiveFireField(roomInfo, roomPendentInfo, userResult, pkIDInfo, playURLInfo, relationInfo, specialUID, mapUfos2Rolaids)
tempResp := &v1pb.LiveAnchorResp{}
tempResp.Rooms = item
resp = relationT.AppSortRuleOnline(tempResp)
}
if len(normalUID) > 0 {
item = LiveFireField(roomInfo, roomPendentInfo, userResult, pkIDInfo, playURLInfo, relationInfo, normalUID, mapUfos2Rolaids)
tempResp := &v1pb.LiveAnchorResp{}
tempResp.Rooms = item
normalResp = relationT.AppSortRuleOnline(tempResp)
}
if len(normalResp) > 0 {
resp = append(resp, normalResp...)
}
return
}
// LiveAnchor implementation
// [app端关注二级页][全量]正在直播接口
func (s *RelationService) LiveAnchor(ctx context.Context, req *v1pb.LiveAnchorReq) (resp *v1pb.LiveAnchorResp, err error) {
resp = &v1pb.LiveAnchorResp{}
MakeLiveAnchorDefaultResult(resp)
sortRule, filterRule, uid, err := CheckLiveAnchorParams(ctx, req)
wg, _ := errgroup.WithContext(ctx)
if err != nil {
log.Error("[LiveAnchor]CheckParamsError,page:%d,pageSize:%d,uid:%d", sortRule, filterRule, uid)
return
}
relationInfo, groupList, mapUfos2Rolaids, _, _, err := GetAttentionListAndGroup(ctx)
if err != nil {
log.Error("[LiveAnchor]get_attentionList_rpc_error")
return
}
// 获取有效(正在直播中)主播,剪枝roomIDs
roomParams := &roomV1.RoomGetStatusInfoByUidsReq{Uids: groupList["all"], FilterOffline: 1, NeedBroadcastType: 1}
// room
roomResp, err := relationT.GetRoomInfo(ctx, roomParams)
if err != nil {
log.Error("[LiveAnchor]get_room_rpc_error")
return
}
livingUfos := make([]int64, 0)
livingRolaids := make([]int64, 0)
// 没有人直播
if len(roomResp) == 0 {
return
}
for k, v := range roomResp {
livingUfos = append(livingUfos, k)
livingRolaids = append(livingRolaids, v.RoomId)
}
userResp := make(map[int64]*accountM.Card)
roomCornerResp := make(map[int64]*roomV1.RoomPendantGetPendantByIdsResp_Result)
pkResp := make(map[string]int64)
attentionRoomListPlayURLMap := make(map[int64]*playurlbvc.PlayUrlItem)
build, _ := strconv.ParseInt(req.Build, 10, 64)
roomPendentParams := &roomV1.RoomPendantGetPendantByIdsReq{Ids: livingRolaids, Type: relationT.PendentMobileBadge, Position: relationT.PendentPosition}
pkParams := &avV1.PkGetPkIdsByRoomIdsReq{RoomIds: livingRolaids, Platform: req.Platform}
if err != nil {
log.Error("[LiveAnchor]get_roomPendant_rpc_error")
return
}
// user信息
wg.Go(func() error {
userResp, err = s.GetUserInfoData(ctx, livingUfos)
return err
})
// room
wg.Go(func() error {
roomCornerResp, err = relationT.GetRoomPendantInfo(ctx, roomPendentParams)
return err
})
// pk_id
wg.Go(func() error {
pkResp, err = relationT.GetPkID(ctx, pkParams)
return err
})
quality := req.Quality
if quality <= 0 {
quality = 4
}
// playurl
wg.Go(func() error {
attentionRoomListPlayURLMap = dao.BvcApi.GetPlayUrlMulti(ctx, livingRolaids, 0, quality, build, req.Platform)
return err
})
waitErr := wg.Wait()
if waitErr != nil {
log.Error("[LiveAnchor][step2] rpc error: %s", waitErr)
return
}
// 下游数据收集完成
mapSp := make([]int64, 0)
normalSp := make([]int64, 0)
mapSp = append(mapSp, groupList["special"]...)
normalSp = append(normalSp, groupList["normal"]...)
resp.Rooms = AdaptLivingField(roomResp, roomCornerResp, userResp, relationInfo, pkResp, attentionRoomListPlayURLMap, mapSp, normalSp, mapUfos2Rolaids)
resp.TotalCount = int64(len(resp.Rooms))
userExtParams := &userExV1.GrayRuleGetByMarkReq{Mark: relationT.App531GrayRule}
grayRule, err := relationT.GetGrayRule(ctx, userExtParams)
if err != nil {
log.Error("[LiveAnchor]get_GrayRule_rpc_error")
resp.BigCardType = 0
} else if grayRule != nil {
resp.BigCardType = relationT.App531ABTest(ctx, grayRule.Content, req.Build, req.Platform)
}
FilterType(ctx, livingUfos, resp, filterRule)
SortType(ctx, resp, sortRule)
return
}
// FilterType implementation
// [app端关注二级页]按照规则过滤结果集
func FilterType(ctx context.Context, targetUIDs []int64, originResult *v1pb.LiveAnchorResp, filterType int64) {
if originResult == nil || len(originResult.Rooms) == 0 {
return
}
switch filterType {
case relationT.AppFilterDefault:
{
}
case relationT.AppFilterFansMedal:
{
filteredRooms, _ := relationT.AppFilterRuleFansMedal(ctx, originResult, targetUIDs)
originResult.Rooms = filteredRooms
originResult.TotalCount = int64(len(originResult.Rooms))
}
case relationT.AppFilterGoldType:
{
filteredRooms, _ := relationT.AppFilterGold(ctx, originResult)
originResult.Rooms = filteredRooms
originResult.TotalCount = int64(len(originResult.Rooms))
}
}
}
// SortType implementation
// [app端关注二级页]按照规则排序结果集
// 规则见https://www.tapd.cn/20082211/prong/stories/view/1120082211001067961
func SortType(ctx context.Context, originResult *v1pb.LiveAnchorResp, sortType int64) (resp *v1pb.LiveAnchorResp, err error) {
if originResult == nil || len(originResult.Rooms) == 0 {
return
}
switch sortType {
// 组间特别关注、组内人气值
case relationT.AppSortDefaultT:
{
}
case relationT.AppSortRuleLiveTimeT:
{
originResult.Rooms = relationT.AppSortRuleLiveTime(originResult)
}
case relationT.AppSortRuleOnlineT:
{
originResult.Rooms = relationT.AppSortRuleOnline(originResult)
}
case relationT.AppSortRuleGoldT:
{
originResult.Rooms = relationT.AppSortRuleGold(ctx, originResult)
}
default:
}
return
}
// GetUserInfoData ...
// 调用account grpc接口cards获取用户信息
func (s *RelationService) GetUserInfoData(ctx context.Context, UIDs []int64) (userResult map[int64]*accountM.Card, err error) {
rpcChunkSize, RPCTimeout, err := relationT.GetChunkInfo(relationT.AccountGRPC)
params := relationT.ChunkCallInfo{ParamsName: "ufos", URLName: relationT.AccountGRPC, ChunkSize: rpcChunkSize, RPCTimeout: RPCTimeout}
userResult = make(map[int64]*accountM.Card)
lens := len(UIDs)
if lens <= 0 {
return
}
// 批次
params.ChunkNum = int64(math.Ceil(float64(lens) / float64(params.ChunkSize)))
chunkResult := make([]map[int64]*accountM.Card, params.ChunkNum)
wg, _ := errgroup.WithContext(ctx)
for i := int64(1); i <= params.ChunkNum; i++ {
x := i
wg.Go(func() error {
chunkUfosIds := make([]int64, 20)
if x == params.ChunkNum {
chunkUfosIds = UIDs[(x-1)*params.ChunkSize:]
} else {
chunkUfosIds = UIDs[(x-1)*params.ChunkSize : x*params.ChunkSize]
}
ret, err := s.accountRPC.Cards3(ctx, &actmdl.ArgMids{Mids: chunkUfosIds})
if err != nil {
err = errors.WithMessage(ecode.AccountGRPCError, "GET SEA PATROL FAIL")
log.Error("Call main.Account.Cards Error.Infos(%+v) error(%+v)", chunkUfosIds, err)
}
chunkResult[x-1] = ret
return nil
})
}
if err := wg.Wait(); err != nil {
erelongInfo := relationT.ErrLogStrut{}
erelongInfo.ErrType = "GoRoutingWaitError"
erelongInfo.URLName = relationT.AccountGRPC
erelongInfo.ErrDesc = relationT.GoRoutingErr
erelongInfo.Code = 1003001
erelongInfo.RPCTimeout = params.RPCTimeout
erelongInfo.ErrorPtr = &err
log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|error:%+v"+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s",
*erelongInfo.ErrorPtr, erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName)
err = errors.WithMessage(ecode.AccountGRPCFrameError, "GET SEA PATROL FAIL")
return nil, err
}
// 整理数据
for _, chunkItemList := range chunkResult {
for _, item := range chunkItemList {
if item != nil {
userResult[item.Mid] = item
}
}
}
return
}
// GetUserFc ...
// 获取用户粉丝
func GetUserFc(ctx context.Context, UIDs []int64) (userResult map[int64]*relationV1.FeedGetUserFcBatchResp_RelationList, err error) {
rpcChunkSize, RPCTimeout, err := relationT.GetChunkInfo(relationT.FansNum)
params := relationT.ChunkCallInfo{ParamsName: "ufos", URLName: relationT.FansNum, ChunkSize: rpcChunkSize, RPCTimeout: RPCTimeout}
userResult = make(map[int64]*relationV1.FeedGetUserFcBatchResp_RelationList)
lens := len(UIDs)
if lens <= 0 {
return
}
// 批次
params.ChunkNum = int64(math.Ceil(float64(lens) / float64(params.ChunkSize)))
chunkResult := make([]map[int64]*relationV1.FeedGetUserFcBatchResp_RelationList, params.ChunkNum)
wg, _ := errgroup.WithContext(ctx)
for i := int64(1); i <= params.ChunkNum; i++ {
x := i
wg.Go(func() error {
chunkUfosIds := make([]int64, 20)
if x == params.ChunkNum {
chunkUfosIds = UIDs[(x-1)*params.ChunkSize:]
} else {
chunkUfosIds = UIDs[(x-1)*params.ChunkSize : x*params.ChunkSize]
}
ret, err := dao.RelationApi.V1Feed.GetUserFcBatch(ctx, &relationV1.FeedGetUserFcBatchReq{Uids: chunkUfosIds})
if err != nil {
err = errors.WithMessage(ecode.AccountGRPCError, "GET SEA PATROL FAIL")
log.Error("Call main.Account.Cards Error.Infos(%+v) error(%+v)", chunkUfosIds, err)
}
chunkResult[x-1] = ret.Data
return nil
})
}
if err := wg.Wait(); err != nil {
erelongInfo := relationT.ErrLogStrut{}
erelongInfo.ErrType = "GoRoutingWaitError"
erelongInfo.URLName = relationT.FansNum
erelongInfo.ErrDesc = relationT.GoRoutingErr
erelongInfo.Code = 1003001
erelongInfo.RPCTimeout = params.RPCTimeout
erelongInfo.ErrorPtr = &err
log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|error:%+v"+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s",
*erelongInfo.ErrorPtr, erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName)
err = errors.WithMessage(ecode.AccountGRPCFrameError, "GET SEA PATROL FAIL")
return nil, err
}
// 整理数据
for _, chunkItemList := range chunkResult {
for _, item := range chunkItemList {
if item != nil {
userResult[item.Uid] = item
}
}
}
return
}

View File

@@ -0,0 +1,64 @@
package relation
import (
"context"
v1pb "go-common/app/interface/live/app-interface/api/http/v1"
fansMedalV1 "go-common/app/service/live/fans_medal/api/liverpc/v1"
"go-common/library/log"
)
const (
// AppFilterDefault implementation
// 默认排序
AppFilterDefault = 0
// AppFilterFansMedal implementation
// 只看我有粉丝勋章的
AppFilterFansMedal = 1
// AppFilterGoldType implementation
// 按照金瓜子排序
AppFilterGoldType = 2
)
// AppFilterRuleFansMedal implementation
// [app端关注二级页]过滤粉丝勋章
func AppFilterRuleFansMedal(ctx context.Context, originResult *v1pb.LiveAnchorResp, targetUIDs []int64) (resp []*v1pb.LiveAnchorResp_Rooms, err error) {
uid := GetUIDFromHeader(ctx)
resp = make([]*v1pb.LiveAnchorResp_Rooms, 0)
if originResult == nil || len(originResult.Rooms) == 0 {
return
}
fansParams := &fansMedalV1.FansMedalTargetsWithMedalReq{Uid: uid, TargetIds: targetUIDs}
hasMedalUIDs, err := GetFansMedal(ctx, fansParams)
if err != nil {
log.Error("[LiveAnchor][FilterType]get_FansMedal_rpc_error")
resp = originResult.Rooms
return
}
for _, v := range originResult.Rooms {
if _, exist := hasMedalUIDs[v.Uid]; exist {
resp = append(resp, v)
}
}
return
}
// AppFilterGold implementation
// [app端关注二级页]过滤送礼
func AppFilterGold(ctx context.Context, originResult *v1pb.LiveAnchorResp) (resp []*v1pb.LiveAnchorResp_Rooms, err error) {
giftInfo, err := GetGiftInfo(ctx)
resp = make([]*v1pb.LiveAnchorResp_Rooms, 0)
if originResult == nil || len(originResult.Rooms) == 0 {
return
}
if err != nil {
log.Error("[LiveAnchor][FilterType]get_RelationGift_rpc_error")
resp = originResult.Rooms
return
}
for _, v := range originResult.Rooms {
if _, exist := giftInfo[v.Uid]; exist {
resp = append(resp, v)
}
}
return
}

View File

@@ -0,0 +1,233 @@
package relation
import (
"context"
v1pb "go-common/app/interface/live/app-interface/api/http/v1"
"go-common/library/log"
"sort"
)
const (
// AppSortDefaultT ...
// 默认排序
AppSortDefaultT = 0
// AppSortRuleLiveTimeT ...
// 开播时间倒序
AppSortRuleLiveTimeT = 1
// AppSortRuleOnlineT ...
// 人气值倒序
AppSortRuleOnlineT = 2
// AppSortRuleGoldT ...
// 金瓜子倒序
AppSortRuleGoldT = 3
)
// SendGift ...
// [app端关注二级页]按照金瓜子排序结构
type SendGift struct {
Mid int64
gold int64
}
// SortLiveTime ... implementation
// [app端关注二级页]按照开播时间排序
type SortLiveTime []*v1pb.LiveAnchorResp_Rooms
// SortOnlineTime ... implementation
// [app端关注二级页]按照开播时间排序
type SortOnlineTime []*v1pb.LiveAnchorResp_Rooms
// // AddGoldRoomInfo ... implementation
// // [app端关注二级页]按照开播时间排序
// type AddGoldRoomInfo []*LiveAnchorRespRoomsAddGold
// SortUIDGift ... implementation
// [app端关注二级页]按照开播时间排序
type SortUIDGift []SendGift
// AppSortRuleLiveTime implementation
// [app端关注二级页]按照开播时间排序
func (p SortLiveTime) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
// AppSortRuleLiveTime implementation
// [app端关注二级页]按照开播时间排序
func (p SortLiveTime) Len() int { return len(p) }
// AppSortRuleLiveTime implementation
// [app端关注二级页]按照开播时间排序
func (p SortLiveTime) Less(i, j int) bool { return p[i].LiveTime > p[j].LiveTime }
// AppSortRuleLiveTime implementation
// [app端关注二级页]按照开播时间排序
func (p SortOnlineTime) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
// AppSortRuleLiveTime implementation
// [app端关注二级页]按照开播时间排序
func (p SortOnlineTime) Len() int { return len(p) }
// AppSortRuleLiveTime implementation
// [app端关注二级页]按照开播时间排序
func (p SortOnlineTime) Less(i, j int) bool { return p[i].Online > p[j].Online }
// Swap
// [app端关注二级页]自定义排序结构
func (p SortUIDGift) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
// Len
// [app端关注二级页]自定义排序结构
func (p SortUIDGift) Len() int { return len(p) }
// Less
// [app端关注二级页]自定义排序结构
func (p SortUIDGift) Less(i, j int) bool { return p[i].gold > p[j].gold }
// AppSortRuleLiveTime implementation
// [app端关注二级页]按照开播时间排序
func AppSortRuleLiveTime(originResult *v1pb.LiveAnchorResp) (resp []*v1pb.LiveAnchorResp_Rooms) {
resp = make([]*v1pb.LiveAnchorResp_Rooms, 0)
if originResult == nil {
return
}
p := make(SortLiveTime, len(originResult.Rooms))
i := 0
for _, v := range originResult.Rooms {
p[i] = &v1pb.LiveAnchorResp_Rooms{
Roomid: v.Roomid,
Uid: v.Uid,
Uname: v.Uname,
Face: v.Face,
Title: v.Title,
LiveTagName: v.LiveTagName,
LiveTime: v.LiveTime,
Online: v.Online,
Playurl: v.Playurl,
AcceptQuality: v.AcceptQuality,
CurrentQuality: v.CurrentQuality,
PkId: v.PkId,
SpecialAttention: v.SpecialAttention,
Area: v.Area,
AreaName: v.AreaName,
AreaV2Id: v.AreaV2Id,
AreaV2Name: v.AreaV2Name,
AreaV2ParentName: v.AreaV2ParentName,
AreaV2ParentId: v.AreaV2ParentId,
BroadcastType: v.BroadcastType,
OfficialVerify: v.OfficialVerify,
Link: v.Link,
Cover: v.Cover,
PendentRu: v.PendentRu,
PendentRuColor: v.PendentRuColor,
PendentRuPic: v.PendentRuPic}
i++
}
sort.Sort(p)
resp = p
return
}
// AppSortRuleOnline implementation
// [app端关注二级页]按照人气值排序
func AppSortRuleOnline(originResult *v1pb.LiveAnchorResp) (resp []*v1pb.LiveAnchorResp_Rooms) {
resp = make([]*v1pb.LiveAnchorResp_Rooms, 0)
if originResult == nil {
return
}
p := make(SortOnlineTime, len(originResult.Rooms))
i := 0
for _, v := range originResult.Rooms {
p[i] = &v1pb.LiveAnchorResp_Rooms{
Roomid: v.Roomid,
Uid: v.Uid,
Uname: v.Uname,
Face: v.Face,
Title: v.Title,
LiveTagName: v.LiveTagName,
LiveTime: v.LiveTime,
Online: v.Online,
Playurl: v.Playurl,
AcceptQuality: v.AcceptQuality,
CurrentQuality: v.CurrentQuality,
PkId: v.PkId,
SpecialAttention: v.SpecialAttention,
Area: v.Area,
AreaName: v.AreaName,
AreaV2Id: v.AreaV2Id,
AreaV2Name: v.AreaV2Name,
AreaV2ParentName: v.AreaV2ParentName,
AreaV2ParentId: v.AreaV2ParentId,
BroadcastType: v.BroadcastType,
OfficialVerify: v.OfficialVerify,
Link: v.Link,
Cover: v.Cover,
PendentRu: v.PendentRu,
PendentRuColor: v.PendentRuColor,
PlayUrlH265: v.PlayUrlH265,
PendentRuPic: v.PendentRuPic}
i++
}
sort.Sort(p)
resp = p
return
}
// AppSortRuleGold implementation
// [app端关注二级页]按照送礼排序
func AppSortRuleGold(ctx context.Context, originResult *v1pb.LiveAnchorResp) (resp []*v1pb.LiveAnchorResp_Rooms) {
resp = make([]*v1pb.LiveAnchorResp_Rooms, 0)
if originResult == nil {
return
}
giftInfo, err := GetGiftInfo(ctx)
if err != nil {
log.Error("[LiveAnchor][FilterType][AppSortRuleGold]get_RelationGift_rpc_error")
resp = originResult.Rooms
return
}
if len(giftInfo) == 0 {
resp = AppSortRuleOnline(originResult)
return
}
respHasGold := make([]*v1pb.LiveAnchorResp_Rooms, 0)
respNoGold := make([]*v1pb.LiveAnchorResp_Rooms, 0)
GiftRank := make(map[int64]int64)
GiftNoGold := make([]int64, 0)
// 计算金瓜子排行榜,uid分key
for _, v := range originResult.Rooms {
roomUID := v.Uid
if _, exist := giftInfo[roomUID]; exist {
GiftRank[roomUID] += giftInfo[roomUID]
}
}
sorted := SortMap(GiftRank)
// 没有送礼的用户
for _, v := range originResult.Rooms {
if _, exist := GiftRank[v.Uid]; !exist {
GiftNoGold = append(GiftNoGold, v.Uid)
}
}
for _, vv := range sorted {
for _, v := range originResult.Rooms {
if v.Uid == vv.Key {
respHasGold = append(respHasGold, v)
}
}
}
for _, v := range originResult.Rooms {
for _, vv := range GiftNoGold {
if v.Uid == vv {
respNoGold = append(respNoGold, v)
}
}
}
tempLiveAnchor := &v1pb.LiveAnchorResp{}
tempLiveAnchor.Rooms = respNoGold
respNoGoldSorted := AppSortRuleOnline(tempLiveAnchor)
resp = append(resp, respHasGold...)
resp = append(resp, respNoGoldSorted...)
return
}

View File

@@ -0,0 +1,52 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = [
"AppRelationFilterStrategy.go",
"AppRelationSortStrategy.go",
"Tools.go",
"rpcWraper.go",
],
importpath = "go-common/app/interface/live/app-interface/service/v1/relation",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/interface/live/app-interface/api/http/v1:go_default_library",
"//app/interface/live/app-interface/conf:go_default_library",
"//app/interface/live/app-interface/dao:go_default_library",
"//app/service/live/av/api/liverpc/v1:go_default_library",
"//app/service/live/fans_medal/api/liverpc/v1:go_default_library",
"//app/service/live/live_data/api/liverpc/v1:go_default_library",
"//app/service/live/relation/api/liverpc/v1:go_default_library",
"//app/service/live/room/api/liverpc/v1:go_default_library",
"//app/service/live/room/api/liverpc/v2:go_default_library",
"//app/service/live/room_ex/api/liverpc/v1:go_default_library",
"//app/service/live/userext/api/liverpc/v1:go_default_library",
"//library/ecode:go_default_library",
"//library/log:go_default_library",
"//library/net/metadata:go_default_library",
"//library/net/rpc/liverpc/context:go_default_library",
"//library/sync/errgroup:go_default_library",
"//vendor/github.com/pkg/errors:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,256 @@
package relation
import (
"context"
"encoding/json"
"go-common/library/net/metadata"
"sort"
"strconv"
)
// Pair ...
// 自定义map排序结构
type Pair struct {
Key int64
Value int64
}
// Gray ...
// 自定义灰度策略结构
type Gray struct {
Key string
Value int
}
// ErrLogStrut ...
// 自定义ErrLog结构
type ErrLogStrut struct {
Code int64
Msg string
ErrDesc string
ErrType string
URLName string
RPCTimeout int64
ChunkSize int64
ChunkNum int64
ErrorPtr *error
}
// GrayRule ...
// 自定义灰度策略
type GrayRule struct {
Name string `json:"name"`
Mark string `json:"mark"`
Value string `json:"value"`
}
// PairList ...
// 自定义灰度策略
type PairList []Pair
// GrayList ...
// 自定义灰度策略
type GrayList []Gray
// Swap
// 自定义排序
func (p PairList) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
// Len
// 自定义排序
func (p PairList) Len() int { return len(p) }
// Less
// 自定义排序
func (p PairList) Less(i, j int) bool { return p[i].Value > p[j].Value }
// Swap
// 自定义排序
func (p GrayList) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
// Len
// 自定义排序
func (p GrayList) Len() int { return len(p) }
// Less
// 自定义排序
func (p GrayList) Less(i, j int) bool { return p[i].Value < p[j].Value }
// SortMap ...
// 自定义排序
func SortMap(input map[int64]int64) (sorted PairList) {
p := make(PairList, len(input))
i := 0
for k, v := range input {
p[i] = Pair{k, v}
i++
}
sort.Sort(p)
sorted = p
return
}
const (
_androidBugBuildLeft = 5332000
_androidBugBuildRight = 5341000
)
// SortMapByValue ...
// 自定义排序
func SortMapByValue(m map[string]int) GrayList {
p := make(GrayList, len(m))
i := 0
for k, v := range m {
p[i] = Gray{k, v}
i++
}
sort.Sort(p)
return p
}
// RParseInt ...
// 转int
func RParseInt(inputStr string, defaultValue int64) (output int64) {
if mid, err := strconv.ParseInt(inputStr, 10, 64); err == nil {
output = mid
} else {
output = defaultValue
}
return
}
func RoleMap(role int8) (changeType int64) {
switch role {
case 0:
{
changeType = -1
}
case 1, 2:
{
changeType = 0
}
case 3, 4, 5, 6:
{
changeType = 1
}
default:
{
changeType = -1
}
}
return
}
// CheckReturn ...
// 检查返回
func CheckReturn(err error, code int64, msg string, urlName string,
rpcTimeout int64, chunkSize int64, chunkNum int64) (errLog *ErrLogStrut, success bool) {
errInfo := ErrLogStrut{}
errInfo.URLName = urlName
errInfo.RPCTimeout = rpcTimeout
errInfo.ChunkSize = chunkSize
errInfo.ChunkNum = chunkNum
success = true
if err != nil {
errInfo.Code = 1003000
errInfo.Msg = ""
errInfo.ErrDesc = "liveRpc调用失败"
errInfo.ErrType = "LiveRpcFrameWorkCallError"
errInfo.ErrorPtr = &err
success = false
} else if code != 0 {
errInfo.Code = code
errInfo.Msg = msg
errInfo.ErrDesc = "调用直播服务" + urlName + "出错"
errInfo.ErrType = "CallLiveRpcCodeError"
success = false
}
errLog = &errInfo
return
}
// App531ABTest ...
// ABTest
func App531ABTest(ctx context.Context, content string, build string, platform string) (grayType int64) {
buildIntValue := RParseInt(build, 534000)
if platform == "android" && buildIntValue > _androidBugBuildLeft && buildIntValue <= _androidBugBuildRight {
grayType = 0
return
}
if len(content) == 0 {
grayType = 0
return
}
resultMap := make(map[string]int64)
resultMap["double_small_card"] = 0
resultMap["card_not_auto_play"] = 1
resultMap["card_auto_play"] = 2
typeMap := make([]string, 0)
mr := &[]GrayRule{}
if err := json.Unmarshal([]byte(content), mr); err != nil {
grayType = 0
return
}
ruleArr := *mr
scoreMap := make(map[string]int)
for _, v := range ruleArr {
scoreMap[v.Mark] = int(RParseInt(v.Value, 100))
}
sortedScore := SortMapByValue(scoreMap)
scoreEnd := make([]int, 0)
for _, v := range sortedScore {
scoreEnd = append(scoreEnd, v.Value)
typeMap = append(typeMap, v.Key)
}
score1 := scoreEnd[0]
score2 := scoreEnd[0] + scoreEnd[1]
score3 := 100
section1 := make(map[int]bool)
section2 := make(map[int]bool)
section3 := make(map[int]bool)
for section1Loop := 0; section1Loop < score1; section1Loop++ {
section1[section1Loop] = true
}
for sectionLoop2 := score1; sectionLoop2 < score2; sectionLoop2++ {
section2[sectionLoop2] = true
}
for sectionLoop3 := score2; sectionLoop3 < score3; sectionLoop3++ {
section3[sectionLoop3] = true
}
mid := GetUIDFromHeader(ctx)
result := int(mid % 100)
if scoreEnd[0] != 0 {
if _, exist := section1[result]; exist {
grayType = resultMap[typeMap[0]]
return
}
}
if scoreEnd[1] != 0 {
if _, exist := section2[result]; exist {
grayType = resultMap[typeMap[1]]
return
}
}
if scoreEnd[2] != 0 {
if _, exist := section3[result]; exist {
grayType = resultMap[typeMap[2]]
return
}
}
grayType = 0
return
}
// GetUIDFromHeader ...
// 获取uid
func GetUIDFromHeader(ctx context.Context) (uid int64) {
midInterface, isUIDSet := metadata.Value(ctx, metadata.Mid).(int64) // 大多使用header里的mid解析, 框架已封装请求的header
mid := int64(0)
if isUIDSet {
mid = midInterface
}
uid = mid
return
}

View File

@@ -0,0 +1,704 @@
package relation
import (
"context"
"math"
"strconv"
"time"
"go-common/app/interface/live/app-interface/conf"
"go-common/app/interface/live/app-interface/dao"
avV1 "go-common/app/service/live/av/api/liverpc/v1"
fansMedalV1 "go-common/app/service/live/fans_medal/api/liverpc/v1"
liveDataV1 "go-common/app/service/live/live_data/api/liverpc/v1"
relationV1 "go-common/app/service/live/relation/api/liverpc/v1"
roomV1 "go-common/app/service/live/room/api/liverpc/v1"
roomV2 "go-common/app/service/live/room/api/liverpc/v2"
roomExV1 "go-common/app/service/live/room_ex/api/liverpc/v1"
userExV1 "go-common/app/service/live/userext/api/liverpc/v1"
"go-common/library/ecode"
"go-common/library/log"
rpcCtx "go-common/library/net/rpc/liverpc/context"
"go-common/library/sync/errgroup"
"github.com/pkg/errors"
)
// ChunkCallInfo ...
// 日志结构体
type ChunkCallInfo struct {
ParamsName string
URLName string
ChunkSize int64
ChunkNum int64
RPCTimeout int64
}
const (
getStatusInfoByUfos = "room/v1/Room/get_status_info_by_uids"
targetsWithMedal = "fans_medal/v1/FansMedal/targetsWithMedal"
uuid2roomed = "room/v2/Room/room_id_by_uid_multi"
record = "live_data/v1/Record/get"
getPkIdsByRoomIds = "av/v1/Pk/getPkIdsByRoomIds"
roomPendent = "room/v1/RoomPendant/getPendantByIds"
roomNews = "/room_ex/v1/RoomNews/multiGet"
relationGiftInfo = "/relation/v1/BaseInfo/getGiftInfo"
// AccountGRPC ...
// 主站grpc用户信息
AccountGRPC = "Cards3"
// LiveUserExpGRPC ...
// 直播用户经验grpc
LiveUserExpGRPC = "xuserExp"
// FansNum ...
// 直播粉丝
FansNum = "GetUserFcBatch"
// LiveDomain implementation
// 域名
LiveDomain = "http://live.bilibili.com/"
// BoastURL implementation
// 秒开url
BoastURL = "?broadcast_type="
emptyResult = "调用直播服务返回data为空"
emptyResultEn = "got_empty_result"
// GoRoutingErr ...
// 协程wait错误
GoRoutingErr = "协程等待数据错误"
// App533CardType implementation
// 大卡类型
App533CardType = 1
// PendentMobileBadge implementation
// 角标类型
PendentMobileBadge = "mobile_index_badge"
// PendentPosition implementation
// 角标位置
PendentPosition = 2
// App531GrayRule implementation
// 灰度策略
App531GrayRule = "r_big_card"
// App536GrayRule implementation
// 灰度策略
App536GrayRule = "r_homepage_card536"
// SelfUID implementation
// 调试UID
SelfUID = 22973824
// DummyUIDEnable implementation
// 调试开
DummyUIDEnable = 1
)
// UIDs2roomIDs ...
// uid转换roomID,每批最大400
func UIDs2roomIDs(ctx context.Context, ufos []int64) (rolaids map[int64]int64, err error) {
rpcChunkSize, RPCTimeout, err := GetChunkInfo(uuid2roomed)
params := ChunkCallInfo{ParamsName: "ufos", URLName: uuid2roomed, ChunkSize: rpcChunkSize, RPCTimeout: RPCTimeout}
rolaids = make(map[int64]int64)
lens := len(ufos)
if lens <= 0 {
return
}
// 批次
params.ChunkNum = int64(math.Ceil(float64(lens) / float64(params.ChunkSize)))
chunkResult := make([]map[string]string, params.ChunkNum)
wg, _ := errgroup.WithContext(ctx)
for i := int64(1); i <= params.ChunkNum; i++ {
x := i
wg.Go(func() error {
chunkUfosIds := make([]int64, 20)
if x == params.ChunkNum {
chunkUfosIds = ufos[(x-1)*params.ChunkSize:]
} else {
chunkUfosIds = ufos[(x-1)*params.ChunkSize : x*params.ChunkSize]
}
ret, err := dao.RoomApi.V2Room.RoomIdByUidMulti(rpcCtx.WithTimeout(ctx, time.Duration(params.RPCTimeout)*time.Millisecond), &roomV2.RoomRoomIdByUidMultiReq{Uids: chunkUfosIds})
if err != nil {
ret = &roomV2.RoomRoomIdByUidMultiResp{}
ret.Code = -1
ret.Msg = "liveprc_error"
}
erelongInfo, success := CheckReturn(err, ret.Code, ret.Msg, uuid2roomed, params.RPCTimeout, params.ChunkSize, params.ChunkNum)
if !success {
if err != nil {
err = errors.WithMessage(ecode.PkIDRecordFrameWorkCallError, "GET SEA PATROL FAIL")
log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|error:%+v"+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s"+"|Params:%v",
err, erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName, chunkUfosIds)
}
return nil
}
if ret.Data == nil || len(ret.Data) <= 0 {
erelongInfo.ErrType = emptyResultEn
erelongInfo.ErrDesc = emptyResult
// log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s"+"|Params:%v",
// erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName, chunkUfosIds)
return nil
}
chunkResult[x-1] = ret.Data
return nil
})
}
if err := wg.Wait(); err != nil {
erelongInfo := ErrLogStrut{}
erelongInfo.ErrType = "GoRoutingWaitError"
erelongInfo.URLName = uuid2roomed
erelongInfo.ErrDesc = GoRoutingErr
erelongInfo.Code = 1003001
erelongInfo.RPCTimeout = params.RPCTimeout
erelongInfo.ErrorPtr = &err
log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|error:%+v"+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s",
*erelongInfo.ErrorPtr, erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName)
err = errors.WithMessage(ecode.RelationFrameWorkGoRoutingError, "GET SEA PATROL FAIL")
return nil, err
}
// 整理数据
for _, chunkItemList := range chunkResult {
for k, item := range chunkItemList {
if item != "" {
Index := RParseInt(k, 1)
itemInt := RParseInt(item, 1)
rolaids[Index] = itemInt
}
}
}
return
}
// GetRoomInfo ...
// 获取room信息
func GetRoomInfo(ctx context.Context, input *roomV1.RoomGetStatusInfoByUidsReq) (roomResult map[int64]*roomV1.RoomGetStatusInfoByUidsResp_RoomInfo, err error) {
rpcChunkSize, RPCTimeout, err := GetChunkInfo(getStatusInfoByUfos)
params := ChunkCallInfo{ParamsName: "uids", URLName: getStatusInfoByUfos, ChunkSize: rpcChunkSize, RPCTimeout: RPCTimeout}
roomResult = make(map[int64]*roomV1.RoomGetStatusInfoByUidsResp_RoomInfo)
lens := len(input.Uids)
if lens <= 0 {
return
}
// 批次
params.ChunkNum = int64(math.Ceil(float64(lens) / float64(params.ChunkSize)))
chunkResult := make([]map[int64]*roomV1.RoomGetStatusInfoByUidsResp_RoomInfo, params.ChunkNum)
wg, _ := errgroup.WithContext(ctx)
for i := int64(1); i <= params.ChunkNum; i++ {
x := i
wg.Go(func() error {
chunkUfosIds := make([]int64, 20)
if x == params.ChunkNum {
chunkUfosIds = input.Uids[(x-1)*params.ChunkSize:]
} else {
chunkUfosIds = input.Uids[(x-1)*params.ChunkSize : x*params.ChunkSize]
}
ret, err := dao.RoomApi.V1Room.GetStatusInfoByUids(rpcCtx.WithTimeout(ctx, time.Duration(params.RPCTimeout)*time.Millisecond), &roomV1.RoomGetStatusInfoByUidsReq{Uids: chunkUfosIds, FilterOffline: input.FilterOffline, NeedBroadcastType: input.NeedBroadcastType})
if err != nil {
if err != nil {
ret = &roomV1.RoomGetStatusInfoByUidsResp{}
ret.Code = -1
ret.Msg = "liveprc_error"
}
}
erelongInfo, success := CheckReturn(err, ret.Code, ret.Msg, getStatusInfoByUfos, params.RPCTimeout, params.ChunkSize, params.ChunkNum)
if !success {
if err != nil {
err = errors.WithMessage(ecode.PkIDRecordFrameWorkCallError, "GET SEA PATROL FAIL")
log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|error:%+v"+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s"+"|Params:%v",
err, erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName, chunkUfosIds)
} else {
err = errors.WithMessage(ecode.PkIDLiveRPCCodeError, "GET SEA PATROL FAIL")
log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|error:%+v"+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s"+"|Params:%v",
err, erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName, chunkUfosIds)
}
return nil
}
if ret.Data == nil || len(ret.Data) <= 0 {
erelongInfo.ErrType = emptyResultEn
erelongInfo.ErrDesc = emptyResult
// log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s"+"|Params:%v",
// erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName, chunkUfosIds)
return nil
}
chunkResult[x-1] = ret.Data
return nil
})
}
if err := wg.Wait(); err != nil {
erelongInfo := ErrLogStrut{}
erelongInfo.ErrType = "GoRoutingWaitError"
erelongInfo.URLName = getStatusInfoByUfos
erelongInfo.ErrDesc = GoRoutingErr
erelongInfo.Code = 1003001
erelongInfo.RPCTimeout = params.RPCTimeout
erelongInfo.ErrorPtr = &err
log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|error:%+v"+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s",
*erelongInfo.ErrorPtr, erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName)
err = errors.WithMessage(ecode.RoomFrameWorkGoRoutingError, "GET SEA PATROL FAIL")
return nil, err
}
// 整理数据
for _, chunkItemList := range chunkResult {
for _, item := range chunkItemList {
if item != nil {
roomResult[item.Uid] = item
}
}
}
return
}
// GetLastLiveTime ...
// 获取Record信息
func GetLastLiveTime(ctx context.Context, rolaids []int64) (literature map[string]string, err error) {
rpcChunkSize, RPCTimeout, err := GetChunkInfo(record)
params := ChunkCallInfo{ParamsName: "rolaids", URLName: record, ChunkSize: rpcChunkSize, RPCTimeout: RPCTimeout}
literature = make(map[string]string)
lens := len(rolaids)
if lens <= 0 {
return
}
// 批次
params.ChunkNum = int64(math.Ceil(float64(lens) / float64(params.ChunkSize)))
chunkResult := make([]map[string]*liveDataV1.RecordGetResp_TimeInfo, params.ChunkNum)
wg, _ := errgroup.WithContext(ctx)
for i := int64(1); i <= params.ChunkNum; i++ {
x := i
wg.Go(func() error {
chunkRoomIds := make([]int64, 20)
if x == params.ChunkNum {
chunkRoomIds = rolaids[(x-1)*params.ChunkSize:]
} else {
chunkRoomIds = rolaids[(x-1)*params.ChunkSize : x*params.ChunkSize]
}
ret, err := dao.LiveDataApi.V1Record.Get(rpcCtx.WithTimeout(ctx, time.Duration(params.RPCTimeout)*time.Millisecond), &liveDataV1.RecordGetReq{Roomids: chunkRoomIds})
if err != nil {
if err != nil {
ret = &liveDataV1.RecordGetResp{}
ret.Code = -1
ret.Msg = "liveprc_error"
}
}
erelongInfo, success := CheckReturn(err, ret.Code, ret.Msg, record, params.RPCTimeout, params.ChunkSize, params.ChunkNum)
if !success {
if err != nil {
err = errors.WithMessage(ecode.PkIDRecordFrameWorkCallError, "GET SEA PATROL FAIL")
log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|error:%+v"+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s"+"|Params:%v",
err, erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName, chunkRoomIds)
} else {
err = errors.WithMessage(ecode.PkIDLiveRPCCodeError, "GET SEA PATROL FAIL")
log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|error:%+v"+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s"+"|Params:%v",
err, erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName, chunkRoomIds)
}
return nil
}
if ret.Data == nil || len(ret.Data) <= 0 {
erelongInfo.ErrType = emptyResultEn
erelongInfo.ErrDesc = emptyResult
// log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s"+"|Params:%v",
// erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName, chunkRoomIds)
return nil
}
// chunkResult = append(chunkResult, ret.Data)
chunkResult[x-1] = ret.Data
return nil
})
}
if err := wg.Wait(); err != nil {
erelongInfo := ErrLogStrut{}
erelongInfo.ErrType = "GoRoutingWaitError"
erelongInfo.URLName = record
erelongInfo.ErrDesc = GoRoutingErr
erelongInfo.Code = 1003001
erelongInfo.RPCTimeout = params.RPCTimeout
erelongInfo.ErrorPtr = &err
log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|error:%+v"+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s",
*erelongInfo.ErrorPtr, erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName)
err = errors.WithMessage(ecode.RecordFrameWorkGoRoutingError, "GET SEA PATROL FAIL")
return nil, err
}
// 整理数据
for _, chunkItemList := range chunkResult {
for k, item := range chunkItemList {
if item != nil {
literature[k] = item.RecentEndTime
}
}
}
return
}
// GetRoomNewsInfo ...
// 获取公告信息
func GetRoomNewsInfo(ctx context.Context, rolaids *roomExV1.RoomNewsMultiGetReq) (roomNewsResult map[int64]*roomExV1.RoomNewsMultiGetResp_Data, err error) {
rpcChunkSize, RPCTimeout, err := GetChunkInfo(roomNews)
params := ChunkCallInfo{ParamsName: "rolaids", URLName: roomNews, ChunkSize: rpcChunkSize, RPCTimeout: RPCTimeout}
roomNewsResult = make(map[int64]*roomExV1.RoomNewsMultiGetResp_Data)
lens := len(rolaids.RoomIds)
if lens <= 0 {
return
}
// 批次
params.ChunkNum = int64(math.Ceil(float64(lens) / float64(params.ChunkSize)))
chunkResult := make([][]*roomExV1.RoomNewsMultiGetResp_Data, params.ChunkNum)
wg, _ := errgroup.WithContext(ctx)
for i := int64(1); i <= params.ChunkNum; i++ {
x := i
wg.Go(func() error {
chunkRoomIds := make([]int64, 20)
if x == params.ChunkNum {
chunkRoomIds = rolaids.RoomIds[(x-1)*params.ChunkSize:]
} else {
chunkRoomIds = rolaids.RoomIds[(x-1)*params.ChunkSize : x*params.ChunkSize]
}
ret, err := dao.RoomExtApi.V1RoomNews.MultiGet(rpcCtx.WithTimeout(ctx, time.Duration(params.RPCTimeout)*time.Millisecond), &roomExV1.RoomNewsMultiGetReq{RoomIds: chunkRoomIds, IsDecoded: rolaids.IsDecoded})
if err != nil {
if err != nil {
ret = &roomExV1.RoomNewsMultiGetResp{}
ret.Code = -1
ret.Msg = "liveprc_error"
}
}
erelongInfo, success := CheckReturn(err, ret.Code, ret.Msg, roomNews, params.RPCTimeout, params.ChunkSize, params.ChunkNum)
if !success {
if err != nil {
err = errors.WithMessage(ecode.PkIDRecordFrameWorkCallError, "GET SEA PATROL FAIL")
log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|error:%+v"+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s"+"|Params:%v",
err, erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName, chunkRoomIds)
} else {
err = errors.WithMessage(ecode.PkIDLiveRPCCodeError, "GET SEA PATROL FAIL")
log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|error:%+v"+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s"+"|Params:%v",
err, erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName, chunkRoomIds)
}
return nil
}
if ret.Data == nil {
erelongInfo.ErrType = emptyResultEn
erelongInfo.ErrDesc = emptyResult
// log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s"+"|Params:%v",
// erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName, chunkRoomIds)
return nil
}
chunkResult[x-1] = ret.Data
return nil
})
}
if err := wg.Wait(); err != nil {
erelongInfo := ErrLogStrut{}
erelongInfo.ErrType = "GoRoutingWaitError"
erelongInfo.URLName = roomNews
erelongInfo.ErrDesc = GoRoutingErr
erelongInfo.Code = 1003001
erelongInfo.RPCTimeout = params.RPCTimeout
erelongInfo.ErrorPtr = &err
log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|error:%+v"+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s",
*erelongInfo.ErrorPtr, erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName)
err = errors.WithMessage(ecode.RoomNewsFrameWorkGoRoutingError, "GET SEA PATROL FAIL")
return nil, err
}
// 整理数据
for _, chunkItemList := range chunkResult {
for _, item := range chunkItemList {
if item != nil {
if mid, err := strconv.ParseInt(item.Roomid, 10, 64); err == nil {
roomNewsResult[mid] = item
}
}
}
}
return
}
// GetRoomPendantInfo ...
// 获取角标信息
func GetRoomPendantInfo(ctx context.Context, req *roomV1.RoomPendantGetPendantByIdsReq) (roomNewsResult map[int64]*roomV1.RoomPendantGetPendantByIdsResp_Result, err error) {
rpcChunkSize, RPCTimeout, err := GetChunkInfo(roomPendent)
params := ChunkCallInfo{ParamsName: "ids", URLName: roomPendent, ChunkSize: rpcChunkSize, RPCTimeout: RPCTimeout}
roomNewsResult = make(map[int64]*roomV1.RoomPendantGetPendantByIdsResp_Result)
lens := len(req.Ids)
if lens <= 0 {
return
}
// 批次
params.ChunkNum = int64(math.Ceil(float64(lens) / float64(params.ChunkSize)))
chunkResult := make([]map[int64]*roomV1.RoomPendantGetPendantByIdsResp_Result, params.ChunkNum)
wg, _ := errgroup.WithContext(ctx)
for i := int64(1); i <= params.ChunkNum; i++ {
x := i
wg.Go(func() error {
chunkRoomIds := make([]int64, 20)
if x == params.ChunkNum {
chunkRoomIds = req.Ids[(x-1)*params.ChunkSize:]
} else {
chunkRoomIds = req.Ids[(x-1)*params.ChunkSize : x*params.ChunkSize]
}
ret, err := dao.RoomApi.V1RoomPendant.GetPendantByIds(rpcCtx.WithTimeout(ctx, time.Duration(params.RPCTimeout)*time.Millisecond), &roomV1.RoomPendantGetPendantByIdsReq{Ids: chunkRoomIds, Type: req.Type, Position: req.Position})
if err != nil {
if err != nil {
ret = &roomV1.RoomPendantGetPendantByIdsResp{}
ret.Code = -1
ret.Msg = "liveprc_error"
}
}
erelongInfo, success := CheckReturn(err, ret.Code, ret.Msg, roomPendent, params.RPCTimeout, params.ChunkSize, params.ChunkNum)
if !success {
if err != nil {
err = errors.WithMessage(ecode.PkIDRecordFrameWorkCallError, "GET SEA PATROL FAIL")
log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|error:%+v"+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s"+"|Params:%v",
err, erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName, chunkRoomIds)
} else {
err = errors.WithMessage(ecode.PkIDLiveRPCCodeError, "GET SEA PATROL FAIL")
log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|error:%+v"+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s"+"|Params:%v",
err, erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName, chunkRoomIds)
}
return nil
}
if ret.Data == nil {
erelongInfo.ErrType = emptyResultEn
erelongInfo.ErrDesc = emptyResult
return nil
}
chunkResult[x-1] = ret.Data.Result
return nil
})
}
if err := wg.Wait(); err != nil {
erelongInfo := ErrLogStrut{}
erelongInfo.ErrType = "GoRoutingWaitError"
erelongInfo.URLName = roomPendent
erelongInfo.ErrDesc = GoRoutingErr
erelongInfo.Code = 1003001
erelongInfo.RPCTimeout = params.RPCTimeout
erelongInfo.ErrorPtr = &err
log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|error:%+v"+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s",
*erelongInfo.ErrorPtr, erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName)
err = errors.WithMessage(ecode.RoomPendentFrameWorkGoRoutingError, "GET SEA PATROL FAIL")
return nil, err
}
// 整理数据
for _, chunkItemList := range chunkResult {
for k, item := range chunkItemList {
if item != nil {
roomNewsResult[k] = item
}
}
}
return
}
// GetPkID ...
// 获取PkId信息
func GetPkID(ctx context.Context, req *avV1.PkGetPkIdsByRoomIdsReq) (avResult map[string]int64, err error) {
rpcChunkSize, RPCTimeout, err := GetChunkInfo(getPkIdsByRoomIds)
params := ChunkCallInfo{ParamsName: "roomids", URLName: getPkIdsByRoomIds, ChunkSize: rpcChunkSize, RPCTimeout: RPCTimeout}
avResult = make(map[string]int64)
lens := len(req.RoomIds)
if lens <= 0 {
return
}
// 批次
params.ChunkNum = int64(math.Ceil(float64(lens) / float64(params.ChunkSize)))
chunkResult := make([]map[string]int64, params.ChunkNum)
wg, _ := errgroup.WithContext(ctx)
for i := int64(1); i <= params.ChunkNum; i++ {
x := i
wg.Go(func() error {
chunkRoomIds := make([]int64, 20)
if x == params.ChunkNum {
chunkRoomIds = req.RoomIds[(x-1)*params.ChunkSize:]
} else {
chunkRoomIds = req.RoomIds[(x-1)*params.ChunkSize : x*params.ChunkSize]
}
ret, err := dao.AvApi.V1Pk.GetPkIdsByRoomIds(rpcCtx.WithTimeout(ctx, time.Duration(params.RPCTimeout)*time.Millisecond), &avV1.PkGetPkIdsByRoomIdsReq{RoomIds: chunkRoomIds, Platform: req.Platform})
if err != nil {
if err != nil {
ret = &avV1.PkGetPkIdsByRoomIdsResp{}
ret.Code = -1
ret.Msg = "liveprc_error"
}
}
erelongInfo, success := CheckReturn(err, ret.Code, ret.Msg, getPkIdsByRoomIds, params.RPCTimeout, params.ChunkSize, params.ChunkNum)
if !success {
if err != nil {
err = errors.WithMessage(ecode.PkIDRecordFrameWorkCallError, "GET SEA PATROL FAIL")
log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|error:%+v"+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s"+"|Params:%v",
err, erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName, chunkRoomIds)
} else {
err = errors.WithMessage(ecode.PkIDLiveRPCCodeError, "GET SEA PATROL FAIL")
log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|error:%+v"+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s"+"|Params:%v",
err, erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName, chunkRoomIds)
}
return nil
}
if ret.Data == nil || len(ret.Data) <= 0 {
erelongInfo.ErrType = emptyResultEn
erelongInfo.ErrDesc = emptyResult
// log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s"+"|Params:%v",
// erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName, chunkRoomIds)
return nil
}
chunkResult[x-1] = ret.Data
return nil
})
}
if err := wg.Wait(); err != nil {
erelongInfo := ErrLogStrut{}
erelongInfo.ErrType = "GoRoutingWaitError"
erelongInfo.URLName = getPkIdsByRoomIds
erelongInfo.ErrDesc = GoRoutingErr
erelongInfo.Code = 1003001
erelongInfo.RPCTimeout = params.RPCTimeout
erelongInfo.ErrorPtr = &err
log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|error:%+v"+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s",
*erelongInfo.ErrorPtr, erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName)
err = errors.WithMessage(ecode.PkIDFrameWorkGoRoutingError, "GET SEA PATROL FAIL")
return nil, err
}
// 整理数据
for _, chunkItemList := range chunkResult {
for k, item := range chunkItemList {
avResult[k] = item
}
}
return
}
// GetFansMedal ...
// 获取粉丝勋章佩戴信息
func GetFansMedal(ctx context.Context, req *fansMedalV1.FansMedalTargetsWithMedalReq) (fansResult map[int64]bool, err error) {
rpcChunkSize, RPCTimeout, err := GetChunkInfo(targetsWithMedal)
params := ChunkCallInfo{ParamsName: "target_ids", URLName: targetsWithMedal, ChunkSize: rpcChunkSize, RPCTimeout: RPCTimeout}
fansResult = make(map[int64]bool)
lens := len(req.TargetIds)
if lens <= 0 {
return
}
// 批次
params.ChunkNum = int64(math.Ceil(float64(lens) / float64(params.ChunkSize)))
chunkResult := make([][]int64, params.ChunkNum)
wg, _ := errgroup.WithContext(ctx)
for i := int64(1); i <= params.ChunkNum; i++ {
x := i
wg.Go(func() error {
chunkRoomIds := make([]int64, 20)
if x == params.ChunkNum {
chunkRoomIds = req.TargetIds[(x-1)*params.ChunkSize:]
} else {
chunkRoomIds = req.TargetIds[(x-1)*params.ChunkSize : x*params.ChunkSize]
}
ret, err := dao.FansMedalApi.V1FansMedal.TargetsWithMedal(rpcCtx.WithTimeout(ctx, time.Duration(params.RPCTimeout)*time.Millisecond), &fansMedalV1.FansMedalTargetsWithMedalReq{Uid: req.Uid, TargetIds: chunkRoomIds})
if err != nil {
if err != nil {
ret = &fansMedalV1.FansMedalTargetsWithMedalResp{}
ret.Code = -1
ret.Msg = "liveprc_error"
}
}
erelongInfo, success := CheckReturn(err, ret.Code, ret.Msg, targetsWithMedal, params.RPCTimeout, params.ChunkSize, params.ChunkNum)
if !success {
if err != nil {
err = errors.WithMessage(ecode.PkIDRecordFrameWorkCallError, "GET SEA PATROL FAIL")
log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|error:%+v"+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s"+"|Params:%v",
err, erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName, chunkRoomIds)
} else {
err = errors.WithMessage(ecode.PkIDLiveRPCCodeError, "GET SEA PATROL FAIL")
log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|error:%+v"+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s"+"|Params:%v",
err, erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName, chunkRoomIds)
}
return nil
}
if ret.Data == nil || len(ret.Data) <= 0 {
erelongInfo.ErrType = emptyResultEn
erelongInfo.ErrDesc = emptyResult
// log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s"+"|Params:%v",
// erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName, chunkRoomIds)
return nil
}
chunkResult[x-1] = ret.Data
return nil
})
}
if err := wg.Wait(); err != nil {
erelongInfo := ErrLogStrut{}
erelongInfo.ErrType = "GoRoutingWaitError"
erelongInfo.URLName = targetsWithMedal
erelongInfo.ErrDesc = GoRoutingErr
erelongInfo.Code = 1003001
erelongInfo.RPCTimeout = params.RPCTimeout
erelongInfo.ErrorPtr = &err
log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|error:%+v"+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s",
*erelongInfo.ErrorPtr, erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName)
err = errors.WithMessage(ecode.FansMedalFrameWorkGoRoutingError, "GET SEA PATROL FAIL")
return nil, err
}
// 整理数据
for _, chunkItemList := range chunkResult {
for _, item := range chunkItemList {
fansResult[item] = true
}
}
return
}
// GetGrayRule ...
// 获取灰度规则信息
func GetGrayRule(ctx context.Context, req *userExV1.GrayRuleGetByMarkReq) (extResult *userExV1.GrayRuleGetByMarkResp_Data, err error) {
extResult = &userExV1.GrayRuleGetByMarkResp_Data{}
if req == nil {
return nil, nil
}
ret, err := dao.UserExtApi.V1GrayRule.GetByMark(ctx, req)
if err != nil {
log.Error("call_userExt_grayRule error,err:%v", err)
err = errors.WithMessage(ecode.GetGrayRuleError, "GET SEA PATROL FAIL")
return
}
extResult = ret.Data
return
}
// GetGiftInfo ...
// 获取送礼信息
func GetGiftInfo(ctx context.Context) (giftInfo map[int64]int64, err error) {
_, RPCTimeout, _ := GetChunkInfo(relationGiftInfo)
relationParams := &relationV1.BaseInfoGetGiftInfoReq{}
giftInfo = make(map[int64]int64)
ret, err := dao.RelationApi.V1BaseInfo.GetGiftInfo(ctx, relationParams)
if err != nil {
if err != nil {
ret = &relationV1.BaseInfoGetGiftInfoResp{}
ret.Code = -1
ret.Msg = "liveprc_error"
}
}
params := ChunkCallInfo{ParamsName: "", URLName: relationGiftInfo, ChunkSize: 1, RPCTimeout: RPCTimeout}
erelongInfo, success := CheckReturn(err, ret.Code, ret.Msg, "gift", params.RPCTimeout, params.ChunkSize, params.ChunkNum)
if !success {
if err != nil {
err = errors.WithMessage(ecode.PkIDRecordFrameWorkCallError, "GET SEA PATROL FAIL")
log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|error:%+v"+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s",
err, erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName)
} else {
err = errors.WithMessage(ecode.PkIDLiveRPCCodeError, "GET SEA PATROL FAIL")
log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|error:%+v"+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s",
err, erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName)
}
return giftInfo, nil
}
if ret.Data == nil || len(ret.Data) < 0 {
erelongInfo.ErrType = emptyResultEn
erelongInfo.ErrDesc = emptyResult
// log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d",
// erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName)
return giftInfo, nil
}
for _, v := range ret.Data {
giftInfo[v.Mid] = v.Gold
}
return
}
// GetChunkInfo ...
// 获取分块信息
func GetChunkInfo(rpcName string) (rpcChunkSize int64, RPCTimeout int64, err error) {
rpcChunkSize = conf.GetChunkSize(rpcName, 20)
RPCTimeout = conf.GetTimeout(rpcName, 100)
return
}