fix tenantId

This commit is contained in:
2024-03-06 19:42:35 +08:00
parent 21b7ec64b2
commit 2e6602737a

View File

@@ -49,6 +49,7 @@ public class DeviceGroupService : IDeviceGroupService
{
var entity = request.Adapt<DeviceGroupEntity>();
entity.Code = Guid.NewGuid();
entity.TenantId = _currentUser.GetStringTenantId();
await _dbContext.InsertAsync(entity);
}
@@ -89,7 +90,7 @@ public class DeviceGroupService : IDeviceGroupService
public async Task AssignDevicesAsync(DeviceAssignRequest request)
{
var group = await _dbContext.Queryable<DeviceGroupEntity>().Where(x => x.Code == request.GroupCode).FirstAsync();
group.ThrowIfNull("设备组不存在");
group.ThrowIfNull("设备组不存在,无法进行分配");
await CheckNoNextGroupAsync(group.Code);
await CheckGroupTypeMatchAsync(request, group);
@@ -133,17 +134,15 @@ public class DeviceGroupService : IDeviceGroupService
/// <returns></returns>
private async Task<DeviceGroupEntity> CheckPCodeAsync(DeviceGroupSaveRequest request)
{
var pGrp = await _dbContext.Queryable<DeviceGroupEntity>().Where(x => x.Code == request.PCode).FirstAsync();
if (pGrp != null)
{
(!pGrp.AbleSetNext && !request.Id.HasValue).ThrowIfTrue($"{pGrp.Name}不可添加下级");
var exists = await _dbContext.Queryable<DeviceGroupRelationshipEntity>().Where(x => x.GroupCode == request.PCode).AnyAsync();
exists.ThrowIfTrue("父级分组存在设备");
exists.ThrowIfTrue("上级分组存在设备");
}
(pGrp != null && pGrp.Type != request.Type).ThrowIfTrue("分组类型必须与上级类型保持一致");
(pGrp != null && pGrp.Type != request.Type).ThrowIfTrue("分组类型必须与上级类型保持一致");
return pGrp;
}