/// <summary>
        /// 路由转换
        /// </summary>
        /// <param name="roteConvert">转换类型枚举</param>
        public static MvcRote RoteConvert(EnumPermissionRoteConvert roteConvert)
        {
            MvcRote mvcRote = new MvcRote();

            switch (roteConvert)
            {
            case EnumPermissionRoteConvert.组织机构数据权限:
                mvcRote.AppCode    = "EIP";
                mvcRote.Area       = "System";
                mvcRote.Controller = "Organization";
                mvcRote.Action     = "List";
                break;

            case EnumPermissionRoteConvert.人员数据权限:
                mvcRote.AppCode    = "EIP";
                mvcRote.Area       = "System";
                mvcRote.Controller = "User";
                mvcRote.Action     = "List";
                break;

            case EnumPermissionRoteConvert.企业信息数据权限:
                mvcRote.AppCode    = "EIP";
                mvcRote.Area       = "Supervise";
                mvcRote.Controller = "Enterprise";
                mvcRote.Action     = "List";
                break;
            }
            return(mvcRote);
        }
        /// <summary>
        /// 根据Mvc规则及用户Id获取字段权限字符串
        /// </summary>
        /// <param name="rote">Mvc规则</param>
        /// <param name="userId">当前用户Id</param>
        /// <returns></returns>
        public string GetFiledPermissionStrByMvcRote(MvcRote rote, Guid userId)
        {
            SystemFieldRepository repository = new SystemFieldRepository();

            //获取字段权限信息
            return(GetFieldStrByMenuIdAndUserId(repository.GetFieldByMenuIdAndUserId(rote, userId).ToList()));
        }
        /// <summary>
        ///     根据菜单Id和用户Id获取字段权限数据
        /// </summary>
        /// <param name="mvcRote"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public IEnumerable <SystemField> GetFieldByMenuIdAndUserId(MvcRote mvcRote, Guid userId)
        {
            const string procName = @"System_Proc_GetFieldPermissions";

            return(SqlMapperUtil.StoredProcWithParamsSync <SystemField>(procName,
                                                                        new { UserId = userId, mvcRote.Area, mvcRote.Controller, mvcRote.Action }));
        }
Example #4
0
        /// <summary>
        ///     根据菜单Id和用户Id获取按钮权限数据
        /// </summary>
        /// <param name="mvcRote"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public Task <IEnumerable <SystemMenuButton> > GetMenuButtonByMenuIdAndUserId(MvcRote mvcRote,
                                                                                     Guid userId)
        {
            const string procName = @"System_Proc_GetMenuButtonPermissions";

            return(SqlMapperUtil.StoredProcWithParams <SystemMenuButton>(procName,
                                                                         new { UserId = userId, mvcRote.Area, mvcRote.Controller, mvcRote.Action }));
        }
        /// <summary>
        /// 获取该用户拥有的数据权限
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public Task <IEnumerable <SystemData> > GetDataPermission(SystemPermissionSqlInput input)
        {
            const string procName = @"System_Proc_GetDataPermissions";
            MvcRote      rote     = PermissionRouteConvert.RoteConvert(input.EnumPermissionRoteConvert);

            return(SqlMapperUtil.StoredProcWithParams <SystemData>(procName,
                                                                   new
            {
                input.PrincipalUser.UserId,
                rote.Area,
                rote.Controller,
                rote.Action
            }));
        }
Example #6
0
        /// <summary>
        /// 路由转换
        /// </summary>
        /// <param name="roteConvert">转换类型枚举</param>
        public static MvcRote RoteConvert(EnumPermissionRoteConvert roteConvert)
        {
            MvcRote mvcRote = new MvcRote();

            switch (roteConvert)
            {
            case EnumPermissionRoteConvert.用户字段数据权限:
                mvcRote.AppCode    = "Solution";
                mvcRote.Area       = "System";
                mvcRote.Controller = "User";
                mvcRote.Action     = "List";
                break;
            }
            return(mvcRote);
        }
Example #7
0
        /// <summary>
        ///     根据路由信息获取菜单信息
        /// </summary>
        /// <param name="mvcRote"></param>
        /// <returns></returns>
        public Task <IEnumerable <SystemMenuButton> > GetMenuButtonByMvcRote(MvcRote mvcRote)
        {
            var sql = new StringBuilder();

            sql.Append(
                "SELECT * FROM System_MenuButton func " +
                "WHERE func.MenuId IN (SELECT MenuId FROM System_Menu WHERE Area=@area AND Controller=@controller AND Action=@action) ORDER BY func.OrderNo");
            return(SqlMapperUtil.SqlWithParams <SystemMenuButton>(sql.ToString(),
                                                                  new
            {
                area = mvcRote.Area,
                controller = mvcRote.Controller,
                action = mvcRote.Action
            }));
        }
Example #8
0
        /// <summary>
        ///     获取登录人员对应菜单下的功能项
        /// </summary>
        /// <param name="mvcRote">路由信息</param>
        /// <param name="userId">用户Id</param>
        /// <returns></returns>
        public async Task <IEnumerable <SystemMenuButton> > GetFunctionByMenuIdAndUserId(MvcRote mvcRote,
                                                                                         Guid userId)
        {
            //判断当前人员是否为超级管理员若是超级管理员则具有最大权限
            IList <SystemMenuButton> functions = new List <SystemMenuButton>();
            //判断该用户是否为超级管理员:若是超级管理员则显示所有菜单
            var userInfo = await _userInfoRepository.GetByIdAsync(userId);

            if (userInfo != null)
            {
                //如果是超级管理员
                if (userInfo.IsAdmin)
                {
                    return((await _menuButtonRepository.GetMenuButtonByMvcRote(mvcRote)).ToList());;
                }
                functions = (await _menuButtonRepository.GetMenuButtonByMenuIdAndUserId(mvcRote, userId)).ToList();
            }
            return(functions);
        }
