Принятая лаба №6
This commit is contained in:
parent
ea2c698577
commit
643cfa5b07
@ -25,7 +25,8 @@ namespace AbstractFoodOrdersBusinessLogic.BusinessLogics
|
|||||||
}
|
}
|
||||||
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
|
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("ReadList. OrderId:{Id}", model?.Id);
|
_logger.LogInformation("ReadList. ClientId:{ClientId}.Status:{Status}.ImplementerId:{ImplementerId}.DateFrom:{DateFrom}.DateTo:{DateTo}OrderId:{Id}",
|
||||||
|
model?.ClientId, model?.OrderStatus, model?.ImplementerId, model?.DateFrom, model?.DateTo, model?.Id);
|
||||||
var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model);
|
var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model);
|
||||||
if (list == null)
|
if (list == null)
|
||||||
{
|
{
|
||||||
@ -35,13 +36,14 @@ namespace AbstractFoodOrdersBusinessLogic.BusinessLogics
|
|||||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
public OrderViewModel? ReadElement(OrderSearchModel? model)
|
public OrderViewModel? ReadElement(OrderSearchModel model)
|
||||||
{
|
{
|
||||||
if (model == null)
|
if (model == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(model));
|
throw new ArgumentNullException(nameof(model));
|
||||||
}
|
}
|
||||||
_logger.LogInformation("ReadElement. ImplementerId:{ImplementerId}. OrderStatus:{OrderStatus}. Id:{Id}", model.ImplementerId, model.OrderStatus, model.Id);
|
_logger.LogInformation("ReadElement. ClientId:{ClientId}.Status:{Status}.ImplementerId:{ImplementerId}.DateFrom:{DateFrom}.DateTo:{DateTo}OrderId:{Id}",
|
||||||
|
model.ClientId, model.OrderStatus, model.ImplementerId, model.DateFrom, model.DateTo, model.Id);
|
||||||
var element = _orderStorage.GetElement(model);
|
var element = _orderStorage.GetElement(model);
|
||||||
if (element == null)
|
if (element == null)
|
||||||
{
|
{
|
||||||
@ -113,11 +115,14 @@ namespace AbstractFoodOrdersBusinessLogic.BusinessLogics
|
|||||||
});
|
});
|
||||||
if (element == null)
|
if (element == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(element));
|
throw new InvalidOperationException(nameof(element));
|
||||||
}
|
}
|
||||||
model.DateCreate = element.DateCreate;
|
model.DateCreate = element.DateCreate;
|
||||||
model.DishId = element.DishId;
|
model.DishId = element.DishId;
|
||||||
model.DateImplement = element.DateImplement;
|
model.DateImplement = element.DateImplement;
|
||||||
|
model.ClientId = element.ClientId;
|
||||||
|
if (!model.ImplementerId.HasValue)
|
||||||
|
model.ImplementerId = element.ImplementerId;
|
||||||
model.Status = element.Status;
|
model.Status = element.Status;
|
||||||
model.Count = element.Count;
|
model.Count = element.Count;
|
||||||
model.Sum = element.Sum;
|
model.Sum = element.Sum;
|
||||||
@ -134,7 +139,7 @@ namespace AbstractFoodOrdersBusinessLogic.BusinessLogics
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
_logger.LogWarning("Changing status operation faled: Current-{Status}:required-{requiredStatus}.", model.Status, requiredStatus);
|
_logger.LogWarning("Changing status operation faled: Current-{Status}:required-{requiredStatus}.", model.Status, requiredStatus);
|
||||||
throw new ArgumentException($"Невозможно приствоить статус {requiredStatus} заказу с текущим статусом {model.Status}");
|
throw new InvalidOperationException($"Невозможно приствоить статус {requiredStatus} заказу с текущим статусом {model.Status}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,9 +39,8 @@ namespace AbstractFoodOrdersBusinessLogic.BusinessLogics
|
|||||||
if (orders == null || orders.Count == 0)
|
if (orders == null || orders.Count == 0)
|
||||||
{
|
{
|
||||||
_logger.LogWarning("DoWork. Orders is null or empty");
|
_logger.LogWarning("DoWork. Orders is null or empty");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
_logger.LogDebug("DoWork for {Count} orders", orders.Count);
|
_logger.LogDebug("DoWork for {Count} orders", orders?.Count);
|
||||||
foreach (var implementer in implementers)
|
foreach (var implementer in implementers)
|
||||||
{
|
{
|
||||||
Task.Run(() => WorkerWorkAsync(implementer, orders));
|
Task.Run(() => WorkerWorkAsync(implementer, orders));
|
||||||
@ -55,11 +54,12 @@ namespace AbstractFoodOrdersBusinessLogic.BusinessLogics
|
|||||||
/// <param name="orders"></param>
|
/// <param name="orders"></param>
|
||||||
private async Task WorkerWorkAsync(ImplementerViewModel implementer, List<OrderViewModel>? orders)
|
private async Task WorkerWorkAsync(ImplementerViewModel implementer, List<OrderViewModel>? orders)
|
||||||
{
|
{
|
||||||
if (_orderLogic == null || implementer == null || orders == null)
|
if (_orderLogic == null || implementer == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await RunOrderInWork(implementer);
|
await RunOrderInWork(implementer);
|
||||||
|
|
||||||
if (orders == null || orders.Count == 0)
|
if (orders == null || orders.Count == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -83,6 +83,8 @@ namespace AbstractFoodOrdersBusinessLogic.BusinessLogics
|
|||||||
{
|
{
|
||||||
Id = order.Id
|
Id = order.Id
|
||||||
});
|
});
|
||||||
|
// отдыхаем
|
||||||
|
await Task.Delay(implementer.Qualification * _rnd.Next(10, 100));
|
||||||
}
|
}
|
||||||
// кто-то мог уже перехватить заказ, игнорируем ошибку
|
// кто-то мог уже перехватить заказ, игнорируем ошибку
|
||||||
catch (InvalidOperationException ex)
|
catch (InvalidOperationException ex)
|
||||||
@ -95,8 +97,6 @@ namespace AbstractFoodOrdersBusinessLogic.BusinessLogics
|
|||||||
_logger.LogError(ex, "Error while do work");
|
_logger.LogError(ex, "Error while do work");
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
// отдыхаем
|
|
||||||
await Task.Delay(implementer.Qualification * _rnd.Next(10, 100));
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -133,7 +133,7 @@ namespace AbstractFoodOrdersBusinessLogic.BusinessLogics
|
|||||||
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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user