예제 #1
0
        public async Task <IResultModel> GetTree()
        {
            if (_cacheHandler.TryGetValue(CacheKeys.EMPLOYEE_TREE, out TreeResultModel <int, EmployeeTreeResultModel> root))
            {
                return(ResultModel.Success(root));
            }

            var allDepart = await _departmentRepository.GetAllAsync();

            var config = _configProvider.Get <PersonnelFilesConfig>();

            root = new TreeResultModel <int, EmployeeTreeResultModel>
            {
                Label = config.CompanyName,
                Item  = new EmployeeTreeResultModel
                {
                    SourceId = "",
                    Name     = config.CompanyName
                }
            };

            root.Children = ResolveTree(allDepart, Guid.Empty, root);

            root.Id = 0;

            if (root.Children.Any())
            {
                await _cacheHandler.SetAsync(CacheKeys.EMPLOYEE_TREE, root);
            }

            return(ResultModel.Success(root));
        }
예제 #2
0
        private List <TreeResultModel <string, DictItemTreeResultModel> > ResolveTree(IList <DictItemEntity> all, TreeResultModel <string, DictItemTreeResultModel> parent)
        {
            return(all.Where(m => m.ParentId == parent.Item.Id).OrderBy(m => m.Sort).Select(m =>
            {
                var node = new TreeResultModel <string, DictItemTreeResultModel>
                {
                    Id = m.Value,
                    Label = m.Name,
                    Item = new DictItemTreeResultModel
                    {
                        Id = m.Id,
                        Name = m.Name,
                        Extend = m.Extend,
                        Icon = m.Icon,
                        Level = m.Level,
                        ParentId = m.ParentId,
                        Sort = m.Sort,
                        Value = m.Value
                    }
                };
                node.Item.IdList.AddRange(parent.Item.IdList);
                node.Item.IdList.Add(m.Value);

                node.Path.AddRange(parent.Path);
                node.Path.Add(node.Label);
                node.Children = ResolveTree(all, node);
                return node;
            }).ToList());
        }
예제 #3
0
        /// <summary>
        /// 加载用户权限树
        /// </summary>
        /// <returns></returns>
        public async Task <List <TreeResultModel <int, MenuEntity> > > LoadUserTree()
        {
            List <TreeResultModel <int, MenuEntity> > list = new List <TreeResultModel <int, MenuEntity> >();
            var menus = await _repository.GetListByUser();

            menus = menus.OrderByDescending(a => a.Seq).ToList();
            var parentMenus = menus.Where(a => a.Fid == 0).ToList();

            foreach (var item in parentMenus)
            {
                var _tree = new TreeResultModel <int, MenuEntity>
                {
                    Id      = item.Id,
                    Text    = item.MenuName,
                    IconCls = item.Icon,
                    Item    = new MenuEntity()
                };
                _tree.Path.Add(_tree.Text);
                LoadTreeLoop(_tree, menus);

                list.Add(_tree);
            }

            return(list);
        }
예제 #4
0
        private void LoadTreeLoop(TreeResultModel <int, MenuEntity> ParentTree, IEnumerable <MenuEntity> Menus)
        {
            var list = Menus.Where(a => a.Fid == ParentTree.Id).ToList();

            if (list.Count > 0)
            {
                ParentTree.Children = new List <TreeResultModel <int, MenuEntity> >();
            }
            //模块
            foreach (var item in list)
            {
                var itemNode = new TreeResultModel <int, MenuEntity>
                {
                    Id      = item.Id,
                    Text    = item.MenuName,
                    IconCls = item.Icon,
                    Item    = item
                };
                LoadTreeLoop(itemNode, Menus);

                itemNode.Path.AddRange(ParentTree.Path);
                itemNode.Path.Add(item.MenuName);

                ParentTree.Children.Add(itemNode);
            }
        }
