From dacfa52fea663dd6bbeca90a3eefae3118177fe0 Mon Sep 17 00:00:00 2001 From: "Pyatkin I.A" <4234.sunrise.234@gmail.com> Date: Tue, 30 Apr 2024 00:39:33 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81=20=D0=BE=D1=88=D0=B8?= =?UTF-8?q?=D0=B1=D0=BE=D0=BA=20+=20=D1=83=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BD=D0=B5=D0=BD=D1=83=D0=B6=D0=BD=D0=BE=D0=B3?= =?UTF-8?q?=D0=BE=20+=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20ReportLogic?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/EmployeeLogic.cs | 8 - .../BusinessLogics/ReportLogic.cs | 60 ++++++++ .../BusinessLogics/WorkModelingEmployee.cs | 138 ------------------ .../BindingModels/EmployeeBindingModel.cs | 3 +- .../BindingModels/ReportBindingModel.cs | 15 ++ .../BusinessLogicsContracts/IReportLogic.cs | 18 +++ .../IWorkEmployeeImitationProcess.cs | 16 -- .../ViewModels/EmployeeViewModel.cs | 4 - .../ViewModels/ReportOrdersViewModel.cs | 18 +++ ... 20240429203544_InitialCreate.Designer.cs} | 8 +- ...ate.cs => 20240429203544_InitialCreate.cs} | 4 +- .../FurnitureFactoryDataBaseModelSnapshot.cs | 6 - .../Models/Employee.cs | 15 +- .../Models/IEmployeeModel.cs | 3 +- 14 files changed, 118 insertions(+), 198 deletions(-) create mode 100644 FurnitureFactory/FurnitureFactoryBusinessLogic/BusinessLogics/ReportLogic.cs delete mode 100644 FurnitureFactory/FurnitureFactoryBusinessLogic/BusinessLogics/WorkModelingEmployee.cs create mode 100644 FurnitureFactory/FurnitureFactoryContracts/BindingModels/ReportBindingModel.cs create mode 100644 FurnitureFactory/FurnitureFactoryContracts/BusinessLogicsContracts/IReportLogic.cs delete mode 100644 FurnitureFactory/FurnitureFactoryContracts/BusinessLogicsContracts/IWorkEmployeeImitationProcess.cs create mode 100644 FurnitureFactory/FurnitureFactoryContracts/ViewModels/ReportOrdersViewModel.cs rename FurnitureFactory/FurnitureFactoryDataBaseImplements/Migrations/{20240428213459_InitialCreate.Designer.cs => 20240429203544_InitialCreate.Designer.cs} (97%) rename FurnitureFactory/FurnitureFactoryDataBaseImplements/Migrations/{20240428213459_InitialCreate.cs => 20240429203544_InitialCreate.cs} (97%) diff --git a/FurnitureFactory/FurnitureFactoryBusinessLogic/BusinessLogics/EmployeeLogic.cs b/FurnitureFactory/FurnitureFactoryBusinessLogic/BusinessLogics/EmployeeLogic.cs index 547e348..04c8d92 100644 --- a/FurnitureFactory/FurnitureFactoryBusinessLogic/BusinessLogics/EmployeeLogic.cs +++ b/FurnitureFactory/FurnitureFactoryBusinessLogic/BusinessLogics/EmployeeLogic.cs @@ -98,14 +98,6 @@ namespace FurnitureFactoryBusinessLogic.BusinessLogics { return; } - if (model.WorkExperience < 0) - { - throw new ArgumentException("Опыт работы не должен быть отрицательным", nameof(model.WorkExperience)); - } - if (model.Qualification < 0) - { - throw new ArgumentException("Квалификация не должна быть отрицательной", nameof(model.Qualification)); - } if (string.IsNullOrEmpty(model.Password)) { throw new ArgumentNullException("Нет пароля сотрудника", nameof(model.EmployeeFIO)); diff --git a/FurnitureFactory/FurnitureFactoryBusinessLogic/BusinessLogics/ReportLogic.cs b/FurnitureFactory/FurnitureFactoryBusinessLogic/BusinessLogics/ReportLogic.cs new file mode 100644 index 0000000..bc792ec --- /dev/null +++ b/FurnitureFactory/FurnitureFactoryBusinessLogic/BusinessLogics/ReportLogic.cs @@ -0,0 +1,60 @@ +using FurnitureFactoryContracts.BindingModels; +using FurnitureFactoryContracts.BusinessLogicsContracts; +using FurnitureFactoryContracts.SearchModels; +using FurnitureFactoryContracts.StorageContracts; +using FurnitureFactoryContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureFactoryBusinessLogic.BusinessLogics +{ + public class ReportLogic : IReportLogic + { + private readonly IFurnitureStorage _furnitureStorage; + private readonly IOrderStorage _orderStorage; + + public ReportLogic(IFurnitureStorage furnitureStorage, IOrderStorage orderStorage) + { + _furnitureStorage = furnitureStorage; + _orderStorage = orderStorage; + } + + public List GetOrders(ReportBindingModel model) + { + return _orderStorage.GetFilteredList(new OrderSearchModel + { + DateFrom = model.DateFrom, + DateTo = model.DateTo + }) + .Select(x => new ReportOrdersViewModel + { + Id = x.Id, + DateCreate = x.DateCreate, + FurnitureName = x.FurnitureName, + OrderPrice = x.OrderPrice, + OStatus = x.OStatus.ToString(), + PStatus = x.PStatus.ToString(), + }) + .ToList(); + } + + public void SaveFurnituresToWordFile(ReportBindingModel model) + { + throw new NotImplementedException(); + } + + public void SaveFurnitureMaterialToExcelFile(ReportBindingModel model) + { + throw new NotImplementedException(); + } + + public void SaveOrdersToPdfFile(ReportBindingModel model) + { + throw new NotImplementedException(); + } + + } +} diff --git a/FurnitureFactory/FurnitureFactoryBusinessLogic/BusinessLogics/WorkModelingEmployee.cs b/FurnitureFactory/FurnitureFactoryBusinessLogic/BusinessLogics/WorkModelingEmployee.cs deleted file mode 100644 index 17b5d8e..0000000 --- a/FurnitureFactory/FurnitureFactoryBusinessLogic/BusinessLogics/WorkModelingEmployee.cs +++ /dev/null @@ -1,138 +0,0 @@ -using FurnitureFactoryContracts.BindingModels; -using FurnitureFactoryContracts.BusinessLogicsContracts; -using FurnitureFactoryContracts.SearchModels; -using FurnitureFactoryContracts.ViewModels; -using FurnitureFactoryDataModels.Enums; -using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace FurnitureFactoryBusinessLogic.BusinessLogics -{ - public class WorkModelingEmployee : IWorkEmployeeImitationProcess - { - private readonly ILogger _logger; - - private readonly Random _rnd; - - private IOrderLogic? _orderLogic; - - public WorkModelingEmployee(ILogger logger) - { - _logger = logger; - _rnd = new Random(1000); - } - - public void DoWork(IEmployeeLogic employeeLogic, IOrderLogic orderLogic) - { - _orderLogic = orderLogic; - var employees = employeeLogic.ReadList(null); - if (employees == null) - { - _logger.LogWarning("DoWork. Employees is null"); - return; - } - - var orders = _orderLogic.ReadList(new OrderSearchModel { OStatuses = new() { OrderStatus.Принят, OrderStatus.Выполняется } }); - if (orders == null || orders.Count == 0) - { - _logger.LogWarning("DoWork. Orders is null or empty"); - return; - } - _logger.LogDebug("DoWork for {Count} orders", orders.Count); - foreach (var employee in employees) - { - Task.Run(() => WorkerWorkAsync(employee, orders)); - } - } - - - private async Task WorkerWorkAsync(EmployeeViewModel employee, List orders) - { - if (_orderLogic == null || employee == null) - { - return; - } - await RunOrderInWork(employee, orders); - - await Task.Run(() => - { - foreach (var order in orders) - { - try - { - _logger.LogDebug("DoWork. Worker {Id} try get order {Order}", employee.Id, order.Id); - - _orderLogic.TakeOrderInWork(new OrderBindingModel - { - Id = order.Id, - EmployeeId = employee.Id - }); - - Thread.Sleep(employee.WorkExperience * _rnd.Next(100, 1000) * order.FurnitureCount); - _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", employee.Id, order.Id); - _orderLogic.FinishOrder(new OrderBindingModel - { - Id = order.Id - }); - - Thread.Sleep(employee.Qualification * _rnd.Next(10, 100)); - } - - catch (InvalidOperationException ex) - { - _logger.LogWarning(ex, "Error try get work"); - } - - catch (Exception ex) - { - _logger.LogError(ex, "Error while do work"); - throw; - } - } - }); - } - - private async Task RunOrderInWork(EmployeeViewModel employee, List allOrders) - { - if (_orderLogic == null || employee == null || allOrders == null || allOrders.Count == 0) - { - return; - } - try - { - - var runOrder = await Task.Run(() => allOrders.FirstOrDefault(x => x.EmployeeId == employee.Id && x.OStatus == OrderStatus.Выполняется)); - if (runOrder == null) - { - return; - } - - _logger.LogDebug("DoWork. Worker {Id} back to order {Order}", employee.Id, runOrder.Id); - - Thread.Sleep(employee.WorkExperience * _rnd.Next(100, 300) * runOrder.FurnitureCount); - _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", employee.Id, runOrder.Id); - _orderLogic.FinishOrder(new OrderBindingModel - { - Id = runOrder.Id - }); - - Thread.Sleep(employee.Qualification * _rnd.Next(10, 100)); - } - - catch (InvalidOperationException ex) - { - _logger.LogWarning(ex, "Error try get work"); - } - - catch (Exception ex) - { - _logger.LogError(ex, "Error while do work"); - throw; - } - } - } -} diff --git a/FurnitureFactory/FurnitureFactoryContracts/BindingModels/EmployeeBindingModel.cs b/FurnitureFactory/FurnitureFactoryContracts/BindingModels/EmployeeBindingModel.cs index 09a4faf..495da97 100644 --- a/FurnitureFactory/FurnitureFactoryContracts/BindingModels/EmployeeBindingModel.cs +++ b/FurnitureFactory/FurnitureFactoryContracts/BindingModels/EmployeeBindingModel.cs @@ -13,8 +13,7 @@ namespace FurnitureFactoryContracts.BindingModels public string EmployeeFIO { get; set; } = string.Empty; public string Email { get; set; } = string.Empty; public string Password { get; set; } = string.Empty; - public int WorkExperience { get; set; } - public int Qualification { get; set; } + } } diff --git a/FurnitureFactory/FurnitureFactoryContracts/BindingModels/ReportBindingModel.cs b/FurnitureFactory/FurnitureFactoryContracts/BindingModels/ReportBindingModel.cs new file mode 100644 index 0000000..0ebb24c --- /dev/null +++ b/FurnitureFactory/FurnitureFactoryContracts/BindingModels/ReportBindingModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureFactoryContracts.BindingModels +{ + public class ReportBindingModel + { + public string FileName { get; set; } = string.Empty; + public DateTime? DateFrom { get; set; } + public DateTime? DateTo { get; set; } + } +} diff --git a/FurnitureFactory/FurnitureFactoryContracts/BusinessLogicsContracts/IReportLogic.cs b/FurnitureFactory/FurnitureFactoryContracts/BusinessLogicsContracts/IReportLogic.cs new file mode 100644 index 0000000..ccceb48 --- /dev/null +++ b/FurnitureFactory/FurnitureFactoryContracts/BusinessLogicsContracts/IReportLogic.cs @@ -0,0 +1,18 @@ +using FurnitureFactoryContracts.BindingModels; +using FurnitureFactoryContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureFactoryContracts.BusinessLogicsContracts +{ + public interface IReportLogic + { + List GetOrders(ReportBindingModel model); + void SaveFurnituresToWordFile(ReportBindingModel model); + void SaveFurnitureMaterialToExcelFile(ReportBindingModel model); + void SaveOrdersToPdfFile(ReportBindingModel model); + } +} diff --git a/FurnitureFactory/FurnitureFactoryContracts/BusinessLogicsContracts/IWorkEmployeeImitationProcess.cs b/FurnitureFactory/FurnitureFactoryContracts/BusinessLogicsContracts/IWorkEmployeeImitationProcess.cs deleted file mode 100644 index faea179..0000000 --- a/FurnitureFactory/FurnitureFactoryContracts/BusinessLogicsContracts/IWorkEmployeeImitationProcess.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace FurnitureFactoryContracts.BusinessLogicsContracts -{ - public interface IWorkEmployeeImitationProcess - { - /// - /// Имитация работы сотрудника = > понадобится в дальнейшей разработке курсовой деятельности - /// - void DoWork(IEmployeeLogic employeeLogic, IOrderLogic orderLogic); - } -} diff --git a/FurnitureFactory/FurnitureFactoryContracts/ViewModels/EmployeeViewModel.cs b/FurnitureFactory/FurnitureFactoryContracts/ViewModels/EmployeeViewModel.cs index 3999e73..76d4b56 100644 --- a/FurnitureFactory/FurnitureFactoryContracts/ViewModels/EmployeeViewModel.cs +++ b/FurnitureFactory/FurnitureFactoryContracts/ViewModels/EmployeeViewModel.cs @@ -19,10 +19,6 @@ namespace FurnitureFactoryContracts.ViewModels public string Email { get; set; } = string.Empty; [DisplayName("Пароль")] public string Password { get; set; } = string.Empty; - [DisplayName("Стаж работы")] - public int WorkExperience { get; set; } - [DisplayName("Квалификация")] - public int Qualification { get; set; } } } diff --git a/FurnitureFactory/FurnitureFactoryContracts/ViewModels/ReportOrdersViewModel.cs b/FurnitureFactory/FurnitureFactoryContracts/ViewModels/ReportOrdersViewModel.cs new file mode 100644 index 0000000..73c6a88 --- /dev/null +++ b/FurnitureFactory/FurnitureFactoryContracts/ViewModels/ReportOrdersViewModel.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureFactoryContracts.ViewModels +{ + public class ReportOrdersViewModel + { + public int Id { get; set; } + public DateTime DateCreate { get; set; } + public string FurnitureName { get; set; } = string.Empty; + public double OrderPrice { get; set; } + public string OStatus { get; set; } = string.Empty; + public string PStatus { get; set; } = string.Empty; + } +} diff --git a/FurnitureFactory/FurnitureFactoryDataBaseImplements/Migrations/20240428213459_InitialCreate.Designer.cs b/FurnitureFactory/FurnitureFactoryDataBaseImplements/Migrations/20240429203544_InitialCreate.Designer.cs similarity index 97% rename from FurnitureFactory/FurnitureFactoryDataBaseImplements/Migrations/20240428213459_InitialCreate.Designer.cs rename to FurnitureFactory/FurnitureFactoryDataBaseImplements/Migrations/20240429203544_InitialCreate.Designer.cs index d93ef7c..86c0736 100644 --- a/FurnitureFactory/FurnitureFactoryDataBaseImplements/Migrations/20240428213459_InitialCreate.Designer.cs +++ b/FurnitureFactory/FurnitureFactoryDataBaseImplements/Migrations/20240429203544_InitialCreate.Designer.cs @@ -12,7 +12,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace FurnitureFactoryDataBaseImplement.Migrations { [DbContext(typeof(FurnitureFactoryDataBase))] - [Migration("20240428213459_InitialCreate")] + [Migration("20240429203544_InitialCreate")] partial class InitialCreate { /// @@ -70,12 +70,6 @@ namespace FurnitureFactoryDataBaseImplement.Migrations .IsRequired() .HasColumnType("nvarchar(max)"); - b.Property("Qualification") - .HasColumnType("int"); - - b.Property("WorkExperience") - .HasColumnType("int"); - b.HasKey("Id"); b.ToTable("Employees"); diff --git a/FurnitureFactory/FurnitureFactoryDataBaseImplements/Migrations/20240428213459_InitialCreate.cs b/FurnitureFactory/FurnitureFactoryDataBaseImplements/Migrations/20240429203544_InitialCreate.cs similarity index 97% rename from FurnitureFactory/FurnitureFactoryDataBaseImplements/Migrations/20240428213459_InitialCreate.cs rename to FurnitureFactory/FurnitureFactoryDataBaseImplements/Migrations/20240429203544_InitialCreate.cs index f29da14..b91e259 100644 --- a/FurnitureFactory/FurnitureFactoryDataBaseImplements/Migrations/20240428213459_InitialCreate.cs +++ b/FurnitureFactory/FurnitureFactoryDataBaseImplements/Migrations/20240429203544_InitialCreate.cs @@ -34,9 +34,7 @@ namespace FurnitureFactoryDataBaseImplement.Migrations .Annotation("SqlServer:Identity", "1, 1"), EmployeeFIO = table.Column(type: "nvarchar(max)", nullable: false), Email = table.Column(type: "nvarchar(max)", nullable: false), - Password = table.Column(type: "nvarchar(max)", nullable: false), - WorkExperience = table.Column(type: "int", nullable: false), - Qualification = table.Column(type: "int", nullable: false) + Password = table.Column(type: "nvarchar(max)", nullable: false) }, constraints: table => { diff --git a/FurnitureFactory/FurnitureFactoryDataBaseImplements/Migrations/FurnitureFactoryDataBaseModelSnapshot.cs b/FurnitureFactory/FurnitureFactoryDataBaseImplements/Migrations/FurnitureFactoryDataBaseModelSnapshot.cs index a8fddec..5c3d72c 100644 --- a/FurnitureFactory/FurnitureFactoryDataBaseImplements/Migrations/FurnitureFactoryDataBaseModelSnapshot.cs +++ b/FurnitureFactory/FurnitureFactoryDataBaseImplements/Migrations/FurnitureFactoryDataBaseModelSnapshot.cs @@ -67,12 +67,6 @@ namespace FurnitureFactoryDataBaseImplement.Migrations .IsRequired() .HasColumnType("nvarchar(max)"); - b.Property("Qualification") - .HasColumnType("int"); - - b.Property("WorkExperience") - .HasColumnType("int"); - b.HasKey("Id"); b.ToTable("Employees"); diff --git a/FurnitureFactory/FurnitureFactoryDataBaseImplements/Models/Employee.cs b/FurnitureFactory/FurnitureFactoryDataBaseImplements/Models/Employee.cs index 879c88f..7b28e36 100644 --- a/FurnitureFactory/FurnitureFactoryDataBaseImplements/Models/Employee.cs +++ b/FurnitureFactory/FurnitureFactoryDataBaseImplements/Models/Employee.cs @@ -23,12 +23,6 @@ namespace FurnitureFactoryDataBaseImplement.Models [Required] public string Password { get; private set; } = string.Empty; - [Required] - public int WorkExperience { get; private set; } - - [Required] - public int Qualification { get; private set; } - [ForeignKey("EmployeeId")] public virtual List Orders { get; set; } = new(); @@ -44,8 +38,7 @@ namespace FurnitureFactoryDataBaseImplement.Models EmployeeFIO = model.EmployeeFIO, Email = model.Email, Password = model.Password, - WorkExperience = model.WorkExperience, - Qualification = model.Qualification, + }; } @@ -58,8 +51,7 @@ namespace FurnitureFactoryDataBaseImplement.Models EmployeeFIO = model.EmployeeFIO; Email = model.Email; Password = model.Password; - WorkExperience = model.WorkExperience; - Qualification = model.Qualification; + } public EmployeeViewModel GetViewModel => new() @@ -68,8 +60,7 @@ namespace FurnitureFactoryDataBaseImplement.Models EmployeeFIO = EmployeeFIO, Email = Email, Password = Password, - WorkExperience = WorkExperience, - Qualification = Qualification, + }; } } diff --git a/FurnitureFactory/FurnitureFactoryDataModels/Models/IEmployeeModel.cs b/FurnitureFactory/FurnitureFactoryDataModels/Models/IEmployeeModel.cs index 426229f..7bd679e 100644 --- a/FurnitureFactory/FurnitureFactoryDataModels/Models/IEmployeeModel.cs +++ b/FurnitureFactory/FurnitureFactoryDataModels/Models/IEmployeeModel.cs @@ -11,7 +11,6 @@ namespace FurnitureFactoryDataModels.Models string EmployeeFIO { get; } string Email { get; } string Password { get; } - int WorkExperience { get; } - int Qualification { get; } + } }