fix datapermission crosstenant
This commit is contained in:
@@ -34,13 +34,10 @@ public class DeviceService : IDeviceService
|
||||
|
||||
public async Task<Pagination<DevicePageResponse>> GetPageAsync(DevicePageRequest request)
|
||||
{
|
||||
var tenantId = _currentUser.GetStringTenantId();
|
||||
|
||||
var page = await _dbContext.Queryable<DeviceEntity>()
|
||||
.LeftJoin<DeviceTemplateEntity>((d, dt) => d.TemplateCode == dt.Code)
|
||||
.LeftJoin<DeviceRegistryEntity>((d, dt, dr) => d.UniqueNo == dr.DeviceUniqueNo)
|
||||
.LeftJoin<BusinessPlaceEntity>((d, dt, dr, bp) => dr.BusinessPlaceCode == bp.Code)
|
||||
.Where(d => tenantId == d.TenantId)
|
||||
.Where((d, dt) => d.Type == request.Type)
|
||||
.WhereIF(request.Enable.HasValue, (d, dt) => d.Enable == request.Enable)
|
||||
.WhereIF(request.Search.IsPresent(), d => d.UniqueNo == request.Search || d.DeployPlace.Contains(request.Search))
|
||||
@@ -65,7 +62,7 @@ public class DeviceService : IDeviceService
|
||||
await CheckUniqueNoExistsAsync(request);
|
||||
await CheckTemplateExistsAsync(request.TemplateCode);
|
||||
await CheckTemplateFieldAsync(request.TemplateCode, request.ConnectionInfo);
|
||||
|
||||
|
||||
await _deviceTimePeriodService.GenerateDeviceTimePeriodTasksAsync(async () =>
|
||||
{
|
||||
DeviceEntity entity;
|
||||
@@ -232,70 +229,36 @@ public class DeviceService : IDeviceService
|
||||
/// <returns></returns>
|
||||
private async Task CheckUniqueNoExistsAsync(DeviceSaveRequest request)
|
||||
{
|
||||
var currentTenantId = _currentUser.GetStringTenantId();
|
||||
_dbContext.Client.QueryFilter.ClearAndBackup<ITenantId>();
|
||||
try
|
||||
{
|
||||
//查询设备是否存在
|
||||
var device = await _dbContext.Queryable<DeviceEntity>()
|
||||
.Where(x => x.UniqueNo == request.UniqueNo)
|
||||
.WhereIF(request.Id.HasValue, x => x.Id != request.Id)
|
||||
.FirstAsync();
|
||||
await _dbContext.IgnoreAsync<ITenantId>(async () =>
|
||||
{
|
||||
var currentTenantId = _currentUser.GetStringTenantId();
|
||||
|
||||
if (device != null)
|
||||
{
|
||||
(device.TenantId == currentTenantId).ThrowIfTrue("设备已经存在,请检查");
|
||||
//查询设备是否存在
|
||||
var device = await _dbContext.Queryable<DeviceEntity>()
|
||||
.Where(x => x.UniqueNo == request.UniqueNo)
|
||||
.WhereIF(request.Id.HasValue, x => x.Id != request.Id)
|
||||
.SingleAsync();
|
||||
|
||||
var factory = device.TenantId;
|
||||
try
|
||||
{
|
||||
var tenantResult = await _tenantApi.GetTenantByCodeAsync(device.TenantId);
|
||||
factory = tenantResult?.Data?.Name ?? string.Empty;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//ignore
|
||||
}
|
||||
if (device != null)
|
||||
{
|
||||
(device.TenantId == currentTenantId).ThrowIfTrue("设备已经存在,请检查");
|
||||
|
||||
true.ThrowIfTrue($"设备已添加{factory}厂区");
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
_dbContext.Client.QueryFilter.Restore();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public async Task<bool> CheckExistsAsync(string deviceUniqueNo)
|
||||
{
|
||||
_dbContext.Client.QueryFilter.ClearAndBackup<ITenantId>();
|
||||
try
|
||||
{
|
||||
return await _dbContext.Queryable<DeviceEntity>()
|
||||
.Where(x => x.UniqueNo == deviceUniqueNo && x.Enable)
|
||||
.AnyAsync();
|
||||
}
|
||||
finally
|
||||
{
|
||||
_dbContext.Client.QueryFilter.Restore();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public async Task<List<DeviceResponse>> GetAttendanceDevicesAsync()
|
||||
{
|
||||
var devices = await _dbContext.Queryable<DeviceEntity>()
|
||||
.Where(x => x.Enable)
|
||||
.Where(x => x.Type == DeviceTypeEnumType.Attendance || (x.Type == DeviceTypeEnumType.Door && x.AsAttendance))
|
||||
.Select(x => new DeviceResponse
|
||||
{
|
||||
FuncsStr = x.Funcs.ToString()
|
||||
}, true)
|
||||
.ToListAsync();
|
||||
|
||||
return devices.Where(x => x.Type == DeviceTypeEnumType.Attendance).ToList();
|
||||
var factory = device.TenantId;
|
||||
try
|
||||
{
|
||||
var tenantResult = await _tenantApi.GetTenantByCodeAsync(device.TenantId);
|
||||
factory = tenantResult?.Data?.Name ?? string.Empty;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//ignore
|
||||
}
|
||||
|
||||
true.ThrowIfTrue($"设备已添加{factory}厂区");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取离线设备
|
||||
|
||||
Reference in New Issue
Block a user