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)
|
||||
|
||||
Reference in New Issue
Block a user