Files
parr_api/PARR.AIHITMainLoader/Services/AihitService.cs

72 lines
2.3 KiB
C#

using Microsoft.Data.SqlClient;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using PARR.AIHITMainLoader.Context;
using PARR.AIHITMainLoader.Models;
namespace PARR.AIHITMainLoader.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 IEnumerable<IMainData>? GetPtkData(string respArea)
{
var parameters = new List<SqlParameter>() { new SqlParameter("@зо", respArea) };
try
{
var result = context.Set<PtkData>().FromSqlRaw($"EXEC mao2.dbo.sp_IPP_PARR_PTK_get_EK @зо", parameters.ToArray()).AsEnumerable();
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({respArea})");
}
return new List<IMainData>();
}
public IEnumerable<IMainData>? GetCvkData(string respArea)
{
var parameters = new List<SqlParameter>() { new SqlParameter("@зо", respArea) };
try
{
var result = context.Set<CvkData>().FromSqlRaw($"EXEC mao2.dbo.sp_IPP_PARR_PTK_get_EK_CVK @зо", parameters.ToArray()).AsEnumerable();
if (result == null || !result.Any())
{
logger.LogWarning($"Процедура sp_IPP_PARR_PTK_get_EK_CVK вернула пустой список ЭК");
}
return result;
}
catch (Exception ex)
{
logger.LogError(ex, $"Ошибка при выполнении ХП sp_IPP_PARR_PTK_get_EK_CVK({respArea})");
}
return new List<IMainData>();
}
}
}