fix 简化代码
This commit is contained in:
@@ -187,7 +187,7 @@ public class DevicePermissionAnalyzeService : IDevicePermissionAnalyzeService
|
||||
var analyzePack = new AnalyzePackDto
|
||||
{
|
||||
UserNo = gainfo.No,
|
||||
UserDepartment = gainfo.Factory + ":" + gainfo.DepartmentNo,
|
||||
UserDepartment = gainfo.DepartmentNo,
|
||||
UserFactory = gainfo.Factory,
|
||||
UserGainfoGroupCodes = gainfoGroupRelationships.Where(x => x.UserNo == gainfo.No).Select(x => x.GroupCode),
|
||||
DeviceCodes = devices.WhereIf(gainfo.Type == GainfoUserTypeEnumType.Outsource, x => x.Type != DeviceTypeEnumType.Meal).Select(x => x.Code), //外包人员不允许餐饮
|
||||
@@ -228,26 +228,43 @@ public class DevicePermissionAnalyzeService : IDevicePermissionAnalyzeService
|
||||
continue;
|
||||
}
|
||||
|
||||
if (assignType == AssignTypeEnumType.Group)
|
||||
{
|
||||
var tempUserGroupCodes = analyzePack.UserGainfoGroupCodes.ToList();
|
||||
foreach (Guid analyzePackUserGainfoGroupCode in analyzePack.UserGainfoGroupCodes)
|
||||
{
|
||||
tempUserGroupCodes.AddRange(RecursionHelper.HandlerGainfoGroupPreviousCodes(analyzePackUserGainfoGroupCode, gainfoGroups));
|
||||
}
|
||||
|
||||
analyzePack.UserGainfoGroupCodes = tempUserGroupCodes.Distinct().ToList();
|
||||
}
|
||||
|
||||
var assignValues = assignType switch
|
||||
{
|
||||
AssignTypeEnumType.User => new[] { analyzePack.UserNo },
|
||||
AssignTypeEnumType.Group => analyzePack.UserGainfoGroupCodes.Select(x => x.ToString()).ToArray(),
|
||||
AssignTypeEnumType.Department => new[] { analyzePack.UserDepartment },
|
||||
AssignTypeEnumType.Tenant => new[] { analyzePack.UserFactory },
|
||||
AssignTypeEnumType.User => new List<string> { analyzePack.UserNo },
|
||||
AssignTypeEnumType.Group => analyzePack.UserGainfoGroupCodes.Select(x => x.ToString()),
|
||||
AssignTypeEnumType.Department => RecursionHelper.HandlerDepartmentPreviousCodes(analyzePack.UserDepartment, departments).Select(x => analyzePack.UserFactory + ":" + x).ToList(),
|
||||
AssignTypeEnumType.Tenant => new List<string> { analyzePack.UserFactory },
|
||||
AssignTypeEnumType.Role => throw new ArgumentOutOfRangeException(),
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
};
|
||||
|
||||
|
||||
var data = assignValues.SelectMany(x => uniqueTypes.Select(p => new { assignValue = x, uniqueType = p })).ToList();
|
||||
var needRemove = data.Where(x => x.assignValue == analyzePack.IgnoreAssignValue && x.uniqueType == analyzePack.IgnoreUniqueType);
|
||||
data = data.ExceptBy(needRemove, x => new { x.assignValue, x.uniqueType }).ToList();
|
||||
|
||||
foreach (var item in data)
|
||||
foreach (var dataPack in data.GroupBy(x => x.uniqueType))
|
||||
{
|
||||
deviceDtos.AddRange(GetCurrentAssignTypePermissions(devicePermissions, gainfoGroups, departments,
|
||||
deviceGroups, deviceGroupRelationships,
|
||||
item.uniqueType, assignType, item.assignValue));
|
||||
var currentUniqueType = dataPack.Key;
|
||||
var currentAssignValues = dataPack.Select(x => x.assignValue).ToList();
|
||||
|
||||
deviceDtos.AddRange(
|
||||
SearchActualAssignPermissions(
|
||||
devicePermissions,
|
||||
deviceGroups, deviceGroupRelationships,
|
||||
currentUniqueType, assignType, currentAssignValues
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -272,35 +289,14 @@ public class DevicePermissionAnalyzeService : IDevicePermissionAnalyzeService
|
||||
});
|
||||
}
|
||||
|
||||
private static List<TenantAssignTypeDeviceCode> GetCurrentAssignTypePermissions(
|
||||
private static List<TenantAssignTypeDeviceCode> SearchActualAssignPermissions(
|
||||
List<DevicePermissionDto> devicePermissions,
|
||||
List<GainfoGroupEntity> gainfoGroups,
|
||||
List<DepartmentEntity> departments,
|
||||
List<DeviceGroupEntity> deviceGroups,
|
||||
List<DeviceGroupRelationshipEntity> deviceGroupRelationships,
|
||||
DeviceAssignmentTypeEnumType uniqueType,
|
||||
AssignTypeEnumType assignType,
|
||||
string assignValue)
|
||||
List<string> assignValues)
|
||||
{
|
||||
var assignValues = new List<string> { assignValue };
|
||||
|
||||
if (assignType == AssignTypeEnumType.Department)
|
||||
{
|
||||
// 2401:00001
|
||||
//递归向上获取 assignValue = department.No
|
||||
var arr = assignValue.Split(":");
|
||||
var tenantId = arr[0];
|
||||
var currentDepartmentNo = arr[1];
|
||||
|
||||
assignValues = RecursionHelper.HandlerDepartmentPreviousCodes(currentDepartmentNo, departments).Select(x => tenantId + ":" + x).ToList();
|
||||
}
|
||||
|
||||
if (assignType == AssignTypeEnumType.Group)
|
||||
{
|
||||
assignValues = RecursionHelper.HandlerGainfoGroupPreviousCodes(Guid.Parse(assignValue), gainfoGroups).Select(x => x.ToString()).ToList();
|
||||
}
|
||||
|
||||
|
||||
var r = devicePermissions
|
||||
.Where(x => x.UniqueType == uniqueType)
|
||||
.Where(x => x.AssignType == assignType)
|
||||
|
||||
@@ -127,39 +127,6 @@ public class DevicePermissionService : IDevicePermissionService
|
||||
Priority = 0,
|
||||
TenantId = currentTenantId
|
||||
}).ToList());
|
||||
|
||||
// await GenerateDeviceTasksAsync(async () =>
|
||||
// {
|
||||
// await _dbContext.DeleteAsync(p);
|
||||
//
|
||||
// //保存配置的权限
|
||||
// if (request.Values.IsPresent())
|
||||
// {
|
||||
// var nos = await _dbContext.Client.Queryable<GainfoEntity>()
|
||||
// .Where(gainfo => factories.Contains(gainfo.Factory) || SqlFunc.Subqueryable<BusinessTripEntity>()
|
||||
// .Where(x => factories.Contains(x.Destination) && SqlFunc.DateIsSame(x.BeginDate, today))
|
||||
// .Any()
|
||||
// )
|
||||
// .Where(gainfo => request.Values.Contains(gainfo.Code) || request.Values.Contains(gainfo.No) || request.Values.Contains(gainfo.IdNo))
|
||||
// .Select(gainfo => gainfo.No)
|
||||
// .ToListAsync();
|
||||
//
|
||||
// //todo 临时注释
|
||||
// //(gainfoNos.Count != request.Values.Count).ThrowIfTrue("存在非当前权限访问的人员,操作禁止!");
|
||||
//
|
||||
// var devicePermissions = nos.Select(v => new DevicePermissionEntity
|
||||
// {
|
||||
// UniqueType = request.UniqueType,
|
||||
// UniqueValue = request.UniqueValue,
|
||||
// AssignType = request.AssignType,
|
||||
// AssignValue = v,
|
||||
// TenantId = currentTenantId,
|
||||
// Type = request.Type
|
||||
// }).ToList();
|
||||
//
|
||||
// await _dbContext.InsertAsync(devicePermissions);
|
||||
// }
|
||||
// }, gainfoNos);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -4,6 +4,13 @@ public static class ParallelExtensions
|
||||
{
|
||||
public static void ParallelForEach<T>(this IEnumerable<T> source, Action<T> action)
|
||||
{
|
||||
#if DEBUG
|
||||
foreach (var item in source)
|
||||
{
|
||||
action.Invoke(item);
|
||||
}
|
||||
#else
|
||||
Parallel.ForEach(source, new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount }, action);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user