diff --git a/PARR.AIHIT/AIHIT/Context/AIHContext.cs b/PARR.AIHIT/AIHIT/Context/AIHContext.cs deleted file mode 100644 index 2cbe7c0a..00000000 --- a/PARR.AIHIT/AIHIT/Context/AIHContext.cs +++ /dev/null @@ -1,16 +0,0 @@ -using Microsoft.EntityFrameworkCore; -using PARR.AIHIT.Models; - -namespace PARR.AIHIT.Context -{ - internal class AIHContext : DbContext - { - public DbSet EKs { get; set; } - public AIHContext() { } - - protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) - { - optionsBuilder.UseSqlServer(@"Data Source=10.248.19.97; Initial Catalog=mao2;User ID=awhit-ipp-parr;pwd=ET3h$9y1LH#D;TrustServerCertificate=true;"); - } - } -} diff --git a/PARR.AIHIT/AIHIT/Context/AIHITContext.cs b/PARR.AIHIT/AIHIT/Context/AIHITContext.cs new file mode 100644 index 00000000..a5afd843 --- /dev/null +++ b/PARR.AIHIT/AIHIT/Context/AIHITContext.cs @@ -0,0 +1,19 @@ +using Microsoft.EntityFrameworkCore; +using PARR.AIHIT.Models; + +namespace PARR.AIHIT.Context +{ + internal class AIHITContext : DbContext + { + public AIHITContext(DbContextOptions options) : base(options) { } + + + + public DbSet EKs { get; set; } + + //protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + //{ + // optionsBuilder.UseSqlServer(@"Data Source=10.248.19.97; Initial Catalog=mao2;User ID=awhit-ipp-parr;pwd=ET3h$9y1LH#D;TrustServerCertificate=true;"); + //} + } +} diff --git a/PARR.AIHIT/AIHIT/MappingProfiles/RequestToDomain.cs b/PARR.AIHIT/AIHIT/MappingProfiles/RequestToDomain.cs index 08451f73..08243a29 100644 --- a/PARR.AIHIT/AIHIT/MappingProfiles/RequestToDomain.cs +++ b/PARR.AIHIT/AIHIT/MappingProfiles/RequestToDomain.cs @@ -1,4 +1,5 @@ using AutoMapper; +using PARR.AIHIT.Models; using PARR.DAL.Models; using PARR.DAL.Models.AIHIT; using PARR.DAL.Models.V1; @@ -35,6 +36,10 @@ namespace PARR.AIHIT.MappingProfiles // .ForMember(d => d.OS, o => o.MapFrom(s => s.OS)) // .ForMember(d => d.DB, o => o.MapFrom(s => s.DB)) // .ForMember(d => d.APP, o => o.MapFrom(s => s.APP)); + + CreateMap(); + + } } } diff --git a/PARR.AIHIT/AIHIT/Models/EK.cs b/PARR.AIHIT/AIHIT/Models/EK.cs index 001ea3ec..16320e69 100644 --- a/PARR.AIHIT/AIHIT/Models/EK.cs +++ b/PARR.AIHIT/AIHIT/Models/EK.cs @@ -73,7 +73,7 @@ namespace PARR.AIHIT.Models public string? CTSDirection { get; set; } [Key] [Column("ID")] - public int? ID { get; set; } + public int? AIHID { get; set; } [Column("недостоверные_данные")] public char? IsUnreliableData { get; set; } [Column("РГ_смены")] diff --git a/PARR.AIHIT/AIHIT/PARR.AIHIT.csproj b/PARR.AIHIT/AIHIT/PARR.AIHIT.csproj index 6593887e..44687f99 100644 --- a/PARR.AIHIT/AIHIT/PARR.AIHIT.csproj +++ b/PARR.AIHIT/AIHIT/PARR.AIHIT.csproj @@ -9,7 +9,7 @@ - + diff --git a/PARR.AIHIT/AIHIT/Services/AIHITService.cs b/PARR.AIHIT/AIHIT/Services/AIHITService.cs new file mode 100644 index 00000000..3e1c8d47 --- /dev/null +++ b/PARR.AIHIT/AIHIT/Services/AIHITService.cs @@ -0,0 +1,42 @@ +using Microsoft.Data.SqlClient; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Logging; +using PARR.AIHIT.Context; +using PARR.AIHIT.Models; + +namespace PARR.AIHIT.Services +{ + internal class AIHITService : IAIHITService + { + private readonly AIHITContext context; + private readonly ILogger logger; + + public AIHITService(AIHITContext context, ILogger logger) + { + this.context = context; + this.logger = logger; + } + public List? GetEKList(string respArea) + { + var parameters = new List() { new SqlParameter("@зо",respArea)}; + + try + { + var result = context.Set().FromSqlRaw($"EXEC mao2.dbo.sp_IPP_PARR_PTK_get_EK @зо", parameters.ToArray()).ToList(); + + if (result == null || !result.Any()) + { + logger.LogWarning($"Процедура sp_IPP_PARR_PTK_get_EK вернула пустой список ЭК"); + } + + return result; + } + catch (Exception ex) + { + logger.LogError(ex, $"Ошибка при выполнении ХП sp_IPP_PARR_PTK_get_EK"); + } + + return null; + } + } +} diff --git a/PARR.AIHIT/AIHIT/Services/IAIHITService.cs b/PARR.AIHIT/AIHIT/Services/IAIHITService.cs new file mode 100644 index 00000000..afd88db4 --- /dev/null +++ b/PARR.AIHIT/AIHIT/Services/IAIHITService.cs @@ -0,0 +1,9 @@ +using PARR.AIHIT.Models; + +namespace PARR.AIHIT.Services +{ + internal interface IAIHITService + { + List? GetEKList(string respArea); + } +} diff --git a/PARR.AIHIT/AIHIT/Syncher.cs b/PARR.AIHIT/AIHIT/Syncher.cs index f3428217..36efcb7e 100644 --- a/PARR.AIHIT/AIHIT/Syncher.cs +++ b/PARR.AIHIT/AIHIT/Syncher.cs @@ -3,8 +3,7 @@ using MailKit.Search; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using MimeKit; -using PARR.AIHIT.Context; -using PARR.AIHIT.Models; +using PARR.AIHIT.Services; using PARR.AIHIT.Settings; using PARR.DAL.Contracts; using PARR.DAL.Extensions; @@ -36,6 +35,8 @@ namespace PARR.AIHIT private readonly IApplicationInHostService appInHostService; private readonly IRawDataEKService rawDataEKService; private readonly ISettingService settingService; + private readonly IAIHITService aihitService; + private readonly IApplicationService applicationService; public List AppTypes { get; private set; } = new List(); @@ -53,7 +54,8 @@ namespace PARR.AIHIT IApplicationTypeService appTypeService, IApplicationInHostService appInHostService, IRawDataEKService rawDataEKService, - ISettingService settingService + ISettingService settingService, + IAIHITService aihitService ) { this.hostService = hostService; @@ -63,6 +65,7 @@ namespace PARR.AIHIT this.appInHostService = appInHostService; this.rawDataEKService = rawDataEKService; this.settingService = settingService; + this.aihitService = aihitService; this.logger = logger; this.mailService = mailService; this.syncherSettings = syncherSettings; @@ -219,25 +222,11 @@ namespace PARR.AIHIT //Запускаем хранимую процедуру в АИХ ИТ и складываем в таблицу RawDataEKs, предварительно почистив старые данные foreach (var respArea in respAreas) { - var eksFromAIHIT = new List(); - 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 = 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; + var eksFromAIHIT = aihitService.GetEKList(respArea.Value)?.ToList(); + + if (eksFromAIHIT == null) + continue; - } - } //Удаляем текущие данные по зоне ответственности respArea var toDelete = rawDataEKService.Get().Where(rd => rd.ResponseArea == respArea.Value).ToList(); toDelete.ForEach(d => rawDataEKService.Delete(d)); @@ -245,55 +234,10 @@ namespace PARR.AIHIT 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 - }; + var mappedEK = mapper.Map(ek); + + mappedEK.Id = Guid.NewGuid(); + mappedEK.DateCreated = DateTimeOffset.UtcNow; if (!await rawDataEKService.CreateAsync(mappedEK) || !await rawDataEKService.CommitAsync()) { @@ -347,7 +291,7 @@ namespace PARR.AIHIT foundHost.Status = mappedHost.Status; isChanged = true; } - else if (!foundHost.WorkGroup!.Equals(mappedHost.WorkGroup)) + else if (mappedHost.WorkGroup != null && !foundHost.WorkGroup!.Equals(mappedHost.WorkGroup)) { foundHost.WorkGroup = mappedHost.WorkGroup; isChanged = true; diff --git a/PARR.AIHIT/AIHIT/SyncherInstaller.cs b/PARR.AIHIT/AIHIT/SyncherInstaller.cs index 3b7a733a..9ded749e 100644 --- a/PARR.AIHIT/AIHIT/SyncherInstaller.cs +++ b/PARR.AIHIT/AIHIT/SyncherInstaller.cs @@ -2,6 +2,7 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using PARR.AIHIT.Context; +using PARR.AIHIT.Services; using PARR.AIHIT.Settings; namespace PARR.AIHIT @@ -13,12 +14,21 @@ namespace PARR.AIHIT var syncherSettings = new SyncherSettings(); configuration.GetSection(nameof(SyncherSettings)).Bind(syncherSettings); services.AddSingleton(syncherSettings); + + services.AddDbContext(options => + options.UseSqlServer( + configuration.GetConnectionString("AihitConnection") + )); services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies()); services.AddTransient(); + services.AddTransient(); - //services.AddDbContext (options => + + + + //services.AddDbContext (options => //{ // options.UseSqlServer("server=(10.248.19.97);uid=awhit-ipp-parr;pwd=ET3h$9y1LH#D"); //}); diff --git a/PARR.Worker/PARR.Worker/appsettings.json b/PARR.Worker/PARR.Worker/appsettings.json index dcb20b3c..deb7aab4 100644 --- a/PARR.Worker/PARR.Worker/appsettings.json +++ b/PARR.Worker/PARR.Worker/appsettings.json @@ -1,6 +1,7 @@ { "ConnectionStrings": { - "DefaultConnection": "Server=10.99.253.184;Database=parr;User Id=app_parr; Password=PosdfkhT&)%sdfligL&%5546;" + "DefaultConnection": "Server=10.99.253.184;Database=parr;User Id=app_parr; Password=PosdfkhT&)%sdfligL&%5546;", + "AihitConnection": "Data Source=10.248.19.97; Initial Catalog=mao2;User ID=awhit-ipp-parr;pwd=ET3h$9y1LH#D;TrustServerCertificate=true;" }, "Logging": { "LogLevel": {