article.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package service
  2. import (
  3. "context"
  4. "go-common/app/interface/main/space/model"
  5. artmdl "go-common/app/interface/openplatform/article/model"
  6. "go-common/library/log"
  7. "go-common/library/net/metadata"
  8. )
  9. var _emptyArticle = make([]*artmdl.Meta, 0)
  10. // Article get articles by upMid.
  11. func (s *Service) Article(c context.Context, mid int64, pn, ps, sort int) (res *artmdl.UpArtMetas, err error) {
  12. ip := metadata.String(c, metadata.RemoteIP)
  13. if res, err = s.art.UpArtMetas(c, &artmdl.ArgUpArts{Mid: mid, Pn: pn, Ps: ps, Sort: sort, RealIP: ip}); err != nil {
  14. log.Error("s.art.UpArtMetas(%d,%d,%d) error(%v)", mid, pn, ps, err)
  15. return
  16. }
  17. if res != nil && len(res.Articles) == 0 {
  18. res.Articles = _emptyArticle
  19. }
  20. return
  21. }
  22. // UpArtStat get up all article stat.
  23. func (s *Service) UpArtStat(c context.Context, mid int64) (data *model.UpArtStat, err error) {
  24. addCache := true
  25. if data, err = s.dao.UpArtCache(c, mid); err != nil {
  26. addCache = false
  27. } else if data != nil {
  28. return
  29. }
  30. if data, err = s.dao.UpArtStat(c, mid); data != nil && addCache {
  31. s.cache.Do(c, func(c context.Context) {
  32. s.dao.SetUpArtCache(c, mid, data)
  33. })
  34. }
  35. return
  36. }