PIbd-21_Ihonkina_E.S._Preca.../PrecastConcretePlantBusinessLogic/BusinessLogic/ReportLogic.cs

182 lines
7.0 KiB
C#
Raw Normal View History

2023-03-22 20:02:42 +04:00
using PrecastConcretePlantBusinessLogic.OfficePackage.HelperModels;
using PrecastConcretePlantBusinessLogic.OfficePackage;
using PrecastConcretePlantContracts.BindingModels;
using PrecastConcretePlantContracts.BusinessLogicsContracts;
using PrecastConcretePlantContracts.SearchModels;
using PrecastConcretePlantContracts.StoragesContracts;
using PrecastConcretePlantContracts.ViewModels;
namespace PrecastConcretePlantBusinessLogic.BusinessLogics
{
public class ReportLogic : IReportLogic
{
private readonly IComponentStorage _componentStorage;
private readonly IReinforcedStorage _reinforcedStorage;
private readonly IOrderStorage _orderStorage;
private readonly AbstractSaveToExcel _saveToExcel;
private readonly AbstractSaveToWord _saveToWord;
private readonly AbstractSaveToPdf _saveToPdf;
public ReportLogic(IReinforcedStorage reinforcedStorage, IComponentStorage componentStorage, IOrderStorage orderStorage,
AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf)
{
_reinforcedStorage = reinforcedStorage;
_componentStorage = componentStorage;
_orderStorage = orderStorage;
_saveToExcel = saveToExcel;
_saveToWord = saveToWord;
_saveToPdf = saveToPdf;
}
/// <summary>
/// Получение списка компонент с указанием, в каких изделиях используются
/// </summary>
/// <returns></returns>
public List<ReportReinforcedComponentViewModel> GetReinforcedComponent()
{
var reinforceds = _reinforcedStorage.GetFullList();
var list = new List<ReportReinforcedComponentViewModel>();
foreach (var reinforced in reinforceds)
{
var record = new ReportReinforcedComponentViewModel
{
ReinforcedName = reinforced.ReinforcedName,
Components = new List<(string, int)>(),
TotalCount = 0
};
2023-05-21 23:52:37 +04:00
foreach (var component in reinforced.ReinforcedComponents)
2023-03-22 20:02:42 +04:00
{
2023-05-21 23:52:37 +04:00
record.Components.Add(new(component.Value.Item1.ComponentName, component.Value.Item2));
record.TotalCount += component.Value.Item2;
2023-03-22 20:02:42 +04:00
}
list.Add(record);
}
return list;
}
/// <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,
ReinforcedName = x.ReinforcedName,
OrderStatus = x.Status.ToString(),
Sum = x.Sum
})
.ToList();
}
/// <summary>
/// Сохранение компонент в файл-Word
/// </summary>
/// <param name="model"></param>
public void SaveReinforcedsToWordFile(ReportBindingModel model)
{
_saveToWord.CreateDoc(new WordInfo
{
FileName = model.FileName,
2023-03-22 20:33:00 +04:00
Title = "Список ЖБИ",
2023-03-22 20:02:42 +04:00
Reinforceds = _reinforcedStorage.GetFullList()
});
}
/// <summary>
/// Сохранение компонент с указаеним продуктов в файл-Excel
/// </summary>
/// <param name="model"></param>
public void SaveReinforcedComponentToExcelFile(ReportBindingModel model)
{
_saveToExcel.CreateReport(new ExcelInfo
{
FileName = model.FileName,
2023-03-22 20:33:00 +04:00
Title = "Список ЖБИ",
2023-03-22 20:02:42 +04:00
ReinforcedComponents = GetReinforcedComponent()
});
}
/// <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)
});
}
2023-05-23 20:15:11 +04:00
public List<ReportShopReinforcedViewModel> GetShopReinforced()
{
var shops = _shopStorage.GetFullList();
var list = new List<ReportShopReinforcedViewModel>();
foreach (var shop in shops)
{
var record = new ReportShopReinforcedViewModel
{
ShopName = shop.ShopName,
Reinforceds = new List<(string, int)>(),
TotalCount = 0
};
foreach (var reinforced in shop.ShopReinforceds)
{
record.Reinforceds.Add(new(reinforced.Value.Item1.ReinforcedName, reinforced.Value.Item2));
record.TotalCount += reinforced.Value.Item2;
}
list.Add(record);
}
return list;
}
public List<ReportOrdersByDateViewModel> GetOrdersByDate()
{
return _orderStorage.GetFullList()
.GroupBy(x => x.DateCreate.Date)
.Select(x => new ReportOrdersByDateViewModel
{
DateCreate = x.Key,
Count = x.Count(),
Sum = x.Sum(x => x.Sum)
})
.ToList();
}
public void SaveShopsToWordFile(ReportBindingModel model)
{
_saveToWord.CreateDocShopTable(new WordInfoShopTable
{
FileName = model.FileName,
Title = "Список магазинов",
Shops = _shopStorage.GetFullList()
});
}
public void SaveShopReinforcedToExcelFile(ReportBindingModel model)
{
_saveToExcel.CreateShopReport(new ExcelInfo
{
FileName = model.FileName,
Title = "Список магазинов",
ShopTravels = GetShopReinforced()
});
}
public void SaveOrdersByDateToPdfFile(ReportBindingModel model)
{
_saveToPdf.CreateDocOrdersByDate(new PdfInfoOrdersByDate
{
FileName = model.FileName,
Title = "Список заказов",
Orders = GetOrdersByDate()
});
}
2023-03-22 20:02:42 +04:00
}
}