infoc.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. package view
  2. import (
  3. "bytes"
  4. "fmt"
  5. "strconv"
  6. "time"
  7. "go-common/app/interface/main/app-intl/conf"
  8. "go-common/app/interface/main/app-intl/model/view"
  9. "go-common/library/ecode"
  10. "go-common/library/log"
  11. "go-common/library/log/infoc"
  12. )
  13. // viewInfoc struct
  14. type viewInfoc struct {
  15. mid string
  16. client string
  17. build string
  18. buvid string
  19. disid string
  20. ip string
  21. api string
  22. now string
  23. aid string
  24. err string
  25. from string
  26. trackid string
  27. autoplay string
  28. }
  29. // relateInfoc struct
  30. type relateInfoc struct {
  31. mid string
  32. aid string
  33. client string
  34. buvid string
  35. disid string
  36. ip string
  37. api string
  38. now string
  39. isRcmmnd int8
  40. rls []*view.Relate
  41. trackid string
  42. build string
  43. returnCode string
  44. userFeature string
  45. from string
  46. }
  47. //ViewInfoc view infoc
  48. func (s *Service) ViewInfoc(mid int64, plat int, trackid, aid, ip, api, build, buvid, disid, from string, now time.Time, err error, autoplay int) {
  49. s.infoc(viewInfoc{strconv.FormatInt(mid, 10), strconv.Itoa(plat), build, buvid, disid, ip, api, strconv.FormatInt(now.Unix(), 10), aid, strconv.Itoa(ecode.Cause(err).Code()), from, trackid, strconv.Itoa(autoplay)})
  50. }
  51. // RelateInfoc Relate Infoc
  52. func (s *Service) RelateInfoc(mid, aid int64, plat int, trackid, build, buvid, disid, ip, api, returnCode, userFeature, from string, rls []*view.Relate, now time.Time, isRec int8) {
  53. s.infoc(relateInfoc{strconv.FormatInt(mid, 10), strconv.FormatInt(aid, 10), strconv.Itoa(plat), buvid, disid, ip, api, strconv.FormatInt(now.Unix(), 10), isRec, rls, trackid, build, returnCode, userFeature, from})
  54. }
  55. // infoc is.
  56. func (s *Service) infoc(i interface{}) {
  57. select {
  58. case s.inCh <- i:
  59. default:
  60. log.Warn("cacheproc chan full")
  61. }
  62. }
  63. // WriteViewInfoc Write View Infoc
  64. func (s *Service) infocproc() {
  65. const (
  66. noItem = `{"section":{"id":"相关视频","pos":1,"from_item":"%s","items":[]}}`
  67. )
  68. var (
  69. msg1 = []byte(`{"section":{"id":"相关视频","pos":1,"from_item":"`)
  70. msg2 = []byte(`","items":[`)
  71. msg3 = []byte(`{"id":`)
  72. msg4 = []byte(`,"pos":`)
  73. msg5 = []byte(`,"goto":"`)
  74. msg6 = []byte(`","from":"`)
  75. msg7 = []byte(`","source":"`)
  76. msg8 = []byte(`","av_feature":`)
  77. msg9 = []byte(`,"type":1,"url":""},`)
  78. infView = infoc.New(conf.Conf.ViewInfoc)
  79. infRelate = infoc.New(conf.Conf.RelateInfoc)
  80. buf bytes.Buffer
  81. list string
  82. )
  83. for {
  84. i := <-s.inCh
  85. switch v := i.(type) {
  86. case viewInfoc:
  87. infView.Info(v.ip, v.now, v.api, v.buvid, v.mid, v.client, v.aid, v.disid, v.err, v.from, v.build, v.trackid, v.autoplay)
  88. case relateInfoc:
  89. if len(v.rls) > 0 {
  90. buf.Write(msg1)
  91. buf.WriteString(v.aid)
  92. buf.Write(msg2)
  93. for key, value := range v.rls {
  94. buf.Write(msg3)
  95. buf.WriteString(strconv.Itoa(int(value.Aid)))
  96. buf.Write(msg4)
  97. buf.WriteString(strconv.Itoa(key + 1))
  98. buf.Write(msg5)
  99. buf.WriteString(value.Goto)
  100. buf.Write(msg6)
  101. buf.WriteString(value.From)
  102. buf.Write(msg7)
  103. buf.WriteString(value.Source)
  104. buf.Write(msg8)
  105. if value.AvFeature != nil {
  106. buf.Write(value.AvFeature)
  107. } else {
  108. buf.Write([]byte(`""`))
  109. }
  110. buf.Write(msg9)
  111. }
  112. buf.Truncate(buf.Len() - 1)
  113. buf.WriteString(`]}}`)
  114. list = buf.String()
  115. buf.Reset()
  116. } else {
  117. list = fmt.Sprintf(noItem, v.aid)
  118. }
  119. infRelate.Info(v.ip, v.now, v.api, v.buvid, v.mid, v.client, "2", list, v.disid, v.isRcmmnd, v.trackid, v.build, v.returnCode, v.userFeature, v.from)
  120. default:
  121. log.Warn("infocproc can't process the type")
  122. }
  123. }
  124. }