работаем

This commit is contained in:
Данила Мочалов 2023-04-19 22:40:36 +04:00
parent bb689ff63b
commit 5a541e540b
3 changed files with 43 additions and 4 deletions

View File

@ -79,13 +79,13 @@ namespace LawFirmBusinessLogic.BusinessLogics
}
CheckModel(model, false);
if (model.Status + 1 != newStatus)
if (model.Status + 1 != newStatus && model.Status!=OrderStatus.Ожидание)
{
_logger.LogWarning("Status update to " + newStatus.ToString() +" operation failed. Order status incorrect.");
return false;
}
if (newStatus == OrderStatus.Готов)
if (newStatus == OrderStatus.Готов || newStatus == OrderStatus.Ожидание)
{
var document = _documentStorage.GetElement(new DocumentSearchModel() { Id = model.DocumentId});
if (document == null)

View File

@ -54,6 +54,9 @@ namespace LawFirmBusinessLogic.BusinessLogics
{
return;
}
await RunWaitingOrder(implementer);
await RunOrderInWork(implementer, orders);
await Task.Run(() =>
@ -117,7 +120,7 @@ namespace LawFirmBusinessLogic.BusinessLogics
// доделываем работу
Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 300) * runOrder.Count);
_logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, runOrder.Id);
_orderLogic.FinishOrder(new OrderBindingModel
_orderLogic.DeliveryOrder(new OrderBindingModel
{
Id = runOrder.Id
});
@ -136,5 +139,40 @@ namespace LawFirmBusinessLogic.BusinessLogics
throw;
}
}
private async Task RunWaitingOrder(ImplementerViewModel implementer)
{
if (_orderLogic == null || implementer == null)
{
return;
}
try
{
var order = await Task.Run(() => _orderLogic.ReadElement(new OrderSearchModel
{
ImplementerId = implementer.Id,
Status = 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

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