From 9a486a57b4b1af30d230dcae6359ccdf9d6d882b Mon Sep 17 00:00:00 2001 From: HK Date: Wed, 10 Jun 2026 13:59:28 +0900 Subject: [PATCH] =?UTF-8?q?=D0=91=D0=BE=D0=BB=D0=B5=D0=B5=20=D0=BC=D0=B5?= =?UTF-8?q?=D0=BD=D0=B5=D0=B5=20=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20?= =?UTF-8?q?=D1=81=D1=82=D1=80=D0=B0=D0=BD=D0=B8=D1=87=D0=BA=D1=83=20=D1=81?= =?UTF-8?q?=20=D0=BF=D1=80=D0=B8=D0=BD=D1=82=D0=B5=D1=80=D0=BE=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Network/NetworkController.cs | 3 +- .../Controllers/Printer/PrinterController.cs | 5 +- CartriX.Api/Controllers/Printer/PrinterMap.cs | 1 + .../Controllers/Printer/PrinterService.cs | 6 +- CartriX.Api/Service/CheckPrinterService.cs | 2 +- CartriX.Api/db.db | Bin 167936 -> 167936 bytes CartriX.Shared/Classes/ApiRoutes.cs | 5 +- CartriX.Shared/Models/Printer/PrinterItem.cs | 4 + CartriX.Web/Pages/PrinterPage.razor | 109 ++++++++++++++---- 9 files changed, 103 insertions(+), 32 deletions(-) diff --git a/CartriX.Api/Controllers/Network/NetworkController.cs b/CartriX.Api/Controllers/Network/NetworkController.cs index 2b3ef31..5748823 100644 --- a/CartriX.Api/Controllers/Network/NetworkController.cs +++ b/CartriX.Api/Controllers/Network/NetworkController.cs @@ -36,9 +36,8 @@ namespace CartriX.Api.Controllers.Network /// Сделать ПИНГ к указанному хосту или IP Адресу /// [ProducesResponseType(typeof(bool), StatusCodes.Status200OK)] - [ProducesResponseType(typeof(bool), StatusCodes.Status404NotFound)] [HttpGet(nameof(Ping))] - public async Task Ping([FromQuery] string IpAddressOrHostname) => (await NetworkHelper.PingHostAsync(IpAddressOrHostname)) ? StatusCode(200, true) : StatusCode(404, false); + public async Task Ping([FromQuery] string IpAddressOrHostname) => StatusCode(200, await NetworkHelper.PingHostAsync(IpAddressOrHostname)); /// diff --git a/CartriX.Api/Controllers/Printer/PrinterController.cs b/CartriX.Api/Controllers/Printer/PrinterController.cs index 8852e9c..d7f4c8b 100644 --- a/CartriX.Api/Controllers/Printer/PrinterController.cs +++ b/CartriX.Api/Controllers/Printer/PrinterController.cs @@ -71,8 +71,9 @@ namespace CartriX.Api.Controllers.Printer /// Поменять статус принтера /// [ProducesResponseType(StatusCodes.Status200OK)] - [HttpPut(nameof(ChangeStatus))] - public async Task ChangeStatus([FromQuery] int PrinterId, [FromQuery] int StatusId) + [ProducesResponseType(StatusCodes.Status404NotFound)] + [HttpPatch(nameof(ChangeStatus))] + public async Task ChangeStatus([FromQuery] int PrinterId, [FromBody] int StatusId) { try { diff --git a/CartriX.Api/Controllers/Printer/PrinterMap.cs b/CartriX.Api/Controllers/Printer/PrinterMap.cs index 6ccfa46..44f6cd7 100644 --- a/CartriX.Api/Controllers/Printer/PrinterMap.cs +++ b/CartriX.Api/Controllers/Printer/PrinterMap.cs @@ -12,6 +12,7 @@ Model = printer.Model.ToItem(), StatusId = printer.StatusId, StatusName = printer.Status.Name, + ConnetctionTypeId = printer.PrinterConnetctionTypeId, ConnetctionTypeName = printer.PrinterConnetctionType.Name, InstalledCartridgeId = printer.InstalledCartridge.Id, LocationName = printer.Location.Name, diff --git a/CartriX.Api/Controllers/Printer/PrinterService.cs b/CartriX.Api/Controllers/Printer/PrinterService.cs index 4f08534..e47db8e 100644 --- a/CartriX.Api/Controllers/Printer/PrinterService.cs +++ b/CartriX.Api/Controllers/Printer/PrinterService.cs @@ -69,7 +69,11 @@ namespace CartriX.Api.Controllers.Cartridge var printer = await _context.Printers.FindAsync(PrinterId); if (printer is not null) { - if (await _context.PrinterStatuses.FindAsync(StatusId) is not null) printer.StatusId = StatusId; + if (await _context.PrinterStatuses.FindAsync(StatusId) is not null) + { + printer.StatusId = StatusId; + await _context.SaveChangesAsync(); + } else throw new NullReferenceException($"Нету статуса под идентификатором {StatusId}"); } else diff --git a/CartriX.Api/Service/CheckPrinterService.cs b/CartriX.Api/Service/CheckPrinterService.cs index 9a08ae2..eff3f8f 100644 --- a/CartriX.Api/Service/CheckPrinterService.cs +++ b/CartriX.Api/Service/CheckPrinterService.cs @@ -42,7 +42,7 @@ namespace CartriX.Api.Service await AnsiConsole.Status() .StartAsync("[bold cyan]Получение списка принтеров...[/]", async ctx => { - List printersList = await dbContext.Printers.Where(p => p.PrinterConnetctionTypeId == 1).AsTracking().ToListAsync(); + List printersList = await dbContext.Printers.Where(p => p.PrinterConnetctionTypeId == 1).Where(p => p.StatusId != 3).AsTracking().ToListAsync(); ctx.Status($"[green]✓[/] Получен список ({printersList.Count} устройств)"); await Task.Delay(500); diff --git a/CartriX.Api/db.db b/CartriX.Api/db.db index 2769ba6bdc05cbf74ea39dc9feb6e1ceb05c69cb..d0fe14ffca4e9b9afa188ea250431d738ef82fd3 100644 GIT binary patch delta 855 zcma))T}TvB6vywmXLjA$k2$+U$&&5|1R1pJ%&cuHAsZX|qPR#wBxIYrrX^al3iTlD zTW@0c;A6fN^c1<|;)4X@OZ65(3Vm!DQkY+uMjFsl;f9R;X0)C0@}v8Ik$V zw?^u8Rpz2hHtSmbSqC7iESDbT8&i}i8-1nMbcP<#DBYo6Qk0*{Te_q?r<2N5!RH-S znhq0?<*z|%XOi24)qk($cz@1^LZ&S}Fx->w9vU{XMoucUcRf|z63sALruQ^YGs4It za>cLp$EZYeLSUK#Rou=_ z0fVwcDAk+JWsOiQrmAhtDG3Xu-^aW{bCuB^eW%reFaLqUHbekK8y7Dw7L;WtV+?7< z#I|TfVDHFLA%TfuajO=5UeR}i(JYOKzPBjR#9hpP0+TYxvYhF;e&cFyvb80W>Np?K zH8rAYaG^qr#-j147S+X57mI4DRf(O(CuZBBML1iq(k_U!FGz8tg8^p_5TE)BpIGjK zfE`Ttrt>8V`@qJ+0J^HjBWgUNshnHRHyHgAzsiQdK2gAC<+I}bOSf*O+opBFe59bs zNLVJhgdiUXZJI(qXtU_^!e^>7B~U_HtjG?g^gq3X%nohRUfH(I6u{!nGf+ZBDG%FJ zA(eaLbRPDDT$ZPAg57IhVzfkSViIr2+_0NhvKYYxFvYPtRB0X zaEw80V+|{qgQ~u$XPAIXy%V~2pw_4gZ>9dQ5jWVIC2Cg&XJSmX^7nB(2#^R z35qZ!>?xAweT$VMPmq`M2}J&*O_L{&1aEj0`q4G&%NVDW$--?mg%H9}{Mr`f!xb{c zPO59tB1@2!DFUf%fR6r7Ntr>~A}mKGq%~&MGS&zB?4Ts`0amW<~pd=aYq03nQ6aS}NASg(tOQZ^&to9%8 $"api/{nameof(Printer)}/{nameof(ListConnectionType)}"; public static string ListPrintType => $"api/{nameof(Printer)}/{nameof(ListPrintType)}"; public static string GetAddressOIDs => $"api/{nameof(Printer)}/{nameof(GetAddressOIDs)}"; - } - public static class Location + public static string ChangeStatus(int PrinterId) => $"api/{nameof(Printer)}/{nameof(ChangeStatus)}?{nameof(PrinterId)}={PrinterId}"; + } + public static class Location { public static string List => $"api/{nameof(Location)}/{nameof(List)}"; public static string ListPrinters(int LocationId) => $"api/{nameof(Location)}/{nameof(ListPrinters)}?{nameof(LocationId)}={LocationId}"; diff --git a/CartriX.Shared/Models/Printer/PrinterItem.cs b/CartriX.Shared/Models/Printer/PrinterItem.cs index 9c97e20..372f436 100644 --- a/CartriX.Shared/Models/Printer/PrinterItem.cs +++ b/CartriX.Shared/Models/Printer/PrinterItem.cs @@ -41,6 +41,10 @@ /// public string StatusName { get; set; } = string.Empty; /// + /// Идентификатор типа подключения принтера + /// + public int ConnetctionTypeId { get; set; } + /// /// Название типа подключения принтера /// public string ConnetctionTypeName { get; set; } = string.Empty; diff --git a/CartriX.Web/Pages/PrinterPage.razor b/CartriX.Web/Pages/PrinterPage.razor index 6cc9b70..299e4c8 100644 --- a/CartriX.Web/Pages/PrinterPage.razor +++ b/CartriX.Web/Pages/PrinterPage.razor @@ -4,53 +4,114 @@ @inject IJSRuntime JS @using System.Net + -@if (printer.StatusId == 1) + + + + + + + +@if (dataIsLoading) +{ + +

