rpc.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. package model
  2. import hismdl "go-common/app/service/main/history/model"
  3. // History video hisotry info.
  4. type History struct {
  5. Mid int64 `json:"mid,omitempty"`
  6. Aid int64 `json:"aid"`
  7. Sid int64 `json:"sid,omitempty"`
  8. Epid int64 `json:"epid,omitempty"`
  9. TP int8 `json:"tp,omitempty"`
  10. Business string `json:"business"`
  11. STP int8 `json:"stp,omitempty"` // sub_type
  12. Cid int64 `json:"cid,omitempty"`
  13. DT int8 `json:"dt,omitempty"`
  14. Pro int64 `json:"pro,omitempty"`
  15. Unix int64 `json:"view_at"`
  16. }
  17. // Histories history sorted.
  18. type Histories []*History
  19. func (h Histories) Len() int { return len(h) }
  20. func (h Histories) Less(i, j int) bool {
  21. if h[i].Unix == h[j].Unix {
  22. return h[i].Aid < h[j].Aid
  23. }
  24. return h[i].Unix > h[j].Unix
  25. }
  26. func (h Histories) Swap(i, j int) { h[i], h[j] = h[j], h[i] }
  27. // FillBusiness add history
  28. func (h *History) FillBusiness() {
  29. if h == nil {
  30. return
  31. }
  32. h.Business = businessIDs[h.TP]
  33. }
  34. // ConvertType convert old type
  35. func (h *History) ConvertType() {
  36. if h == nil {
  37. return
  38. }
  39. switch h.TP {
  40. case TypeBangumi:
  41. h.TP = TypePGC
  42. h.STP = SubTypeBangumi
  43. case TypeMovie:
  44. h.TP = TypePGC
  45. h.STP = SubTypeFilm
  46. case TypePGC:
  47. if h.Epid == 0 || h.Sid == 0 {
  48. h.TP = TypeUGC
  49. }
  50. }
  51. }
  52. // ConvertServiceType .
  53. func (h History) ConvertServiceType() (r *hismdl.History) {
  54. switch h.TP {
  55. case TypeOffline:
  56. h.TP = TypeUGC
  57. h.STP = SubTypeOffline
  58. case TypeUnknown:
  59. h.TP = TypeUGC
  60. case TypeBangumi:
  61. h.TP = TypePGC
  62. h.STP = SubTypeBangumi
  63. case TypeMovie:
  64. h.TP = TypePGC
  65. h.STP = SubTypeFilm
  66. }
  67. if h.TP == TypePGC && (h.Epid == 0 || h.Sid == 0) {
  68. h.TP = TypeUGC
  69. }
  70. h.FillBusiness()
  71. r = &hismdl.History{
  72. Mid: h.Mid,
  73. BusinessID: int64(h.TP),
  74. Business: h.Business,
  75. Kid: h.Aid,
  76. Aid: h.Aid,
  77. Sid: h.Sid,
  78. Epid: h.Epid,
  79. Cid: h.Cid,
  80. SubType: int32(h.STP),
  81. Device: int32(h.DT),
  82. Progress: int32(h.Pro),
  83. ViewAt: h.Unix,
  84. }
  85. if h.TP == TypePGC {
  86. r.Kid = r.Sid
  87. }
  88. return
  89. }
  90. // ArgPro arg.
  91. type ArgPro struct {
  92. Mid int64
  93. RealIP string
  94. Aids []int64
  95. }
  96. // ArgPos arg.
  97. type ArgPos struct {
  98. Mid int64
  99. Aid int64
  100. Business string
  101. TP int8
  102. RealIP string
  103. }
  104. // ArgDelete arg.
  105. type ArgDelete struct {
  106. Mid int64
  107. RealIP string
  108. Resources []*Resource
  109. }
  110. // ArgHistory arg.
  111. type ArgHistory struct {
  112. Mid int64
  113. Realtime int64
  114. RealIP string
  115. History *History
  116. }
  117. // ArgHistories arg.
  118. type ArgHistories struct {
  119. Mid int64
  120. TP int8
  121. Business string
  122. Pn int
  123. Ps int
  124. RealIP string
  125. }
  126. // ArgCursor arg.
  127. type ArgCursor struct {
  128. Mid int64
  129. Max int64
  130. TP int8
  131. // history business
  132. Business string
  133. ViewAt int64
  134. // filter business, blank means all business
  135. Businesses []string
  136. Ps int
  137. RealIP string
  138. }
  139. // Resource video hisotry info .
  140. type Resource struct {
  141. Mid int64 `json:"mid,omitempty"`
  142. Oid int64 `json:"oid"`
  143. Sid int64 `json:"sid,omitempty"`
  144. Epid int64 `json:"epid,omitempty"`
  145. TP int8 `json:"tp,omitempty"`
  146. STP int8 `json:"stp,omitempty"` // sub_type
  147. Cid int64 `json:"cid,omitempty"`
  148. Business string `json:"business"`
  149. DT int8 `json:"dt,omitempty"`
  150. Pro int64 `json:"pro,omitempty"`
  151. Unix int64 `json:"view_at"`
  152. }
  153. // ArgClear .
  154. type ArgClear struct {
  155. Mid int64
  156. RealIP string
  157. Businesses []string
  158. }