infoc.go 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. package channel
  2. import (
  3. "bytes"
  4. "strconv"
  5. "time"
  6. "go-common/app/interface/main/app-channel/model/feed"
  7. "go-common/library/log"
  8. "go-common/library/log/infoc"
  9. )
  10. type feedInfoc struct {
  11. mobiApp string
  12. device string
  13. build string
  14. now string
  15. pull string
  16. loginEvent string
  17. channelID string
  18. channelName string
  19. mid string
  20. buvid string
  21. displayID string
  22. feed *feed.Show
  23. Items []*feed.Item
  24. isRec string
  25. topChannel string
  26. ServerCode string
  27. }
  28. type channelOperation struct {
  29. mobiApp string
  30. device string
  31. build string
  32. now string
  33. channelID string
  34. operation string
  35. mid string
  36. from string
  37. }
  38. // OperationInfoc channel operation infoc
  39. func (s *Service) OperationInfoc(mobiApp, device, operation string, build, from int, channelID, mid int64, now time.Time) {
  40. infoc := &channelOperation{
  41. mobiApp: mobiApp,
  42. device: device,
  43. build: strconv.Itoa(build),
  44. now: now.Format("2006-01-02 15:04:05"),
  45. channelID: strconv.FormatInt(channelID, 10),
  46. operation: operation,
  47. mid: strconv.FormatInt(mid, 10),
  48. from: strconv.Itoa(from),
  49. }
  50. s.infoc(infoc)
  51. }
  52. func (s *Service) infoc(i interface{}) {
  53. select {
  54. case s.logCh <- i:
  55. default:
  56. log.Warn("infocproc chan full")
  57. }
  58. }
  59. func (s *Service) infocproc() {
  60. const (
  61. noItem = `[]`
  62. )
  63. var (
  64. msg1 = []byte(`[`)
  65. msg2 = []byte(`{"goto":"`)
  66. msg3 = []byte(`","param":"`)
  67. msg4 = []byte(`","uri":"`)
  68. msg5 = []byte(`","r_pos":`)
  69. msg6 = []byte(`,"from_type":"`)
  70. msg7 = []byte(`"},`)
  71. msg8 = []byte(`]`)
  72. buf bytes.Buffer
  73. list string
  74. feedInf2 = infoc.New(s.c.FeedInfoc2)
  75. channelnf2 = infoc.New(s.c.ChannelInfoc2)
  76. )
  77. for {
  78. i, ok := <-s.logCh
  79. if !ok {
  80. log.Warn("infoc proc exit")
  81. return
  82. }
  83. var pos int
  84. switch l := i.(type) {
  85. case *feedInfoc:
  86. if l.feed != nil {
  87. if f := l.feed; len(f.Feed) == 0 && f.Topic == nil {
  88. list = noItem
  89. } else {
  90. buf.Write(msg1)
  91. if t := f.Topic; t != nil {
  92. buf.Write(msg2)
  93. buf.WriteString(t.Goto)
  94. buf.Write(msg3)
  95. buf.WriteString(t.Param)
  96. buf.Write(msg4)
  97. buf.WriteString(t.URI)
  98. buf.Write(msg5)
  99. pos = t.Pos
  100. buf.WriteString(strconv.Itoa(pos))
  101. buf.Write(msg6)
  102. buf.WriteString(t.FromType)
  103. buf.Write(msg7)
  104. }
  105. if items := f.Feed; len(items) == 0 {
  106. buf.Truncate(buf.Len() - 1)
  107. } else {
  108. for _, item := range items {
  109. buf.Write(msg2)
  110. buf.WriteString(item.Goto)
  111. buf.Write(msg3)
  112. buf.WriteString(item.Param)
  113. buf.Write(msg4)
  114. buf.WriteString(item.URI)
  115. buf.Write(msg5)
  116. if item.Pos == 0 {
  117. pos++
  118. } else {
  119. pos = item.Pos
  120. }
  121. buf.WriteString(strconv.Itoa(pos))
  122. buf.Write(msg6)
  123. buf.WriteString(item.FromType)
  124. buf.Write(msg7)
  125. }
  126. buf.Truncate(buf.Len() - 1)
  127. }
  128. buf.Write(msg8)
  129. list = buf.String()
  130. buf.Reset()
  131. }
  132. } else if items := l.Items; len(items) > 0 {
  133. buf.Write(msg1)
  134. for _, item := range items {
  135. buf.Write(msg2)
  136. buf.WriteString(item.Goto)
  137. buf.Write(msg3)
  138. buf.WriteString(item.Param)
  139. buf.Write(msg4)
  140. buf.WriteString(item.URI)
  141. buf.Write(msg5)
  142. if item.Pos == 0 {
  143. pos++
  144. } else {
  145. pos = item.Pos
  146. }
  147. buf.WriteString(strconv.Itoa(pos))
  148. buf.Write(msg6)
  149. buf.WriteString(item.FromType)
  150. buf.Write(msg7)
  151. }
  152. buf.Truncate(buf.Len() - 1)
  153. buf.Write(msg8)
  154. list = buf.String()
  155. buf.Reset()
  156. } else if len(l.Items) == 0 {
  157. list = noItem
  158. }
  159. log.Info("channel_infoc_index(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)_list(%s)", l.mobiApp, l.device, l.build, l.now, l.pull, l.loginEvent,
  160. l.channelID, l.channelName, l.mid, l.buvid, l.displayID, l.ServerCode, list)
  161. feedInf2.Info(l.mobiApp, l.device, l.build, l.now, l.pull, l.loginEvent, l.channelID, l.channelName, l.mid, l.buvid, l.displayID,
  162. list, "9", l.isRec, l.topChannel, l.ServerCode)
  163. case *channelOperation:
  164. log.Info("channel_infoc_operation_(%s,%s,%s,%s,%s,%s,%s,%s)", l.mobiApp, l.device, l.build, l.now, l.channelID, l.operation, l.mid, l.from)
  165. channelnf2.Info(l.mobiApp, l.device, l.build, l.now, l.channelID, l.operation, l.mid, l.from)
  166. }
  167. }
  168. }