chart_classify.go 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. package data
  2. import (
  3. "eta/eta_mobile/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. }
  34. // HandleNoPermissionChart 图表列表返回,将没有权限的图表移除
  35. func HandleNoPermissionChart(allNodes []*data_manage.ChartClassifyItems, noPermissionChartIdMap map[int]bool) (newAllNodes []*data_manage.ChartClassifyItems) {
  36. // 移除没有权限的图表
  37. newAllNodes = make([]*data_manage.ChartClassifyItems, 0)
  38. for _, node := range allNodes {
  39. // 二级分类
  40. tmpNodeInfo := *node
  41. tmpNodeList := make([]*data_manage.ChartClassifyItems, 0)
  42. if node.Children != nil {
  43. for _, chartList := range node.Children {
  44. tmpInfo := *chartList
  45. tmpList := make([]*data_manage.ChartClassifyItems, 0)
  46. if chartList.Children != nil {
  47. for _, chartInfo := range chartList.Children {
  48. thirdInfo := *chartInfo
  49. thirdList := make([]*data_manage.ChartClassifyItems, 0)
  50. // 如果指标不可见,那么就不返回该指标
  51. if _, ok := noPermissionChartIdMap[chartInfo.ChartInfoId]; ok {
  52. continue
  53. }
  54. tmpList = append(tmpList, chartInfo)
  55. if chartInfo.Children != nil {
  56. for _, thirdChart := range chartInfo.Children {
  57. // 如果指标不可见,那么就不返回该指标
  58. if _, ok := noPermissionChartIdMap[chartInfo.ChartInfoId]; ok {
  59. continue
  60. }
  61. thirdList = append(thirdList, thirdChart)
  62. }
  63. }
  64. thirdInfo.Children = thirdList
  65. tmpList = append(tmpList, &thirdInfo)
  66. }
  67. }
  68. tmpInfo.Children = tmpList
  69. tmpNodeList = append(tmpNodeList, &tmpInfo)
  70. }
  71. }
  72. tmpNodeInfo.Children = tmpNodeList
  73. newAllNodes = append(newAllNodes, &tmpNodeInfo)
  74. }
  75. return
  76. }