infoc.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. package view
  2. import (
  3. "bytes"
  4. "fmt"
  5. "strconv"
  6. "time"
  7. "go-common/app/interface/main/app-view/conf"
  8. "go-common/app/interface/main/app-view/model/view"
  9. "go-common/library/ecode"
  10. "go-common/library/log"
  11. "go-common/library/log/infoc"
  12. )
  13. type viewInfoc struct {
  14. mid string
  15. client string
  16. build string
  17. buvid string
  18. disid string
  19. ip string
  20. api string
  21. now string
  22. aid string
  23. err string
  24. from string
  25. trackid string
  26. autoplay string
  27. fromSpmid string
  28. spmid string
  29. }
  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, spmid, fromSpmid string) {
  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), fromSpmid, spmid})
  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. func (s *Service) infoc(i interface{}) {
  56. select {
  57. case s.inCh <- i:
  58. default:
  59. log.Warn("cacheproc chan full")
  60. }
  61. }
  62. // WriteViewInfoc Write View Infoc
  63. func (s *Service) infocproc() {
  64. const (
  65. noItem = `{"section":{"id":"相关视频","pos":1,"from_item":"%s","items":[]}}`
  66. )
  67. var (
  68. msg1 = []byte(`{"section":{"id":"相关视频","pos":1,"from_item":"`)
  69. msg2 = []byte(`","items":[`)
  70. msg3 = []byte(`{"id":`)
  71. msg4 = []byte(`,"pos":`)
  72. msg5 = []byte(`,"goto":"`)
  73. msg6 = []byte(`","from":"`)
  74. msg7 = []byte(`","source":"`)
  75. msg8 = []byte(`","av_feature":`)
  76. msg9 = []byte(`,"type":1,"url":""},`)
  77. infView = infoc.New(conf.Conf.InfocView)
  78. infRelate = infoc.New(conf.Conf.InfocRelate)
  79. buf bytes.Buffer
  80. list string
  81. )
  82. for {
  83. i := <-s.inCh
  84. switch v := i.(type) {
  85. case viewInfoc:
  86. 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, v.fromSpmid, v.spmid)
  87. case relateInfoc:
  88. var trackID string
  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. // trackid
  95. if value.TrackID != "" {
  96. trackID = value.TrackID
  97. }
  98. //list
  99. id, _ := strconv.ParseInt(value.Param, 10, 64)
  100. buf.Write(msg3)
  101. buf.WriteString(strconv.FormatInt(id, 10))
  102. buf.Write(msg4)
  103. buf.WriteString(strconv.Itoa(key + 1))
  104. buf.Write(msg5)
  105. buf.WriteString(value.Goto)
  106. buf.Write(msg6)
  107. buf.WriteString(value.From)
  108. buf.Write(msg7)
  109. buf.WriteString(value.Source)
  110. buf.Write(msg8)
  111. if value.AvFeature != nil {
  112. buf.Write(value.AvFeature)
  113. } else {
  114. buf.Write([]byte(`""`))
  115. }
  116. buf.Write(msg9)
  117. }
  118. buf.Truncate(buf.Len() - 1)
  119. buf.WriteString(`]}}`)
  120. list = buf.String()
  121. buf.Reset()
  122. } else {
  123. list = fmt.Sprintf(noItem, v.aid)
  124. }
  125. infRelate.Info(v.ip, v.now, v.api, v.buvid, v.mid, v.client, "2", list, v.disid, v.isRcmmnd, trackID, v.build, v.returnCode, v.userFeature, v.from)
  126. default:
  127. log.Warn("infocproc can't process the type")
  128. }
  129. }
  130. }