From 7b1c67650726d6e9edc83ffe4cd2393e314c7ccc Mon Sep 17 00:00:00 2001 From: Mikhail Kuznetsov Date: Mon, 2 Jun 2025 16:26:15 +1000 Subject: [PATCH] =?UTF-8?q?fix(aihitRelationShips):=20=D0=B4=D0=BE=D0=B1?= =?UTF-8?q?=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B0=20=D0=BF=D1=80=D0=BE=D0=B2?= =?UTF-8?q?=D0=B5=D1=80=D0=BA=D0=B0=20=D0=BD=D0=B0=D0=BB=D0=B8=D1=87=D0=B8?= =?UTF-8?q?=D1=8F=20=D1=83=D0=B6=D0=B5=20=D1=83=D0=B6=D0=B5=20=D1=81=D1=83?= =?UTF-8?q?=D1=89=D0=B5=D1=81=D1=82=D0=B2=D1=83=D1=8E=D1=88=D0=B5=D0=B9=20?= =?UTF-8?q?=D1=81=D0=B2=D1=8F=D0=B7=D0=B8,=20=D1=81=D0=BE=D0=B1=D1=8B?= =?UTF-8?q?=D1=82=D0=B8=D0=B5=20=D1=81=D0=BB=D1=83=D1=87=D0=B0=D0=B5=D1=82?= =?UTF-8?q?=D1=81=D1=8F=20=D0=B5=D1=81=D0=BB=D0=B8=20=D0=B2=20=D1=81=D0=BF?= =?UTF-8?q?=D0=B8=D1=81=D0=BA=D0=B5=20=D0=B8=D0=BC=D0=B5=D1=8E=D1=82=D1=81?= =?UTF-8?q?=D1=8F=20=D0=B2=20=D0=BD=D0=B0=D0=BB=D0=B8=D1=87=D0=B8=D0=B8=20?= =?UTF-8?q?=D0=AD=D0=9A=20=D1=80=D0=B0=D0=B7=D0=BD=D0=BE=D0=B3=D0=BE=20?= =?UTF-8?q?=D1=80=D0=B5=D0=B3=D0=B8=D1=81=D1=82=D1=80=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RelationshipsSyncSrevice.cs | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/PARR.AIHITRelationshipsSyncer/Services/Implementations/RelationshipsSyncSrevice.cs b/PARR.AIHITRelationshipsSyncer/Services/Implementations/RelationshipsSyncSrevice.cs index a82108fb..b7109a60 100644 --- a/PARR.AIHITRelationshipsSyncer/Services/Implementations/RelationshipsSyncSrevice.cs +++ b/PARR.AIHITRelationshipsSyncer/Services/Implementations/RelationshipsSyncSrevice.cs @@ -54,8 +54,7 @@ namespace PARR.AIHITRelationshipsSyncer.Services.Implementations //Из данных АИХ ИТ получаем имена всех дочерних ЭК var childsName = parrent.Where(t => t.ChildEk != parentName && t.ChildEk != null).Select(t => t.ChildEk); - //Убираем ЭК типа РПА-РОБИН-РЦКУ-СПИУИ-ИНФО-27-ГОР и РПА - РОБИН - РЦКУ - СПиУИ - ИНФО - 27 - ГОР - childsName = childsName.Select(t => t?.ToLower().Trim()).Distinct(); + childsName = childsName.Select(t => t?.Trim()).Distinct(); //Проходим циклом по полученному списку для актуализации связей в полученном нами экземпляре Unit var isChanged = await SyncChildSUnitAsync(unit, childsName); @@ -113,7 +112,7 @@ namespace PARR.AIHITRelationshipsSyncer.Services.Implementations var isChanged = false; //удаляем лишние дочерние связи существующие только в БД - var childsToDelete = unit.ChildUnits.Where(t => !childsName.Any(a => t.ChildUnit?.Name.ToLower() == a!.ToLower().Trim())); + var childsToDelete = unit.ChildUnits.Where(t => !childsName.Any(a => t.ChildUnit?.Name.ToLower() == a!.ToLower())); if (childsToDelete.Any()) { DeleteChilds(unit, childsToDelete); @@ -122,7 +121,7 @@ namespace PARR.AIHITRelationshipsSyncer.Services.Implementations } //проверяем отсутсвующие связи - var absentChildrens = childsName.Where(c => !unit.ChildUnits.Any(x => x.ChildUnit?.Name.ToLower() == c.ToLower().Trim())); + var absentChildrens = childsName.Where(c => !unit.ChildUnits.Any(x => x.ChildUnit?.Name.ToLower() == c?.ToLower())); foreach (var absentChildren in absentChildrens) { var childUnit = await GetUnitByNameAsync(absentChildren!); @@ -132,15 +131,20 @@ namespace PARR.AIHITRelationshipsSyncer.Services.Implementations return false; } - unit.ChildUnits.Add( - new UnitInUnit - { - ParentUnitId = unit.Id, - ChildUnitId = childUnit.Id, - DateCreated = DateTimeOffset.UtcNow, - } - ); - logger.LogInformation($"----- Создан связь Unit {unit.Name} - {childUnit.Name}-----"); + if (unit.ChildUnits.Any(x => x.ChildUnitId == childUnit.Id)) + logger.LogWarning($"Попытка создать существующую связь для {unit.Name} - {childUnit.Name}"); + else + { + unit.ChildUnits.Add( + new UnitInUnit + { + ParentUnitId = unit.Id, + ChildUnitId = childUnit.Id, + DateCreated = DateTimeOffset.UtcNow, + } + ); + logger.LogInformation($"----- Создан связь Unit {unit.Name} - {childUnit.Name}-----"); + } if (!isChanged) isChanged = true;