daowrapper.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  1. package v2
  2. import (
  3. "context"
  4. "math"
  5. "strconv"
  6. "github.com/pkg/errors"
  7. ServiceConf "go-common/app/interface/live/app-interface/conf"
  8. "go-common/app/interface/live/app-interface/dao"
  9. relationT "go-common/app/interface/live/app-interface/service/v1/relation"
  10. avV1 "go-common/app/service/live/av/api/liverpc/v1"
  11. fansMedalV1 "go-common/app/service/live/fans_medal/api/liverpc/v1"
  12. liveDataV1 "go-common/app/service/live/live_data/api/liverpc/v1"
  13. relationV1 "go-common/app/service/live/relation/api/liverpc/v1"
  14. roomV1 "go-common/app/service/live/room/api/liverpc/v1"
  15. roomV2 "go-common/app/service/live/room/api/liverpc/v2"
  16. roomExV1 "go-common/app/service/live/room_ex/api/liverpc/v1"
  17. userExV1 "go-common/app/service/live/userext/api/liverpc/v1"
  18. liveUserExpM "go-common/app/service/live/xuser/api/grpc/v1"
  19. accountM "go-common/app/service/main/account/model"
  20. "go-common/library/ecode"
  21. "go-common/library/log"
  22. "go-common/library/sync/errgroup"
  23. )
  24. // ChunkCallInfo ...
  25. // 日志结构体
  26. type ChunkCallInfo struct {
  27. ParamsName string
  28. URLName string
  29. ChunkSize int64
  30. ChunkNum int64
  31. RPCTimeout int64
  32. }
  33. const (
  34. // GoRoutingErr ...
  35. // 协程wait错误
  36. GoRoutingErr = "协程等待数据错误"
  37. )
  38. // UIDs2roomIDs ...
  39. // uid转换roomID,每批最大400
  40. func (s *IndexService) UIDs2roomIDs(ctx context.Context, UIDs []int64) (roomIDs map[int64]int64, err error) {
  41. rpcChunkSize, RPCTimeout, err := relationT.GetChunkInfo(ServiceConf.GetRoomID)
  42. params := ServiceConf.ChunkCallInfo{ParamsName: "uids", URLName: ServiceConf.GetRoomID, ChunkSize: rpcChunkSize, RPCTimeout: RPCTimeout}
  43. roomIDs = make(map[int64]int64)
  44. lens := len(UIDs)
  45. if lens <= 0 {
  46. return
  47. }
  48. // 批次
  49. params.ChunkNum = int64(math.Ceil(float64(lens) / float64(params.ChunkSize)))
  50. chunkResult := make([]map[string]string, params.ChunkNum)
  51. wg, _ := errgroup.WithContext(ctx)
  52. for i := int64(1); i <= params.ChunkNum; i++ {
  53. x := i
  54. wg.Go(func() error {
  55. chunkUfosIds := make([]int64, 20)
  56. if x == params.ChunkNum {
  57. chunkUfosIds = UIDs[(x-1)*params.ChunkSize:]
  58. } else {
  59. chunkUfosIds = UIDs[(x-1)*params.ChunkSize : x*params.ChunkSize]
  60. }
  61. ret, err := s.roomDao.UIDs2roomIDs(ctx, &roomV2.RoomRoomIdByUidMultiReq{Uids: chunkUfosIds}, params)
  62. if err != nil {
  63. return err
  64. }
  65. chunkResult[x-1] = ret.Data
  66. return nil
  67. })
  68. }
  69. if err := wg.Wait(); err != nil {
  70. erelongInfo := ServiceConf.ErrLogStrut{}
  71. erelongInfo.ErrType = "GoRoutingWaitError"
  72. erelongInfo.URLName = ServiceConf.GetRoomID
  73. erelongInfo.ErrDesc = GoRoutingErr
  74. erelongInfo.Code = 1003001
  75. erelongInfo.RPCTimeout = params.RPCTimeout
  76. erelongInfo.ErrorPtr = &err
  77. log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|error:%+v"+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s",
  78. *erelongInfo.ErrorPtr, erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName)
  79. err = errors.WithMessage(ecode.RelationFrameWorkGoRoutingError, "GET SEA PATROL FAIL")
  80. return nil, err
  81. }
  82. // 整理数据
  83. for _, chunkItemList := range chunkResult {
  84. for k, item := range chunkItemList {
  85. if item != "" {
  86. Index := RParseInt(k, 1)
  87. itemInt := RParseInt(item, 1)
  88. roomIDs[Index] = itemInt
  89. }
  90. }
  91. }
  92. return
  93. }
  94. // GetRoomInfo ...
  95. // 获取room信息
  96. func (s *IndexService) GetRoomInfo(ctx context.Context, input *roomV1.RoomGetStatusInfoByUidsReq) (roomResult map[int64]*roomV1.RoomGetStatusInfoByUidsResp_RoomInfo, err error) {
  97. rpcChunkSize, RPCTimeout, err := relationT.GetChunkInfo(ServiceConf.GetStatusInfoByUfos)
  98. params := ServiceConf.ChunkCallInfo{ParamsName: "uids", URLName: ServiceConf.GetStatusInfoByUfos, ChunkSize: rpcChunkSize, RPCTimeout: RPCTimeout}
  99. roomResult = make(map[int64]*roomV1.RoomGetStatusInfoByUidsResp_RoomInfo)
  100. lens := len(input.Uids)
  101. if lens <= 0 {
  102. return
  103. }
  104. // 批次
  105. params.ChunkNum = int64(math.Ceil(float64(lens) / float64(params.ChunkSize)))
  106. chunkResult := make([]map[int64]*roomV1.RoomGetStatusInfoByUidsResp_RoomInfo, params.ChunkNum)
  107. wg, _ := errgroup.WithContext(ctx)
  108. for i := int64(1); i <= params.ChunkNum; i++ {
  109. x := i
  110. wg.Go(func() error {
  111. chunkUfosIds := make([]int64, 20)
  112. if x == params.ChunkNum {
  113. chunkUfosIds = input.Uids[(x-1)*params.ChunkSize:]
  114. } else {
  115. chunkUfosIds = input.Uids[(x-1)*params.ChunkSize : x*params.ChunkSize]
  116. }
  117. ret, err := s.roomDao.GetRoomInfo(ctx, &roomV1.RoomGetStatusInfoByUidsReq{Uids: chunkUfosIds, FilterOffline: input.FilterOffline, NeedBroadcastType: input.NeedBroadcastType}, params)
  118. if err != nil {
  119. return err
  120. }
  121. chunkResult[x-1] = ret.Data
  122. return nil
  123. })
  124. }
  125. if err := wg.Wait(); err != nil {
  126. erelongInfo := ServiceConf.ErrLogStrut{}
  127. erelongInfo.ErrType = "GoRoutingWaitError"
  128. erelongInfo.URLName = ServiceConf.GetStatusInfoByUfos
  129. erelongInfo.ErrDesc = GoRoutingErr
  130. erelongInfo.Code = 1003001
  131. erelongInfo.RPCTimeout = params.RPCTimeout
  132. erelongInfo.ErrorPtr = &err
  133. log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|error:%+v"+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s",
  134. *erelongInfo.ErrorPtr, erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName)
  135. err = errors.WithMessage(ecode.RoomFrameWorkGoRoutingError, "GET SEA PATROL FAIL")
  136. return nil, err
  137. }
  138. // 整理数据
  139. for _, chunkItemList := range chunkResult {
  140. for _, item := range chunkItemList {
  141. if item != nil {
  142. roomResult[item.Uid] = item
  143. }
  144. }
  145. }
  146. return
  147. }
  148. // GetLastLiveTime ...
  149. // 获取Record信息
  150. func (s *IndexService) GetLastLiveTime(ctx context.Context, rolaids []int64) (resp map[string]string, err error) {
  151. rpcChunkSize, RPCTimeout, err := relationT.GetChunkInfo(ServiceConf.Record)
  152. params := ServiceConf.ChunkCallInfo{ParamsName: "uids", URLName: ServiceConf.Record, ChunkSize: rpcChunkSize, RPCTimeout: RPCTimeout}
  153. resp = make(map[string]string)
  154. lens := len(rolaids)
  155. if lens <= 0 {
  156. return
  157. }
  158. // 批次
  159. params.ChunkNum = int64(math.Ceil(float64(lens) / float64(params.ChunkSize)))
  160. chunkResult := make([]map[string]*liveDataV1.RecordGetResp_TimeInfo, params.ChunkNum)
  161. wg, _ := errgroup.WithContext(ctx)
  162. for i := int64(1); i <= params.ChunkNum; i++ {
  163. x := i
  164. wg.Go(func() error {
  165. chunkRoomIds := make([]int64, 20)
  166. if x == params.ChunkNum {
  167. chunkRoomIds = rolaids[(x-1)*params.ChunkSize:]
  168. } else {
  169. chunkRoomIds = rolaids[(x-1)*params.ChunkSize : x*params.ChunkSize]
  170. }
  171. ret, err := s.livedataDao.GetLastLiveTime(ctx, &liveDataV1.RecordGetReq{Roomids: chunkRoomIds}, params)
  172. if err != nil {
  173. return err
  174. }
  175. chunkResult[x-1] = ret
  176. return nil
  177. })
  178. }
  179. if err := wg.Wait(); err != nil {
  180. erelongInfo := ServiceConf.ErrLogStrut{}
  181. erelongInfo.ErrType = "GoRoutingWaitError"
  182. erelongInfo.URLName = ServiceConf.Record
  183. erelongInfo.ErrDesc = GoRoutingErr
  184. erelongInfo.Code = 1003001
  185. erelongInfo.RPCTimeout = params.RPCTimeout
  186. erelongInfo.ErrorPtr = &err
  187. log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|error:%+v"+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s",
  188. *erelongInfo.ErrorPtr, erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName)
  189. err = errors.WithMessage(ecode.RecordFrameWorkGoRoutingError, "GET SEA PATROL FAIL")
  190. return nil, err
  191. }
  192. // 整理数据
  193. for _, chunkItemList := range chunkResult {
  194. for k, item := range chunkItemList {
  195. if item != nil {
  196. resp[k] = item.RecentEndTime
  197. }
  198. }
  199. }
  200. return
  201. }
  202. // GetRoomNewsInfo ...
  203. // 获取公告信息
  204. func (s *IndexService) GetRoomNewsInfo(ctx context.Context, rolaids *roomExV1.RoomNewsMultiGetReq) (roomNewsResult map[int64]*roomExV1.RoomNewsMultiGetResp_Data, err error) {
  205. rpcChunkSize, RPCTimeout, err := relationT.GetChunkInfo(ServiceConf.RoomNews)
  206. params := ServiceConf.ChunkCallInfo{ParamsName: "roomids", URLName: ServiceConf.RoomNews, ChunkSize: rpcChunkSize, RPCTimeout: RPCTimeout}
  207. roomNewsResult = make(map[int64]*roomExV1.RoomNewsMultiGetResp_Data)
  208. lens := len(rolaids.RoomIds)
  209. if lens <= 0 {
  210. return
  211. }
  212. // 批次
  213. params.ChunkNum = int64(math.Ceil(float64(lens) / float64(params.ChunkSize)))
  214. chunkResult := make([][]*roomExV1.RoomNewsMultiGetResp_Data, params.ChunkNum)
  215. wg, _ := errgroup.WithContext(ctx)
  216. for i := int64(1); i <= params.ChunkNum; i++ {
  217. x := i
  218. wg.Go(func() error {
  219. chunkRoomIds := make([]int64, 20)
  220. if x == params.ChunkNum {
  221. chunkRoomIds = rolaids.RoomIds[(x-1)*params.ChunkSize:]
  222. } else {
  223. chunkRoomIds = rolaids.RoomIds[(x-1)*params.ChunkSize : x*params.ChunkSize]
  224. }
  225. ret, err := s.roomexDao.GetRoomNewsInfo(ctx, &roomExV1.RoomNewsMultiGetReq{RoomIds: chunkRoomIds, IsDecoded: rolaids.IsDecoded}, params)
  226. if err != nil {
  227. return err
  228. }
  229. chunkResult[x-1] = ret.Data
  230. return nil
  231. })
  232. }
  233. if err := wg.Wait(); err != nil {
  234. erelongInfo := ServiceConf.ErrLogStrut{}
  235. erelongInfo.ErrType = "GoRoutingWaitError"
  236. erelongInfo.URLName = ServiceConf.RoomNews
  237. erelongInfo.ErrDesc = GoRoutingErr
  238. erelongInfo.Code = 1003001
  239. erelongInfo.RPCTimeout = params.RPCTimeout
  240. erelongInfo.ErrorPtr = &err
  241. log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|error:%+v"+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s",
  242. *erelongInfo.ErrorPtr, erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName)
  243. err = errors.WithMessage(ecode.RoomNewsFrameWorkGoRoutingError, "GET SEA PATROL FAIL")
  244. return nil, err
  245. }
  246. // 整理数据
  247. for _, chunkItemList := range chunkResult {
  248. for _, item := range chunkItemList {
  249. if item != nil {
  250. if mid, err := strconv.ParseInt(item.Roomid, 10, 64); err == nil {
  251. roomNewsResult[mid] = item
  252. }
  253. }
  254. }
  255. }
  256. return
  257. }
  258. // GetRoomPendantInfo ...
  259. // 获取角标信息
  260. func (s *IndexService) GetRoomPendantInfo(ctx context.Context, req *roomV1.RoomPendantGetPendantByIdsReq) (roomNewsResult map[int64]*roomV1.RoomPendantGetPendantByIdsResp_Result, err error) {
  261. rpcChunkSize, RPCTimeout, err := relationT.GetChunkInfo(ServiceConf.RoomPendent)
  262. params := ServiceConf.ChunkCallInfo{ParamsName: "ids", URLName: ServiceConf.RoomPendent, ChunkSize: rpcChunkSize, RPCTimeout: RPCTimeout}
  263. roomNewsResult = make(map[int64]*roomV1.RoomPendantGetPendantByIdsResp_Result)
  264. lens := len(req.Ids)
  265. if lens <= 0 {
  266. return
  267. }
  268. // 批次
  269. params.ChunkNum = int64(math.Ceil(float64(lens) / float64(params.ChunkSize)))
  270. chunkResult := make([]map[int64]*roomV1.RoomPendantGetPendantByIdsResp_Result, params.ChunkNum)
  271. wg, _ := errgroup.WithContext(ctx)
  272. for i := int64(1); i <= params.ChunkNum; i++ {
  273. x := i
  274. wg.Go(func() error {
  275. chunkRoomIds := make([]int64, 20)
  276. if x == params.ChunkNum {
  277. chunkRoomIds = req.Ids[(x-1)*params.ChunkSize:]
  278. } else {
  279. chunkRoomIds = req.Ids[(x-1)*params.ChunkSize : x*params.ChunkSize]
  280. }
  281. ret, err := s.roomDao.GetRoomPendantInfo(ctx, &roomV1.RoomPendantGetPendantByIdsReq{Ids: chunkRoomIds, Type: req.Type, Position: req.Position}, params)
  282. if err != nil || ret == nil {
  283. return err
  284. }
  285. chunkResult[x-1] = ret.Data.Result
  286. return nil
  287. })
  288. }
  289. if err := wg.Wait(); err != nil {
  290. erelongInfo := ServiceConf.ErrLogStrut{}
  291. erelongInfo.ErrType = "GoRoutingWaitError"
  292. erelongInfo.URLName = ServiceConf.RoomPendent
  293. erelongInfo.ErrDesc = GoRoutingErr
  294. erelongInfo.Code = 1003001
  295. erelongInfo.RPCTimeout = params.RPCTimeout
  296. erelongInfo.ErrorPtr = &err
  297. log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|error:%+v"+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s",
  298. *erelongInfo.ErrorPtr, erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName)
  299. err = errors.WithMessage(ecode.RoomPendentFrameWorkGoRoutingError, "GET SEA PATROL FAIL")
  300. return nil, err
  301. }
  302. // 整理数据
  303. for _, chunkItemList := range chunkResult {
  304. for k, item := range chunkItemList {
  305. if item != nil {
  306. roomNewsResult[k] = item
  307. }
  308. }
  309. }
  310. return
  311. }
  312. // GetPkID ...
  313. // 获取PkId信息
  314. func (s *IndexService) GetPkID(ctx context.Context, req *avV1.PkGetPkIdsByRoomIdsReq) (avResult map[string]int64, err error) {
  315. rpcChunkSize, RPCTimeout, err := relationT.GetChunkInfo(ServiceConf.GetPkIdsByRoomIds)
  316. params := ServiceConf.ChunkCallInfo{ParamsName: "ids", URLName: ServiceConf.GetPkIdsByRoomIds, ChunkSize: rpcChunkSize, RPCTimeout: RPCTimeout}
  317. avResult = make(map[string]int64)
  318. lens := len(req.RoomIds)
  319. if lens <= 0 {
  320. return
  321. }
  322. // 批次
  323. params.ChunkNum = int64(math.Ceil(float64(lens) / float64(params.ChunkSize)))
  324. chunkResult := make([]map[string]int64, params.ChunkNum)
  325. wg, _ := errgroup.WithContext(ctx)
  326. for i := int64(1); i <= params.ChunkNum; i++ {
  327. x := i
  328. wg.Go(func() error {
  329. chunkRoomIds := make([]int64, 20)
  330. if x == params.ChunkNum {
  331. chunkRoomIds = req.RoomIds[(x-1)*params.ChunkSize:]
  332. } else {
  333. chunkRoomIds = req.RoomIds[(x-1)*params.ChunkSize : x*params.ChunkSize]
  334. }
  335. ret, err := s.avDao.GetPkID(ctx, &avV1.PkGetPkIdsByRoomIdsReq{RoomIds: chunkRoomIds, Platform: req.Platform}, params)
  336. if err != nil {
  337. return err
  338. }
  339. chunkResult[x-1] = ret.Data
  340. return nil
  341. })
  342. }
  343. if err := wg.Wait(); err != nil {
  344. erelongInfo := ServiceConf.ErrLogStrut{}
  345. erelongInfo.ErrType = "GoRoutingWaitError"
  346. erelongInfo.URLName = ServiceConf.GetPkIdsByRoomIds
  347. erelongInfo.ErrDesc = GoRoutingErr
  348. erelongInfo.Code = 1003001
  349. erelongInfo.RPCTimeout = params.RPCTimeout
  350. erelongInfo.ErrorPtr = &err
  351. log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|error:%+v"+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s",
  352. *erelongInfo.ErrorPtr, erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName)
  353. err = errors.WithMessage(ecode.PkIDFrameWorkGoRoutingError, "GET SEA PATROL FAIL")
  354. return nil, err
  355. }
  356. // 整理数据
  357. for _, chunkItemList := range chunkResult {
  358. for k, item := range chunkItemList {
  359. avResult[k] = item
  360. }
  361. }
  362. return
  363. }
  364. // GetFansMedal ...
  365. // 获取粉丝勋章佩戴信息
  366. func (s *IndexService) GetFansMedal(ctx context.Context, req *fansMedalV1.FansMedalTargetsWithMedalReq) (fansResult map[int64]bool, err error) {
  367. rpcChunkSize, RPCTimeout, err := relationT.GetChunkInfo(ServiceConf.TargetsWithMedal)
  368. params := ServiceConf.ChunkCallInfo{ParamsName: "ids", URLName: ServiceConf.TargetsWithMedal, ChunkSize: rpcChunkSize, RPCTimeout: RPCTimeout}
  369. fansResult = make(map[int64]bool)
  370. lens := len(req.TargetIds)
  371. if lens <= 0 {
  372. return
  373. }
  374. // 批次
  375. params.ChunkNum = int64(math.Ceil(float64(lens) / float64(params.ChunkSize)))
  376. chunkResult := make([][]int64, params.ChunkNum)
  377. wg, _ := errgroup.WithContext(ctx)
  378. for i := int64(1); i <= params.ChunkNum; i++ {
  379. x := i
  380. wg.Go(func() error {
  381. chunkRoomIds := make([]int64, 20)
  382. if x == params.ChunkNum {
  383. chunkRoomIds = req.TargetIds[(x-1)*params.ChunkSize:]
  384. } else {
  385. chunkRoomIds = req.TargetIds[(x-1)*params.ChunkSize : x*params.ChunkSize]
  386. }
  387. ret, err := s.fansMedalDao.GetFansMedal(ctx, &fansMedalV1.FansMedalTargetsWithMedalReq{Uid: req.Uid, TargetIds: chunkRoomIds}, params)
  388. if err != nil {
  389. return err
  390. }
  391. chunkResult[x-1] = ret.Data
  392. return nil
  393. })
  394. }
  395. if err := wg.Wait(); err != nil {
  396. erelongInfo := ServiceConf.ErrLogStrut{}
  397. erelongInfo.ErrType = "GoRoutingWaitError"
  398. erelongInfo.URLName = ServiceConf.TargetsWithMedal
  399. erelongInfo.ErrDesc = GoRoutingErr
  400. erelongInfo.Code = 1003001
  401. erelongInfo.RPCTimeout = params.RPCTimeout
  402. erelongInfo.ErrorPtr = &err
  403. log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|error:%+v"+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s",
  404. *erelongInfo.ErrorPtr, erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName)
  405. err = errors.WithMessage(ecode.FansMedalFrameWorkGoRoutingError, "GET SEA PATROL FAIL")
  406. return nil, err
  407. }
  408. // 整理数据
  409. for _, chunkItemList := range chunkResult {
  410. for _, item := range chunkItemList {
  411. fansResult[item] = true
  412. }
  413. }
  414. return
  415. }
  416. // GetGrayRule ...
  417. // 获取灰度规则信息
  418. func (s *IndexService) GetGrayRule(ctx context.Context, req *userExV1.GrayRuleGetByMarkReq) (extResult *userExV1.GrayRuleGetByMarkResp_Data, err error) {
  419. extResult = &userExV1.GrayRuleGetByMarkResp_Data{}
  420. if req == nil {
  421. return nil, nil
  422. }
  423. ret, err := s.userextDao.GetGrayRule(ctx, req)
  424. if err != nil {
  425. log.Error("call_userExt_grayRule error,err:%v", err)
  426. err = errors.WithMessage(ecode.GetGrayRuleError, "GET SEA PATROL FAIL")
  427. return
  428. }
  429. extResult = ret.Data
  430. return
  431. }
  432. // GetGiftInfo ...
  433. // 获取送礼信息
  434. func GetGiftInfo(ctx context.Context) (giftInfo map[int64]int64, err error) {
  435. relationParams := &relationV1.BaseInfoGetGiftInfoReq{}
  436. giftInfo = make(map[int64]int64)
  437. ret, err := dao.RelationApi.V1BaseInfo.GetGiftInfo(ctx, relationParams)
  438. for _, v := range ret.Data {
  439. giftInfo[v.Mid] = v.Gold
  440. }
  441. return
  442. }
  443. // GetUserInfo 获取用户信息
  444. func (s *IndexService) GetUserInfo(ctx context.Context, UIDs []int64) (userResult map[int64]*accountM.Card, err error) {
  445. rpcChunkSize, RPCTimeout, err := relationT.GetChunkInfo(ServiceConf.AccountGRPC)
  446. params := ServiceConf.ChunkCallInfo{ParamsName: "uids", URLName: ServiceConf.AccountGRPC, ChunkSize: rpcChunkSize, RPCTimeout: RPCTimeout}
  447. userResult = make(map[int64]*accountM.Card)
  448. lens := len(UIDs)
  449. if lens <= 0 {
  450. return
  451. }
  452. // 批次
  453. params.ChunkNum = int64(math.Ceil(float64(lens) / float64(params.ChunkSize)))
  454. chunkResult := make([]map[int64]*accountM.Card, params.ChunkNum)
  455. wg, _ := errgroup.WithContext(ctx)
  456. for i := int64(1); i <= params.ChunkNum; i++ {
  457. x := i
  458. wg.Go(func() error {
  459. chunkUfosIds := make([]int64, 20)
  460. if x == params.ChunkNum {
  461. chunkUfosIds = UIDs[(x-1)*params.ChunkSize:]
  462. } else {
  463. chunkUfosIds = UIDs[(x-1)*params.ChunkSize : x*params.ChunkSize]
  464. }
  465. ret, err := s.accountDao.GetUserInfoData(ctx, chunkUfosIds)
  466. if err != nil {
  467. err = errors.WithMessage(ecode.AccountGRPCError, "GET SEA PATROL FAIL")
  468. log.Error("Call main.Account.Cards Error.Infos(%+v) error(%+v)", chunkUfosIds, err)
  469. return nil
  470. }
  471. chunkResult[x-1] = ret
  472. return nil
  473. })
  474. }
  475. if err := wg.Wait(); err != nil {
  476. erelongInfo := relationT.ErrLogStrut{}
  477. erelongInfo.ErrType = "GoRoutingWaitError"
  478. erelongInfo.URLName = relationT.AccountGRPC
  479. erelongInfo.ErrDesc = relationT.GoRoutingErr
  480. erelongInfo.Code = 1003001
  481. erelongInfo.RPCTimeout = params.RPCTimeout
  482. erelongInfo.ErrorPtr = &err
  483. log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|error:%+v"+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s",
  484. *erelongInfo.ErrorPtr, erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName)
  485. err = errors.WithMessage(ecode.AccountGRPCFrameError, "GET SEA PATROL FAIL")
  486. return nil, err
  487. }
  488. for _, chunkItemList := range chunkResult {
  489. for _, item := range chunkItemList {
  490. if item != nil {
  491. userResult[item.Mid] = item
  492. }
  493. }
  494. }
  495. return
  496. }
  497. // GetLiveUserExp 获取用户经验信息
  498. func (s *IndexService) GetLiveUserExp(ctx context.Context, UIDs []int64) (userResult map[int64]*liveUserExpM.LevelInfo, err error) {
  499. rpcChunkSize, RPCTimeout, err := relationT.GetChunkInfo(ServiceConf.LiveUserExpGRPC)
  500. params := ServiceConf.ChunkCallInfo{ParamsName: "uids", URLName: ServiceConf.LiveUserExpGRPC, ChunkSize: rpcChunkSize, RPCTimeout: RPCTimeout}
  501. userResult = make(map[int64]*liveUserExpM.LevelInfo)
  502. lens := len(UIDs)
  503. if lens <= 0 {
  504. return
  505. }
  506. // 批次
  507. params.ChunkNum = int64(math.Ceil(float64(lens) / float64(params.ChunkSize)))
  508. chunkResult := make([]map[int64]*liveUserExpM.LevelInfo, params.ChunkNum)
  509. wg, _ := errgroup.WithContext(ctx)
  510. for i := int64(1); i <= params.ChunkNum; i++ {
  511. x := i
  512. wg.Go(func() error {
  513. chunkUfosIds := make([]int64, 20)
  514. if x == params.ChunkNum {
  515. chunkUfosIds = UIDs[(x-1)*params.ChunkSize:]
  516. } else {
  517. chunkUfosIds = UIDs[(x-1)*params.ChunkSize : x*params.ChunkSize]
  518. }
  519. ret, err := s.xuserDao.GetUserExpData(ctx, chunkUfosIds)
  520. if err != nil {
  521. err = errors.WithMessage(ecode.AccountGRPCError, "GET SEA PATROL FAIL")
  522. log.Error("Call main.Account.Cards Error.Infos(%+v) error(%+v)", chunkUfosIds, err)
  523. return nil
  524. }
  525. chunkResult[x-1] = ret
  526. return nil
  527. })
  528. }
  529. if err := wg.Wait(); err != nil {
  530. erelongInfo := relationT.ErrLogStrut{}
  531. erelongInfo.ErrType = "GoRoutingWaitError"
  532. erelongInfo.URLName = relationT.LiveUserExpGRPC
  533. erelongInfo.ErrDesc = relationT.GoRoutingErr
  534. erelongInfo.Code = 1003001
  535. erelongInfo.RPCTimeout = params.RPCTimeout
  536. erelongInfo.ErrorPtr = &err
  537. log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|error:%+v"+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s",
  538. *erelongInfo.ErrorPtr, erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName)
  539. err = errors.WithMessage(ecode.AccountGRPCFrameError, "GET SEA PATROL FAIL")
  540. return nil, err
  541. }
  542. for _, chunkItemList := range chunkResult {
  543. for _, item := range chunkItemList {
  544. if item != nil {
  545. userResult[item.Uid] = item
  546. }
  547. }
  548. }
  549. return
  550. }