This commit is contained in:
苏尹岚
2021-01-21 17:13:33 +08:00
parent 091e46b74d
commit 5eeb60c12d
2 changed files with 7 additions and 3 deletions

View File

@@ -78,14 +78,14 @@ func UpdateMenu(ctx *jxcontext.Context, menuID int, payload map[string]interface
}
func GetRole(ctx *jxcontext.Context) (roles []*model.Role, err error) {
return dao.GetRole(dao.GetDB(), "")
return dao.GetRole(dao.GetDB(), "", "")
}
func AddRole(ctx *jxcontext.Context, name string) (err error) {
var (
db = dao.GetDB()
)
roles, err := dao.GetRole(db, name)
roles, err := dao.GetRole(db, "", name)
if len(roles) > 0 {
return fmt.Errorf("添加失败!已存在相同名称的 role name : %v", name)
}

View File

@@ -48,7 +48,7 @@ func GetMenuWithUser(db *DaoDB, name string, level int, userID string) (menus []
return menus, err
}
func GetRole(db *DaoDB, name string) (roles []*model.Role, err error) {
func GetRole(db *DaoDB, name, name2 string) (roles []*model.Role, err error) {
sql := `
SELECT *
FROM role
@@ -61,6 +61,10 @@ func GetRole(db *DaoDB, name string) (roles []*model.Role, err error) {
sql += " AND name LIKE ?"
sqlParams = append(sqlParams, "%"+name+"%")
}
if name2 != "" {
sql += " AND name = ?"
sqlParams = append(sqlParams, name2)
}
err = GetRows(db, &roles, sql, sqlParams)
return roles, err
}