chart_classify.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. package data
  2. import (
  3. "hongze/hz_crm_api/models/data_manage"
  4. )
  5. func chartClassifyHaveChild(allNode []*data_manage.ChartClassifyItems, node *data_manage.ChartClassifyItems) (childs []*data_manage.ChartClassifyItems, yes bool) {
  6. for _, v := range allNode {
  7. if v.ParentId == node.ChartClassifyId {
  8. childs = append(childs, v)
  9. }
  10. }
  11. if len(childs) > 0 {
  12. yes = true
  13. }
  14. return
  15. }
  16. func ChartClassifyItemsMakeTree(allNode []*data_manage.ChartClassifyItems, node *data_manage.ChartClassifyItems) {
  17. childs, _ := chartClassifyHaveChild(allNode, node) //判断节点是否有子节点并返回
  18. if len(childs) > 0 {
  19. node.Children = append(node.Children, childs[0:]...) //添加子节点
  20. for _, v := range childs { //查询子节点的子节点,并添加到子节点
  21. _, has := chartClassifyHaveChild(allNode, v)
  22. if has {
  23. ChartClassifyItemsMakeTree(allNode, v) //递归添加节点
  24. } else {
  25. childrenArr := make([]*data_manage.ChartClassifyItems, 0)
  26. v.Children = childrenArr
  27. }
  28. }
  29. } else {
  30. childrenArr := make([]*data_manage.ChartClassifyItems, 0)
  31. node.Children = childrenArr
  32. }
  33. }