From 56866b458c161e0b45fa6863f09f68eb3474ea37 Mon Sep 17 00:00:00 2001 From: ujijrujijr Date: Wed, 1 May 2024 14:03:33 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BD=D0=B5=D0=B4=D0=BE=D0=B4=D0=B5=D0=BB?= =?UTF-8?q?=D0=B0=D0=BD=D0=BD=D0=BE=D0=B5,=20=D1=81=20=D0=BE=D1=88=D0=B8?= =?UTF-8?q?=D0=B1=D0=BA=D0=B0=D0=BC=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/ReportImplementerLogic.cs | 41 +++++++++++++++ .../BindingModels/ReportBindingModel.cs | 15 ++++++ .../IReportImplementerLogic.cs | 28 ++++++++++ .../StorageContracts/IOrderStorage.cs | 1 + .../ReportOrderAssemblyViewModel.cs | 23 ++++++++ .../ReportOrderRequestAssemblyViewModel.cs | 25 +++++++++ .../Implements/OrderStorage.cs | 52 +++++++++++++++++++ .../Implements/RequestStorage.cs | 1 + .../Implements/ShipmentStorage.cs | 1 + 9 files changed, 187 insertions(+) create mode 100644 ComputerShopBusinessLogic/BusinessLogics/ReportImplementerLogic.cs create mode 100644 ComputerShopContracts/BindingModels/ReportBindingModel.cs create mode 100644 ComputerShopContracts/BusinessLogicContracts/IReportImplementerLogic.cs create mode 100644 ComputerShopContracts/ViewModels/ReportOrderAssemblyViewModel.cs create mode 100644 ComputerShopContracts/ViewModels/ReportOrderRequestAssemblyViewModel.cs diff --git a/ComputerShopBusinessLogic/BusinessLogics/ReportImplementerLogic.cs b/ComputerShopBusinessLogic/BusinessLogics/ReportImplementerLogic.cs new file mode 100644 index 0000000..3ef3fb0 --- /dev/null +++ b/ComputerShopBusinessLogic/BusinessLogics/ReportImplementerLogic.cs @@ -0,0 +1,41 @@ +using ComputerShopContracts.BindingModels; +using ComputerShopContracts.BusinessLogicContracts; +using ComputerShopContracts.SearchModels; +using ComputerShopContracts.StorageContracts; +using ComputerShopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputerShopBusinessLogic.BusinessLogics +{ + public class ReportImplementerLogic : IReportImplementerLogic + { + private readonly IAssemblyStorage _assemblyStorage; + private readonly IRequestStorage _requestStorage; + private readonly IOrderStorage _orderStorage; + + public ReportImplementerLogic(IAssemblyStorage assemblyStorage, IRequestStorage requestStorage, IOrderStorage orderStorage) + { + _assemblyStorage = assemblyStorage; + _requestStorage = requestStorage; + _orderStorage = orderStorage; + } + /// + /// Отчёт для doc/xls + /// + /// + public List GetOrderAssemblies(List selectedOrders) { + //!!!исправить на filteredList + return _orderStorage.GetReportWithAssembly(selectedOrders).Select(x => new ReportOrderAssemblyViewModel + { + OrderId = x.Id, + DateCreateOrder = x.DateCreate, + OrderSum = x.Sum, + + }); + } + } +} diff --git a/ComputerShopContracts/BindingModels/ReportBindingModel.cs b/ComputerShopContracts/BindingModels/ReportBindingModel.cs new file mode 100644 index 0000000..5edb012 --- /dev/null +++ b/ComputerShopContracts/BindingModels/ReportBindingModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputerShopContracts.BindingModels +{ + public class ReportBindingModel + { + public string FileName { get; set; } = string.Empty; + public DateTime? DateFrom { get; set; } + public DateTime? DateTo { get; set; } + } +} diff --git a/ComputerShopContracts/BusinessLogicContracts/IReportImplementerLogic.cs b/ComputerShopContracts/BusinessLogicContracts/IReportImplementerLogic.cs new file mode 100644 index 0000000..9198ee4 --- /dev/null +++ b/ComputerShopContracts/BusinessLogicContracts/IReportImplementerLogic.cs @@ -0,0 +1,28 @@ +using ComputerShopContracts.BindingModels; +using ComputerShopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputerShopContracts.BusinessLogicContracts +{ + public interface IReportImplementerLogic + { + /// + /// Получение отчёта для word/excel + /// + /// + List GetOrderAssemblies(); + + /// + /// Получение отчёта для почты + /// + /// + List GetOrderRequestAssemblies(); + void SaveOrderAssembliesToWordFile(ReportBindingModel model); + + void SaveOrderAssembliesToExcelFile(ReportBindingModel model); + } +} diff --git a/ComputerShopContracts/StorageContracts/IOrderStorage.cs b/ComputerShopContracts/StorageContracts/IOrderStorage.cs index add00ea..e2ec1f1 100644 --- a/ComputerShopContracts/StorageContracts/IOrderStorage.cs +++ b/ComputerShopContracts/StorageContracts/IOrderStorage.cs @@ -17,5 +17,6 @@ namespace ComputerShopContracts.StorageContracts OrderViewModel? Insert(OrderBindingModel model); OrderViewModel? Update(OrderBindingModel model); OrderViewModel? Delete(OrderBindingModel model); + List GetReportWithAssembly(List model); } } diff --git a/ComputerShopContracts/ViewModels/ReportOrderAssemblyViewModel.cs b/ComputerShopContracts/ViewModels/ReportOrderAssemblyViewModel.cs new file mode 100644 index 0000000..8c457c5 --- /dev/null +++ b/ComputerShopContracts/ViewModels/ReportOrderAssemblyViewModel.cs @@ -0,0 +1,23 @@ +using ComputerShopDataModels.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputerShopContracts.ViewModels +{ + public class ReportOrderAssemblyViewModel + { + //!!!мб тут хранить списки промежуточных сущностей + public int OrderId { get; set; } + public DateTime DateCreateOrder { get; set; } + public double OrderSum { get; set; } + + public OrderStatus OrderStatus { get; set; } + + public string AssemblyName { get; set; } + public string AssemblyCategory { get; set; } + public double AssemblyCost { get; set; } + } +} diff --git a/ComputerShopContracts/ViewModels/ReportOrderRequestAssemblyViewModel.cs b/ComputerShopContracts/ViewModels/ReportOrderRequestAssemblyViewModel.cs new file mode 100644 index 0000000..fd9027d --- /dev/null +++ b/ComputerShopContracts/ViewModels/ReportOrderRequestAssemblyViewModel.cs @@ -0,0 +1,25 @@ +using ComputerShopDataModels.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputerShopContracts.ViewModels +{ + public class ReportOrderRequestAssemblyViewModel + { + //!!!мб тут хранить списки промежуточных сущностей + public int OrderID { get; set; } + public DateTime DateCreateOrder { get; set; } + public double OrderSum { get; set; } + + public OrderStatus OrderStatus { get; set; } + public int RequestId { get; set; } + public string ClientFIO { get; set; } + public DateTime DateRequest { get; set; } + public string AssemblyName { get; set; } + public string AssemblyCategory { get; set; } + public double AssemblyCost { get; set; } + } +} diff --git a/ComputerShopDatabaseImplement/Implements/OrderStorage.cs b/ComputerShopDatabaseImplement/Implements/OrderStorage.cs index 80e005a..3999933 100644 --- a/ComputerShopDatabaseImplement/Implements/OrderStorage.cs +++ b/ComputerShopDatabaseImplement/Implements/OrderStorage.cs @@ -10,11 +10,13 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using static Microsoft.EntityFrameworkCore.DbLoggerCategory; namespace ComputerShopDatabaseImplement.Implements { public class OrderStorage : IOrderStorage { + //id пользователя учитывается в GetFilteredList public List GetFullList() { using var context = new ComputerShopDatabase(); @@ -70,6 +72,56 @@ namespace ComputerShopDatabaseImplement.Implements .ToList(); } + //получение данных для отчёта сборок по выбранным заказам + public List GetReportWithAssembly(List selectedModels) + { + using var context = new ComputerShopDatabase(); + //id заказов, которые выбрал пользователь + List id_of_selected_models = selectedModels.Select(x => x.Id).ToList(); + + //те заказы из бд, которые выбрал пользователь и имеют сборку + return context.Orders.Include(x => x.Requests) + .ThenInclude(x => x.Request) + .ThenInclude(x => x.Assembly) + .Where(x => id_of_selected_models.Contains(x.Id) && x.Requests.Any(r => r.Request.Assembly != null)) + + + + context.Orders + .Where(x => id_of_selected_models.Contains(x.Id) && x.Requests.Any(r => r.Request.Assembly != null)) + foreach (var selectedModel in selectedModels) + { + //заказ, у которого должна быть сборка + var order = context.Orders.FirstOrDefault(x => x.Id == selectedModel.Id && x.Requests.Any(r => r.Request.Assembly != null)); + //если у заказа нет сборки, то его не надо обрабатывать + if (order == null) + { + continue; + } + + } + var ordersWithAssemblies = selectedModels + + //возвращение тех заказов, кот. принадлежат пользователю и кот. имеют сборку в соответствующей заявке + return context.Orders + .Where(x => x.UserId == model.UserId && x.Requests.Any(r => r.Request.Assembly != null)) + .Include(x => x.Requests) + .ThenInclude(x => x.Request) + .ThenInclude(x => x.Assembly) + .ToList() + .Select(x => new ReportOrderAssemblyViewModel + { + OrderId = x.Id, + DateCreateOrder = x.DateCreate, + OrderSum = x.Sum, + OrderStatus = x.Status, + AssemblyName = x.Requests.FirstOrDefault(r => r.Request.Assembly != null)?.Request.Assembly.AssemblyName, + + + }) + .ToList(); + } + //Поиск только по id, потому что другие поля не уникальные - нет смысла искать 1 элемент public OrderViewModel? GetElement(OrderSearchModel model) { diff --git a/ComputerShopDatabaseImplement/Implements/RequestStorage.cs b/ComputerShopDatabaseImplement/Implements/RequestStorage.cs index e87e5d9..5ab8ec6 100644 --- a/ComputerShopDatabaseImplement/Implements/RequestStorage.cs +++ b/ComputerShopDatabaseImplement/Implements/RequestStorage.cs @@ -14,6 +14,7 @@ namespace ComputerShopDatabaseImplement.Implements { public class RequestStorage : IRequestStorage { + //id пользователя учитывается в GetFilteredList public List GetFullList() { using var context = new ComputerShopDatabase(); diff --git a/ComputerShopDatabaseImplement/Implements/ShipmentStorage.cs b/ComputerShopDatabaseImplement/Implements/ShipmentStorage.cs index c52ef14..11aa5d4 100644 --- a/ComputerShopDatabaseImplement/Implements/ShipmentStorage.cs +++ b/ComputerShopDatabaseImplement/Implements/ShipmentStorage.cs @@ -14,6 +14,7 @@ namespace ComputerShopDatabaseImplement.Implements { public class ShipmentStorage : IShipmentStorage { + //id пользователя учитывается в GetFilteredList public List GetFullList() { using var context = new ComputerShopDatabase();