Example #9
0
 public async Task <JsonResult> GetFunctionByMenuIdAndUserId(MvcRote mvcRote)
 {
     return(Json(await _permissionLogic.GetFunctionByMenuIdAndUserId(mvcRote, CurrentUser.UserId)));
 }
Example #10
0
 /// <summary>
 ///     获取登录人员对应菜单下的功能项
 /// </summary>
 /// <param name="mvcRote">路由信息</param>
 /// <param name="userId">用户Id</param>
 /// <returns></returns>
 public async Task <IEnumerable <SystemMenuButton> > GetMenuButtonByMenuIdAndUserId(MvcRote mvcRote,
                                                                                    Guid userId)
 {
     return((await _functionRepository.GetMenuButtonByMenuIdAndUserId(mvcRote, userId)).ToList());
 }
Example #11
0
        /// <summary>
        /// 保存功能项信息
        /// </summary>
        /// <param name="rotes"></param>
        /// <returns></returns>
        public async Task <OperateStatus> SaveFunction(IList <MvcRote> rotes)
        {
            OperateStatus          operateStatus   = new OperateStatus();
            IList <SystemFunction> insertFunctions = new List <SystemFunction>();
            IList <SystemFunction> deleteFunctions = new List <SystemFunction>();
            IList <SystemFunction> updateFunctions = new List <SystemFunction>();

            if (rotes.Any())
            {
                try
                {
                    //获取该系统的功能项信息
                    IList <SystemFunction> functions = (await _functionRepository.GetSystemFunctionsByAppCode(new IdInput <string>(rotes[0].AppCode))).ToList();
                    //新增功能项信息
                    foreach (var rote in rotes)
                    {
                        //判断该功能项是否已存在
                        SystemFunction function = functions.Where(w =>
                                                                  w.IsPage == rote.IsPage && w.Area == rote.Area && w.Controller == rote.Controller &&
                                                                  w.Action == rote.Action && w.AppCode == rote.AppCode).FirstOrDefault();

                        //若存在则不进行操作
                        if (function == null)
                        {
                            SystemFunction insertFunction = rote.MapTo <SystemFunction>();
                            insertFunction.FunctionId = CombUtil.NewComb();
                            insertFunctions.Add(insertFunction);
                        }
                        else
                        {
                            //如果描述不一样则进行修改
                            if (function.Description != rote.Description ||
                                function.ByDeveloperCode != rote.ByDeveloperCode ||
                                function.ByDeveloperTime != rote.ByDeveloperTime)
                            {
                                function.ByDeveloperCode = rote.ByDeveloperCode;
                                function.ByDeveloperTime = rote.ByDeveloperTime;
                                function.Description     = rote.Description;
                                updateFunctions.Add(function);
                            }
                        }
                    }
                    //需要删除的功能项信息
                    foreach (var function in functions)
                    {
                        //判断该功能项是否已存在
                        MvcRote rote = rotes.Where(w =>
                                                   w.IsPage == function.IsPage && w.Area == function.Area && w.Controller == function.Controller &&
                                                   w.Action == function.Action && w.AppCode == function.AppCode).FirstOrDefault();
                        //若存在则不进行操作
                        if (rote == null)
                        {
                            deleteFunctions.Add(function);
                        }
                    }
                    //删除
                    if (deleteFunctions.Any())
                    {
                        //需要进行删除的字符串
                        foreach (var delete in deleteFunctions)
                        {
                            //删除关联项信息
                            await _menuButtonFunctionRepository.DeleteMenuButtonFunction(new SystemMenuButtonFunction()
                            {
                                FunctionId = delete.FunctionId
                            });

                            //删除功能项信息
                            if ((await DeleteAsync(delete)).ResultSign == ResultSign.Successful)
                            {
                                operateStatus.ResultSign = ResultSign.Successful;
                            }
                        }
                    }
                    //更新
                    if (updateFunctions.Any())
                    {
                        foreach (var update in updateFunctions)
                        {
                            if ((await UpdateAsync(update)).ResultSign == ResultSign.Successful)
                            {
                                operateStatus.ResultSign = ResultSign.Successful;
                            }
                        }
                    }

                    //新增
                    if (insertFunctions.Any() && await _functionRepository.BulkInsertAsync(insertFunctions) > 0)
                    {
                        operateStatus.ResultSign = ResultSign.Successful;
                    }

                    if (operateStatus.ResultSign == ResultSign.Successful)
                    {
                        operateStatus.Message = Chs.Successful;
                    }
                }
                catch (Exception ex)
                {
                    operateStatus.ResultSign = ResultSign.Error;
                    operateStatus.Message    = ex.Message;
                }
            }
            else
            {
                operateStatus.ResultSign = ResultSign.Successful;
                operateStatus.Message    = Chs.Successful;
            }
            return(operateStatus);
        }