voice_section.go 2.6 KB

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