123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- package archive
- import (
- "context"
- "database/sql"
- "encoding/json"
- "strconv"
- "strings"
- "go-common/app/job/main/videoup/model/archive"
- "go-common/library/log"
- "go-common/library/xstr"
- )
- const (
- _confSQL = "SELECT value FROM archive_config WHERE state=0 AND name=?"
- )
- //RoundEndConf round_delay_time 正常状态的配置
- func (d *Dao) RoundEndConf(c context.Context) (days int64, err error) {
- row := d.db.QueryRow(c, _confSQL, archive.ConfForRoundEnd)
- var val string
- if err = row.Scan(&val); err != nil {
- if err == sql.ErrNoRows {
- err = nil
- } else {
- log.Error("row.Scan error(%v)", err)
- }
- return
- }
- if days, err = strconv.ParseInt(val, 10, 64); err != nil {
- log.Error("srconv.ParseInt(%s) error(%v)", val, err)
- }
- return
- }
- //FansConf round_limit_fans正常状态的配置
- func (d *Dao) FansConf(c context.Context) (fans int64, err error) {
- row := d.db.QueryRow(c, _confSQL, archive.ConfForClick)
- var val string
- if err = row.Scan(&val); err != nil {
- if err == sql.ErrNoRows {
- err = nil
- } else {
- log.Error("row.Scan error(%v)", err)
- }
- return
- }
- if fans, err = strconv.ParseInt(val, 10, 64); err != nil {
- log.Error("strconv.ParseInt(%s) error(%v)", val, err)
- }
- return
- }
- //RoundTypeConf round_limit_tids 正常状态的配置
- func (d *Dao) RoundTypeConf(c context.Context) (roundTypes map[int16]struct{}, err error) {
- roundTypes = map[int16]struct{}{}
- row := d.db.QueryRow(c, _confSQL, archive.ConfForRoundType)
- var (
- val string
- tids []string
- tid int64
- )
- if err = row.Scan(&val); err != nil {
- if err == sql.ErrNoRows {
- err = nil
- } else {
- log.Error("row.Scan error(%v)", err)
- }
- return
- }
- tids = strings.Split(val, ",")
- for _, tidStr := range tids {
- if tid, err = strconv.ParseInt(tidStr, 10, 64); err != nil {
- log.Error("strconv.ParseInt(%d) error(%v)", tid, err)
- return
- }
- roundTypes[int16(tid)] = struct{}{}
- }
- return
- }
- //AuditTypesConf wait_audit_arctype 状态正常的配置
- func (d *Dao) AuditTypesConf(c context.Context) (atps map[int16]struct{}, err error) {
- row := d.db.QueryRow(c, _confSQL, archive.ConfForAuditType)
- var (
- value string
- typeIDs []int64
- )
- if err = row.Scan(&value); err != nil {
- if err == sql.ErrNoRows {
- err = nil
- } else {
- log.Error("row.Scan error(%v)", err)
- }
- return
- }
- typeIDs, err = xstr.SplitInts(value)
- if err != nil {
- log.Error("archive_config value(%s) xstr.SplitInts error(%v)", value, err)
- return
- }
- atps = map[int16]struct{}{}
- for _, typeid := range typeIDs {
- atps[int16(typeid)] = struct{}{}
- }
- return
- }
- //ThresholdConf ThresholdConf is second types opposite first types.
- func (d *Dao) ThresholdConf(c context.Context) (tpThr map[int16]int, err error) {
- row := d.db.QueryRow(c, _confSQL, archive.ConfForThreshold)
- var value string
- if err = row.Scan(&value); err != nil {
- if err == sql.ErrNoRows {
- err = nil
- } else {
- log.Error("row.Scan() error(%v)", err)
- }
- return
- }
- if err = json.Unmarshal([]byte(value), &tpThr); err != nil {
- log.Error("json.Unmarshal(%s) error(%v)", value, err)
- return
- }
- return
- }
|