1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- package data
- import (
- "eta/eta_mobile/models/data_manage"
- )
- func chartClassifyHaveChild(allNode []*data_manage.ChartClassifyItems, node *data_manage.ChartClassifyItems) (childs []*data_manage.ChartClassifyItems, yes bool) {
- for _, v := range allNode {
- if v.ParentId == node.ChartClassifyId {
- childs = append(childs, v)
- }
- }
- if len(childs) > 0 {
- yes = true
- }
- return
- }
- func ChartClassifyItemsMakeTree(allNode []*data_manage.ChartClassifyItems, node *data_manage.ChartClassifyItems) {
- childs, _ := chartClassifyHaveChild(allNode, node) //判断节点是否有子节点并返回
- if len(childs) > 0 {
- node.Children = append(node.Children, childs[0:]...) //添加子节点
- for _, v := range childs { //查询子节点的子节点,并添加到子节点
- _, has := chartClassifyHaveChild(allNode, v)
- if has {
- ChartClassifyItemsMakeTree(allNode, v) //递归添加节点
- } else {
- childrenArr := make([]*data_manage.ChartClassifyItems, 0)
- v.Children = childrenArr
- }
- }
- } else {
- childrenArr := make([]*data_manage.ChartClassifyItems, 0)
- node.Children = childrenArr
- }
- }
- // HandleNoPermissionChart 图表列表返回,将没有权限的图表移除
- func HandleNoPermissionChart(allNodes []*data_manage.ChartClassifyItems, noPermissionChartIdMap map[int]bool) (newAllNodes []*data_manage.ChartClassifyItems) {
- // 移除没有权限的图表
- newAllNodes = make([]*data_manage.ChartClassifyItems, 0)
- for _, node := range allNodes {
- // 二级分类
- tmpNodeInfo := *node
- tmpNodeList := make([]*data_manage.ChartClassifyItems, 0)
- if node.Children != nil {
- for _, chartList := range node.Children {
- tmpInfo := *chartList
- tmpList := make([]*data_manage.ChartClassifyItems, 0)
- if chartList.Children != nil {
- for _, chartInfo := range chartList.Children {
- thirdInfo := *chartInfo
- thirdList := make([]*data_manage.ChartClassifyItems, 0)
- // 如果指标不可见,那么就不返回该指标
- if _, ok := noPermissionChartIdMap[chartInfo.ChartInfoId]; ok {
- continue
- }
- tmpList = append(tmpList, chartInfo)
- if chartInfo.Children != nil {
- for _, thirdChart := range chartInfo.Children {
- // 如果指标不可见,那么就不返回该指标
- if _, ok := noPermissionChartIdMap[chartInfo.ChartInfoId]; ok {
- continue
- }
- thirdList = append(thirdList, thirdChart)
- }
- }
- thirdInfo.Children = thirdList
- tmpList = append(tmpList, &thirdInfo)
- }
- }
- tmpInfo.Children = tmpList
- tmpNodeList = append(tmpNodeList, &tmpInfo)
- }
- }
- tmpNodeInfo.Children = tmpNodeList
- newAllNodes = append(newAllNodes, &tmpNodeInfo)
- }
- return
- }
|