rpc3.go 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. package server
  2. import (
  3. "go-common/app/service/main/archive/api"
  4. "go-common/app/service/main/archive/model/archive"
  5. "go-common/library/log"
  6. "go-common/library/net/rpc/context"
  7. )
  8. // 3结尾的方法全都是pb格式的memcache
  9. // MaxAID get max aid
  10. func (r *RPC) MaxAID(c context.Context, a *struct{}, res *int64) (err error) {
  11. *res, err = r.s.MaxAID(c)
  12. return
  13. }
  14. // Archive3 receive aid, then init archive info.
  15. func (r *RPC) Archive3(c context.Context, a *archive.ArgAid2, res *api.Arc) (err error) {
  16. var ar *api.Arc
  17. if ar, err = r.s.Archive3(c, a.Aid); err == nil {
  18. *res = *ar
  19. }
  20. return
  21. }
  22. // Archives3 receive aids, then init archives info.
  23. func (r *RPC) Archives3(c context.Context, a *archive.ArgAids2, res *map[int64]*api.Arc) (err error) {
  24. if len(a.Aids) > 300 {
  25. log.Error("Too many Args aids(%d) caller(%s) arg(%v)", len(a.Aids), c.User(), a.Aids)
  26. }
  27. *res, err = r.s.Archives3(c, a.Aids)
  28. return
  29. }
  30. // View3 view archive.
  31. func (r *RPC) View3(c context.Context, a *archive.ArgAid2, av *archive.View3) (err error) {
  32. var res *api.ViewReply
  33. if res, err = r.s.View3(c, a.Aid); err == nil {
  34. *av = *archive.BuildView3(res.Arc, res.Pages)
  35. }
  36. return
  37. }
  38. // Views3 view archive.
  39. func (r *RPC) Views3(c context.Context, a *archive.ArgAids2, res *map[int64]*archive.View3) (err error) {
  40. if len(a.Aids) > 300 {
  41. log.Error("Too many Args aids(%d) caller(%s)", len(a.Aids), c.User())
  42. }
  43. var views map[int64]*api.ViewReply
  44. if views, err = r.s.Views3(c, a.Aids); err == nil {
  45. var resp = make(map[int64]*archive.View3)
  46. for aid, view := range views {
  47. v := archive.BuildView3(view.Arc, view.Pages)
  48. if v != nil {
  49. resp[aid] = v
  50. }
  51. }
  52. *res = resp
  53. }
  54. return
  55. }
  56. // Stat3 archive stat.
  57. func (r *RPC) Stat3(c context.Context, a *archive.ArgAid2, res *api.Stat) (err error) {
  58. var st *api.Stat
  59. if st, err = r.s.Stat3(c, a.Aid); err == nil {
  60. *res = *st
  61. }
  62. return
  63. }
  64. // Page3 get videos by aid
  65. func (r *RPC) Page3(c context.Context, a *archive.ArgAid2, res *[]*api.Page) (err error) {
  66. *res, err = r.s.Page3(c, a.Aid)
  67. return
  68. }
  69. // Stats3 archive stats.
  70. func (r *RPC) Stats3(c context.Context, a *archive.ArgAids2, res *map[int64]*api.Stat) (err error) {
  71. if len(a.Aids) > 200 {
  72. log.Error("Too many Args aids(%d) caller(%s)", len(a.Aids), c.User())
  73. log.Error("Too many Args aids(%d) caller(%s) arg(%v)", len(a.Aids), c.User(), a.Aids)
  74. }
  75. *res, err = r.s.Stats3(c, a.Aids)
  76. return
  77. }
  78. // Click3 archive click.
  79. func (r *RPC) Click3(c context.Context, a *archive.ArgAid2, res *api.Click) (err error) {
  80. var clk *api.Click
  81. if clk, err = r.s.Click3(c, a.Aid); err == nil {
  82. *res = *clk
  83. }
  84. return
  85. }
  86. // UpArcs3 up archives.
  87. func (r *RPC) UpArcs3(c context.Context, a *archive.ArgUpArcs2, res *[]*api.Arc) (err error) {
  88. *res, err = r.s.UpperPassed3(c, a.Mid, a.Pn, a.Ps)
  89. return
  90. }
  91. // UpsArcs3 ups archives.
  92. func (r *RPC) UpsArcs3(c context.Context, a *archive.ArgUpsArcs2, res *map[int64][]*api.Arc) (err error) {
  93. *res, err = r.s.UppersPassed3(c, a.Mids, a.Pn, a.Ps)
  94. return
  95. }
  96. // Recommend3 from archive_recommend by aid
  97. func (r *RPC) Recommend3(c context.Context, a *archive.ArgAid2, res *[]*api.Arc) (err error) {
  98. *res, err = r.s.UpperReommend(c, a.Aid)
  99. return
  100. }
  101. // RankArcs3 Arcs by rid
  102. func (r *RPC) RankArcs3(c context.Context, a *archive.ArgRank2, res *archive.RankArchives3) (err error) {
  103. if a.Type == 0 {
  104. res.Archives, res.Count, err = r.s.RegionArcs3(c, a.Rid, a.Pn, a.Ps)
  105. } else {
  106. res.Archives, res.Count, err = r.s.RegionOriginArcs3(c, a.Rid, a.Pn, a.Ps)
  107. }
  108. return
  109. }
  110. // ArchivesWithPlayer archives with player info
  111. func (r *RPC) ArchivesWithPlayer(c context.Context, a *archive.ArgPlayer, res *map[int64]*archive.ArchiveWithPlayer) (err error) {
  112. var as map[int64]*archive.ArchiveWithPlayer
  113. if as, err = r.s.ArchivesWithPlayer(c, a, false); err != nil {
  114. return
  115. }
  116. *res = as
  117. return
  118. }
  119. // RanksArcs3 Arcs by rids
  120. func (r *RPC) RanksArcs3(c context.Context, a *archive.ArgRanks2, res *map[int16]*archive.RankArchives3) (err error) {
  121. var (
  122. as []*api.Arc
  123. tmp map[int16]*archive.RankArchives3
  124. count int
  125. )
  126. tmp = make(map[int16]*archive.RankArchives3)
  127. for _, rid := range a.Rids {
  128. if a.Type == 0 {
  129. as, count, err = r.s.RegionArcs3(c, rid, a.Pn, a.Ps)
  130. } else {
  131. as, count, err = r.s.RegionOriginArcs3(c, rid, a.Pn, a.Ps)
  132. }
  133. if err != nil {
  134. return
  135. }
  136. tmp[rid] = &archive.RankArchives3{Archives: as, Count: count}
  137. }
  138. *res = tmp
  139. return
  140. }
  141. // RankTopArcs3 Arcs by reids
  142. func (r *RPC) RankTopArcs3(c context.Context, a *archive.ArgRankTop2, res *[]*api.Arc) (err error) {
  143. *res, err = r.s.RegionTopArcs3(c, a.ReID, a.Pn, a.Ps)
  144. return
  145. }
  146. // RankAllArcs3 left 7 days all Arcs
  147. func (r *RPC) RankAllArcs3(c context.Context, a *archive.ArgRankAll2, res *archive.RankArchives3) (err error) {
  148. var data *archive.RankArchives3
  149. data, err = r.s.RegionAllArcs3(c, a.Pn, a.Ps)
  150. if err == nil {
  151. *res = *data
  152. }
  153. return
  154. }
  155. // Video3 get video by aid & cid.
  156. func (r *RPC) Video3(c context.Context, a *archive.ArgVideo2, res *api.Page) (err error) {
  157. var p *api.Page
  158. p, err = r.s.Video3(c, a.Aid, a.Cid)
  159. if err == nil {
  160. *res = *p
  161. }
  162. return
  163. }