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 { /// /// Реализация интерфейса бизнес-логики для создания отчетов /// public class ReportLogic : IReportLogic { /// /// Хранилище компонентов /// private readonly IComponentStorage _componentStorage; /// /// Хранилище изделий /// private readonly IPlaneStorage _planeStorage; /// /// Хранилище заказов /// private readonly IOrderStorage _orderStorage; /// /// Взаимодействие с отчетами в Excel-формате /// private readonly AbstractSaveToExcel _saveToExcel; /// /// Взаимодействие с отчетами в Word-формате /// private readonly AbstractSaveToWord _saveToWord; /// /// Взаимодействие с отчетами в Pdf-формате /// private readonly AbstractSaveToPdf _saveToPdf; /// /// Конструктор /// /// /// /// /// /// /// 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; } /// /// Получение списка изделий с расшифровкой по компонентам /// /// public List 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(); } /// /// Получение списка заказов за определенный период /// /// /// public List 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(); } /// /// Сохранение изделий в Word-файл /// /// public void SavePlanesToWordFile(ReportBindingModel model) { _saveToWord.CreateDoc(new WordInfo { FileName = model.FileName, Title = "Список изделий", Planes = _planeStorage.GetFullList() }); } /// /// Сохранение изделий с расшифровкой по компонентам в Excel-файл /// /// public void SavePlaneComponentsToExcelFile(ReportBindingModel model) { _saveToExcel.CreateReport(new ExcelInfo { FileName = model.FileName, Title = "Список изделий", PlaneComponents = GetPlaneComponents() }); } /// /// Сохранение заказов в Pdf-файл /// /// public void SaveOrdersToPdfFile(ReportBindingModel model) { _saveToPdf.CreateDoc(new PdfInfo { FileName = model.FileName, Title = "Список заказов", DateFrom = model.DateFrom!.Value, DateTo = model.DateTo!.Value, Orders = GetOrders(model) }); } } }