예제 #5
0
        public async Task <IResultModel> Tree(string group, string code)
        {
            if (group.IsNull() || code.IsNull())
            {
                return(ResultModel.Failed("请指定分组和编码"));
            }

            var dict = await _dictionaryRepository.FirstAsync(m => m.GroupCode == group && m.Code == code && m.IsDel == false);

            if (dict == null)
            {
                return(ResultModel.Failed("字典不存在"));
            }

            var root = new TreeResultModel <string, DictionaryItemTreeResultModel>
            {
                Id    = dict.Id,
                Label = dict.Name,
                Item  = new DictionaryItemTreeResultModel
                {
                    Id   = dict.Id,
                    Name = dict.Name
                }
            };

            var all = await _dictionaryItemRepository.GetListAsync(m => m.GroupCode == group && m.DictCode == code && m.IsDel == false);

            root.Children = ResolveTree(all, dict.Id);


            return(ResultModel.Success(root));
        }
예제 #6
0
        private List <TreeResultModel <int, EmployeeTreeResultModel> > ResolveTree(IList <DepartmentEntity> all, Guid parentId, TreeResultModel <int, EmployeeTreeResultModel> root)
        {
            return(all.Where(m => m.ParentId == parentId).OrderBy(m => m.Sort)
                   .Select(m =>
            {
                var node = new TreeResultModel <int, EmployeeTreeResultModel>
                {
                    Id = ++root.Id,
                    Label = m.Name,
                    Item = new EmployeeTreeResultModel
                    {
                        SourceId = m.Id.ToString(),
                        Name = m.Name
                    },
                    Children = new List <TreeResultModel <int, EmployeeTreeResultModel> >()
                };

                node.Children.AddRange(ResolveTree(all, m.Id, root));

                var employeeList = _repository.QueryByDepartment(m.Id).Result;
                if (employeeList.Any())
                {
                    foreach (var employeeEntity in employeeList)
                    {
                        //排除已离职人员
                        if (employeeEntity.Status == EmployeeStatus.Leave)
                        {
                            continue;
                        }

                        node.Children.Add(new TreeResultModel <EmployeeTreeResultModel>
                        {
                            Id = ++root.Id,
                            Label = employeeEntity.Name,
                            Item = new EmployeeTreeResultModel
                            {
                                Type = 1,
                                SourceId = employeeEntity.Id.ToString(),
                                Name = employeeEntity.Name,
                                PostName = employeeEntity.PostName,
                                Sex = employeeEntity.Sex,
                                DepartmentPath = employeeEntity.DepartmentPath
                            }
                        });
                    }
                }

                return node;
            }).ToList());
        }
예제 #7
0
        public async Task <IResultModel> GetTree()
        {
            var all = await _menuRepository.GetAllAsync();

            var root = new TreeResultModel <Guid, MenuTreeResultModel>
            {
                Id    = Guid.Empty,
                Label = _systemConfig.Base.Title,
                Item  = new MenuTreeResultModel()
            };

            root.Path.Add(root.Label);
            root.Children = ResolveTree(all, root);
            return(ResultModel.Success(root));
        }
예제 #8
0
        private List <TreeResultModel <string, UserTreeResultModel> > ResolveTree(IList <OrganizeEntity> allOrg, IList <UserEntity> allUser, string parentId)
        {
            return(allOrg.Where(m => m.ParentId == parentId).OrderBy(m => m.OrganizeCode)
                   .Select(m =>
            {
                var node = new TreeResultModel <string, UserTreeResultModel>
                {
                    Id = m.Id,
                    Label = m.OrganizeName,
                    Item = new UserTreeResultModel
                    {
                        Type = 0,
                        SourceId = m.OrganizeCode,
                        Name = m.OrganizeName
                    },
                    Children = new List <TreeResultModel <string, UserTreeResultModel> >()
                };

                node.Children.AddRange(ResolveTree(allOrg, allUser, m.Id));

                var users = allUser.Where(t => t.OrganizeId == m.Id);

                if (!users.Any())
                {
                    return node;
                }

                foreach (var user in users)
                {
                    node.Children.Add(new TreeResultModel <string, UserTreeResultModel>
                    {
                        Id = user.Id,
                        Label = user.UserName,
                        Item = new UserTreeResultModel
                        {
                            Type = 1,
                            SourceId = user.Id.ToString(),
                            Code = user.UserCode,
                            Name = user.UserName,
                            Sex = user.Sex,
                            JobName = user.JobName
                        }
                    });
                }

                return node;
            }).ToList());
        }
        private List <TreeResultModel <int, DictItemTreeResultModel> > ResolveTree(IList <DictItemEntity> all, int parentId = 0)
        {
            return(all.Where(m => m.ParentId == parentId).OrderBy(m => m.Sort).Select(m =>
            {
                var node = new TreeResultModel <int, DictItemTreeResultModel>
                {
                    Id = m.Id,
                    Label = m.Name,
                    Value = m.Value,
                    Item = _mapper.Map <DictItemTreeResultModel>(m),
                    Children = ResolveTree(all, m.Id)
                };

                return node;
            }).ToList());
        }
