dao.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. package archive
  2. import (
  3. "context"
  4. "go-common/app/interface/main/app-show/conf"
  5. "go-common/app/service/main/archive/api"
  6. arcrpc "go-common/app/service/main/archive/api/gorpc"
  7. "go-common/app/service/main/archive/model/archive"
  8. "go-common/library/log"
  9. )
  10. // Dao is archive dao.
  11. type Dao struct {
  12. c *conf.Config
  13. // rpc
  14. arcRpc *arcrpc.Service2
  15. }
  16. // New new a archive dao.
  17. func New(c *conf.Config) (d *Dao) {
  18. d = &Dao{
  19. c: c,
  20. // rpc
  21. arcRpc: arcrpc.New2(c.ArchiveRPC),
  22. }
  23. return
  24. }
  25. // Archive get archive by aid.
  26. func (d *Dao) Archive(ctx context.Context, aid int64) (a *api.Arc, err error) {
  27. arg := &archive.ArgAid2{Aid: aid}
  28. if a, err = d.arcRpc.Archive3(ctx, arg); err != nil {
  29. log.Error("d.arcRpc.Archive3(%v) error(%v)", arg, err)
  30. return
  31. }
  32. return
  33. }
  34. // ArchivesPB multi get archives.
  35. func (d *Dao) ArchivesPB(ctx context.Context, aids []int64) (as map[int64]*api.Arc, err error) {
  36. arg := &archive.ArgAids2{Aids: aids}
  37. return d.arcRpc.Archives3(ctx, arg)
  38. }
  39. // RanksArcs
  40. func (d *Dao) RanksArcs(ctx context.Context, rid, pn, ps int) (res []*api.Arc, aids []int64, err error) {
  41. arg := &archive.ArgRank2{
  42. Rid: int16(rid),
  43. Pn: pn,
  44. Ps: ps,
  45. }
  46. var as *archive.RankArchives3
  47. if as, err = d.arcRpc.RankArcs3(ctx, arg); err != nil {
  48. log.Error("d.arcRpc.RankArcs3(%v) error(%v)", arg, err)
  49. return
  50. }
  51. if as != nil {
  52. res = as.Archives
  53. for _, a := range res {
  54. aids = append(aids, a.Aid)
  55. }
  56. }
  57. return
  58. }
  59. // RankTopArcs
  60. func (d *Dao) RankTopArcs(ctx context.Context, rid, pn, ps int) (res []*api.Arc, err error) {
  61. arg := &archive.ArgRankTop2{
  62. ReID: int16(rid),
  63. Pn: pn,
  64. Ps: ps,
  65. }
  66. if res, err = d.arcRpc.RankTopArcs3(ctx, arg); err != nil {
  67. log.Error("d.arcRpc.RankTopArcs3(%v) error(%v)", arg, err)
  68. return
  69. }
  70. return
  71. }