databus.go 925 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "strconv"
  6. "time"
  7. "go-common/app/service/main/member/model"
  8. )
  9. func notifyKey(mid int64) string {
  10. return fmt.Sprintf("MemberService-AccountNotify-T%d", mid)
  11. }
  12. // AddExplog add exp log with databus
  13. func (d *Dao) AddExplog(c context.Context, mid, exp, toExp int64, oper, reason, ip string) (err error) {
  14. log := &model.UserLog{
  15. Mid: mid,
  16. IP: ip,
  17. TS: time.Now().Unix(),
  18. LogID: model.UUID4(),
  19. Content: map[string]string{
  20. "from_exp": strconv.FormatInt(exp, 10),
  21. "to_exp": strconv.FormatInt(toExp, 10),
  22. "operater": oper,
  23. "reason": reason,
  24. },
  25. }
  26. err = d.logDatabus.Send(c, strconv.FormatInt(mid, 10), log)
  27. return
  28. }
  29. // NotifyPurgeCache is
  30. func (d *Dao) NotifyPurgeCache(c context.Context, mid int64, action string) error {
  31. msg := &model.NotifyInfo{
  32. Mid: mid,
  33. Action: action,
  34. }
  35. key := notifyKey(mid)
  36. return d.accNotify.Send(c, key, msg)
  37. }