新增返回值

This commit is contained in:
2023-06-28 17:55:40 +08:00
parent 6e6e3803e4
commit b4e18e23e3
9 changed files with 92 additions and 11 deletions
+14 -5
View File
@@ -8,6 +8,7 @@ import (
"hospital-admin-api/api/requests"
"hospital-admin-api/api/responses/roleResponse"
"hospital-admin-api/global"
"strconv"
)
type RoleService struct{}
@@ -36,8 +37,13 @@ func (r *RoleService) GetRoleMenuList(roleId int64) ([]*roleResponse.GetRoleMenu
menuIDs = append(menuIDs, roleMenu.MenuID)
}
// 构建菜单树
menuTree = buildMenuTree(menuIDs, adminMenu)
if len(menuIDs) > 0 {
// 构建菜单树
menuTree = buildMenuTree(menuIDs, adminMenu)
if menuTree == nil {
return nil, nil
}
}
}
return menuTree, nil
@@ -53,10 +59,10 @@ func buildMenuTree(menuIds []int64, menuData []*model.AdminMenu) []*roleResponse
for _, v := range menuIds {
if v == menu.MenuId {
node := &roleResponse.GetRoleMenuList{
MenuId: menu.MenuId,
MenuId: strconv.FormatInt(menu.MenuId, 10),
MenuName: menu.MenuName,
MenuTitle: menu.MenuTitle,
ParentId: menu.ParentId,
ParentId: strconv.FormatInt(menu.ParentId, 10),
MenuStatus: menu.MenuStatus,
MenuType: menu.MenuType,
Permission: menu.Permission,
@@ -75,8 +81,11 @@ func buildMenuTree(menuIds []int64, menuData []*model.AdminMenu) []*roleResponse
// 构建菜单树
for _, menu := range menuData {
if menu.ParentId == 0 {
if menuMap[menu.MenuId] == nil {
continue
}
rootNodes = append(rootNodes, menuMap[menu.MenuId])
} else if parent, ok := menuMap[menu.ParentId]; ok {
} else if parent, ok := menuMap[menu.ParentId]; ok && parent != nil {
parent.Children = append(parent.Children, menuMap[menu.MenuId])
}
}