This commit is contained in:
苏尹岚
2020-09-29 15:46:32 +08:00
parent 5ed74064a7
commit b4f5a8af7d
2 changed files with 20 additions and 1 deletions

View File

@@ -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) {

View File

@@ -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 *