package services import "hongze/hz_crm_api/models/cygx" func MakeTree(allNode []*cygx.CygxIndustryMapItems, node *cygx.CygxIndustryMapItems) { childs, _ := haveChild(allNode, node) //判断节点是否有子节点并返回 if len(childs) > 0 { node.Children = append(node.Children, childs[0:]...) //添加子节点 for _, v := range childs { //查询子节点的子节点,并添加到子节点 _, has := haveChild(allNode, v) if has { MakeTree(allNode, v) //递归添加节点 } } } } func haveChild(allNode []*cygx.CygxIndustryMapItems, node *cygx.CygxIndustryMapItems) (childs []*cygx.CygxIndustryMapItems, yes bool) { for _, v := range allNode { if v.ParentId == node.IndustryMapId { childs = append(childs, v) } } if len(childs) > 0 { yes = true } return }