вроде работает

This commit is contained in:
Inohara 2023-04-09 20:36:57 +04:00
parent b489c47251
commit ccfced6fd3
2 changed files with 21 additions and 35 deletions

View File

@ -95,45 +95,32 @@ namespace IceCreamBusinessLogic.BusinessLogics
_logger.LogInformation("Order. OrderID:{Id}.Sum:{ Sum}. DocumentId: { DocumentId}", model.Id, model.Sum, model.IceCreamId); _logger.LogInformation("Order. OrderID:{Id}.Sum:{ Sum}. DocumentId: { DocumentId}", model.Id, model.Sum, model.IceCreamId);
} }
public bool SetNewStatus(OrderBindingModel rawModel, OrderStatus newStatus) public bool SetNewStatus(OrderBindingModel model, OrderStatus orderStatus)
{ {
var viewModel = _orderStorage.GetElement(new OrderSearchModel // Находим статус заказа по его айди
var vmodel = _orderStorage.GetElement(new() { Id = model.Id });
if (vmodel == null)
{ {
Id = rawModel.Id throw new ArgumentNullException(nameof(model));
});
if (viewModel == null)
{
_logger.LogWarning("Order model not found");
return false;
} }
if ((int)vmodel.Status + 1 != (int)orderStatus)
OrderBindingModel model = new OrderBindingModel
{ {
Id = viewModel.Id, throw new InvalidOperationException($"Попытка перевести заказ не в следующий статус: " +
IceCreamId = viewModel.IceCreamId, $"Текущий статус: {vmodel.Status} \n" +
Status = viewModel.Status, $"Планируемый статус: {orderStatus} \n" +
DateCreate = viewModel.DateCreate, $"Доступный статус: {(OrderStatus)((int)vmodel.Status + 1)}");
DateImplement = viewModel.DateImplement,
Count = viewModel.Count,
Sum = viewModel.Sum
};
if (rawModel.ImplementerId.HasValue)
{
model.ImplementerId = rawModel.ImplementerId;
} }
model.Status = orderStatus;
CheckModel(model); model.DateCreate = vmodel.DateCreate;
if (model.Status + 1 != newStatus) if (model.DateImplement == null)
{ model.DateImplement = vmodel.DateImplement;
_logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Order status incorrect."); if (vmodel.ImplementerId.HasValue)
return false; model.ImplementerId = vmodel.ImplementerId;
} model.IceCreamId = vmodel.IceCreamId;
model.Status = newStatus; model.Sum = vmodel.Sum;
if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now; model.Count = vmodel.Count;
if (_orderStorage.Update(model) == null) if (_orderStorage.Update(model) == null)
{ {
model.Status--;
_logger.LogWarning("Update operation failed"); _logger.LogWarning("Update operation failed");
return false; return false;
} }

View File

@ -72,12 +72,11 @@ namespace IceCreamBusinessLogic.BusinessLogic
ImplementerId = implementer.Id ImplementerId = implementer.Id
}); });
// делаем работу // делаем работу
Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 1000) * order.Count); Thread.Sleep(implementer.WorkExperience * _rnd.Next(200, 500) * order.Count);
_logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, order.Id); _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, order.Id);
_orderLogic.DeliveryOrder(new OrderBindingModel _orderLogic.DeliveryOrder(new OrderBindingModel
{ {
Id = order.Id, Id = order.Id,
ImplementerId = implementer.Id
}); });
// отдыхаем // отдыхаем
Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100));
@ -121,7 +120,7 @@ namespace IceCreamBusinessLogic.BusinessLogic
// доделываем работу // доделываем работу
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); _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
}); });