yb_voice_broadcast.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package yb
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type VoiceBroadcast struct {
  7. BroadcastId int `gorm:"primaryKey;column:broadcast_id;type:int(11)" description:"语音ID"`
  8. BroadcastName string `description:"语音名称"`
  9. SectionId int `description:"语音分类ID"`
  10. SectionName string `description:"语音分类名称"`
  11. VarietyId int `description:"品种id"`
  12. VarietyName string `description:"品种名称"`
  13. AuthorId int `description:"作者id"`
  14. Author string `description:"作者"`
  15. ImgUrl string `description:"背景图url"`
  16. VoiceUrl string `description:"音频url"`
  17. VoicePlaySeconds string `description:"音频时长"`
  18. VoiceSize string `description:"音频大小"`
  19. CreateTime time.Time `description:"创建时间"`
  20. ModifyTime time.Time `description:"更新时间"`
  21. PublishState int `description:"发布状态:0-未发布 1-已发布"`
  22. PublishTime time.Time `description:"发布时间"`
  23. PrePublishTime time.Time `description:"预发布时间"`
  24. MsgState int `description:"消息推送状态:0-待推送 1-已推送"`
  25. MsgTime time.Time `description:"消息推送时间"`
  26. }
  27. // TableName get sql table name.获取数据库表名
  28. func (m *VoiceBroadcast) TableName() string {
  29. return "yb_voice_broadcast"
  30. }
  31. func (item *VoiceBroadcast) Update(cols []string) (err error) {
  32. o := orm.NewOrm()
  33. _, err = o.Update(item, cols...)
  34. return
  35. }
  36. func GetBroadcastById(broadcastId int) (item *VoiceBroadcast, err error) {
  37. o := orm.NewOrm()
  38. sql := `SELECT * FROM yb_voice_broadcast WHERE broadcast_id = ? LIMIT 1`
  39. err = o.Raw(sql, broadcastId).QueryRow(&item)
  40. return
  41. }
  42. // GetUnpublishedVoiceBroadcastList 获取未发布的语音播报列表
  43. func GetUnpublishedVoiceBroadcastList() (list []*VoiceBroadcast, err error) {
  44. o := orm.NewOrm()
  45. sql := `SELECT * FROM yb_voice_broadcast WHERE publish_state = 0 `
  46. _, err = o.Raw(sql).QueryRows(&list)
  47. return
  48. }
  49. // PublishVoiceBroadcast 发布语音播报
  50. func PublishVoiceBroadcast(broadcastId int) (err error) {
  51. o := orm.NewOrm()
  52. sql := `UPDATE yb_voice_broadcast
  53. SET publish_state = 1, publish_time = NOW(), msg_state = 1, msg_time = NOW()
  54. WHERE
  55. broadcast_id = ?
  56. LIMIT 1`
  57. _, err = o.Raw(sql, broadcastId).Exec()
  58. return
  59. }