public AuthStrategyDto NormalAuthStrategy(int employeeId)
        {
            var result      = new AuthStrategyDto();
            var userRoleIds = _relevanceBusiness.Query(p => p.FirstId == employeeId && p.Identifiers == PowerIdentifiers.UserByRole).Select(p => p.SecondId);

            if (userRoleIds.Count() == 0)
            {
                return(result);
            }
            var roleIds = _roleBusiness.Query(p => userRoleIds.Contains(p.Id) && p.Status == NomalStatus.Valid).Select(p => p.Id);

            if (userRoleIds.Count() == 0)
            {
                return(result);
            }

            //先拉取角色对应的模块和元素
            var relevanceIds = _relevanceBusiness.Query(p => roleIds.Contains(p.FirstId));
            var moduleIds    = relevanceIds.Where(p => p.Identifiers == PowerIdentifiers.RoleByModule).Select(p => p.SecondId);

            if (moduleIds.Count() == 0)
            {
                return(result);
            }

            List <KeyValuePair <string, OrderBy> > order = new List <KeyValuePair <string, OrderBy> >()
            {
                new KeyValuePair <string, OrderBy>("Level", OrderBy.Asc),
                new KeyValuePair <string, OrderBy>("DisplayOrder", OrderBy.Asc)
            };
            var modules = _moduleBusiness.Query(p => moduleIds.Contains(p.Id) && p.Status == NomalStatus.Valid, p => p, order);

            result.Modules = modules.Select(p => new PowerModuleDto()
            {
                Id       = p.Id,
                Name     = p.Name,
                Code     = p.Code,
                Level    = p.Level,
                Pid      = p.Pid,
                Url      = p.Url,
                IconName = p.IconName
            }).GenerateTree(p => p.Id, p => p.Pid).ToList();

            //模块元素
            var elementIds = relevanceIds.Where(p => p.Identifiers == PowerIdentifiers.RoleByElement).Select(p => p.SecondId);
            var elements   = _elementBusiness.Query(p => elementIds.Contains(p.Id) && p.IsSystem == 0 && p.Status == NomalStatus.Valid);

            result.Elements = modules.Select(p => new PowerModuleElementDto()
            {
                Id       = p.Id,
                Code     = p.Code,
                Name     = p.Name,
                Elements = elements.Where(p1 => p1.ModuleId == p.Id).OrderBy(p1 => p1.DisplayOrder).ToList()
            }).ToList();

            return(result);
        }
示例#2
0
        /// <summary>
        /// [列表] 迭代
        /// </summary>
        public List <PowerModuleDto> QueryNav(int roleId)
        {
            List <KeyValuePair <string, OrderBy> > order = new List <KeyValuePair <string, OrderBy> >()
            {
                new KeyValuePair <string, OrderBy>("Level", OrderBy.Asc),
                new KeyValuePair <string, OrderBy>("DisplayOrder", OrderBy.Asc),
            };

            var oldList = _moduleBusiness.Query(p => p.Code != "050001" & p.Status == NomalStatus.Valid, p => p, order).MapToList <PowerModuleDto>();

            //获取角色对应的模块元素
            var lsCheckElement = new List <PowerRelevance>();

            if (roleId > 0)
            {
                lsCheckElement = _relevanceBusiness.Query(p => p.FirstId == roleId & p.Identifiers == PowerIdentifiers.RoleByElement).ToList();
            }
            //获取 模块元素
            var lsElement = _elementBusiness.Query(p => p.Status == NomalStatus.Valid, p => new PowerElement()
            {
                Id           = p.Id,
                ModuleId     = p.ModuleId,
                Name         = p.Name,
                DomId        = p.DomId,
                DisplayOrder = p.DisplayOrder,
                IsSystem     = p.IsSystem,
                Class        = p.Class,
                Position     = p.Position,
                IconName     = p.IconName,
                Checkeds     = roleId == 0 ? 0 : lsCheckElement.Count(p2 => p2.SecondId == p.Id)
            }).ToList();

            var newList = new List <PowerModuleDto>();

            //调用迭代组合成List
            GetChilds(oldList, newList, 0, 0);

            var resultList = new List <PowerModuleDto>();

            foreach (var item in newList)
            {
                item.Elements = lsElement.Where(p => p.ModuleId == item.Id).OrderBy(p => p.DisplayOrder).ToList();
            }

            return(newList);
        }