privilege.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/service/main/vip/model"
  5. "go-common/library/database/sql"
  6. "github.com/pkg/errors"
  7. )
  8. const (
  9. privilegeListSQL = "SELECT id, privileges_name, title, explains, privileges_type, operator, state, deleted, icon_url, icon_gray_url, order_num, lang_type, ctime, mtime FROM vip_privileges WHERE deleted = 0 AND state = 1 ORDER BY order_num;"
  10. privilegeResourcesListSQL = "SELECT id,pid,link,image_url,resources_type,ctime,mtime FROM vip_privileges_resources;"
  11. )
  12. // PrivilegeList query .
  13. func (d *Dao) PrivilegeList(c context.Context) (res []*model.Privilege, err error) {
  14. var rows *sql.Rows
  15. if rows, err = d.db.Query(c, privilegeListSQL); err != nil {
  16. err = errors.WithStack(err)
  17. return
  18. }
  19. defer rows.Close()
  20. for rows.Next() {
  21. r := new(model.Privilege)
  22. if err = rows.Scan(&r.ID, &r.Name, &r.Title, &r.Explain, &r.Type, &r.Operator, &r.State, &r.Deleted, &r.IconURL, &r.IconGrayURL, &r.Order, &r.LangType, &r.Ctime, &r.Mtime); err != nil {
  23. err = errors.WithStack(err)
  24. res = nil
  25. return
  26. }
  27. res = append(res, r)
  28. }
  29. err = rows.Err()
  30. return
  31. }
  32. // PrivilegeResourcesList query privilege resources .
  33. func (d *Dao) PrivilegeResourcesList(c context.Context) (res []*model.PrivilegeResources, err error) {
  34. var rows *sql.Rows
  35. if rows, err = d.db.Query(c, privilegeResourcesListSQL); err != nil {
  36. err = errors.WithStack(err)
  37. return
  38. }
  39. defer rows.Close()
  40. for rows.Next() {
  41. r := new(model.PrivilegeResources)
  42. if err = rows.Scan(&r.ID, &r.PID, &r.Link, &r.ImageURL, &r.Type, &r.Ctime, &r.Mtime); err != nil {
  43. err = errors.WithStack(err)
  44. res = nil
  45. return
  46. }
  47. res = append(res, r)
  48. }
  49. err = rows.Err()
  50. return
  51. }