log.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package model
  2. import (
  3. "sort"
  4. "strconv"
  5. "time"
  6. xtime "go-common/library/time"
  7. )
  8. // RelationLog is
  9. type RelationLog struct {
  10. Mid int64 `json:"mid"`
  11. Fid int64 `json:"fid"`
  12. MemberName string `json:"member_name"`
  13. FollowingName string `json:"following_name"`
  14. Source int32 `json:"source"`
  15. MTime xtime.Time `json:"mtime"`
  16. Attention int32 `json:"attention"`
  17. Black int32 `json:"black"`
  18. Whisper int32 `json:"whisper"`
  19. AttrField string `json:"attr_field"`
  20. AttrChange string `json:"attr_change"`
  21. }
  22. // FillAttrField is
  23. func (l *RelationLog) FillAttrField() {
  24. if l.Attention > 0 {
  25. l.AttrField = "attention"
  26. return
  27. }
  28. if l.Black > 0 {
  29. l.AttrField = "black"
  30. return
  31. }
  32. if l.Whisper > 0 {
  33. l.AttrField = "whisper"
  34. return
  35. }
  36. }
  37. // RelationLogList is
  38. type RelationLogList []*RelationLog
  39. // Len is
  40. func (rl RelationLogList) Len() int {
  41. return len(rl)
  42. }
  43. // Swap is
  44. func (rl RelationLogList) Swap(i, j int) {
  45. rl[i], rl[j] = rl[j], rl[i]
  46. }
  47. // Less is
  48. func (rl RelationLogList) Less(i, j int) bool {
  49. return rl[i].MTime < rl[j].MTime
  50. }
  51. // OrderByMTime is
  52. func (rl RelationLogList) OrderByMTime(desc bool) {
  53. sort.Sort(rl)
  54. }
  55. // ParseAction is
  56. func ParseAction(act string) int32 {
  57. i, _ := strconv.ParseInt(act, 10, 32)
  58. return int32(i)
  59. }
  60. // ParseSource is
  61. func ParseSource(src string) int32 {
  62. i, _ := strconv.ParseInt(src, 10, 64)
  63. return int32(i)
  64. }
  65. // ParseLogTime is
  66. func ParseLogTime(ts string) (xt xtime.Time, err error) {
  67. var (
  68. t time.Time
  69. )
  70. if t, err = time.ParseInLocation("2006-01-02 15:04:05", ts, time.Local); err != nil {
  71. return
  72. }
  73. xt.Scan(t)
  74. return
  75. }