sys_menu_button.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package system
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type SysMenuButton struct {
  7. MenuButtonId int `orm:"column(menu_button_id);pk" description:"菜单按钮id"`
  8. MenuId int
  9. ButtonName int
  10. CreateTime time.Time
  11. }
  12. type SysMenuButtonItem struct {
  13. MenuButtonId int `description:"菜单按钮id"`
  14. MenuId int `description:"菜单id"`
  15. ButtonName string `description:"按钮名称"`
  16. }
  17. func GetSysMenuButtonItems(menuId int) (items []*SysMenuButtonItem, err error) {
  18. sql := ` SELECT * FROM sys_menu_button WHERE menu_id=? `
  19. _, err = orm.NewOrm().Raw(sql, menuId).QueryRows(&items)
  20. return
  21. }
  22. type MenuButtonsResp struct {
  23. List []*ButtonMenu
  24. CheckList []*int
  25. }
  26. func AddSysMenuButton(item *SysMenuButton) (lastId int64, err error) {
  27. o := orm.NewOrm()
  28. lastId, err = o.Insert(item)
  29. return
  30. }
  31. type SysRoleButton struct {
  32. Id int `orm:"column(id);pk" description:"关联id"`
  33. RoleId int
  34. MenuButtonId int
  35. CreateTime time.Time
  36. }
  37. func AddSysRoleButton(item *SysRoleButton) (lastId int64, err error) {
  38. o := orm.NewOrm()
  39. lastId, err = o.Insert(item)
  40. return
  41. }
  42. func GetRoleButtonCheck(roleId int) (items []*SysRoleButton, err error) {
  43. sql := `SELECT b.* FROM sys_menu_button AS a
  44. INNER JOIN sys_role_button AS b ON a.menu_button_id=b.menu_button_id
  45. WHERE b.role_id=?`
  46. o := orm.NewOrm()
  47. _, err = o.Raw(sql, roleId).QueryRows(&items)
  48. return
  49. }
  50. type ButtonMenu struct {
  51. MenuId int `description:"导航唯一标识"`
  52. Name string `json:"name" description:"导航名称"`
  53. List []*SysMenuButtonItem
  54. }
  55. func GetButtonMenu() (items []*ButtonMenu, err error) {
  56. sql := `SELECT b.menu_id,b.name FROM sys_menu_button AS a
  57. INNER JOIN sys_menu AS b ON a.menu_id=b.menu_id
  58. GROUP BY b.menu_id `
  59. o := orm.NewOrm()
  60. _, err = o.Raw(sql).QueryRows(&items)
  61. return
  62. }
  63. func DeleteSysRoleButton(roleId int) (err error) {
  64. o := orm.NewOrm()
  65. sql := `DELETE FROM sys_role_button WHERE role_id=? `
  66. _, err = o.Raw(sql, roleId).Exec()
  67. return
  68. }
  69. func GetSysRoleButtonCount(roleId, buttonId int) (count int, err error) {
  70. o := orm.NewOrm()
  71. sql := `SELECT COUNT(1) AS count FROM sys_role_button WHERE role_id=? AND menu_button_id=? `
  72. _, err = o.Raw(sql, roleId, buttonId).Exec()
  73. return
  74. }