예제 #10
0
 /// <summary>
 /// 解析菜单树
 /// </summary>
 private List <TreeResultModel <Guid, MenuTreeResultModel> > ResolveTree(IList <MenuEntity> all, TreeResultModel <Guid, MenuTreeResultModel> parent)
 {
     return(all.Where(m => m.ParentId == parent.Id).OrderBy(m => m.Sort)
            .Select(m =>
     {
         var menu = new TreeResultModel <Guid, MenuTreeResultModel>
         {
             Id = m.Id,
             Label = m.Name,
             Item = _mapper.Map <MenuTreeResultModel>(m)
         };
         menu.Path.AddRange(parent.Path);
         menu.Path.Add(m.Name);
         menu.Children = ResolveTree(all, menu);
         return menu;
     }).ToList());
 }
예제 #11
0
        public async Task <IResultModel> Tree(string group, string code)
        {
            if (group.IsNull() || code.IsNull())
            {
                return(ResultModel.Failed("请指定分组和编码"));
            }

            TreeResultModel <string, DictItemTreeResultModel> tree;
            var key = string.Format(CacheKeys.DictTree, group.ToUpper(), code.ToUpper());

            if (_options.DictCacheEnabled)
            {
                tree = await _cacheHandler.GetAsync <TreeResultModel <string, DictItemTreeResultModel> >(key);

                if (tree != null)
                {
                    return(ResultModel.Success(tree));
                }
            }

            var dict = await _repository.GetByCode(group, code);

            if (dict == null)
            {
                return(ResultModel.Failed("字典不存在"));
            }

            tree = new TreeResultModel <string, DictItemTreeResultModel>
            {
                Id    = "",
                Label = dict.Name,
                Path  = { dict.Name },
                Item  = new DictItemTreeResultModel()
            };
            var list = await _itemRepository.QueryAll(group, code);

            tree.Children = ResolveTree(list, tree);

            if (_options.DictCacheEnabled)
            {
                await _cacheHandler.SetAsync(key, tree);
            }

            return(ResultModel.Success(tree));
        }
예제 #12
0
        public async Task <IActionResult> Select(bool easyui)
        {
            List <TreeResultModel <int, MenuEntity> > list = new List <TreeResultModel <int, MenuEntity> >();
            var result = await _service.LoadTree();

            var NullModel = new TreeResultModel <int, MenuEntity>()
            {
                Id       = 0,
                Text     = "无上级菜单",
                Children = result
            };

            list.Add(NullModel);
            if (easyui)
            {
                return(Json(list));
            }
            return(Json(ResultModel.Success(list)));
        }
        public async Task <IResultModel> Tree(string group, string code)
        {
            if (group.IsNull() || code.IsNull())
            {
                return(ResultModel.Failed("请指定分组和编码"));
            }

            var config = _configProvider.Get <CommonConfig>();
            var key    = $"{CacheKeys.DICT_TREE}:{group.ToUpper()}_{code.ToUpper()}";

            if (config.DictCacheEnabled && _cacheHandler.TryGetValue(key, out TreeResultModel <int, DictItemTreeResultModel> root))
            {
                return(ResultModel.Success(root));
            }

            var dict = await _repository.GetByCode(group, code);

            if (dict == null)
            {
                return(ResultModel.Failed("字典不存在"));
            }

            root = new TreeResultModel <int, DictItemTreeResultModel>
            {
                Id    = 0,
                Label = dict.Name,
                Item  = new DictItemTreeResultModel
                {
                    Name = dict.Name
                }
            };

            var all = await _itemRepository.QueryAll(group, code);

            root.Children = ResolveTree(all);

            if (config.DictCacheEnabled)
            {
                await _cacheHandler.SetAsync(key, root);
            }

            return(ResultModel.Success(root));
        }
