view.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package archive
  2. import (
  3. "context"
  4. "go-common/app/service/main/archive/api"
  5. "go-common/app/service/main/archive/model/archive"
  6. "go-common/library/ecode"
  7. "go-common/library/log"
  8. "github.com/pkg/errors"
  9. )
  10. // View3 view archive with pages pb.
  11. func (d *Dao) View3(c context.Context, aid int64) (v *archive.View3, err error) {
  12. arg := &archive.ArgAid2{Aid: aid}
  13. if v, err = d.arcRPC.View3(c, arg); err != nil {
  14. log.Error("d.arcRPC.View3(%v) error(%+v)", arg, err)
  15. if ecode.Cause(err) == ecode.NothingFound {
  16. err = nil
  17. return
  18. }
  19. if v, err = d.arcRPC2.View3(c, arg); err != nil {
  20. err = errors.Wrapf(err, "%v", arg)
  21. }
  22. }
  23. return
  24. }
  25. // ViewCache get view static data from cache if cache missed from rpc.
  26. func (d *Dao) ViewCache(c context.Context, aid int64) (vs *archive.View3, err error) {
  27. if aid == 0 {
  28. return
  29. }
  30. if vs, err = d.viewCache(c, aid); err != nil {
  31. return
  32. }
  33. if vs != nil && vs.Archive3 != nil && len(vs.Pages) != 0 {
  34. var st *api.Stat
  35. if st, err = d.Stat(c, aid); err != nil {
  36. log.Error("%+v", err)
  37. err = nil
  38. return
  39. }
  40. if st != nil {
  41. vs.Archive3.Stat = archive.Stat3{
  42. Aid: st.Aid,
  43. View: st.View,
  44. Danmaku: st.Danmaku,
  45. Reply: st.Reply,
  46. Fav: st.Fav,
  47. Coin: st.Coin,
  48. Share: st.Share,
  49. NowRank: st.NowRank,
  50. HisRank: st.HisRank,
  51. Like: st.Like,
  52. DisLike: st.DisLike,
  53. }
  54. }
  55. }
  56. return
  57. }
  58. // Description get archive description by aid.
  59. func (d *Dao) Description(c context.Context, aid int64) (desc string, err error) {
  60. arg := &archive.ArgAid{Aid: aid}
  61. if desc, err = d.arcRPC.Description2(c, arg); err != nil {
  62. err = errors.Wrapf(err, "%v", arg)
  63. }
  64. return
  65. }