fix 设备注册自动新增

This commit is contained in:
2024-01-10 17:33:27 +08:00
parent 2e51a13c3d
commit 54835e6cae
6 changed files with 47 additions and 8 deletions

View File

@@ -1,4 +1,5 @@
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using Npgsql.Replication.PgOutput;
namespace Dlhis.Basic.Device.Request; namespace Dlhis.Basic.Device.Request;
@@ -10,6 +11,11 @@ public class DeviceResigterRequest
[Required(ErrorMessage = "设备唯一编码不能为空")] [Required(ErrorMessage = "设备唯一编码不能为空")]
public string UniqueNo { get; set; } public string UniqueNo { get; set; }
/// <summary>
/// 设备部署位置
/// </summary>
public string DeployPlace { get; set; }
/// <summary> /// <summary>
/// 营业点手工号; 可为空,后续在后台中设置 /// 营业点手工号; 可为空,后续在后台中设置
/// </summary> /// </summary>

View File

@@ -23,10 +23,11 @@ public class DeviceConnectService : IDeviceConnectService
[IgnoreTenant] [IgnoreTenant]
public async Task<string> ResigterAsync(DeviceResigterRequest request) public async Task<string> ResigterAsync(DeviceResigterRequest request)
{ {
var device = await GetEnableDeviceAsync(request.UniqueNo);
var registry = await _dbContext.Queryable<DeviceRegistryEntity>().Where(x => x.DeviceUniqueNo == request.UniqueNo).FirstAsync();
var businessPlace = await _dbContext.Queryable<CanteenBusinessPlaceEntity>().Where(x => x.CustomCode == request.BusinessCustomCode).FirstAsync(); var businessPlace = await _dbContext.Queryable<CanteenBusinessPlaceEntity>().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<DeviceRegistryEntity>().Where(x => x.DeviceUniqueNo == request.UniqueNo).FirstAsync();
if (registry == null) if (registry == null)
{ {
@@ -92,15 +93,45 @@ public class DeviceConnectService : IDeviceConnectService
/// 获取启用的设备 /// 获取启用的设备
/// </summary> /// </summary>
/// <param name="uniqueNo"></param> /// <param name="uniqueNo"></param>
/// <param name="checkExists"></param>
/// <param name="deployPlace"></param>
/// <param name="tenantId"></param>
/// <returns></returns> /// <returns></returns>
private async Task<DeviceEntity> GetEnableDeviceAsync(string uniqueNo) private async Task<DeviceEntity> GetEnableDeviceAsync(string uniqueNo, bool checkExists = true, string deployPlace = "", string tenantId = "")
{ {
var device = await _dbContext.Queryable<DeviceEntity>() var device = await _dbContext.Queryable<DeviceEntity>()
.Where(x => x.UniqueNo == uniqueNo) .Where(x => x.UniqueNo == uniqueNo)
.FirstAsync(); .FirstAsync();
device.ThrowIfNull($"未知的设备唯一编码{uniqueNo}"); if (checkExists)
device.Enable.ThrowIfFalse("设备尚未启用"); {
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<DeviceFuncEnumType>(),
DeployPlace = deployPlace,
HeartbeatInterval = 0,
DeployDirection = string.Empty,
Enable = true,
DeployPosition = string.Empty,
};
await _dbContext.InsertAsync(device);
}
}
return device; return device;
} }

View File

@@ -18,6 +18,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Kurisu.AspNetCore" Version="0.4.8" /> <PackageReference Include="Kurisu.AspNetCore" Version="0.4.8" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.4" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@@ -7,7 +7,9 @@ EXPOSE 80
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src WORKDIR /src
COPY ["Src/Dlhis.Basic/Dlhis.Basic.csproj", "Src/Dlhis.Basic/"] 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.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" RUN dotnet restore "Src/Dlhis.Basic/Dlhis.Basic.csproj"
COPY . . COPY . .
WORKDIR "/src/Src/Dlhis.Basic" WORKDIR "/src/Src/Dlhis.Basic"

View File

@@ -36,4 +36,3 @@ public class WerkService : IWerkService
return tenants.FirstOrDefault(x => x.Code == tenant); return tenants.FirstOrDefault(x => x.Code == tenant);
} }
} }
*/

View File

@@ -69,7 +69,7 @@ public class DeviceEntity : SugarBaseEntity, ITenantId
/// 模板code /// 模板code
/// </summary> /// </summary>
[SugarColumn(ColumnDescription = "模板code")] [SugarColumn(ColumnDescription = "模板code")]
public Guid TemplateCode { get; set; } public Guid? TemplateCode { get; set; }
/// <summary> /// <summary>
/// 连接信息 /// 连接信息