Получаем информацию...

+
+} +else if (printer is null) { } else { - + if (pingIsActive) + { +

Пингуем...

+ } + else + { + + + + @if (printer.Model.PicturePath is null) + { + + } + else + { + + } + + + @printer.Model.Manufacturer.Name + + + + + + + + + + + + + + + + + } } - - - - - - - - - - - - - - @code { - //bool dataIsLoading; + bool dataIsLoading; + bool pingIsActive; [Parameter] public int PrinterId { get; set; } - private Models.Printer.PrinterItem printer = default!; + private Models.Printer.PrinterItem? printer = default!; protected async override Task OnInitializedAsync() { - // dataIsLoading = true; + dataIsLoading = true; await GetPrinterInfo(); - //dataIsLoading = false; + dataIsLoading = false; + StateHasChanged(); + await PingPrinter(); } - async Task GetPrinterInfo() { var responce = await http.GetAsync(ApiRoutes.Printer.Item(PrinterId)); var json = await responce.Content.ReadAsStringAsync(); printer = JsonConvert.DeserializeObject(json)!; } + async Task PingPrinter() + { + pingIsActive = true; + await InvokeAsync(StateHasChanged); + var responce = await http.GetFromJsonAsync(ApiRoutes.Network.Ping(printer!.IpAddressOrHostname!)); + Console.WriteLine(responce); + bool pingIsSuccessful = (bool)responce; + int SetStatusId = (pingIsSuccessful) ? 1 : 2; + await http.PatchAsJsonAsync(ApiRoutes.Printer.ChangeStatus(PrinterId), SetStatusId); + await GetPrinterInfo(); + pingIsActive = false; + await InvokeAsync(StateHasChanged); + } async Task ChangeCartridgeClick() { NavigationManager.NavigateTo($"/printer/{PrinterId}/cartridgereplace"); @@ -59,7 +120,7 @@ else { string features = "width=1280,height=720,resizable=no,scrollbars=yes"; - if (IPAddress.TryParse(printer.IpAddressOrHostname, out IPAddress? address)) + if (IPAddress.TryParse(printer!.IpAddressOrHostname, out IPAddress? address)) { await JS.InvokeVoidAsync("open", $"http://{address.ToString()}", "_blank", features); }