package eta_business import ( "hongze/hz_crm_api/models/eta_business" ) // GetMenuTreeRecursive 递归菜单树 func GetMenuTreeRecursive(list []*eta_business.EtaBusinessMenuItem, parentId int) []*eta_business.EtaBusinessMenuItem { res := make([]*eta_business.EtaBusinessMenuItem, 0) for _, v := range list { if v.ParentId == parentId { v.Children = GetMenuTreeRecursive(list, v.MenuId) res = append(res, v) } } return res } // GetMenuChildrenIdsRecursive 遍历子菜单IDs func GetMenuChildrenIdsRecursive(list []*eta_business.EtaBusinessMenu, parentId int) []int { res := make([]int, 0) for _, v := range list { if v.ParentId == parentId { ids := GetMenuChildrenIdsRecursive(list, v.MenuId) res = append(res, v.MenuId) res = append(res, ids...) } } return res } // GetMenuParentsRecursive 遍历子菜单的所有父级菜单 func GetMenuParentsRecursive(list []*eta_business.EtaBusinessMenu, parentId int) []*eta_business.EtaBusinessMenu { res := make([]*eta_business.EtaBusinessMenu, 0) for _, v := range list { if v.MenuId == parentId { res = append(res, v) parents := make([]*eta_business.EtaBusinessMenu, 0) if v.ParentId > 0 { parents = GetMenuParentsRecursive(list, v.ParentId) } res = append(res, parents...) } } return res }