public ActionResult GetTreeJson(string organize_id) { var treeList = new List <TreeViewModel>(); //获取所有分公司和部门信息 var data = organizeApp.GetList(); //分公司 OrganizeEntity company = organizeApp.GetOrgById(organize_id); TreeViewModel tree = new TreeViewModel(); List <OrganizeEntity> departmentList = data.FindAll(t => t.F_ParentId == company.F_Id); bool hasChildren = departmentList.Count == 0 ? false : true; tree.id = company.F_Id; tree.text = company.F_FullName; tree.value = company.F_EnCode; tree.parentId = company.F_ParentId; tree.isexpand = true; tree.complete = true; tree.hasChildren = hasChildren; tree.nodeDepth = 1; treeList.Add(tree); //部门 if (hasChildren) { for (int i = 0; i < departmentList.Count; i++) { OrganizeEntity department = departmentList[i]; TreeViewModel departmentTree = new TreeViewModel(); var roleData = roleApp.GetDutyList(); List <RoleEntity> dutyList = roleData.FindAll(t => t.F_OrganizeId == department.F_Id && t.F_Category == 2); hasChildren = dutyList.Count == 0 ? false : true; departmentTree.id = department.F_Id; departmentTree.text = department.F_FullName; departmentTree.value = department.F_EnCode; departmentTree.parentId = company.F_Id; departmentTree.isexpand = true; departmentTree.complete = true; departmentTree.hasChildren = hasChildren; departmentTree.nodeDepth = 2; treeList.Add(departmentTree); //岗位 if (hasChildren) { for (int j = 0; j < dutyList.Count; j++) { RoleEntity duty = dutyList[j]; TreeViewModel dutyTree = new TreeViewModel(); var userData = userApp.GetList(); List <UserEntity> userList = userData.FindAll(t => t.F_DutyId == duty.F_Id && t.F_OrganizeId == company.F_Id && t.F_DepartmentId == department.F_Id); hasChildren = userList.Count == 0 ? false : true; dutyTree.id = duty.F_Id; dutyTree.text = duty.F_FullName; dutyTree.value = duty.F_EnCode; dutyTree.parentId = department.F_Id; dutyTree.isexpand = true; dutyTree.complete = true; dutyTree.hasChildren = hasChildren; dutyTree.nodeDepth = 3; treeList.Add(dutyTree); if (hasChildren) { for (int k = 0; k < userList.Count; k++) { UserEntity user = userList[k]; TreeViewModel userTree = new TreeViewModel(); hasChildren = false; userTree.id = user.F_Id; userTree.text = user.F_RealName; userTree.value = user.F_Id; userTree.parentId = duty.F_Id; userTree.isexpand = true; userTree.complete = true; userTree.hasChildren = hasChildren; userTree.nodeDepth = 4; treeList.Add(userTree); } } } } } } return(Content(treeList.TreeViewJson(company.F_ParentId))); }