academy.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package dao
  2. import (
  3. "context"
  4. "strconv"
  5. "go-common/app/interface/openplatform/article/model"
  6. "go-common/app/service/main/archive/api"
  7. "go-common/app/service/main/archive/model/archive"
  8. "go-common/library/ecode"
  9. "go-common/library/log"
  10. "go-common/library/net/metadata"
  11. )
  12. // Archive get archive.
  13. func (d *Dao) Archive(c context.Context, aid int64) (a *api.Arc, err error) {
  14. var ip = metadata.String(c, metadata.RemoteIP)
  15. var arg = &archive.ArgAid2{Aid: aid, RealIP: ip}
  16. if a, err = d.arc.Archive3(c, arg); err != nil {
  17. log.Error("d.arc.Archive3 aid(%d)|error(%v)", aid, err)
  18. err = ecode.CreativeArcServiceErr
  19. }
  20. return
  21. }
  22. // Archives get archive list.
  23. func (d *Dao) Archives(c context.Context, aids []int64) (a map[int64]*api.Arc, err error) {
  24. var ip = metadata.String(c, metadata.RemoteIP)
  25. var arg = &archive.ArgAids2{Aids: aids, RealIP: ip}
  26. if a, err = d.arc.Archives3(c, arg); err != nil {
  27. log.Error("d.arc.Archive3 aids(%v+)|error(%v)", aids, err)
  28. err = ecode.CreativeArcServiceErr
  29. }
  30. return
  31. }
  32. // ArticleMetas batch get articles by aids.
  33. func (d *Dao) ArticleMetas(c context.Context, aids []int64) (res map[int64]*model.Meta, err error) {
  34. var ip = metadata.String(c, metadata.RemoteIP)
  35. arg := &model.ArgAids{Aids: aids, RealIP: ip}
  36. if res, err = d.art.ArticleMetas(c, arg); err != nil {
  37. log.Error("d.art.ArticleMetas aids(%+v)|error(%v)", arg, err)
  38. if _, er := strconv.ParseInt(err.Error(), 10, 64); er != nil {
  39. err = ecode.CreativeArticleRPCErr
  40. }
  41. }
  42. log.Info("d.art.ArticleMetas aids(%v)|res(%+v)", aids, res)
  43. return
  44. }
  45. // Stats get archives stat.
  46. func (d *Dao) Stats(c context.Context, aids []int64, ip string) (a map[int64]*api.Stat, err error) {
  47. var arg = &archive.ArgAids2{Aids: aids, RealIP: ip}
  48. if a, err = d.arc.Stats3(c, arg); err != nil {
  49. log.Error("rpc Stats (%v) error(%v)", aids, err)
  50. err = ecode.CreativeArcServiceErr
  51. }
  52. return
  53. }