PIbd-21_MasenkinMS_Aircraft.../AircraftPlant/AircraftPlantBusinessLogic/BusinessLogics/ReportLogic.cs
2024-04-08 00:02:59 +04:00

231 lines
8.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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>
/// Хранилище магазинов
/// </summary>
private readonly IShopStorage _shopStorage;
/// <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, IShopStorage shopStorage,
AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf)
{
_planeStorage = planeStorage;
_componentStorage = componentStorage;
_orderStorage = orderStorage;
_shopStorage = shopStorage;
_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>
/// Получение списка заказов с группировкой по датам
/// </summary>
/// <returns></returns>
public List<ReportGroupOrdersViewModel> GetGroupOrders()
{
return _orderStorage.GetFullList()
.GroupBy(x => x.DateCreate.Date)
.Select(x => new ReportGroupOrdersViewModel
{
DateCreate = x.Key,
Count = x.Count(),
Sum = x.Select(y => y.Sum).Sum()
})
.ToList();
}
/// <summary>
/// Получение списка магазинов с указанием хранимых изделий
/// </summary>
/// <returns></returns>
public List<ReportShopPlanesViewModel> GetShopPlanes()
{
return _shopStorage.GetFullList()
.Select(x => new ReportShopPlanesViewModel
{
ShopName = x.ShopName,
Planes = x.ShopPlanes.Select(x => (x.Value.Item1.PlaneName, x.Value.Item2)).ToList(),
TotalCount = x.ShopPlanes.Select(x => x.Value.Item2).Sum()
})
.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)
});
}
/// <summary>
/// Сохранение магазинов в Word-файл
/// </summary>
/// <param name="model"></param>
public void SaveShopsToWordFile(ReportBindingModel model)
{
_saveToWord.CreateShopsDoc(new WordInfo
{
FileName = model.FileName,
Title = "Список магазинов",
Shops = _shopStorage.GetFullList()
});
}
/// <summary>
/// Сохранение магазинов с указанием изделий в файл-Excel
/// </summary>
/// <param name="model"></param>
public void SaveShopPlanesToExcelFile(ReportBindingModel model)
{
_saveToExcel.CreateShopPlanesReport(new ExcelInfo
{
FileName = model.FileName,
Title = "Ассортимент магазинов",
ShopPlanes = GetShopPlanes()
});
}
/// <summary>
/// Сохранение заказов с группировкой по датам в файл-Pdf
/// </summary>
/// <param name="model"></param>
public void SaveGroupOrdersToPdfFile(ReportBindingModel model)
{
_saveToPdf.CreateGroupOrdersDoc(new PdfInfo
{
FileName= model.FileName,
Title = "Список заказов с группировкой по датам",
GroupOrders = GetGroupOrders()
});
}
}
}