eta_business_menu.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package eta_business
  2. import (
  3. "hongze/hz_crm_api/models/eta_business"
  4. )
  5. // GetMenuTreeRecursive 递归菜单树
  6. func GetMenuTreeRecursive(list []*eta_business.EtaBusinessMenuItem, parentId int) []*eta_business.EtaBusinessMenuItem {
  7. res := make([]*eta_business.EtaBusinessMenuItem, 0)
  8. for _, v := range list {
  9. if v.ParentId == parentId {
  10. v.Children = GetMenuTreeRecursive(list, v.MenuId)
  11. res = append(res, v)
  12. }
  13. }
  14. return res
  15. }
  16. // GetMenuChildrenIdsRecursive 遍历子菜单IDs
  17. func GetMenuChildrenIdsRecursive(list []*eta_business.EtaBusinessMenu, parentId int) []int {
  18. res := make([]int, 0)
  19. for _, v := range list {
  20. if v.ParentId == parentId {
  21. ids := GetMenuChildrenIdsRecursive(list, v.MenuId)
  22. res = append(res, v.MenuId)
  23. res = append(res, ids...)
  24. }
  25. }
  26. return res
  27. }
  28. // GetMenuParentsRecursive 遍历子菜单的所有父级菜单
  29. func GetMenuParentsRecursive(list []*eta_business.EtaBusinessMenu, parentId int) []*eta_business.EtaBusinessMenu {
  30. res := make([]*eta_business.EtaBusinessMenu, 0)
  31. for _, v := range list {
  32. if v.MenuId == parentId {
  33. res = append(res, v)
  34. parents := make([]*eta_business.EtaBusinessMenu, 0)
  35. if v.ParentId > 0 {
  36. parents = GetMenuParentsRecursive(list, v.ParentId)
  37. }
  38. res = append(res, parents...)
  39. }
  40. }
  41. return res
  42. }