conf.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "strconv"
  6. "strings"
  7. "time"
  8. "go-common/app/job/live/xroom-feed/internal/model"
  9. "go-common/library/database/sql"
  10. "go-common/library/log"
  11. )
  12. const (
  13. _sqlConf = "select id, name, type, rules, module_type, position, percent, priority from ap_rec_pool_conf where is_del = 0 and (status = 2 or (status = 1 and start_time < '%s' and end_time > '%s'))"
  14. _sqlWhiteList = "select room_id from ap_rec_white_list where rec_id = %d and is_del = 0"
  15. )
  16. func (d *Dao) GetConfFromDb() (ruleConf []*model.RecPoolConf, err error) {
  17. var rows *sql.Rows
  18. ruleConf = make([]*model.RecPoolConf, 0)
  19. timeNow := time.Now().Format("2006-01-02 15:04:05")
  20. rows, err = d.liveAppDb.Query(context.TODO(), fmt.Sprintf(_sqlConf, timeNow, timeNow))
  21. if err != nil {
  22. log.Error("getConfFromDb_error:%+v", err)
  23. return
  24. }
  25. for rows.Next() {
  26. r := new(model.RecPoolConf)
  27. if err = rows.Scan(&r.Id, &r.Name, &r.ConfType, &r.Rules, &r.ModuleType, &r.Position, &r.Percent, &r.Priority); err != nil {
  28. log.Error("getConfFromDb_parseError:%+v", err)
  29. continue
  30. }
  31. ruleConf = append(ruleConf, r)
  32. }
  33. return
  34. }
  35. func (d *Dao) GetWhiteList(ctx context.Context, id int) (whiteStr string, err error) {
  36. //白名单获取
  37. var whiteRows *sql.Rows
  38. whiteRows, err = d.liveAppDb.Query(ctx, fmt.Sprintf(_sqlWhiteList, id))
  39. if err != nil {
  40. log.Error("getWhiteListFromDb_error:%+v", err)
  41. return
  42. }
  43. whiteList := make([]string, 0)
  44. for whiteRows.Next() {
  45. r := new(model.RecWhiteList)
  46. if err = whiteRows.Scan(&r.RoomId); err != nil {
  47. log.Error("getWhiteListFromDb_parseError:%+v", err)
  48. continue
  49. }
  50. if r.RoomId == 0 {
  51. continue
  52. }
  53. whiteList = append(whiteList, strconv.Itoa(r.RoomId))
  54. }
  55. if len(whiteList) <= 0 {
  56. return
  57. }
  58. whiteStr = strings.Join(whiteList, ",")
  59. return
  60. }