Загрузка сырых данных из АИХ ИТ

This commit is contained in:
Mikhail Kuznetsov
2023-08-14 11:38:59 +10:00
parent 23b9d5da56
commit e16eecaeba
5 changed files with 128 additions and 84 deletions

View File

@@ -1,4 +1,5 @@
using AutoMapper; using AutoMapper;
using PARR.DAL.Models.AIHIT;
using PARR.DAL.Models.V1; using PARR.DAL.Models.V1;
using System.Xml; 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.WorkGroup, o => o.MapFrom(s => (s.Attributes!["РАБОЧАЯ_ГР_ОТВ_ЗАК"] != null) ? s.Attributes!["РАБОЧАЯ_ГР_ОТВ_ЗАК"]!.Value.Trim() : ""))
.ForMember(d => d.Responsible, o => o.MapFrom(s => s.Attributes!["ОТВЕТСТВЕННЫЙ_ЗАК"]!.Value.Trim())); .ForMember(d => d.Responsible, o => o.MapFrom(s => s.Attributes!["ОТВЕТСТВЕННЫЙ_ЗАК"]!.Value.Trim()));
CreateMap<Models.EK, RawDataEK>();
//CreateMap<PARR.DAL.Models.Host, PARR.DAL.Models.Host>() //CreateMap<PARR.DAL.Models.Host, PARR.DAL.Models.Host>()
// .ForMember(d => d.HostName, o => o.MapFrom(s => s.HostName)) // .ForMember(d => d.HostName, o => o.MapFrom(s => s.HostName))
// .ForMember(d => d.IP, o => o.MapFrom(s => s.IP)) // .ForMember(d => d.IP, o => o.MapFrom(s => s.IP))

View File

