menu
This commit is contained in:
@@ -10,7 +10,11 @@ import (
|
||||
)
|
||||
|
||||
func GetMenu(ctx *jxcontext.Context, userID string) (menus []*model.Menu, err error) {
|
||||
return dao.GetMenu(dao.GetDB(), "", 0, userID)
|
||||
if userID == "" {
|
||||
return dao.GetMenu(dao.GetDB(), "", 0, userID)
|
||||
} else {
|
||||
return dao.GetMenuWithUser(dao.GetDB(), "", 0, userID)
|
||||
}
|
||||
}
|
||||
|
||||
func AddMenu(ctx *jxcontext.Context, menu *model.Menu) (err error) {
|
||||
|
||||
@@ -33,6 +33,21 @@ func GetMenu(db *DaoDB, name string, level int, userID string) (menus []*model.M
|
||||
return menus, err
|
||||
}
|
||||
|
||||
func GetMenuWithUser(db *DaoDB, name string, level int, userID string) (menus []*model.Menu, err error) {
|
||||
sql := `
|
||||
SELECT b.* FROM (
|
||||
SELECT a.id,a.parent_id
|
||||
FROM menu a
|
||||
JOIN user_role b ON b.user_id = ?
|
||||
JOIN role_menu c ON c.menu_id = a.id AND c.role_id = b.role_id
|
||||
WHERE a.deleted_at = ?)a
|
||||
JOIN menu b ON (b.id = a.id OR b.id = a.parent_id)
|
||||
`
|
||||
sqlParams := []interface{}{userID, utils.DefaultTimeValue}
|
||||
err = GetRows(db, &menus, sql, sqlParams)
|
||||
return menus, err
|
||||
}
|
||||
|
||||
func GetRole(db *DaoDB, name string) (roles []*model.Role, err error) {
|
||||
sql := `
|
||||
SELECT *
|
||||
|
||||
Reference in New Issue
Block a user