123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- package system
- import (
- "github.com/beego/beego/v2/client/orm"
- "time"
- )
- type MenuList struct {
- MenuId int `description:"导航唯一标识"`
- IsLevel int `description:"1,只有一级;2,有多级"`
- Name string `json:"name" description:"导航名称"`
- Path string `json:"path"`
- IconPath string `json:"icon_path"`
- LevelPath string `json:"level_path"`
- Component string `json:"component"`
- Hidden bool `json:"hidden"`
- Children []*ChildMenu `json:"children"`
- }
- type ChildMenu struct {
- MenuId int `description:"导航唯一标识"`
- Name string `json:"name" description:"导航名称"`
- Path string `json:"path"`
- Component string `json:"component"`
- IconPath string `json:"icon_path"`
- Hidden bool `json:"hidden"`
- }
- type MenuListResp struct {
- List []*MenuList
- }
- func GetMenuList(roleId int) (items []*MenuList, err error) {
- sql := ` SELECT a.* FROM sys_menu AS a
- INNER JOIN sys_role_menu AS b ON a.menu_id=b.menu_id
- INNER JOIN sys_role AS c ON b.role_id=c.role_id
- WHERE c.role_id=?
- AND a.parent_id=0
- ORDER BY sort ASC `
- _, err = orm.NewOrm().Raw(sql, roleId).QueryRows(&items)
- return
- }
- func GetMenuByParentId(roleId, parentId int) (items []*ChildMenu, err error) {
- sql := ` SELECT a.* FROM sys_menu AS a
- INNER JOIN sys_role_menu AS b ON a.menu_id=b.menu_id
- INNER JOIN sys_role AS c ON b.role_id=c.role_id
- WHERE c.role_id=?
- AND a.parent_id=?
- ORDER BY sort ASC `
- _, err = orm.NewOrm().Raw(sql, roleId, parentId).QueryRows(&items)
- return
- }
- // GetMenuListByRoleIds 根据管理员多个角色查询菜单ID
- func GetMenuListByRoleIds(roleIds string) (items []*MenuList, err error) {
- sql := ` SELECT DISTINCT a.* FROM sys_menu AS a
- INNER JOIN sys_role_menu AS b ON a.menu_id=b.menu_id
- INNER JOIN sys_role AS c ON b.role_id=c.role_id
- WHERE c.role_id in (` + roleIds + `)
- AND a.parent_id=0
- ORDER BY sort ASC `
- _, err = orm.NewOrm().Raw(sql).QueryRows(&items)
- return
- }
- // GetMenuByParentIdRoleIds 根据管理员多个角色查询子菜单ID
- func GetMenuByParentIdRoleIds(roleIds string, parentId int) (items []*ChildMenu, err error) {
- sql := ` SELECT DISTINCT a.* FROM sys_menu AS a
- INNER JOIN sys_role_menu AS b ON a.menu_id=b.menu_id
- INNER JOIN sys_role AS c ON b.role_id=c.role_id
- WHERE c.role_id in (` + roleIds + `)
- AND a.parent_id=?
- ORDER BY a.sort ASC`
- _, err = orm.NewOrm().Raw(sql, parentId).QueryRows(&items)
- return
- }
- type SysMenu struct {
- MenuId int `orm:"column(menu_id);pk"`
- ParentId int `description:"父级菜单ID"`
- Name string `description:"菜单名称或者按钮名称"`
- Sort string `description:"排序"`
- Path string `description:"路由地址"`
- IconPath string `description:"菜单图标地址"`
- Component int `description:"组件路径"`
- Hidden int `description:"是否隐藏:1-隐藏 0-显示"`
- IsLevel int `description:"是否为多级菜单:1,只有一级;2,有多级"`
- LevelPath string `description:"兼容以前menu表的字段"`
- MenuType int `description:"菜单类型: 0-菜单; 1-按钮; 2-字段(需要特殊处理)"`
- ButtonCode string `description:"按钮/菜单唯一标识"`
- CreateTime time.Time `description:"创建时间"`
- ModifyTime time.Time `description:"更新时间"`
- }
- // GetMenuButtonsByRoleId 获取角色按钮菜单
- func GetMenuButtonsByRoleId(roleId int) (items []*SysMenu, err error) {
- sql := `SELECT
- r.*
- FROM
- sys_menu AS r
- JOIN sys_role_menu AS rm ON r.menu_id = rm.menu_id AND rm.type = 0
- WHERE
- rm.role_id = ? AND r.menu_type <> 0 AND r.hidden = 0
- ORDER BY
- r.sort ASC,
- r.create_time DESC`
- _, err = orm.NewOrm().Raw(sql, roleId).QueryRows(&items)
- return
- }
- // SysMenuButtonResp 按钮菜单响应体
- type SysMenuButtonResp struct {
- MenuId int `description:"菜单ID"`
- ParentId int `description:"父级菜单ID"`
- Name string `description:"菜单名称或者按钮名称"`
- MenuType int `description:"菜单类型: 0-菜单; 1-按钮"`
- ButtonCode string `description:"按钮唯一标识"`
- }
- // BusinessConf 商户配置表
- type BusinessConf struct {
- ConfKey string `description:"配置Key"`
- ConfVal string `description:"配置值"`
- }
|