예제 #14
0
        public async Task <IResultModel> GetTree()
        {
            //先取缓存
            if (_cacheHandler.TryGetValue(CacheKeys.PermissionTree, out TreeResultModel <int, PermissionTreeResultModel> root))
            {
                return(ResultModel.Success(root));
            }

            var id = 0;

            root = new TreeResultModel <int, PermissionTreeResultModel>
            {
                Id    = id,
                Label = _systemConfig.Base.Title,
                Item  = new PermissionTreeResultModel()
            };
            root.Path.Add(root.Label);

            var modules     = _moduleRepository.GetAllAsync();
            var permissions = await _repository.GetAllAsync();

            //模块
            foreach (var module in await modules)
            {
                var moduleNode = new TreeResultModel <int, PermissionTreeResultModel>
                {
                    Id    = ++id,
                    Label = module.Name,
                    Item  = new PermissionTreeResultModel
                    {
                        Label = module.Name,
                        Code  = module.Code
                    }
                };

                moduleNode.Path.AddRange(root.Path);
                moduleNode.Path.Add(module.Name);

                var controllers = permissions.Where(m => m.ModuleCode.EqualsIgnoreCase(module.Code)).DistinctBy(m => m.Controller);
                //控制器
                foreach (var controller in controllers)
                {
                    var controllerName = controller.Name.Split('_')[0];
                    var controllerNode = new TreeResultModel <int, PermissionTreeResultModel>
                    {
                        Id    = ++id,
                        Label = controllerName,
                        Item  = new PermissionTreeResultModel
                        {
                            Label = controllerName,
                            Code  = controller.Controller
                        }
                    };

                    controllerNode.Path.AddRange(moduleNode.Path);
                    controllerNode.Path.Add(controllerName);

                    var permissionList = permissions.Where(m => m.ModuleCode.EqualsIgnoreCase(module.Code) && m.Controller.EqualsIgnoreCase(controller.Controller));
                    //权限
                    foreach (var permission in permissionList)
                    {
                        var permissionName = permission.Name.Contains("_") ? permission.Name.Split('_')[1] : permission.Name;
                        var permissionNode = new TreeResultModel <int, PermissionTreeResultModel>
                        {
                            Id    = ++id,
                            Label = permissionName,
                            Item  = new PermissionTreeResultModel
                            {
                                Label        = permissionName,
                                Code         = permission.Code,
                                IsPermission = true
                            }
                        };

                        permissionNode.Path.AddRange(controllerNode.Path);
                        permissionNode.Path.Add(permissionName);

                        controllerNode.Children.Add(permissionNode);
                    }

                    moduleNode.Children.Add(controllerNode);
                }
                root.Children.Add(moduleNode);
            }

            await _cacheHandler.SetAsync(CacheKeys.PermissionTree, root);

            return(ResultModel.Success(root));
        }
