relation.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package model
  2. import (
  3. "encoding/json"
  4. "time"
  5. sml "go-common/app/service/main/relation/model"
  6. )
  7. // Message define binlog databus message.
  8. type Message struct {
  9. Action string `json:"action"`
  10. Table string `json:"table"`
  11. New json.RawMessage `json:"new"`
  12. Old json.RawMessage `json:"old"`
  13. }
  14. // Relation user_relation_fid_0~user_relation_fid_49,user_relation_mid_0~user_relation_mid_49
  15. type Relation struct {
  16. Mid int64 `json:"mid,omitempty"`
  17. Fid int64 `json:"fid,omitempty"`
  18. Attribute uint32 `json:"attribute"`
  19. Status int `json:"status"`
  20. MTime string `json:"mtime"`
  21. CTime string `json:"ctime"`
  22. }
  23. // Stat user_relation_stat
  24. type Stat struct {
  25. Mid int64 `json:"mid,omitempty"`
  26. Following int64 `json:"following"`
  27. Whisper int64 `json:"whisper"`
  28. Black int64 `json:"black"`
  29. Follower int64 `json:"follower"`
  30. }
  31. // LastChangeAt is.
  32. func (r *Relation) LastChangeAt() (at time.Time, err error) {
  33. // FIXME(zhoujiahui): ctime and mtime should not be used here
  34. return time.ParseInLocation("2006-01-02 15:04:05", r.MTime, time.Local)
  35. }
  36. // Attr is.
  37. func (r *Relation) Attr() uint32 {
  38. return sml.Attr(r.Attribute)
  39. }
  40. // IsRecent is.
  41. func (r *Relation) IsRecent(at time.Time, trange time.Duration) bool {
  42. lastAt, err := r.LastChangeAt()
  43. if err != nil {
  44. return false
  45. }
  46. if lastAt.Sub(at) > trange {
  47. return true
  48. }
  49. return false
  50. }