eta_training_video_classify.go 1.5 KB

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