archive.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package archive
  2. import (
  3. "context"
  4. "go-common/app/interface/main/app-channel/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/net/metadata"
  9. "github.com/pkg/errors"
  10. )
  11. // Dao is archive dao.
  12. type Dao struct {
  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. // rpc
  20. arcRPC: arcrpc.New2(c.ArchiveRPC),
  21. }
  22. return
  23. }
  24. // Archive get archive by aid.
  25. func (d *Dao) Archive(ctx context.Context, aid int64) (a *api.Arc, err error) {
  26. arg := &archive.ArgAid2{Aid: aid}
  27. a, err = d.arcRPC.Archive3(ctx, arg)
  28. return
  29. }
  30. // Archives multi get archives.
  31. func (d *Dao) Archives(ctx context.Context, aids []int64) (as map[int64]*api.Arc, err error) {
  32. arg := &archive.ArgAids2{Aids: aids}
  33. as, err = d.arcRPC.Archives3(ctx, arg)
  34. return
  35. }
  36. // ArchivesWithPlayer archives witch player
  37. func (d *Dao) ArchivesWithPlayer(c context.Context, aids []int64, qn int, platform string, fnver, fnval, build int) (res map[int64]*archive.ArchiveWithPlayer, err error) {
  38. if len(aids) == 0 {
  39. return
  40. }
  41. ip := metadata.String(c, metadata.RemoteIP)
  42. arg := &archive.ArgPlayer{Aids: aids, Qn: qn, Platform: platform, Fnval: fnval, Fnver: fnver, RealIP: ip, Build: build}
  43. if res, err = d.arcRPC.ArchivesWithPlayer(c, arg); err != nil {
  44. err = errors.Wrapf(err, "%v", arg)
  45. }
  46. return
  47. }
  48. // UpCount2 get upper count.
  49. func (d *Dao) UpCount2(c context.Context, mid int64) (cnt int, err error) {
  50. arg := &archive.ArgUpCount2{Mid: mid}
  51. if cnt, err = d.arcRPC.UpCount2(c, arg); err != nil {
  52. err = errors.Wrapf(err, "%v", arg)
  53. }
  54. return
  55. }