AIHITService

This commit is contained in:
Mikhail Kuznetsov
2023-08-23 16:57:38 +10:00
parent 906982d08d
commit f3914c07a4
10 changed files with 105 additions and 91 deletions

View File

@@ -1,16 +0,0 @@
using Microsoft.EntityFrameworkCore;
using PARR.AIHIT.Models;
namespace PARR.AIHIT.Context
{
internal class AIHContext : DbContext
{
public DbSet<EK> 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;");
}
}
}

View File

@@ -0,0 +1,19 @@
using Microsoft.EntityFrameworkCore;
using PARR.AIHIT.Models;
namespace PARR.AIHIT.Context
{
internal class AIHITContext : DbContext
{
public AIHITContext(DbContextOptions<AIHITContext> options) : base(options) { }
public DbSet<EK> 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;");
//}
}
}

View File

@@ -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<EK, RawDataEK>();
}
}
}

View File

@@ -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("РГ_смены")]

View File

@@ -9,7 +9,7 @@
<ItemGroup>
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.10" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.1" />
</ItemGroup>
<ItemGroup>

View File

@@ -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<AIHITService> logger;
public AIHITService(AIHITContext context, ILogger<AIHITService> logger)
{
this.context = context;
this.logger = logger;
}
public List<EK>? GetEKList(string respArea)
{
var parameters = new List<SqlParameter>() { new SqlParameter("@зо",respArea)};
try
{
var result = context.Set<EK>().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;
}
}
}

View File

@@ -0,0 +1,9 @@
using PARR.AIHIT.Models;
namespace PARR.AIHIT.Services
{
internal interface IAIHITService
{
List<EK>? GetEKList(string respArea);
}
}

View File

@@ -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<ApplicationType> AppTypes { get; private set; } = new List<ApplicationType>();
@@ -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<EK>();
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<RawDataEK>(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;

View File

@@ -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<AIHITContext>(options =>
options.UseSqlServer(
configuration.GetConnectionString("AihitConnection")
));
services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
services.AddTransient<ISyncher, Syncher>();
services.AddTransient<IAIHITService,AIHITService>();
//services.AddDbContext <AIHContext> (options =>
//services.AddDbContext <AIHITContext> (options =>
//{
// options.UseSqlServer("server=(10.248.19.97);uid=awhit-ipp-parr;pwd=ET3h$9y1LH#D");
//});

View File

@@ -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": {