infoc.go 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. package feed
  2. import (
  3. "bytes"
  4. "context"
  5. "encoding/json"
  6. "strconv"
  7. "time"
  8. "go-common/app/interface/main/app-card/model/card/ai"
  9. "go-common/app/interface/main/app-feed/model"
  10. "go-common/library/log"
  11. binfoc "go-common/library/log/infoc"
  12. "go-common/library/net/metadata"
  13. )
  14. type infoc struct {
  15. typ string
  16. mid string
  17. client string
  18. build string
  19. buvid string
  20. disid string
  21. ip string
  22. style string
  23. api string
  24. now string
  25. isRcmd string
  26. pull string
  27. userFeature json.RawMessage
  28. code string
  29. items []*ai.Item
  30. zoneID string
  31. adResponse string
  32. deviceID string
  33. network string
  34. newUser string
  35. flush string
  36. autoPlay string
  37. deviceType string
  38. }
  39. func (s *Service) IndexInfoc(c context.Context, mid int64, plat int8, build int, buvid, disid, api string, userFeature json.RawMessage, style, code int, items []*ai.Item, isRcmd, pull, newUser bool, now time.Time, adResponse, deviceID, network string, flush int, autoPlay string, deviceType int) {
  40. if items == nil {
  41. return
  42. }
  43. var (
  44. isRc = "0"
  45. isPull = "0"
  46. isNewUser = "0"
  47. zoneID int64
  48. )
  49. if isRcmd {
  50. isRc = "1"
  51. }
  52. if pull {
  53. isPull = "1"
  54. }
  55. if newUser {
  56. isNewUser = "1"
  57. }
  58. ip := metadata.String(c, metadata.RemoteIP)
  59. info, err := s.loc.Info(c, ip)
  60. if err != nil {
  61. log.Warn(" s.loc.Info(%v) error(%v)", ip, err)
  62. err = nil
  63. }
  64. if info != nil {
  65. zoneID = info.ZoneID
  66. }
  67. s.infoc(infoc{"综合推荐", strconv.FormatInt(mid, 10), strconv.Itoa(int(plat)), strconv.Itoa(build), buvid, disid, ip, strconv.Itoa(style), api, strconv.FormatInt(now.Unix(), 10), isRc, isPull, userFeature, strconv.Itoa(code), items, strconv.FormatInt(zoneID, 10), adResponse, deviceID, network, isNewUser, strconv.Itoa(flush), autoPlay, strconv.Itoa(deviceType)})
  68. }
  69. func (s *Service) infoc(i interface{}) {
  70. select {
  71. case s.logCh <- i:
  72. default:
  73. log.Warn("infocproc chan full")
  74. }
  75. }
  76. // writeInfoc
  77. func (s *Service) infocproc() {
  78. const (
  79. // infoc format {"section":{"id":"%s推荐","pos":1,"style":%d,"items":[{"id":%s,"pos":%d,"type":1,"url":""}]}}
  80. noItem1 = `{"section":{"id":"`
  81. noItem2 = `{","pos":1,"style":`
  82. noItem3 = `,"items":[]}}`
  83. )
  84. // is_ad_loc, resource_id,source_id, creative_id,
  85. var (
  86. msg1 = []byte(`{"section":{"id":"`)
  87. msg2 = []byte(`","pos":1,"style":`)
  88. msg3 = []byte(`,"items":[`)
  89. msg4 = []byte(`{"id":`)
  90. msg5 = []byte(`,"pos":`)
  91. msg6 = []byte(`,"type":`)
  92. msg7 = []byte(`,"source":"`)
  93. msg8 = []byte(`","tid":`)
  94. msg9 = []byte(`,"av_feature":`)
  95. msg10 = []byte(`,"url":"`)
  96. msg11 = []byte(`","rcmd_reason":"`)
  97. msg12 = []byte(`","is_ad_loc":`)
  98. msg13 = []byte(`,"resource_id":`)
  99. msg14 = []byte(`,"source_id":`)
  100. msg15 = []byte(`,"creative_id":`)
  101. msg16 = []byte(`},`)
  102. msg17 = []byte(`"},`)
  103. msg18 = []byte(`]}}`)
  104. showInf = binfoc.New(s.c.ShowInfoc2)
  105. buf bytes.Buffer
  106. list string
  107. trackID string
  108. )
  109. for {
  110. i, ok := <-s.logCh
  111. if !ok {
  112. log.Warn("infoc proc exit")
  113. return
  114. }
  115. switch l := i.(type) {
  116. case infoc:
  117. if len(l.items) > 0 {
  118. buf.Write(msg1)
  119. buf.WriteString(l.typ)
  120. buf.Write(msg2)
  121. buf.WriteString(l.style)
  122. buf.Write(msg3)
  123. for i, v := range l.items {
  124. if v == nil {
  125. continue
  126. }
  127. if v.TrackID != "" {
  128. trackID = v.TrackID
  129. }
  130. buf.Write(msg4)
  131. buf.WriteString(strconv.FormatInt(v.ID, 10))
  132. buf.Write(msg5)
  133. buf.WriteString(strconv.Itoa(i + 1))
  134. buf.Write(msg6)
  135. buf.WriteString(gotoMapID(v.Goto))
  136. buf.Write(msg7)
  137. buf.WriteString(v.Source)
  138. buf.Write(msg8)
  139. buf.WriteString(strconv.FormatInt(v.Tid, 10))
  140. buf.Write(msg9)
  141. if v.AvFeature != nil {
  142. buf.Write(v.AvFeature)
  143. } else {
  144. buf.Write([]byte(`""`))
  145. }
  146. buf.Write(msg10)
  147. buf.WriteString("")
  148. buf.Write(msg11)
  149. if v.RcmdReason != nil {
  150. buf.WriteString(v.RcmdReason.Content)
  151. }
  152. if v.Ad != nil {
  153. buf.Write(msg12)
  154. buf.WriteString(strconv.FormatBool(v.Ad.IsAdLoc))
  155. buf.Write(msg13)
  156. buf.WriteString(strconv.FormatInt(v.Ad.Resource, 10))
  157. buf.Write(msg14)
  158. buf.WriteString(strconv.Itoa(v.Ad.Source))
  159. buf.Write(msg15)
  160. buf.WriteString(strconv.FormatInt(v.Ad.CreativeID, 10))
  161. buf.Write(msg16)
  162. } else {
  163. buf.Write(msg17)
  164. }
  165. }
  166. buf.Truncate(buf.Len() - 1)
  167. buf.Write(msg18)
  168. list = buf.String()
  169. buf.Reset()
  170. } else {
  171. list = noItem1 + l.typ + noItem2 + l.style + noItem3
  172. }
  173. showInf.Info(l.ip, l.now, l.api, l.buvid, l.mid, l.client, l.pull, list, l.disid, l.isRcmd, l.build, l.code, string(l.userFeature), l.zoneID, l.adResponse, l.deviceID, l.network, l.newUser, l.flush, l.autoPlay, trackID, l.deviceType)
  174. log.Info("infocproc %s param(mid:%s,buvid:%s,plat:%s,build:%s,isRcmd:%s,code:%s,zone_id:%s,user_feature:%s,ad_response:%s,device_id:%s,network:%s,new_user:%s,flush:%s,autoplay_card:%s,trackid:%s,device_type:%s) response(%s)", l.api, l.mid, l.buvid, l.client, l.build, l.isRcmd, l.code, l.zoneID, l.userFeature, l.adResponse, l.deviceID, l.network, l.newUser, l.flush, l.autoPlay, trackID, l.deviceType, list)
  175. }
  176. }
  177. }
  178. func gotoMapID(gt string) (id string) {
  179. if gt == model.GotoAv {
  180. id = "1"
  181. } else if gt == model.GotoBangumi {
  182. id = "2"
  183. } else if gt == model.GotoLive {
  184. id = "3"
  185. } else if gt == model.GotoRank {
  186. id = "6"
  187. } else if gt == model.GotoAdAv {
  188. id = "8"
  189. } else if gt == model.GotoAdWeb {
  190. id = "9"
  191. } else if gt == model.GotoBangumiRcmd {
  192. id = "10"
  193. } else if gt == model.GotoLogin {
  194. id = "11"
  195. } else if gt == model.GotoUpBangumi {
  196. id = "12"
  197. } else if gt == model.GotoBanner {
  198. id = "13"
  199. } else if gt == model.GotoAdWebS {
  200. id = "14"
  201. } else if gt == model.GotoUpArticle {
  202. id = "15"
  203. } else if gt == model.GotoConverge {
  204. id = "17"
  205. } else if gt == model.GotoSpecial {
  206. id = "18"
  207. } else if gt == model.GotoArticleS {
  208. id = "20"
  209. } else if gt == model.GotoGameDownloadS {
  210. id = "21"
  211. } else if gt == model.GotoShoppingS {
  212. id = "22"
  213. } else if gt == model.GotoAudio {
  214. id = "23"
  215. } else if gt == model.GotoPlayer {
  216. id = "24"
  217. } else if gt == model.GotoSpecialS {
  218. id = "25"
  219. } else if gt == model.GotoAdLarge {
  220. id = "26"
  221. } else if gt == model.GotoPlayerLive {
  222. id = "27"
  223. } else if gt == model.GotoSong {
  224. id = "28"
  225. } else if gt == model.GotoLiveUpRcmd {
  226. id = "29"
  227. } else if gt == model.GotoUpRcmdAv {
  228. id = "30"
  229. } else if gt == model.GotoSubscribe {
  230. id = "31"
  231. } else if gt == model.GotoChannelRcmd {
  232. id = "32"
  233. } else if gt == model.GotoMoe {
  234. id = "33"
  235. } else if gt == model.GotoPGC {
  236. id = "34"
  237. } else if gt == model.GotoSearchSubscribe {
  238. id = "35"
  239. } else if gt == model.GotoPicture {
  240. id = "36"
  241. } else if gt == model.GotoInterest {
  242. id = "37"
  243. } else {
  244. id = "-1"
  245. }
  246. return
  247. }