config.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/interface/live/push-live/model"
  5. "go-common/library/log"
  6. )
  7. const (
  8. _getPushConfig = "SELECT `type` FROM ap_push_config WHERE value=? ORDER BY `order` ASC" // 获取推送选项配置
  9. _getPushInterval = "SELECT `order` FROM ap_push_config WHERE type=?" // 获取推送间隔时间
  10. )
  11. // GetPushConfig 从DB中获取推送配置
  12. func (d *Dao) GetPushConfig(c context.Context) (types []string, err error) {
  13. var t string
  14. types = make([]string, 0)
  15. rows, err := d.db.Query(c, _getPushConfig, model.LivePushConfigOn)
  16. if err != nil {
  17. log.Error("[dao.config|GetPushConfig] db.Query() error(%v)", err)
  18. return
  19. }
  20. for rows.Next() {
  21. if err = rows.Scan(&t); err != nil {
  22. log.Error("[dao.config|GetPushConfig] rows.Scan() error(%v)", err)
  23. return
  24. }
  25. types = append(types, t)
  26. }
  27. return
  28. }
  29. // GetPushInterval 获取推送时间间隔
  30. func (d *Dao) GetPushInterval(c context.Context) (interval int32, err error) {
  31. var i int32
  32. row := d.db.QueryRow(c, _getPushInterval, model.PushIntervalKey)
  33. if err = row.Scan(&i); err != nil {
  34. log.Error("[dao.config|GetPushInterval] row.Scan() error(%v)", err)
  35. return
  36. }
  37. interval = i * 60 // min to sec
  38. return
  39. }