stat.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package model
  2. import "go-common/app/service/main/archive/api"
  3. const (
  4. TypeForView = "view"
  5. TypeForDm = "dm"
  6. TypeForReply = "reply"
  7. TypeForFav = "fav"
  8. TypeForCoin = "coin"
  9. TypeForShare = "share"
  10. TypeForRank = "rank"
  11. TypeForLike = "like"
  12. )
  13. // StatMsg stat info.
  14. type StatMsg struct {
  15. Aid int64 `json:"aid"`
  16. Click int `json:"click"`
  17. DM int `json:"dm"`
  18. Reply int `json:"reply"`
  19. Fav int `json:"fav"`
  20. Coin int `json:"coin"`
  21. Share int `json:"share"`
  22. NowRank int `json:"now_rank"`
  23. HisRank int `json:"his_rank"`
  24. Like int `json:"like"`
  25. DisLike int `json:"dislike_count"`
  26. Type string `json:"-"`
  27. Ts int64 `json:"-"`
  28. }
  29. type StatCount struct {
  30. Type string `json:"type"`
  31. Aid int64 `json:"id"`
  32. Count int `json:"count"`
  33. DisLike int `json:"dislike_count"`
  34. TimeStamp int64 `json:"timestamp"`
  35. }
  36. // Merge merge message and stat from db.
  37. func Merge(m *StatMsg, s *api.Stat) {
  38. if m.Click >= 0 && m.Type == TypeForView {
  39. s.View = int32(m.Click)
  40. }
  41. if m.Coin >= 0 && m.Type == TypeForCoin {
  42. s.Coin = int32(m.Coin)
  43. }
  44. if m.DM >= 0 && m.Type == TypeForDm {
  45. s.Danmaku = int32(m.DM)
  46. }
  47. if m.Fav >= 0 && m.Type == TypeForFav {
  48. s.Fav = int32(m.Fav)
  49. }
  50. if m.Reply >= 0 && m.Type == TypeForReply {
  51. s.Reply = int32(m.Reply)
  52. }
  53. if m.Share >= 0 && m.Type == TypeForShare && int32(m.Share) > s.Share {
  54. s.Share = int32(m.Share)
  55. }
  56. if m.NowRank >= 0 && m.Type == TypeForRank {
  57. s.NowRank = int32(m.NowRank)
  58. }
  59. if m.HisRank >= 0 && m.Type == TypeForRank {
  60. s.HisRank = int32(m.HisRank)
  61. }
  62. if m.Like >= 0 && m.Type == TypeForLike {
  63. s.Like = int32(m.Like)
  64. }
  65. if m.DisLike >= 0 && m.Type == TypeForLike {
  66. s.DisLike = int32(m.DisLike)
  67. }
  68. }