fix 调整无授权处理,增加检查设备是否存在接口
This commit is contained in:
@@ -9,4 +9,6 @@ public interface IDeviceService : IScopeDependency
|
||||
Task<Pagination<DeviceResponse>> GetPageAsync(DevicePageRequest request);
|
||||
|
||||
Task SaveAsync(DeviceSaveRequest request);
|
||||
|
||||
Task<bool> CheckExistsAsync(string deviceUniqueNo);
|
||||
}
|
||||
|
||||
@@ -35,9 +35,10 @@ public class DeviceConnectService : IDeviceConnectService
|
||||
RegisterTime = DateTime.Now,
|
||||
BusinessPlaceCode = businessPlace?.Code,
|
||||
BusinessPlaceCustomCode = businessPlace?.CustomCode,
|
||||
TenantId = device.TenantId,
|
||||
};
|
||||
await _dbContext.InsertAsync(registry);
|
||||
|
||||
await _dbContext.InsertAsync(registry);
|
||||
return "设备注册成功";
|
||||
}
|
||||
|
||||
@@ -93,8 +94,8 @@ public class DeviceConnectService : IDeviceConnectService
|
||||
private async Task<DeviceEntity> GetEnableDeviceAsync(string uniqueNo)
|
||||
{
|
||||
var device = await _dbContext.Queryable<DeviceEntity>()
|
||||
.Where(x => x.UniqueNo == uniqueNo)
|
||||
.FirstAsync();
|
||||
.Where(x => x.UniqueNo == uniqueNo)
|
||||
.FirstAsync();
|
||||
|
||||
device.ThrowIfNull($"未知的设备唯一编码{uniqueNo}");
|
||||
device.Enable.ThrowIfFalse("设备尚未启用");
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
using Dlhis.Basic.Device.Request;
|
||||
using Dlhis.Basic.Device.Response;
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Device.Entities;
|
||||
using Kurisu.AspNetCore.UnifyResultAndValidation;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
using Kurisu.Core.DataAccess.Dto;
|
||||
using Kurisu.SqlSugar.Attributes;
|
||||
using Kurisu.SqlSugar.Extensions;
|
||||
using Kurisu.SqlSugar.Services;
|
||||
using Mapster;
|
||||
@@ -34,6 +36,7 @@ public class DeviceService : IDeviceService
|
||||
return page;
|
||||
}
|
||||
|
||||
[Transactional]
|
||||
public async Task SaveAsync(DeviceSaveRequest request)
|
||||
{
|
||||
await CheckUniqueNoExistsAsync(request);
|
||||
@@ -46,6 +49,21 @@ public class DeviceService : IDeviceService
|
||||
entity.Code = Guid.NewGuid();
|
||||
entity.Brand = template.Brand;
|
||||
await _dbContext.InsertAsync(entity);
|
||||
//同时保存注册信息
|
||||
var registry = await _dbContext.Queryable<DeviceRegistryEntity>().Where(x => x.DeviceUniqueNo == request.UniqueNo).FirstAsync();
|
||||
if (registry == null)
|
||||
{
|
||||
registry = new DeviceRegistryEntity()
|
||||
{
|
||||
DeviceUniqueNo = request.UniqueNo,
|
||||
LastHeartbeatTime = DateTime.Now,
|
||||
RegisterTime = DateTime.Now,
|
||||
BusinessPlaceCode = null,
|
||||
BusinessPlaceCustomCode = null,
|
||||
};
|
||||
|
||||
await _dbContext.InsertAsync(registry);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -119,5 +137,13 @@ public class DeviceService : IDeviceService
|
||||
|
||||
exists.ThrowIfTrue("唯一号已经存在");
|
||||
}
|
||||
|
||||
[IgnoreTenant]
|
||||
public async Task<bool> CheckExistsAsync(string deviceUniqueNo)
|
||||
{
|
||||
return await _dbContext.Queryable<DeviceEntity>()
|
||||
.Where(x => x.UniqueNo == deviceUniqueNo && x.Enable)
|
||||
.AnyAsync();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user