english_video.go 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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_report"
  9. "hongze/hongze_yb_en_api/models/english_video"
  10. english_report_service "hongze/hongze_yb_en_api/services/english_report"
  11. "hongze/hongze_yb_en_api/utils"
  12. "strconv"
  13. )
  14. type EnglishVideoController struct {}
  15. func (er *EnglishVideoController) List(c *gin.Context) {
  16. req := new(english_report.ReportListReq)
  17. err := c.BindQuery(&req)
  18. if err != nil {
  19. errs, ok := err.(validator.ValidationErrors)
  20. if !ok {
  21. resp.FailData("参数解析失败", "Err:"+err.Error(), c)
  22. return
  23. }
  24. resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
  25. return
  26. }
  27. page := new(base.Page)
  28. page.SetPageSize(req.PageSize)
  29. page.SetCurrent(req.Current)
  30. item := new(english_video.EnglishVideo)
  31. condition := " state=2"
  32. var pars []interface{}
  33. var total int64
  34. var tmpList []*english_video.EnglishVideo
  35. list := make([]*english_video.VideoListItem, 0)
  36. if req.ClassifyIdFirst >0 {
  37. condition += " and classify_id_first = ?"
  38. pars = append(pars, req.ClassifyIdFirst)
  39. }
  40. if req.ClassifyIdSecond >0 {
  41. condition += " and classify_id_second = ?"
  42. pars = append(pars, req.ClassifyIdSecond)
  43. }
  44. page.AddOrderItem(base.OrderItem{Column: "publish_time", Asc: false})
  45. page.AddOrderItem(base.OrderItem{Column: "id", Asc: false})
  46. total, tmpList, err = item.SelectPage(page, condition, pars)
  47. if err != nil {
  48. resp.FailMsg("获取失败", "获取失败,Err:"+err.Error(), c)
  49. return
  50. }
  51. if len(tmpList) > 0 {
  52. for _, v := range tmpList {
  53. tmp := &english_video.VideoListItem{
  54. Id: v.Id,
  55. ClassifyIdFirst: v.ClassifyIdFirst,
  56. ClassifyNameFirst: v.ClassifyNameFirst,
  57. ClassifyIdSecond: v.ClassifyIdSecond,
  58. ClassifyNameSecond: v.ClassifyNameSecond,
  59. Title: v.Title,
  60. Abstract: v.Abstract,
  61. Author: v.Author,
  62. PublishTime: utils.TimeTransferString(utils.FormatDateTime, v.PublishTime),
  63. VideoUrl: v.VideoUrl,
  64. VideoCoverUrl: v.VideoCoverUrl,
  65. VideoSeconds: v.VideoSeconds,
  66. VideoCode: v.VideoCode,
  67. ShareUrl: "https://share.hzinsights.com/reportEn?code=" + v.VideoCode,
  68. CreateTime: utils.TimeTransferString(utils.FormatDateTime, v.CreateTime),
  69. ModifyTime: utils.TimeTransferString(utils.FormatDateTime, v.ModifyTime),
  70. }
  71. list = append(list, tmp)
  72. }
  73. }
  74. page.SetTotal(total)
  75. baseData := new(base.BaseData)
  76. baseData.SetPage(page)
  77. baseData.SetList(list)
  78. resp.OkData("获取成功", baseData, c)
  79. }
  80. func (er *EnglishVideoController) Detail(c *gin.Context) {
  81. req := new(english_video.VideoDetailReq)
  82. err := c.BindQuery(&req)
  83. if err != nil {
  84. errs, ok := err.(validator.ValidationErrors)
  85. if !ok {
  86. resp.FailData("参数解析失败", "Err:"+err.Error(), c)
  87. return
  88. }
  89. resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
  90. return
  91. }
  92. videoItem := new(english_video.EnglishVideo)
  93. videoItem, err = videoItem.GetEnglishVideoByCode(req.VideoCode)
  94. if err != nil {
  95. resp.FailMsg("该报告已删除", "报告查询失败,Err:" + err.Error(), c)
  96. return
  97. }
  98. err = videoItem.UpdatePvByVideoCode(req.VideoCode)
  99. if err != nil {
  100. resp.FailMsg("更新失败", "更新失败,Err:" + err.Error(), c)
  101. return
  102. }
  103. shareEmailId := req.ShareEmail
  104. if shareEmailId == 0 {
  105. shareEmailIdStr := c.GetString("shareEmailId")
  106. shareEmailId, _ = strconv.Atoi(shareEmailIdStr)
  107. }
  108. // 记录邮箱
  109. if shareEmailId > 0 {
  110. go english_report_service.DealVideoEmail(videoItem, req.VideoCode, shareEmailId)
  111. }
  112. videoDetail := &english_video.VideoDetail{
  113. Id: videoItem.Id,
  114. ClassifyIdFirst: videoItem.ClassifyIdFirst,
  115. ClassifyNameFirst: videoItem.ClassifyNameFirst,
  116. ClassifyIdSecond: videoItem.ClassifyIdSecond,
  117. ClassifyNameSecond: videoItem.ClassifyNameSecond,
  118. Title: videoItem.Title,
  119. Abstract: videoItem.Abstract,
  120. Author: videoItem.Author,
  121. Overview: videoItem.Overview,
  122. PublishTime: utils.TimeTransferString(utils.FormatDateTime, videoItem.PublishTime),
  123. VideoUrl: videoItem.VideoUrl,
  124. VideoCoverUrl: videoItem.VideoCoverUrl,
  125. VideoSeconds: videoItem.VideoSeconds,
  126. VideoCode: videoItem.VideoCode,
  127. CreateTime: utils.TimeTransferString(utils.FormatDateTime, videoItem.CreateTime),
  128. ModifyTime: utils.TimeTransferString(utils.FormatDateTime, videoItem.ModifyTime),
  129. }
  130. baseData := new(english_video.VideoDetailResp)
  131. baseData.Video = videoDetail
  132. resp.OkData("查询成功", baseData, c)
  133. }