eta_training_video_classify.go 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. package eta_training_video
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "strings"
  6. "time"
  7. )
  8. // EtaTrainingVideoClassify 视频分类
  9. type EtaTrainingVideoClassify struct {
  10. EtaTrainingVideoClassifyId int `orm:"column(eta_training_video_classify_id);pk"`
  11. ClassifyName string `description:"视频分类名称"`
  12. ParentId int `description:"父级ID"`
  13. Sort int `description:"排序"`
  14. SysUserId int `description:"创建人ID"`
  15. SysRealName string `description:"创建人姓名"`
  16. CreateTime time.Time `description:"创建时间"`
  17. ModifyTime time.Time `description:"更新时间"`
  18. }
  19. func (m *EtaTrainingVideoClassify) TableName() string {
  20. return "eta_training_video_classify"
  21. }
  22. func (m *EtaTrainingVideoClassify) PrimaryId() string {
  23. return VideoClassifyColumns.EtaTrainingVideoClassifyId
  24. }
  25. var VideoClassifyColumns = struct {
  26. EtaTrainingVideoClassifyId string
  27. ClassifyName string
  28. ParentId string
  29. Sort string
  30. SysUserId string
  31. SysRealName string
  32. CreateTime string
  33. ModifyTime string
  34. }{
  35. EtaTrainingVideoClassifyId: "eta_training_video_classify_id",
  36. ClassifyName: "classify_name",
  37. ParentId: "parent_id",
  38. Sort: "sort",
  39. SysUserId: "sys_user_id",
  40. SysRealName: "sys_real_name",
  41. CreateTime: "create_time",
  42. ModifyTime: "modify_time",
  43. }
  44. func (m *EtaTrainingVideoClassify) Create() (err error) {
  45. o := orm.NewOrm()
  46. id, err := o.Insert(m)
  47. if err != nil {
  48. return
  49. }
  50. m.EtaTrainingVideoClassifyId = int(id)
  51. return
  52. }
  53. func (m *EtaTrainingVideoClassify) CreateMulti(items []*EtaTrainingVideoClassify) (err error) {
  54. if len(items) == 0 {
  55. return
  56. }
  57. o := orm.NewOrm()
  58. _, err = o.InsertMulti(len(items), items)
  59. return
  60. }
  61. func (m *EtaTrainingVideoClassify) Update(cols []string) (err error) {
  62. o := orm.NewOrm()
  63. _, err = o.Update(m, cols...)
  64. return
  65. }
  66. func (m *EtaTrainingVideoClassify) Del() (err error) {
  67. o := orm.NewOrm()
  68. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  69. _, err = o.Raw(sql, m.EtaTrainingVideoClassifyId).Exec()
  70. return
  71. }
  72. func (m *EtaTrainingVideoClassify) GetItemById(id int) (item *EtaTrainingVideoClassify, err error) {
  73. o := orm.NewOrm()
  74. sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  75. err = o.Raw(sql, id).QueryRow(&item)
  76. return
  77. }
  78. func (m *EtaTrainingVideoClassify) GetItemByCondition(condition string, pars []interface{}) (item *EtaTrainingVideoClassify, err error) {
  79. o := orm.NewOrm()
  80. sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s LIMIT 1`, m.TableName(), condition)
  81. err = o.Raw(sql, pars).QueryRow(&item)
  82. return
  83. }
  84. func (m *EtaTrainingVideoClassify) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  85. o := orm.NewOrm()
  86. sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
  87. err = o.Raw(sql, pars).QueryRow(&count)
  88. return
  89. }
  90. func (m *EtaTrainingVideoClassify) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*EtaTrainingVideoClassify, err error) {
  91. o := orm.NewOrm()
  92. fields := strings.Join(fieldArr, ",")
  93. if len(fieldArr) == 0 {
  94. fields = `*`
  95. }
  96. order := `ORDER BY create_time DESC`
  97. if orderRule != "" {
  98. order = ` ORDER BY ` + orderRule
  99. }
  100. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  101. _, err = o.Raw(sql, pars).QueryRows(&items)
  102. return
  103. }
  104. func (m *EtaTrainingVideoClassify) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*EtaTrainingVideoClassify, err error) {
  105. o := orm.NewOrm()
  106. fields := strings.Join(fieldArr, ",")
  107. if len(fieldArr) == 0 {
  108. fields = `*`
  109. }
  110. order := `ORDER BY create_time DESC`
  111. if orderRule != "" {
  112. order = ` ORDER BY ` + orderRule
  113. }
  114. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
  115. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  116. return
  117. }
  118. // EtaTrainingVideoClassifyAddReq 新增视频分类请求体
  119. type EtaTrainingVideoClassifyAddReq struct {
  120. ParentId int `description:"父级ID"`
  121. ClassifyName string `description:"视频分类名称"`
  122. }
  123. // EtaTrainingVideoClassifyEditReq 编辑视频分类请求体
  124. type EtaTrainingVideoClassifyEditReq struct {
  125. ClassifyId int `description:"视频分类ID"`
  126. EtaTrainingVideoClassifyAddReq
  127. }
  128. // EtaTrainingVideoClassifyRemoveReq 删除视频分类请求体
  129. type EtaTrainingVideoClassifyRemoveReq struct {
  130. ClassifyId int `description:"视频分类ID"`
  131. }
  132. // EtaTrainingVideoClassifyResp 视频分类响应体
  133. type EtaTrainingVideoClassifyResp struct {
  134. List []*EtaTrainingVideoClassifyItem
  135. }
  136. // EtaTrainingVideoClassifyItem 视频分类信息
  137. type EtaTrainingVideoClassifyItem struct {
  138. ClassifyId int `description:"视频分类ID"`
  139. ClassifyName string `description:"视频分类名称"`
  140. ParentId int `description:"父级ID"`
  141. Sort int `description:"排序"`
  142. Children []*EtaTrainingVideoClassifyItem
  143. }