auto_case.go 1008 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package dao
  2. import (
  3. "context"
  4. "database/sql"
  5. "go-common/app/job/main/credit/model"
  6. "go-common/library/log"
  7. "go-common/library/xstr"
  8. )
  9. const (
  10. _autoCaseConfigSQL = "SELECT reasons,report_score,likes FROM blocked_auto_case WHERE platform = ?"
  11. )
  12. // AutoCaseConf get auto case config.
  13. func (d *Dao) AutoCaseConf(c context.Context, otype int8) (ac *model.AutoCaseConf, err error) {
  14. ac = &model.AutoCaseConf{}
  15. row := d.db.QueryRow(c, _autoCaseConfigSQL, otype)
  16. if err = row.Scan(&ac.ReasonStr, &ac.ReportScore, &ac.Likes); err != nil {
  17. if err != sql.ErrNoRows {
  18. log.Error("d.AutoCaseConf err(%v)", err)
  19. return
  20. }
  21. ac = nil
  22. err = nil
  23. }
  24. if ac != nil && ac.ReasonStr != "" {
  25. var reasonSlice []int64
  26. if reasonSlice, err = xstr.SplitInts(ac.ReasonStr); err != nil {
  27. log.Error("xstr.SplitInts(%s) err(%v)", ac.ReasonStr, err)
  28. return
  29. }
  30. ac.Reasons = make(map[int8]struct{}, len(reasonSlice))
  31. for _, v := range reasonSlice {
  32. ac.Reasons[int8(v)] = struct{}{}
  33. }
  34. }
  35. return
  36. }