sys_menu.go 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package system
  2. import "github.com/beego/beego/v2/client/orm"
  3. type MenuList struct {
  4. MenuId int `description:"导航唯一标识"`
  5. IsLevel int `description:"1,只有一级;2,有多级"`
  6. Name string `json:"name" description:"导航名称"`
  7. Path string `json:"path"`
  8. IconPath string `json:"icon_path"`
  9. LevelPath string `json:"level_path"`
  10. Component string `json:"component"`
  11. Hidden bool `json:"hidden"`
  12. Children []*ChildMenu `json:"children"`
  13. }
  14. type ChildMenu struct {
  15. MenuId int `description:"导航唯一标识"`
  16. Name string `json:"name" description:"导航名称"`
  17. Path string `json:"path"`
  18. Component string `json:"component"`
  19. IconPath string `json:"icon_path"`
  20. Hidden bool `json:"hidden"`
  21. }
  22. type MenuListResp struct {
  23. List []*MenuList
  24. }
  25. func GetMenuList(roleId int) (items []*MenuList, err error) {
  26. sql := ` SELECT a.* FROM sys_menu_crm AS a
  27. INNER JOIN sys_role_menu_crm AS b ON a.menu_id=b.menu_id
  28. INNER JOIN sys_role AS c ON b.role_id=c.role_id
  29. WHERE c.role_id=?
  30. AND a.parent_id=0
  31. ORDER BY sort ASC `
  32. _, err = orm.NewOrm().Raw(sql, roleId).QueryRows(&items)
  33. return
  34. }
  35. func GetMenuByParentId(roleId, parentId int) (items []*ChildMenu, err error) {
  36. sql := ` SELECT a.* FROM sys_menu_crm AS a
  37. INNER JOIN sys_role_menu_crm AS b ON a.menu_id=b.menu_id
  38. INNER JOIN sys_role AS c ON b.role_id=c.role_id
  39. WHERE c.role_id=?
  40. AND a.parent_id=?
  41. ORDER BY sort ASC `
  42. _, err = orm.NewOrm().Raw(sql, roleId, parentId).QueryRows(&items)
  43. return
  44. }
  45. // GetMenuListByRoleIds 根据管理员多个角色查询菜单ID
  46. func GetMenuListByRoleIds(roleIds string) (items []*MenuList, err error) {
  47. sql := ` SELECT DISTINCT a.* FROM sys_menu_crm AS a
  48. INNER JOIN sys_role_menu_crm AS b ON a.menu_id=b.menu_id
  49. INNER JOIN sys_role AS c ON b.role_id=c.role_id
  50. WHERE c.role_id in (` + roleIds + `)
  51. AND a.parent_id=0
  52. ORDER BY sort ASC `
  53. _, err = orm.NewOrm().Raw(sql).QueryRows(&items)
  54. return
  55. }
  56. // GetMenuByParentIdRoleIds 根据管理员多个角色查询子菜单ID
  57. func GetMenuByParentIdRoleIds(roleIds string, parentId int) (items []*ChildMenu, err error) {
  58. sql := ` SELECT DISTINCT a.* FROM sys_menu_crm AS a
  59. INNER JOIN sys_role_menu_crm AS b ON a.menu_id=b.menu_id
  60. INNER JOIN sys_role AS c ON b.role_id=c.role_id
  61. WHERE c.role_id in (` + roleIds + `)
  62. AND a.parent_id=?
  63. ORDER BY a.sort ASC`
  64. _, err = orm.NewOrm().Raw(sql, parentId).QueryRows(&items)
  65. return
  66. }