@@ -3,11 +3,9 @@ using MailKit.Search;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using MimeKit; using MimeKit;
using PARR.AIHIT.Context;
using PARR.AIHIT.Settings; using PARR.AIHIT.Settings;
using PARR.DAL.Contracts; using PARR.DAL.Contracts;
using PARR.DAL.Extensions; using PARR.DAL.Extensions;
using PARR.DAL.Models.AIHIT;
using PARR.DAL.Models.V1; using PARR.DAL.Models.V1;
using PARR.DAL.Services.Interfaces; using PARR.DAL.Services.Interfaces;
using PARR.DAL.Services.Interfaces.AIHIT; using PARR.DAL.Services.Interfaces.AIHIT;
@@ -28,6 +26,7 @@ namespace PARR.AIHIT
private readonly IApplicationTypeService appTypeService; private readonly IApplicationTypeService appTypeService;
private readonly IApplicationInHostService appInHostService; private readonly IApplicationInHostService appInHostService;
private readonly IRawDataEKService rawDataEKService; private readonly IRawDataEKService rawDataEKService;
private readonly ISettingService settingService;
public List<V1_ApplicationType> AppTypes { get; private set; } = new List<V1_ApplicationType>(); public List<V1_ApplicationType> AppTypes { get; private set; } = new List<V1_ApplicationType>();
@@ -40,7 +39,8 @@ namespace PARR.AIHIT
IApplicationService appService, IApplicationService appService,
IApplicationTypeService appTypeService, IApplicationTypeService appTypeService,
IApplicationInHostService appInHostService, IApplicationInHostService appInHostService,
IRawDataEKService rawDataEKService IRawDataEKService rawDataEKService,
ISettingService settingService
) )
{ {
this.hostService = hostService; this.hostService = hostService;
@@ -49,6 +49,7 @@ namespace PARR.AIHIT
this.appTypeService = appTypeService; this.appTypeService = appTypeService;
this.appInHostService = appInHostService; this.appInHostService = appInHostService;
this.rawDataEKService = rawDataEKService; this.rawDataEKService = rawDataEKService;
this.settingService = settingService;
this.logger = logger; this.logger = logger;
this.mailService = mailService; this.mailService = mailService;
this.syncherSettings = syncherSettings; this.syncherSettings = syncherSettings;
@@ -178,33 +179,9 @@ namespace PARR.AIHIT
// Синхронизация Applications // Синхронизация Applications
await SyncApplicationAndHostAsync(foundHost, hostApplications, true); 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; break;
} }
} }
@@ -217,42 +194,109 @@ namespace PARR.AIHIT
public async Task InvokeFromDatabase() public async Task InvokeFromDatabase()
{ {
var eksFromAIHIT = new List<EK>();
//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 вурнула пустой список ЭК"); var respAreas = settingService.Get().Where(ra => ra.Group == AIHTITSettings.RespAreaGroupName).ToList();
return;
} //Запускаем хранимую процедуру в АИХ ИТ и складываем в таблицу RawDataEKs, предварительно почистив старые данные
rawDataEKService.DeleteAll(); foreach (var respArea in respAreas)
foreach (var ek in eksFromAIHIT)
{ {
// создаем var eksFromAIHIT = new List<EK>();
var mappedEK = mapper.Map<RawDataEK>(ek); using (AIHContext db = new AIHContext())
if (!await rawDataEKService.CreateAsync(mappedEK) || !await rawDataEKService.CommitAsync())
{ {
logger.LogError($"Не удалось создать запись rawDataEK {mappedEK.ShortName}({mappedEK.IP})"); var zo = new Microsoft.Data.SqlClient.SqlParameter
continue; {
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<V1_Application> hostApplications, bool isUpdateDateModified = false) private async Task SyncApplicationAndHostAsync(V1_Host? host, List<V1_Application> hostApplications, bool isUpdateDateModified = false)
{ {
@@ -415,20 +459,6 @@ namespace PARR.AIHIT
return existType; 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) private static string EncodeString(string str)
{ {
byte[] bStr = Encoding.GetEncoding("koi8r").GetBytes(str); byte[] bStr = Encoding.GetEncoding("koi8r").GetBytes(str);

View File

@@ -61,8 +61,10 @@ namespace PARR.DAL.Context
{ {
f.HasData( 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("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("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 = "ResponsibleArea", Name = "DVS", Value = "96-ДВС", 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 = "Статус актуальных ЭК" }
); );
}); });
} }

View File

@@ -52,8 +52,8 @@ namespace PARR.DAL.Migrations
b.Property<string>("Company") b.Property<string>("Company")
.HasColumnType("text"); .HasColumnType("text");
b.Property<DateTime?>("CreateTime") b.Property<string>("CreateTime")
.HasColumnType("timestamp with time zone"); .HasColumnType("text");
b.Property<string>("DBType") b.Property<string>("DBType")
.HasColumnType("text"); .HasColumnType("text");
@@ -82,8 +82,8 @@ namespace PARR.DAL.Migrations
b.Property<string>("EKType") b.Property<string>("EKType")
.HasColumnType("text"); .HasColumnType("text");
b.Property<DateTime?>("EndExplotationDate") b.Property<string>("EndExplotationDate")
.HasColumnType("timestamp with time zone"); .HasColumnType("text");
b.Property<string>("FullName") b.Property<string>("FullName")
.HasColumnType("text"); .HasColumnType("text");
@@ -124,8 +124,8 @@ namespace PARR.DAL.Migrations
b.Property<string>("OldEKFindCode") b.Property<string>("OldEKFindCode")
.HasColumnType("text"); .HasColumnType("text");
b.Property<DateTime?>("PlannedTimeToRepair") b.Property<string>("PlannedTimeToRepair")
.HasColumnType("timestamp with time zone"); .HasColumnType("text");
b.Property<string>("Prescription") b.Property<string>("Prescription")
.HasColumnType("text"); .HasColumnType("text");
@@ -148,14 +148,14 @@ namespace PARR.DAL.Migrations
b.Property<string>("ShortName") b.Property<string>("ShortName")
.HasColumnType("text"); .HasColumnType("text");
b.Property<DateTime?>("StartExplotationDate") b.Property<string>("StartExplotationDate")
.HasColumnType("timestamp with time zone"); .HasColumnType("text");
b.Property<string>("Status") b.Property<string>("Status")
.HasColumnType("text"); .HasColumnType("text");
b.Property<DateTime?>("SysModTime") b.Property<string>("SysModTime")
.HasColumnType("timestamp with time zone"); .HasColumnType("text");
b.Property<string>("SysModUser") b.Property<string>("SysModUser")
.HasColumnType("text"); .HasColumnType("text");
@@ -217,7 +217,7 @@ namespace PARR.DAL.Migrations
Description = "Зона ответственности", Description = "Зона ответственности",
Group = "ResponsibleArea", Group = "ResponsibleArea",
Name = "ZAB", Name = "ZAB",
Value = "94 - ЗАБ" Value = "94-ЗАБ"
}, },
new new
{ {
@@ -227,6 +227,15 @@ namespace PARR.DAL.Migrations
Group = "ResponsibleArea", Group = "ResponsibleArea",
Name = "DVS", Name = "DVS",
Value = "96-ДВС" 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-В эксплуатации"
}); });
}); });

View File

@@ -24,6 +24,7 @@ namespace PARR.DAL
services.AddTransient<IJobService, JobService>(); services.AddTransient<IJobService, JobService>();
services.AddTransient<IJobJournalService, JobJournalService>(); services.AddTransient<IJobJournalService, JobJournalService>();
services.AddTransient<IRawDataEKService, RawDataEKService>(); services.AddTransient<IRawDataEKService, RawDataEKService>();
services.AddTransient<ISettingService, SettingService>();
//services.AddTransient<ISchedulerService, SchedulerService>(); //services.AddTransient<ISchedulerService, SchedulerService>();
//services.AddTransient<IAreasInLayerService, AreasInLayerService>(); //services.AddTransient<IAreasInLayerService, AreasInLayerService>();