dao.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package resource
  2. import (
  3. "context"
  4. "go-common/app/interface/main/app-interface/conf"
  5. resmdl "go-common/app/service/main/resource/model"
  6. resrpc "go-common/app/service/main/resource/rpc/client"
  7. "go-common/library/log"
  8. "go-common/library/net/metadata"
  9. )
  10. type Dao struct {
  11. c *conf.Config
  12. // rpc
  13. resRPC *resrpc.Service
  14. }
  15. func New(c *conf.Config) (d *Dao) {
  16. d = &Dao{
  17. c: c,
  18. // rpc
  19. resRPC: resrpc.New(c.ResourceRPC),
  20. }
  21. return
  22. }
  23. // Banner get search banner
  24. func (d *Dao) Banner(c context.Context, mobiApp, device, network, channel, buvid, adExtra, resIDStr string, build int, plat int8, mid int64) (res map[int][]*resmdl.Banner, err error) {
  25. var (
  26. bs *resmdl.Banners
  27. ip = metadata.String(c, metadata.RemoteIP)
  28. )
  29. arg := &resmdl.ArgBanner{
  30. MobiApp: mobiApp,
  31. Device: device,
  32. Network: network,
  33. Channel: channel,
  34. IP: ip,
  35. Buvid: buvid,
  36. AdExtra: adExtra,
  37. ResIDs: resIDStr,
  38. Build: build,
  39. Plat: plat,
  40. MID: mid,
  41. IsAd: true,
  42. }
  43. if bs, err = d.resRPC.Banners(c, arg); err != nil || bs == nil {
  44. log.Error("d.resRPC.Banners(%v) error(%v) or bs is nil", arg, err)
  45. return
  46. }
  47. if len(bs.Banner) > 0 {
  48. res = bs.Banner
  49. }
  50. return
  51. }