работает ?
This commit is contained in:
parent
bb6c1345d1
commit
c83a68d282
@ -84,13 +84,13 @@ namespace SushiBarBusinessLogic.BusinessLogics
|
|||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(model));
|
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.");
|
_logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Order status incorrect.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
model.Status = newStatus;
|
model.Status = newStatus;
|
||||||
if (model.Status == OrderStatus.Готов)
|
if (model.Status == OrderStatus.Готов || viewModel.Status == OrderStatus.Ожидание)
|
||||||
{
|
{
|
||||||
model.DateImplement = DateTime.Now;
|
model.DateImplement = DateTime.Now;
|
||||||
var sushi = _sushiStorage.GetElement(new() { Id = viewModel.SushiId });
|
var sushi = _sushiStorage.GetElement(new() { Id = viewModel.SushiId });
|
||||||
@ -100,7 +100,8 @@ namespace SushiBarBusinessLogic.BusinessLogics
|
|||||||
}
|
}
|
||||||
if (!_shopLogic.AddSushi(sushi, viewModel.Count))
|
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
|
else
|
||||||
|
@ -182,6 +182,8 @@ namespace SushiBarBusinessLogic.BusinessLogics
|
|||||||
foreach (var shop in _shopStorage.GetFullList())
|
foreach (var shop in _shopStorage.GetFullList())
|
||||||
{
|
{
|
||||||
int countFree = shop.MaxCountSushi - shop.ListSushi.Select(x => x.Value.Item2).Sum();
|
int countFree = shop.MaxCountSushi - shop.ListSushi.Select(x => x.Value.Item2).Sum();
|
||||||
|
if (countFree <= 0)
|
||||||
|
continue;
|
||||||
if (countFree < count)
|
if (countFree < count)
|
||||||
{
|
{
|
||||||
if (!AddSushiInShop(new() { Id = shop.Id }, model, countFree))
|
if (!AddSushiInShop(new() { Id = shop.Id }, model, countFree))
|
||||||
|
@ -54,6 +54,9 @@ namespace SushiBarBusinessLogic.BusinessLogics
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await RunOrderAfterWaiting(implementer);
|
||||||
|
|
||||||
await RunOrderInWork(implementer);
|
await RunOrderInWork(implementer);
|
||||||
|
|
||||||
await Task.Run(() =>
|
await Task.Run(() =>
|
||||||
@ -140,5 +143,47 @@ namespace SushiBarBusinessLogic.BusinessLogics
|
|||||||
throw;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,5 +7,6 @@
|
|||||||
Выполняется = 1,
|
Выполняется = 1,
|
||||||
Готов = 2,
|
Готов = 2,
|
||||||
Выдан = 3,
|
Выдан = 3,
|
||||||
|
Ожидание = 4
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user