diff --git a/Projects/Config/WebClient.Operation.Config.json b/Projects/Config/WebClient.Operation.Config.json index dbe75ad..c234a72 100644 --- a/Projects/Config/WebClient.Operation.Config.json +++ b/Projects/Config/WebClient.Operation.Config.json @@ -9,7 +9,9 @@ { "Id": 1, "ApiName": "CPMetaWbms", - "Host": "10.188.172.194:9000" + //"Host": "10.188.172.194:9000" + "Host": "127.0.0.1:9000", + "LastCount": 30 }, { "Id": 2, diff --git a/Projects/WebApi/WebApi.Project.UniqueKeyApi/Controllers/CPMetaController.cs b/Projects/WebApi/WebApi.Project.UniqueKeyApi/Controllers/CPMetaController.cs index bdfc6d5..1e4de51 100644 --- a/Projects/WebApi/WebApi.Project.UniqueKeyApi/Controllers/CPMetaController.cs +++ b/Projects/WebApi/WebApi.Project.UniqueKeyApi/Controllers/CPMetaController.cs @@ -79,5 +79,18 @@ namespace WebApi.Project.UniqueKeyApi.Controllers return Results.Ok(response); } + + [HttpGet] + public async Task 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); + } } } diff --git a/Projects/WebApi/WebApi.Project.UniqueKeyApi/Models/Packet.cs b/Projects/WebApi/WebApi.Project.UniqueKeyApi/Models/Packet.cs index 9908d2c..ffecf59 100644 --- a/Projects/WebApi/WebApi.Project.UniqueKeyApi/Models/Packet.cs +++ b/Projects/WebApi/WebApi.Project.UniqueKeyApi/Models/Packet.cs @@ -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 Wbms { get; set; } diff --git a/Projects/WebApi/WebApi.Project.UniqueKeyApi/Services/CPMetaService.cs b/Projects/WebApi/WebApi.Project.UniqueKeyApi/Services/CPMetaService.cs index 67f6536..bc669db 100644 --- a/Projects/WebApi/WebApi.Project.UniqueKeyApi/Services/CPMetaService.cs +++ b/Projects/WebApi/WebApi.Project.UniqueKeyApi/Services/CPMetaService.cs @@ -309,6 +309,56 @@ namespace WebApi.Project.UniqueKeyApi.Services return response; } + public async Task GetWbmsLatest(Request_GetWbmsLatest request, string guid = "") + { + Response_GetWbms response = new Response_GetWbms(); + response.Wbms = new List(); + + if (request != null) + { + using (var scope = _scopeFactory.CreateScope()) + { + int shardId = request.ShardID; + if (shardId <= 0) + shardId = 1; + + var provider = scope.ServiceProvider.GetRequiredService(); + 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) { diff --git a/Projects/WebClient/Web.Operation/Components/Layout/MainLayout.razor b/Projects/WebClient/Web.Operation/Components/Layout/MainLayout.razor index 4464138..a87530b 100644 --- a/Projects/WebClient/Web.Operation/Components/Layout/MainLayout.razor +++ b/Projects/WebClient/Web.Operation/Components/Layout/MainLayout.razor @@ -18,7 +18,7 @@ @* *@ - + @Body diff --git a/Projects/WebClient/Web.Operation/Components/Pages/CPMeta.razor b/Projects/WebClient/Web.Operation/Components/Pages/CPMeta.razor index fa995d0..3bdb520 100644 --- a/Projects/WebClient/Web.Operation/Components/Pages/CPMeta.razor +++ b/Projects/WebClient/Web.Operation/Components/Pages/CPMeta.razor @@ -46,7 +46,11 @@ *@ + +
+ + @code { @@ -56,10 +60,18 @@ private string SearchProductMacAddress = string.Empty; Response_GetWbmsMeta response = new Response_GetWbmsMeta(); + Response_GetWbmsMeta latest = new Response_GetWbmsMeta(); protected override async Task OnInitializedAsync() { 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() diff --git a/Projects/WebClient/Web.Operation/Module/OperationGrid.razor b/Projects/WebClient/Web.Operation/Module/OperationGrid.razor index fedacac..f60993d 100644 --- a/Projects/WebClient/Web.Operation/Module/OperationGrid.razor +++ b/Projects/WebClient/Web.Operation/Module/OperationGrid.razor @@ -4,7 +4,7 @@ @typeparam TDataModel @foreach (var col in typeof(TDataModel).GetProperties()) diff --git a/Projects/WebClient/Web.Operation/Packet/CPMetaWbms.cs b/Projects/WebClient/Web.Operation/Packet/CPMetaWbms.cs index 9e0fb8a..5c76348 100644 --- a/Projects/WebClient/Web.Operation/Packet/CPMetaWbms.cs +++ b/Projects/WebClient/Web.Operation/Packet/CPMetaWbms.cs @@ -34,6 +34,12 @@ 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 List Wbms { get; set; } = new List(); diff --git a/Projects/WebClient/Web.Operation/Services/CPMetaService.cs b/Projects/WebClient/Web.Operation/Services/CPMetaService.cs index 7cc3095..8e9c86b 100644 --- a/Projects/WebClient/Web.Operation/Services/CPMetaService.cs +++ b/Projects/WebClient/Web.Operation/Services/CPMetaService.cs @@ -64,5 +64,19 @@ namespace Web.Operation.Services return res; } + + public async Task 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($"{requestUrl}"); + + LogXnet.WriteLine($"{res.ToJson()}", LogXLabel.HTTP); + + return res; + } } } diff --git a/Projects/WebClient/WebClient.Library/Model/API.cs b/Projects/WebClient/WebClient.Library/Model/API.cs index 56dfd82..3a5d169 100644 --- a/Projects/WebClient/WebClient.Library/Model/API.cs +++ b/Projects/WebClient/WebClient.Library/Model/API.cs @@ -11,5 +11,6 @@ namespace WebClient.Library.Model public int Id { get; set; } public string ApiName { get; set; } public string Host { get; set; } + public int LastCount { get; set; } } }