english_video.go 13 KB

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