test ts
This commit is contained in:
@@ -10,5 +10,5 @@ public class UserTenantDeviceCodeDto
|
||||
/// <summary>
|
||||
/// 设备权限
|
||||
/// </summary>
|
||||
public List<Guid> Codes { get; set; }
|
||||
public IEnumerable<Guid> Codes { get; set; }
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Collections.Concurrent;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Dlhis.Basic.DataPermissions;
|
||||
using Dlhis.Basic.Device.Dtos;
|
||||
using Dlhis.Basic.Device.Request;
|
||||
@@ -581,8 +582,8 @@ public class DevicePermissionService : IDevicePermissionService
|
||||
|
||||
foreach (var tenant in tenants)
|
||||
{
|
||||
var currentCodes = currentTenantDeviceCodes.FirstOrDefault(x => x.Tenant == tenant)?.Codes ?? new List<Guid>();
|
||||
var beforeCodes = beforeTenantDeviceCodes.FirstOrDefault(x => x.Tenant == tenant)?.Codes ?? new List<Guid>();
|
||||
var currentCodes = currentTenantDeviceCodes.FirstOrDefault(x => x.Tenant == tenant)?.Codes?.ToList() ?? new List<Guid>();
|
||||
var beforeCodes = beforeTenantDeviceCodes.FirstOrDefault(x => x.Tenant == tenant)?.Codes?.ToList() ?? new List<Guid>();
|
||||
|
||||
//被删除
|
||||
var deletedItems = beforeCodes.Where(x => !currentCodes.Contains(x)).ToList();
|
||||
@@ -952,12 +953,12 @@ public class DevicePermissionService : IDevicePermissionService
|
||||
List<DevicePermissionEntity> devicePermissions, List<DeviceGroupEntity> deviceGroups, List<DepartmentEntity> departments,
|
||||
DeviceAssignmentTypeEnumType uniqueType, AssignTypeEnumType assignType, string assignValue)
|
||||
{
|
||||
var tenantDevicePermissions = devicePermissions
|
||||
.Where(x => x.UniqueType == uniqueType)
|
||||
.Where(x => x.AssignType == assignType)
|
||||
.Where(x => x.AssignValue == assignValue)
|
||||
var tenantDevicePermissions = devicePermissions.AsParallel()
|
||||
.Where(x => x.UniqueType == uniqueType
|
||||
&& x.AssignType == assignType
|
||||
&& x.AssignValue == assignValue)
|
||||
.GroupBy(x => x.TenantId)
|
||||
.Select(x => new UserTenantDeviceCodeDto { Tenant = x.Key, Codes = x.Select(p => p.UniqueValue).ToList() })
|
||||
.Select(x => new UserTenantDeviceCodeDto { Tenant = x.Key, Codes = x.Select(p => p.UniqueValue) })
|
||||
.ToList();
|
||||
|
||||
//处理获取设备分组的情况
|
||||
@@ -974,17 +975,17 @@ public class DevicePermissionService : IDevicePermissionService
|
||||
var arr = assignValue.Split(":");
|
||||
var tenantId = arr.First();
|
||||
var currentDepartmentNo = arr.Last();
|
||||
var departmentNos = new List<string> { currentDepartmentNo };
|
||||
var departmentNos = new List<string>(12) { currentDepartmentNo };
|
||||
DepartmentRecursionGetPNo(currentDepartmentNo, departments, departmentNos);
|
||||
|
||||
departmentNos = departmentNos.Select(x => tenantId + ":" + x).ToList();
|
||||
|
||||
tenantDevicePermissions = devicePermissions
|
||||
tenantDevicePermissions = devicePermissions.AsParallel()
|
||||
.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() })
|
||||
.Select(x => new UserTenantDeviceCodeDto { Tenant = x.Key, Codes = x.Select(p => p.UniqueValue) })
|
||||
.ToList();
|
||||
}
|
||||
|
||||
@@ -998,32 +999,37 @@ public class DevicePermissionService : IDevicePermissionService
|
||||
Codes = x.SelectMany(item => item.Codes).ToList()
|
||||
};
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
void DeviceGroupRecursionGetNext(DeviceGroupEntity current, List<DeviceGroupEntity> currentDeviceGroups, List<UserTenantDeviceCodeDto> result, bool add)
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
static void DepartmentRecursionGetPNo(string current, List<DepartmentEntity> data, List<string> result)
|
||||
{
|
||||
var p = data.FirstOrDefault(x => x.No == current)?.PNo;
|
||||
if (!p.IsPresent())
|
||||
{
|
||||
var next = currentDeviceGroups.Where(x => x.PCode == current.Code).ToList();
|
||||
foreach (var item in next)
|
||||
{
|
||||
if (add)
|
||||
{
|
||||
result.Add(new UserTenantDeviceCodeDto { Tenant = item.TenantId, Codes = new List<Guid> { item.Code } });
|
||||
}
|
||||
|
||||
DeviceGroupRecursionGetNext(item, currentDeviceGroups, result, result.SelectMany(x => x.Codes).Contains(item.Code));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void DepartmentRecursionGetPNo(string current, List<DepartmentEntity> data, List<string> result)
|
||||
result.Add(p);
|
||||
DepartmentRecursionGetPNo(p, data, result);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
static void DeviceGroupRecursionGetNext(DeviceGroupEntity current, List<DeviceGroupEntity> currentDeviceGroups, List<UserTenantDeviceCodeDto> result, bool add)
|
||||
{
|
||||
var next = currentDeviceGroups.Where(x => x.PCode == current.Code).ToList();
|
||||
foreach (var item in next)
|
||||
{
|
||||
var p = data.FirstOrDefault(x => x.No == current)?.PNo;
|
||||
if (p.IsPresent())
|
||||
if (add)
|
||||
{
|
||||
result.Add(p);
|
||||
DepartmentRecursionGetPNo(p, data, result);
|
||||
result.Add(new UserTenantDeviceCodeDto { Tenant = item.TenantId, Codes = new List<Guid> { item.Code } });
|
||||
}
|
||||
|
||||
DeviceGroupRecursionGetNext(item, currentDeviceGroups, result, result.SelectMany(x => x.Codes).Contains(item.Code));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private async Task<Dictionary<string, List<UserTenantDeviceCodeDto>>> GetAssignDeviceCodesInternalAsync(List<string> userNos)
|
||||
{
|
||||
var sw = Stopwatch.StartNew();
|
||||
@@ -1051,7 +1057,7 @@ public class DevicePermissionService : IDevicePermissionService
|
||||
|
||||
_logger.LogWarning("获取数据时间:{ts}", sw.ElapsedMilliseconds);
|
||||
sw.Restart();
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
if (_parallelService.Enable)
|
||||
|
||||
Reference in New Issue
Block a user