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

231 lines
8.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;
2024-04-08 00:02:59 +04:00
/// <summary>
/// Хранилище магазинов
/// </summary>
private readonly IShopStorage _shopStorage;
2024-03-25 00:53:24 +04:00
/// <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>
2024-04-08 00:02:59 +04:00
public ReportLogic(IPlaneStorage planeStorage, IComponentStorage componentStorage, IOrderStorage orderStorage, IShopStorage shopStorage,
2024-03-25 00:53:24 +04:00
AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf)
{
_planeStorage = planeStorage;
_componentStorage = componentStorage;
_orderStorage = orderStorage;
2024-04-08 00:02:59 +04:00
_shopStorage = shopStorage;
2024-03-25 00:53:24 +04:00
_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();
}
2024-04-08 00:02:59 +04:00
/// <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();
}
2024-03-25 00:53:24 +04:00
/// <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)
});
}
2024-04-08 00:02:59 +04:00
/// <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()
});
}
2024-03-25 00:53:24 +04:00
}
}