english_video.go 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. package english_video
  2. import (
  3. "hongze/hongze_yb_en_api/global"
  4. "hongze/hongze_yb_en_api/models/base"
  5. "time"
  6. )
  7. type EnglishVideo struct {
  8. Id uint `gorm:"primaryKey;column:id" json:"id"`
  9. ClassifyIdFirst int `gorm:"column:classify_id_first" json:"classify_id_first"` //一级分类id
  10. ClassifyNameFirst string `gorm:"column:classify_name_first" json:"classify_name_first"` //一级分类名称
  11. ClassifyIdSecond int `gorm:"column:classify_id_second" json:"classify_id_second"` //二级分类id
  12. ClassifyNameSecond string `gorm:"column:classify_name_second" json:"classify_name_second"` //二级分类名称
  13. Title string `gorm:"column:title" json:"title"` //标题
  14. Abstract string `gorm:"column:abstract" json:"abstract"` //摘要
  15. Author string `gorm:"column:author" json:"author"` //作者
  16. State int8 `gorm:"column:state" json:"state"` //1:未发布,2:已发布
  17. PublishTime time.Time `gorm:"column:publish_time" json:"publish_time"` //发布时间
  18. Overview string `gorm:"column:overview" json:"overview"` //概述
  19. VideoUrl string `gorm:"column:video_url" json:"video_url"` //视频文件URL
  20. VideoCoverUrl string `gorm:"column:video_cover_url" json:"video_cover_url"` //视频文件封面地址
  21. VideoSeconds string `gorm:"column:video_seconds" json:"video_seconds"` //视频时长
  22. VideoCode string `gorm:"column:video_code" json:"video_code"` //唯一编码
  23. Pv int `gorm:"column:pv" json:"pv"`
  24. ShareUrl string `gorm:"column:share_url" json:"share_url"` //分享url
  25. PvEmail uint `gorm:"column:pv_email" json:"pv_email"` //分享邮箱的PV
  26. EmailState uint8 `gorm:"column:email_state" json:"email_state"` //是否已群发邮件:0-否; 1-是
  27. base.TimeBase
  28. }
  29. // TableName get sql table name.获取数据库表名
  30. func (r *EnglishVideo) TableName() string {
  31. return "english_video"
  32. }
  33. type VideoListReq struct {
  34. ClassifyIdFirst int `json:"classify_id_first" form:"classify_id_first"`
  35. ClassifyIdSecond int `json:"classify_id_second" form:"classify_id_second"`
  36. base.PageReq
  37. }
  38. type VideoListItem struct {
  39. Id uint `json:"id"`
  40. ClassifyIdFirst int `json:"classify_id_first"` //一级分类id
  41. ClassifyNameFirst string `json:"classify_name_first"` //一级分类名称
  42. ClassifyIdSecond int `json:"classify_id_second"` //二级分类id
  43. ClassifyNameSecond string `json:"classify_name_second"` //二级分类名称
  44. Title string `json:"title"` //标题
  45. Abstract string `json:"abstract"` //摘要
  46. Author string `json:"author"` //作者
  47. PublishTime string `json:"publish_time"` //发布时间
  48. VideoUrl string `json:"video_url"` //视频文件URL
  49. VideoCoverUrl string `json:"video_cover_url"` //视频文件封面地址
  50. VideoSeconds string `json:"video_seconds"` //视频时长
  51. VideoCode string `json:"video_code"` //唯一编码
  52. ShareUrl string `json:"share_url"` //分享url
  53. CreateTime string `json:"create_time"` //创建时间
  54. ModifyTime string `json:"modify_time"` //最后更新时间
  55. }
  56. type VideoSearchReq struct {
  57. KeyWord string `json:"key_word" form:"key_word"`
  58. base.PageReq
  59. }
  60. type VideoDetailReq struct {
  61. VideoCode string `json:"video_code" form:"video_code" binding:"required"` //唯一编码
  62. ShareEmail int `json:"share_email" form:"share_email"` //推送的邮箱ID
  63. }
  64. type VideoDetail struct {
  65. Id uint `json:"id"`
  66. ClassifyIdFirst int `json:"classify_id_first"` //一级分类id
  67. ClassifyNameFirst string `json:"classify_name_first"` //一级分类名称
  68. ClassifyIdSecond int `json:"classify_id_second"` //二级分类id
  69. ClassifyNameSecond string `json:"classify_name_second"` //二级分类名称
  70. Title string `json:"title"` //标题
  71. Abstract string `json:"abstract"` //摘要
  72. Author string `json:"author"` //作者
  73. PublishTime string `json:"publish_time"` //发布时间
  74. VideoUrl string `json:"video_url"` //视频文件URL
  75. VideoCoverUrl string `json:"video_cover_url"` //视频文件封面地址
  76. VideoSeconds string `json:"video_seconds"` //视频时长
  77. VideoCode string `json:"video_code"` //唯一编码
  78. CreateTime string `json:"create_time"` //创建时间
  79. ModifyTime string `json:"modify_time"` //最后更新时间
  80. Overview string `json:"overview"` //概述
  81. }
  82. type VideoDetailResp struct {
  83. Video *VideoDetail `json:"Video"`
  84. AuthOk bool `json:"auth_ok"`
  85. }
  86. type SearchEnglishVideoItem struct {
  87. Id uint `json:"id"`
  88. ClassifyIdFirst int `json:"classify_id_first"` //一级分类id
  89. ClassifyNameFirst string `json:"classify_name_first"` //一级分类名称
  90. ClassifyIdSecond int `json:"classify_id_second"` //二级分类id
  91. ClassifyNameSecond string `json:"classify_name_second"` //二级分类名称
  92. Title string `json:"title"` //标题
  93. Author string `json:"author"` //作者
  94. PublishTime string `json:"publish_time"` //发布时间
  95. VideoCode string `json:"video_code"` //唯一编码
  96. CreateTime string `json:"create_time"` //创建时间
  97. ContentSub string `json:"content_sub"` //内容前两个章节"`
  98. }
  99. func (r *EnglishVideo) SelectPage(page base.IPage, condition string, pars []interface{}) (count int64, results []*EnglishVideo, err error) {
  100. results = make([]*EnglishVideo, 0)
  101. query := global.DEFAULT_MYSQL.Model(r).
  102. Select("*").
  103. Where(condition, pars...)
  104. query.Count(&count)
  105. if len(page.GetOrderItemsString()) > 0 {
  106. query = query.Order(page.GetOrderItemsString())
  107. }
  108. err = query.Limit(int(page.GetPageSize())).Offset(int(page.Offset())).Find(&results).Error
  109. return
  110. }
  111. func (r *EnglishVideo) GetEnglishVideoByCode(videoCode string) (item *EnglishVideo, err error) {
  112. err = global.MYSQL["rddp"].Model(r).Where("video_code= ?", videoCode).First(&item).Error
  113. return
  114. }
  115. // 修改
  116. func (r *EnglishVideo) Update(updateCols []string) (err error) {
  117. err = global.DEFAULT_MYSQL.Model(r).Select(updateCols).Updates(r).Error
  118. return
  119. }
  120. func (r *EnglishVideo) UpdatePvEmailByVideoCode(videoCode string) (err error) {
  121. sql := `UPDATE english_video SET pv_email = pv_email+1 WHERE video_code = ? `
  122. err = global.DEFAULT_MYSQL.Exec(sql, videoCode).Error
  123. return
  124. }
  125. func (r *EnglishVideo) UpdatePvByVideoCode(videoCode string) (err error) {
  126. sql := `UPDATE english_video SET pv = pv+1 WHERE video_code = ? `
  127. err = global.DEFAULT_MYSQL.Exec(sql, videoCode).Error
  128. return
  129. }
  130. // GetVideosByIds 通过IDs获取集合
  131. func (r *EnglishVideo) GetVideosByIds(ids []uint) (list []*EnglishVideo, err error) {
  132. err = global.DEFAULT_MYSQL.Model(r).Where("id IN (?)", ids).Scan(&list).Error
  133. return
  134. }