location.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/interface/bbq/app-bbq/model"
  5. )
  6. var (
  7. locationQueryChild = "select `loc_id`, `pid`, `name` from `bbq_location` where `pid` = ?;"
  8. locationQueryAll = "select `loc_id`, `pid`, `name` from `bbq_location`;"
  9. )
  10. // GetLocationAll .
  11. func (d *Dao) GetLocationAll(c context.Context) (*map[int32][]*model.Location, error) {
  12. rows, err := d.db.Query(c, locationQueryAll)
  13. if err != nil {
  14. return nil, err
  15. }
  16. defer rows.Close()
  17. m := make(map[int32][]*model.Location)
  18. var id, pid int32
  19. var name string
  20. for rows.Next() {
  21. rows.Scan(&id, &pid, &name)
  22. m[pid] = append(m[pid], &model.Location{
  23. ID: id,
  24. PID: pid,
  25. Name: name,
  26. })
  27. }
  28. return &m, err
  29. }
  30. // GetLocationChild .
  31. func (d *Dao) GetLocationChild(c context.Context, locID int32) (*map[int32][]*model.Location, error) {
  32. rows, err := d.db.Query(c, locationQueryChild, locID)
  33. if err != nil {
  34. return nil, err
  35. }
  36. defer rows.Close()
  37. m := make(map[int32][]*model.Location)
  38. var id, pid int32
  39. var name string
  40. for rows.Next() {
  41. rows.Scan(&id, &pid, &name)
  42. m[pid] = append(m[pid], &model.Location{
  43. ID: id,
  44. PID: pid,
  45. Name: name,
  46. })
  47. }
  48. return &m, err
  49. }