perf: 优化人员同步权限和历史查询
This commit is contained in:
@@ -104,10 +104,36 @@ public class DevicePermissionAnalyzeService : IDevicePermissionAnalyzeService
|
||||
.ToListAsync();
|
||||
var gainfoGroups = await _dbContext.Queryable<GainfoGroupEntity>().ToListAsync();
|
||||
|
||||
var devicePermissions = await _dbContext.Queryable<DevicePermissionEntity>()
|
||||
.Where(x => x.IsDeleted == false)
|
||||
.Select<DevicePermissionDto>()
|
||||
.ToListAsync();
|
||||
var departments = await _dbContext.Queryable<DepartmentEntity>().Select<DepartmentDto>().ToListAsync();
|
||||
|
||||
var userAssignValues = gainfos
|
||||
.Select(x => x.No)
|
||||
.Distinct()
|
||||
.ToList();
|
||||
|
||||
var groupAssignValues = gainfoGroupRelationships
|
||||
.SelectMany(x => RecursionHelper.HandlerGainfoGroupPreviousCodes(x.GroupCode, gainfoGroups))
|
||||
.Select(x => x.ToString())
|
||||
.Distinct()
|
||||
.ToList();
|
||||
|
||||
var departmentAssignValues = gainfos
|
||||
.SelectMany(x => RecursionHelper.HandlerDepartmentPreviousCodes(x.DepartmentNo, departments)
|
||||
.Select(departmentNo => $"{x.Factory}:{departmentNo}"))
|
||||
.Distinct()
|
||||
.ToList();
|
||||
|
||||
var tenantAssignValues = gainfos
|
||||
.Select(x => x.Factory)
|
||||
.Where(x => x.IsPresent())
|
||||
.Distinct()
|
||||
.ToList();
|
||||
|
||||
var devicePermissions = new List<DevicePermissionDto>();
|
||||
devicePermissions.AddRange(await GetDevicePermissionsAsync(AssignTypeEnumType.User, userAssignValues));
|
||||
devicePermissions.AddRange(await GetDevicePermissionsAsync(AssignTypeEnumType.Group, groupAssignValues));
|
||||
devicePermissions.AddRange(await GetDevicePermissionsAsync(AssignTypeEnumType.Department, departmentAssignValues));
|
||||
devicePermissions.AddRange(await GetDevicePermissionsAsync(AssignTypeEnumType.Tenant, tenantAssignValues));
|
||||
|
||||
var deviceGroups = await _dbContext.Queryable<DeviceGroupEntity>()
|
||||
.Where(x => x.IsDeleted == false)
|
||||
@@ -115,7 +141,6 @@ public class DevicePermissionAnalyzeService : IDevicePermissionAnalyzeService
|
||||
var deviceRelationships = await _dbContext.Queryable<DeviceGroupRelationshipEntity>()
|
||||
.Where(x => x.IsDeleted == false)
|
||||
.ToListAsync();
|
||||
var departments = await _dbContext.Queryable<DepartmentEntity>().Select<DepartmentDto>().ToListAsync();
|
||||
|
||||
var result = new ConcurrentDictionary<string, List<TenantAssignTypeDeviceCode>>();
|
||||
|
||||
@@ -159,6 +184,25 @@ public class DevicePermissionAnalyzeService : IDevicePermissionAnalyzeService
|
||||
return result.ToDictionary(x => x.Key, x => x.Value);
|
||||
}
|
||||
|
||||
private async Task<List<DevicePermissionDto>> GetDevicePermissionsAsync(
|
||||
AssignTypeEnumType assignType,
|
||||
List<string> assignValues)
|
||||
{
|
||||
var result = new List<DevicePermissionDto>();
|
||||
foreach (var chunk in assignValues.Distinct().Chunk(1000))
|
||||
{
|
||||
var items = await _dbContext.Queryable<DevicePermissionEntity>()
|
||||
.Where(x => x.IsDeleted == false)
|
||||
.Where(x => x.AssignType == assignType)
|
||||
.Where(x => chunk.Contains(x.AssignValue))
|
||||
.Select<DevicePermissionDto>()
|
||||
.ToListAsync();
|
||||
result.AddRange(items);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
private static List<TenantAssignTypeDeviceCode> GetAssignDeviceCodesPermissions(
|
||||
AnalyzePackDto analyzePack,
|
||||
@@ -326,4 +370,4 @@ public class DevicePermissionAnalyzeService : IDevicePermissionAnalyzeService
|
||||
Factory = x.Factory
|
||||
}).ToListAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user