diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs
index 26d3f81..64ef1da 100644
--- a/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs
+++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs
@@ -84,13 +84,13 @@ namespace SushiBarBusinessLogic.BusinessLogics
{
throw new ArgumentNullException(nameof(model));
}
- if (viewModel.Status + 1 != newStatus)
+ if (viewModel.Status + 1 != newStatus && viewModel.Status != OrderStatus.Ожидание)
{
_logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Order status incorrect.");
return false;
}
model.Status = newStatus;
- if (model.Status == OrderStatus.Готов)
+ if (model.Status == OrderStatus.Готов || viewModel.Status == OrderStatus.Ожидание)
{
model.DateImplement = DateTime.Now;
var sushi = _sushiStorage.GetElement(new() { Id = viewModel.SushiId });
@@ -100,7 +100,8 @@ namespace SushiBarBusinessLogic.BusinessLogics
}
if (!_shopLogic.AddSushi(sushi, viewModel.Count))
{
- throw new Exception($"AddSushi operation failed. Shop is full.");
+ model.Status = OrderStatus.Ожидание;
+ _logger.LogWarning($"AddSushi operation failed. Shop is full.");
}
}
else
diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/ShopLogic.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/ShopLogic.cs
index a31b18b..c3f47d8 100644
--- a/SushiBar/SushiBarBusinessLogic/BusinessLogics/ShopLogic.cs
+++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/ShopLogic.cs
@@ -182,6 +182,8 @@ namespace SushiBarBusinessLogic.BusinessLogics
foreach (var shop in _shopStorage.GetFullList())
{
int countFree = shop.MaxCountSushi - shop.ListSushi.Select(x => x.Value.Item2).Sum();
+ if (countFree <= 0)
+ continue;
if (countFree < count)
{
if (!AddSushiInShop(new() { Id = shop.Id }, model, countFree))
diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/WorkModeling.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/WorkModeling.cs
index 8f71021..55d8c49 100644
--- a/SushiBar/SushiBarBusinessLogic/BusinessLogics/WorkModeling.cs
+++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/WorkModeling.cs
@@ -54,6 +54,9 @@ namespace SushiBarBusinessLogic.BusinessLogics
{
return;
}
+
+ await RunOrderAfterWaiting(implementer);
+
await RunOrderInWork(implementer);
await Task.Run(() =>
@@ -140,5 +143,47 @@ namespace SushiBarBusinessLogic.BusinessLogics
throw;
}
}
+
+ ///
+ /// Ищем заказ, который в ожидании
+ ///
+ ///
+ ///
+ private async Task RunOrderAfterWaiting(ImplementerViewModel implementer)
+ {
+ if (_orderLogic == null || implementer == null)
+ {
+ return;
+ }
+ try
+ {
+ var order = await Task.Run(() => _orderLogic.ReadElement(new OrderSearchModel
+ {
+ ImplementerId = implementer.Id,
+ OrderStatus = OrderStatus.Ожидание
+ }));
+ if (order == null)
+ {
+ return;
+ }
+ // доделываем работу
+ _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, order.Id);
+ _orderLogic.FinishOrder(new OrderBindingModel
+ {
+ Id = order.Id
+ });
+ // отдыхаем
+ Thread.Sleep(implementer.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/SushiBar/SushiBarDataModels/Enums/OrderStatus.cs b/SushiBar/SushiBarDataModels/Enums/OrderStatus.cs
index e7973ca..5f699dc 100644
--- a/SushiBar/SushiBarDataModels/Enums/OrderStatus.cs
+++ b/SushiBar/SushiBarDataModels/Enums/OrderStatus.cs
@@ -7,5 +7,6 @@
Выполняется = 1,
Готов = 2,
Выдан = 3,
+ Ожидание = 4
}
}