dao.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package location
  2. import (
  3. "context"
  4. "strconv"
  5. "go-common/app/interface/main/app-view/conf"
  6. locmdl "go-common/app/service/main/location/model"
  7. locrpc "go-common/app/service/main/location/rpc/client"
  8. "go-common/library/log"
  9. )
  10. // Dao is location dao.
  11. type Dao struct {
  12. // rpc
  13. locRPC *locrpc.Service
  14. }
  15. // New new a location dao.
  16. func New(c *conf.Config) (d *Dao) {
  17. d = &Dao{
  18. // rpc
  19. locRPC: locrpc.New(c.LocationRPC),
  20. }
  21. return
  22. }
  23. func (d *Dao) AuthPIDs(c context.Context, pids, ipaddr string) (res map[string]*locmdl.Auth, err error) {
  24. var auths map[int64]*locmdl.Auth
  25. if auths, err = d.locRPC.AuthPIDs(c, &locmdl.ArgPids{Pids: pids, IP: ipaddr}); err != nil {
  26. log.Error("%v", err)
  27. return
  28. }
  29. res = make(map[string]*locmdl.Auth)
  30. for pid, auth := range auths {
  31. p := strconv.FormatInt(pid, 10)
  32. res[p] = auth
  33. }
  34. return
  35. }
  36. // Archive get auth by aid.
  37. func (d *Dao) Archive(c context.Context, aid, mid int64, ipaddr, cndip string) (auth *locmdl.Auth, err error) {
  38. if auth, err = d.locRPC.Archive2(c, &locmdl.Archive{Aid: aid, Mid: mid, IP: ipaddr, CIP: cndip}); err != nil {
  39. log.Error("%v", err)
  40. }
  41. return
  42. }