Compare commits

..

No commits in common. "07d26155a92ac23cc6484b5950590d7f9d04ab1f" and "fb2a1369004edb799187bf841638b848698af384" have entirely different histories.

4 changed files with 44 additions and 43 deletions

View File

@ -70,9 +70,8 @@ namespace AutomobilePlantBusinessLogic.BusinessLogics
DateCreate = viewModel.DateCreate, DateCreate = viewModel.DateCreate,
DateImplement = viewModel.DateImplement, DateImplement = viewModel.DateImplement,
Count = viewModel.Count, Count = viewModel.Count,
Sum = viewModel.Sum, Sum = viewModel.Sum
ImplementerId = viewModel.ImplementerId };
};
if (rawModel.ImplementerId.HasValue) if (rawModel.ImplementerId.HasValue)
{ {

View File

@ -54,7 +54,7 @@ namespace AutomobilePlantBusinessLogic.BusinessLogics
{ {
return; return;
} }
await RunOrderInWork(implementer); await RunOrderInWork(implementer, orders);
await Task.Run(() => await Task.Run(() =>
{ {
@ -98,45 +98,43 @@ namespace AutomobilePlantBusinessLogic.BusinessLogics
}); });
} }
private async Task RunOrderInWork(ImplementerViewModel implementer) private async Task RunOrderInWork(ImplementerViewModel implementer, List<OrderViewModel> allOrders)
{ {
if (_orderLogic == null || implementer == null) if (_orderLogic == null || implementer == null || allOrders == null || allOrders.Count == 0)
{ {
return; return;
} }
try try
{ {
var runOrder = await Task.Run(() => _orderLogic.ReadElement(new OrderSearchModel // Выбираем из всех заказов тот, который выполняется данным исполнителем
{ var runOrder = await Task.Run(() => allOrders.FirstOrDefault(x => x.ImplementerId == implementer.Id && x.Status == OrderStatus.Выполняется));
ImplementerId = implementer.Id, if (runOrder == null)
Status = OrderStatus.Выполняется {
})); return;
if (runOrder == null) }
{
return; _logger.LogDebug("DoWork. Worker {Id} back to order {Order}", implementer.Id, runOrder.Id);
}
_logger.LogDebug("DoWork. Worker {Id} back to order {Order}", implementer.Id, runOrder.Id);
// доделываем работу // доделываем работу
Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 300) * runOrder.Count); await Task.Delay(implementer.WorkExperience * _rnd.Next(100, 300) * runOrder.Count);
_logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, runOrder.Id); _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, runOrder.Id);
_orderLogic.DeliveryOrder(new OrderBindingModel _orderLogic.FinishOrder(new OrderBindingModel
{ {
Id = runOrder.Id Id = runOrder.Id
}); });
// отдыхаем // отдыхаем
Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); await Task.Delay(implementer.Qualification * _rnd.Next(10, 100));
} }
// заказа может не быть, просто игнорируем ошибку // заказа может не быть, просто игнорируем ошибку
catch (InvalidOperationException ex) catch (InvalidOperationException ex)
{ {
_logger.LogWarning(ex, "Error try get work"); _logger.LogWarning(ex, "Error try get work");
} }
// а может возникнуть иная ошибка, тогда просто заканчиваем выполнение имитации // а может возникнуть иная ошибка, тогда просто заканчиваем выполнение имитации
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex, "Error while do work"); _logger.LogError(ex, "Error while do work");
throw; throw;
} }
} }
} }
} }

View File

@ -16,6 +16,10 @@ namespace AutomobilePlantDatabaseImplement.Implements
{ {
public OrderViewModel? GetElement(OrderSearchModel model) public OrderViewModel? GetElement(OrderSearchModel model)
{ {
if (!model.Id.HasValue)
{
return null;
}
using var context = new AutomobilePlantDatabase(); using var context = new AutomobilePlantDatabase();
return context.Orders return context.Orders
.Include(x => x.Car) .Include(x => x.Car)

View File

@ -83,8 +83,8 @@ namespace AutomobilePlantDatabaseImplement.Models
DateImplement = DateImplement, DateImplement = DateImplement,
Id = Id, Id = Id,
Status = Status, Status = Status,
CarName = Car?.CarName ?? string.Empty, CarName = Car.CarName,
ClientFIO = Client?.ClientFIO ?? string.Empty, ClientFIO = Client.ClientFIO,
ImplementerFIO = Implementer?.ImplementerFIO ?? string.Empty, ImplementerFIO = Implementer?.ImplementerFIO ?? string.Empty,
}; };
} }