/// <summary> /// 根据当前节点,加载子节点 /// </summary> /// <param name="treeEntitys">TreeEntity的集合</param> /// <param name="currTreeEntity">当前节点</param> private IList <SystemOrganizationChartOutput> GetWdChildNodes(ref List <SystemOrganization> treeEntitys, SystemOrganization currTreeEntity) { IList <SystemOrganization> childNodes = treeEntitys.Where(f => f.ParentId.ToString() == currTreeEntity.OrganizationId.ToString()).ToList(); if (childNodes.Count <= 0) { return(null); } IList <SystemOrganizationChartOutput> childTrees = new List <SystemOrganizationChartOutput>(childNodes.Count); SystemOrganizationChartOutput tree = null; foreach (var treeEntity in childNodes) { tree = new SystemOrganizationChartOutput { name = treeEntity.Name, title = treeEntity.MainSupervisor.IsNullOrEmpty() ? "" : treeEntity.MainSupervisor, children = GetWdChildNodes(ref treeEntitys, treeEntity) }; childTrees.Add(tree); } return(childTrees); }
/// <summary> /// /// </summary> /// <returns></returns> public async Task <IEnumerable <SystemOrganizationChartOutput> > GetOrganizationChart() { var allOrgs = (await GetAllEnumerableAsync()).ToList(); var topOrgs = allOrgs.Where(w => w.ParentId == Guid.Empty).ToList(); //总模块 IList <SystemOrganizationChartOutput> outputs = new List <SystemOrganizationChartOutput>(topOrgs.Count); foreach (var root in topOrgs) { outputs.Add(new SystemOrganizationChartOutput { id = root.OrganizationId, name = root.Name, title = root.MainSupervisor.IsNullOrEmpty() ? "" : root.MainSupervisor }); } //便利子模块 foreach (var permission in outputs) { //判断有多少个模块 IList <SystemOrganization> perRoots = allOrgs.Where(f => f.ParentId.ToString() == permission.id.ToString()).ToList(); IList <SystemOrganizationChartOutput> trees = new List <SystemOrganizationChartOutput>(); SystemOrganizationChartOutput tree = null; foreach (var treeEntity in perRoots) { tree = new SystemOrganizationChartOutput { name = treeEntity.Name, title = treeEntity.MainSupervisor.IsNullOrEmpty() ? "" : treeEntity.MainSupervisor, children = GetWdChildNodes(ref allOrgs, treeEntity) }; trees.Add(tree); } permission.children = trees; tree = null; } return(outputs); }