This commit is contained in:
ngfrolov 2022-12-05 08:49:45 +05:00
commit 7c31f7ce76
3 changed files with 44 additions and 17 deletions

View File

@ -27,6 +27,16 @@ namespace AsbCloudApp.Data
/// Идентификатор критерия бурения
/// </summary>
public short IdFeedRegulator { get; set; }
/// <summary>
/// Наименование критерия бурения
/// </summary>
public string NameFeedRegulator { get; set; } = string.Empty;
/// <summary>
/// Количество включений
/// </summary>
public int NumberInclusions { get; set; }
}
#nullable disable
}

View File

@ -90,10 +90,10 @@ namespace AsbCloudInfrastructure.Repository
public async Task<int> UpdateAsync(UserRoleDto dto, CancellationToken token)
{
var entity = Convert(dto);
await UpdatePermissionsAsync(dto, token);
await UpdateIncludedRolesAsync(dto, token);
var entity = Convert(dto);
var result = dbContext.UserRoles.Upsert(entity);
await dbContext.SaveChangesAsync(token);
DropCacheUserRole();
@ -177,13 +177,29 @@ namespace AsbCloudInfrastructure.Repository
return false;
}
private IEnumerable<UserRoleDto> GetNestedByIds(IEnumerable<int> ids, int recursionLevel = 7)
{
var roles = new List<UserRoleDto>();
foreach (var id in ids)
roles.AddRange(GetNestedById(id, recursionLevel));
return roles;
}
private async Task UpdateIncludedRolesAsync(UserRoleDto dto, CancellationToken token)
{
if (dto?.Roles is null)
return;
var relations = (await GetCacheRelationUserRoleUserRoleAsync(token).ConfigureAwait(false))
.Where(r => r.Id == dto.Id);
var idsIncludeRole = GetNestedByIds(dto.Roles.Select(x => x.Id)).Select(x => x.Id);
if (idsIncludeRole is not null && idsIncludeRole.Any(x => x == dto.Id))
throw new ArgumentInvalidException("Invalid include role (self reference)", nameof(dto));
var relations = await dbContext.RelationUserRoleUserRoles
.Where(r => r.Id == dto.Id)
.ToListAsync(token)
.ConfigureAwait(false);
dbContext.RelationUserRoleUserRoles.RemoveRange(relations);
@ -201,9 +217,10 @@ namespace AsbCloudInfrastructure.Repository
if (dto?.Permissions is null)
return;
var relations = (await GetCacheRelationUserRolePermissionsAsync(token).ConfigureAwait(false))
.Where(r => r.IdUserRole == dto.Id);
var relations = await dbContext.RelationUserRolePermissions
.Where(r => r.IdUserRole == dto.Id)
.ToListAsync(token)
.ConfigureAwait(false);
dbContext.RelationUserRolePermissions.RemoveRange(relations);
if (dto.Permissions.Any())
@ -235,19 +252,9 @@ namespace AsbCloudInfrastructure.Repository
private void DropCacheUserRole()
=> dbContext.RelationUserUserRoles.DropCache(userRoleCacheTag);
private Task<IEnumerable<RelationUserRoleUserRole>> GetCacheRelationUserRoleUserRoleAsync(CancellationToken token)
=> dbContext.RelationUserRoleUserRoles
.Include(r => r.IncludeRole)
.Include(r => r.Role)
.FromCacheAsync(relationUserRoleUserRoleCacheTag, relationCacheObsolence, token);
private void DropCacheRelationUserRoleUserRole()
=> dbContext.RelationUserUserRoles.DropCache(relationUserRoleUserRoleCacheTag);
private Task<IEnumerable<RelationUserRolePermission>> GetCacheRelationUserRolePermissionsAsync(CancellationToken token)
=> dbContext.RelationUserRolePermissions
.Include(r => r.UserRole)
.Include(r => r.Permission)
.FromCacheAsync(relationUserRolePermissionsCacheTag, relationCacheObsolence, token);
private IEnumerable<RelationUserRolePermission> GetCacheRelationUserRolePermissions()
=> dbContext.RelationUserRolePermissions
.Include(r => r.UserRole)

View File

@ -15,6 +15,14 @@ namespace AsbCloudInfrastructure.Services
{
private readonly ILimitingParameterRepository limitingParameterRepository;
private readonly IWellService wellService;
private readonly Dictionary<int, string> feedRegulatorData = new Dictionary<int, string>()
{
{ 0, "Нет ограничения" },
{ 1, "МСП" },
{ 2, "Давление" },
{ 3, "Осевая нагрузка" },
{ 4, "Момент" }
};
public LimitingParameterService(ILimitingParameterRepository limitingParameterRepository,
IWellService wellService)
@ -46,7 +54,9 @@ namespace AsbCloudInfrastructure.Services
IdWell = well.Id,
IdFeedRegulator = item.Key,
Depth = allItemDepths,
TotalMinutes = (float)allItemDates
TotalMinutes = (float)allItemDates,
NumberInclusions = item.Count(),
NameFeedRegulator = feedRegulatorData.GetValueOrDefault(item.Key) ?? $"Id: {item.Key}"
});
}