[성현모] CPMeta 최근데이터 조회 기능 추가
This commit is contained in:
@ -9,7 +9,9 @@
|
|||||||
{
|
{
|
||||||
"Id": 1,
|
"Id": 1,
|
||||||
"ApiName": "CPMetaWbms",
|
"ApiName": "CPMetaWbms",
|
||||||
"Host": "10.188.172.194:9000"
|
//"Host": "10.188.172.194:9000"
|
||||||
|
"Host": "127.0.0.1:9000",
|
||||||
|
"LastCount": 30
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"Id": 2,
|
"Id": 2,
|
||||||
|
|||||||
@ -79,5 +79,18 @@ namespace WebApi.Project.UniqueKeyApi.Controllers
|
|||||||
|
|
||||||
return Results.Ok(response);
|
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 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 class Response_GetWbms
|
||||||
{
|
{
|
||||||
public List<tWbms> Wbms { get; set; }
|
public List<tWbms> Wbms { get; set; }
|
||||||
|
|||||||
@ -309,6 +309,56 @@ namespace WebApi.Project.UniqueKeyApi.Services
|
|||||||
return response;
|
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)
|
private CPMetaContext? GetCPMetaDBContext(DbContextProvider provider, int dbID)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -18,7 +18,7 @@
|
|||||||
@* <RadzenPanelMenuItem Text="ProxyKms" Icon="assignment" Path="/ProxyKms"/> *@
|
@* <RadzenPanelMenuItem Text="ProxyKms" Icon="assignment" Path="/ProxyKms"/> *@
|
||||||
</RadzenPanelMenu>
|
</RadzenPanelMenu>
|
||||||
</RadzenSidebar>
|
</RadzenSidebar>
|
||||||
<RadzenBody Style="margin:0; padding:1rem; overflow:hidden; font-size: 2rem;">
|
<RadzenBody Style="margin:0; padding:1rem; overflow:auto; font-size: 2rem;">
|
||||||
@Body
|
@Body
|
||||||
</RadzenBody>
|
</RadzenBody>
|
||||||
</RadzenLayout>
|
</RadzenLayout>
|
||||||
|
|||||||
@ -46,7 +46,11 @@
|
|||||||
</div> *@
|
</div> *@
|
||||||
|
|
||||||
<OperationGrid TDataModel="tWbms" DataList="@response.Wbms">
|
<OperationGrid TDataModel="tWbms" DataList="@response.Wbms">
|
||||||
|
</OperationGrid>
|
||||||
|
|
||||||
|
<br />
|
||||||
|
<RadzenLabel Style="width: 200px; color:darkorange" Text="Latest Data"></RadzenLabel>
|
||||||
|
<OperationGrid TDataModel="tWbms" DataList="@latest.Wbms">
|
||||||
</OperationGrid>
|
</OperationGrid>
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
@ -56,10 +60,18 @@
|
|||||||
private string SearchProductMacAddress = string.Empty;
|
private string SearchProductMacAddress = string.Empty;
|
||||||
|
|
||||||
Response_GetWbmsMeta response = new Response_GetWbmsMeta();
|
Response_GetWbmsMeta response = new Response_GetWbmsMeta();
|
||||||
|
Response_GetWbmsMeta latest = new Response_GetWbmsMeta();
|
||||||
|
|
||||||
protected override async Task OnInitializedAsync()
|
protected override async Task OnInitializedAsync()
|
||||||
{
|
{
|
||||||
ServerAddress = _cpMetaService.ApiHost;
|
ServerAddress = _cpMetaService.ApiHost;
|
||||||
|
|
||||||
|
var apiConfig = _configService.GetConfig().Api.Find(x => x.Id == 1);
|
||||||
|
|
||||||
|
if (apiConfig is not null)
|
||||||
|
{
|
||||||
|
latest = await _cpMetaService.GetWbmsLatest(ServerAddress, apiConfig.LastCount);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task SearchByProductID()
|
private async Task SearchByProductID()
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
@typeparam TDataModel
|
@typeparam TDataModel
|
||||||
|
|
||||||
<RadzenDataGrid class="rz-shadow-1" TItem="TDataModel" Data="@DataList" GridLines="DataGridGridLines.Both"
|
<RadzenDataGrid class="rz-shadow-1" TItem="TDataModel" Data="@DataList" GridLines="DataGridGridLines.Both"
|
||||||
AllowFiltering FilterMode="FilterMode.Simple" AllowColumnResize
|
AllowFiltering FilterMode="FilterMode.Simple" AllowPaging Count=10 PageNumbersCount="10" PagerHorizontalAlign="HorizontalAlign.Center"
|
||||||
SelectionMode="DataGridSelectionMode.Single" Density="@Density.Default">
|
SelectionMode="DataGridSelectionMode.Single" Density="@Density.Default">
|
||||||
<Columns>
|
<Columns>
|
||||||
@foreach (var col in typeof(TDataModel).GetProperties())
|
@foreach (var col in typeof(TDataModel).GetProperties())
|
||||||
|
|||||||
@ -34,6 +34,12 @@
|
|||||||
public int ShardID { get; set; } = 1;
|
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_GetWbmsMeta
|
public class Response_GetWbmsMeta
|
||||||
{
|
{
|
||||||
public List<tWbms> Wbms { get; set; } = new List<tWbms>();
|
public List<tWbms> Wbms { get; set; } = new List<tWbms>();
|
||||||
|
|||||||
@ -64,5 +64,19 @@ namespace Web.Operation.Services
|
|||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<Response_GetWbmsMeta> GetWbmsLatest(string host, int count = 20, int shardID = 1)
|
||||||
|
{
|
||||||
|
string requestUrl = $"https://{host}/CPMeta/GetWbmsLatest?";
|
||||||
|
requestUrl += $"Count={count}&";
|
||||||
|
requestUrl += $"ShardID={shardID}";
|
||||||
|
|
||||||
|
Http http = new Http();
|
||||||
|
var res = await http.GetJsonAsync<Response_GetWbmsMeta>($"{requestUrl}");
|
||||||
|
|
||||||
|
LogXnet.WriteLine($"{res.ToJson()}", LogXLabel.HTTP);
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,5 +11,6 @@ namespace WebClient.Library.Model
|
|||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
public string ApiName { get; set; }
|
public string ApiName { get; set; }
|
||||||
public string Host { get; set; }
|
public string Host { get; set; }
|
||||||
|
public int LastCount { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user