voice_section.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package yb
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. )
  5. type VoiceSection struct {
  6. SectionId int `orm:"column(section_id);pk" description:"板块id"`
  7. SectionName string `description:"板块名称"`
  8. ImgUrl string `description:"背景图url"`
  9. VarietyId int `description:"品种id"`
  10. VarietyName string `description:"品种名称"`
  11. Status int `description:"角色状态"`
  12. CreateTime string `description:"创建时间"`
  13. }
  14. // TableName 表名变更
  15. func (voiceSection *VoiceSection) TableName() string {
  16. return "yb_voice_section"
  17. }
  18. func GetVoiceSectionList(startSize, pageSize int) (list []*VoiceSection, err error) {
  19. o := orm.NewOrm()
  20. sql := "SELECT * FROM yb_voice_section ORDER BY create_time DESC limit ?, ? "
  21. _, err = o.Raw(sql, startSize, pageSize).QueryRows(&list)
  22. return
  23. }
  24. func AddVoiceSection(item VoiceSection) (err error) {
  25. o := orm.NewOrm()
  26. _, err = o.Insert(&item)
  27. if err != nil {
  28. return err
  29. }
  30. return
  31. }
  32. func GetVoiceSectionTotal() (total int, err error) {
  33. o := orm.NewOrm()
  34. sql := "SELECT COUNT(1) AS ct FROM yb_voice_section "
  35. err = o.Raw(sql).QueryRow(&total)
  36. return
  37. }
  38. func GetVoiceSectionEnableTotal() (total int, err error) {
  39. o := orm.NewOrm()
  40. sql := "SELECT COUNT(1) AS ct FROM yb_voice_section WHERE status=1 "
  41. err = o.Raw(sql).QueryRow(&total)
  42. return
  43. }
  44. func EditVoiceSection(condition string, pars []interface{}) (err error) {
  45. o := orm.NewOrm()
  46. sql := "UPDATE yb_voice_section SET status=? WHERE 1=1 "
  47. if condition != "" {
  48. sql += condition
  49. }
  50. _, err = o.Raw(sql, pars).Exec()
  51. return
  52. }
  53. // Update 更新语音播报板块
  54. func (voiceSection *VoiceSection) Update(cols []string) (err error) {
  55. o := orm.NewOrm()
  56. _, err = o.Update(voiceSection, cols...)
  57. return
  58. }
  59. // GetAllEnableVoiceSectionList 获取所有启用的语言播报版块
  60. func GetAllEnableVoiceSectionList() (list []*VoiceSection, err error) {
  61. o := orm.NewOrm()
  62. sql := "SELECT * FROM yb_voice_section where status=1 ORDER BY create_time ASC "
  63. _, err = o.Raw(sql).QueryRows(&list)
  64. return
  65. }
  66. // GetVoiceSectionById 根据版块id来获取版块信息
  67. func GetVoiceSectionById(sectionId int) (item *VoiceSection, err error) {
  68. o := orm.NewOrm()
  69. sql := "SELECT * FROM yb_voice_section WHERE section_id= ? "
  70. err = o.Raw(sql, sectionId).QueryRow(&item)
  71. return
  72. }