done hard6
This commit is contained in:
parent
d8b075f8eb
commit
3bd5643b10
@ -13,7 +13,6 @@ namespace PizzeriaBusinessLogic.BusinessLogics
|
|||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly IOrderStorage _orderStorage;
|
private readonly IOrderStorage _orderStorage;
|
||||||
static readonly object _locker = new object();
|
static readonly object _locker = new object();
|
||||||
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
|
|
||||||
private readonly IShopStorage _shopStorage;
|
private readonly IShopStorage _shopStorage;
|
||||||
|
|
||||||
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, IShopStorage shopStorage)
|
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, IShopStorage shopStorage)
|
||||||
@ -44,7 +43,7 @@ namespace PizzeriaBusinessLogic.BusinessLogics
|
|||||||
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
|
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("ReadList. ClientId:{ClientId}.Status:{Status}.ImplementerId:{ImplementerId}.DateFrom:{DateFrom}.DateTo:{DateTo}OrderId:{Id}",
|
_logger.LogInformation("ReadList. ClientId:{ClientId}.Status:{Status}.ImplementerId:{ImplementerId}.DateFrom:{DateFrom}.DateTo:{DateTo}OrderId:{Id}",
|
||||||
model?.ClientId, model?.Status, model?.ImplementerId, model?.DateFrom, model?.DateTo, model?.Id);
|
model?.ClientId, model?.Status, model?.ImplementerId, model?.DateFrom, model?.DateTo, model?.Id);
|
||||||
var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model);
|
var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model);
|
||||||
if (list == null)
|
if (list == null)
|
||||||
{
|
{
|
||||||
@ -84,24 +83,29 @@ namespace PizzeriaBusinessLogic.BusinessLogics
|
|||||||
|
|
||||||
public bool DeliveryOrder(OrderBindingModel model)
|
public bool DeliveryOrder(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
var order = _orderStorage.GetElement(new OrderSearchModel
|
lock (_locker)
|
||||||
{
|
{
|
||||||
Id = model.Id,
|
model = FillOrderBindingModel(model);
|
||||||
});
|
if (model.Status != OrderStatus.Готов && model.Status != OrderStatus.Ожидает)
|
||||||
if (order == null)
|
{
|
||||||
{
|
_logger.LogWarning("Changing status operation faled: Current-{Status}:required-Выдан.", model.Status);
|
||||||
throw new ArgumentNullException(nameof(order));
|
throw new InvalidOperationException($"Невозможно приствоить статус выдан заказу с текущим статусом {model.Status}");
|
||||||
|
}
|
||||||
|
if (!_shopStorage.RestockingShops(new SupplyBindingModel
|
||||||
|
{
|
||||||
|
PizzaId = model.PizzaId,
|
||||||
|
Count = model.Count
|
||||||
|
}))
|
||||||
|
{
|
||||||
|
if (model.Status == OrderStatus.Готов || model.Status == OrderStatus.Ожидает)
|
||||||
|
{
|
||||||
|
model.Status = OrderStatus.Ожидает;
|
||||||
|
return UpdateOrder(model);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
model.Status = OrderStatus.Выдан;
|
||||||
|
return UpdateOrder(model);
|
||||||
}
|
}
|
||||||
if (!_shopStorage.RestockingShops(new SupplyBindingModel
|
|
||||||
{
|
|
||||||
PizzaId = order.PizzaId,
|
|
||||||
Count = order.Count
|
|
||||||
}))
|
|
||||||
{
|
|
||||||
throw new ArgumentException("Недостаточно места");
|
|
||||||
}
|
|
||||||
|
|
||||||
return ChangeStatus(model, OrderStatus.Выдан);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CheckModel(OrderBindingModel model, bool withParams = true)
|
private void CheckModel(OrderBindingModel model, bool withParams = true)
|
||||||
@ -129,8 +133,22 @@ namespace PizzeriaBusinessLogic.BusinessLogics
|
|||||||
_logger.LogInformation("Pizza. PizzaId:{PizzaId}.Count:{Count}.Sum:{Sum}Id:{Id}",
|
_logger.LogInformation("Pizza. PizzaId:{PizzaId}.Count:{Count}.Sum:{Sum}Id:{Id}",
|
||||||
model.PizzaId, model.Count, model.Sum, model.Id);
|
model.PizzaId, model.Count, model.Sum, model.Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool ChangeStatus(OrderBindingModel model, OrderStatus requiredStatus)
|
private bool ChangeStatus(OrderBindingModel model, OrderStatus requiredStatus)
|
||||||
|
{
|
||||||
|
model = FillOrderBindingModel(model);
|
||||||
|
|
||||||
|
if (requiredStatus - model.Status == 1)
|
||||||
|
{
|
||||||
|
model.Status = requiredStatus;
|
||||||
|
if (model.Status == OrderStatus.Готов)
|
||||||
|
model.DateImplement = DateTime.Now;
|
||||||
|
return UpdateOrder(model);
|
||||||
|
}
|
||||||
|
_logger.LogWarning("Changing status operation faled: Current-{Status}:required-{requiredStatus}.", model.Status, requiredStatus);
|
||||||
|
throw new InvalidOperationException($"Невозможно приствоить статус {requiredStatus} заказу с текущим статусом {model.Status}");
|
||||||
|
}
|
||||||
|
|
||||||
|
private OrderBindingModel FillOrderBindingModel(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
CheckModel(model, false);
|
CheckModel(model, false);
|
||||||
var element = _orderStorage.GetElement(new OrderSearchModel()
|
var element = _orderStorage.GetElement(new OrderSearchModel()
|
||||||
@ -141,33 +159,30 @@ namespace PizzeriaBusinessLogic.BusinessLogics
|
|||||||
{
|
{
|
||||||
throw new InvalidOperationException(nameof(element));
|
throw new InvalidOperationException(nameof(element));
|
||||||
}
|
}
|
||||||
|
model.Id = element.Id;
|
||||||
model.DateCreate = element.DateCreate;
|
model.DateCreate = element.DateCreate;
|
||||||
model.PizzaId = element.PizzaId;
|
model.PizzaId = element.PizzaId;
|
||||||
model.DateImplement = element.DateImplement;
|
model.DateImplement = element.DateImplement;
|
||||||
model.ClientId = element.ClientId;
|
model.ClientId = element.ClientId;
|
||||||
|
model.Status = element.Status;
|
||||||
|
model.Count = element.Count;
|
||||||
|
model.Sum = element.Sum;
|
||||||
if (!model.ImplementerId.HasValue)
|
if (!model.ImplementerId.HasValue)
|
||||||
{
|
{
|
||||||
model.ImplementerId = element.ImplementerId;
|
model.ImplementerId = element.ImplementerId;
|
||||||
}
|
}
|
||||||
model.Status = element.Status;
|
return model;
|
||||||
model.Count = element.Count;
|
}
|
||||||
model.Sum = element.Sum;
|
|
||||||
if (requiredStatus - model.Status == 1)
|
private bool UpdateOrder(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
if (_orderStorage.Update(model) == null)
|
||||||
{
|
{
|
||||||
model.Status = requiredStatus;
|
_logger.LogWarning("Update operation failed");
|
||||||
if (model.Status == OrderStatus.Готов)
|
return false;
|
||||||
{
|
|
||||||
model.DateImplement = DateTime.Now;
|
|
||||||
}
|
|
||||||
if (_orderStorage.Update(model) == null)
|
|
||||||
{
|
|
||||||
_logger.LogWarning("Update operation failed");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
_logger.LogWarning("Changing status operation faled: Current-{Status}:required-{requiredStatus}.", model.Status, requiredStatus);
|
_logger.LogWarning("Update operation sucsess");
|
||||||
throw new InvalidOperationException($"Невозможно приствоить статус {requiredStatus} заказу с текущим статусом {model.Status}");
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,12 +30,14 @@ namespace PizzeriaBusinessLogic.BusinessLogics
|
|||||||
_logger.LogWarning("DoWork. Implementers is null");
|
_logger.LogWarning("DoWork. Implementers is null");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var orders = _orderLogic.ReadList(new OrderSearchModel { Status = OrderStatus.Принят });
|
var orders = _orderLogic.ReadList(new OrderSearchModel { Status = OrderStatus.Выдан });
|
||||||
if (orders == null || orders.Count == 0)
|
int count = _orderLogic.ReadList(null).Count;
|
||||||
|
if (orders == null || count == orders.Count)
|
||||||
{
|
{
|
||||||
_logger.LogWarning("DoWork. Orders is null or empty");
|
_logger.LogWarning("DoWork. Orders is null or empty");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
orders = _orderLogic.ReadList(null);
|
||||||
_logger.LogDebug("DoWork for {Count} orders", orders.Count);
|
_logger.LogDebug("DoWork for {Count} orders", orders.Count);
|
||||||
foreach (var implementer in implementers)
|
foreach (var implementer in implementers)
|
||||||
{
|
{
|
||||||
@ -49,6 +51,7 @@ namespace PizzeriaBusinessLogic.BusinessLogics
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
await DeliverWaitingOrder(implementer);
|
||||||
await RunOrderInWork(implementer);
|
await RunOrderInWork(implementer);
|
||||||
|
|
||||||
await Task.Run(() =>
|
await Task.Run(() =>
|
||||||
@ -71,6 +74,7 @@ namespace PizzeriaBusinessLogic.BusinessLogics
|
|||||||
{
|
{
|
||||||
Id = order.Id
|
Id = order.Id
|
||||||
});
|
});
|
||||||
|
_orderLogic.DeliveryOrder(new OrderBindingModel { Id = order.Id });
|
||||||
}
|
}
|
||||||
// кто-то мог уже перехватить заказ, игнорируем ошибку
|
// кто-то мог уже перехватить заказ, игнорируем ошибку
|
||||||
catch (InvalidOperationException ex)
|
catch (InvalidOperationException ex)
|
||||||
@ -115,6 +119,7 @@ namespace PizzeriaBusinessLogic.BusinessLogics
|
|||||||
{
|
{
|
||||||
Id = runOrder.Id
|
Id = runOrder.Id
|
||||||
});
|
});
|
||||||
|
_orderLogic.DeliveryOrder(new OrderBindingModel { Id = runOrder.Id });
|
||||||
// отдыхаем
|
// отдыхаем
|
||||||
Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100));
|
Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100));
|
||||||
}
|
}
|
||||||
@ -130,5 +135,47 @@ namespace PizzeriaBusinessLogic.BusinessLogics
|
|||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task DeliverWaitingOrder(ImplementerViewModel implementer)
|
||||||
|
{
|
||||||
|
if (_orderLogic == null || implementer == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var waitingOrders = await Task.Run(() => _orderLogic.ReadList(new OrderSearchModel
|
||||||
|
{
|
||||||
|
ImplementerId = implementer.Id,
|
||||||
|
Status = OrderStatus.Ожидает
|
||||||
|
}));
|
||||||
|
if (waitingOrders == null || waitingOrders.Count == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("DeliverWaitingOrder. Find some waitig order for implementer:{id}.Count:{count}", implementer.Id, waitingOrders.Count);
|
||||||
|
foreach (var waitingOrder in waitingOrders)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_logger.LogInformation("DeliverWaitingOrder. Trying to deliver order id:{id}", waitingOrder.Id);
|
||||||
|
var res = _orderLogic.DeliveryOrder(new OrderBindingModel
|
||||||
|
{
|
||||||
|
Id = waitingOrder.Id
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (ArgumentException ex)
|
||||||
|
{
|
||||||
|
_logger.LogWarning(ex, "DeliverWaitingOrder. Fault");
|
||||||
|
}
|
||||||
|
catch (InvalidOperationException ex)
|
||||||
|
{
|
||||||
|
_logger.LogWarning(ex, "Error try deliver order");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Error while do work");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ namespace PizzeriaDataModels.Enums
|
|||||||
Принят = 0,
|
Принят = 0,
|
||||||
Выполняется = 1,
|
Выполняется = 1,
|
||||||
Готов = 2,
|
Готов = 2,
|
||||||
Выдан = 3
|
Ожидает = 3,
|
||||||
|
Выдан = 4
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,5 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using PizzeriaDatabaseImplement.Models;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace PizzeriaDatabaseImplement
|
namespace PizzeriaDatabaseImplement
|
||||||
{
|
{
|
||||||
|
18
Pizzeria/PizzeriaView/FormMain.Designer.cs
generated
18
Pizzeria/PizzeriaView/FormMain.Designer.cs
generated
@ -39,10 +39,6 @@
|
|||||||
this.transactionToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
this.transactionToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
this.продажаToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
this.продажаToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
this.отчётыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
this.отчётыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
this.componentsToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
|
|
||||||
this.componentPizzaToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
|
|
||||||
this.ordersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
|
||||||
this.запускРаботToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
|
||||||
this.изделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
this.изделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
this.списокИзделийToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
this.списокИзделийToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
this.пиццаСИнгридиентамиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
this.пиццаСИнгридиентамиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
@ -52,6 +48,10 @@
|
|||||||
this.заказыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
this.заказыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
this.заказыToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
|
this.заказыToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
this.заказыПоГруппамToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
this.заказыПоГруппамToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
|
this.componentsToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
|
this.componentPizzaToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
|
this.ordersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
|
this.запускРаботToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
this.dataGridView = new System.Windows.Forms.DataGridView();
|
this.dataGridView = new System.Windows.Forms.DataGridView();
|
||||||
this.buttonCreateOrder = new System.Windows.Forms.Button();
|
this.buttonCreateOrder = new System.Windows.Forms.Button();
|
||||||
this.buttonTakeOrderInWork = new System.Windows.Forms.Button();
|
this.buttonTakeOrderInWork = new System.Windows.Forms.Button();
|
||||||
@ -67,8 +67,7 @@
|
|||||||
this.menuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20);
|
this.menuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20);
|
||||||
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||||
this.bookToolStripMenuItem,
|
this.bookToolStripMenuItem,
|
||||||
this.отчётыToolStripMenuItem,
|
this.запускРаботToolStripMenuItem,
|
||||||
this.запускРаботToolStripMenuItem});
|
|
||||||
this.operationToolStripMenuItem,
|
this.operationToolStripMenuItem,
|
||||||
this.отчётыToolStripMenuItem});
|
this.отчётыToolStripMenuItem});
|
||||||
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
|
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
|
||||||
@ -83,8 +82,7 @@
|
|||||||
this.bookToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
this.bookToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||||
this.ingridientsToolStripMenuItem,
|
this.ingridientsToolStripMenuItem,
|
||||||
this.pizzasToolStripMenuItem,
|
this.pizzasToolStripMenuItem,
|
||||||
this.клиентToolStripMenuItem,
|
this.исполнителиToolStripMenuItem,
|
||||||
this.исполнителиToolStripMenuItem});
|
|
||||||
this.shopsToolStripMenuItem,
|
this.shopsToolStripMenuItem,
|
||||||
this.клиентToolStripMenuItem});
|
this.клиентToolStripMenuItem});
|
||||||
this.bookToolStripMenuItem.Name = "bookToolStripMenuItem";
|
this.bookToolStripMenuItem.Name = "bookToolStripMenuItem";
|
||||||
@ -346,8 +344,6 @@
|
|||||||
private ToolStripMenuItem componentPizzaToolStripMenuItem1;
|
private ToolStripMenuItem componentPizzaToolStripMenuItem1;
|
||||||
private ToolStripMenuItem ordersToolStripMenuItem;
|
private ToolStripMenuItem ordersToolStripMenuItem;
|
||||||
private ToolStripMenuItem клиентToolStripMenuItem;
|
private ToolStripMenuItem клиентToolStripMenuItem;
|
||||||
private ToolStripMenuItem исполнителиToolStripMenuItem;
|
|
||||||
private ToolStripMenuItem запускРаботToolStripMenuItem;
|
|
||||||
private ToolStripMenuItem shopsToolStripMenuItem;
|
private ToolStripMenuItem shopsToolStripMenuItem;
|
||||||
private ToolStripMenuItem operationToolStripMenuItem;
|
private ToolStripMenuItem operationToolStripMenuItem;
|
||||||
private ToolStripMenuItem transactionToolStripMenuItem;
|
private ToolStripMenuItem transactionToolStripMenuItem;
|
||||||
@ -361,5 +357,7 @@
|
|||||||
private ToolStripMenuItem заказыToolStripMenuItem;
|
private ToolStripMenuItem заказыToolStripMenuItem;
|
||||||
private ToolStripMenuItem заказыToolStripMenuItem1;
|
private ToolStripMenuItem заказыToolStripMenuItem1;
|
||||||
private ToolStripMenuItem заказыПоГруппамToolStripMenuItem;
|
private ToolStripMenuItem заказыПоГруппамToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem исполнителиToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem запускРаботToolStripMenuItem;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user