fix 优化任务生成
This commit is contained in:
@@ -9,6 +9,7 @@ using Dlhis.Entity.Sys.Enums;
|
|||||||
using Kurisu.AspNetCore.Utils.Extensions;
|
using Kurisu.AspNetCore.Utils.Extensions;
|
||||||
using Kurisu.Core.DataAccess.Dto;
|
using Kurisu.Core.DataAccess.Dto;
|
||||||
using Kurisu.Core.DataAccess.Entity;
|
using Kurisu.Core.DataAccess.Entity;
|
||||||
|
using Kurisu.Core.User.Abstractions;
|
||||||
using Kurisu.SqlSugar.Services;
|
using Kurisu.SqlSugar.Services;
|
||||||
|
|
||||||
namespace Dlhis.Basic.Device.Services.Implements;
|
namespace Dlhis.Basic.Device.Services.Implements;
|
||||||
@@ -16,10 +17,12 @@ namespace Dlhis.Basic.Device.Services.Implements;
|
|||||||
public class DevicePermissionService : IDevicePermissionService
|
public class DevicePermissionService : IDevicePermissionService
|
||||||
{
|
{
|
||||||
private readonly IDbContext _dbContext;
|
private readonly IDbContext _dbContext;
|
||||||
|
private readonly ICurrentUser _currentUser;
|
||||||
|
|
||||||
public DevicePermissionService(IDbContext dbContext)
|
public DevicePermissionService(IDbContext dbContext, ICurrentUser currentUser)
|
||||||
{
|
{
|
||||||
_dbContext = dbContext;
|
_dbContext = dbContext;
|
||||||
|
_currentUser = currentUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task AssignAsync(DevicePermissionSaveReuqest reuqest)
|
public async Task AssignAsync(DevicePermissionSaveReuqest reuqest)
|
||||||
@@ -58,7 +61,8 @@ public class DevicePermissionService : IDevicePermissionService
|
|||||||
var devicePermissions = await _dbContext.Queryable<DevicePermissionEntity>().ToListAsync();
|
var devicePermissions = await _dbContext.Queryable<DevicePermissionEntity>().ToListAsync();
|
||||||
var deviceGroups = await _dbContext.Queryable<DeviceGroupEntity>().ToListAsync();
|
var deviceGroups = await _dbContext.Queryable<DeviceGroupEntity>().ToListAsync();
|
||||||
|
|
||||||
return GetAssignmentsInternal(devicePermissions, deviceGroups, uniqueType, assignType, assignValue);
|
var result = GetAssignCodesInternal(devicePermissions, deviceGroups, uniqueType, assignType, assignValue);
|
||||||
|
return result.FirstOrDefault(x => x.Tenant == _currentUser.GetStringTenantId())?.Codes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -72,7 +76,7 @@ public class DevicePermissionService : IDevicePermissionService
|
|||||||
userNos = await GetPermissionUserNosAsync();
|
userNos = await GetPermissionUserNosAsync();
|
||||||
|
|
||||||
//var before = await GetAssignDeviceCodesInternalAsync(userNos);
|
//var before = await GetAssignDeviceCodesInternalAsync(userNos);
|
||||||
var before = await GetAssignDeviceCodesInternal1Async(userNos);
|
var before = await GetAssignDeviceCodesInternalAsync(userNos);
|
||||||
|
|
||||||
_dbContext.Client.QueryFilter.Restore();
|
_dbContext.Client.QueryFilter.Restore();
|
||||||
//业务处理
|
//业务处理
|
||||||
@@ -85,7 +89,7 @@ public class DevicePermissionService : IDevicePermissionService
|
|||||||
userNos = userNos.Concat(nextUserNos).Distinct().ToList();
|
userNos = userNos.Concat(nextUserNos).Distinct().ToList();
|
||||||
|
|
||||||
//var current = await GetAssignDeviceCodesInternalAsync(userNos);
|
//var current = await GetAssignDeviceCodesInternalAsync(userNos);
|
||||||
var current = await GetAssignDeviceCodesInternal1Async(userNos);
|
var current = await GetAssignDeviceCodesInternalAsync(userNos);
|
||||||
|
|
||||||
var deivces = await _dbContext.Queryable<DeviceEntity>().ToListAsync();
|
var deivces = await _dbContext.Queryable<DeviceEntity>().ToListAsync();
|
||||||
var waitTasks = new List<DeviceTaskEntity>();
|
var waitTasks = new List<DeviceTaskEntity>();
|
||||||
@@ -98,10 +102,12 @@ public class DevicePermissionService : IDevicePermissionService
|
|||||||
current.TryGetValue(userNo, out var currentTenantDeviceCodes);
|
current.TryGetValue(userNo, out var currentTenantDeviceCodes);
|
||||||
currentTenantDeviceCodes ??= new();
|
currentTenantDeviceCodes ??= new();
|
||||||
|
|
||||||
foreach (var item in currentTenantDeviceCodes)
|
var tenants = beforeTenantDeviceCodes.Select(x => x.Tenant).Concat(currentTenantDeviceCodes.Select(x => x.Tenant)).Distinct().ToList();
|
||||||
|
|
||||||
|
foreach (var tenant in tenants)
|
||||||
{
|
{
|
||||||
var currentCodes = item.Codes;
|
var currentCodes = currentTenantDeviceCodes.FirstOrDefault(x => x.Tenant == tenant)?.Codes ?? new();
|
||||||
var beforeCodes = beforeTenantDeviceCodes.FirstOrDefault(x => x.Tenant == item.Tenant)?.Codes ?? new();
|
var beforeCodes = beforeTenantDeviceCodes.FirstOrDefault(x => x.Tenant == tenant)?.Codes ?? new();
|
||||||
|
|
||||||
//被删除
|
//被删除
|
||||||
var deletedItems = beforeCodes.Where(x => !currentCodes.Contains(x)).ToList();
|
var deletedItems = beforeCodes.Where(x => !currentCodes.Contains(x)).ToList();
|
||||||
@@ -125,7 +131,7 @@ public class DevicePermissionService : IDevicePermissionService
|
|||||||
Type = DeviceTaskEnumType.Delete,
|
Type = DeviceTaskEnumType.Delete,
|
||||||
UserNo = userNo,
|
UserNo = userNo,
|
||||||
Version = 0,
|
Version = 0,
|
||||||
TenantId = item.Tenant,
|
TenantId = tenant,
|
||||||
}).ToList();
|
}).ToList();
|
||||||
|
|
||||||
var toAdd = addItems.Select(x => new DeviceTaskEntity
|
var toAdd = addItems.Select(x => new DeviceTaskEntity
|
||||||
@@ -135,14 +141,13 @@ public class DevicePermissionService : IDevicePermissionService
|
|||||||
Type = DeviceTaskEnumType.Add,
|
Type = DeviceTaskEnumType.Add,
|
||||||
UserNo = userNo,
|
UserNo = userNo,
|
||||||
Version = 0,
|
Version = 0,
|
||||||
TenantId = item.Tenant,
|
TenantId = tenant,
|
||||||
}).ToList();
|
}).ToList();
|
||||||
|
|
||||||
waitTasks.AddRange(toDeleted.Concat(toAdd).ToList());
|
waitTasks.AddRange(toDeleted.Concat(toAdd).ToList());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (waitTasks.Any())
|
if (waitTasks.Any())
|
||||||
{
|
{
|
||||||
await _dbContext.InsertAsync(waitTasks);
|
await _dbContext.InsertAsync(waitTasks);
|
||||||
@@ -212,108 +217,10 @@ public class DevicePermissionService : IDevicePermissionService
|
|||||||
var deviceGroups = await _dbContext.Queryable<DeviceGroupEntity>().ToListAsync();
|
var deviceGroups = await _dbContext.Queryable<DeviceGroupEntity>().ToListAsync();
|
||||||
var deviceRelationships = await _dbContext.Queryable<DeviceGroupRelationshipEntity>().ToListAsync();
|
var deviceRelationships = await _dbContext.Queryable<DeviceGroupRelationshipEntity>().ToListAsync();
|
||||||
|
|
||||||
return GetAssignDeviceCodesInternal(new List<GainfoEntity> { gainfo }, gainfoGroups, devicePermissions, deviceGroups, deviceRelationships, userNo);
|
var result = GetAssignDeviceCodesInternal(gainfo, gainfoGroups, devicePermissions, deviceGroups, deviceRelationships);
|
||||||
|
return result.SelectMany(x => x.Codes).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Guid> GetAssignDeviceCodesInternal(List<GainfoEntity> gainfos,
|
|
||||||
List<GainfoGroupRelationshipEntity> gainfoGroupRelationships,
|
|
||||||
List<DevicePermissionEntity> devicePermissions,
|
|
||||||
List<DeviceGroupEntity> deviceGroups,
|
|
||||||
List<DeviceGroupRelationshipEntity> deviceGroupRelationships,
|
|
||||||
string userNo)
|
|
||||||
{
|
|
||||||
var deviceCodes = new List<Guid>();
|
|
||||||
var deviceGroupCodes = new List<Guid>();
|
|
||||||
|
|
||||||
var gainfo = gainfos.Where(x => x.No == userNo).FirstOrDefault();
|
|
||||||
var gainfoGroups = gainfoGroupRelationships.Where(x => x.UserNo == userNo).Select(x => x.GroupCode).ToList();
|
|
||||||
|
|
||||||
var du = GetAssignmentsInternal(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Device, AssignTypeEnumType.User, userNo);
|
|
||||||
var gu = GetAssignmentsInternal(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Group, AssignTypeEnumType.User, userNo);
|
|
||||||
deviceCodes.AddRange(du);
|
|
||||||
deviceGroupCodes.AddRange(gu);
|
|
||||||
|
|
||||||
foreach (var group in gainfoGroups)
|
|
||||||
{
|
|
||||||
var dg = GetAssignmentsInternal(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Device, AssignTypeEnumType.Group, group.ToString());
|
|
||||||
var gg = GetAssignmentsInternal(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Group, AssignTypeEnumType.Group, group.ToString());
|
|
||||||
deviceCodes.AddRange(dg);
|
|
||||||
deviceGroupCodes.AddRange(gg);
|
|
||||||
}
|
|
||||||
|
|
||||||
var dd = GetAssignmentsInternal(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Device, AssignTypeEnumType.Department, gainfo.DepartmentNo);
|
|
||||||
var gd = GetAssignmentsInternal(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Group, AssignTypeEnumType.Department, gainfo.DepartmentNo);
|
|
||||||
deviceCodes.AddRange(dd);
|
|
||||||
deviceGroupCodes.AddRange(gd);
|
|
||||||
|
|
||||||
var dt = GetAssignmentsInternal(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Device, AssignTypeEnumType.Tenant, gainfo.Werks);
|
|
||||||
var gt = GetAssignmentsInternal(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Group, AssignTypeEnumType.Tenant, gainfo.Werks);
|
|
||||||
deviceCodes.AddRange(du);
|
|
||||||
deviceGroupCodes.AddRange(gu);
|
|
||||||
|
|
||||||
var deveiceCodesByGroup = deviceGroupRelationships.Where(x => deviceGroupCodes.Contains(x.GroupCode)).Select(x => x.DeviceCode).ToList();
|
|
||||||
deviceCodes.AddRange(deveiceCodesByGroup);
|
|
||||||
|
|
||||||
return deviceCodes.Distinct().ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<UserTenantDeviceCodeDto> GetAssignDeviceCodesInternal1(GainfoEntity gainfo,
|
|
||||||
List<GainfoGroupRelationshipEntity> gainfoGroupRelationships,
|
|
||||||
List<DevicePermissionEntity> devicePermissions,
|
|
||||||
List<DeviceGroupEntity> deviceGroups,
|
|
||||||
List<DeviceGroupRelationshipEntity> deviceGroupRelationships)
|
|
||||||
{
|
|
||||||
var userNo = gainfo.No;
|
|
||||||
var deviceCodes = new List<UserTenantDeviceCodeDto>();
|
|
||||||
var deviceGroupCodes = new List<UserTenantDeviceCodeDto>();
|
|
||||||
|
|
||||||
//获取人员的分组,跨基地
|
|
||||||
var gainfoGroups = gainfoGroupRelationships.Where(x => x.UserNo == userNo).Select(x => x.GroupCode).ToList();
|
|
||||||
|
|
||||||
//按User获取权限
|
|
||||||
var du = GetAssignCodesInternal1(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Device, AssignTypeEnumType.User, userNo);
|
|
||||||
var gu = GetAssignCodesInternal1(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Group, AssignTypeEnumType.User, userNo);
|
|
||||||
deviceCodes.AddRange(du);
|
|
||||||
deviceGroupCodes.AddRange(gu);
|
|
||||||
|
|
||||||
foreach (var groupCode in gainfoGroups)
|
|
||||||
{
|
|
||||||
var dg = GetAssignCodesInternal1(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Device, AssignTypeEnumType.Group, groupCode.ToString());
|
|
||||||
var gg = GetAssignCodesInternal1(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Group, AssignTypeEnumType.Group, groupCode.ToString());
|
|
||||||
deviceCodes.AddRange(dg);
|
|
||||||
deviceGroupCodes.AddRange(gg);
|
|
||||||
}
|
|
||||||
|
|
||||||
var dd = GetAssignCodesInternal1(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Device, AssignTypeEnumType.Department, gainfo.DepartmentNo);
|
|
||||||
var gd = GetAssignCodesInternal1(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Group, AssignTypeEnumType.Department, gainfo.DepartmentNo);
|
|
||||||
deviceCodes.AddRange(dd);
|
|
||||||
deviceGroupCodes.AddRange(gd);
|
|
||||||
|
|
||||||
var dt = GetAssignCodesInternal1(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Device, AssignTypeEnumType.Tenant, gainfo.Factory);
|
|
||||||
var gt = GetAssignCodesInternal1(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Group, AssignTypeEnumType.Tenant, gainfo.Factory);
|
|
||||||
deviceCodes.AddRange(du);
|
|
||||||
deviceGroupCodes.AddRange(gu);
|
|
||||||
|
|
||||||
var groupCodes = deviceGroupCodes.SelectMany(x => x.Codes).Distinct().ToList();
|
|
||||||
var deveiceCodesByGroup = deviceGroupRelationships.Where(x => groupCodes.Contains(x.GroupCode)).GroupBy(x => x.TenantId)
|
|
||||||
.Select(x => new UserTenantDeviceCodeDto
|
|
||||||
{
|
|
||||||
Tenant = x.Key,
|
|
||||||
Codes = x.Select(item => item.DeviceCode).Distinct().ToList()
|
|
||||||
});
|
|
||||||
|
|
||||||
deviceCodes.AddRange(deveiceCodesByGroup);
|
|
||||||
|
|
||||||
return deviceCodes.GroupBy(x => x.Tenant).Select(x => new UserTenantDeviceCodeDto
|
|
||||||
{
|
|
||||||
Tenant = x.Key,
|
|
||||||
Codes = x.SelectMany(item => item.Codes).Distinct().ToList()
|
|
||||||
|
|
||||||
}).ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取用户权限设备
|
/// 获取用户权限设备
|
||||||
@@ -430,7 +337,7 @@ public class DevicePermissionService : IDevicePermissionService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<UserTenantDeviceCodeDto> GetAssignCodesInternal1(
|
private static List<UserTenantDeviceCodeDto> GetAssignCodesInternal(
|
||||||
List<DevicePermissionEntity> devicePermissions, List<DeviceGroupEntity> deviceGroups,
|
List<DevicePermissionEntity> devicePermissions, List<DeviceGroupEntity> deviceGroups,
|
||||||
DeviceAssignmentTypeEnumType uniqueType, AssignTypeEnumType assignType, string assignValue)
|
DeviceAssignmentTypeEnumType uniqueType, AssignTypeEnumType assignType, string assignValue)
|
||||||
{
|
{
|
||||||
@@ -462,15 +369,14 @@ public class DevicePermissionService : IDevicePermissionService
|
|||||||
Tenant = tenant,
|
Tenant = tenant,
|
||||||
Codes = x.SelectMany(item => item.Codes).ToList()
|
Codes = x.SelectMany(item => item.Codes).ToList()
|
||||||
};
|
};
|
||||||
})
|
}).ToList();
|
||||||
.Where(x => x.Tenant.IsPresent()).ToList();
|
|
||||||
|
|
||||||
void RecursionGetNext(DeviceGroupEntity current, List<DeviceGroupEntity> deviceGroups, List<UserTenantDeviceCodeDto> result, bool add)
|
void RecursionGetNext(DeviceGroupEntity current, List<DeviceGroupEntity> deviceGroups, List<UserTenantDeviceCodeDto> result, bool add)
|
||||||
{
|
{
|
||||||
var next = deviceGroups.Where(x => x.PCode == current.Code).ToList();
|
var next = deviceGroups.Where(x => x.PCode == current.Code).ToList();
|
||||||
foreach (var item in next)
|
foreach (var item in next)
|
||||||
{
|
{
|
||||||
if (add && item.TenantId.IsPresent())
|
if (add)
|
||||||
{
|
{
|
||||||
result.Add(new UserTenantDeviceCodeDto { Tenant = item.TenantId, Codes = new List<Guid> { item.Code } });
|
result.Add(new UserTenantDeviceCodeDto { Tenant = item.TenantId, Codes = new List<Guid> { item.Code } });
|
||||||
}
|
}
|
||||||
@@ -479,34 +385,7 @@ public class DevicePermissionService : IDevicePermissionService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task<Dictionary<string, List<UserTenantDeviceCodeDto>>> GetAssignDeviceCodesInternalAsync(List<string> userNos)
|
||||||
private async Task<Dictionary<string, List<Guid>>> GetAssignDeviceCodesInternalAsync(List<string> userNos)
|
|
||||||
{
|
|
||||||
var gainfos = await _dbContext.Queryable<GainfoEntity>().Where(x => userNos.Contains(x.No)).ToListAsync();
|
|
||||||
if (!gainfos.Any())
|
|
||||||
{
|
|
||||||
return new Dictionary<string, List<Guid>>();
|
|
||||||
}
|
|
||||||
|
|
||||||
var gainfoGroupRelationships = await _dbContext.Queryable<GainfoGroupRelationshipEntity>().Where(x => userNos.Contains(x.UserNo)).ToListAsync();
|
|
||||||
var devicePermissions = await _dbContext.Queryable<DevicePermissionEntity>().ToListAsync();
|
|
||||||
var deviceGroups = await _dbContext.Queryable<DeviceGroupEntity>().ToListAsync();
|
|
||||||
var deviceRelationships = await _dbContext.Queryable<DeviceGroupRelationshipEntity>().ToListAsync();
|
|
||||||
|
|
||||||
var result = new Dictionary<string, List<Guid>>(gainfos.Count);
|
|
||||||
|
|
||||||
foreach (var gainfo in gainfos)
|
|
||||||
{
|
|
||||||
var userNo = gainfo.No;
|
|
||||||
var codes = GetAssignDeviceCodesInternal(gainfos, gainfoGroupRelationships, devicePermissions, deviceGroups, deviceRelationships, userNo);
|
|
||||||
|
|
||||||
result.Add(userNo, codes);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task<Dictionary<string, List<UserTenantDeviceCodeDto>>> GetAssignDeviceCodesInternal1Async(List<string> userNos)
|
|
||||||
{
|
{
|
||||||
var gainfos = await _dbContext.Queryable<GainfoEntity>().Where(x => userNos.Contains(x.No)).ToListAsync();
|
var gainfos = await _dbContext.Queryable<GainfoEntity>().Where(x => userNos.Contains(x.No)).ToListAsync();
|
||||||
if (!gainfos.Any())
|
if (!gainfos.Any())
|
||||||
@@ -523,7 +402,7 @@ public class DevicePermissionService : IDevicePermissionService
|
|||||||
|
|
||||||
foreach (var gainfo in gainfos)
|
foreach (var gainfo in gainfos)
|
||||||
{
|
{
|
||||||
var codes = GetAssignDeviceCodesInternal1(gainfo, gainfoGroupRelationships, devicePermissions, deviceGroups, deviceRelationships);
|
var codes = GetAssignDeviceCodesInternal(gainfo, gainfoGroupRelationships, devicePermissions, deviceGroups, deviceRelationships);
|
||||||
result.Add(gainfo.No, codes);
|
result.Add(gainfo.No, codes);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -531,4 +410,59 @@ public class DevicePermissionService : IDevicePermissionService
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private static List<UserTenantDeviceCodeDto> GetAssignDeviceCodesInternal(GainfoEntity gainfo,
|
||||||
|
List<GainfoGroupRelationshipEntity> gainfoGroupRelationships,
|
||||||
|
List<DevicePermissionEntity> devicePermissions,
|
||||||
|
List<DeviceGroupEntity> deviceGroups,
|
||||||
|
List<DeviceGroupRelationshipEntity> deviceGroupRelationships)
|
||||||
|
{
|
||||||
|
var userNo = gainfo.No;
|
||||||
|
var deviceCodes = new List<UserTenantDeviceCodeDto>();
|
||||||
|
var deviceGroupCodes = new List<UserTenantDeviceCodeDto>();
|
||||||
|
|
||||||
|
//获取人员的分组,跨基地
|
||||||
|
var gainfoGroups = gainfoGroupRelationships.Where(x => x.UserNo == userNo).Select(x => x.GroupCode).ToList();
|
||||||
|
|
||||||
|
//按User获取权限
|
||||||
|
var du = GetAssignCodesInternal(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Device, AssignTypeEnumType.User, userNo);
|
||||||
|
var gu = GetAssignCodesInternal(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Group, AssignTypeEnumType.User, userNo);
|
||||||
|
deviceCodes.AddRange(du);
|
||||||
|
deviceGroupCodes.AddRange(gu);
|
||||||
|
|
||||||
|
foreach (var groupCode in gainfoGroups)
|
||||||
|
{
|
||||||
|
var dg = GetAssignCodesInternal(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Device, AssignTypeEnumType.Group, groupCode.ToString());
|
||||||
|
var gg = GetAssignCodesInternal(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Group, AssignTypeEnumType.Group, groupCode.ToString());
|
||||||
|
deviceCodes.AddRange(dg);
|
||||||
|
deviceGroupCodes.AddRange(gg);
|
||||||
|
}
|
||||||
|
|
||||||
|
var dd = GetAssignCodesInternal(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Device, AssignTypeEnumType.Department, gainfo.DepartmentNo);
|
||||||
|
var gd = GetAssignCodesInternal(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Group, AssignTypeEnumType.Department, gainfo.DepartmentNo);
|
||||||
|
deviceCodes.AddRange(dd);
|
||||||
|
deviceGroupCodes.AddRange(gd);
|
||||||
|
|
||||||
|
var dt = GetAssignCodesInternal(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Device, AssignTypeEnumType.Tenant, gainfo.Factory);
|
||||||
|
var gt = GetAssignCodesInternal(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Group, AssignTypeEnumType.Tenant, gainfo.Factory);
|
||||||
|
deviceCodes.AddRange(du);
|
||||||
|
deviceGroupCodes.AddRange(gu);
|
||||||
|
|
||||||
|
var groupCodes = deviceGroupCodes.SelectMany(x => x.Codes).Distinct().ToList();
|
||||||
|
var deveiceCodesByGroup = deviceGroupRelationships.Where(x => groupCodes.Contains(x.GroupCode)).GroupBy(x => x.TenantId)
|
||||||
|
.Select(x => new UserTenantDeviceCodeDto
|
||||||
|
{
|
||||||
|
Tenant = x.Key,
|
||||||
|
Codes = x.Select(item => item.DeviceCode).Distinct().ToList()
|
||||||
|
});
|
||||||
|
|
||||||
|
deviceCodes.AddRange(deveiceCodesByGroup);
|
||||||
|
|
||||||
|
return deviceCodes.GroupBy(x => x.Tenant).Select(x => new UserTenantDeviceCodeDto
|
||||||
|
{
|
||||||
|
Tenant = x.Key,
|
||||||
|
Codes = x.SelectMany(item => item.Codes).Distinct().ToList()
|
||||||
|
|
||||||
|
}).ToList();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user