From 65e8c7d8c1666ae7a5bedc4b7aeb9f6a1176c595 Mon Sep 17 00:00:00 2001 From: "ai.astrakhantsev" Date: Mon, 28 Nov 2022 11:54:02 +0500 Subject: [PATCH 1/6] =?UTF-8?q?#7887519=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BF=D0=B0=D1=80=D0=B0=D0=BC?= =?UTF-8?q?=D0=B5=D1=82=D1=80=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AsbCloudApp/Data/LimitingParameterDto.cs | 10 ++++++++++ .../Services/LimitingParameterService.cs | 12 +++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/AsbCloudApp/Data/LimitingParameterDto.cs b/AsbCloudApp/Data/LimitingParameterDto.cs index 2c03eb45..a1f03219 100644 --- a/AsbCloudApp/Data/LimitingParameterDto.cs +++ b/AsbCloudApp/Data/LimitingParameterDto.cs @@ -27,6 +27,16 @@ namespace AsbCloudApp.Data /// Идентификатор критерия бурения /// public short IdFeedRegulator { get; set; } + + /// + /// Наименование критерия бурения + /// + public string NameFeedRegulator { get; set; } = string.Empty; + + /// + /// Количество включений + /// + public int NumberInclusions { get; set; } } #nullable disable } diff --git a/AsbCloudInfrastructure/Services/LimitingParameterService.cs b/AsbCloudInfrastructure/Services/LimitingParameterService.cs index 34ebbd24..abf66978 100644 --- a/AsbCloudInfrastructure/Services/LimitingParameterService.cs +++ b/AsbCloudInfrastructure/Services/LimitingParameterService.cs @@ -15,6 +15,14 @@ namespace AsbCloudInfrastructure.Services { private readonly ILimitingParameterRepository limitingParameterRepository; private readonly IWellService wellService; + private readonly Dictionary feedRegulatorData = new Dictionary() + { + { 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.FirstOrDefault(x => x.Key == item.Key).Value }); } From 481e87083f0afff716570c0c0164523b6f80d10d Mon Sep 17 00:00:00 2001 From: "ai.astrakhantsev" Date: Mon, 28 Nov 2022 11:54:02 +0500 Subject: [PATCH 2/6] =?UTF-8?q?#7887519=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BF=D0=B0=D1=80=D0=B0=D0=BC?= =?UTF-8?q?=D0=B5=D1=82=D1=80=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AsbCloudApp/Data/LimitingParameterDto.cs | 10 ++++++++++ .../Services/LimitingParameterService.cs | 12 +++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/AsbCloudApp/Data/LimitingParameterDto.cs b/AsbCloudApp/Data/LimitingParameterDto.cs index 2c03eb45..a1f03219 100644 --- a/AsbCloudApp/Data/LimitingParameterDto.cs +++ b/AsbCloudApp/Data/LimitingParameterDto.cs @@ -27,6 +27,16 @@ namespace AsbCloudApp.Data /// Идентификатор критерия бурения /// public short IdFeedRegulator { get; set; } + + /// + /// Наименование критерия бурения + /// + public string NameFeedRegulator { get; set; } = string.Empty; + + /// + /// Количество включений + /// + public int NumberInclusions { get; set; } } #nullable disable } diff --git a/AsbCloudInfrastructure/Services/LimitingParameterService.cs b/AsbCloudInfrastructure/Services/LimitingParameterService.cs index 34ebbd24..c50729f8 100644 --- a/AsbCloudInfrastructure/Services/LimitingParameterService.cs +++ b/AsbCloudInfrastructure/Services/LimitingParameterService.cs @@ -15,6 +15,14 @@ namespace AsbCloudInfrastructure.Services { private readonly ILimitingParameterRepository limitingParameterRepository; private readonly IWellService wellService; + private readonly Dictionary feedRegulatorData = new Dictionary() + { + { 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}" }); } From ba966452887f1ad4953e28d604e4013ad6fc8a4d Mon Sep 17 00:00:00 2001 From: "ai.astrakhantsev" Date: Tue, 29 Nov 2022 08:40:01 +0500 Subject: [PATCH 3/6] =?UTF-8?q?#7759269=20=D0=9F=D1=80=D0=BE=D0=B2=D0=B5?= =?UTF-8?q?=D1=80=D0=BA=D0=B0=20=D1=80=D0=BE=D0=BB=D0=B5=D0=B9=20=D0=BD?= =?UTF-8?q?=D0=B0=20=D0=B7=D0=B0=D1=86=D0=B8=D0=BA=D0=BB=D0=B8=D0=B2=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=B2=D0=BA=D0=BB=D1=8E=D1=87=D0=B5=D0=BD?= =?UTF-8?q?=D0=BD=D1=8B=D1=85=20=D1=80=D0=BE=D0=BB=D0=B5=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Repository/UserRoleRepository.cs | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/AsbCloudInfrastructure/Repository/UserRoleRepository.cs b/AsbCloudInfrastructure/Repository/UserRoleRepository.cs index 2ca837d3..52c087fa 100644 --- a/AsbCloudInfrastructure/Repository/UserRoleRepository.cs +++ b/AsbCloudInfrastructure/Repository/UserRoleRepository.cs @@ -90,10 +90,10 @@ namespace AsbCloudInfrastructure.Repository public async Task 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(); @@ -182,8 +182,15 @@ namespace AsbCloudInfrastructure.Repository if (dto?.Roles is null) return; - var relations = (await GetCacheRelationUserRoleUserRoleAsync(token).ConfigureAwait(false)) - .Where(r => r.Id == dto.Id); + var idsIncludeRole = dto.Roles.Select(x => x.Id); + + if (idsIncludeRole.Any(x => x == dto.Id)) + throw new ArgumentInvalidException("Invalid include role", nameof(UserRoleDto)); + + var relations = await dbContext.RelationUserRoleUserRoles + .Where(r => r.Id == dto.Id) + .ToListAsync(token) + .ConfigureAwait(false); dbContext.RelationUserRoleUserRoles.RemoveRange(relations); @@ -201,9 +208,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()) From c9c60bce2b275778590389328860929043461cdd Mon Sep 17 00:00:00 2001 From: "ai.astrakhantsev" Date: Tue, 29 Nov 2022 11:22:09 +0500 Subject: [PATCH 4/6] =?UTF-8?q?#7759269=20=D0=9F=D1=80=D0=BE=D0=B2=D0=B5?= =?UTF-8?q?=D1=80=D0=BA=D0=B0=20=D1=80=D0=BE=D0=BB=D0=B5=D0=B9=20=D0=BD?= =?UTF-8?q?=D0=B0=20=D0=B7=D0=B0=D1=86=D0=B8=D0=BA=D0=BB=D0=B8=D0=B2=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=B2=D0=BA=D0=BB=D1=8E=D1=87=D0=B5=D0=BD?= =?UTF-8?q?=D0=BD=D1=8B=D1=85=20=D1=80=D0=BE=D0=BB=D0=B5=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Repository/UserRoleRepository.cs | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/AsbCloudInfrastructure/Repository/UserRoleRepository.cs b/AsbCloudInfrastructure/Repository/UserRoleRepository.cs index 52c087fa..e386bb7f 100644 --- a/AsbCloudInfrastructure/Repository/UserRoleRepository.cs +++ b/AsbCloudInfrastructure/Repository/UserRoleRepository.cs @@ -5,6 +5,7 @@ using AsbCloudApp.Repositories; using AsbCloudDb; using AsbCloudDb.Model; using AsbCloudInfrastructure.EfCache; +using DocumentFormat.OpenXml.Vml.Office; using Mapster; using Microsoft.EntityFrameworkCore; using System; @@ -177,14 +178,23 @@ namespace AsbCloudInfrastructure.Repository return false; } + private IEnumerable GetNestedByIds(IEnumerable ids, int recursionLevel = 7) + { + var roles = new List(); + 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 idsIncludeRole = dto.Roles.Select(x => x.Id); + var idsIncludeRole = GetNestedByIds(dto.Roles.Select(x => x.Id)).Select(x => x.Id); - if (idsIncludeRole.Any(x => x == dto.Id)) + if (idsIncludeRole is null || idsIncludeRole.Any(x => x == dto.Id)) throw new ArgumentInvalidException("Invalid include role", nameof(UserRoleDto)); var relations = await dbContext.RelationUserRoleUserRoles @@ -203,6 +213,21 @@ namespace AsbCloudInfrastructure.Repository DropCacheRelationUserRoleUserRole(); } + //private IEnumerable GetNestedRoleIds(UserRoleDto dto) + //{ + // var result = new List(); + // if (dto.Roles is not null) + // { + // foreach (var role in dto.Roles) + // { + // result.Add(role.Id); + // if (role.Roles is not null) + // GetNestedRoleIds(role); + // } + // } + // return result; + //} + private async Task UpdatePermissionsAsync(UserRoleDto dto, CancellationToken token) { if (dto?.Permissions is null) From a12906d5581bb779695f2af134b7b1e635425951 Mon Sep 17 00:00:00 2001 From: "ai.astrakhantsev" Date: Tue, 29 Nov 2022 11:22:34 +0500 Subject: [PATCH 5/6] =?UTF-8?q?#7759269=20=D0=9F=D1=80=D0=BE=D0=B2=D0=B5?= =?UTF-8?q?=D1=80=D0=BA=D0=B0=20=D1=80=D0=BE=D0=BB=D0=B5=D0=B9=20=D0=BD?= =?UTF-8?q?=D0=B0=20=D0=B7=D0=B0=D1=86=D0=B8=D0=BA=D0=BB=D0=B8=D0=B2=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=B2=D0=BA=D0=BB=D1=8E=D1=87=D0=B5=D0=BD?= =?UTF-8?q?=D0=BD=D1=8B=D1=85=20=D1=80=D0=BE=D0=BB=D0=B5=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Repository/UserRoleRepository.cs | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/AsbCloudInfrastructure/Repository/UserRoleRepository.cs b/AsbCloudInfrastructure/Repository/UserRoleRepository.cs index e386bb7f..ccb736ea 100644 --- a/AsbCloudInfrastructure/Repository/UserRoleRepository.cs +++ b/AsbCloudInfrastructure/Repository/UserRoleRepository.cs @@ -213,21 +213,6 @@ namespace AsbCloudInfrastructure.Repository DropCacheRelationUserRoleUserRole(); } - //private IEnumerable GetNestedRoleIds(UserRoleDto dto) - //{ - // var result = new List(); - // if (dto.Roles is not null) - // { - // foreach (var role in dto.Roles) - // { - // result.Add(role.Id); - // if (role.Roles is not null) - // GetNestedRoleIds(role); - // } - // } - // return result; - //} - private async Task UpdatePermissionsAsync(UserRoleDto dto, CancellationToken token) { if (dto?.Permissions is null) From 4a547d82ae93ede0f2b76b6104c1fe8e8a88ffb7 Mon Sep 17 00:00:00 2001 From: "ai.astrakhantsev" Date: Tue, 29 Nov 2022 11:22:34 +0500 Subject: [PATCH 6/6] =?UTF-8?q?#7759269=20=D0=9F=D1=80=D0=BE=D0=B2=D0=B5?= =?UTF-8?q?=D1=80=D0=BA=D0=B0=20=D1=80=D0=BE=D0=BB=D0=B5=D0=B9=20=D0=BD?= =?UTF-8?q?=D0=B0=20=D0=B7=D0=B0=D1=86=D0=B8=D0=BA=D0=BB=D0=B8=D0=B2=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=B2=D0=BA=D0=BB=D1=8E=D1=87=D0=B5=D0=BD?= =?UTF-8?q?=D0=BD=D1=8B=D1=85=20=D1=80=D0=BE=D0=BB=D0=B5=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Repository/UserRoleRepository.cs | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/AsbCloudInfrastructure/Repository/UserRoleRepository.cs b/AsbCloudInfrastructure/Repository/UserRoleRepository.cs index e386bb7f..56daca96 100644 --- a/AsbCloudInfrastructure/Repository/UserRoleRepository.cs +++ b/AsbCloudInfrastructure/Repository/UserRoleRepository.cs @@ -5,7 +5,6 @@ using AsbCloudApp.Repositories; using AsbCloudDb; using AsbCloudDb.Model; using AsbCloudInfrastructure.EfCache; -using DocumentFormat.OpenXml.Vml.Office; using Mapster; using Microsoft.EntityFrameworkCore; using System; @@ -213,21 +212,6 @@ namespace AsbCloudInfrastructure.Repository DropCacheRelationUserRoleUserRole(); } - //private IEnumerable GetNestedRoleIds(UserRoleDto dto) - //{ - // var result = new List(); - // if (dto.Roles is not null) - // { - // foreach (var role in dto.Roles) - // { - // result.Add(role.Id); - // if (role.Roles is not null) - // GetNestedRoleIds(role); - // } - // } - // return result; - //} - private async Task UpdatePermissionsAsync(UserRoleDto dto, CancellationToken token) { if (dto?.Permissions is null)