sys_menu_button.go 2.1 KB

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