feat(dal,aihitLoader,aihitSyncer): добавлены новые типы программного обеспечения. При синхронизации хосты находятся по имени ЭК вместо IP-адерса

This commit is contained in:
Mikhail Kuznetsov
2024-04-18 10:18:14 +10:00
parent f6342719b6
commit 3d89e5956c
11 changed files with 2877 additions and 85 deletions

View File

@@ -71,7 +71,7 @@ namespace PARR.AIHITLoader
logger.LogDebug($"Список ЭК переданных в RabbitMQ: {string.Join(", ", batch)}");
}
else
logger.LogError($"Ошибка при передаче нарядов в Rabbit, не переданные сообщения: {string.Join(", ", sendResult.NotSendMessages)}");
logger.LogError($"Ошибка при передаче нарядов в Rabbit, не переданные сообщения: {string.Join(", ", sendResult.NotSendMessages!)}");
}
}
@@ -86,7 +86,8 @@ namespace PARR.AIHITLoader
private List<EK> FilterData(List<EK> aihitData)
{
var vrt = aihitData.Where(ek => ek.EKFindCode!.StartsWith("ВРТ", true, CultureInfo.GetCultureInfo("ru-RU"))).ToList();
return vrt.Where(vrt => vrt.IP != null).ToList();
//return vrt.Where(vrt => vrt.IP != null).ToList();
return vrt.ToList();
}
private List<EK>? GetDataFromAihit(string respArea)
@@ -108,11 +109,15 @@ namespace PARR.AIHITLoader
{
EK = ek.EKFindCode!,
IP = ek.IP,
APPType = ek.APPType,
DBType = ek.DBType,
OSType = ek.OSType,
APP = ek.APPType,
DB = ek.DBType,
CKBS = ek.CKBSServerType,
IB = ek.IBServerType,
SI = ek.InfrastructureServerType,
SM = ek.MonitoringServerType,
OS = ek.OSType,
WorkGroup = ek.WorkGroup,
Status = (ek.Status == "00-ГВЦ")? "99-ГВЦ": ek.Status!,
Status = (ek.Status == "00-ГВЦ") ? "99-ГВЦ" : ek.Status!,
ResponseArea = ek.ResponseArea!
};
}

View File

@@ -92,7 +92,7 @@ namespace PARR.AIHITSyncer
//private async Task SyncHostToScopeAsync(IHostService hostService, AihitDataMq objFromQuery)
//{
// //ищем существующий хост в БД
// var host = await hostService.GetHostWithAppsAsync(objFromQuery.IP);
// var host = await hostService.GetHostWithAppsByIpAsync(objFromQuery.IP);
// var isNew = false;
// //если не нашли - создаём
// if (host == null)
@@ -136,7 +136,7 @@ namespace PARR.AIHITSyncer
// logger.LogInformation($"----- Создан узел: {host.Id} -----");
// return await hostService.GetHostWithAppsAsync(host.IP);
// return await hostService.GetHostWithAppsByIpAsync(host.IP);
//}

View File

