fix 逻辑调整
This commit is contained in:
@@ -132,7 +132,10 @@ public class DevicePermissionAnalyzeService : IDevicePermissionAnalyzeService
|
||||
}
|
||||
|
||||
|
||||
public async Task<Dictionary<string, IEnumerable<TenantAssignTypeDeviceCode>>> GetUserAssignDeviceCodesWithTypeInTenantAsync(List<string> userNos, params AssignTypeEnumType[] ignoreAssignTypes)
|
||||
public async Task<Dictionary<string, IEnumerable<TenantAssignTypeDeviceCode>>> GetUserAssignDeviceCodesWithTypeInTenantAsync(
|
||||
List<string> userNos,
|
||||
string ignoreAssignValue = null,
|
||||
params AssignTypeEnumType[] ignoreAssignTypes)
|
||||
{
|
||||
var gainfos = await _dbContext.Queryable<GainfoEntity>().Where(x => userNos.Contains(x.No)).ToListAsync();
|
||||
if (!gainfos.Any()) return new Dictionary<string, IEnumerable<TenantAssignTypeDeviceCode>>();
|
||||
@@ -144,7 +147,10 @@ public class DevicePermissionAnalyzeService : IDevicePermissionAnalyzeService
|
||||
var gainfoGroupRelationships = await _dbContext.Queryable<GainfoGroupRelationshipEntity>().Where(x => userNos.Contains(x.UserNo)).ToListAsync();
|
||||
var gainfoGroups = await _dbContext.Queryable<GainfoGroupEntity>().ToListAsync();
|
||||
|
||||
var devicePermissions = await _dbContext.Queryable<DevicePermissionEntity>().WhereIF(ignoreAssignTypes.IsPresent(), x => !ignoreAssignTypes.Contains(x.AssignType)).ToListAsync();
|
||||
var devicePermissions = await _dbContext.Queryable<DevicePermissionEntity>()
|
||||
.WhereIF(ignoreAssignTypes.IsPresent(), x => !ignoreAssignTypes.Contains(x.AssignType) && x.AssignValue != ignoreAssignValue)
|
||||
.Select<DevicePermissionDto>()
|
||||
.ToListAsync();
|
||||
var deviceGroups = await _dbContext.Queryable<DeviceGroupEntity>().ToListAsync();
|
||||
var deviceRelationships = await _dbContext.Queryable<DeviceGroupRelationshipEntity>().ToListAsync();
|
||||
var departments = await _dbContext.Queryable<DepartmentEntity>().ToListAsync();
|
||||
@@ -167,6 +173,7 @@ public class DevicePermissionAnalyzeService : IDevicePermissionAnalyzeService
|
||||
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), //外包人员不允许餐饮
|
||||
IgnoreAssignValue = ignoreAssignValue,
|
||||
IgnoreAssignTypeTypes = internalIgnoreAssignTypes
|
||||
};
|
||||
|
||||
@@ -187,13 +194,12 @@ public class DevicePermissionAnalyzeService : IDevicePermissionAnalyzeService
|
||||
private static IEnumerable<TenantAssignTypeDeviceCode> GetAssignDeviceCodesInternal(
|
||||
AnalyzePackDto analyzePack,
|
||||
List<GainfoGroupEntity> gainfoGroups,
|
||||
List<DevicePermissionEntity> devicePermissions,
|
||||
List<DevicePermissionDto> devicePermissions,
|
||||
List<DeviceGroupEntity> deviceGroups,
|
||||
List<DeviceGroupRelationshipEntity> deviceGroupRelationships,
|
||||
List<DepartmentEntity> departments)
|
||||
{
|
||||
var deviceDtos = new List<TenantAssignTypeDeviceCode>();
|
||||
var deviceGroupDtos = new List<TenantAssignTypeDeviceCode>();
|
||||
|
||||
foreach (var assignType in new[] { AssignTypeEnumType.User, AssignTypeEnumType.Group, AssignTypeEnumType.Department, AssignTypeEnumType.Tenant })
|
||||
{
|
||||
@@ -207,40 +213,32 @@ public class DevicePermissionAnalyzeService : IDevicePermissionAnalyzeService
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
};
|
||||
|
||||
if (analyzePack.IgnoreAssignTypeTypes.Contains(assignType))
|
||||
foreach (var assignValue in assignValues.WhereIf(analyzePack.IgnoreAssignTypeTypes.Contains(assignType), x => x != analyzePack.IgnoreAssignValue))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach (var assignValue in assignValues)
|
||||
{
|
||||
deviceDtos.AddRange(GetMyTypeDevicePermissionAsync(devicePermissions, gainfoGroups, deviceGroups, departments,
|
||||
deviceDtos.AddRange(GetCurrentAssignTypePermissions(devicePermissions, gainfoGroups, departments,
|
||||
DeviceAssignmentTypeEnumType.Device, assignType, assignValue));
|
||||
deviceGroupDtos.AddRange(GetMyTypeDevicePermissionAsync(devicePermissions, gainfoGroups, deviceGroups, departments,
|
||||
DeviceAssignmentTypeEnumType.Group, assignType, assignValue));
|
||||
}
|
||||
}
|
||||
|
||||
//设备组转设备
|
||||
deviceDtos.AddRange(deviceGroupDtos.Select(x =>
|
||||
{
|
||||
var tenant = x.Tenant;
|
||||
var groupItems = GetCurrentAssignTypePermissions(devicePermissions, gainfoGroups, departments,
|
||||
DeviceAssignmentTypeEnumType.Group, assignType, assignValue);
|
||||
|
||||
var deviceGroupCodes = x.AssignTypes.SelectMany(item => item.Codes);
|
||||
var type = x.AssignTypes.ElementAt(0).AssignType;
|
||||
return new TenantAssignTypeDeviceCode
|
||||
{
|
||||
Tenant = tenant,
|
||||
AssignTypes = new[]
|
||||
foreach (var groupItem in groupItems)
|
||||
{
|
||||
new AssignTypeDeviceCode
|
||||
foreach (var assignTypeDeviceCodeItem in groupItem.AssignTypes)
|
||||
{
|
||||
AssignType = type,
|
||||
Codes = deviceGroupRelationships.Where(item => deviceGroupCodes.Contains(item.GroupCode)).Select(item => item.DeviceCode)
|
||||
var r = new List<Guid>();
|
||||
foreach (var code in assignTypeDeviceCodeItem.Codes)
|
||||
{
|
||||
r.AddRange(RecursionHelper.HandlerDeviceGroupNextCodes(code, deviceGroups));
|
||||
}
|
||||
|
||||
assignTypeDeviceCodeItem.OriginalCodes = r;
|
||||
assignTypeDeviceCodeItem.Codes = deviceGroupRelationships.Where(x => r.Contains(x.GroupCode)).Select(x => x.DeviceCode);
|
||||
}
|
||||
}
|
||||
};
|
||||
}));
|
||||
|
||||
deviceDtos.AddRange(groupItems);
|
||||
}
|
||||
}
|
||||
|
||||
return deviceDtos.GroupBy(x => x.Tenant).Select(x =>
|
||||
{
|
||||
@@ -248,11 +246,14 @@ public class DevicePermissionAnalyzeService : IDevicePermissionAnalyzeService
|
||||
{
|
||||
Tenant = x.Key,
|
||||
AssignTypes = x.SelectMany(p => p.AssignTypes)
|
||||
.GroupBy(p => p.AssignType)
|
||||
.GroupBy(p => new { p.AssignType, p.AssignValue, p.UniqueType })
|
||||
.Select(p => new AssignTypeDeviceCode
|
||||
{
|
||||
AssignType = p.Key,
|
||||
Codes = p.SelectMany(item => analyzePack.DeviceCodes.Where(it => item.Codes.Contains(it)))
|
||||
AssignType = p.Key.AssignType,
|
||||
AssignValue = p.Key.AssignValue,
|
||||
UniqueType = p.Key.UniqueType,
|
||||
Codes = p.SelectMany(xx => xx.Codes),
|
||||
OriginalCodes = p.Where(xx => xx.OriginalCodes.IsPresent()).SelectMany(xx => xx.OriginalCodes)
|
||||
})
|
||||
};
|
||||
|
||||
@@ -260,14 +261,16 @@ public class DevicePermissionAnalyzeService : IDevicePermissionAnalyzeService
|
||||
});
|
||||
}
|
||||
|
||||
private static List<UserTenantDeviceCodeDto> GetCurrentAssignTypePermissions(
|
||||
List<DevicePermissionEntity> devicePermissions,
|
||||
private static List<TenantAssignTypeDeviceCode> GetCurrentAssignTypePermissions(
|
||||
List<DevicePermissionDto> devicePermissions,
|
||||
List<GainfoGroupEntity> gainfoGroups,
|
||||
List<DepartmentEntity> departments,
|
||||
DeviceAssignmentTypeEnumType uniqueType,
|
||||
AssignTypeEnumType assignType,
|
||||
string assignValue)
|
||||
{
|
||||
var assignValues = new List<string> { assignValue };
|
||||
|
||||
if (assignType == AssignTypeEnumType.Department)
|
||||
{
|
||||
// 2401:00001
|
||||
@@ -276,86 +279,33 @@ public class DevicePermissionAnalyzeService : IDevicePermissionAnalyzeService
|
||||
var tenantId = arr[0];
|
||||
var currentDepartmentNo = arr[1];
|
||||
|
||||
var departmentNos = RecursionHelper.HandlerDepartmentPreviousCodes(currentDepartmentNo, departments).Select(x => tenantId + ":" + x).ToList();
|
||||
|
||||
return devicePermissions
|
||||
.Where(x => x.UniqueType == uniqueType)
|
||||
.Where(x => x.AssignType == assignType)
|
||||
.Where(x => departmentNos.Contains(x.AssignValue))
|
||||
.GroupBy(x => x.TenantId)
|
||||
.Select(x => new UserTenantDeviceCodeDto { Tenant = x.Key, Codes = x.Select(p => p.UniqueValue) })
|
||||
.ToList();
|
||||
assignValues = RecursionHelper.HandlerDepartmentPreviousCodes(currentDepartmentNo, departments).Select(x => tenantId + ":" + x).ToList();
|
||||
}
|
||||
|
||||
if (assignType == AssignTypeEnumType.Group)
|
||||
{
|
||||
var gainfoGroupCodes = RecursionHelper.HandlerGainfoGroupPreviousCodes(Guid.Parse(assignValue), gainfoGroups).Select(x => x.ToString());
|
||||
return devicePermissions
|
||||
.Where(x => x.UniqueType == uniqueType)
|
||||
.Where(x => x.AssignType == assignType)
|
||||
.Where(x => gainfoGroupCodes.Contains(x.AssignValue))
|
||||
.GroupBy(x => x.TenantId)
|
||||
.Select(x => new UserTenantDeviceCodeDto { Tenant = x.Key, Codes = x.Select(p => p.UniqueValue) })
|
||||
.ToList();
|
||||
assignValues = RecursionHelper.HandlerGainfoGroupPreviousCodes(Guid.Parse(assignValue), gainfoGroups).Select(x => x.ToString()).ToList();
|
||||
}
|
||||
|
||||
//user / tenant
|
||||
return devicePermissions
|
||||
.Where(x => x.UniqueType == uniqueType
|
||||
&& x.AssignType == assignType
|
||||
&& x.AssignValue == assignValue)
|
||||
.Where(x => x.UniqueType == uniqueType)
|
||||
.Where(x => x.AssignType == assignType)
|
||||
.Where(x => assignValues.Contains(x.AssignValue))
|
||||
.GroupBy(x => x.TenantId)
|
||||
.Select(x => new UserTenantDeviceCodeDto { Tenant = x.Key, Codes = x.Select(p => p.UniqueValue) })
|
||||
.Select(x => new TenantAssignTypeDeviceCode
|
||||
{
|
||||
Tenant = x.Key,
|
||||
AssignTypes = x.GroupBy(xx => new { xx.AssignType, xx.AssignValue }).Select(xx => new AssignTypeDeviceCode
|
||||
{
|
||||
AssignType = xx.Key.AssignType,
|
||||
AssignValue = xx.Key.AssignValue,
|
||||
UniqueType = uniqueType,
|
||||
Codes = xx.Select(xxx => xxx.UniqueValue)
|
||||
})
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
|
||||
private static IEnumerable<TenantAssignTypeDeviceCode> GetMyTypeDevicePermissionAsync(
|
||||
List<DevicePermissionEntity> devicePermissions,
|
||||
List<GainfoGroupEntity> gainfoGroups,
|
||||
List<DeviceGroupEntity> deviceGroups,
|
||||
List<DepartmentEntity> departments,
|
||||
DeviceAssignmentTypeEnumType uniqueType, AssignTypeEnumType assignType, string assignValue)
|
||||
{
|
||||
var tenantDevicePermissions = GetCurrentAssignTypePermissions(devicePermissions, gainfoGroups, departments, uniqueType, assignType, assignValue);
|
||||
|
||||
//处理获取设备分组的情况,递归向下查询子分组
|
||||
if (uniqueType == DeviceAssignmentTypeEnumType.Group)
|
||||
{
|
||||
foreach (var tenantDevicePermission in tenantDevicePermissions)
|
||||
{
|
||||
var deviceGroupCodes = tenantDevicePermission.Codes;
|
||||
var r = tenantDevicePermission.Codes.ToList();
|
||||
|
||||
foreach (var deviceGroupCode in deviceGroupCodes)
|
||||
{
|
||||
r.AddRange(RecursionHelper.HandlerDeviceGroupNextCodes(deviceGroupCode, deviceGroups));
|
||||
}
|
||||
|
||||
tenantDevicePermission.Codes = r.Distinct().ToList();
|
||||
}
|
||||
}
|
||||
|
||||
return tenantDevicePermissions.GroupBy(x => x.Tenant).Select(x =>
|
||||
{
|
||||
var tenant = x.Key;
|
||||
|
||||
return new TenantAssignTypeDeviceCode
|
||||
{
|
||||
Tenant = tenant,
|
||||
AssignTypes = new[]
|
||||
{
|
||||
new AssignTypeDeviceCode
|
||||
{
|
||||
AssignType = assignType,
|
||||
Codes = x.SelectMany(item => item.Codes)
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private async Task ChunkInsertAsync<T>(List<T> batch) where T : class, new()
|
||||
{
|
||||
foreach (var tasks in batch.Chunk(500))
|
||||
@@ -365,9 +315,9 @@ public class DevicePermissionAnalyzeService : IDevicePermissionAnalyzeService
|
||||
}
|
||||
|
||||
|
||||
public async Task<Dictionary<string, IEnumerable<UserTenantDeviceCodeDto>>> GetUserAssignDeviceCodesInTenantAsync(List<string> userNos, params AssignTypeEnumType[] ignoreAssignTypes)
|
||||
public async Task<Dictionary<string, IEnumerable<UserTenantDeviceCodeDto>>> GetUserAssignDeviceCodesInTenantAsync(List<string> userNos, string ignoreAssignValue = null, params AssignTypeEnumType[] ignoreAssignTypes)
|
||||
{
|
||||
var result = await GetUserAssignDeviceCodesWithTypeInTenantAsync(userNos, ignoreAssignTypes);
|
||||
var result = await GetUserAssignDeviceCodesWithTypeInTenantAsync(userNos, ignoreAssignValue, ignoreAssignTypes);
|
||||
|
||||
return result.ToDictionary(x => x.Key, x => x.Value.GroupBy(p => p.Tenant).Select(item =>
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user