fix 移除并发
This commit is contained in:
@@ -216,10 +216,15 @@ public class DevicePermissionService : IDevicePermissionService
|
||||
var current = await GetAssignDeviceCodesInternalAsync(userNos);
|
||||
|
||||
var devices = await _dbContext.Queryable<DeviceEntity>().Where(x => x.Enable).ToListAsync();
|
||||
var waitAddTasks = new ConcurrentBag<DeviceTaskEntity>();
|
||||
var waitDeleteTasks = new ConcurrentBag<DeviceTaskEntity>();
|
||||
// var waitAddTasks = new ConcurrentBag<DeviceTaskEntity>();
|
||||
// var waitDeleteTasks = new ConcurrentBag<DeviceTaskEntity>();
|
||||
|
||||
Parallel.ForEach(userNos, userNo =>
|
||||
var waitAddTasks = new List<DeviceTaskEntity>();
|
||||
var waitDeleteTasks = new List<DeviceTaskEntity>();
|
||||
|
||||
// Parallel.ForEach(userNos, userNo =>
|
||||
// {
|
||||
foreach (var userNo in userNos)
|
||||
{
|
||||
before.TryGetValue(userNo, out var beforeTenantDeviceCodes);
|
||||
beforeTenantDeviceCodes ??= new List<UserTenantDeviceCodeDto>();
|
||||
@@ -277,7 +282,8 @@ public class DevicePermissionService : IDevicePermissionService
|
||||
Source = DeviceTaskSourceEnumType.Manually
|
||||
}));
|
||||
}
|
||||
});
|
||||
}
|
||||
// });
|
||||
|
||||
if (waitAddTasks.Any())
|
||||
await ChunkInsertAsync(waitAddTasks.ToList());
|
||||
@@ -621,8 +627,30 @@ public class DevicePermissionService : IDevicePermissionService
|
||||
var deviceRelationships = await _dbContext.Queryable<DeviceGroupRelationshipEntity>().ToListAsync();
|
||||
var departments = await _dbContext.Queryable<DepartmentEntity>().ToListAsync();
|
||||
|
||||
var result = new ConcurrentDictionary<string, List<UserTenantDeviceCodeDto>>();
|
||||
Parallel.ForEach(gainfos, gainfo =>
|
||||
//var result = new ConcurrentDictionary<string, List<UserTenantDeviceCodeDto>>();
|
||||
|
||||
// Parallel.ForEach(gainfos, new ParallelOptions { MaxDegreeOfParallelism = 4 }, gainfo =>
|
||||
// {
|
||||
// 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);
|
||||
// });
|
||||
//
|
||||
// return result.ToDictionary(x => x.Key, x => x.Value);
|
||||
var result = new Dictionary<string, List<UserTenantDeviceCodeDto>>();
|
||||
foreach (var gainfo in gainfos)
|
||||
{
|
||||
var gainfoDto = new GainfoDto
|
||||
{
|
||||
@@ -638,12 +666,13 @@ public class DevicePermissionService : IDevicePermissionService
|
||||
};
|
||||
|
||||
var codes = GetAssignDeviceCodesInternal(gainfoDto, gainfoGroupRelationships, devicePermissions, deviceGroups, deviceRelationships, registries, devices, departments);
|
||||
result.TryAdd(gainfo.No, codes);
|
||||
});
|
||||
result.Add(gainfo.No, codes);
|
||||
}
|
||||
|
||||
return result.ToDictionary(x => x.Key, x => x.Value);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
private static List<UserTenantDeviceCodeDto> GetAssignDeviceCodesInternal(
|
||||
GainfoDto gainfo,
|
||||
List<GainfoGroupRelationshipEntity> gainfoGroupRelationships,
|
||||
|
||||
Reference in New Issue
Block a user