subject.go 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. package model
  2. import (
  3. "database/sql/driver"
  4. "strconv"
  5. "time"
  6. )
  7. // All const variable used in job
  8. const (
  9. SubTypeVideo = int32(1) // 主题类型
  10. SubStateOpen = int32(0) // 主题打开
  11. SubStateClosed = int32(1) // 主题关闭
  12. AttrSubGuest = uint(0) // 允许游客弹幕
  13. AttrSubSpolier = uint(1) // 允许剧透弹幕
  14. AttrSubMission = uint(2) // 允许活动弹幕
  15. AttrSubAdvance = uint(3) // 允许高级弹幕
  16. AttrSubMonitorBefore = uint(4) // 弹幕先审后发
  17. AttrSubMonitorAfter = uint(5) // 弹幕先发后审
  18. AttrSubMaskOpen = uint(6) // 开启蒙版
  19. AttrSubMaskReady = uint(7) // 蒙版生产完成
  20. MaskPlatWeb int8 = 0 // web端
  21. MaskPlatMbl int8 = 1 // 移动端
  22. MaskPlatAll int8 = 100 //全部端
  23. )
  24. // Subject dm_subject.
  25. type Subject struct {
  26. ID int64 `json:"id"`
  27. Type int32 `json:"type"`
  28. Oid int64 `json:"oid"`
  29. Pid int64 `json:"pid"`
  30. Mid int64 `json:"mid"`
  31. State int32 `json:"state"`
  32. Attr int32 `json:"attr"`
  33. ACount int64 `json:"acount"`
  34. Count int64 `json:"count"`
  35. MCount int64 `json:"mcount"`
  36. MoveCnt int64 `json:"move_count"`
  37. Maxlimit int64 `json:"maxlimit"`
  38. Childpool int32 `json:"childpool"`
  39. Ctime stime `json:"ctime"`
  40. Mtime stime `json:"mtime"`
  41. }
  42. // ConvertStime .
  43. func ConvertStime(t time.Time) stime {
  44. return stime(t.Unix())
  45. }
  46. type stime int64
  47. // Scan scan time.
  48. func (st *stime) Scan(src interface{}) (err error) {
  49. switch sc := src.(type) {
  50. case time.Time:
  51. *st = stime(sc.Unix())
  52. case string:
  53. var i int64
  54. i, err = strconv.ParseInt(sc, 10, 64)
  55. *st = stime(i)
  56. }
  57. return
  58. }
  59. // Value get time value.
  60. func (st stime) Value() (driver.Value, error) {
  61. return time.Unix(int64(st), 0), nil
  62. }
  63. // UnmarshalJSON implements the json.Unmarshaler interface.
  64. func (st *stime) UnmarshalJSON(data []byte) error {
  65. timestamp, err := strconv.ParseInt(string(data), 10, 64)
  66. if err == nil {
  67. *st = stime(timestamp)
  68. return nil
  69. }
  70. t, err := time.ParseInLocation(`"2006-01-02 15:04:05"`, string(data), time.Local)
  71. *st = stime(t.Unix())
  72. return err
  73. }
  74. // AttrVal return val of subject'attr
  75. func (s *Subject) AttrVal(bit uint) int32 {
  76. return (s.Attr >> bit) & int32(1)
  77. }
  78. // AttrSet set val of subject'attr
  79. func (s *Subject) AttrSet(v int32, bit uint) {
  80. s.Attr = s.Attr&(^(1 << bit)) | (v << bit)
  81. }