From 54835e6caeade615c8f132bcf1b2689880b6f21b Mon Sep 17 00:00:00 2001 From: liguoyang Date: Wed, 10 Jan 2024 17:33:27 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E8=AE=BE=E5=A4=87=E6=B3=A8=E5=86=8C?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E6=96=B0=E5=A2=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Device/Request/DeviceResigterRequest.cs | 6 +++ .../Implements/DeviceConnectService.cs | 43 ++++++++++++++++--- Src/Dlhis.Basic/Dlhis.Basic.csproj | 1 + Src/Dlhis.Basic/Dockerfile | 2 + .../Services/Implements/WerkService.cs | 1 - Src/Dlhis.Entity/Basic/Entity/DeviceEntity.cs | 2 +- 6 files changed, 47 insertions(+), 8 deletions(-) diff --git a/Src/Dlhis.Basic/Device/Request/DeviceResigterRequest.cs b/Src/Dlhis.Basic/Device/Request/DeviceResigterRequest.cs index f9ed7579..e591f825 100644 --- a/Src/Dlhis.Basic/Device/Request/DeviceResigterRequest.cs +++ b/Src/Dlhis.Basic/Device/Request/DeviceResigterRequest.cs @@ -1,4 +1,5 @@ using System.ComponentModel.DataAnnotations; +using Npgsql.Replication.PgOutput; namespace Dlhis.Basic.Device.Request; @@ -10,6 +11,11 @@ public class DeviceResigterRequest [Required(ErrorMessage = "设备唯一编码不能为空")] public string UniqueNo { get; set; } + /// + /// 设备部署位置 + /// + public string DeployPlace { get; set; } + /// /// 营业点手工号; 可为空,后续在后台中设置 /// diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DeviceConnectService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DeviceConnectService.cs index e3e43cbc..2e83f8fa 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DeviceConnectService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DeviceConnectService.cs @@ -23,10 +23,11 @@ public class DeviceConnectService : IDeviceConnectService [IgnoreTenant] public async Task ResigterAsync(DeviceResigterRequest request) { - var device = await GetEnableDeviceAsync(request.UniqueNo); - - var registry = await _dbContext.Queryable().Where(x => x.DeviceUniqueNo == request.UniqueNo).FirstAsync(); var businessPlace = await _dbContext.Queryable().Where(x => x.CustomCode == request.BusinessCustomCode).FirstAsync(); + businessPlace.ThrowIfNull("营业点不存在"); + + var device = await GetEnableDeviceAsync(request.UniqueNo, false, request.DeployPlace, businessPlace.TenantId); + var registry = await _dbContext.Queryable().Where(x => x.DeviceUniqueNo == request.UniqueNo).FirstAsync(); if (registry == null) { @@ -92,15 +93,45 @@ public class DeviceConnectService : IDeviceConnectService /// 获取启用的设备 /// /// + /// + /// + /// /// - private async Task GetEnableDeviceAsync(string uniqueNo) + private async Task GetEnableDeviceAsync(string uniqueNo, bool checkExists = true, string deployPlace = "", string tenantId = "") { var device = await _dbContext.Queryable() .Where(x => x.UniqueNo == uniqueNo) .FirstAsync(); - device.ThrowIfNull($"未知的设备唯一编码{uniqueNo}"); - device.Enable.ThrowIfFalse("设备尚未启用"); + if (checkExists) + { + device.ThrowIfNull($"未知的设备唯一编码{uniqueNo}"); + device.Enable.ThrowIfFalse("设备尚未启用"); + } + else + { + if (device == null) + { + device = new DeviceEntity() + { + Code = Guid.NewGuid(), + Brand = string.Empty, + ConnectionInfo = string.Empty, + TemplateCode = null, + UniqueNo = uniqueNo, + TenantId = tenantId, + Supplier = string.Empty, + Funcs = new List(), + DeployPlace = deployPlace, + HeartbeatInterval = 0, + DeployDirection = string.Empty, + Enable = true, + DeployPosition = string.Empty, + }; + + await _dbContext.InsertAsync(device); + } + } return device; } diff --git a/Src/Dlhis.Basic/Dlhis.Basic.csproj b/Src/Dlhis.Basic/Dlhis.Basic.csproj index d1819b46..2dac3683 100644 --- a/Src/Dlhis.Basic/Dlhis.Basic.csproj +++ b/Src/Dlhis.Basic/Dlhis.Basic.csproj @@ -18,6 +18,7 @@ + diff --git a/Src/Dlhis.Basic/Dockerfile b/Src/Dlhis.Basic/Dockerfile index 074db035..e2202471 100644 --- a/Src/Dlhis.Basic/Dockerfile +++ b/Src/Dlhis.Basic/Dockerfile @@ -7,7 +7,9 @@ EXPOSE 80 FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build WORKDIR /src COPY ["Src/Dlhis.Basic/Dlhis.Basic.csproj", "Src/Dlhis.Basic/"] +COPY ["Src/Dlhis.Common.Api/Dlhis.Common.Api.csproj", "Src/Dlhis.Common.Api/"] COPY ["Src/Dlhis.Entity/Dlhis.Entity.csproj", "Src/Dlhis.Entity/"] +COPY ["Src/Dlhis.User.Api/Dlhis.User.Api.csproj", "Src/Dlhis.User.Api/"] RUN dotnet restore "Src/Dlhis.Basic/Dlhis.Basic.csproj" COPY . . WORKDIR "/src/Src/Dlhis.Basic" diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/WerkService.cs b/Src/Dlhis.Basic/Organization/Services/Implements/WerkService.cs index 12c3bc68..7af7ff74 100644 --- a/Src/Dlhis.Basic/Organization/Services/Implements/WerkService.cs +++ b/Src/Dlhis.Basic/Organization/Services/Implements/WerkService.cs @@ -36,4 +36,3 @@ public class WerkService : IWerkService return tenants.FirstOrDefault(x => x.Code == tenant); } } -*/ \ No newline at end of file diff --git a/Src/Dlhis.Entity/Basic/Entity/DeviceEntity.cs b/Src/Dlhis.Entity/Basic/Entity/DeviceEntity.cs index 2b977cc8..cfec400f 100644 --- a/Src/Dlhis.Entity/Basic/Entity/DeviceEntity.cs +++ b/Src/Dlhis.Entity/Basic/Entity/DeviceEntity.cs @@ -69,7 +69,7 @@ public class DeviceEntity : SugarBaseEntity, ITenantId /// 模板code /// [SugarColumn(ColumnDescription = "模板code")] - public Guid TemplateCode { get; set; } + public Guid? TemplateCode { get; set; } /// /// 连接信息