From 0f7148fbe5a629085800ca7375bf31a8d8ab9af5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=BE=D0=BB=D0=B0=D0=B9?= Date: Mon, 3 Apr 2023 23:59:08 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D1=83=D1=87=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D1=85=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=20=D1=84=D0=BE=D1=80=D0=BC=D0=B8=D1=80=D0=BE=D0=B2?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8=D1=8F=20=D0=BE=D1=82=D1=87=D1=91=D1=82=D0=B0?= =?UTF-8?q?=20=D0=B3=D0=BE=D1=82=D0=BE=D0=B2=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Worker/WorkerReportLogic.cs | 146 ++++++++++++++++++ .../HardwareShopBusinessLogic.csproj | 1 + .../BindingModels/BuildBindingModel.cs | 2 + .../BindingModels/PurchaseBindingModel.cs | 2 + .../IWorkerReportLogic.cs | 40 +++++ .../SearchModels/PurchaseSearchModel.cs | 7 +- .../ViewModels/BuildViewModel.cs | 1 + .../ViewModels/PurchaseViewModel.cs | 2 + .../ReportPurchaseComponentViewModel.cs | 23 +++ .../ViewModels/ReportPurchaseViewModel.cs | 15 ++ .../Models/IBuildModel.cs | 4 + .../Models/ICommentModel.cs | 2 +- .../Models/IPurchaseModel.cs | 2 + .../Implements/Worker/PurchaseStorage.cs | 11 +- .../Models/Worker/Build.cs | 34 +++- .../Models/Worker/Purchase.cs | 17 +- 16 files changed, 300 insertions(+), 9 deletions(-) create mode 100644 HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Worker/WorkerReportLogic.cs create mode 100644 HardwareShop/HardwareShopContracts/BusinessLogicsContracts/IWorkerReportLogic.cs create mode 100644 HardwareShop/HardwareShopContracts/ViewModels/ReportPurchaseComponentViewModel.cs create mode 100644 HardwareShop/HardwareShopContracts/ViewModels/ReportPurchaseViewModel.cs diff --git a/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Worker/WorkerReportLogic.cs b/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Worker/WorkerReportLogic.cs new file mode 100644 index 0000000..dbd0768 --- /dev/null +++ b/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Worker/WorkerReportLogic.cs @@ -0,0 +1,146 @@ + +using HardwareShopContracts.BindingModels; +using HardwareShopContracts.SearchModels; +using HardwareShopContracts.StoragesContracts; +using HardwareShopContracts.ViewModels; +using HardwareShopDatabaseImplement.Implements.Storekeeper; +using HardwareShopDatabaseImplement.Implements.Worker; +using HardwareShopDatabaseImplement.Models.Storekeeper; +using HardwareShopDatabaseImplement.Models.Worker; +using System.Collections.Generic; +using System.ComponentModel; + +namespace HardwareShopContracts.BusinessLogicsContracts +{ + public class WorkerReportLogic : IWorkerReportLogic + { + private readonly IComponentStorage _componentStorage; + + private readonly BuildStorage _buildStorage; + + private readonly IPurchaseStorage _purchaseStorage; + + private readonly IGoodStorage _goodStorage; + + private readonly ICommentStorage _commentStorage; + + public WorkerReportLogic(IComponentStorage componentStorage, BuildStorage buildStorage, IPurchaseStorage purchaseStorage, IGoodStorage goodStorage, ICommentStorage commentStorage) + { + _componentStorage = componentStorage; + _buildStorage = buildStorage; + _purchaseStorage = purchaseStorage; + _goodStorage = goodStorage; + _commentStorage = commentStorage; + } + + /// + /// Получение списка компонент с указанием, в каких покупках используются + /// + /// + public List GetPurchaseComponent(List purchaseList) + { + var list = new List(); + + foreach (var purchase in purchaseList) + { + var record = new ReportPurchaseComponentViewModel + { + Id = purchase.Id, + Builds = new List<(string Build, int count, List<(string Component, int count)>)>(), + Goods = new List<(string Good, int count, List<(string Component, int count)>)>(), + TotalCount = 0, + TotalCost = 0 + }; + foreach (var good in purchase.PurchaseGoods) + { + List<(string Component, int count)> componentList = new List<(string Component, int count)>(); + int goodTotalCount = 0; + foreach (var component in good.Value.Item1.GoodsComponents) + { + componentList.Add(new(component.Value.Item1.ComponentName, component.Value.Item2)); + goodTotalCount += component.Value.Item2; + } + record.Goods.Add(new(good.Value.Item1.GoodName, good.Value.Item2, componentList)); + record.TotalCount += goodTotalCount * good.Value.Item2; + } + foreach (var build in purchase.PurchaseBuilds) + { + List<(string Component, int count)> componentList = new List<(string Component, int count)>(); + int buildTotalCount = 0; + foreach (var component in build.Value.Item1.BuildComponents) + { + componentList.Add(new(component.Value.Item1.ComponentName, component.Value.Item2)); + buildTotalCount += component.Value.Item2; + } + record.Builds.Add(new(build.Value.Item1.BuildName, build.Value.Item2, componentList)); + record.TotalCount += buildTotalCount * build.Value.Item2; + } + list.Add(record); + } + return list; + } + + /// + /// Получение списка покупок за определенный период + /// + /// + /// + public List GetPurchase(ReportBindingModel model) + { + var list = new List(); + var purchases = _purchaseStorage.GetFilteredList(new PurchaseSearchModel { DateFrom = model.DateFrom, DateTo = model.DateTo }); + + foreach (var purchase in purchases) + { + var record = new ReportPurchaseViewModel + { + Id = purchase.Id, + Builds = new List<(string Build, int count, List, List<(string Component, int count)>)>(), + }; + foreach (var build in purchase.PurchaseBuilds) + { + List commentList = new List(); + foreach (var comment in build.Value.Item1.BuildComments) + { + commentList.Add(new(comment.Value.Text)); + } + List<(string Component, int count)> componentList = new List<(string Component, int count)>(); + foreach (var component in build.Value.Item1.BuildComponents) + { + componentList.Add(new(component.Value.Item1.ComponentName, component.Value.Item2)); + } + record.Builds.Add(new (build.Value.Item1.BuildName, build.Value.Item2, commentList, componentList)); + } + } + return list; + } + + + /// + /// Сохранение компонент с указаеним покупок в файл-Word + /// + /// + public void SaveComponentsToWordFile(ReportBindingModel model) + { + throw new NotImplementedException(); + } + + /// + /// Сохранение компонент с указаеним покупок в файл-Excel + /// + /// + public void SaveDishComponentToExcelFile(ReportBindingModel model) + { + throw new NotImplementedException(); + } + + /// + /// Сохранение отчёта по покупкам в файл-Pdf + /// + /// + public void SaveOrdersToPdfFile(ReportBindingModel model) + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/HardwareShop/HardwareShopBusinessLogic/HardwareShopBusinessLogic.csproj b/HardwareShop/HardwareShopBusinessLogic/HardwareShopBusinessLogic.csproj index c758485..1dbf0ca 100644 --- a/HardwareShop/HardwareShopBusinessLogic/HardwareShopBusinessLogic.csproj +++ b/HardwareShop/HardwareShopBusinessLogic/HardwareShopBusinessLogic.csproj @@ -12,6 +12,7 @@ + diff --git a/HardwareShop/HardwareShopContracts/BindingModels/BuildBindingModel.cs b/HardwareShop/HardwareShopContracts/BindingModels/BuildBindingModel.cs index d373725..40a72b5 100644 --- a/HardwareShop/HardwareShopContracts/BindingModels/BuildBindingModel.cs +++ b/HardwareShop/HardwareShopContracts/BindingModels/BuildBindingModel.cs @@ -13,5 +13,7 @@ namespace HardwareShopContracts.BindingModels public int UserId { get; set; } public Dictionary BuildPurchases { get; set; } = new(); + + public Dictionary BuildComponents { get; set; } = new(); } } diff --git a/HardwareShop/HardwareShopContracts/BindingModels/PurchaseBindingModel.cs b/HardwareShop/HardwareShopContracts/BindingModels/PurchaseBindingModel.cs index ccaaf61..3a52f0f 100644 --- a/HardwareShop/HardwareShopContracts/BindingModels/PurchaseBindingModel.cs +++ b/HardwareShop/HardwareShopContracts/BindingModels/PurchaseBindingModel.cs @@ -16,5 +16,7 @@ namespace HardwareShopContracts.BindingModels public int UserId { get; set; } public Dictionary PurchaseGoods { get; set; } = new(); + + public Dictionary PurchaseBuilds { get; set; } = new(); } } diff --git a/HardwareShop/HardwareShopContracts/BusinessLogicsContracts/IWorkerReportLogic.cs b/HardwareShop/HardwareShopContracts/BusinessLogicsContracts/IWorkerReportLogic.cs new file mode 100644 index 0000000..9702d5d --- /dev/null +++ b/HardwareShop/HardwareShopContracts/BusinessLogicsContracts/IWorkerReportLogic.cs @@ -0,0 +1,40 @@ + +using HardwareShopContracts.BindingModels; +using HardwareShopContracts.ViewModels; + +namespace HardwareShopContracts.BusinessLogicsContracts +{ + public interface IWorkerReportLogic + { + /// + /// Получение списка компонент с указанием, в каких покупках используются + /// + /// + List GetPurchaseComponent(List purchaseList); + + /// + /// Получение списка покупок за определенный период + /// + /// + /// + List GetPurchase(ReportBindingModel model); + + /// + /// Сохранение компонент с указаеним покупок в файл-Word + /// + /// + void SaveComponentsToWordFile(ReportBindingModel model); + + /// + /// Сохранение компонент с указаеним покупок в файл-Excel + /// + /// + void SaveDishComponentToExcelFile(ReportBindingModel model); + + /// + /// Сохранение отчёта по покупкам в файл-Pdf + /// + /// + void SaveOrdersToPdfFile(ReportBindingModel model); + } +} \ No newline at end of file diff --git a/HardwareShop/HardwareShopContracts/SearchModels/PurchaseSearchModel.cs b/HardwareShop/HardwareShopContracts/SearchModels/PurchaseSearchModel.cs index 7f2e5f6..00897a1 100644 --- a/HardwareShop/HardwareShopContracts/SearchModels/PurchaseSearchModel.cs +++ b/HardwareShop/HardwareShopContracts/SearchModels/PurchaseSearchModel.cs @@ -1,4 +1,5 @@  +using HardwareShopDataModels.Enums; using System.ComponentModel; namespace HardwareShopContracts.SearchModels { @@ -8,6 +9,10 @@ namespace HardwareShopContracts.SearchModels public int? UserId { get; set; } - public DateTime? DatePurchase { get; set; } + public PurchaseStatus? PurchaseStatus { get; set; } + + public DateTime? DateFrom { get; set; } + + public DateTime? DateTo { get; set; } } } diff --git a/HardwareShop/HardwareShopContracts/ViewModels/BuildViewModel.cs b/HardwareShop/HardwareShopContracts/ViewModels/BuildViewModel.cs index c71783a..b30b0fd 100644 --- a/HardwareShop/HardwareShopContracts/ViewModels/BuildViewModel.cs +++ b/HardwareShop/HardwareShopContracts/ViewModels/BuildViewModel.cs @@ -16,5 +16,6 @@ namespace HardwareShopContracts.ViewModels public Dictionary BuildPurchases { get; set; } = new(); + public Dictionary BuildComponents { get; set; } = new(); } } diff --git a/HardwareShop/HardwareShopContracts/ViewModels/PurchaseViewModel.cs b/HardwareShop/HardwareShopContracts/ViewModels/PurchaseViewModel.cs index 2a2c9a7..6a16837 100644 --- a/HardwareShop/HardwareShopContracts/ViewModels/PurchaseViewModel.cs +++ b/HardwareShop/HardwareShopContracts/ViewModels/PurchaseViewModel.cs @@ -19,5 +19,7 @@ namespace HardwareShopContracts.ViewModels public int UserId { get; set; } public Dictionary PurchaseGoods { get; set; } = new(); + + public Dictionary PurchaseBuilds { get; set; } = new(); } } diff --git a/HardwareShop/HardwareShopContracts/ViewModels/ReportPurchaseComponentViewModel.cs b/HardwareShop/HardwareShopContracts/ViewModels/ReportPurchaseComponentViewModel.cs new file mode 100644 index 0000000..1e8661f --- /dev/null +++ b/HardwareShop/HardwareShopContracts/ViewModels/ReportPurchaseComponentViewModel.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HardwareShopContracts.ViewModels +{ + public class ReportPurchaseComponentViewModel + { + public int Id { get; set; } + + public List<(string Build, int count, List<(string Component, int count)>)> Builds { get; set; } = new(); + + public List<(string Good, int count, List<(string Component, int count)>)> Goods { get; set; } = new(); + + public int TotalCount { get; set; } + + public int TotalCost { get; set; } + + + } +} diff --git a/HardwareShop/HardwareShopContracts/ViewModels/ReportPurchaseViewModel.cs b/HardwareShop/HardwareShopContracts/ViewModels/ReportPurchaseViewModel.cs new file mode 100644 index 0000000..ec1fb2f --- /dev/null +++ b/HardwareShop/HardwareShopContracts/ViewModels/ReportPurchaseViewModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HardwareShopContracts.ViewModels +{ + public class ReportPurchaseViewModel + { + public int Id { get; set; } + + public List<(string Build, int count, List, List<(string Component, int count)>)> Builds { get; set; } = new(); + } +} diff --git a/HardwareShop/HardwareShopDataModels/Models/IBuildModel.cs b/HardwareShop/HardwareShopDataModels/Models/IBuildModel.cs index 3e57d64..0327a66 100644 --- a/HardwareShop/HardwareShopDataModels/Models/IBuildModel.cs +++ b/HardwareShop/HardwareShopDataModels/Models/IBuildModel.cs @@ -16,5 +16,9 @@ namespace HardwareShopDataModels.Models int UserId { get; } Dictionary BuildPurchases { get; } + + Dictionary BuildComponents { get; } + + Dictionary BuildComments { get; } } } diff --git a/HardwareShop/HardwareShopDataModels/Models/ICommentModel.cs b/HardwareShop/HardwareShopDataModels/Models/ICommentModel.cs index 7897562..34c055c 100644 --- a/HardwareShop/HardwareShopDataModels/Models/ICommentModel.cs +++ b/HardwareShop/HardwareShopDataModels/Models/ICommentModel.cs @@ -12,6 +12,6 @@ namespace HardwareShopDataModels.Models int BuildId { get; } - int UserId { get; } + int UserId { get; } } } diff --git a/HardwareShop/HardwareShopDataModels/Models/IPurchaseModel.cs b/HardwareShop/HardwareShopDataModels/Models/IPurchaseModel.cs index 91420cf..a0dbcda 100644 --- a/HardwareShop/HardwareShopDataModels/Models/IPurchaseModel.cs +++ b/HardwareShop/HardwareShopDataModels/Models/IPurchaseModel.cs @@ -13,5 +13,7 @@ namespace HardwareShopDataModels.Models int UserId { get; } Dictionary PurchaseGoods { get; } + + Dictionary PurchaseBuilds { get; } } } diff --git a/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/PurchaseStorage.cs b/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/PurchaseStorage.cs index 95b9553..055bce1 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/PurchaseStorage.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/PurchaseStorage.cs @@ -24,9 +24,14 @@ namespace HardwareShopDatabaseImplement.Implements.Worker public List GetFilteredList(PurchaseSearchModel model) { using var context = new HardwareShopDatabase(); - if (!model.UserId.HasValue && !model.DatePurchase.HasValue) + if (!model.UserId.HasValue && !model.PurchaseStatus.HasValue && model.DateFrom.HasValue && model.DateTo.HasValue) { - return new(); + return context.Purchases + .Include(x => x.Goods) + .ThenInclude(x => x.Good) + .Where(x => x.DatePurchase >= model.DateFrom && x.DatePurchase <= model.DateTo) + .Select(x => x.GetViewModel) + .ToList(); } if (model.UserId.HasValue) { @@ -40,7 +45,7 @@ namespace HardwareShopDatabaseImplement.Implements.Worker return context.Purchases .Include(x => x.Goods) .ThenInclude(x => x.Good) - .Where(x => x.DatePurchase == model.DatePurchase) + .Where(x => x.PurchaseStatus == model.PurchaseStatus) .Select(x => x.GetViewModel) .ToList(); } diff --git a/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Build.cs b/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Build.cs index 812f6ea..8efd262 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Build.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Build.cs @@ -33,7 +33,37 @@ namespace HardwareShopDatabaseImplement.Models.Worker [ForeignKey("BuildId")] public virtual List Purchases { get; set; } = new(); - public Dictionary? _buildPurchases = null; + private Dictionary _buildComments = null; + + [NotMapped] + public Dictionary BuildComments + { + get + { + if (_buildComments == null) + { + _buildComments = Comments.ToDictionary(recBC=> recBC.Id, recBC => recBC as ICommentModel); + } + return _buildComments; + } + } + + private Dictionary? _buildComponents = null; + + [NotMapped] + public Dictionary BuildComponents + { + get + { + if (_buildComponents == null) + { + _buildComponents = Components.ToDictionary(recBC => recBC.ComponentId, recBC => (recBC.Component as IComponentModel, recBC.Count)); + } + return _buildComponents; + } + } + + private Dictionary? _buildPurchases = null; [NotMapped] public Dictionary BuildPurchases @@ -116,7 +146,5 @@ namespace HardwareShopDatabaseImplement.Models.Worker var buildPurchases = context.PurchasesBuilds.Where(rec => rec.BuildId == model.Id).ToList(); } - - } } diff --git a/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Purchase.cs b/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Purchase.cs index c7ffc1e..352f3e1 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Purchase.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Purchase.cs @@ -32,7 +32,7 @@ namespace HardwareShopDatabaseImplement.Models.Worker [ForeignKey("PurchaseId")] public virtual List Goods { get; set; } = new(); - public Dictionary? _purchaseGoods = null; + private Dictionary? _purchaseGoods = null; [NotMapped] public Dictionary PurchaseGoods @@ -47,6 +47,21 @@ namespace HardwareShopDatabaseImplement.Models.Worker } } + private Dictionary? _purchaseBuilds = null; + + [NotMapped] + public Dictionary PurchaseBuilds + { + get + { + if (_purchaseBuilds == null) + { + _purchaseBuilds = Builds.ToDictionary(recPG => recPG.BuildId, recPG => (recPG.Build as IBuildModel, recPG.Count)); + } + return _purchaseBuilds; + } + } + public static Purchase Create(HardwareShopDatabase context, PurchaseBindingModel model) { return new Purchase()