english_video.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  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 UpdateEnglishVideoClassifyByFirstSecondClassifyId(classifyId, parentId int) (err error) {
  222. o := orm.NewOrmUsingDB("rddp")
  223. // 更新相关联的二级分类的parentId,和classify_name_second
  224. sql := `update english_video r
  225. LEFT JOIN english_classify c ON r.classify_id_second = c.id
  226. SET r.classify_id_first=c.parent_id, r.classify_name_second=c.classify_name
  227. where (r.classify_id_first != c.parent_id or r.classify_name_second != c.classify_name) and r.classify_id_second =?`
  228. _, err = o.Raw(sql, classifyId).Exec()
  229. if err != nil {
  230. return
  231. }
  232. //更新一级分类名
  233. sql = `update english_video r
  234. LEFT JOIN english_classify c ON r.classify_id_first = c.id
  235. SET r.classify_name_first=c.classify_name
  236. where r.classify_name_first != c.classify_name and r.classify_id_first=?`
  237. _, err = o.Raw(sql, parentId).Exec()
  238. if err != nil {
  239. return
  240. }
  241. //更新一级分类名
  242. sql = `update english_video r
  243. LEFT JOIN english_classify c ON r.classify_id_first = c.id
  244. SET r.classify_name_first=c.classify_name
  245. where r.classify_name_first != c.classify_name and r.classify_id_first=?`
  246. _, err = o.Raw(sql, classifyId).Exec()
  247. return
  248. }
  249. // Update 更新
  250. func (item *EnglishVideo) Update(cols []string) (err error) {
  251. o := orm.NewOrmUsingDB("rddp")
  252. _, err = o.Update(item, cols...)
  253. return
  254. }
  255. func GetEnglishVideoCounts(classifyId, parentId int) (count int, err error) {
  256. o := orm.NewOrmUsingDB("rddp")
  257. sql := ``
  258. if parentId == 0 {
  259. sql = `SELECT COUNT(1) AS count FROM english_video WHERE classify_id_first=? `
  260. } else {
  261. sql = `SELECT COUNT(1) AS count FROM english_video WHERE classify_id_second=? `
  262. }
  263. err = o.Raw(sql, classifyId).QueryRow(&count)
  264. return
  265. }
  266. // UpdateEnglishVideoSecondClassifyNameByClassifyId 更新报告分类名称字段
  267. func UpdateEnglishVideoSecondClassifyNameByClassifyId(classifyId int, classifyName string) (err error) {
  268. o := orm.NewOrmUsingDB("rddp")
  269. sql := " UPDATE english_video SET classify_name_second = ? WHERE classify_id_second = ? "
  270. _, err = o.Raw(sql, classifyName, classifyId).Exec()
  271. return
  272. }
  273. // UpdateEnglishVideoFirstClassifyNameByClassifyId 更新报告分类名称字段
  274. func UpdateEnglishVideoFirstClassifyNameByClassifyId(classifyId int, classifyName string) (err error) {
  275. o := orm.NewOrmUsingDB("rddp")
  276. sql := " UPDATE english_video SET classify_name_first = ? WHERE classify_id_first = ? "
  277. _, err = o.Raw(sql, classifyName, classifyId).Exec()
  278. return
  279. }
  280. // UpdateEnglishVideoFirstClassifyNameByClassifyId 更新报告分类名称字段
  281. func UpdateEnglishVideoByClassifyId(classifyFirstName, classifySecondName string, firstClassifyId, secondClassifyId int, ids string) (err error) {
  282. o := orm.NewOrmUsingDB("rddp")
  283. sql := " UPDATE english_video SET classify_name_first = ?,classify_name_second = ?,classify_id_first=?, classify_id_second =? WHERE id IN (" + ids + ") "
  284. _, err = o.Raw(sql, classifyFirstName, classifySecondName, firstClassifyId, secondClassifyId).Exec()
  285. return
  286. }
  287. // GetEnglishVideoByIds 根据IDs获取英文报告列表
  288. func GetEnglishVideoByIds(Ids []int, fieldArr []string) (list []*EnglishVideo, err error) {
  289. listLen := len(Ids)
  290. if listLen == 0 {
  291. return
  292. }
  293. fields := ` * `
  294. if len(fieldArr) > 0 {
  295. fields = strings.Join(fieldArr, ",")
  296. }
  297. o := orm.NewOrmUsingDB("rddp")
  298. sql := `SELECT ` + fields + ` FROM english_video WHERE id IN (` + utils.GetOrmInReplace(listLen) + `)`
  299. _, err = o.Raw(sql, Ids).QueryRows(&list)
  300. return
  301. }