databus.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package dao
  2. import (
  3. "context"
  4. "strconv"
  5. "time"
  6. "go-common/app/service/main/thumbup/model"
  7. "go-common/library/log"
  8. )
  9. // PubStatDatabus pub stat databus
  10. func (d *Dao) PubStatDatabus(c context.Context, business string, mid int64, s *model.Stats, upMid int64) (err error) {
  11. msg := &model.StatMsg{Type: business, ID: s.ID, Count: s.Likes, Timestamp: time.Now().Unix(), OriginID: s.OriginID, DislikeCount: s.Dislikes, Mid: mid, UpMid: upMid}
  12. if err = d.statDbus.Send(c, strconv.FormatInt(s.ID, 10), msg); err != nil {
  13. log.Error("d.databus.Send error(%v)", err)
  14. PromError("databus:stat")
  15. return
  16. }
  17. log.Info("s.PubStatDatabus (%+v)", msg)
  18. return
  19. }
  20. // PubLikeDatabus .
  21. func (d *Dao) PubLikeDatabus(c context.Context, p *model.LikeMsg) (err error) {
  22. if err = d.likeDbus.Send(c, strconv.FormatInt(p.Mid, 10), p); err != nil {
  23. log.Error("d.likeDbus.Send error(%v)", err)
  24. PromError("databus:like")
  25. return
  26. }
  27. log.Info("s.PubLikeDatabus success (%+v)", p)
  28. return
  29. }
  30. // PubItemMsg .
  31. func (d *Dao) PubItemMsg(c context.Context, business string, originID, messageID int64, state int8) (err error) {
  32. msg := &model.ItemMsg{
  33. State: state,
  34. Business: business,
  35. OriginID: originID,
  36. MessageID: messageID,
  37. }
  38. if err = d.itemDbus.Send(c, strconv.FormatInt(messageID, 10), msg); err != nil {
  39. log.Error("d.PubItemMsg.databus.Send error(%v)", err)
  40. PromError("databus:item")
  41. return
  42. }
  43. log.Info("s.PubItemMsg success (%+v)", msg)
  44. return
  45. }
  46. // PubUserMsg .
  47. func (d *Dao) PubUserMsg(c context.Context, business string, mid int64, state int8) (err error) {
  48. msg := &model.UserMsg{
  49. Mid: mid,
  50. State: state,
  51. Business: business,
  52. }
  53. if err = d.userDbus.Send(c, strconv.FormatInt(mid, 10), msg); err != nil {
  54. log.Error("d.PubUserMsg.databus.Send error(%v)", err)
  55. PromError("databus:user")
  56. return
  57. }
  58. log.Info("s.PubUserMsg success (%+v)", msg)
  59. return
  60. }
  61. // AddCacheUserLikeList .
  62. func (d *Dao) AddCacheUserLikeList(c context.Context, mid int64, miss []*model.ItemLikeRecord, businessID int64, state int8) (err error) {
  63. err = d.PubUserMsg(c, d.BusinessIDMap[businessID].Name, mid, state)
  64. return
  65. }