config.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. package archive
  2. import (
  3. "context"
  4. "database/sql"
  5. "encoding/json"
  6. "strconv"
  7. "strings"
  8. "go-common/app/job/main/videoup/model/archive"
  9. "go-common/library/log"
  10. "go-common/library/xstr"
  11. )
  12. const (
  13. _confSQL = "SELECT value FROM archive_config WHERE state=0 AND name=?"
  14. )
  15. //RoundEndConf round_delay_time 正常状态的配置
  16. func (d *Dao) RoundEndConf(c context.Context) (days int64, err error) {
  17. row := d.db.QueryRow(c, _confSQL, archive.ConfForRoundEnd)
  18. var val string
  19. if err = row.Scan(&val); err != nil {
  20. if err == sql.ErrNoRows {
  21. err = nil
  22. } else {
  23. log.Error("row.Scan error(%v)", err)
  24. }
  25. return
  26. }
  27. if days, err = strconv.ParseInt(val, 10, 64); err != nil {
  28. log.Error("srconv.ParseInt(%s) error(%v)", val, err)
  29. }
  30. return
  31. }
  32. //FansConf round_limit_fans正常状态的配置
  33. func (d *Dao) FansConf(c context.Context) (fans int64, err error) {
  34. row := d.db.QueryRow(c, _confSQL, archive.ConfForClick)
  35. var val string
  36. if err = row.Scan(&val); err != nil {
  37. if err == sql.ErrNoRows {
  38. err = nil
  39. } else {
  40. log.Error("row.Scan error(%v)", err)
  41. }
  42. return
  43. }
  44. if fans, err = strconv.ParseInt(val, 10, 64); err != nil {
  45. log.Error("strconv.ParseInt(%s) error(%v)", val, err)
  46. }
  47. return
  48. }
  49. //RoundTypeConf round_limit_tids 正常状态的配置
  50. func (d *Dao) RoundTypeConf(c context.Context) (roundTypes map[int16]struct{}, err error) {
  51. roundTypes = map[int16]struct{}{}
  52. row := d.db.QueryRow(c, _confSQL, archive.ConfForRoundType)
  53. var (
  54. val string
  55. tids []string
  56. tid int64
  57. )
  58. if err = row.Scan(&val); err != nil {
  59. if err == sql.ErrNoRows {
  60. err = nil
  61. } else {
  62. log.Error("row.Scan error(%v)", err)
  63. }
  64. return
  65. }
  66. tids = strings.Split(val, ",")
  67. for _, tidStr := range tids {
  68. if tid, err = strconv.ParseInt(tidStr, 10, 64); err != nil {
  69. log.Error("strconv.ParseInt(%d) error(%v)", tid, err)
  70. return
  71. }
  72. roundTypes[int16(tid)] = struct{}{}
  73. }
  74. return
  75. }
  76. //AuditTypesConf wait_audit_arctype 状态正常的配置
  77. func (d *Dao) AuditTypesConf(c context.Context) (atps map[int16]struct{}, err error) {
  78. row := d.db.QueryRow(c, _confSQL, archive.ConfForAuditType)
  79. var (
  80. value string
  81. typeIDs []int64
  82. )
  83. if err = row.Scan(&value); err != nil {
  84. if err == sql.ErrNoRows {
  85. err = nil
  86. } else {
  87. log.Error("row.Scan error(%v)", err)
  88. }
  89. return
  90. }
  91. typeIDs, err = xstr.SplitInts(value)
  92. if err != nil {
  93. log.Error("archive_config value(%s) xstr.SplitInts error(%v)", value, err)
  94. return
  95. }
  96. atps = map[int16]struct{}{}
  97. for _, typeid := range typeIDs {
  98. atps[int16(typeid)] = struct{}{}
  99. }
  100. return
  101. }
  102. //ThresholdConf ThresholdConf is second types opposite first types.
  103. func (d *Dao) ThresholdConf(c context.Context) (tpThr map[int16]int, err error) {
  104. row := d.db.QueryRow(c, _confSQL, archive.ConfForThreshold)
  105. var value string
  106. if err = row.Scan(&value); err != nil {
  107. if err == sql.ErrNoRows {
  108. err = nil
  109. } else {
  110. log.Error("row.Scan() error(%v)", err)
  111. }
  112. return
  113. }
  114. if err = json.Unmarshal([]byte(value), &tpThr); err != nil {
  115. log.Error("json.Unmarshal(%s) error(%v)", value, err)
  116. return
  117. }
  118. return
  119. }