重复设备sn 判断

This commit is contained in:
yanghongwei 2025-04-18 20:32:04 +08:00
parent 1e0e5ff151
commit 32e9ced4dc
1 changed files with 9 additions and 0 deletions

View File

@ -64,6 +64,15 @@ namespace LY.App.Service
public async Task<ApiResult> Add(AddDevice input)
{
var entity = input.Adapt<DeviceEntity>();
var exists = await _db.Queryable<DeviceEntity>().FirstAsync(s => s.DeviceSN == entity.DeviceSN);
if (exists!= null)
{
return new ApiResult()
{
code = 1,
msg = "设备SN已存在"
};
}
var id = await _db.Insertable(entity).ExecuteReturnSnowflakeIdAsync();
entity.Id = id;
await AddDevice2Manager(entity);