PIbd-21_MasenkinMS_Aircraft.../AircraftPlant/AircraftPlantBusinessLogic/BusinessLogics/ReportLogic.cs

150 lines
5.5 KiB
C#
Raw Normal View History

2024-03-25 00:53:24 +04:00
using AircraftPlantBusinessLogic.OfficePackage;
using AircraftPlantBusinessLogic.OfficePackage.HelperModels;
using AircraftPlantContracts.BindingModels;
using AircraftPlantContracts.BusinessLogicsContracts;
using AircraftPlantContracts.SearchModels;
using AircraftPlantContracts.StoragesContracts;
using AircraftPlantContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AircraftPlantBusinessLogic.BusinessLogics
{
/// <summary>
/// Реализация интерфейса бизнес-логики для создания отчетов
/// </summary>
public class ReportLogic : IReportLogic
{
/// <summary>
/// Хранилище компонентов
/// </summary>
private readonly IComponentStorage _componentStorage;
/// <summary>
/// Хранилище изделий
/// </summary>
private readonly IPlaneStorage _planeStorage;
/// <summary>
/// Хранилище заказов
/// </summary>
private readonly IOrderStorage _orderStorage;
/// <summary>
/// Взаимодействие с отчетами в Excel-формате
/// </summary>
private readonly AbstractSaveToExcel _saveToExcel;
/// <summary>
/// Взаимодействие с отчетами в Word-формате
/// </summary>
private readonly AbstractSaveToWord _saveToWord;
/// <summary>
/// Взаимодействие с отчетами в Pdf-формате
/// </summary>
private readonly AbstractSaveToPdf _saveToPdf;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="planeStorage"></param>
/// <param name="componentStorage"></param>
/// <param name="orderStorage"></param>
/// <param name="saveToExcel"></param>
/// <param name="saveToWord"></param>
/// <param name="saveToPdf"></param>
public ReportLogic(IPlaneStorage planeStorage, IComponentStorage componentStorage, IOrderStorage orderStorage,
AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf)
{
_planeStorage = planeStorage;
_componentStorage = componentStorage;
_orderStorage = orderStorage;
_saveToExcel = saveToExcel;
_saveToWord = saveToWord;
_saveToPdf = saveToPdf;
}
/// <summary>
/// Получение списка изделий с расшифровкой по компонентам
/// </summary>
/// <returns></returns>
public List<ReportPlaneComponentViewModel> GetPlaneComponents()
{
return _planeStorage.GetFullList().Select(x => new ReportPlaneComponentViewModel
{
PlaneName = x.PlaneName,
Components = x.PlaneComponents.Select(x => (x.Value.Item1.ComponentName, x.Value.Item2)).ToList(),
TotalCount = x.PlaneComponents.Select(x => x.Value.Item2).Sum()
}).ToList();
}
/// <summary>
/// Получение списка заказов за определенный период
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public List<ReportOrdersViewModel> GetOrders(ReportBindingModel model)
{
return _orderStorage.GetFilteredList(new OrderSearchModel { DateFrom = model.DateFrom, DateTo = model.DateTo })
.Select(x => new ReportOrdersViewModel
{
Id = x.Id,
DateCreate = x.DateCreate,
PlaneName = x.PlaneName,
Sum = x.Sum,
Status = x.Status.ToString()
})
.ToList();
}
/// <summary>
/// Сохранение изделий в Word-файл
/// </summary>
/// <param name="model"></param>
public void SavePlanesToWordFile(ReportBindingModel model)
{
_saveToWord.CreateDoc(new WordInfo
{
FileName = model.FileName,
Title = "Список изделий",
Planes = _planeStorage.GetFullList()
});
}
/// <summary>
/// Сохранение изделий с расшифровкой по компонентам в Excel-файл
/// </summary>
/// <param name="model"></param>
public void SavePlaneComponentsToExcelFile(ReportBindingModel model)
{
_saveToExcel.CreateReport(new ExcelInfo
{
FileName = model.FileName,
Title = "Список изделий",
PlaneComponents = GetPlaneComponents()
});
}
/// <summary>
/// Сохранение заказов в Pdf-файл
/// </summary>
/// <param name="model"></param>
public void SaveOrdersToPdfFile(ReportBindingModel model)
{
_saveToPdf.CreateDoc(new PdfInfo
{
FileName = model.FileName,
Title = "Список заказов",
DateFrom = model.DateFrom!.Value,
DateTo = model.DateTo!.Value,
Orders = GetOrders(model)
});
}
}
}