sv.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. package http
  2. import (
  3. "strconv"
  4. "strings"
  5. v1 "go-common/app/interface/bbq/app-bbq/api/http/v1"
  6. "go-common/app/interface/bbq/app-bbq/model"
  7. video "go-common/app/service/bbq/video/api/grpc/v1"
  8. "go-common/library/ecode"
  9. "go-common/library/log"
  10. bm "go-common/library/net/http/blademaster"
  11. "go-common/library/net/metadata"
  12. "github.com/pkg/errors"
  13. )
  14. // @params SvListReq
  15. // @router get /bbq/app-bbq/sv/list/
  16. // @response VideoResponse
  17. func svList(c *bm.Context) {
  18. b, _ := c.Get("BBQBase")
  19. mid, _ := c.Get("mid")
  20. arg := &v1.SvListReq{}
  21. if err := c.Bind(arg); err != nil {
  22. errors.Wrap(err, "参数验证失败")
  23. return
  24. }
  25. arg.Base = b.(*v1.Base)
  26. if mid != nil {
  27. arg.MID = mid.(int64)
  28. } else {
  29. arg.MID = 0
  30. }
  31. //获取deviceID
  32. deviceID := c.Request.Form.Get("device_id")
  33. log.Info("sv list Context [%+v]", c.Request.Header)
  34. log.Info("sv list Base [%+v]", arg.Base)
  35. arg.RemoteIP = metadata.String(c, metadata.RemoteIP)
  36. resp, err := srv.SvList(c, arg.PageSize, arg.MID, arg.Base, deviceID)
  37. c.JSON(resp, err)
  38. // 埋点
  39. if err != nil {
  40. return
  41. }
  42. var svidList []int64
  43. for _, v := range resp {
  44. svidList = append(svidList, v.SVID)
  45. }
  46. ext := struct {
  47. Svids []int64 `json:"svid_list"`
  48. }{
  49. Svids: svidList,
  50. }
  51. uiLog(c, model.ActionRecommend, ext)
  52. }
  53. func svDetail(c *bm.Context) {
  54. mid := int64(0)
  55. if res, ok := c.Get("mid"); ok {
  56. mid = res.(int64)
  57. }
  58. arg := &v1.SvDetailReq{}
  59. if err := c.Bind(arg); err != nil {
  60. errors.Wrap(err, "参数验证失败")
  61. return
  62. }
  63. c.JSON(srv.SvDetail(c, arg.SVID, mid))
  64. }
  65. //svStatistics 视频互动数据
  66. func svStatistics(c *bm.Context) {
  67. arg := new(model.ParamStatistic)
  68. if err := c.Bind(arg); err != nil {
  69. errors.Wrap(err, "参数验证失败")
  70. return
  71. }
  72. ids := strings.Split(arg.SVIDs, ",")
  73. if len(ids) == 0 {
  74. err := ecode.RequestErr
  75. errors.Wrap(err, "svid解析为空")
  76. return
  77. }
  78. var svids []int64
  79. for _, v := range ids {
  80. id, err := strconv.ParseInt(v, 10, 64)
  81. if err != nil {
  82. errors.Wrap(err, "svid解析错误")
  83. return
  84. }
  85. svids = append(svids, id)
  86. }
  87. var mid int64
  88. if res, ok := c.Get("mid"); ok {
  89. mid = res.(int64)
  90. }
  91. c.JSON(srv.SvStatistics(c, mid, svids))
  92. }
  93. func svPlayList(c *bm.Context) {
  94. dev, _ := c.Get("device")
  95. mid, _ := c.Get("mid")
  96. arg := &v1.PlayListReq{}
  97. if err := c.Bind(arg); err != nil {
  98. errors.Wrap(err, "参数验证失败")
  99. return
  100. }
  101. arg.Device = dev.(*bm.Device)
  102. if mid != nil {
  103. arg.MID = mid.(int64)
  104. } else {
  105. arg.MID = 0
  106. }
  107. arg.RemoteIP = metadata.String(c, metadata.RemoteIP)
  108. cidStr := strings.Split(arg.CIDs, ",")
  109. var cids []int64
  110. for _, v := range cidStr {
  111. cid, err := strconv.ParseInt(v, 10, 64)
  112. if err != nil {
  113. errors.Wrap(err, "cid解析错误")
  114. return
  115. }
  116. cids = append(cids, cid)
  117. }
  118. c.JSON(srv.SvCPlays(c, cids, arg.MID))
  119. }
  120. func svRelList(c *bm.Context) {
  121. b, _ := c.Get("BBQBase")
  122. mid, _ := c.Get("mid")
  123. arg := &v1.SvRelReq{}
  124. if err := c.Bind(arg); err != nil {
  125. errors.Wrap(err, "参数验证失败")
  126. return
  127. }
  128. base := b.(*v1.Base)
  129. if mid != nil {
  130. arg.MID = mid.(int64)
  131. } else {
  132. arg.MID = 0
  133. }
  134. arg.BUVID = base.BUVID
  135. arg.APP = base.App
  136. arg.APPVersion = base.Version
  137. arg.QueryID = base.QueryID
  138. arg.Limit = 15
  139. arg.Offset = 0
  140. c.JSON(srv.SvRelRec(c, arg))
  141. }
  142. func svDel(c *bm.Context) {
  143. arg := new(video.VideoDeleteRequest)
  144. if err := c.Bind(arg); err != nil {
  145. return
  146. }
  147. if mid, _ := c.Get("mid"); mid != nil {
  148. arg.UpMid = mid.(int64)
  149. } else {
  150. arg.UpMid = 0
  151. }
  152. c.JSON(srv.SvDel(c, arg))
  153. }