test ts
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Concurrent;
|
||||
using System.Diagnostics;
|
||||
using Dlhis.Basic.DataPermissions;
|
||||
using Dlhis.Basic.Device.Dtos;
|
||||
using Dlhis.Basic.Device.Request;
|
||||
@@ -30,18 +31,21 @@ public class DevicePermissionService : IDevicePermissionService
|
||||
private readonly IMyDataPermissionService _myDataPermissionService;
|
||||
private readonly ITenantApi _tenantApi;
|
||||
private readonly IParallelService _parallelService;
|
||||
private readonly ILogger<DevicePermissionService> _logger;
|
||||
private readonly ICurrentUser _currentUser;
|
||||
|
||||
public DevicePermissionService(IDbContext dbContext,
|
||||
IMyDataPermissionService myDataPermissionService,
|
||||
ITenantApi tenantApi,
|
||||
IParallelService parallelService,
|
||||
ILogger<DevicePermissionService> logger,
|
||||
ICurrentUser currentUser)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
_myDataPermissionService = myDataPermissionService;
|
||||
_tenantApi = tenantApi;
|
||||
_parallelService = parallelService;
|
||||
_logger = logger;
|
||||
_currentUser = currentUser;
|
||||
}
|
||||
|
||||
@@ -1022,6 +1026,8 @@ public class DevicePermissionService : IDevicePermissionService
|
||||
|
||||
private async Task<Dictionary<string, List<UserTenantDeviceCodeDto>>> GetAssignDeviceCodesInternalAsync(List<string> userNos)
|
||||
{
|
||||
var sw = Stopwatch.StartNew();
|
||||
|
||||
var devices = await _dbContext.Queryable<DeviceEntity>().Where(x => x.Enable).ToListAsync();
|
||||
var deviceUniqueNos = devices.Select(x => x.UniqueNo).ToList();
|
||||
var registries = await _dbContext.Queryable<DeviceRegistryEntity>()
|
||||
@@ -1043,54 +1049,63 @@ public class DevicePermissionService : IDevicePermissionService
|
||||
var deviceRelationships = await _dbContext.Queryable<DeviceGroupRelationshipEntity>().ToListAsync();
|
||||
var departments = await _dbContext.Queryable<DepartmentEntity>().ToListAsync();
|
||||
|
||||
if (_parallelService.Enable)
|
||||
_logger.LogWarning("获取数据时间:{ts}", sw.ElapsedMilliseconds);
|
||||
|
||||
try
|
||||
{
|
||||
var result = new ConcurrentDictionary<string, List<UserTenantDeviceCodeDto>>();
|
||||
|
||||
Parallel.ForEach(gainfos, new ParallelOptions { MaxDegreeOfParallelism = 4 }, gainfo =>
|
||||
if (_parallelService.Enable)
|
||||
{
|
||||
var gainfoDto = new GainfoDto
|
||||
var result = new ConcurrentDictionary<string, List<UserTenantDeviceCodeDto>>();
|
||||
|
||||
Parallel.ForEach(gainfos, new ParallelOptions { MaxDegreeOfParallelism = 4 }, gainfo =>
|
||||
{
|
||||
Id = gainfo.Id,
|
||||
No = gainfo.No,
|
||||
Code = gainfo.Code,
|
||||
Name = gainfo.Name,
|
||||
Workplace = gainfo.Workplace,
|
||||
Factory = gainfo.Factory,
|
||||
DepartmentNo = gainfo.DepartmentNo,
|
||||
IsOutsource = gainfo.Type == GainfoUserTypeEnumType.Outsource,
|
||||
EnableFactoryPermission = enableFactoryPermissions.FirstOrDefault(x => x.TenantId == gainfo.Factory)?.EnableOutsourceDown ?? true
|
||||
};
|
||||
var gainfoDto = new GainfoDto
|
||||
{
|
||||
Id = gainfo.Id,
|
||||
No = gainfo.No,
|
||||
Code = gainfo.Code,
|
||||
Name = gainfo.Name,
|
||||
Workplace = gainfo.Workplace,
|
||||
Factory = gainfo.Factory,
|
||||
DepartmentNo = gainfo.DepartmentNo,
|
||||
IsOutsource = gainfo.Type == GainfoUserTypeEnumType.Outsource,
|
||||
EnableFactoryPermission = enableFactoryPermissions.FirstOrDefault(x => x.TenantId == gainfo.Factory)?.EnableOutsourceDown ?? true
|
||||
};
|
||||
|
||||
var codes = GetAssignDeviceCodesInternal(gainfoDto, gainfoGroupRelationships, devicePermissions, deviceGroups, deviceRelationships, registries, devices, departments);
|
||||
result.TryAdd(gainfo.No, codes);
|
||||
});
|
||||
var codes = GetAssignDeviceCodesInternal(gainfoDto, gainfoGroupRelationships, devicePermissions, deviceGroups, deviceRelationships, registries, devices, departments);
|
||||
result.TryAdd(gainfo.No, codes);
|
||||
});
|
||||
|
||||
return result.ToDictionary(x => x.Key, x => x.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
var result = new Dictionary<string, List<UserTenantDeviceCodeDto>>();
|
||||
foreach (var gainfo in gainfos)
|
||||
{
|
||||
var gainfoDto = new GainfoDto
|
||||
{
|
||||
Id = gainfo.Id,
|
||||
No = gainfo.No,
|
||||
Code = gainfo.Code,
|
||||
Name = gainfo.Name,
|
||||
Workplace = gainfo.Workplace,
|
||||
Factory = gainfo.Factory,
|
||||
DepartmentNo = gainfo.DepartmentNo,
|
||||
IsOutsource = gainfo.Type == GainfoUserTypeEnumType.Outsource,
|
||||
EnableFactoryPermission = enableFactoryPermissions.FirstOrDefault(x => x.TenantId == gainfo.Factory)?.EnableOutsourceDown ?? true
|
||||
};
|
||||
|
||||
var codes = GetAssignDeviceCodesInternal(gainfoDto, gainfoGroupRelationships, devicePermissions, deviceGroups, deviceRelationships, registries, devices, departments);
|
||||
result.Add(gainfo.No, codes);
|
||||
return result.ToDictionary(x => x.Key, x => x.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
var result = new Dictionary<string, List<UserTenantDeviceCodeDto>>();
|
||||
foreach (var gainfo in gainfos)
|
||||
{
|
||||
var gainfoDto = new GainfoDto
|
||||
{
|
||||
Id = gainfo.Id,
|
||||
No = gainfo.No,
|
||||
Code = gainfo.Code,
|
||||
Name = gainfo.Name,
|
||||
Workplace = gainfo.Workplace,
|
||||
Factory = gainfo.Factory,
|
||||
DepartmentNo = gainfo.DepartmentNo,
|
||||
IsOutsource = gainfo.Type == GainfoUserTypeEnumType.Outsource,
|
||||
EnableFactoryPermission = enableFactoryPermissions.FirstOrDefault(x => x.TenantId == gainfo.Factory)?.EnableOutsourceDown ?? true
|
||||
};
|
||||
|
||||
return result;
|
||||
var codes = GetAssignDeviceCodesInternal(gainfoDto, gainfoGroupRelationships, devicePermissions, deviceGroups, deviceRelationships, registries, devices, departments);
|
||||
result.Add(gainfo.No, codes);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
_logger.LogWarning("权限获取时间:{ts}", sw.ElapsedMilliseconds);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user