@@ -54,7 +54,8 @@ namespace PARR.AIHITSyncer.Services
private async Task SyncHostAsync(AihitDataMq objFromQuery)
{
//ищем существующий хост в БД
var host = await hostService.GetHostWithAppsAsync(objFromQuery.IP);
//var host = await hostService.GetHostWithAppsByIpAsync(objFromQuery.IP);
var host = await hostService.GetHostWithAppsByEkAsync(objFromQuery.EK);
var isNew = false;
//если не нашли - создаём
if (host == null)
@@ -95,7 +96,8 @@ namespace PARR.AIHITSyncer.Services
logger.LogInformation($"----- Создан узел: {host.Id} -----");
return await hostService.GetHostWithAppsAsync(host.IP);
//return await hostService.GetHostWithAppsByIpAsync(host.IP);
return await hostService.GetHostWithAppsByEkAsync(host.Ek);
}
@@ -137,9 +139,9 @@ namespace PARR.AIHITSyncer.Services
{
var applications = new List<Application>();
if (objFromQuery.APPType != null)
if (objFromQuery.APP != null)
{
var appList = objFromQuery.APPType.Split(new char[] { ',', ';' }).Distinct().ToList();
var appList = objFromQuery.APP.Split(new char[] { ',', ';' }).Distinct().ToList();
foreach (var app in appList)
{
var created = await CreateAppIfNotExistAsync(app, ApplicationTypesEnum.APP);
@@ -147,9 +149,9 @@ namespace PARR.AIHITSyncer.Services
applications.Add(created);
}
}
if (objFromQuery.DBType != null)
if (objFromQuery.DB != null)
{
var appList = objFromQuery.DBType.Split(new char[] { ',', ';' }).Distinct().ToList();
var appList = objFromQuery.DB.Split(new char[] { ',', ';' }).Distinct().ToList();
foreach (var app in appList)
{
var created = await CreateAppIfNotExistAsync(app, ApplicationTypesEnum.DB);
@@ -157,9 +159,49 @@ namespace PARR.AIHITSyncer.Services
applications.Add(created);
}
}
if (objFromQuery.OSType != null)
if (objFromQuery.CKBS != null)
{
var appList = objFromQuery.OSType.Split(new char[] { ',', ';' }).Distinct().ToList();
var appList = objFromQuery.CKBS.Split(new char[] { ',', ';' }).Distinct().ToList();
foreach (var app in appList)
{
var created = await CreateAppIfNotExistAsync(app, ApplicationTypesEnum.CKBS);
if (created != null)
applications.Add(created);
}
}
if (objFromQuery.IB != null)
{
var appList = objFromQuery.IB.Split(new char[] { ',', ';' }).Distinct().ToList();
foreach (var app in appList)
{
var created = await CreateAppIfNotExistAsync(app, ApplicationTypesEnum.IB);
if (created != null)
applications.Add(created);
}
}
if (objFromQuery.SI != null)
{
var appList = objFromQuery.SI.Split(new char[] { ',', ';' }).Distinct().ToList();
foreach (var app in appList)
{
var created = await CreateAppIfNotExistAsync(app, ApplicationTypesEnum.SI);
if (created != null)
applications.Add(created);
}
}
if (objFromQuery.SM != null)
{
var appList = objFromQuery.SM.Split(new char[] { ',', ';' }).Distinct().ToList();
foreach (var app in appList)
{
var created = await CreateAppIfNotExistAsync(app, ApplicationTypesEnum.SM);
if (created != null)
applications.Add(created);
}
}
if (objFromQuery.OS != null)
{
var appList = objFromQuery.OS.Split(new char[] { ',', ';' }).Distinct().ToList();
foreach (var app in appList)
{
var created = await CreateAppIfNotExistAsync(app, ApplicationTypesEnum.OS);

View File

@@ -7,9 +7,13 @@
{
public required string EK { get; set; }
public string? IP { get; set; }
public string? DBType { get; set; }
public string? APPType { get; set; }
public string? OSType { get; set; }
public string? DB { get; set; }
public string? APP { get; set; }
public string? CKBS { get; set; }
public string? IB { get; set; }
public string? SI { get; set; }
public string? SM { get; set; }
public string? OS { get; set; }
public string? WorkGroup { get; set; }
public required string Status { get; set; }
public required string ResponseArea { get; set; }

View File

@@ -62,9 +62,13 @@ namespace PARR.DAL.Context
modelBuilder.Entity<ApplicationType>(f =>
{
f.HasData(
new() { Id = new Guid("32c28386-6f13-4f7b-8508-be165b7fabdb"), DateCreated = dateCreated, DateModified = null, Name = ApplicationTypesEnum.APP.ToString(), Description = "Поле СП xml АИХ ИТ" },
new() { Id = new Guid("7848a96c-cdee-48c1-a786-de9cb889723a"), DateCreated = dateCreated, DateModified = null, Name = ApplicationTypesEnum.OS.ToString(), Description = "Поле ОС xml АИХ ИТ" },
new() { Id = new Guid("aae2636f-b93a-42dc-873e-0764a90a0a40"), DateCreated = dateCreated, DateModified = null, Name = ApplicationTypesEnum.DB.ToString(), Description = "Поле СУБД xml АИХ ИТ" }
new() { Id = new Guid("32c28386-6f13-4f7b-8508-be165b7fabdb"), DateCreated = dateCreated, DateModified = null, Name = ApplicationTypesEnum.APP.ToString(), Description = "Сервер приложений" },
new() { Id = new Guid("7848a96c-cdee-48c1-a786-de9cb889723a"), DateCreated = dateCreated, DateModified = null, Name = ApplicationTypesEnum.OS.ToString(), Description = "ОС" },
new() { Id = new Guid("aae2636f-b93a-42dc-873e-0764a90a0a40"), DateCreated = dateCreated, DateModified = null, Name = ApplicationTypesEnum.DB.ToString(), Description = "СУБД" },
new() { Id = new Guid("749f4c34-b883-4f28-90dd-c161dd3c4270"), DateCreated = dateCreated, DateModified = null, Name = ApplicationTypesEnum.CKBS.ToString(), Description = "ЦК БС" },
new() { Id = new Guid("0bd96f9b-d36b-4dfb-bd8a-9c356bc6912b"), DateCreated = dateCreated, DateModified = null, Name = ApplicationTypesEnum.IB.ToString(), Description = "ИБ" },
new() { Id = new Guid("4466148b-510d-4423-a58f-ce878152ff01"), DateCreated = dateCreated, DateModified = null, Name = ApplicationTypesEnum.SI.ToString(), Description = "Инфраструктура" },
new() { Id = new Guid("725a96db-358e-489b-a7c9-a84b06ec15df"), DateCreated = dateCreated, DateModified = null, Name = ApplicationTypesEnum.SM.ToString(), Description = "Мониторинг" }
);
});
#endregion

View File

@@ -4,6 +4,10 @@
{
APP,
OS,
DB
DB,
CKBS,
IB,
SI,
SM
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,94 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional
namespace PARR.DAL.Migrations
{
/// <inheritdoc />
public partial class TblApplicationTypeAddValues : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.UpdateData(
table: "ApplicationTypes",
keyColumn: "Id",
keyValue: new Guid("32c28386-6f13-4f7b-8508-be165b7fabdb"),
column: "Description",
value: "Сервер приложений");
migrationBuilder.UpdateData(
table: "ApplicationTypes",
keyColumn: "Id",
keyValue: new Guid("7848a96c-cdee-48c1-a786-de9cb889723a"),
column: "Description",
value: "ОС");
migrationBuilder.UpdateData(
table: "ApplicationTypes",
keyColumn: "Id",
keyValue: new Guid("aae2636f-b93a-42dc-873e-0764a90a0a40"),
column: "Description",
value: "СУБД");
migrationBuilder.InsertData(
table: "ApplicationTypes",
columns: new[] { "Id", "DateCreated", "DateModified", "Description", "Name" },
values: new object[,]
{
{ new Guid("0bd96f9b-d36b-4dfb-bd8a-9c356bc6912b"), new DateTimeOffset(new DateTime(2023, 5, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)), null, "ИБ", "IB" },
{ new Guid("4466148b-510d-4423-a58f-ce878152ff01"), new DateTimeOffset(new DateTime(2023, 5, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)), null, "Инфраструктура", "SI" },
{ new Guid("725a96db-358e-489b-a7c9-a84b06ec15df"), new DateTimeOffset(new DateTime(2023, 5, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)), null, "Мониторинг", "SM" },
{ new Guid("749f4c34-b883-4f28-90dd-c161dd3c4270"), new DateTimeOffset(new DateTime(2023, 5, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)), null, "ЦК БС", "CKBS" }
});
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DeleteData(
table: "ApplicationTypes",
keyColumn: "Id",
keyValue: new Guid("0bd96f9b-d36b-4dfb-bd8a-9c356bc6912b"));
migrationBuilder.DeleteData(
table: "ApplicationTypes",
keyColumn: "Id",
keyValue: new Guid("4466148b-510d-4423-a58f-ce878152ff01"));
migrationBuilder.DeleteData(
table: "ApplicationTypes",
keyColumn: "Id",
keyValue: new Guid("725a96db-358e-489b-a7c9-a84b06ec15df"));
migrationBuilder.DeleteData(
table: "ApplicationTypes",
keyColumn: "Id",
keyValue: new Guid("749f4c34-b883-4f28-90dd-c161dd3c4270"));
migrationBuilder.UpdateData(
table: "ApplicationTypes",
keyColumn: "Id",
keyValue: new Guid("32c28386-6f13-4f7b-8508-be165b7fabdb"),
column: "Description",
value: "Поле СП xml АИХ ИТ");
migrationBuilder.UpdateData(
table: "ApplicationTypes",
keyColumn: "Id",
keyValue: new Guid("7848a96c-cdee-48c1-a786-de9cb889723a"),
column: "Description",
value: "Поле ОС xml АИХ ИТ");
migrationBuilder.UpdateData(
table: "ApplicationTypes",
keyColumn: "Id",
keyValue: new Guid("aae2636f-b93a-42dc-873e-0764a90a0a40"),
column: "Description",
value: "Поле СУБД xml АИХ ИТ");
}
}
}

View File

@@ -173,22 +173,50 @@ namespace PARR.DAL.Migrations
{
Id = new Guid("32c28386-6f13-4f7b-8508-be165b7fabdb"),
DateCreated = new DateTimeOffset(new DateTime(2023, 5, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)),
Description = "Поле СП xml АИХ ИТ",
Description = "Сервер приложений",
Name = "APP"
},
new
{
Id = new Guid("7848a96c-cdee-48c1-a786-de9cb889723a"),
DateCreated = new DateTimeOffset(new DateTime(2023, 5, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)),
Description = "Поле ОС xml АИХ ИТ",
Description = "ОС",
Name = "OS"
},
new
{
Id = new Guid("aae2636f-b93a-42dc-873e-0764a90a0a40"),
DateCreated = new DateTimeOffset(new DateTime(2023, 5, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)),
Description = "Поле СУБД xml АИХ ИТ",
Description = "СУБД",
Name = "DB"
},
new
{
Id = new Guid("749f4c34-b883-4f28-90dd-c161dd3c4270"),
DateCreated = new DateTimeOffset(new DateTime(2023, 5, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)),
Description = "ЦК БС",
Name = "CKBS"
},
new
{
Id = new Guid("0bd96f9b-d36b-4dfb-bd8a-9c356bc6912b"),
DateCreated = new DateTimeOffset(new DateTime(2023, 5, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)),
Description = "ИБ",
Name = "IB"
},
new
{
Id = new Guid("4466148b-510d-4423-a58f-ce878152ff01"),
DateCreated = new DateTimeOffset(new DateTime(2023, 5, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)),
Description = "Инфраструктура",
Name = "SI"
},
new
{
Id = new Guid("725a96db-358e-489b-a7c9-a84b06ec15df"),
DateCreated = new DateTimeOffset(new DateTime(2023, 5, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)),
Description = "Мониторинг",
Name = "SM"
});
});

