Фикс ошибок + удаление ненужного + добавление ReportLogic
This commit is contained in:
parent
9ad59c6636
commit
dacfa52fea
@ -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));
|
||||
|
@ -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<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,
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -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<WorkModelingEmployee> 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<OrderViewModel> 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<OrderViewModel> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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; }
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -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; }
|
||||
}
|
||||
}
|
@ -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<ReportOrdersViewModel> GetOrders(ReportBindingModel model);
|
||||
void SaveFurnituresToWordFile(ReportBindingModel model);
|
||||
void SaveFurnitureMaterialToExcelFile(ReportBindingModel model);
|
||||
void SaveOrdersToPdfFile(ReportBindingModel model);
|
||||
}
|
||||
}
|
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// Имитация работы сотрудника = > понадобится в дальнейшей разработке курсовой деятельности
|
||||
/// </summary>
|
||||
void DoWork(IEmployeeLogic employeeLogic, IOrderLogic orderLogic);
|
||||
}
|
||||
}
|
@ -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; }
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -12,7 +12,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
namespace FurnitureFactoryDataBaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(FurnitureFactoryDataBase))]
|
||||
[Migration("20240428213459_InitialCreate")]
|
||||
[Migration("20240429203544_InitialCreate")]
|
||||
partial class InitialCreate
|
||||
{
|
||||
/// <inheritdoc />
|
||||
@ -70,12 +70,6 @@ namespace FurnitureFactoryDataBaseImplement.Migrations
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<int>("Qualification")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("WorkExperience")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Employees");
|
@ -34,9 +34,7 @@ namespace FurnitureFactoryDataBaseImplement.Migrations
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
EmployeeFIO = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Email = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Password = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
WorkExperience = table.Column<int>(type: "int", nullable: false),
|
||||
Qualification = table.Column<int>(type: "int", nullable: false)
|
||||
Password = table.Column<string>(type: "nvarchar(max)", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
@ -67,12 +67,6 @@ namespace FurnitureFactoryDataBaseImplement.Migrations
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<int>("Qualification")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("WorkExperience")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Employees");
|
||||
|
@ -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<Order> 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,
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,6 @@ namespace FurnitureFactoryDataModels.Models
|
||||
string EmployeeFIO { get; }
|
||||
string Email { get; }
|
||||
string Password { get; }
|
||||
int WorkExperience { get; }
|
||||
int Qualification { get; }
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user