From e16eecaebad67e704e6568ab5b6e4fe0b98ae4ea Mon Sep 17 00:00:00 2001 From: Mikhail Kuznetsov Date: Mon, 14 Aug 2023 11:38:59 +1000 Subject: [PATCH] =?UTF-8?q?=D0=97=D0=B0=D0=B3=D1=80=D1=83=D0=B7=D0=BA?= =?UTF-8?q?=D0=B0=20=D1=81=D1=8B=D1=80=D1=8B=D1=85=20=D0=B4=D0=B0=D0=BD?= =?UTF-8?q?=D0=BD=D1=8B=D1=85=20=D0=B8=D0=B7=20=D0=90=D0=98=D0=A5=20=D0=98?= =?UTF-8?q?=D0=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AIHIT/MappingProfiles/RequestToDomain.cs | 2 + PARR.AIHIT/AIHIT/Syncher.cs | 172 ++++++++++-------- PARR.DAL/Context/DataContext.cs | 6 +- .../Migrations/DataContextModelSnapshot.cs | 31 ++-- PARR.DAL/ParrDalInstaller.cs | 1 + 5 files changed, 128 insertions(+), 84 deletions(-) diff --git a/PARR.AIHIT/AIHIT/MappingProfiles/RequestToDomain.cs b/PARR.AIHIT/AIHIT/MappingProfiles/RequestToDomain.cs index e6e16757..7662b1db 100644 --- a/PARR.AIHIT/AIHIT/MappingProfiles/RequestToDomain.cs +++ b/PARR.AIHIT/AIHIT/MappingProfiles/RequestToDomain.cs @@ -1,4 +1,5 @@ using AutoMapper; +using PARR.DAL.Models.AIHIT; using PARR.DAL.Models.V1; using System.Xml; @@ -17,6 +18,7 @@ namespace PARR.AIHIT.MappingProfiles .ForMember(d => d.WorkGroup, o => o.MapFrom(s => (s.Attributes!["РАБОЧАЯ_ГР_ОТВ_ЗА_ЭК"] != null) ? s.Attributes!["РАБОЧАЯ_ГР_ОТВ_ЗА_ЭК"]!.Value.Trim() : "")) .ForMember(d => d.Responsible, o => o.MapFrom(s => s.Attributes!["ОТВЕТСТВЕННЫЙ_ЗА_ЭК"]!.Value.Trim())); + CreateMap(); //CreateMap() // .ForMember(d => d.HostName, o => o.MapFrom(s => s.HostName)) // .ForMember(d => d.IP, o => o.MapFrom(s => s.IP)) diff --git a/PARR.AIHIT/AIHIT/Syncher.cs b/PARR.AIHIT/AIHIT/Syncher.cs index 59f36be6..0298202e 100644 --- a/PARR.AIHIT/AIHIT/Syncher.cs +++ b/PARR.AIHIT/AIHIT/Syncher.cs @@ -3,11 +3,9 @@ using MailKit.Search; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using MimeKit; -using PARR.AIHIT.Context; using PARR.AIHIT.Settings; using PARR.DAL.Contracts; using PARR.DAL.Extensions; -using PARR.DAL.Models.AIHIT; using PARR.DAL.Models.V1; using PARR.DAL.Services.Interfaces; using PARR.DAL.Services.Interfaces.AIHIT; @@ -28,6 +26,7 @@ namespace PARR.AIHIT private readonly IApplicationTypeService appTypeService; private readonly IApplicationInHostService appInHostService; private readonly IRawDataEKService rawDataEKService; + private readonly ISettingService settingService; public List AppTypes { get; private set; } = new List(); @@ -40,7 +39,8 @@ namespace PARR.AIHIT IApplicationService appService, IApplicationTypeService appTypeService, IApplicationInHostService appInHostService, - IRawDataEKService rawDataEKService + IRawDataEKService rawDataEKService, + ISettingService settingService ) { this.hostService = hostService; @@ -49,6 +49,7 @@ namespace PARR.AIHIT this.appTypeService = appTypeService; this.appInHostService = appInHostService; this.rawDataEKService = rawDataEKService; + this.settingService = settingService; this.logger = logger; this.mailService = mailService; this.syncherSettings = syncherSettings; @@ -178,33 +179,9 @@ namespace PARR.AIHIT // Синхронизация Applications await SyncApplicationAndHostAsync(foundHost, hostApplications, true); } - - - - - //host.DateModified = ... - //var host = new PARR.DAL.Models.Host - //{ - // HostName = "", - // IP = vm!.Attributes["IP_АДРЕС"]!.Value, - // RegionalEK = vm?.Attributes?["РЕГИОНАЛЬНЫЙ_ЭК"]?.Value, - // LinkEK = vm?.Attributes?["СВЯЗАННЫЙ_ЭК"]?.Value, - // Status = vm?.Attributes?["СТАТУС"]?.Value, - // WorkGroup = vm?.Attributes?["РАБОЧАЯ_ГР_ОТВ_ЗА_ЭК"]?.Value, - // Responsible = vm?.Attributes?["ОТВЕТСТВЕННЫЙ_ЗА_ЭК"]?.Value, - // OS = vm?.Attributes?["ОС"]?.Value, - // DB = vm?.Attributes?["СУБД"]?.Value, - // APP = vm?.Attributes?["СП"]?.Value, - - //}; - //logger.LogInformation($"Запись сервера {mappedHost.IP}, региональный ЭК {mappedHost.RegionalEK}"); - //if (String.IsNullOrEmpty(host.Status) || !host.Status.Equals("3-В эксплуатации")) continue; - //if (String.IsNullOrEmpty(host.IP)) continue; - } } break; - } } @@ -217,42 +194,109 @@ namespace PARR.AIHIT public async Task InvokeFromDatabase() { - var eksFromAIHIT = new List(); - //call procedure - using (AIHContext db = new AIHContext()) - { - var zo = new Microsoft.Data.SqlClient.SqlParameter - { - ParameterName = "@зо", - SqlDbType = System.Data.SqlDbType.NVarChar, - Direction = System.Data.ParameterDirection.Input, - Size = 60, - Value = "96-ДВС" - }; - eksFromAIHIT = db.EKs.FromSqlRaw($"EXEC mao2.dbo.sp_IPP_PARR_PTK_get_EK @зо", zo).ToList(); - } - if (!eksFromAIHIT.Any()) - { - logger.LogWarning($"Процедура sp_IPP_PARR_PTK_get_EK вурнула пустой список ЭК"); - return; + /* + //Получаем зоны ответственности из БД + var respAreas = settingService.Get().Where(ra => ra.Group == AIHTITSettings.RespAreaGroupName).ToList(); - } - rawDataEKService.DeleteAll(); - foreach (var ek in eksFromAIHIT) + //Запускаем хранимую процедуру в АИХ ИТ и складываем в таблицу RawDataEKs, предварительно почистив старые данные + foreach (var respArea in respAreas) { - // создаем - var mappedEK = mapper.Map(ek); - if (!await rawDataEKService.CreateAsync(mappedEK) || !await rawDataEKService.CommitAsync()) + var eksFromAIHIT = new List(); + using (AIHContext db = new AIHContext()) { - logger.LogError($"Не удалось создать запись rawDataEK {mappedEK.ShortName}({mappedEK.IP})"); - continue; + var zo = new Microsoft.Data.SqlClient.SqlParameter + { + ParameterName = "@зо", + SqlDbType = System.Data.SqlDbType.NVarChar, + Direction = System.Data.ParameterDirection.Input, + Size = 60, + Value = respArea.Value + }; + eksFromAIHIT = db.EKs.FromSqlRaw($"EXEC mao2.dbo.sp_IPP_PARR_PTK_get_EK @зо", zo).ToList(); + if (eksFromAIHIT == null || !eksFromAIHIT.Any()) + { + logger.LogWarning($"Процедура sp_IPP_PARR_PTK_get_EK вурнула пустой список ЭК"); + return; + + } + } + //Удаляем текущие данные по зоне ответственности respArea + var toDelete = rawDataEKService.Get().Where(rd => rd.ResponseArea == respArea.Value).ToList(); + toDelete.ForEach(d => rawDataEKService.Delete(d)); + + foreach (var ek in eksFromAIHIT) + { + // создаем + var mappedEK = new RawDataEK() + { + Id = Guid.NewGuid(), + DateCreated = DateTimeOffset.UtcNow, + IP = ek.IP, + Metka = ek.Metka, + IsActive = ek.IsActive, + IsImportant = ek.IsImportant, + CreateTime = ek.CreateTime.ToString(), + AdditionalInfo = ek.AdditionalInfo, + ResponseArea = ek.ResponseArea, + EKCategory = ek.EKCategory, + EKFindCode = ek.EKFindCode, + ProductCode = ek.ProductCode, + ServiceCode = ek.ServiceCode, + ShortName = ek.ShortName, + ResponsibleByEK = ek.ResponsibleByEK, + PlannedTimeToRepair = ek.PlannedTimeToRepair.ToString(), + EKSubCategory = ek.EKSubCategory, + FullName = ek.FullName, + Prescription = ek.Prescription, + Company = ek.Company, + WorkGroup = ek.WorkGroup, + Location = ek.Location, + EKRevizor = ek.EKRevizor, + EKRegister = ek.EKRegister, + NetworkName = ek.NetworkName, + Status = ek.Status, + EKType = ek.EKType, + EndExplotationDate = ek.EndExplotationDate.ToString(), + StartExplotationDate = ek.StartExplotationDate.ToString(), + TargetRepairTime = ek.TargetRepairTime, + SysModTime = ek.SysModTime.ToString(), + SysModUser = ek.SysModUser, + NewEKFindCode = ek.NewEKFindCode, + OldEKFindCode = ek.OldEKFindCode, + CTSDirection = ek.CTSDirection, + AIHID = ek.ID, + IsUnreliableData = ek.IsUnreliableData, + ShiftWorkGroup = ek.ShiftWorkGroup, + ClientSoftware = ek.ClientSoftware, + ClientOS = ek.ClientOS, + DBType = ek.DBType, + APPType = ek.APPType, + CKBSServerType = ek.CKBSServerType, + IBServerType = ek.IBServerType, + InfrastructureServerType = ek.InfrastructureServerType, + MonitoringServerType = ek.MonitoringServerType + }; + + if (!await rawDataEKService.CreateAsync(mappedEK) || !await rawDataEKService.CommitAsync()) + { + logger.LogError($"Не удалось создать запись rawDataEK {mappedEK.ShortName}({mappedEK.IP})"); + continue; + } + else + logger.LogInformation($"----- Создана запись rawDataEK {mappedEK.ShortName}({mappedEK.IP}) -----"); } - else - logger.LogInformation($"----- Создана запись rawDataEK {mappedEK.ShortName}({mappedEK.IP}) -----"); } - //get raw data - //save data + */ + //Разбираем сырые данные + + //Получаем интересующие статусы ЭК + var statusList = settingService.Get().Where(s => s.Group == AIHTITSettings.StatusGroupName).Select(s => s.Value.Trim()).ToList(); + if (statusList == null || statusList.Count == 0) return; + + var eks = rawDataEKService.Get().Where(e => e.IsActive == "t" && (e.Status != null && statusList.Contains(e.Status.Trim()))).ToList(); + + } private async Task SyncApplicationAndHostAsync(V1_Host? host, List hostApplications, bool isUpdateDateModified = false) { @@ -415,20 +459,6 @@ namespace PARR.AIHIT return existType; } - - //private bool IsChanged(Host host, Host mappedHost) - //{ - // if (host == null) return true; - // if (mappedHost == null) return true; - // if (!host.IP.Equals(mappedHost.IP)) return true; - // if (!host.RegionalEK!.Equals(mappedHost.RegionalEK)) return true; - // if (!host.LinkEK!.Equals(mappedHost.LinkEK)) return true; - // if (!host.Status!.Equals(mappedHost.Status)) return true; - // if (!host.WorkGroup!.Equals(mappedHost.WorkGroup)) return true; - // if (!host.Responsible!.Equals(mappedHost.Responsible)) return true; - // return false; - //} - private static string EncodeString(string str) { byte[] bStr = Encoding.GetEncoding("koi8r").GetBytes(str); diff --git a/PARR.DAL/Context/DataContext.cs b/PARR.DAL/Context/DataContext.cs index 5f93c5b4..6f6dd822 100644 --- a/PARR.DAL/Context/DataContext.cs +++ b/PARR.DAL/Context/DataContext.cs @@ -61,8 +61,10 @@ namespace PARR.DAL.Context { f.HasData( new() { Id = new Guid("1AD12210-BE62-459A-AA6C-FDA7648503F7"), DateCreated = dateCreated, DateModified = null, Group = null, Name = "ConnectionString", Value = @"Data Source=10.248.19.97; Initial Catalog=mao2;User ID=awhit-ipp-parr;pwd=ET3h$9y1LH#D;TrustServerCertificate=true;", Description = "Строка подключения к базе данных АИХ ИТ" }, - new() { Id = new Guid("50F66704-4D26-4587-BB1E-DCA70C8F4B89"), DateCreated = dateCreated, DateModified = null, Group = "ResponsibleArea", Name = "ZAB", Value = "94-ЗАБ", Description = "Зона ответственности" }, - new() { Id = new Guid("1FD43634-4A06-4237-9727-EDFA6F3EEBE8"), DateCreated = dateCreated, DateModified = null, Group = "ResponsibleArea", Name = "DVS", Value = "96-ДВС", Description = "Зона ответственности" } + new() { Id = new Guid("50F66704-4D26-4587-BB1E-DCA70C8F4B89"), DateCreated = dateCreated, DateModified = null, Group = AIHTITSettings.RespAreaGroupName, Name = "ZAB", Value = "94-ЗАБ", Description = "Зона ответственности" }, + new() { Id = new Guid("1FD43634-4A06-4237-9727-EDFA6F3EEBE8"), DateCreated = dateCreated, DateModified = null, Group = AIHTITSettings.RespAreaGroupName, Name = "DVS", Value = "96-ДВС", Description = "Зона ответственности" }, + new() { Id = new Guid("77C73C0A-8E4D-4676-B6E2-6A112F20E346"), DateCreated = dateCreated, DateModified = null, Group = AIHTITSettings.StatusGroupName, Name = "Exploitation", Value = "3-В эксплуатации", Description = "Статус актуальных ЭК" } + ); }); } diff --git a/PARR.DAL/Migrations/DataContextModelSnapshot.cs b/PARR.DAL/Migrations/DataContextModelSnapshot.cs index c36597ed..5f36f793 100644 --- a/PARR.DAL/Migrations/DataContextModelSnapshot.cs +++ b/PARR.DAL/Migrations/DataContextModelSnapshot.cs @@ -52,8 +52,8 @@ namespace PARR.DAL.Migrations b.Property("Company") .HasColumnType("text"); - b.Property("CreateTime") - .HasColumnType("timestamp with time zone"); + b.Property("CreateTime") + .HasColumnType("text"); b.Property("DBType") .HasColumnType("text"); @@ -82,8 +82,8 @@ namespace PARR.DAL.Migrations b.Property("EKType") .HasColumnType("text"); - b.Property("EndExplotationDate") - .HasColumnType("timestamp with time zone"); + b.Property("EndExplotationDate") + .HasColumnType("text"); b.Property("FullName") .HasColumnType("text"); @@ -124,8 +124,8 @@ namespace PARR.DAL.Migrations b.Property("OldEKFindCode") .HasColumnType("text"); - b.Property("PlannedTimeToRepair") - .HasColumnType("timestamp with time zone"); + b.Property("PlannedTimeToRepair") + .HasColumnType("text"); b.Property("Prescription") .HasColumnType("text"); @@ -148,14 +148,14 @@ namespace PARR.DAL.Migrations b.Property("ShortName") .HasColumnType("text"); - b.Property("StartExplotationDate") - .HasColumnType("timestamp with time zone"); + b.Property("StartExplotationDate") + .HasColumnType("text"); b.Property("Status") .HasColumnType("text"); - b.Property("SysModTime") - .HasColumnType("timestamp with time zone"); + b.Property("SysModTime") + .HasColumnType("text"); b.Property("SysModUser") .HasColumnType("text"); @@ -217,7 +217,7 @@ namespace PARR.DAL.Migrations Description = "Зона ответственности", Group = "ResponsibleArea", Name = "ZAB", - Value = "94 - ЗАБ" + Value = "94-ЗАБ" }, new { @@ -227,6 +227,15 @@ namespace PARR.DAL.Migrations Group = "ResponsibleArea", Name = "DVS", Value = "96-ДВС" + }, + new + { + Id = new Guid("77c73c0a-8e4d-4676-b6e2-6a112f20e346"), + DateCreated = new DateTimeOffset(new DateTime(2023, 5, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)), + Description = "Статус актуальных ЭК", + Group = "Status", + Name = "Exploitation", + Value = "3-В эксплуатации" }); }); diff --git a/PARR.DAL/ParrDalInstaller.cs b/PARR.DAL/ParrDalInstaller.cs index 2455b04e..9bd41adb 100644 --- a/PARR.DAL/ParrDalInstaller.cs +++ b/PARR.DAL/ParrDalInstaller.cs @@ -24,6 +24,7 @@ namespace PARR.DAL services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); //services.AddTransient(); //services.AddTransient();