예제 #15
0
        /// <summary>
        /// 加载权限树
        /// </summary>
        /// <returns></returns>
        private void LoadTree()
        {
            var config = _configProvider.Get <SystemConfig>();

            _tree = new TreeResultModel <string, PermissionTreeModel>
            {
                Id    = "",
                Label = config.Title,
                Item  = new PermissionTreeModel()
            };
            _tree.Path.Add(_tree.Label);

            var controllers = _mvcHelper.GetAllController();

            //模块
            foreach (var module in _moduleCollection)
            {
                var moduleNode = new TreeResultModel <string, PermissionTreeModel>
                {
                    Id    = module.Code,
                    Label = module.Name,
                    Item  = new PermissionTreeModel
                    {
                        Label = module.Name,
                        Code  = module.Code
                    }
                };

                moduleNode.Path.AddRange(_tree.Path);
                moduleNode.Path.Add(module.Name);

                //控制器
                foreach (var controller in controllers.Where(m => m.Area.EqualsIgnoreCase(module.Code)))
                {
                    var controllerName = controller.Description ?? controller.Name;
                    var controllerNode = new TreeResultModel <string, PermissionTreeModel>
                    {
                        Id    = $"{module.Code}_{controller.Name}".ToLower(),
                        Label = controllerName,
                        Item  = new PermissionTreeModel
                        {
                            Label = controllerName
                        }
                    };

                    controllerNode.Item.Code = controllerNode.Id;

                    controllerNode.Path.AddRange(moduleNode.Path);
                    controllerNode.Path.Add(controllerName);

                    var permissions = Query(module.Code, controller.Name);
                    //权限
                    foreach (var permission in permissions)
                    {
                        var permissionName = permission.Name.Contains("_") ? permission.Name.Split('_')[1] : permission.Name;
                        var permissionNode = new TreeResultModel <string, PermissionTreeModel>
                        {
                            Id    = permission.Code,
                            Label = permissionName,
                            Item  = new PermissionTreeModel
                            {
                                Label        = permissionName,
                                Code         = permission.Code,
                                IsPermission = true
                            }
                        };

                        permissionNode.Path.AddRange(controllerNode.Path);
                        permissionNode.Path.Add(permissionName);

                        controllerNode.Children.Add(permissionNode);
                    }

                    moduleNode.Children.Add(controllerNode);
                }
                _tree.Children.Add(moduleNode);
            }
        }
예제 #16
0
        /// <summary>
        /// 加载权限树
        /// </summary>
        /// <returns></returns>
        private void LoadTree()
        {
            _tree = new TreeResultModel <string, PermissionTreeModel>
            {
                Id       = "",
                Text     = "Zoomtel",
                Item     = new PermissionTreeModel(),
                Children = new List <TreeResultModel <string, PermissionTreeModel> >()
            };
            _tree.Path.Add(_tree.Text);

            var controllers = _mvcHelper.GetAllController().Where(a => a.Area != null);


            //模块
            foreach (var module in _moduleCollection)
            {
                var moduleNode = new TreeResultModel <string, PermissionTreeModel>
                {
                    Id   = module.Code,
                    Text = module.Name,
                    Item = new PermissionTreeModel
                    {
                        Label = module.Name,
                        Code  = module.Code
                    }
                };

                moduleNode.Path.AddRange(_tree.Path);
                moduleNode.Path.Add(module.Name);

                var moduleControllers = controllers.Where(m => m.Area.EqualsIgnoreCase(module.Code));
                if (moduleControllers.Count() > 0)
                {
                    moduleNode.Children = new List <TreeResultModel <string, PermissionTreeModel> >();
                }
                //控制器
                foreach (var controller in moduleControllers)
                {
                    var controllerName = controller.Description ?? controller.Name;
                    var controllerNode = new TreeResultModel <string, PermissionTreeModel>
                    {
                        Id   = $"{module.Code}_{controller.Name}".ToLower(),
                        Text = controllerName,
                        Item = new PermissionTreeModel
                        {
                            Label = controllerName
                        }
                    };

                    controllerNode.Item.Code = controllerNode.Id;

                    controllerNode.Path.AddRange(moduleNode.Path);
                    controllerNode.Path.Add(controllerName);

                    var permissions = Query(module.Code, controller.Name);
                    if (permissions.Count > 0)
                    {
                        controllerNode.Children = new List <TreeResultModel <string, PermissionTreeModel> >();
                    }
                    //权限
                    foreach (var permission in permissions)
                    {
                        var permissionName = permission.Name.Contains("_") ? permission.Name.Split('_')[1] : permission.Name;
                        var permissionNode = new TreeResultModel <string, PermissionTreeModel>
                        {
                            Id   = permission.Code,
                            Text = permissionName,
                            Item = new PermissionTreeModel
                            {
                                Label        = permissionName,
                                Code         = permission.Code,
                                IsPermission = true,
                                IsPage       = permission.IsPage
                            }
                        };

                        permissionNode.Path.AddRange(controllerNode.Path);
                        permissionNode.Path.Add(permissionName);

                        controllerNode.Children.Add(permissionNode);
                    }
                    moduleNode.Children.Add(controllerNode);
                }
                _tree.Children.Add(moduleNode);
            }
        }