diff --git a/Projects/Config/WebClient.Operation.Config.json b/Projects/Config/WebClient.Operation.Config.json index 1c5c75f..00f01e5 100644 --- a/Projects/Config/WebClient.Operation.Config.json +++ b/Projects/Config/WebClient.Operation.Config.json @@ -3,7 +3,7 @@ "Server": { "Address": "https://*", "Port": 9100, - "IIS": false + "IIS": true }, "API": [ { diff --git a/Projects/WebApi/WebApi.Project.UniqueKeyApi/Controllers/CPMetaController.cs b/Projects/WebApi/WebApi.Project.UniqueKeyApi/Controllers/CPMetaController.cs index 7ca580b..bdfc6d5 100644 --- a/Projects/WebApi/WebApi.Project.UniqueKeyApi/Controllers/CPMetaController.cs +++ b/Projects/WebApi/WebApi.Project.UniqueKeyApi/Controllers/CPMetaController.cs @@ -41,6 +41,19 @@ namespace WebApi.Project.UniqueKeyApi.Controllers return Results.Ok(response); } + [HttpGet] + public async Task GetWbmsMeta([FromQuery] DateOnly? startDate, DateOnly? endDate, int? ShardID = 1) + { + Guid guid = Guid.NewGuid(); + LogXnet.WriteLine($"[Request][{GetRequestMethod()}:{GetMethodName()}][Client IP:{GetClientIP()}][RequestUrl:{GetRequestUrl()}]::({guid}){Environment.NewLine} key:{startDate}~{endDate}", LogXLabel.CONTROLLER); + + Response_GetWbms response = await _cpMetaService.GetWbmsMeta(new Request_GetWbmsMeta() { StartDateTime = startDate, EndDateTime = endDate, ShardID = (int)ShardID }, guid.ToString()); + + LogXnet.WriteLine($"[Response]::({guid}){Environment.NewLine} {response.ToJson()}", LogXLabel.CONTROLLER); + + return Results.Ok(response); + } + [HttpGet] public async Task GetWbmsMetaByProductID([FromQuery] string ProductID, int? ShardID = 1) { diff --git a/Projects/WebApi/WebApi.Project.UniqueKeyApi/Models/Packet.cs b/Projects/WebApi/WebApi.Project.UniqueKeyApi/Models/Packet.cs index fbbebee..9908d2c 100644 --- a/Projects/WebApi/WebApi.Project.UniqueKeyApi/Models/Packet.cs +++ b/Projects/WebApi/WebApi.Project.UniqueKeyApi/Models/Packet.cs @@ -29,6 +29,12 @@ namespace WebApi.Project.UniqueKeyApi.Models } //Wbms Meta Select + public class Request_GetWbmsMeta + { + public DateOnly? StartDateTime { get; set; } + public DateOnly? EndDateTime { get; set; } + public int ShardID { get; set; } = 1; + } public class Request_GetWbmsMetaByProductID { public string ProductID { get; set; } = string.Empty; diff --git a/Projects/WebApi/WebApi.Project.UniqueKeyApi/Services/CPMetaService.cs b/Projects/WebApi/WebApi.Project.UniqueKeyApi/Services/CPMetaService.cs index 7ba3742..67f6536 100644 --- a/Projects/WebApi/WebApi.Project.UniqueKeyApi/Services/CPMetaService.cs +++ b/Projects/WebApi/WebApi.Project.UniqueKeyApi/Services/CPMetaService.cs @@ -107,6 +107,70 @@ namespace WebApi.Project.UniqueKeyApi.Services return response; } + public async Task GetWbmsMeta(Request_GetWbmsMeta 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)) + { + var data = await context.tWbms.AsNoTracking().Where(x => ((DateOnly)request.StartDateTime) <= DateOnly.FromDateTime(x.cDateTime) && DateOnly.FromDateTime(x.cDateTime) <= ((DateOnly)request.EndDateTime)).ToListAsync(); + await context.CloseTransactionAsync(transaction); + if (data != null) + { + if (response.Wbms is not null) + { + response.Wbms.AddRange(data); + } + + response.Result = WebApiResult.Success.ToString(); + } + else + { + response.Wbms = null; + response.Result = WebApiResult.Failed.ToString(); + response.Message = $"Get CPMeta Failed"; + } + } + } + catch (Exception e) + { + response.Wbms = null; + response.Result = WebApiResult.Failed.ToString(); + response.Message = $"Get CPMeta Failed"; + + LogXnet.WriteLine($"GetWbmsMeta By ProductID 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; + } + public async Task GetWbmsMeta(Request_GetWbmsMetaByProductID request, string guid = "") { Response_GetWbms response = new Response_GetWbms(); diff --git a/Projects/WebClient/Web.Operation/.config/dotnet-tools.json b/Projects/WebClient/Web.Operation/.config/dotnet-tools.json new file mode 100644 index 0000000..d4937e0 --- /dev/null +++ b/Projects/WebClient/Web.Operation/.config/dotnet-tools.json @@ -0,0 +1,13 @@ +{ + "version": 1, + "isRoot": true, + "tools": { + "dotnet-ef": { + "version": "9.0.10", + "commands": [ + "dotnet-ef" + ], + "rollForward": false + } + } +} \ No newline at end of file diff --git a/Projects/WebClient/Web.Operation/Components/App.razor b/Projects/WebClient/Web.Operation/Components/App.razor index 5ae47fc..05de1d0 100644 --- a/Projects/WebClient/Web.Operation/Components/App.razor +++ b/Projects/WebClient/Web.Operation/Components/App.razor @@ -16,7 +16,7 @@ - + diff --git a/Projects/WebClient/Web.Operation/Components/Pages/CPMeta.razor b/Projects/WebClient/Web.Operation/Components/Pages/CPMeta.razor index ab246d3..28dd133 100644 --- a/Projects/WebClient/Web.Operation/Components/Pages/CPMeta.razor +++ b/Projects/WebClient/Web.Operation/Components/Pages/CPMeta.razor @@ -1,7 +1,79 @@ @page "/CpMeta" +@rendermode InteractiveServer + +@using Web.Operation.Module; +@using Web.Operation.Services +@using Packet + +@inject CPMetaService _cpMetaService +@inject PopupService PopupService

CPMeta

-@code { + +
+ + +
+
-} + +
+ + + Search + + + + Search +
+
+
+ +@*
+
+ + +
+
+ + +
+
*@ + + + + + +@code { + private string ServerAddress = "192.168.0.126:9000"; + private string SearchProductID = string.Empty; + private string SearchProductMacAddress = string.Empty; + + Response_GetWbmsMeta response = new Response_GetWbmsMeta(); + + protected override async Task OnInitializedAsync() + { + + } + + private async Task SearchByProductID() + { + PopupService.OpenIndicator(""); + if (string.IsNullOrEmpty(SearchProductID) == false) + response = await _cpMetaService.GetWbmsMetaByProductID(SearchProductID, ServerAddress); + + await Task.Delay(300); + PopupService.CloseIndicator(); + } + + private async Task SearchByMacAddress() + { + PopupService.OpenIndicator(""); + if (string.IsNullOrEmpty(SearchProductMacAddress) == false) + response = await _cpMetaService.GetWbmsMetaByMacAddress(SearchProductMacAddress, ServerAddress); + + await Task.Delay(300); + PopupService.CloseIndicator(); + } +} \ No newline at end of file diff --git a/Projects/WebClient/Web.Operation/Components/Routes.razor b/Projects/WebClient/Web.Operation/Components/Routes.razor index f756e19..f7f43eb 100644 --- a/Projects/WebClient/Web.Operation/Components/Routes.razor +++ b/Projects/WebClient/Web.Operation/Components/Routes.razor @@ -1,4 +1,6 @@ - +@rendermode InteractiveServer + + diff --git a/Projects/WebClient/Web.Operation/Dialog/Loading.razor.css b/Projects/WebClient/Web.Operation/Dialog/Loading.razor.css new file mode 100644 index 0000000..8b45671 --- /dev/null +++ b/Projects/WebClient/Web.Operation/Dialog/Loading.razor.css @@ -0,0 +1,58 @@ +.message { + /* change color here */ + color: #f8b26a; + text-align: center; + font-size: 1.5rem; +} + +.lds-ring { + /* change color here */ + color: #f8b26a; +} + + .lds-ring, + .lds-ring div { + box-sizing: border-box; + } + +.lds-ring { + display: inline-block; + position: relative; + width: 80px; + height: 80px; +} + + .lds-ring div { + box-sizing: border-box; + display: block; + position: absolute; + width: 64px; + height: 64px; + margin: 8px; + border: 8px solid currentColor; + border-radius: 50%; + animation: lds-ring 1.2s cubic-bezier(0.5, 0, 0.5, 1) infinite; + border-color: currentColor transparent transparent transparent; + } + + .lds-ring div:nth-child(1) { + animation-delay: -0.45s; + } + + .lds-ring div:nth-child(2) { + animation-delay: -0.3s; + } + + .lds-ring div:nth-child(3) { + animation-delay: -0.15s; + } + +@keyframes lds-ring { + 0% { + transform: rotate(0deg); + } + + 100% { + transform: rotate(360deg); + } +} diff --git a/Projects/WebClient/Web.Operation/Module/OperationGrid.razor b/Projects/WebClient/Web.Operation/Module/OperationGrid.razor new file mode 100644 index 0000000..110c709 --- /dev/null +++ b/Projects/WebClient/Web.Operation/Module/OperationGrid.razor @@ -0,0 +1,26 @@ +@using Radzen +@using Radzen.Blazor +@using WebClient.Library.Model +@typeparam TDataModel + + + + @foreach (var col in typeof(TDataModel).GetProperties()) + { + + + + } + + + +@code { + [Parameter] + public IEnumerable DataList { get; set; } +} diff --git a/Projects/WebClient/Web.Operation/Packet/CPMetaWbms.cs b/Projects/WebClient/Web.Operation/Packet/CPMetaWbms.cs new file mode 100644 index 0000000..334b38c --- /dev/null +++ b/Projects/WebClient/Web.Operation/Packet/CPMetaWbms.cs @@ -0,0 +1,55 @@ +namespace Web.Operation.Packet +{ + public class Request_SetWbmsMeta + { + //pk + public string ProductID { get; set; } = string.Empty; + //uk + public string MacAddress1 { get; set; } = string.Empty; + public string MacAddress2 { get; set; } = string.Empty; + + //value + public string Type { get; set; } = string.Empty; + public string ProductNo { get; set; } = string.Empty; + public string SpareValue { get; set; } = string.Empty; + + public int ShardID { get; set; } = 1; + } + + public class Response_SetWbmsMeta + { + public string ProductID { get; set; } = string.Empty; + public string Result { get; set; } = string.Empty; + public string Message { get; set; } = string.Empty; + } + + public class Request_GetWbmsMetaByProductID + { + public string ProductID { get; set; } = string.Empty; + public int ShardID { get; set; } = 1; + } + public class Request_GetWbmsMetaByMacAddress + { + public string MacAddress { get; set; } = string.Empty; + public int ShardID { get; set; } = 1; + } + + public class Response_GetWbmsMeta + { + public List Wbms { get; set; } + public string Result { get; set; } = string.Empty; + public string Message { get; set; } = string.Empty; + } + + public class tWbms + { + public string cProductID { get; set; } = null; + + public string cMacAddress1 { get; set; } + public string cMacAddress2 { get; set; } + public string cType { get; set; } + public string cProductNo { get; set; } + public string cSpareValue { get; set; } + public DateTime cDateTime { get; set; } + } +} diff --git a/Projects/WebClient/Web.Operation/Program.cs b/Projects/WebClient/Web.Operation/Program.cs index 8209ee0..6f744d3 100644 --- a/Projects/WebClient/Web.Operation/Program.cs +++ b/Projects/WebClient/Web.Operation/Program.cs @@ -33,6 +33,7 @@ builder.Services.AddSingleton>(); //scoped builder.Services.AddScoped(); +builder.Services.AddScoped(); //db builder.Services.AddSingleton(); // Generic µî·Ï diff --git a/Projects/WebClient/Web.Operation/Services/CPMetaService.cs b/Projects/WebClient/Web.Operation/Services/CPMetaService.cs new file mode 100644 index 0000000..b0bc95c --- /dev/null +++ b/Projects/WebClient/Web.Operation/Services/CPMetaService.cs @@ -0,0 +1,68 @@ +using Newtonsoft.Json; +using System; +using SystemX.Core.Communication; +using SystemX.Core.Services; +using Web.Operation.Packet; +using WebClient.Library.Config; + +namespace Web.Operation.Services +{ + public class CPMetaService + { + private readonly IServiceScopeFactory _scopeFactory; + private readonly ConfigService? _configService; + + private string ApiHost = string.Empty; + + public CPMetaService(IServiceProvider serviceProvider, IServiceScopeFactory scopeFactory, ConfigService configService) + { + _scopeFactory = scopeFactory; + _configService = configService; + + ApiHost = _configService.GetConfig()?.Api.Find(x => x.Id == 1)?.Host; + } + + public async Task GetWbmsMeta(DateOnly? startDate, DateOnly? endDate, string host) + { + string requestUrl = $"https://{host}/CPMeta/GetWbmsMeta?"; + requestUrl += $"startDate={startDate}&"; + requestUrl += $"endDate={endDate}&"; + requestUrl += $"ShardID=1"; + + Http http = new Http(); + var res = await http.GetJsonAsync($"{requestUrl}"); + + LogXnet.WriteLine($"{res.ToJson()}", LogXLabel.HTTP); + + return res; + } + + public async Task GetWbmsMetaByProductID(string productId, string host) + { + string requestUrl = $"https://{host}/CPMeta/GetWbmsMetaByProductID?"; + requestUrl += $"ProductID={productId}&"; + requestUrl += $"ShardID=1"; + + Http http = new Http(); + var res = await http.GetJsonAsync($"{requestUrl}"); + + LogXnet.WriteLine($"{res.ToJson()}", LogXLabel.HTTP); + + return res; + } + + public async Task GetWbmsMetaByMacAddress(string macAddress, string host) + { + string requestUrl = $"https://{host}/CPMeta/GetWbmsMetaByMacAddress?"; + requestUrl += $"MacAddress={macAddress}&"; + requestUrl += $"ShardID=1"; + + Http http = new Http(); + var res = await http.GetJsonAsync($"{requestUrl}"); + + LogXnet.WriteLine($"{res.ToJson()}", LogXLabel.HTTP); + + return res; + } + } +} diff --git a/Projects/WebClient/WebClient.sln b/Projects/WebClient/WebClient.sln index 959706b..3201236 100644 --- a/Projects/WebClient/WebClient.sln +++ b/Projects/WebClient/WebClient.sln @@ -9,6 +9,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Web.Tra", "Web.Tra\Web.Tra. EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Config", "Config", "{C8D5274F-AC00-46C7-1F8D-E88E81087A52}" ProjectSection(SolutionItems) = preProject + ..\Config\WebClient.Operation.Config.json = ..\Config\WebClient.Operation.Config.json ..\Config\WebClient.Tra.Config.json = ..\Config\WebClient.Tra.Config.json EndProjectSection EndProject