/// <summary> /// 根据关联的系统登录终结点查询指定名称的关联验证终结点 /// </summary> /// <param name="systemLoginEndpointId"></param> /// <param name="authorizationName"></param> /// <returns></returns> public async Task <AuthorizationEndpoint> QueryBySystemLoginEndpointRelation(Guid systemLoginEndpointId, string authorizationName) { AuthorizationEndpoint result = null; await DBTransactionHelper.SqlTransactionWorkAsync(DBTypes.SqlServer, false, false, _dbConnectionFactory.CreateReadForSystemToken(), async (conn, transaction) => { SqlTransaction sqlTran = null; if (transaction != null) { sqlTran = (SqlTransaction)transaction; } await using (SqlCommand command = new SqlCommand() { Connection = (SqlConnection)conn, CommandType = CommandType.Text, Transaction = sqlTran, }) { SqlParameter parameter; command.CommandText = string.Format(@" SELECT {0} FROM [DBO].[AUTHORIZATIONENDPOINT] A JOIN DBO.SYSTEMLOGINENDPOINTAUTHORIZATIONENDPOINTRELATION R ON(A.ID = R.AUTHORIZATIONENDPOINTID AND R.SYSTEMLOGINENDPOINTID = @systemLoginEndpointId AND A.Name = @name );", StoreHelper.GetAuthorizationEndpointStoreSelectFields("A")); parameter = new SqlParameter("@systemLoginEndpointId", SqlDbType.UniqueIdentifier) { Value = systemLoginEndpointId }; command.Parameters.Add(parameter); parameter = new SqlParameter("@name", SqlDbType.NVarChar, 500) { Value = authorizationName }; command.Parameters.Add(parameter); await command.PrepareAsync(); SqlDataReader reader = null; await using (reader = await command.ExecuteReaderAsync()) { if (await reader.ReadAsync()) { result = new AuthorizationEndpoint(); StoreHelper.SetAuthorizationEndpointSelectFields(result, reader, "A"); } await reader.CloseAsync(); } } }); return(result); }
/// <summary> /// 根据关联的系统登录终结点分页查询匹配名称的关联验证终结点 /// </summary> /// <param name="systemLoginEndpointId"></param> /// <param name="authorizationName"></param> /// <param name="page"></param> /// <param name="pageSize"></param> /// <returns></returns> public async Task <QueryResult <AuthorizationEndpoint> > QueryBySystemLoginEndpointRelationPage(Guid systemLoginEndpointId, string authorizationName, int page, int pageSize) { QueryResult <AuthorizationEndpoint> result = new QueryResult <AuthorizationEndpoint>(); await DBTransactionHelper.SqlTransactionWorkAsync(DBTypes.SqlServer, true, false, _dbConnectionFactory.CreateReadForSystemToken(), async (conn, transaction) => { SqlTransaction sqlTran = null; if (transaction != null) { sqlTran = (SqlTransaction)transaction; } await using (SqlCommand command = new SqlCommand() { Connection = (SqlConnection)conn, CommandType = CommandType.Text, CommandText = string.Format(@"SET @currentpage = @page; SELECT @count = COUNT(*) FROM [DBO].[AUTHORIZATIONENDPOINT] A JOIN DBO.SYSTEMLOGINENDPOINTAUTHORIZATIONENDPOINTRELATION R ON(A.ID = R.AUTHORIZATIONENDPOINTID AND R.SYSTEMLOGINENDPOINTID = @systemLoginEndpointId AND A.Name like @name) IF @pagesize * @page >= @count BEGIN SET @currentpage = @count / @pagesize; IF @count % @pagesize <> 0 BEGIN SET @currentpage = @currentpage + 1; END; IF @currentpage = 0 SET @currentpage = 1; END; ELSE IF @page < 1 BEGIN SET @currentpage = 1; END; SELECT {0} FROM [DBO].[AUTHORIZATIONENDPOINT] A JOIN DBO.SYSTEMLOGINENDPOINTAUTHORIZATIONENDPOINTRELATION R ON(A.ID = R.AUTHORIZATIONENDPOINTID AND R.SYSTEMLOGINENDPOINTID = @systemLoginEndpointId AND A.Name like @name) ORDER BY [Asequence] OFFSET (@pagesize * (@currentpage - 1)) ROWS FETCH NEXT @pagesize ROWS ONLY;", StoreHelper.GetAuthorizationEndpointStoreSelectFields("A")), Transaction = sqlTran }) { var parameter = new SqlParameter("@page", SqlDbType.Int) { Value = page }; command.Parameters.Add(parameter); parameter = new SqlParameter("@pagesize", SqlDbType.Int) { Value = pageSize }; command.Parameters.Add(parameter); parameter = new SqlParameter("@count", SqlDbType.Int) { Direction = ParameterDirection.Output }; command.Parameters.Add(parameter); parameter = new SqlParameter("@currentpage", SqlDbType.Int) { Direction = ParameterDirection.Output }; command.Parameters.Add(parameter); parameter = new SqlParameter("@systemLoginEndpointId", SqlDbType.UniqueIdentifier) { Value = systemLoginEndpointId }; command.Parameters.Add(parameter); parameter = new SqlParameter("@name", SqlDbType.NVarChar, 500) { Value = $"{authorizationName.ToSqlLike()}%" }; command.Parameters.Add(parameter); await command.PrepareAsync(); SqlDataReader reader = null; await using (reader = await command.ExecuteReaderAsync()) { while (await reader.ReadAsync()) { var authorizationEndpoint = new AuthorizationEndpoint(); StoreHelper.SetAuthorizationEndpointSelectFields(authorizationEndpoint, reader, "A"); result.Results.Add(authorizationEndpoint); } await reader.CloseAsync(); result.TotalCount = (int)command.Parameters["@count"].Value; result.CurrentPage = (int)command.Parameters["@currentpage"].Value; } }; }); return(result); }
/// <summary> /// 通过Name进行分页查询 /// </summary> /// <param name="authorizationName"></param> /// <param name="page"></param> /// <param name="pageSize"></param> /// <returns></returns> public async Task <QueryResult <AuthorizationEndpoint> > QueryByPage(string authorizationName, int page, int pageSize) { QueryResult <AuthorizationEndpoint> result = new QueryResult <AuthorizationEndpoint>(); await DBTransactionHelper.SqlTransactionWorkAsync(DBTypes.SqlServer, true, false, _dbConnectionFactory.CreateReadForSystemToken(), async (conn, transaction) => { SqlTransaction sqlTran = null; if (transaction != null) { sqlTran = (SqlTransaction)transaction; } await using (SqlCommand command = new SqlCommand() { Connection = (SqlConnection)conn, CommandType = CommandType.Text, CommandText = string.Format(@"SET @currentpage = @page; SELECT @count = COUNT(*) FROM [dbo].[AuthorizationEndpoint] WHERE [name] LIKE @name IF @pagesize * @page >= @count BEGIN SET @currentpage = @count / @pagesize; IF @count % @pagesize <> 0 BEGIN SET @currentpage = @currentpage + 1; END; IF @currentpage = 0 SET @currentpage = 1; END; ELSE IF @page < 1 BEGIN SET @currentpage = 1; END; SELECT {0} FROM [dbo].[AuthorizationEndpoint] WHERE [name] LIKE @name ORDER BY sequence OFFSET (@pagesize * (@currentpage - 1)) ROWS FETCH NEXT @pagesize ROWS ONLY;", StoreHelper.GetAuthorizationEndpointStoreSelectFields(string.Empty)), Transaction = sqlTran }) { var parameter = new SqlParameter("@page", SqlDbType.Int) { Value = page }; command.Parameters.Add(parameter); parameter = new SqlParameter("@pagesize", SqlDbType.Int) { Value = pageSize }; command.Parameters.Add(parameter); parameter = new SqlParameter("@count", SqlDbType.Int) { Direction = ParameterDirection.Output }; command.Parameters.Add(parameter); parameter = new SqlParameter("@currentpage", SqlDbType.Int) { Direction = ParameterDirection.Output }; command.Parameters.Add(parameter); parameter = new SqlParameter("@name", SqlDbType.NVarChar, 500) { Value = $"{authorizationName.ToSqlLike()}%" }; command.Parameters.Add(parameter); await command.PrepareAsync(); SqlDataReader reader = null; await using (reader = await command.ExecuteReaderAsync()) { while (await reader.ReadAsync()) { var authorizationEndpoint = new AuthorizationEndpoint(); StoreHelper.SetAuthorizationEndpointSelectFields(authorizationEndpoint, reader, string.Empty); result.Results.Add(authorizationEndpoint); } await reader.CloseAsync(); result.TotalCount = (int)command.Parameters["@count"].Value; result.CurrentPage = (int)command.Parameters["@currentpage"].Value; } }; }); return(result); }
/// <summary> /// 通过Name进行查询 /// </summary> /// <param name="name"></param> /// <returns></returns> public async Task <AuthorizationEndpoint> QueryByName(string name) { AuthorizationEndpoint result = null; await DBTransactionHelper.SqlTransactionWorkAsync(DBTypes.SqlServer, false, false, _dbConnectionFactory.CreateReadForSystemToken(), async (conn, transaction) => { SqlTransaction sqlTran = null; if (transaction != null) { sqlTran = (SqlTransaction)transaction; } await using (SqlCommand command = new SqlCommand() { Connection = (SqlConnection)conn, CommandType = CommandType.Text, Transaction = sqlTran, }) { SqlParameter parameter; command.CommandText = string.Format(@"SELECT {0} FROM [dbo].[AuthorizationEndpoint] WHERE name=@name;", StoreHelper.GetAuthorizationEndpointStoreSelectFields(string.Empty)); parameter = new SqlParameter("@name", SqlDbType.NVarChar, 500) { Value = name }; command.Parameters.Add(parameter); await command.PrepareAsync(); SqlDataReader reader = null; await using (reader = await command.ExecuteReaderAsync()) { if (await reader.ReadAsync()) { result = new AuthorizationEndpoint(); StoreHelper.SetAuthorizationEndpointSelectFields(result, reader, string.Empty); } await reader.CloseAsync(); } } }); return(result); }