video.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. package road
  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 chart_permission_id query int false "品种ID"
  21. // @Success 200 {object}
  22. // @failure 400 {string} string "获取失败"
  23. // @Router /road/videos [get]
  24. func VideoList(c *gin.Context) {
  25. var req request.RoadVideoListReq
  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, code := community.GetRoadVideoList(userinfo, req.PageIndex, req.PageSize, req.VideoId, req.ChartPermissionId, req.Keywords)
  38. if err != nil {
  39. if code == response.SPECIFIC_FAIL_CODE {
  40. response.SpecificFail(list, err.Error(), c)
  41. return
  42. }
  43. response.FailMsg("获取失败", "VideoList ErrMsg:"+err.Error(), c)
  44. return
  45. }
  46. // 点赞/吐槽数据
  47. err = community.HandleLikeOrTeaseByRoadVideoItemList(userinfo.UserID, list.List)
  48. if err != nil {
  49. response.FailMsg("获取失败", "QuestionList ErrMsg:"+err.Error(), c)
  50. return
  51. }
  52. // 评论数据
  53. err = community.HandleCommentByRoadVideoItemList(list.List)
  54. if err != nil {
  55. response.FailMsg("获取失败", "QuestionList ErrMsg:"+err.Error(), c)
  56. return
  57. }
  58. idsArr := make([]int, 0)
  59. for i := range list.List {
  60. idsArr = append(idsArr, list.List[i].RoadVideoID)
  61. }
  62. // 弹幕数据
  63. idBulletsMap, e := bullet_chat.GetListMapBySourceAndIds(bullet_chat.SourceBulletChatRoadVideo, idsArr)
  64. if e != nil {
  65. response.FailMsg("获取失败", "获取视频社区弹幕列表Map失败, Err: "+e.Error(), c)
  66. return
  67. }
  68. for i := range list.List {
  69. ls := make([]*responseModel.BulletChatItem, 0)
  70. bs := idBulletsMap[list.List[i].RoadVideoID]
  71. if bs != nil && len(bs) > 0 {
  72. for k := range bs {
  73. ls = append(ls, &responseModel.BulletChatItem{
  74. Id: bs[k].ID,
  75. Content: bs[k].Content,
  76. UserId: bs[k].UserID,
  77. Color: bs[k].Color,
  78. Seconds: fmt.Sprint(bs[k].Seconds),
  79. })
  80. }
  81. }
  82. list.List[i].BulletChatList = ls
  83. }
  84. response.OkData("获取成功", list, c)
  85. }
  86. // VideoPlayLog 记录视频播放日志
  87. // @Tags 视频社区模块
  88. // @Description 记录视频播放日志
  89. // @Param video_id query int true "音频ID"
  90. // @Param source_agent query int true "操作来源,1:小程序,2:小程序 pc 3:弘则研究公众号,4:web pc"
  91. // @Success 200 {string} string "操作成功"
  92. // @failure 400 {string} string "操作失败"
  93. // @Router /video/play_log [post]
  94. func VideoPlayLog(c *gin.Context) {
  95. var req request.RoadVideoPlayLogReq
  96. if err := c.ShouldBind(&req); err != nil {
  97. response.Fail("参数有误", c)
  98. return
  99. }
  100. if req.VideoId == 0 {
  101. response.Fail("参数有误", c)
  102. return
  103. }
  104. if req.SourceAgent == 0 {
  105. response.Fail("参数有误", c)
  106. return
  107. }
  108. userinfo := user.GetInfoByClaims(c)
  109. newId, errMsg, err := community.SaveVideoPlayLog(userinfo, req.VideoId, req.SourceAgent, 2)
  110. if err != nil {
  111. response.FailMsg(errMsg, "VideoPlayLog ErrMsg:"+err.Error(), c)
  112. return
  113. }
  114. response.OkData("操作成功", newId, c)
  115. }