[성현모] CPMeta 최근데이터 조회 기능 추가
This commit is contained in:
@ -309,6 +309,56 @@ namespace WebApi.Project.UniqueKeyApi.Services
|
||||
return response;
|
||||
}
|
||||
|
||||
public async Task<Response_GetWbms> GetWbmsLatest(Request_GetWbmsLatest request, string guid = "")
|
||||
{
|
||||
Response_GetWbms response = new Response_GetWbms();
|
||||
response.Wbms = new List<tWbms>();
|
||||
|
||||
if (request != null)
|
||||
{
|
||||
using (var scope = _scopeFactory.CreateScope())
|
||||
{
|
||||
int shardId = request.ShardID;
|
||||
if (shardId <= 0)
|
||||
shardId = 1;
|
||||
|
||||
var provider = scope.ServiceProvider.GetRequiredService<DbContextProvider>();
|
||||
using (var context = GetCPMetaDBContext(provider, shardId))
|
||||
{
|
||||
if (context is not null)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var transaction = await context.CreateTransactionAsync(IsolationLevel.ReadUncommitted))
|
||||
{
|
||||
response.Wbms = await context.tWbms.AsNoTracking().OrderByDescending(x => x.cDateTime).Take(request.Count).ToListAsync();
|
||||
|
||||
await context.CloseTransactionAsync(transaction);
|
||||
response.Result = WebApiResult.Success.ToString();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
response.Wbms = null;
|
||||
response.Result = WebApiResult.Failed.ToString();
|
||||
|
||||
LogXnet.WriteLine($"GetWbmsMeta By Latest({request.Count}) Transaction Error::{guid}", LogXLabel.Error);
|
||||
LogXnet.WriteLine(e);
|
||||
}
|
||||
}
|
||||
else //invalid shard id
|
||||
{
|
||||
LogXnet.WriteLine($"ShardID Error::{guid}", LogXLabel.Error);
|
||||
response.Result = WebApiResult.Failed.ToString();
|
||||
response.Message = "Invalid shard id";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
private CPMetaContext? GetCPMetaDBContext(DbContextProvider provider, int dbID)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user