databus.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package dao
  2. import (
  3. "context"
  4. "strconv"
  5. "time"
  6. "go-common/app/interface/main/playlist/model"
  7. pjmdl "go-common/app/job/main/playlist/model"
  8. "go-common/library/log"
  9. "go-common/library/net/metadata"
  10. xtime "go-common/library/time"
  11. )
  12. var _defaultAdd = int64(1)
  13. // PubView adds a view count.
  14. func (d *Dao) PubView(c context.Context, pid, aid, view int64) (err error) {
  15. ip := metadata.String(c, metadata.RemoteIP)
  16. view += _defaultAdd
  17. msg := &pjmdl.StatM{
  18. Type: model.PlDBusType,
  19. ID: pid,
  20. Aid: aid,
  21. IP: ip,
  22. Count: &view,
  23. Timestamp: xtime.Time(time.Now().Unix()),
  24. }
  25. if err = d.viewDbus.Send(c, strconv.FormatInt(pid, 10), msg); err != nil {
  26. PromError("databus:发送浏览量", "d.viewDbus.Send(%+v) error(%v)", msg, err)
  27. return
  28. }
  29. log.Info("s.PubView( pid: %d, aid: %d, ip: %s, view: %d)", msg.ID, msg.Aid, msg.IP, *msg.Count)
  30. return
  31. }
  32. // PubShare adds a share count.
  33. func (d *Dao) PubShare(c context.Context, pid, aid, share int64) (err error) {
  34. ip := metadata.String(c, metadata.RemoteIP)
  35. share += _defaultAdd
  36. msg := &pjmdl.StatM{
  37. Type: model.PlDBusType,
  38. ID: pid,
  39. Aid: aid,
  40. IP: ip,
  41. Count: &share,
  42. Timestamp: xtime.Time(time.Now().Unix()),
  43. }
  44. if err = d.shareDbus.Send(c, strconv.FormatInt(pid, 10), msg); err != nil {
  45. PromError("databus:发送分享数", "d.shareDbus.Send(%+v) error(%v)", msg, err)
  46. return
  47. }
  48. log.Info("s.PubShare( pid: %d, aid: %d, ip: %s, share: %d)", msg.ID, msg.Aid, msg.IP, *msg.Count)
  49. return
  50. }