View File

@@ -21,73 +21,40 @@ namespace PARR.DAL.Services.Implementations
this.logger = logger;
}
public async Task<Host?> GetHostWithAppsAsync(string IP)
{
//try
//{
// var host = await EntitySet.FirstAsync(h => h.IP == IP && h.RegionalEK == RegionalEK);
// return host;
//}
//catch
//{
// logger.LogInformation($"Не найден узел с IP адресом {IP} и региональным ЭК {RegionalEK}");
// return null;
//}
return await EntitySet
.Include(t => t.ApplicationsInHosts).ThenInclude(a => a.Application).ThenInclude(t => t!.ApplicationType)
public async Task<Host?> GetHostWithAppsByIpAsync(string ip)
{
return await GetHostWithIncludeApps()
.AsSplitQuery()
.FirstOrDefaultAsync(h => h.IP == IP);
.FirstOrDefaultAsync(h => h.IP == ip);
}
public async Task<Host?> GetHostWithAppsByEkAsync(string ek)
{
return await GetHostWithIncludeApps()
.AsSplitQuery()
.FirstOrDefaultAsync(h => h.Ek.ToLower() == ek.ToLower());
}
private IQueryable<Host> GetHostWithIncludeApps()
{
return EntitySet.Include(t => t.ApplicationsInHosts).ThenInclude(a => a.Application).ThenInclude(t => t!.ApplicationType);
}
public async Task<Host?> GetByIpAsync(string ip)
{
return await EntitySet.FirstOrDefaultAsync(t => t.IP == ip);
}
//public async Task<Host?> GetHostByRegionalEKAsync(string RegionalEK)И
//{
// try
// {
// var host = await EntitySet.FirstAsync(h => h.RegionalEK == RegionalEK);
// return host;
// }
// catch
// {
// logger.LogInformation($"Не найден узел с региональным ЭК {RegionalEK}");
// return null;
// }
//}
//public async Task<bool> UpdateAsync(Host host)
//{
// var orig = await EntitySet.FirstAsync(h => h.IP == host.IP);
// if (orig == null)
// return false;
public async Task<Host?> GetByEkAsync(string ek)
{
return await EntitySet.FirstOrDefaultAsync(t => t.Ek.ToLower() == ek.ToLower());
}
// orig.DateModified = DateTimeOffset.UtcNow;
// orig.HostName = host.HostName;
// orig.RegionalEK = host.RegionalEK;
// orig.LinkEK = host.LinkEK;
// orig.Status = host.Status;
// orig.WorkGroup = host.WorkGroup;
// orig.Responsible = host.Responsible;
// orig.OS = host.OS;
// orig.DB = host.DB;
// orig.APP = host.APP;
// if (!await CommitAsync())
// {
// logger.LogError($"Ошибка обновления узла {host.IP}");
// return false;
// }
// else
// {
// logger.LogInformation($"Обновлен узел {host.IP}");
// return true;
// }
//}
}
}

View File

@@ -5,10 +5,10 @@ namespace PARR.DAL.Services.Interfaces
{
public interface IHostService : IBaseService<Host>
{
Task<Host?> GetHostWithAppsAsync(string ip);
Task<Host?> GetHostWithAppsByIpAsync(string ip);
Task<Host?> GetByIpAsync(string ip);
Task<Host?> GetHostWithAppsByEkAsync(string ek);
Task<Host?> GetByEkAsync(string ek);
}
}