/// <summary>
        /// 根据用户ID和菜单编码查询用户所拥有的功能信息列表
        /// </summary>
        /// <param name="userId">用户ID</param>
        /// <param name="menuCode">菜单编码</param>
        /// <param name="connectionId">连接ID</param>
        /// <param name="comData">通用数据</param>
        /// <returns>返回信息</returns>
        public virtual ReturnInfo <IList <FunctionInfo> > QueryUserOwnFunctionsByMenuCode([DisplayName2("用户ID"), Id] int userId, [DisplayName2("菜单编码"), Required] string menuCode, CommonUseData comData = null, string connectionId = null)
        {
            if ("Role".Equals(Config["User:PermissionBenchmark"]))
            {
                return(ExecReturnFuncAndConnectionId <IList <FunctionInfo> >((reInfo, connId) =>
                {
                    // 查找该用户所属角色
                    ReturnInfo <IList <RoleInfo> > reRoleInfo = UserRoleService.OwnRolesByUserId(userId, connectionId: connId, comData: comData);
                    if (reRoleInfo.Failure())
                    {
                        reInfo.FromBasic(reRoleInfo);
                        return null;
                    }
                    if (reRoleInfo.Data.IsNullOrCount0())
                    {
                        return null;
                    }
                    int[] roleIds = new int[reRoleInfo.Data.Count];
                    for (var i = 0; i < roleIds.Length; i++)
                    {
                        roleIds[i] = reRoleInfo.Data[i].Id;
                    }

                    return RoleMenuFunctionPersistence.SelectFunctionsByMenuCodeAndRoleIds(menuCode, roleIds, connId);
                }, null, connectionId, AccessMode.SLAVE));
            }
            else
            {
                return(ExecReturnFunc <IList <FunctionInfo> >((reInfo) =>
                {
                    return UserMenuFunctionPersistence.SelectFunctionsByMenuCodeAndUserId(menuCode, userId, connectionId);
                }));
            }
        }
        /// <summary>
        /// 根据用户ID、菜单编码和功能编码集合判断用户是否有权限
        /// </summary>
        /// <param name="userId">用户ID</param>
        /// <param name="menuCode">菜单编码</param>
        /// <param name="functionCodes">功能编码集合</param>
        /// <param name="connectionId">连接ID</param>
        /// <param name="comData">通用数据</param>
        /// <returns>返回信息</returns>
        public virtual ReturnInfo <bool> IsPermission([DisplayName2("用户ID"), Id] int userId, [DisplayName2("菜单编码"), Required] string menuCode,
                                                      [DisplayName2("功能编码集合"), ArrayNotEmpty] string[] functionCodes, CommonUseData comData = null, string connectionId = null)
        {
            if ("Role".Equals(Config["User:PermissionBenchmark"]))
            {
                return(ExecReturnFuncAndConnectionId <bool>((reInfo, connId) =>
                {
                    // 查找该用户所属角色
                    ReturnInfo <IList <RoleInfo> > reRoleInfo = UserRoleService.OwnRolesByUserId(userId, comData, connId);
                    if (reRoleInfo.Failure())
                    {
                        reInfo.FromBasic(reRoleInfo);
                        return false;
                    }
                    if (reRoleInfo.Data.IsNullOrCount0())
                    {
                        return false;
                    }
                    int[] roleIds = new int[reRoleInfo.Data.Count];
                    for (var i = 0; i < roleIds.Length; i++)
                    {
                        roleIds[i] = reRoleInfo.Data[i].Id;
                    }

                    if (RoleMenuFunctionPersistence.CountByMenuCodeAndFunctionCodesAndRoleIds(menuCode, functionCodes, roleIds, connId) > 0)
                    {
                        return true;
                    }
                    else
                    {
                        reInfo.SetCodeMsg(CommonCodeDefine.NOT_PERMISSION, "Sorry,您没有访问此功能权限!");
                        return false;
                    }
                }, null, connectionId, AccessMode.SLAVE));
            }
            else
            {
                return(ExecReturnFunc <bool>((reInfo) =>
                {
                    if (UserMenuFunctionPersistence.CountByMenuCodeAndFunctionCodesAndUserId(menuCode, functionCodes, userId, connectionId) > 0)
                    {
                        return true;
                    }
                    else
                    {
                        reInfo.SetCodeMsg(CommonCodeDefine.NOT_PERMISSION, "Sorry,您没有访问此功能权限!");
                        return false;
                    }
                }));
            }
        }
        /// <summary>
        /// 根据用户ID获取能访问的菜单列表
        /// </summary>
        /// <param name="userId">用户ID</param>
        /// <param name="connectionId">连接ID</param>
        /// <param name="comData">通用数据</param>
        /// <returns>返回信息</returns>
        public virtual ReturnInfo <UserMenuInfo> CanAccessMenus([DisplayName2("用户ID"), Id] int userId, CommonUseData comData = null, string connectionId = null)
        {
            return(ExecReturnFuncAndConnectionId <UserMenuInfo>((reInfo, connId) =>
            {
                ReturnInfo <UserInfo> protoReturnInfo = Find(userId, connectionId: connId, comData: comData);
                if (protoReturnInfo.Failure())
                {
                    reInfo.FromBasic(protoReturnInfo);
                    return null;
                }
                if (protoReturnInfo.Data == null)
                {
                    reInfo.SetFailureMsg("找不到该用户");
                    return null;
                }
                protoReturnInfo.Data.Password = null;

                // 查找该用户所属角色
                ReturnInfo <IList <RoleInfo> > reRoleInfo = UserRoleService.OwnRolesByUserId(userId, connectionId: connId, comData: comData);
                if (reRoleInfo.Failure())
                {
                    reInfo.FromBasic(reRoleInfo);
                    return null;
                }
                protoReturnInfo.Data.OwnRoles = reRoleInfo.Data;

                var result = AutoMapperUtil.Mapper.Map <UserInfo, UserMenuInfo>(protoReturnInfo.Data);

                // 查找能拥有的权限菜单
                IList <MenuInfo> menus = null;
                if ("Role".Equals(Config["User:PermissionBenchmark"]))
                {
                    if (!reRoleInfo.Data.IsNullOrCount0())
                    {
                        int[] roleIds = new int[reRoleInfo.Data.Count];
                        for (var i = 0; i < roleIds.Length; i++)
                        {
                            roleIds[i] = reRoleInfo.Data[i].Id;
                        }
                        menus = MenuPersistence.SelectByRoleIds(roleIds, connId);
                    }
                }
                else
                {
                    menus = MenuPersistence.SelectByUserId(userId, connId);
                }

                if (menus.IsNullOrCount0())
                {
                    return result;
                }

                // 如果没有查询权限则需要移除
                IList <MenuInfo> tempMenus = new List <MenuInfo>();
                foreach (MenuInfo m in menus)
                {
                    if (m.Functions.IsNullOrCount0())
                    {
                        continue;
                    }

                    foreach (FunctionInfo funInfo in m.Functions)
                    {
                        if (FunCodeDefine.QUERY_CODE.Equals(funInfo.Code))
                        {
                            tempMenus.Add(m);
                            break;
                        }
                    }
                }

                result.Menus = tempMenus.ToOrigAndSort();

                return result;
            }, connectionId: connectionId, accessMode: AccessMode.SLAVE));
        }