english_video.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. package models
  2. import (
  3. "eta/eta_mobile/utils"
  4. "github.com/beego/beego/v2/client/orm"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "strings"
  7. "time"
  8. )
  9. type EnglishVideo struct {
  10. Id int `orm:"column(id);pk;auto" description:"路演视频Id"`
  11. ClassifyIdFirst int `description:"一级分类id"`
  12. ClassifyNameFirst string `description:"一级分类名称"`
  13. ClassifyIdSecond int `description:"二级分类id"`
  14. ClassifyNameSecond string `description:"二级分类名称"`
  15. Title string `description:"标题"`
  16. Abstract string `description:"摘要"`
  17. Author string `description:"作者"`
  18. CreateTime time.Time `description:"创建时间"`
  19. ModifyTime time.Time `description:"修改时间"`
  20. State int `description:"1:未发布,2:已发布"`
  21. PublishTime time.Time `description:"发布时间"`
  22. VideoUrl string `description:"视频文件URL"`
  23. VideoCoverUrl string `description:"视频文件封面地址"`
  24. VideoSeconds string `description:"视频时长"`
  25. VideoCode string `description:"报告唯一编码"`
  26. Pv int `description:"Pv"`
  27. PvEmail int `description:"邮箱PV"`
  28. EmailState int `description:"群发邮件状态: 0-未发送; 1-已发送"`
  29. Overview string `description:"英文概述部分"`
  30. AdminId int `description:"上传视频的管理员账号"`
  31. AdminRealName string `description:"上传视频的管理员姓名"`
  32. }
  33. func AddEnglishVideo(item *EnglishVideo) (err error) {
  34. o := orm.NewOrmUsingDB("rddp")
  35. _, err = o.Insert(item)
  36. return
  37. }
  38. func ModifyEnglishVideoCode(id int, VideoCode string) (err error) {
  39. o := orm.NewOrmUsingDB("rddp")
  40. sql := `UPDATE english_video SET video_code=? WHERE id=? `
  41. _, err = o.Raw(sql, VideoCode, id).Exec()
  42. return
  43. }
  44. type SaveEnglishVideoReq struct {
  45. Id int `description:"路演视频ID"`
  46. ClassifyIdFirst int `description:"一级分类id"`
  47. //ClassifyNameFirst string `description:"一级分类名称"`
  48. ClassifyIdSecond int `description:"二级分类id"`
  49. //ClassifyNameSecond string `description:"二级分类名称"`
  50. Title string `description:"标题"`
  51. Abstract string `description:"摘要"`
  52. Author string `description:"作者"`
  53. State int `description:"状态:1:未发布,2:已发布"`
  54. VideoUrl string `description:"视频文件URL"`
  55. VideoCoverUrl string `description:"视频文件封面地址"`
  56. VideoSeconds string `description:"视频时长"`
  57. Overview string `description:"英文概述部分"`
  58. }
  59. type SaveEnglishVideoResp struct {
  60. Id int `description:"路演视频ID"`
  61. VideoCode string `description:"报告code"`
  62. }
  63. type ElasticEnglishVideoDetail struct {
  64. Id int `description:"路演视频ID"`
  65. ClassifyIdFirst int `description:"一级分类id"`
  66. ClassifyNameFirst string `description:"一级分类名称"`
  67. ClassifyIdSecond int `description:"二级分类id"`
  68. ClassifyNameSecond string `description:"二级分类名称"`
  69. StageStr string `description:"报告期数"`
  70. Title string `description:"标题"`
  71. Abstract string `description:"摘要"`
  72. Author string `description:"作者"`
  73. Frequency string `description:"频度"`
  74. PublishState int `description:"状态:1:未发布,2:已发布"`
  75. BodyContent string `description:"内容"`
  76. ContentSub string `description:"前两段内容"`
  77. CreateTime string `description:"创建时间"`
  78. PublishTime string `description:"发布时间"`
  79. VideoCode string `description:"报告唯一编码"`
  80. Overview string `description:"英文概述部分"`
  81. }
  82. func EditEnglishVideo(item *EnglishVideo, Id int) (err error) {
  83. o := orm.NewOrmUsingDB("rddp")
  84. sql := `UPDATE english_video
  85. SET
  86. classify_id_first =?,
  87. classify_name_first = ?,
  88. classify_id_second = ?,
  89. classify_name_second = ?,
  90. title = ?,
  91. abstract = ?,
  92. state = ?,
  93. modify_time = ?,
  94. overview = ?,
  95. video_url = ?,
  96. video_cover_url = ?,
  97. video_seconds = ?
  98. WHERE id = ? `
  99. _, err = o.Raw(sql, item.ClassifyIdFirst, item.ClassifyNameFirst, item.ClassifyIdSecond, item.ClassifyNameSecond, item.Title,
  100. item.Abstract, item.State, time.Now(), item.Overview, item.VideoUrl, item.VideoCoverUrl, item.VideoSeconds, Id).Exec()
  101. return
  102. }
  103. type EnglishVideoDetail struct {
  104. Id int `description:"路演视频ID"`
  105. ClassifyIdFirst int `description:"一级分类id"`
  106. ClassifyNameFirst string `description:"一级分类名称"`
  107. ClassifyIdSecond int `description:"二级分类id"`
  108. ClassifyNameSecond string `description:"二级分类名称"`
  109. Title string `description:"标题"`
  110. Abstract string `description:"摘要"`
  111. Author string `description:"作者"`
  112. CreateTime string `description:"创建时间"`
  113. ModifyTime string `description:"修改时间"`
  114. State int `description:"1:未发布,2:已发布"`
  115. PublishTime string `description:"发布时间"`
  116. MsgIsSend int `description:"消息是否已发送,0:否,1:是"`
  117. VideoCode string `description:"报告唯一编码"`
  118. VideoUrl string `description:"视频文件URL"`
  119. VideoCoverUrl string `description:"视频文件封面地址"`
  120. VideoSeconds string `description:"视频时长"`
  121. Pv int `description:"Pv"`
  122. Overview string `description:"英文概述部分"`
  123. }
  124. func GetEnglishVideoById(Id int) (item *EnglishVideoDetail, err error) {
  125. o := orm.NewOrmUsingDB("rddp")
  126. sql := `SELECT * FROM english_video WHERE id=?`
  127. err = o.Raw(sql, Id).QueryRow(&item)
  128. return
  129. }
  130. func GetEnglishVideoItemById(Id int) (item *EnglishVideo, err error) {
  131. o := orm.NewOrmUsingDB("rddp")
  132. sql := `SELECT * FROM english_video WHERE id = ? LIMIT 1`
  133. err = o.Raw(sql, Id).QueryRow(&item)
  134. return
  135. }
  136. type EnglishVideoList struct {
  137. Id int `description:"id"`
  138. ClassifyIdFirst int `description:"一级分类id"`
  139. ClassifyNameFirst string `description:"一级分类名称"`
  140. ClassifyIdSecond int `description:"二级分类id"`
  141. ClassifyNameSecond string `description:"二级分类名称"`
  142. Title string `description:"标题"`
  143. Abstract string `description:"摘要"`
  144. CreateTime string `description:"创建时间"`
  145. ModifyTime string `description:"修改时间"`
  146. State int `description:"1:未发布,2:已发布"`
  147. PublishTime string `description:"发布时间"`
  148. VideoUrl string `description:"视频文件URL"`
  149. VideoCoverUrl string `description:"视频文件封面地址"`
  150. VideoSeconds string `description:"视频时长"`
  151. VideoCode string `description:"报告唯一编码"`
  152. Pv int `description:"Pv"`
  153. ShareUrl string `description:"分享url"`
  154. PvEmail int `description:"邮箱PV"`
  155. EmailState int `description:"群发邮件状态: 0-未发送; 1-已发送"`
  156. EmailAuth bool `description:"是否有权限群发邮件"`
  157. EmailHasFail bool `description:"是否存在邮件发送失败的记录"`
  158. Overview string `description:"英文概述部分"`
  159. AdminId int `description:"上传视频的管理员账号"`
  160. AdminRealName string `description:"上传视频的管理员姓名"`
  161. }
  162. type EnglishVideoListResp struct {
  163. List []*EnglishVideoList
  164. Paging *paging.PagingItem `description:"分页数据"`
  165. }
  166. type EnglishVideoReq struct {
  167. Id int `description:"路演视频id"`
  168. }
  169. func GetEnglishVideoListCount(condition string, pars []interface{}) (count int, err error) {
  170. //产品权限
  171. oRddp := orm.NewOrmUsingDB("rddp")
  172. sql := `SELECT COUNT(1) AS count FROM english_video WHERE 1=1 `
  173. if condition != "" {
  174. sql += condition
  175. }
  176. err = oRddp.Raw(sql, pars).QueryRow(&count)
  177. return
  178. }
  179. func GetEnglishVideoList(condition string, pars []interface{}, startSize, pageSize int) (items []*EnglishVideoList, err error) {
  180. o := orm.NewOrmUsingDB("rddp")
  181. sql := `SELECT *
  182. FROM english_video WHERE 1=1 `
  183. if condition != "" {
  184. sql += condition
  185. }
  186. sql += `ORDER BY modify_time DESC LIMIT ?,?`
  187. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  188. return
  189. }
  190. func GetEnglishVideoByCondition(condition string, pars []interface{}) (items []*EnglishVideo, err error) {
  191. o := orm.NewOrmUsingDB("rddp")
  192. sql := `SELECT *
  193. FROM english_video WHERE 1=1 `
  194. if condition != "" {
  195. sql += condition
  196. }
  197. _, err = o.Raw(sql, pars).QueryRows(&items)
  198. return
  199. }
  200. // 发布报告
  201. func PublishEnglishVideoById(Id int) (err error) {
  202. o := orm.NewOrmUsingDB("rddp")
  203. sql := `UPDATE english_video SET state=2,publish_time=now(),modify_time=NOW() WHERE id = ? `
  204. _, err = o.Raw(sql, Id).Exec()
  205. return
  206. }
  207. // 取消发布报告
  208. func PublishCancelEnglishVideo(Ids int) (err error) {
  209. o := orm.NewOrmUsingDB("rddp")
  210. sql := ` UPDATE english_video SET state=1,publish_time=null WHERE id =? `
  211. _, err = o.Raw(sql, Ids).Exec()
  212. return
  213. }
  214. // DeleteEnglishVideo 删除路演视频
  215. func DeleteEnglishVideo(Id int) (err error) {
  216. o := orm.NewOrmUsingDB("rddp")
  217. sql := ` DELETE FROM english_video WHERE id=? `
  218. _, err = o.Raw(sql, Id).Exec()
  219. return
  220. }
  221. func GetEnglishVideoDetailByClassifyId(classifyIdFirst, classifyIdSecond int) (item *EnglishVideo, err error) {
  222. o := orm.NewOrmUsingDB("rddp")
  223. sql := ` SELECT * FROM english_video WHERE 1=1 `
  224. if classifyIdSecond > 0 {
  225. sql = sql + ` AND classify_id_second=? ORDER BY stage DESC LIMIT 1`
  226. err = o.Raw(sql, classifyIdSecond).QueryRow(&item)
  227. } else {
  228. sql = sql + ` AND classify_id_first=? ORDER BY stage DESC LIMIT 1`
  229. err = o.Raw(sql, classifyIdFirst).QueryRow(&item)
  230. }
  231. return
  232. }
  233. // Update 更新
  234. func (item *EnglishVideo) Update(cols []string) (err error) {
  235. o := orm.NewOrmUsingDB("rddp")
  236. _, err = o.Update(item, cols...)
  237. return
  238. }
  239. func GetEnglishVideoCounts(classifyId, parentId int) (count int, err error) {
  240. o := orm.NewOrmUsingDB("rddp")
  241. sql := ``
  242. if parentId == 0 {
  243. sql = `SELECT COUNT(1) AS count FROM english_video WHERE classify_id_first=? `
  244. } else {
  245. sql = `SELECT COUNT(1) AS count FROM english_video WHERE classify_id_second=? `
  246. }
  247. err = o.Raw(sql, classifyId).QueryRow(&count)
  248. return
  249. }
  250. // UpdateEnglishVideoSecondClassifyNameByClassifyId 更新报告分类名称字段
  251. func UpdateEnglishVideoSecondClassifyNameByClassifyId(classifyId int, classifyName string) (err error) {
  252. o := orm.NewOrmUsingDB("rddp")
  253. sql := " UPDATE english_video SET classify_name_second = ? WHERE classify_id_second = ? "
  254. _, err = o.Raw(sql, classifyName, classifyId).Exec()
  255. return
  256. }
  257. // UpdateEnglishVideoFirstClassifyNameByClassifyId 更新报告分类名称字段
  258. func UpdateEnglishVideoFirstClassifyNameByClassifyId(classifyId int, classifyName string) (err error) {
  259. o := orm.NewOrmUsingDB("rddp")
  260. sql := " UPDATE english_video SET classify_name_first = ? WHERE classify_id_first = ? "
  261. _, err = o.Raw(sql, classifyName, classifyId).Exec()
  262. return
  263. }
  264. // UpdateEnglishVideoFirstClassifyNameByClassifyId 更新报告分类名称字段
  265. func UpdateEnglishVideoByClassifyId(classifyFirstName, classifySecondName string, firstClassifyId, secondClassifyId int, ids string) (err error) {
  266. o := orm.NewOrmUsingDB("rddp")
  267. sql := " UPDATE english_video SET classify_name_first = ?,classify_name_second = ?,classify_id_first=?, classify_id_second =? WHERE id IN (" + ids + ") "
  268. _, err = o.Raw(sql, classifyFirstName, classifySecondName, firstClassifyId, secondClassifyId).Exec()
  269. return
  270. }
  271. // GetEnglishVideoByIds 根据IDs获取英文报告列表
  272. func GetEnglishVideoByIds(Ids []int, fieldArr []string) (list []*EnglishVideo, err error) {
  273. listLen := len(Ids)
  274. if listLen == 0 {
  275. return
  276. }
  277. fields := ` * `
  278. if len(fieldArr) > 0 {
  279. fields = strings.Join(fieldArr, ",")
  280. }
  281. o := orm.NewOrmUsingDB("rddp")
  282. sql := `SELECT ` + fields + ` FROM english_video WHERE id IN (` + utils.GetOrmInReplace(listLen) + `)`
  283. _, err = o.Raw(sql, Ids).QueryRows(&list)
  284. return
  285. }