Ejemplo n.º 1
0
        public ActionResult GetTreeJson(string keyword)
        {
            string dataAutor = string.Format(OperatorProvider.Provider.Current().DataAuthorize.ReadAutorize, OperatorProvider.Provider.Current().UserId);

            //var organizedata = organizeCache.GetList();
            //var departmentdata = departmentCache.GetList();
            //var userdata = userCache.GetList();
            var organizedata   = organizeCache.GetListByIds();
            var departmentdata = departmentCache.GetListByIds();
            var userdata       = userCache.GetListByIds();

            var treeList = new List <TreeEntity>();

            foreach (OrganizeEntity item in organizedata)
            {
                #region 机构
                TreeEntity tree        = new TreeEntity();
                bool       hasChildren = organizedata.Count(t => t.ParentId == item.OrganizeId) == 0 ? false : true;
                if (hasChildren == false)
                {
                    hasChildren = departmentdata.Count(t => t.OrganizeId == item.OrganizeId) == 0 ? false : true;
                    if (hasChildren == false)
                    {
                        continue;
                    }
                }
                tree.id             = item.OrganizeId;
                tree.text           = item.FullName;
                tree.value          = item.OrganizeId;
                tree.parentId       = item.ParentId;
                tree.isexpand       = true;
                tree.complete       = true;
                tree.hasChildren    = hasChildren;
                tree.Attribute      = "Sort";
                tree.AttributeValue = "Organize";
                treeList.Add(tree);
                #endregion
            }
            foreach (DepartmentEntity item in departmentdata)
            {
                #region 部门
                TreeEntity tree = new TreeEntity();
                tree.id    = item.DepartmentId;
                tree.text  = item.FullName;
                tree.value = item.DepartmentId;
                if (item.ParentId == "0")
                {
                    tree.parentId = item.OrganizeId;
                }
                else
                {
                    tree.parentId = item.ParentId;
                }
                tree.isexpand       = true;
                tree.complete       = true;
                tree.hasChildren    = true;
                tree.Attribute      = "Sort";
                tree.AttributeValue = "Department";
                treeList.Add(tree);
                #endregion
            }
            foreach (UserEntity item in userdata)
            {
                #region 用户
                TreeEntity tree = new TreeEntity();
                tree.id             = item.UserId;
                tree.text           = item.RealName;
                tree.value          = item.Account;
                tree.parentId       = item.DepartmentId;
                tree.title          = item.RealName + "(" + item.Account + ")";
                tree.isexpand       = true;
                tree.complete       = true;
                tree.hasChildren    = false;
                tree.Attribute      = "Sort";
                tree.AttributeValue = "User";
                tree.img            = "fa fa-user";
                treeList.Add(tree);
                #endregion
            }
            if (!string.IsNullOrEmpty(keyword))
            {
                treeList = treeList.TreeWhere(t => t.text.Contains(keyword), "id", "parentId");
            }
            return(Content(treeList.TreeToJson()));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 部门列表
        /// </summary>
        /// <param name="keyword">关键字</param>
        /// <returns>返回机构+部门树形Json</returns>
        public ActionResult GetOrganizeTreeJson(string keyword)
        {
            //var organizedata = organizeCache.GetList();
            var organizedata = organizeCache.GetListByIds();
            //var departmentdata = departmentBLL.GetList();
            var departmentdata = departmentCache.GetListByIds();

            organizedata.First().ParentId = "0";//分级机构登录时,默认第一个上级机构为0;才能展示出树形结构

            var treeList = new List <TreeEntity>();

            foreach (OrganizeEntity item in organizedata)
            {
                #region 机构
                TreeEntity tree        = new TreeEntity();
                bool       hasChildren = organizedata.Count(t => t.ParentId == item.OrganizeId) == 0 ? false : true;
                //if (hasChildren == false)
                //{
                //    hasChildren = departmentdata.Count(t => t.OrganizeId == item.OrganizeId) == 0 ? false : true;
                //    if (hasChildren == false)
                //    {
                //        continue;
                //    }
                //}
                tree.id             = item.OrganizeId;
                tree.text           = item.FullName;
                tree.value          = item.OrganizeId;
                tree.parentId       = item.ParentId;
                tree.isexpand       = true;
                tree.complete       = true;
                tree.hasChildren    = hasChildren;
                tree.Attribute      = "Sort";
                tree.AttributeValue = "Organize";
                treeList.Add(tree);
                #endregion
            }
            foreach (DepartmentEntity item in departmentdata)
            {
                #region 部门
                TreeEntity tree        = new TreeEntity();
                bool       hasChildren = departmentdata.Count(t => t.ParentId == item.DepartmentId) == 0 ? false : true;
                tree.id    = item.DepartmentId;
                tree.text  = item.FullName;
                tree.value = item.DepartmentId;
                if (item.ParentId == "0")
                {
                    tree.parentId = item.OrganizeId;
                }
                else
                {
                    tree.parentId = item.ParentId;
                }
                tree.isexpand       = true;
                tree.complete       = true;
                tree.hasChildren    = hasChildren;
                tree.Attribute      = "Sort";
                tree.AttributeValue = "Department";
                treeList.Add(tree);
                #endregion
            }
            if (!string.IsNullOrEmpty(keyword))
            {
                treeList = treeList.TreeWhere(t => t.text.Contains(keyword), "id", "parentId");
            }
            return(Content(treeList.TreeToJson()));
        }