работает ?

This commit is contained in:
dasha 2023-04-19 20:01:35 +04:00
parent bb6c1345d1
commit c83a68d282
4 changed files with 52 additions and 3 deletions

View File

@ -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

View File

@ -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))

View File

@ -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;
}
}
/// <summary>
/// Ищем заказ, который в ожидании
/// </summary>
/// <param name="implementer"></param>
/// <returns></returns>
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;
}
}
}
}

View File

@ -7,5 +7,6 @@
Выполняется = 1,
Готов = 2,
Выдан = 3,
Ожидание = 4
}
}