rpcWraper.go 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  1. package relation
  2. import (
  3. "context"
  4. "math"
  5. "strconv"
  6. "time"
  7. "go-common/app/interface/live/app-interface/conf"
  8. "go-common/app/interface/live/app-interface/dao"
  9. avV1 "go-common/app/service/live/av/api/liverpc/v1"
  10. fansMedalV1 "go-common/app/service/live/fans_medal/api/liverpc/v1"
  11. liveDataV1 "go-common/app/service/live/live_data/api/liverpc/v1"
  12. relationV1 "go-common/app/service/live/relation/api/liverpc/v1"
  13. roomV1 "go-common/app/service/live/room/api/liverpc/v1"
  14. roomV2 "go-common/app/service/live/room/api/liverpc/v2"
  15. roomExV1 "go-common/app/service/live/room_ex/api/liverpc/v1"
  16. userExV1 "go-common/app/service/live/userext/api/liverpc/v1"
  17. "go-common/library/ecode"
  18. "go-common/library/log"
  19. rpcCtx "go-common/library/net/rpc/liverpc/context"
  20. "go-common/library/sync/errgroup"
  21. "github.com/pkg/errors"
  22. )
  23. // ChunkCallInfo ...
  24. // 日志结构体
  25. type ChunkCallInfo struct {
  26. ParamsName string
  27. URLName string
  28. ChunkSize int64
  29. ChunkNum int64
  30. RPCTimeout int64
  31. }
  32. const (
  33. getStatusInfoByUfos = "room/v1/Room/get_status_info_by_uids"
  34. targetsWithMedal = "fans_medal/v1/FansMedal/targetsWithMedal"
  35. uuid2roomed = "room/v2/Room/room_id_by_uid_multi"
  36. record = "live_data/v1/Record/get"
  37. getPkIdsByRoomIds = "av/v1/Pk/getPkIdsByRoomIds"
  38. roomPendent = "room/v1/RoomPendant/getPendantByIds"
  39. roomNews = "/room_ex/v1/RoomNews/multiGet"
  40. relationGiftInfo = "/relation/v1/BaseInfo/getGiftInfo"
  41. // AccountGRPC ...
  42. // 主站grpc用户信息
  43. AccountGRPC = "Cards3"
  44. // LiveUserExpGRPC ...
  45. // 直播用户经验grpc
  46. LiveUserExpGRPC = "xuserExp"
  47. // FansNum ...
  48. // 直播粉丝
  49. FansNum = "GetUserFcBatch"
  50. // LiveDomain implementation
  51. // 域名
  52. LiveDomain = "http://live.bilibili.com/"
  53. // BoastURL implementation
  54. // 秒开url
  55. BoastURL = "?broadcast_type="
  56. emptyResult = "调用直播服务返回data为空"
  57. emptyResultEn = "got_empty_result"
  58. // GoRoutingErr ...
  59. // 协程wait错误
  60. GoRoutingErr = "协程等待数据错误"
  61. // App533CardType implementation
  62. // 大卡类型
  63. App533CardType = 1
  64. // PendentMobileBadge implementation
  65. // 角标类型
  66. PendentMobileBadge = "mobile_index_badge"
  67. // PendentPosition implementation
  68. // 角标位置
  69. PendentPosition = 2
  70. // App531GrayRule implementation
  71. // 灰度策略
  72. App531GrayRule = "r_big_card"
  73. // App536GrayRule implementation
  74. // 灰度策略
  75. App536GrayRule = "r_homepage_card536"
  76. // SelfUID implementation
  77. // 调试UID
  78. SelfUID = 22973824
  79. // DummyUIDEnable implementation
  80. // 调试开
  81. DummyUIDEnable = 1
  82. )
  83. // UIDs2roomIDs ...
  84. // uid转换roomID,每批最大400
  85. func UIDs2roomIDs(ctx context.Context, ufos []int64) (rolaids map[int64]int64, err error) {
  86. rpcChunkSize, RPCTimeout, err := GetChunkInfo(uuid2roomed)
  87. params := ChunkCallInfo{ParamsName: "ufos", URLName: uuid2roomed, ChunkSize: rpcChunkSize, RPCTimeout: RPCTimeout}
  88. rolaids = make(map[int64]int64)
  89. lens := len(ufos)
  90. if lens <= 0 {
  91. return
  92. }
  93. // 批次
  94. params.ChunkNum = int64(math.Ceil(float64(lens) / float64(params.ChunkSize)))
  95. chunkResult := make([]map[string]string, params.ChunkNum)
  96. wg, _ := errgroup.WithContext(ctx)
  97. for i := int64(1); i <= params.ChunkNum; i++ {
  98. x := i
  99. wg.Go(func() error {
  100. chunkUfosIds := make([]int64, 20)
  101. if x == params.ChunkNum {
  102. chunkUfosIds = ufos[(x-1)*params.ChunkSize:]
  103. } else {
  104. chunkUfosIds = ufos[(x-1)*params.ChunkSize : x*params.ChunkSize]
  105. }
  106. ret, err := dao.RoomApi.V2Room.RoomIdByUidMulti(rpcCtx.WithTimeout(ctx, time.Duration(params.RPCTimeout)*time.Millisecond), &roomV2.RoomRoomIdByUidMultiReq{Uids: chunkUfosIds})
  107. if err != nil {
  108. ret = &roomV2.RoomRoomIdByUidMultiResp{}
  109. ret.Code = -1
  110. ret.Msg = "liveprc_error"
  111. }
  112. erelongInfo, success := CheckReturn(err, ret.Code, ret.Msg, uuid2roomed, params.RPCTimeout, params.ChunkSize, params.ChunkNum)
  113. if !success {
  114. if err != nil {
  115. err = errors.WithMessage(ecode.PkIDRecordFrameWorkCallError, "GET SEA PATROL FAIL")
  116. log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|error:%+v"+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s"+"|Params:%v",
  117. err, erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName, chunkUfosIds)
  118. }
  119. return nil
  120. }
  121. if ret.Data == nil || len(ret.Data) <= 0 {
  122. erelongInfo.ErrType = emptyResultEn
  123. erelongInfo.ErrDesc = emptyResult
  124. // log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s"+"|Params:%v",
  125. // erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName, chunkUfosIds)
  126. return nil
  127. }
  128. chunkResult[x-1] = ret.Data
  129. return nil
  130. })
  131. }
  132. if err := wg.Wait(); err != nil {
  133. erelongInfo := ErrLogStrut{}
  134. erelongInfo.ErrType = "GoRoutingWaitError"
  135. erelongInfo.URLName = uuid2roomed
  136. erelongInfo.ErrDesc = GoRoutingErr
  137. erelongInfo.Code = 1003001
  138. erelongInfo.RPCTimeout = params.RPCTimeout
  139. erelongInfo.ErrorPtr = &err
  140. log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|error:%+v"+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s",
  141. *erelongInfo.ErrorPtr, erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName)
  142. err = errors.WithMessage(ecode.RelationFrameWorkGoRoutingError, "GET SEA PATROL FAIL")
  143. return nil, err
  144. }
  145. // 整理数据
  146. for _, chunkItemList := range chunkResult {
  147. for k, item := range chunkItemList {
  148. if item != "" {
  149. Index := RParseInt(k, 1)
  150. itemInt := RParseInt(item, 1)
  151. rolaids[Index] = itemInt
  152. }
  153. }
  154. }
  155. return
  156. }
  157. // GetRoomInfo ...
  158. // 获取room信息
  159. func GetRoomInfo(ctx context.Context, input *roomV1.RoomGetStatusInfoByUidsReq) (roomResult map[int64]*roomV1.RoomGetStatusInfoByUidsResp_RoomInfo, err error) {
  160. rpcChunkSize, RPCTimeout, err := GetChunkInfo(getStatusInfoByUfos)
  161. params := ChunkCallInfo{ParamsName: "uids", URLName: getStatusInfoByUfos, ChunkSize: rpcChunkSize, RPCTimeout: RPCTimeout}
  162. roomResult = make(map[int64]*roomV1.RoomGetStatusInfoByUidsResp_RoomInfo)
  163. lens := len(input.Uids)
  164. if lens <= 0 {
  165. return
  166. }
  167. // 批次
  168. params.ChunkNum = int64(math.Ceil(float64(lens) / float64(params.ChunkSize)))
  169. chunkResult := make([]map[int64]*roomV1.RoomGetStatusInfoByUidsResp_RoomInfo, params.ChunkNum)
  170. wg, _ := errgroup.WithContext(ctx)
  171. for i := int64(1); i <= params.ChunkNum; i++ {
  172. x := i
  173. wg.Go(func() error {
  174. chunkUfosIds := make([]int64, 20)
  175. if x == params.ChunkNum {
  176. chunkUfosIds = input.Uids[(x-1)*params.ChunkSize:]
  177. } else {
  178. chunkUfosIds = input.Uids[(x-1)*params.ChunkSize : x*params.ChunkSize]
  179. }
  180. 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})
  181. if err != nil {
  182. if err != nil {
  183. ret = &roomV1.RoomGetStatusInfoByUidsResp{}
  184. ret.Code = -1
  185. ret.Msg = "liveprc_error"
  186. }
  187. }
  188. erelongInfo, success := CheckReturn(err, ret.Code, ret.Msg, getStatusInfoByUfos, params.RPCTimeout, params.ChunkSize, params.ChunkNum)
  189. if !success {
  190. if err != nil {
  191. err = errors.WithMessage(ecode.PkIDRecordFrameWorkCallError, "GET SEA PATROL FAIL")
  192. log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|error:%+v"+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s"+"|Params:%v",
  193. err, erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName, chunkUfosIds)
  194. } else {
  195. err = errors.WithMessage(ecode.PkIDLiveRPCCodeError, "GET SEA PATROL FAIL")
  196. log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|error:%+v"+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s"+"|Params:%v",
  197. err, erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName, chunkUfosIds)
  198. }
  199. return nil
  200. }
  201. if ret.Data == nil || len(ret.Data) <= 0 {
  202. erelongInfo.ErrType = emptyResultEn
  203. erelongInfo.ErrDesc = emptyResult
  204. // log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s"+"|Params:%v",
  205. // erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName, chunkUfosIds)
  206. return nil
  207. }
  208. chunkResult[x-1] = ret.Data
  209. return nil
  210. })
  211. }
  212. if err := wg.Wait(); err != nil {
  213. erelongInfo := ErrLogStrut{}
  214. erelongInfo.ErrType = "GoRoutingWaitError"
  215. erelongInfo.URLName = getStatusInfoByUfos
  216. erelongInfo.ErrDesc = GoRoutingErr
  217. erelongInfo.Code = 1003001
  218. erelongInfo.RPCTimeout = params.RPCTimeout
  219. erelongInfo.ErrorPtr = &err
  220. log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|error:%+v"+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s",
  221. *erelongInfo.ErrorPtr, erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName)
  222. err = errors.WithMessage(ecode.RoomFrameWorkGoRoutingError, "GET SEA PATROL FAIL")
  223. return nil, err
  224. }
  225. // 整理数据
  226. for _, chunkItemList := range chunkResult {
  227. for _, item := range chunkItemList {
  228. if item != nil {
  229. roomResult[item.Uid] = item
  230. }
  231. }
  232. }
  233. return
  234. }
  235. // GetLastLiveTime ...
  236. // 获取Record信息
  237. func GetLastLiveTime(ctx context.Context, rolaids []int64) (literature map[string]string, err error) {
  238. rpcChunkSize, RPCTimeout, err := GetChunkInfo(record)
  239. params := ChunkCallInfo{ParamsName: "rolaids", URLName: record, ChunkSize: rpcChunkSize, RPCTimeout: RPCTimeout}
  240. literature = make(map[string]string)
  241. lens := len(rolaids)
  242. if lens <= 0 {
  243. return
  244. }
  245. // 批次
  246. params.ChunkNum = int64(math.Ceil(float64(lens) / float64(params.ChunkSize)))
  247. chunkResult := make([]map[string]*liveDataV1.RecordGetResp_TimeInfo, params.ChunkNum)
  248. wg, _ := errgroup.WithContext(ctx)
  249. for i := int64(1); i <= params.ChunkNum; i++ {
  250. x := i
  251. wg.Go(func() error {
  252. chunkRoomIds := make([]int64, 20)
  253. if x == params.ChunkNum {
  254. chunkRoomIds = rolaids[(x-1)*params.ChunkSize:]
  255. } else {
  256. chunkRoomIds = rolaids[(x-1)*params.ChunkSize : x*params.ChunkSize]
  257. }
  258. ret, err := dao.LiveDataApi.V1Record.Get(rpcCtx.WithTimeout(ctx, time.Duration(params.RPCTimeout)*time.Millisecond), &liveDataV1.RecordGetReq{Roomids: chunkRoomIds})
  259. if err != nil {
  260. if err != nil {
  261. ret = &liveDataV1.RecordGetResp{}
  262. ret.Code = -1
  263. ret.Msg = "liveprc_error"
  264. }
  265. }
  266. erelongInfo, success := CheckReturn(err, ret.Code, ret.Msg, record, params.RPCTimeout, params.ChunkSize, params.ChunkNum)
  267. if !success {
  268. if err != nil {
  269. err = errors.WithMessage(ecode.PkIDRecordFrameWorkCallError, "GET SEA PATROL FAIL")
  270. log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|error:%+v"+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s"+"|Params:%v",
  271. err, erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName, chunkRoomIds)
  272. } else {
  273. err = errors.WithMessage(ecode.PkIDLiveRPCCodeError, "GET SEA PATROL FAIL")
  274. log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|error:%+v"+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s"+"|Params:%v",
  275. err, erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName, chunkRoomIds)
  276. }
  277. return nil
  278. }
  279. if ret.Data == nil || len(ret.Data) <= 0 {
  280. erelongInfo.ErrType = emptyResultEn
  281. erelongInfo.ErrDesc = emptyResult
  282. // log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s"+"|Params:%v",
  283. // erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName, chunkRoomIds)
  284. return nil
  285. }
  286. // chunkResult = append(chunkResult, ret.Data)
  287. chunkResult[x-1] = ret.Data
  288. return nil
  289. })
  290. }
  291. if err := wg.Wait(); err != nil {
  292. erelongInfo := ErrLogStrut{}
  293. erelongInfo.ErrType = "GoRoutingWaitError"
  294. erelongInfo.URLName = record
  295. erelongInfo.ErrDesc = GoRoutingErr
  296. erelongInfo.Code = 1003001
  297. erelongInfo.RPCTimeout = params.RPCTimeout
  298. erelongInfo.ErrorPtr = &err
  299. log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|error:%+v"+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s",
  300. *erelongInfo.ErrorPtr, erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName)
  301. err = errors.WithMessage(ecode.RecordFrameWorkGoRoutingError, "GET SEA PATROL FAIL")
  302. return nil, err
  303. }
  304. // 整理数据
  305. for _, chunkItemList := range chunkResult {
  306. for k, item := range chunkItemList {
  307. if item != nil {
  308. literature[k] = item.RecentEndTime
  309. }
  310. }
  311. }
  312. return
  313. }
  314. // GetRoomNewsInfo ...
  315. // 获取公告信息
  316. func GetRoomNewsInfo(ctx context.Context, rolaids *roomExV1.RoomNewsMultiGetReq) (roomNewsResult map[int64]*roomExV1.RoomNewsMultiGetResp_Data, err error) {
  317. rpcChunkSize, RPCTimeout, err := GetChunkInfo(roomNews)
  318. params := ChunkCallInfo{ParamsName: "rolaids", URLName: roomNews, ChunkSize: rpcChunkSize, RPCTimeout: RPCTimeout}
  319. roomNewsResult = make(map[int64]*roomExV1.RoomNewsMultiGetResp_Data)
  320. lens := len(rolaids.RoomIds)
  321. if lens <= 0 {
  322. return
  323. }
  324. // 批次
  325. params.ChunkNum = int64(math.Ceil(float64(lens) / float64(params.ChunkSize)))
  326. chunkResult := make([][]*roomExV1.RoomNewsMultiGetResp_Data, params.ChunkNum)
  327. wg, _ := errgroup.WithContext(ctx)
  328. for i := int64(1); i <= params.ChunkNum; i++ {
  329. x := i
  330. wg.Go(func() error {
  331. chunkRoomIds := make([]int64, 20)
  332. if x == params.ChunkNum {
  333. chunkRoomIds = rolaids.RoomIds[(x-1)*params.ChunkSize:]
  334. } else {
  335. chunkRoomIds = rolaids.RoomIds[(x-1)*params.ChunkSize : x*params.ChunkSize]
  336. }
  337. ret, err := dao.RoomExtApi.V1RoomNews.MultiGet(rpcCtx.WithTimeout(ctx, time.Duration(params.RPCTimeout)*time.Millisecond), &roomExV1.RoomNewsMultiGetReq{RoomIds: chunkRoomIds, IsDecoded: rolaids.IsDecoded})
  338. if err != nil {
  339. if err != nil {
  340. ret = &roomExV1.RoomNewsMultiGetResp{}
  341. ret.Code = -1
  342. ret.Msg = "liveprc_error"
  343. }
  344. }
  345. erelongInfo, success := CheckReturn(err, ret.Code, ret.Msg, roomNews, params.RPCTimeout, params.ChunkSize, params.ChunkNum)
  346. if !success {
  347. if err != nil {
  348. err = errors.WithMessage(ecode.PkIDRecordFrameWorkCallError, "GET SEA PATROL FAIL")
  349. log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|error:%+v"+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s"+"|Params:%v",
  350. err, erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName, chunkRoomIds)
  351. } else {
  352. err = errors.WithMessage(ecode.PkIDLiveRPCCodeError, "GET SEA PATROL FAIL")
  353. log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|error:%+v"+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s"+"|Params:%v",
  354. err, erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName, chunkRoomIds)
  355. }
  356. return nil
  357. }
  358. if ret.Data == nil {
  359. erelongInfo.ErrType = emptyResultEn
  360. erelongInfo.ErrDesc = emptyResult
  361. // log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s"+"|Params:%v",
  362. // erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName, chunkRoomIds)
  363. return nil
  364. }
  365. chunkResult[x-1] = ret.Data
  366. return nil
  367. })
  368. }
  369. if err := wg.Wait(); err != nil {
  370. erelongInfo := ErrLogStrut{}
  371. erelongInfo.ErrType = "GoRoutingWaitError"
  372. erelongInfo.URLName = roomNews
  373. erelongInfo.ErrDesc = GoRoutingErr
  374. erelongInfo.Code = 1003001
  375. erelongInfo.RPCTimeout = params.RPCTimeout
  376. erelongInfo.ErrorPtr = &err
  377. log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|error:%+v"+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s",
  378. *erelongInfo.ErrorPtr, erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName)
  379. err = errors.WithMessage(ecode.RoomNewsFrameWorkGoRoutingError, "GET SEA PATROL FAIL")
  380. return nil, err
  381. }
  382. // 整理数据
  383. for _, chunkItemList := range chunkResult {
  384. for _, item := range chunkItemList {
  385. if item != nil {
  386. if mid, err := strconv.ParseInt(item.Roomid, 10, 64); err == nil {
  387. roomNewsResult[mid] = item
  388. }
  389. }
  390. }
  391. }
  392. return
  393. }
  394. // GetRoomPendantInfo ...
  395. // 获取角标信息
  396. func GetRoomPendantInfo(ctx context.Context, req *roomV1.RoomPendantGetPendantByIdsReq) (roomNewsResult map[int64]*roomV1.RoomPendantGetPendantByIdsResp_Result, err error) {
  397. rpcChunkSize, RPCTimeout, err := GetChunkInfo(roomPendent)
  398. params := ChunkCallInfo{ParamsName: "ids", URLName: roomPendent, ChunkSize: rpcChunkSize, RPCTimeout: RPCTimeout}
  399. roomNewsResult = make(map[int64]*roomV1.RoomPendantGetPendantByIdsResp_Result)
  400. lens := len(req.Ids)
  401. if lens <= 0 {
  402. return
  403. }
  404. // 批次
  405. params.ChunkNum = int64(math.Ceil(float64(lens) / float64(params.ChunkSize)))
  406. chunkResult := make([]map[int64]*roomV1.RoomPendantGetPendantByIdsResp_Result, params.ChunkNum)
  407. wg, _ := errgroup.WithContext(ctx)
  408. for i := int64(1); i <= params.ChunkNum; i++ {
  409. x := i
  410. wg.Go(func() error {
  411. chunkRoomIds := make([]int64, 20)
  412. if x == params.ChunkNum {
  413. chunkRoomIds = req.Ids[(x-1)*params.ChunkSize:]
  414. } else {
  415. chunkRoomIds = req.Ids[(x-1)*params.ChunkSize : x*params.ChunkSize]
  416. }
  417. 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})
  418. if err != nil {
  419. if err != nil {
  420. ret = &roomV1.RoomPendantGetPendantByIdsResp{}
  421. ret.Code = -1
  422. ret.Msg = "liveprc_error"
  423. }
  424. }
  425. erelongInfo, success := CheckReturn(err, ret.Code, ret.Msg, roomPendent, params.RPCTimeout, params.ChunkSize, params.ChunkNum)
  426. if !success {
  427. if err != nil {
  428. err = errors.WithMessage(ecode.PkIDRecordFrameWorkCallError, "GET SEA PATROL FAIL")
  429. log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|error:%+v"+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s"+"|Params:%v",
  430. err, erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName, chunkRoomIds)
  431. } else {
  432. err = errors.WithMessage(ecode.PkIDLiveRPCCodeError, "GET SEA PATROL FAIL")
  433. log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|error:%+v"+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s"+"|Params:%v",
  434. err, erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName, chunkRoomIds)
  435. }
  436. return nil
  437. }
  438. if ret.Data == nil {
  439. erelongInfo.ErrType = emptyResultEn
  440. erelongInfo.ErrDesc = emptyResult
  441. return nil
  442. }
  443. chunkResult[x-1] = ret.Data.Result
  444. return nil
  445. })
  446. }
  447. if err := wg.Wait(); err != nil {
  448. erelongInfo := ErrLogStrut{}
  449. erelongInfo.ErrType = "GoRoutingWaitError"
  450. erelongInfo.URLName = roomPendent
  451. erelongInfo.ErrDesc = GoRoutingErr
  452. erelongInfo.Code = 1003001
  453. erelongInfo.RPCTimeout = params.RPCTimeout
  454. erelongInfo.ErrorPtr = &err
  455. log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|error:%+v"+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s",
  456. *erelongInfo.ErrorPtr, erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName)
  457. err = errors.WithMessage(ecode.RoomPendentFrameWorkGoRoutingError, "GET SEA PATROL FAIL")
  458. return nil, err
  459. }
  460. // 整理数据
  461. for _, chunkItemList := range chunkResult {
  462. for k, item := range chunkItemList {
  463. if item != nil {
  464. roomNewsResult[k] = item
  465. }
  466. }
  467. }
  468. return
  469. }
  470. // GetPkID ...
  471. // 获取PkId信息
  472. func GetPkID(ctx context.Context, req *avV1.PkGetPkIdsByRoomIdsReq) (avResult map[string]int64, err error) {
  473. rpcChunkSize, RPCTimeout, err := GetChunkInfo(getPkIdsByRoomIds)
  474. params := ChunkCallInfo{ParamsName: "roomids", URLName: getPkIdsByRoomIds, ChunkSize: rpcChunkSize, RPCTimeout: RPCTimeout}
  475. avResult = make(map[string]int64)
  476. lens := len(req.RoomIds)
  477. if lens <= 0 {
  478. return
  479. }
  480. // 批次
  481. params.ChunkNum = int64(math.Ceil(float64(lens) / float64(params.ChunkSize)))
  482. chunkResult := make([]map[string]int64, params.ChunkNum)
  483. wg, _ := errgroup.WithContext(ctx)
  484. for i := int64(1); i <= params.ChunkNum; i++ {
  485. x := i
  486. wg.Go(func() error {
  487. chunkRoomIds := make([]int64, 20)
  488. if x == params.ChunkNum {
  489. chunkRoomIds = req.RoomIds[(x-1)*params.ChunkSize:]
  490. } else {
  491. chunkRoomIds = req.RoomIds[(x-1)*params.ChunkSize : x*params.ChunkSize]
  492. }
  493. ret, err := dao.AvApi.V1Pk.GetPkIdsByRoomIds(rpcCtx.WithTimeout(ctx, time.Duration(params.RPCTimeout)*time.Millisecond), &avV1.PkGetPkIdsByRoomIdsReq{RoomIds: chunkRoomIds, Platform: req.Platform})
  494. if err != nil {
  495. if err != nil {
  496. ret = &avV1.PkGetPkIdsByRoomIdsResp{}
  497. ret.Code = -1
  498. ret.Msg = "liveprc_error"
  499. }
  500. }
  501. erelongInfo, success := CheckReturn(err, ret.Code, ret.Msg, getPkIdsByRoomIds, params.RPCTimeout, params.ChunkSize, params.ChunkNum)
  502. if !success {
  503. if err != nil {
  504. err = errors.WithMessage(ecode.PkIDRecordFrameWorkCallError, "GET SEA PATROL FAIL")
  505. log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|error:%+v"+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s"+"|Params:%v",
  506. err, erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName, chunkRoomIds)
  507. } else {
  508. err = errors.WithMessage(ecode.PkIDLiveRPCCodeError, "GET SEA PATROL FAIL")
  509. log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|error:%+v"+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s"+"|Params:%v",
  510. err, erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName, chunkRoomIds)
  511. }
  512. return nil
  513. }
  514. if ret.Data == nil || len(ret.Data) <= 0 {
  515. erelongInfo.ErrType = emptyResultEn
  516. erelongInfo.ErrDesc = emptyResult
  517. // log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s"+"|Params:%v",
  518. // erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName, chunkRoomIds)
  519. return nil
  520. }
  521. chunkResult[x-1] = ret.Data
  522. return nil
  523. })
  524. }
  525. if err := wg.Wait(); err != nil {
  526. erelongInfo := ErrLogStrut{}
  527. erelongInfo.ErrType = "GoRoutingWaitError"
  528. erelongInfo.URLName = getPkIdsByRoomIds
  529. erelongInfo.ErrDesc = GoRoutingErr
  530. erelongInfo.Code = 1003001
  531. erelongInfo.RPCTimeout = params.RPCTimeout
  532. erelongInfo.ErrorPtr = &err
  533. log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|error:%+v"+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s",
  534. *erelongInfo.ErrorPtr, erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName)
  535. err = errors.WithMessage(ecode.PkIDFrameWorkGoRoutingError, "GET SEA PATROL FAIL")
  536. return nil, err
  537. }
  538. // 整理数据
  539. for _, chunkItemList := range chunkResult {
  540. for k, item := range chunkItemList {
  541. avResult[k] = item
  542. }
  543. }
  544. return
  545. }
  546. // GetFansMedal ...
  547. // 获取粉丝勋章佩戴信息
  548. func GetFansMedal(ctx context.Context, req *fansMedalV1.FansMedalTargetsWithMedalReq) (fansResult map[int64]bool, err error) {
  549. rpcChunkSize, RPCTimeout, err := GetChunkInfo(targetsWithMedal)
  550. params := ChunkCallInfo{ParamsName: "target_ids", URLName: targetsWithMedal, ChunkSize: rpcChunkSize, RPCTimeout: RPCTimeout}
  551. fansResult = make(map[int64]bool)
  552. lens := len(req.TargetIds)
  553. if lens <= 0 {
  554. return
  555. }
  556. // 批次
  557. params.ChunkNum = int64(math.Ceil(float64(lens) / float64(params.ChunkSize)))
  558. chunkResult := make([][]int64, params.ChunkNum)
  559. wg, _ := errgroup.WithContext(ctx)
  560. for i := int64(1); i <= params.ChunkNum; i++ {
  561. x := i
  562. wg.Go(func() error {
  563. chunkRoomIds := make([]int64, 20)
  564. if x == params.ChunkNum {
  565. chunkRoomIds = req.TargetIds[(x-1)*params.ChunkSize:]
  566. } else {
  567. chunkRoomIds = req.TargetIds[(x-1)*params.ChunkSize : x*params.ChunkSize]
  568. }
  569. ret, err := dao.FansMedalApi.V1FansMedal.TargetsWithMedal(rpcCtx.WithTimeout(ctx, time.Duration(params.RPCTimeout)*time.Millisecond), &fansMedalV1.FansMedalTargetsWithMedalReq{Uid: req.Uid, TargetIds: chunkRoomIds})
  570. if err != nil {
  571. if err != nil {
  572. ret = &fansMedalV1.FansMedalTargetsWithMedalResp{}
  573. ret.Code = -1
  574. ret.Msg = "liveprc_error"
  575. }
  576. }
  577. erelongInfo, success := CheckReturn(err, ret.Code, ret.Msg, targetsWithMedal, params.RPCTimeout, params.ChunkSize, params.ChunkNum)
  578. if !success {
  579. if err != nil {
  580. err = errors.WithMessage(ecode.PkIDRecordFrameWorkCallError, "GET SEA PATROL FAIL")
  581. log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|error:%+v"+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s"+"|Params:%v",
  582. err, erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName, chunkRoomIds)
  583. } else {
  584. err = errors.WithMessage(ecode.PkIDLiveRPCCodeError, "GET SEA PATROL FAIL")
  585. log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|error:%+v"+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s"+"|Params:%v",
  586. err, erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName, chunkRoomIds)
  587. }
  588. return nil
  589. }
  590. if ret.Data == nil || len(ret.Data) <= 0 {
  591. erelongInfo.ErrType = emptyResultEn
  592. erelongInfo.ErrDesc = emptyResult
  593. // log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s"+"|Params:%v",
  594. // erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName, chunkRoomIds)
  595. return nil
  596. }
  597. chunkResult[x-1] = ret.Data
  598. return nil
  599. })
  600. }
  601. if err := wg.Wait(); err != nil {
  602. erelongInfo := ErrLogStrut{}
  603. erelongInfo.ErrType = "GoRoutingWaitError"
  604. erelongInfo.URLName = targetsWithMedal
  605. erelongInfo.ErrDesc = GoRoutingErr
  606. erelongInfo.Code = 1003001
  607. erelongInfo.RPCTimeout = params.RPCTimeout
  608. erelongInfo.ErrorPtr = &err
  609. log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|error:%+v"+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s",
  610. *erelongInfo.ErrorPtr, erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName)
  611. err = errors.WithMessage(ecode.FansMedalFrameWorkGoRoutingError, "GET SEA PATROL FAIL")
  612. return nil, err
  613. }
  614. // 整理数据
  615. for _, chunkItemList := range chunkResult {
  616. for _, item := range chunkItemList {
  617. fansResult[item] = true
  618. }
  619. }
  620. return
  621. }
  622. // GetGrayRule ...
  623. // 获取灰度规则信息
  624. func GetGrayRule(ctx context.Context, req *userExV1.GrayRuleGetByMarkReq) (extResult *userExV1.GrayRuleGetByMarkResp_Data, err error) {
  625. extResult = &userExV1.GrayRuleGetByMarkResp_Data{}
  626. if req == nil {
  627. return nil, nil
  628. }
  629. ret, err := dao.UserExtApi.V1GrayRule.GetByMark(ctx, req)
  630. if err != nil {
  631. log.Error("call_userExt_grayRule error,err:%v", err)
  632. err = errors.WithMessage(ecode.GetGrayRuleError, "GET SEA PATROL FAIL")
  633. return
  634. }
  635. extResult = ret.Data
  636. return
  637. }
  638. // GetGiftInfo ...
  639. // 获取送礼信息
  640. func GetGiftInfo(ctx context.Context) (giftInfo map[int64]int64, err error) {
  641. _, RPCTimeout, _ := GetChunkInfo(relationGiftInfo)
  642. relationParams := &relationV1.BaseInfoGetGiftInfoReq{}
  643. giftInfo = make(map[int64]int64)
  644. ret, err := dao.RelationApi.V1BaseInfo.GetGiftInfo(ctx, relationParams)
  645. if err != nil {
  646. if err != nil {
  647. ret = &relationV1.BaseInfoGetGiftInfoResp{}
  648. ret.Code = -1
  649. ret.Msg = "liveprc_error"
  650. }
  651. }
  652. params := ChunkCallInfo{ParamsName: "", URLName: relationGiftInfo, ChunkSize: 1, RPCTimeout: RPCTimeout}
  653. erelongInfo, success := CheckReturn(err, ret.Code, ret.Msg, "gift", params.RPCTimeout, params.ChunkSize, params.ChunkNum)
  654. if !success {
  655. if err != nil {
  656. err = errors.WithMessage(ecode.PkIDRecordFrameWorkCallError, "GET SEA PATROL FAIL")
  657. log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|error:%+v"+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s",
  658. err, erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName)
  659. } else {
  660. err = errors.WithMessage(ecode.PkIDLiveRPCCodeError, "GET SEA PATROL FAIL")
  661. log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|error:%+v"+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s",
  662. err, erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName)
  663. }
  664. return giftInfo, nil
  665. }
  666. if ret.Data == nil || len(ret.Data) < 0 {
  667. erelongInfo.ErrType = emptyResultEn
  668. erelongInfo.ErrDesc = emptyResult
  669. // log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d",
  670. // erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName)
  671. return giftInfo, nil
  672. }
  673. for _, v := range ret.Data {
  674. giftInfo[v.Mid] = v.Gold
  675. }
  676. return
  677. }
  678. // GetChunkInfo ...
  679. // 获取分块信息
  680. func GetChunkInfo(rpcName string) (rpcChunkSize int64, RPCTimeout int64, err error) {
  681. rpcChunkSize = conf.GetChunkSize(rpcName, 20)
  682. RPCTimeout = conf.GetTimeout(rpcName, 100)
  683. return
  684. }