PIbd-22 Kaznacheeva E.K. LabWork_6 #8
@ -63,7 +63,7 @@ namespace SoftwareInstallationBusinessLogic.BusinessLogics
|
||||
|
||||
model.Status = newStatus;
|
||||
|
||||
if (model.Status == OrderStatus.Выдан)
|
||||
if (model.Status == OrderStatus.Готов)
|
||||
model.DateImplement = DateTime.Now;
|
||||
|
||||
if (viewModel.ImplementerId.HasValue)
|
||||
|
@ -22,14 +22,13 @@ namespace SoftwareInstallationBusinessLogic.BusinessLogics
|
||||
_logger = logger;
|
||||
_rnd = new Random(1000);
|
||||
}
|
||||
public void DoWork(IImplementerLogic implementerLogic, IOrderLogic
|
||||
orderLogic)
|
||||
public void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic)
|
||||
{
|
||||
_orderLogic = orderLogic;
|
||||
var implementers = implementerLogic.ReadList(null);
|
||||
if (implementers == null)
|
||||
{
|
||||
_logger.LogWarning("DoWork. Implementers is null");
|
||||
_logger.LogWarning("DoWork. Исполнитель равен null");
|
||||
return;
|
||||
}
|
||||
var orders = _orderLogic.ReadList(new OrderSearchModel
|
||||
@ -47,22 +46,25 @@ namespace SoftwareInstallationBusinessLogic.BusinessLogics
|
||||
Task.Run(() => WorkerWorkAsync(implementer, orders));
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Иммитация работы исполнителя
|
||||
/// </summary>
|
||||
/// <param name="implementer"></param>
|
||||
/// <param name="orders"></param>
|
||||
private async Task WorkerWorkAsync(ImplementerViewModel implementer, List<OrderViewModel> orders)
|
||||
{
|
||||
if (_orderLogic == null || implementer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
await RunOrderInWork(implementer);
|
||||
await Task.Run(() =>
|
||||
{
|
||||
foreach (var order in orders)
|
||||
{
|
||||
try
|
||||
{
|
||||
RunOrderInWork(implementer);
|
||||
_logger.LogDebug("DoWork. Worker {Id} try get order { Order}", implementer.Id, order.Id);
|
||||
_logger.LogDebug("DoWork. Worker {Id} try get order {Order} ", implementer.Id, order.Id);
|
||||
// пытаемся назначить заказ на исполнителя
|
||||
_orderLogic.TakeOrderInWork(new OrderBindingModel
|
||||
{
|
||||
@ -70,15 +72,14 @@ namespace SoftwareInstallationBusinessLogic.BusinessLogics
|
||||
ImplementerId = implementer.Id
|
||||
});
|
||||
// делаем работу
|
||||
Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 1000) * order.Count);
|
||||
_logger.LogDebug("DoWork. Worker {Id} finish order { Order}", implementer.Id, order.Id);
|
||||
|
||||
Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 10000) * order.Count);
|
||||
_logger.LogDebug("DoWork. Worker {Id} finish order {Order} ", implementer.Id, order.Id);
|
||||
_orderLogic.FinishOrder(new OrderBindingModel
|
||||
{
|
||||
Id = order.Id
|
||||
Id = order.Id,
|
||||
});
|
||||
|
||||
Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100));
|
||||
// отдыхаем
|
||||
Thread.Sleep(implementer.Qualification * _rnd.Next(10, 50));
|
||||
}
|
||||
// кто-то мог уже перехватить заказ, игнорируем ошибку
|
||||
catch (InvalidOperationException ex)
|
||||
@ -94,7 +95,11 @@ namespace SoftwareInstallationBusinessLogic.BusinessLogics
|
||||
}
|
||||
});
|
||||
}
|
||||
/// <summary>
|
||||
/// Ищем заказ, которые уже в работе (вдруг исполнителя прервали)
|
||||
/// </summary>
|
||||
/// <param name="implementer"></param>
|
||||
/// <returns></returns>
|
||||
private async Task RunOrderInWork(ImplementerViewModel implementer)
|
||||
{
|
||||
if (_orderLogic == null || implementer == null)
|
||||
@ -103,8 +108,7 @@ namespace SoftwareInstallationBusinessLogic.BusinessLogics
|
||||
}
|
||||
try
|
||||
{
|
||||
var runOrder = await Task.Run(() => _orderLogic.ReadElement(new
|
||||
OrderSearchModel
|
||||
var runOrder = await Task.Run(() => _orderLogic.ReadElement(new OrderSearchModel
|
||||
{
|
||||
ImplementerId = implementer.Id,
|
||||
Statuses = new() { OrderStatus.Выполняется }
|
||||
@ -115,8 +119,7 @@ namespace SoftwareInstallationBusinessLogic.BusinessLogics
|
||||
}
|
||||
_logger.LogDebug("DoWork. Worker {Id} back to order {Order}", implementer.Id, runOrder.Id);
|
||||
// доделываем работу
|
||||
Thread.Sleep(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);
|
||||
_orderLogic.FinishOrder(new OrderBindingModel
|
||||
{
|
||||
|
@ -96,6 +96,7 @@
|
||||
Controls.Add(dataGridView);
|
||||
Name = "FormImplementers";
|
||||
Text = "Исполнители";
|
||||
Load += FormImplementers_Load;
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user