/// <summary> /// 根据ID查询 /// </summary> /// <param name="id"></param> /// <returns></returns> public async Task <ClientSMessageTypeListenerEndpoint> QueryById(Guid id) { ClientSMessageTypeListenerEndpoint result = null; await DBTransactionHelper.SqlTransactionWorkAsync(DBTypes.SqlServer, true, false, _messageQueueConnectionFactory.CreateReadForMessageQueueMain(), 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(@"SELECT {0} FROM [dbo].[ClientSMessageTypeListenerEndpoint] WHERE id=@id;", StoreHelper.GetClientSMessageTypeListenerEndpointSelectFields(string.Empty)), Transaction = sqlTran }) { var parameter = new SqlParameter("@id", SqlDbType.UniqueIdentifier) { Value = id }; command.Parameters.Add(parameter); command.Prepare(); SqlDataReader reader = null; await using (reader = await command.ExecuteReaderAsync()) { if (await reader.ReadAsync()) { result = new ClientSMessageTypeListenerEndpoint(); StoreHelper.SetClientSMessageTypeListenerEndpointSelectFields(result, reader, string.Empty); } await reader.CloseAsync(); } } }); return(result); }
public async Task <SQueueProcessGroup> QueryById(Guid id) { SQueueProcessGroup group = null; await DBTransactionHelper.SqlTransactionWorkAsync(DBTypes.SqlServer, true, false, _messageQueueConnectionFactory.CreateReadForMessageQueueMain(), async (conn, transaction) => { SqlTransaction sqlTran = null; if (transaction != null) { sqlTran = (SqlTransaction)transaction; } await using (SqlCommand commond = new SqlCommand() { Connection = (SqlConnection)conn, CommandType = CommandType.Text, Transaction = sqlTran, CommandText = string.Format(@"select {0} from SQueueProcessGroup where [id]=@id", StoreHelper.GetSQueueProcessGroupSelectFields(string.Empty)) }) { var parameter = new SqlParameter("@id", SqlDbType.UniqueIdentifier) { Value = id }; commond.Parameters.Add(parameter); await commond.PrepareAsync(); SqlDataReader reader = null; await using (reader = await commond.ExecuteReaderAsync()) { if (await reader.ReadAsync()) { group = new SQueueProcessGroup(); StoreHelper.SetSQueueProcessGroupSelectFields(group, reader, string.Empty); } await reader.CloseAsync(); } } }); return(group); }
public async Task <QueryResult <SMessageExecuteType> > Query(string name, int page, int pageSize) { QueryResult <SMessageExecuteType> result = new QueryResult <SMessageExecuteType>(); await DBTransactionHelper.SqlTransactionWorkAsync(DBTypes.SqlServer, true, false, _messageQueueConnectionFactory.CreateReadForMessageQueueMain(), async (conn, transaction) => { SqlTransaction sqlTran = null; if (transaction != null) { sqlTran = (SqlTransaction)transaction; } await using (SqlCommand commond = new SqlCommand() { Connection = (SqlConnection)conn, CommandType = CommandType.Text, Transaction = sqlTran, CommandText = string.Format(@"set @currentpage=@page select @count= count(*) from SMessageExecuteType 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 SMessageExecuteType where [name] like @name order by [sequence] desc offset (@pagesize * (@currentpage - 1)) rows fetch next @pagesize rows only;" , StoreHelper.GetSMessageExecuteTypeSelectFields(string.Empty)) }) { var parameter = new SqlParameter("@page", SqlDbType.Int) { Value = page }; commond.Parameters.Add(parameter); parameter = new SqlParameter("@pagesize", SqlDbType.Int) { Value = pageSize }; parameter = new SqlParameter("@name", SqlDbType.VarChar, 200) { Value = string.Format("{0}%", name.ToSqlLike()) }; commond.Parameters.Add(parameter); parameter = new SqlParameter("@count", SqlDbType.Int) { Direction = ParameterDirection.Output }; commond.Parameters.Add(parameter); parameter = new SqlParameter("@currentpage", SqlDbType.Int) { Direction = ParameterDirection.Output }; commond.Parameters.Add(parameter); await commond.PrepareAsync(); SqlDataReader reader = null; await using (reader = await commond.ExecuteReaderAsync()) { while (await reader.ReadAsync()) { var type = new SMessageExecuteType(); StoreHelper.SetSMessageExecuteTypeSelectFields(type, reader, string.Empty); result.Results.Add(type); } await reader.CloseAsync(); result.TotalCount = (int)commond.Parameters["@count"].Value; result.CurrentPage = (int)commond.Parameters["@currentpage"].Value; } } }); return(result); }