english_video.go 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. package english_report
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "github.com/go-playground/validator/v10"
  5. "hongze/hongze_yb_en_api/controller/resp"
  6. "hongze/hongze_yb_en_api/global"
  7. "hongze/hongze_yb_en_api/models/base"
  8. "hongze/hongze_yb_en_api/models/english_classify"
  9. "hongze/hongze_yb_en_api/models/english_report"
  10. "hongze/hongze_yb_en_api/models/english_video"
  11. english_report_service "hongze/hongze_yb_en_api/services/english_report"
  12. "hongze/hongze_yb_en_api/utils"
  13. "strconv"
  14. )
  15. type EnglishVideoController struct{}
  16. func (er *EnglishVideoController) List(c *gin.Context) {
  17. req := new(english_report.ReportListReq)
  18. err := c.BindQuery(&req)
  19. if err != nil {
  20. errs, ok := err.(validator.ValidationErrors)
  21. if !ok {
  22. resp.FailData("参数解析失败", "Err:"+err.Error(), c)
  23. return
  24. }
  25. resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
  26. return
  27. }
  28. page := new(base.Page)
  29. page.SetPageSize(req.PageSize)
  30. page.SetCurrent(req.Current)
  31. item := new(english_video.EnglishVideo)
  32. condition := " state=2"
  33. var pars []interface{}
  34. var total int64
  35. var tmpList []*english_video.EnglishVideo
  36. list := make([]*english_video.VideoListItem, 0)
  37. enClassify := new(english_classify.Classify)
  38. if req.ClassifyIdFirst > 0 {
  39. condition += " and classify_id_first = ?"
  40. pars = append(pars, req.ClassifyIdFirst)
  41. }
  42. if req.ClassifyIdSecond > 0 {
  43. condition += " and classify_id_second = ?"
  44. pars = append(pars, req.ClassifyIdSecond)
  45. }
  46. if req.ClassifyIdRoot > 0 && req.ClassifyIdFirst == 0 && req.ClassifyIdSecond == 0 {
  47. //查询顶级分类下的所有二级分类
  48. secondClassify, err := enClassify.GetSecondChild(req.ClassifyIdRoot)
  49. if err != nil {
  50. resp.FailMsg("获取分类失败", "获取分类信息失败,Err:"+err.Error(), c)
  51. return
  52. }
  53. var classifyIdFirstSlice []int
  54. for _, v := range secondClassify {
  55. classifyIdFirstSlice = append(classifyIdFirstSlice, v.Id)
  56. }
  57. condition += " and classify_id_first in (?)"
  58. pars = append(pars, classifyIdFirstSlice)
  59. }
  60. page.AddOrderItem(base.OrderItem{Column: "publish_time", Asc: false})
  61. page.AddOrderItem(base.OrderItem{Column: "id", Asc: false})
  62. total, tmpList, err = item.SelectPage(page, condition, pars)
  63. if err != nil {
  64. resp.FailMsg("获取失败", "获取失败,Err:"+err.Error(), c)
  65. return
  66. }
  67. if len(tmpList) > 0 {
  68. for _, v := range tmpList {
  69. tmp := &english_video.VideoListItem{
  70. Id: v.Id,
  71. ClassifyIdFirst: v.ClassifyIdFirst,
  72. ClassifyNameFirst: v.ClassifyNameFirst,
  73. ClassifyIdSecond: v.ClassifyIdSecond,
  74. ClassifyNameSecond: v.ClassifyNameSecond,
  75. Title: v.Title,
  76. Abstract: v.Abstract,
  77. Author: v.Author,
  78. PublishTime: utils.TimeTransferString(utils.FormatDateTime, v.PublishTime),
  79. VideoUrl: v.VideoUrl,
  80. VideoCoverUrl: v.VideoCoverUrl,
  81. VideoSeconds: v.VideoSeconds,
  82. VideoCode: v.VideoCode,
  83. ShareUrl: "https://share.hzinsights.com/reportEn?code=" + v.VideoCode,
  84. CreateTime: utils.TimeTransferString(utils.FormatDateTime, v.CreateTime),
  85. ModifyTime: utils.TimeTransferString(utils.FormatDateTime, v.ModifyTime),
  86. }
  87. list = append(list, tmp)
  88. }
  89. }
  90. page.SetTotal(total)
  91. baseData := new(base.BaseData)
  92. baseData.SetPage(page)
  93. baseData.SetList(list)
  94. resp.OkData("获取成功", baseData, c)
  95. }
  96. func (er *EnglishVideoController) Detail(c *gin.Context) {
  97. req := new(english_video.VideoDetailReq)
  98. err := c.BindQuery(&req)
  99. if err != nil {
  100. errs, ok := err.(validator.ValidationErrors)
  101. if !ok {
  102. resp.FailData("参数解析失败", "Err:"+err.Error(), c)
  103. return
  104. }
  105. resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
  106. return
  107. }
  108. // 英文研报1.1改-路演开放所有权限
  109. //userinfo := services.GetInfoByClaims(c)
  110. videoItem := new(english_video.EnglishVideo)
  111. videoItem, err = videoItem.GetEnglishVideoByCode(req.VideoCode)
  112. if err != nil {
  113. resp.FailMsg("该视频已删除", "视频查询失败,Err:"+err.Error(), c)
  114. return
  115. }
  116. // 权限校验
  117. //authOk, e := english_report_service.CheckUserReportAuthByCompanyAndClassify(int(userinfo.CompanyId), videoItem.ClassifyIdSecond)
  118. //if e != nil {
  119. // resp.FailMsg("获取失败", "报告权限校验失败, Err: "+e.Error(), c)
  120. // return
  121. //}
  122. //videoUrl := ``
  123. //if authOk {
  124. // videoUrl = videoItem.VideoUrl
  125. //}
  126. err = videoItem.UpdatePvByVideoCode(req.VideoCode)
  127. if err != nil {
  128. resp.FailMsg("更新失败", "更新失败,Err:"+err.Error(), c)
  129. return
  130. }
  131. shareEmailId := req.ShareEmail
  132. if shareEmailId == 0 {
  133. shareEmailIdStr := c.GetString("shareEmailId")
  134. shareEmailId, _ = strconv.Atoi(shareEmailIdStr)
  135. }
  136. // 记录邮箱
  137. if shareEmailId > 0 {
  138. go english_report_service.DealVideoEmail(videoItem, req.VideoCode, shareEmailId)
  139. }
  140. videoDetail := &english_video.VideoDetail{
  141. Id: videoItem.Id,
  142. ClassifyIdFirst: videoItem.ClassifyIdFirst,
  143. ClassifyNameFirst: videoItem.ClassifyNameFirst,
  144. ClassifyIdSecond: videoItem.ClassifyIdSecond,
  145. ClassifyNameSecond: videoItem.ClassifyNameSecond,
  146. Title: videoItem.Title,
  147. Abstract: videoItem.Abstract,
  148. Author: videoItem.Author,
  149. Overview: videoItem.Overview,
  150. PublishTime: utils.TimeTransferString(utils.FormatDateTime, videoItem.PublishTime),
  151. VideoUrl: videoItem.VideoUrl,
  152. VideoCoverUrl: videoItem.VideoCoverUrl,
  153. VideoSeconds: videoItem.VideoSeconds,
  154. VideoCode: videoItem.VideoCode,
  155. CreateTime: utils.TimeTransferString(utils.FormatDateTime, videoItem.CreateTime),
  156. ModifyTime: utils.TimeTransferString(utils.FormatDateTime, videoItem.ModifyTime),
  157. }
  158. baseData := new(english_video.VideoDetailResp)
  159. baseData.Video = videoDetail
  160. baseData.AuthOk = true
  161. resp.OkData("查询成功", baseData, c)
  162. }
  163. // VideoPlayLog 记录视频播放日志
  164. // @Tags 视频社区模块
  165. // @Description 记录视频播放日志
  166. // @Param video_id query int true "音频ID"
  167. // @Param source_agent query int true "操作来源,1:小程序,2:小程序 pc 3:弘则研究公众号,4:web pc"
  168. // @Success 200 {string} string "操作成功"
  169. // @failure 400 {string} string "操作失败"
  170. // @Router /play_log [post]
  171. func (er *EnglishVideoController) VideoPlayLog(c *gin.Context) {
  172. var req english_video.VideoPlayLogReq
  173. err := c.ShouldBind(&req)
  174. if err != nil {
  175. errs, ok := err.(validator.ValidationErrors)
  176. if !ok {
  177. resp.FailData("参数解析失败", "Err:"+err.Error(), c)
  178. return
  179. }
  180. resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
  181. return
  182. }
  183. shareEmailIdStr := c.GetString("shareEmailId")
  184. shareEmailId, _ := strconv.Atoi(shareEmailIdStr)
  185. item := new(english_video.PlayLog)
  186. if req.Id > 0 {
  187. //查找当前播放日志,并更新停止播放时长
  188. item.Id = req.Id
  189. item, err = item.GetById()
  190. if err != nil {
  191. if err == utils.ErrNoRow {
  192. resp.Fail("播放日志不存在", c)
  193. return
  194. }
  195. resp.FailMsg("查询播放日志失败", "新增播放日志失败,Err:"+err.Error(), c)
  196. return
  197. }
  198. item.StopSeconds = req.StopSeconds
  199. err = item.Update([]string{"stop_seconds"})
  200. if err != nil {
  201. resp.FailMsg("更新播放日志失败", "更新播放日志失败,Err:"+err.Error(), c)
  202. return
  203. }
  204. } else {
  205. if req.VideoId == 0 {
  206. resp.Fail("请输入点击的视频ID", c)
  207. return
  208. }
  209. item = &english_video.PlayLog{
  210. VideoId: req.VideoId,
  211. EmailId: shareEmailId,
  212. StopSeconds: 0,
  213. }
  214. err = item.Add()
  215. if err != nil {
  216. resp.FailMsg("新增播放日志失败", "新增播放日志失败,Err:"+err.Error(), c)
  217. return
  218. }
  219. }
  220. baseData := new(english_video.VideoPlayLogResp)
  221. baseData.Id = item.Id
  222. resp.OkData("操作成功", baseData, c)
  223. }