style.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package report
  2. import (
  3. "context"
  4. "strings"
  5. "time"
  6. mdlpgc "go-common/app/job/main/tv/model/pgc"
  7. "go-common/library/log"
  8. )
  9. func (s *Service) showStyle() {
  10. var (
  11. err error
  12. res []*mdlpgc.StyleRes
  13. styleStr []*mdlpgc.ParamStyle
  14. styleRes = make(map[int][]*mdlpgc.ParamStyle)
  15. ctx = context.Background()
  16. )
  17. for {
  18. if res, err = s.dao.FindStyle(ctx); err != nil {
  19. log.Error("s.dao.FindStyle error(%v)", err)
  20. time.Sleep(time.Second * 5)
  21. continue
  22. }
  23. if len(res) != 0 {
  24. for _, v := range res {
  25. styleStr = make([]*mdlpgc.ParamStyle, 0)
  26. if m, ok := s.labelRes[v.Category]; ok {
  27. a := strings.Split(v.Style, ",")
  28. for _, v1 := range a {
  29. r := &mdlpgc.ParamStyle{}
  30. if m1, ok1 := m[v1]; ok1 {
  31. r.Name = v1
  32. r.StyleID = m1
  33. styleStr = append(styleStr, r)
  34. }
  35. }
  36. if len(styleStr) != 0 {
  37. styleRes[v.ID] = styleStr
  38. }
  39. }
  40. }
  41. }
  42. if len(styleRes) > 0 {
  43. s.cache.Do(ctx, func(ctx context.Context) {
  44. // set style data to mc
  45. s.dao.SetStyleCache(ctx, styleRes)
  46. })
  47. }
  48. time.Sleep(time.Duration(s.c.Style.StyleSpan))
  49. }
  50. }
  51. func (s *Service) showLabel() {
  52. var (
  53. err error
  54. res map[int]map[string]int
  55. ctx = context.Background()
  56. )
  57. for {
  58. if res, err = s.dao.FindLabelID(ctx); err != nil {
  59. log.Error("s.dao.FindLabelID error(%v)", err)
  60. time.Sleep(time.Second * 5)
  61. continue
  62. }
  63. if len(res) != 0 {
  64. s.labelRes = res
  65. s.cache.Do(ctx, func(ctx context.Context) {
  66. // set label data to mc
  67. s.dao.SetLabelCache(ctx, s.labelRes)
  68. })
  69. }
  70. time.Sleep(time.Duration(s.c.Style.LabelSpan))
  71. }
  72. }
  73. func (s *Service) readLabelCache() {
  74. var (
  75. err error
  76. m map[int]map[string]int
  77. )
  78. if m, err = s.dao.GetLabelCache(context.Background()); err != nil {
  79. log.Error("s.dao.GetLabelCache error(%v)", err)
  80. panic(err)
  81. }
  82. s.labelRes = m
  83. }