style.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package report
  2. import (
  3. "context"
  4. mdlpgc "go-common/app/job/main/tv/model/pgc"
  5. "go-common/library/database/sql"
  6. "go-common/library/log"
  7. )
  8. const (
  9. _styleSQL = "SELECT id,style,category FROM tv_ep_season WHERE is_deleted=0 AND `check`=1 AND valid=1"
  10. _labelSQL = `SELECT name,value,category FROM tv_label WHERE deleted=0 AND param="style_id" AND valid=1`
  11. )
  12. // FindStyle style all .
  13. func (d *Dao) FindStyle(ctx context.Context) (res []*mdlpgc.StyleRes, err error) {
  14. var (
  15. rows *sql.Rows
  16. )
  17. if rows, err = d.DB.Query(ctx, _styleSQL); err != nil {
  18. log.Error("d.DB.Query sql(%s) error(%v)", _styleSQL, err)
  19. return
  20. }
  21. defer rows.Close()
  22. for rows.Next() {
  23. r := &mdlpgc.StyleRes{}
  24. if err = rows.Scan(&r.ID, &r.Style, &r.Category); err != nil {
  25. log.Error("d.DB.QueryRow error(%v)", err)
  26. return
  27. }
  28. res = append(res, r)
  29. }
  30. if err = rows.Err(); err != nil {
  31. log.Error("rows.Err() error(%v)", err)
  32. }
  33. return
  34. }
  35. // FindLabelID label all .
  36. func (d *Dao) FindLabelID(ctx context.Context) (res map[int]map[string]int, err error) {
  37. var (
  38. rows *sql.Rows
  39. m map[string]int
  40. )
  41. res = make(map[int]map[string]int)
  42. if rows, err = d.DB.Query(ctx, _labelSQL); err != nil {
  43. log.Error("d.DB.Query error(%v)", err)
  44. return
  45. }
  46. defer rows.Close()
  47. for rows.Next() {
  48. r := &mdlpgc.LabelRes{}
  49. if err = rows.Scan(&r.Name, &r.Value, &r.Category); err != nil {
  50. log.Error("d.DB.Query Scan error(%v)", err)
  51. return
  52. }
  53. if _, ok := res[r.Category]; ok {
  54. m[r.Name] = r.Value
  55. } else {
  56. m = make(map[string]int)
  57. }
  58. res[r.Category] = m
  59. }
  60. if err = rows.Err(); err != nil {
  61. log.Error("rows.Err() error(%v)", err)
  62. }
  63. return
  64. }