video.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. package community
  2. import (
  3. "fmt"
  4. "github.com/gin-gonic/gin"
  5. "hongze/hongze_yb/controller/response"
  6. "hongze/hongze_yb/models/request"
  7. responseModel "hongze/hongze_yb/models/response"
  8. "hongze/hongze_yb/services/bullet_chat"
  9. "hongze/hongze_yb/services/community"
  10. "hongze/hongze_yb/services/user"
  11. "hongze/hongze_yb/utils"
  12. )
  13. // VideoList 视频列表
  14. // @Tags 视频社区模块
  15. // @Description 获取视频社区列表
  16. // @Param page_index query int false "页码"
  17. // @Param page_size query int false "每页数量"
  18. // @Param keywords query string false "只看我的"
  19. // @Param video_id query int false "视频ID"
  20. // @Param variety_tag_id query int false "标签ID"
  21. // @Success 200 {object}
  22. // @failure 400 {string} string "获取失败"
  23. // @Router /video/list [get]
  24. func VideoList(c *gin.Context) {
  25. var req request.VideoListReq
  26. if err := c.Bind(&req); err != nil {
  27. response.Fail("参数有误", c)
  28. return
  29. }
  30. if req.PageIndex == 0 {
  31. req.PageIndex = 1
  32. }
  33. if req.PageSize == 0 {
  34. req.PageSize = utils.PageSize20
  35. }
  36. userInfo := user.GetInfoByClaims(c)
  37. list, err := community.GetVideoList(int(userInfo.UserID), req.PageIndex, req.PageSize, req.VideoId, req.VarietyTagId, req.Keywords)
  38. if err != nil {
  39. response.FailMsg("获取失败", "VideoList ErrMsg:"+err.Error(), c)
  40. return
  41. }
  42. idsArr := make([]int, 0)
  43. for i := range list {
  44. idsArr = append(idsArr, list[i].CommunityVideoID)
  45. }
  46. // 点赞/吐槽数据
  47. err = community.HandleLikeOrTeaseByCommunityVideoItemList(userInfo.UserID, list)
  48. if err != nil {
  49. response.FailMsg("获取失败", "QuestionList ErrMsg:"+err.Error(), c)
  50. return
  51. }
  52. // 评论数据
  53. err = community.HandleCommentByCommunityVideoItemList(list)
  54. if err != nil {
  55. response.FailMsg("获取失败", "QuestionList ErrMsg:"+err.Error(), c)
  56. return
  57. }
  58. // 弹幕数据
  59. idBulletsMap, e := bullet_chat.GetListMapBySourceAndIds(bullet_chat.SourceBulletChatVideo, idsArr)
  60. if e != nil {
  61. response.FailMsg("获取失败", "获取视频社区弹幕列表Map失败, Err: "+e.Error(), c)
  62. return
  63. }
  64. for i := range list {
  65. ls := make([]*responseModel.BulletChatItem, 0)
  66. bs := idBulletsMap[list[i].CommunityVideoID]
  67. if bs != nil && len(bs) > 0 {
  68. for k := range bs {
  69. ls = append(ls, &responseModel.BulletChatItem{
  70. Id: bs[k].ID,
  71. Content: bs[k].Content,
  72. UserId: bs[k].UserID,
  73. Color: bs[k].Color,
  74. Seconds: fmt.Sprint(bs[k].Seconds),
  75. })
  76. }
  77. }
  78. list[i].BulletChatList = ls
  79. }
  80. response.OkData("获取成功", list, c)
  81. }
  82. // VideoPlayLog 记录视频播放日志
  83. // @Tags 视频社区模块
  84. // @Description 记录视频播放日志
  85. // @Param video_id query int true "音频ID"
  86. // @Param source_agent query int true "操作来源,1:小程序,2:小程序 pc 3:弘则研究公众号,4:web pc"
  87. // @Success 200 {string} string "操作成功"
  88. // @failure 400 {string} string "操作失败"
  89. // @Router /video/play_log [post]
  90. func VideoPlayLog(c *gin.Context) {
  91. var req request.VideoPlayLogReq
  92. if err := c.ShouldBind(&req); err != nil {
  93. response.Fail("参数有误", c)
  94. return
  95. }
  96. if req.VideoId == 0 {
  97. response.Fail("参数有误", c)
  98. return
  99. }
  100. if req.SourceAgent == 0 {
  101. response.Fail("参数有误", c)
  102. return
  103. }
  104. userinfo := user.GetInfoByClaims(c)
  105. newId, errMsg, err := community.SaveVideoPlayLog(userinfo, req.VideoId, req.SourceAgent, 1)
  106. if err != nil {
  107. response.FailMsg(errMsg, "VideoPlayLog ErrMsg:"+err.Error(), c)
  108. return
  109. }
  110. response.OkData("操作成功", newId, c)
  111. }