en_video_cover.go 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. package models
  2. import (
  3. "eta_gn/eta_api/global"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "time"
  6. )
  7. // EnglishVideoCover 英文研报视频封面库
  8. type EnglishVideoCover struct {
  9. Id int `gorm:"column:id;primaryKey;autoIncrement" description:"封面ID"`
  10. CoverName string `gorm:"column:cover_name" description:"封面名称"`
  11. CoverUrl string `gorm:"column:cover_url" description:"封面图地址"`
  12. IsDeleted int `gorm:"column:is_deleted" description:"是否已删除 0-否 1-是"`
  13. CreateTime time.Time `gorm:"column:create_time;autoCreateTime" description:"创建时间"`
  14. ModifyTime time.Time `gorm:"column:modify_time;autoUpdateTime" description:"修改时间"`
  15. DeleteTime time.Time `gorm:"column:delete_time" description:"删除时间"`
  16. }
  17. func (item *EnglishVideoCover) TableName() string {
  18. return "english_video_cover"
  19. }
  20. func (item *EnglishVideoCover) Add() (err error) {
  21. err = global.DmSQL["rddp"].Create(item).Error
  22. return
  23. }
  24. func (item *EnglishVideoCover) Update(cols []string) (err error) {
  25. err = global.DmSQL["rddp"].Select(cols).Updates(item).Error
  26. return
  27. }
  28. // GetEnglishVideoCoverById 主键获取封面
  29. func GetEnglishVideoCoverById(coverId int) (item *EnglishVideoCover, err error) {
  30. sql := `SELECT * FROM english_video_cover WHERE id = ? AND is_deleted = 0 LIMIT 1`
  31. err = global.DmSQL["rddp"].Raw(sql, coverId).First(&item).Error
  32. return
  33. }
  34. // GetEnglishVideoCoverPageList 获取封面库分页列表
  35. func GetEnglishVideoCoverPageList(condition string, pars []interface{}, orderRule string, startSize, pageSize int) (total int, list []*EnglishVideoCover, err error) {
  36. sql := `SELECT * FROM english_video_cover WHERE is_deleted = 0 `
  37. sql += condition
  38. if orderRule == "" {
  39. orderRule = ` ORDER BY modify_time DESC`
  40. }
  41. sql += orderRule
  42. totalSQL := `SELECT COUNT(1) total FROM (` + sql + `) z`
  43. if err = global.DmSQL["rddp"].Raw(totalSQL, pars...).Scan(&total).Error; err != nil {
  44. return
  45. }
  46. sql += ` LIMIT ?,?`
  47. pars = append(pars, startSize)
  48. pars = append(pars, pageSize)
  49. err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&list).Error
  50. return
  51. }
  52. // DeleteEnglishVideoCover 删除封面
  53. func DeleteEnglishVideoCover(coverId int) (err error) {
  54. sql := `UPDATE english_video_cover SET is_deleted = 1, delete_time = NOW() WHERE id = ? LIMIT 1`
  55. err = global.DmSQL["rddp"].Exec(sql, coverId).Error
  56. return
  57. }
  58. type EnglishVideoCoverListResp struct {
  59. Paging *paging.PagingItem
  60. List []*EnglishVideoCoverItem `description:"列表数据"`
  61. }
  62. type EnglishVideoCoverItem struct {
  63. Id int `description:"封面ID"`
  64. CoverName string `description:"封面名称"`
  65. CoverUrl string `description:"封面图地址"`
  66. CreateTime string `description:"提问时间"`
  67. ModifyTime string `description:"修改时间"`
  68. }
  69. type EnglishVideoCoverSaveReq struct {
  70. Id int `description:"封面ID"`
  71. CoverName string `description:"封面名称"`
  72. CoverUrl string `description:"封面图地址"`
  73. }
  74. type EnglishVideoCoverOptionReq struct {
  75. Id int `description:"封面图ID"`
  76. }