2024-05-26 16:27:14 +04:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2024-05-28 22:38:20 +04:00
|
|
|
|
using ServiceStationBusinessLogic.MailWorker;
|
2024-05-27 21:44:16 +04:00
|
|
|
|
using ServiceStationContracts.BindingModels;
|
|
|
|
|
using ServiceStationContracts.BusinessLogicsContracts;
|
2024-05-26 16:27:14 +04:00
|
|
|
|
|
|
|
|
|
namespace ServiceStationRestApi.Controllers
|
|
|
|
|
{
|
|
|
|
|
[Route("api/[controller]/[action]")]
|
|
|
|
|
[ApiController]
|
|
|
|
|
public class ReportController : Controller
|
|
|
|
|
{
|
2024-05-27 21:44:16 +04:00
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
private readonly IExecutorReportLogic _executorReportLogic;
|
2024-05-28 22:40:54 +04:00
|
|
|
|
private readonly IGuarantorReportLogic _guarantorReportLogic;
|
2024-05-28 22:38:20 +04:00
|
|
|
|
private readonly AbstractMailWorker _mailWorker;
|
2024-05-27 21:44:16 +04:00
|
|
|
|
|
2024-05-28 23:36:22 +04:00
|
|
|
|
public ReportController(ILogger<ReportController> logger, IExecutorReportLogic executorReportLogic, AbstractMailWorker abstractMailWorker, IGuarantorLogic guarantorReportLogic)
|
2024-05-27 21:44:16 +04:00
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_executorReportLogic = executorReportLogic;
|
2024-05-28 22:38:20 +04:00
|
|
|
|
_mailWorker = abstractMailWorker;
|
2024-05-28 22:40:54 +04:00
|
|
|
|
_guarantorReportLogic = guarantorReportLogic;
|
2024-05-27 21:44:16 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void CreateExecutorReportToWord(ReportExecutorBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_executorReportLogic.SaveWorkByCarsWordFile(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка создания отчета");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void CreateExecutorReportToExcel(ReportExecutorBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_executorReportLogic.SaveWorkByCarsToExcelFile(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка создания отчета");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void CreateExecutorReportToPdf(ReportExecutorBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_executorReportLogic.SaveTechWorkAndRepairsByCarsToPdfFile(new ReportExecutorBindingModel
|
|
|
|
|
{
|
|
|
|
|
FileName = model.FileName,
|
|
|
|
|
DateFrom = model.DateFrom,
|
|
|
|
|
DateTo = model.DateTo,
|
|
|
|
|
ExecutorId = model.ExecutorId,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка создания отчета");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-28 23:36:22 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void SendPdfToMail(MailSendInfoBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_mailWorker.MailSendAsync(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка отправки письма");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-28 22:40:54 +04:00
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void CreateGuarantorReportToWord(ReportGuarantorBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_guarantorReportLogic.SaveDefectsToWordFile(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка создания отчета");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void CreateGuarantorReportToExcel(ReportGuarantorBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_guarantorReportLogic.SaveDefectsToExcelFile(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка создания отчета");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void CreateGuarantorReportToPdf(ReportGuarantorBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_guarantorReportLogic.SaveSparePartsToPdfFile(new ReportGuarantorBindingModel
|
|
|
|
|
{
|
|
|
|
|
FileName = model.FileName,
|
|
|
|
|
DateFrom = model.DateFrom,
|
|
|
|
|
DateTo = model.DateTo,
|
|
|
|
|
GuarantorId = model.GuarantorId,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка создания отчета");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-28 23:36:22 +04:00
|
|
|
|
|
2024-05-26 16:27:14 +04:00
|
|
|
|
}
|
|
|
|
|
}
|