fix 设备注册自动新增
This commit is contained in:
@@ -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; }
|
||||
|
||||
/// <summary>
|
||||
/// 设备部署位置
|
||||
/// </summary>
|
||||
public string DeployPlace { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 营业点手工号; 可为空,后续在后台中设置
|
||||
/// </summary>
|
||||
|
||||
@@ -23,10 +23,11 @@ public class DeviceConnectService : IDeviceConnectService
|
||||
[IgnoreTenant]
|
||||
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();
|
||||
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)
|
||||
{
|
||||
@@ -92,15 +93,45 @@ public class DeviceConnectService : IDeviceConnectService
|
||||
/// 获取启用的设备
|
||||
/// </summary>
|
||||
/// <param name="uniqueNo"></param>
|
||||
/// <param name="checkExists"></param>
|
||||
/// <param name="deployPlace"></param>
|
||||
/// <param name="tenantId"></param>
|
||||
/// <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>()
|
||||
.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<DeviceFuncEnumType>(),
|
||||
DeployPlace = deployPlace,
|
||||
HeartbeatInterval = 0,
|
||||
DeployDirection = string.Empty,
|
||||
Enable = true,
|
||||
DeployPosition = string.Empty,
|
||||
};
|
||||
|
||||
await _dbContext.InsertAsync(device);
|
||||
}
|
||||
}
|
||||
|
||||
return device;
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Kurisu.AspNetCore" Version="0.4.8" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.4" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -36,4 +36,3 @@ public class WerkService : IWerkService
|
||||
return tenants.FirstOrDefault(x => x.Code == tenant);
|
||||
}
|
||||
}
|
||||
*/
|
||||
@@ -69,7 +69,7 @@ public class DeviceEntity : SugarBaseEntity, ITenantId
|
||||
/// 模板code
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnDescription = "模板code")]
|
||||
public Guid TemplateCode { get; set; }
|
||||
public Guid? TemplateCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 连接信息
|
||||
|
||||
Reference in New Issue
Block a user