用户添加全新啊

This commit is contained in:
苏尹岚
2020-09-28 10:43:48 +08:00
parent 58e6775125
commit 98c0b852af
3 changed files with 17 additions and 11 deletions

View File

@@ -11,8 +11,8 @@ import (
"git.rosy.net.cn/jx-callback/business/model/dao"
)
func GetMenu(ctx *jxcontext.Context) (menus []*model.Menu, err error) {
return dao.GetMenu(dao.GetDB(), "", 0)
func GetMenu(ctx *jxcontext.Context, userID string) (menus []*model.Menu, err error) {
return dao.GetMenu(dao.GetDB(), "", 0, userID)
}
func AddMenu(ctx *jxcontext.Context, menu *model.Menu) (err error) {

View File

@@ -5,21 +5,26 @@ import (
"git.rosy.net.cn/jx-callback/business/model"
)
func GetMenu(db *DaoDB, name string, level int) (menus []*model.Menu, err error) {
func GetMenu(db *DaoDB, name string, level int, userID string) (menus []*model.Menu, err error) {
sqlParams := []interface{}{}
sql := `
SELECT *
FROM menu
WHERE deleted_at = ?
SELECT DISTINCT a.*
FROM menu a
`
sqlParams := []interface{}{
utils.DefaultTimeValue,
if userID != "" {
sql += ` 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
`
sqlParams = append(sqlParams, userID)
}
sql += " WHERE a.deleted_at = ?"
sqlParams = append(sqlParams, utils.DefaultTimeValue)
if name != "" {
sql += " AND name LIKE ?"
sql += " AND a.name LIKE ?"
sqlParams = append(sqlParams, "%"+name+"%")
}
if level != 0 {
sql += " AND level = ?"
sql += " AND a.level = ?"
sqlParams = append(sqlParams, level)
}
err = GetRows(db, &menus, sql, sqlParams)

View File

@@ -32,12 +32,13 @@ func (c *PowerController) AddMenu() {
// @Title 查询功能(菜单)
// @Description 查询功能(菜单)
// @Param token header string true "认证token"
// @Param userID query string false "用户ID"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /GetMenu [get]
func (c *PowerController) GetMenu() {
c.callGetMenu(func(params *tPowerGetMenuParams) (retVal interface{}, errCode string, err error) {
retVal, err = cms.GetMenu(params.Ctx)
retVal, err = cms.GetMenu(params.Ctx, params.UserID)
return retVal, "", err
})
}