fav.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. package model
  2. import (
  3. "database/sql/driver"
  4. "encoding/json"
  5. "errors"
  6. "strconv"
  7. "time"
  8. )
  9. var (
  10. // ErrFavResourceExist error this has been favoured.
  11. ErrFavResourceExist = errors.New("error this has been favoured")
  12. // ErrFavResourceAlreadyDel error this has been unfavoured.
  13. ErrFavResourceAlreadyDel = errors.New("error this has been unfavoured")
  14. )
  15. const (
  16. // CacheNotFound .
  17. CacheNotFound = -1
  18. // SyncInsert binlog action.
  19. SyncInsert = "insert"
  20. // SyncUpdate binlog action.
  21. SyncUpdate = "update"
  22. // SyncDelete binlog action.
  23. SyncDelete = "delete"
  24. )
  25. // CanelMessage binlog message.
  26. type CanelMessage struct {
  27. Action string `json:"action"`
  28. Table string `json:"table"`
  29. New json.RawMessage `json:"new"`
  30. Old json.RawMessage `json:"old"`
  31. }
  32. // OldCount .
  33. type OldCount struct {
  34. ID int64 `json:"id"`
  35. Aid int64 `json:"aid"`
  36. Count int64 `json:"count"`
  37. CTime Stime `json:"ctime"`
  38. MTime Stime `json:"mtime"`
  39. }
  40. // NewCount .
  41. type NewCount struct {
  42. ID int64 `json:"id"`
  43. Type int8 `json:"type"`
  44. Oid int64 `json:"oid"`
  45. Count int64 `json:"count"`
  46. CTime Stime `json:"ctime"`
  47. MTime Stime `json:"mtime"`
  48. }
  49. // OldFolder .
  50. type OldFolder struct {
  51. ID int64 `json:"id"`
  52. Mid int64 `json:"mid"`
  53. Name string `json:"name"`
  54. CurCount int `json:"cur_count"`
  55. State int8 `json:"state"`
  56. CTime Stime `json:"ctime"`
  57. MTime Stime `json:"mtime"`
  58. }
  59. // NewFolder .
  60. type NewFolder struct {
  61. ID int64 `json:"id"`
  62. Type int8 `json:"type"`
  63. Mid int64 `json:"mid"`
  64. Name string `json:"name"`
  65. Count int `json:"count"`
  66. Attr int8 `json:"attr"`
  67. State int8 `json:"state"`
  68. CTime Stime `json:"ctime"`
  69. MTime Stime `json:"mtime"`
  70. }
  71. // VideoFolder .
  72. type VideoFolder struct {
  73. ID int64 `json:"id"`
  74. Mid int64 `json:"mid"`
  75. Fid int64 `json:"fid"`
  76. VideoFid int64 `json:"video_fid"`
  77. CTime Stime `json:"ctime"`
  78. MTime Stime `json:"mtime"`
  79. }
  80. // OldVideo .
  81. type OldVideo struct {
  82. ID int64 `json:"id"`
  83. Mid int64 `json:"mid"`
  84. Fid int64 `json:"fid"`
  85. Aid int64 `json:"aid"`
  86. CTime Stime `json:"ctime"`
  87. MTime Stime `json:"mtime"`
  88. }
  89. // NewRelation .
  90. type NewRelation struct {
  91. ID int64 `json:"id"`
  92. Type int8 `json:"type"`
  93. Mid int64 `json:"mid"`
  94. Fid int64 `json:"fid"`
  95. Oid int64 `json:"oid"`
  96. State int8 `json:"state"`
  97. CTime Stime `json:"ctime"`
  98. MTime Stime `json:"mtime"`
  99. }
  100. // OldFolderSort .
  101. type OldFolderSort struct {
  102. ID int64 `json:"id"`
  103. Mid int64 `json:"mid"`
  104. Sort string `json:"sort"`
  105. CTime Stime `json:"ctime"`
  106. MTime Stime `json:"mtime"`
  107. }
  108. // NewFolderSort .
  109. type NewFolderSort struct {
  110. ID int64 `json:"id"`
  111. Type int8 `json:"type"`
  112. Mid int64 `json:"mid"`
  113. Sort []byte `json:"sort"`
  114. CTime Stime `json:"ctime"`
  115. MTime Stime `json:"mtime"`
  116. }
  117. // Stime .
  118. type Stime int64
  119. // Scan scan time.
  120. func (st *Stime) Scan(src interface{}) (err error) {
  121. switch sc := src.(type) {
  122. case time.Time:
  123. *st = Stime(sc.Unix())
  124. case string:
  125. var i int64
  126. i, err = strconv.ParseInt(sc, 10, 64)
  127. *st = Stime(i)
  128. }
  129. return
  130. }
  131. // Value get time value.
  132. func (st Stime) Value() (driver.Value, error) {
  133. return time.Unix(int64(st), 0), nil
  134. }
  135. // UnmarshalJSON implements the json.Unmarshaler interface.
  136. func (st *Stime) UnmarshalJSON(data []byte) error {
  137. timestamp, err := strconv.ParseInt(string(data), 10, 64)
  138. if err == nil {
  139. *st = Stime(timestamp)
  140. return nil
  141. }
  142. t, err := time.ParseInLocation(`"2006-01-02 15:04:05"`, string(data), time.Local)
  143. if err == nil {
  144. *st = Stime(t.Unix())
  145. }
  146. return nil
  147. }
  148. // StatMsg .
  149. type StatMsg struct {
  150. Play *int64 `json:"play"`
  151. Fav *int64 `json:"fav"`
  152. Share *int64 `json:"share"`
  153. Oid int64 `json:"oid"`
  154. }
  155. // StatCount .
  156. type StatCount struct {
  157. Type string `json:"type"`
  158. ID int64 `json:"id"`
  159. Count int64 `json:"count"`
  160. DisLike int64 `json:"dislike_count"`
  161. TimeStamp int64 `json:"timestamp"`
  162. }
  163. // PlayReport .
  164. type PlayReport struct {
  165. ID int64 `json:"id"`
  166. Mid int64 `json:"mid"`
  167. LV string `json:"lv"`
  168. IP string `json:"ip"`
  169. Buvid string `json:"buvid"`
  170. DeviceID string `json:"device_id"`
  171. UA string `json:"ua"`
  172. Refer string `json:"refer"`
  173. TS int64 `json:"ts"`
  174. }