[성현모] CPMeta 최근데이터 조회 기능 추가
This commit is contained in:
@ -79,5 +79,18 @@ namespace WebApi.Project.UniqueKeyApi.Controllers
|
||||
|
||||
return Results.Ok(response);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IResult> GetWbmsLatest([FromQuery] int count = 20, int? ShardID = 1)
|
||||
{
|
||||
Guid guid = Guid.NewGuid();
|
||||
LogXnet.WriteLine($"[Request][{GetRequestMethod()}:{GetMethodName()}][Client IP:{GetClientIP()}][RequestUrl:{GetRequestUrl()}]::({guid}){Environment.NewLine} Count:{count}", LogXLabel.CONTROLLER);
|
||||
|
||||
Response_GetWbms response = await _cpMetaService.GetWbmsLatest(new Request_GetWbmsLatest() { Count = count, ShardID = (int)ShardID }, guid.ToString());
|
||||
|
||||
LogXnet.WriteLine($"[Response]::({guid}){Environment.NewLine} {response.ToJson()}", LogXLabel.CONTROLLER);
|
||||
|
||||
return Results.Ok(response);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -46,6 +46,12 @@ namespace WebApi.Project.UniqueKeyApi.Models
|
||||
public int ShardID { get; set; } = 1;
|
||||
}
|
||||
|
||||
public class Request_GetWbmsLatest
|
||||
{
|
||||
public int Count { get; set; } = 20;
|
||||
public int ShardID { get; set; } = 1;
|
||||
}
|
||||
|
||||
public class Response_GetWbms
|
||||
{
|
||||
public List<tWbms> Wbms { get; set; }
|
||||
|
||||
@ -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