query.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package voice_broadcast
  2. import "hongze/hongze_yb/global"
  3. func GetBroadcastByCondition(pageIndex, pageSize, sectionId int) (list []*VoiceBroadcast, err error) {
  4. offset := (pageIndex - 1) * pageSize
  5. err = global.DEFAULT_MYSQL.Model(VoiceBroadcast{}).Where("section_id=?", sectionId).Offset(offset).Limit(pageSize).Order("create_time DESC").Scan(&list).Error
  6. return
  7. }
  8. func GetBroadcastByIdAndPage(pageIndex, pageSize, broadcastId int) (list []*VoiceBroadcast, err error) {
  9. offset := (pageIndex - 1) * pageSize
  10. err = global.DEFAULT_MYSQL.Model(VoiceBroadcast{}).Where("broadcast_id=?", broadcastId).Offset(offset).Limit(pageSize).Order("create_time DESC").Scan(&list).Error
  11. return
  12. }
  13. func GetBroadcast(pageIndex, pageSize int) (list []*VoiceBroadcast, err error) {
  14. offset := (pageIndex - 1) * pageSize
  15. err = global.DEFAULT_MYSQL.Model(VoiceBroadcast{}).Offset(offset).Limit(pageSize).Order("create_time DESC").Scan(&list).Error
  16. return
  17. }
  18. func GetBroadcastById(broadcastId int) (item *VoiceBroadcast, err error) {
  19. err = global.DEFAULT_MYSQL.Model(VoiceBroadcast{}).Where("broadcast_id=?", broadcastId).First(&item).Error
  20. return
  21. }
  22. func GetBroadcastList() (list []*VoiceBroadcast, err error) {
  23. err = global.DEFAULT_MYSQL.Model(VoiceBroadcast{}).Scan(&list).Error
  24. return
  25. }
  26. func GetPageListByCondition(condition string, pars []interface{}, pageIndex, pageSize int) (list []*VoiceBroadcast, err error) {
  27. offset := (pageIndex - 1) * pageSize
  28. err = global.DEFAULT_MYSQL.Model(VoiceBroadcast{}).
  29. Where(condition, pars...).
  30. Offset(offset).Limit(pageSize).
  31. Order("create_time DESC").
  32. Scan(&list).Error
  33. return
  34. }
  35. type VoiceBroadcastListStatusCount struct {
  36. Num int `json:"num" description:"计数"`
  37. State int `json:"state" description:"状态:0-未发布 1-已发布"`
  38. }
  39. // GetVoiceBroadcastListStatusCount 获取语音播报列表计数-根据状态分组
  40. func GetVoiceBroadcastListStatusCount(condition string, pars []interface{}) (list []*VoiceBroadcastListStatusCount, err error) {
  41. err = global.DEFAULT_MYSQL.Model(VoiceBroadcast{}).
  42. Where(condition, pars...).
  43. Select("COUNT(1) AS num, publish_state AS state").
  44. Group("state").
  45. Scan(&list).Error
  46. return
  47. }