Compare commits
2 Commits
fb2a136900
...
07d26155a9
Author | SHA1 | Date | |
---|---|---|---|
07d26155a9 | |||
73549e4a7b |
@ -70,7 +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)
|
||||||
|
@ -54,7 +54,7 @@ namespace AutomobilePlantBusinessLogic.BusinessLogics
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await RunOrderInWork(implementer, orders);
|
await RunOrderInWork(implementer);
|
||||||
|
|
||||||
await Task.Run(() =>
|
await Task.Run(() =>
|
||||||
{
|
{
|
||||||
@ -98,31 +98,33 @@ namespace AutomobilePlantBusinessLogic.BusinessLogics
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task RunOrderInWork(ImplementerViewModel implementer, List<OrderViewModel> allOrders)
|
private async Task RunOrderInWork(ImplementerViewModel implementer)
|
||||||
{
|
{
|
||||||
if (_orderLogic == null || implementer == null || allOrders == null || allOrders.Count == 0)
|
if (_orderLogic == null || implementer == null)
|
||||||
{
|
{
|
||||||
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,
|
||||||
|
Status = OrderStatus.Выполняется
|
||||||
|
}));
|
||||||
if (runOrder == null)
|
if (runOrder == null)
|
||||||
{
|
{
|
||||||
return;
|
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);
|
||||||
// доделываем работу
|
// доделываем работу
|
||||||
await Task.Delay(implementer.WorkExperience * _rnd.Next(100, 300) * runOrder.Count);
|
Thread.Sleep(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.FinishOrder(new OrderBindingModel
|
_orderLogic.DeliveryOrder(new OrderBindingModel
|
||||||
{
|
{
|
||||||
Id = runOrder.Id
|
Id = runOrder.Id
|
||||||
});
|
});
|
||||||
// отдыхаем
|
// отдыхаем
|
||||||
await Task.Delay(implementer.Qualification * _rnd.Next(10, 100));
|
Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100));
|
||||||
}
|
}
|
||||||
// заказа может не быть, просто игнорируем ошибку
|
// заказа может не быть, просто игнорируем ошибку
|
||||||
catch (InvalidOperationException ex)
|
catch (InvalidOperationException ex)
|
||||||
|
@ -16,10 +16,6 @@ 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)
|
||||||
|
@ -83,8 +83,8 @@ namespace AutomobilePlantDatabaseImplement.Models
|
|||||||
DateImplement = DateImplement,
|
DateImplement = DateImplement,
|
||||||
Id = Id,
|
Id = Id,
|
||||||
Status = Status,
|
Status = Status,
|
||||||
CarName = Car.CarName,
|
CarName = Car?.CarName ?? string.Empty,
|
||||||
ClientFIO = Client.ClientFIO,
|
ClientFIO = Client?.ClientFIO ?? string.Empty,
|
||||||
ImplementerFIO = Implementer?.ImplementerFIO ?? string.Empty,
|
ImplementerFIO = Implementer?.ImplementerFIO ?? string.Empty,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user