Загрузка сырых данных из АИХ ИТ
This commit is contained in:
@@ -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<Models.EK, RawDataEK>();
|
||||
//CreateMap<PARR.DAL.Models.Host, PARR.DAL.Models.Host>()
|
||||
// .ForMember(d => d.HostName, o => o.MapFrom(s => s.HostName))
|
||||
// .ForMember(d => d.IP, o => o.MapFrom(s => s.IP))
|
||||
|
||||
@@ -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<V1_ApplicationType> AppTypes { get; private set; } = new List<V1_ApplicationType>();
|
||||
|
||||
@@ -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<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 вурнула пустой список ЭК");
|
||||
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<RawDataEK>(ek);
|
||||
if (!await rawDataEKService.CreateAsync(mappedEK) || !await rawDataEKService.CommitAsync())
|
||||
var eksFromAIHIT = new List<EK>();
|
||||
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<V1_Application> 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);
|
||||
|
||||
@@ -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 = "Статус актуальных ЭК" }
|
||||
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -52,8 +52,8 @@ namespace PARR.DAL.Migrations
|
||||
b.Property<string>("Company")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime?>("CreateTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
b.Property<string>("CreateTime")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("DBType")
|
||||
.HasColumnType("text");
|
||||
@@ -82,8 +82,8 @@ namespace PARR.DAL.Migrations
|
||||
b.Property<string>("EKType")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime?>("EndExplotationDate")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
b.Property<string>("EndExplotationDate")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("FullName")
|
||||
.HasColumnType("text");
|
||||
@@ -124,8 +124,8 @@ namespace PARR.DAL.Migrations
|
||||
b.Property<string>("OldEKFindCode")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime?>("PlannedTimeToRepair")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
b.Property<string>("PlannedTimeToRepair")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Prescription")
|
||||
.HasColumnType("text");
|
||||
@@ -148,14 +148,14 @@ namespace PARR.DAL.Migrations
|
||||
b.Property<string>("ShortName")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime?>("StartExplotationDate")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
b.Property<string>("StartExplotationDate")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Status")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime?>("SysModTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
b.Property<string>("SysModTime")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("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-В эксплуатации"
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ namespace PARR.DAL
|
||||
services.AddTransient<IJobService, JobService>();
|
||||
services.AddTransient<IJobJournalService, JobJournalService>();
|
||||
services.AddTransient<IRawDataEKService, RawDataEKService>();
|
||||
services.AddTransient<ISettingService, SettingService>();
|
||||
//services.AddTransient<ISchedulerService, SchedulerService>();
|
||||
|
||||
//services.AddTransient<IAreasInLayerService, AreasInLayerService>();
|
||||
|
||||
Reference in New Issue
Block a user