relation_log.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/service/main/relation/model"
  5. "go-common/library/log"
  6. "go-common/library/queue/databus/report"
  7. "go-common/library/time"
  8. )
  9. // consts
  10. const (
  11. RelationLogID = 13
  12. )
  13. // AddFollowingLog is
  14. func (d *Dao) AddFollowingLog(ctx context.Context, rl *model.RelationLog) {
  15. d.addLog(ctx, RelationLogID, "log_add_following", rl)
  16. d.addLog(ctx, RelationLogID, "log_follower_incr", rl.Reverse())
  17. }
  18. // DelFollowingLog is
  19. func (d *Dao) DelFollowingLog(ctx context.Context, rl *model.RelationLog) {
  20. d.addLog(ctx, RelationLogID, "log_del_following", rl)
  21. d.addLog(ctx, RelationLogID, "log_follower_decr", rl.Reverse())
  22. }
  23. // DelFollowerLog is
  24. func (d *Dao) DelFollowerLog(ctx context.Context, rl *model.RelationLog) {
  25. d.addLog(ctx, RelationLogID, "log_del_follower", rl)
  26. d.addLog(ctx, RelationLogID, "log_following_decr", rl.Reverse())
  27. }
  28. // AddWhisperLog is
  29. func (d *Dao) AddWhisperLog(ctx context.Context, rl *model.RelationLog) {
  30. d.addLog(ctx, RelationLogID, "log_add_whisper", rl)
  31. d.addLog(ctx, RelationLogID, "log_whisper_follower_incr", rl.Reverse())
  32. }
  33. // DelWhisperLog is
  34. func (d *Dao) DelWhisperLog(ctx context.Context, rl *model.RelationLog) {
  35. d.addLog(ctx, RelationLogID, "log_del_whisper", rl)
  36. d.addLog(ctx, RelationLogID, "log_whisper_follower_decr", rl.Reverse())
  37. }
  38. // AddBlackLog is
  39. func (d *Dao) AddBlackLog(ctx context.Context, rl *model.RelationLog) {
  40. d.addLog(ctx, RelationLogID, "log_add_black", rl)
  41. d.addLog(ctx, RelationLogID, "log_black_incr", rl.Reverse())
  42. }
  43. // DelBlackLog is
  44. func (d *Dao) DelBlackLog(ctx context.Context, rl *model.RelationLog) {
  45. d.addLog(ctx, RelationLogID, "log_del_black", rl)
  46. d.addLog(ctx, RelationLogID, "log_black_decr", rl.Reverse())
  47. }
  48. func (d *Dao) addLog(ctx context.Context, business int, action string, rl *model.RelationLog) {
  49. t := time.Time(rl.Ts)
  50. content := make(map[string]interface{}, len(rl.Content))
  51. for k, v := range rl.Content {
  52. content[k] = v
  53. }
  54. content["from_attr"] = rl.FromAttr
  55. content["to_attr"] = rl.ToAttr
  56. content["from_rev_attr"] = rl.FromRevAttr
  57. content["to_rev_attr"] = rl.ToRevAttr
  58. content["source"] = rl.Source
  59. ui := &report.UserInfo{
  60. Mid: rl.Mid,
  61. Platform: "",
  62. Build: 0,
  63. Buvid: rl.Buvid,
  64. Business: business,
  65. Type: 0,
  66. Oid: rl.Fid,
  67. Action: action,
  68. Ctime: t.Time(),
  69. IP: rl.Ip,
  70. // extra
  71. Index: []interface{}{int64(rl.Source), 0, "", "", ""},
  72. Content: content,
  73. }
  74. report.User(ui)
  75. log.Info("add log to report: relationlog: %+v userinfo: %+v", rl, ui)
  76. }