From 5a541e540b3de874731c515df94dafd218f2bdf6 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Wed, 19 Apr 2023 22:40:36 +0400 Subject: [PATCH] =?UTF-8?q?=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5?= =?UTF-8?q?=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/OrderLogic.cs | 4 +- .../BusinessLogics/WorkModeling.cs | 42 ++++++++++++++++++- .../LawFirmDataModels/Enums/OrderStatus.cs | 1 + 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/LawFirm/LawFirmBusinessLogic/BusinessLogics/OrderLogic.cs b/LawFirm/LawFirmBusinessLogic/BusinessLogics/OrderLogic.cs index 83b1c79..9b00c2c 100644 --- a/LawFirm/LawFirmBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/LawFirm/LawFirmBusinessLogic/BusinessLogics/OrderLogic.cs @@ -79,13 +79,13 @@ namespace LawFirmBusinessLogic.BusinessLogics } CheckModel(model, false); - if (model.Status + 1 != newStatus) + if (model.Status + 1 != newStatus && model.Status!=OrderStatus.Ожидание) { _logger.LogWarning("Status update to " + newStatus.ToString() +" operation failed. Order status incorrect."); return false; } - if (newStatus == OrderStatus.Готов) + if (newStatus == OrderStatus.Готов || newStatus == OrderStatus.Ожидание) { var document = _documentStorage.GetElement(new DocumentSearchModel() { Id = model.DocumentId}); if (document == null) diff --git a/LawFirm/LawFirmBusinessLogic/BusinessLogics/WorkModeling.cs b/LawFirm/LawFirmBusinessLogic/BusinessLogics/WorkModeling.cs index 05aee6a..1889131 100644 --- a/LawFirm/LawFirmBusinessLogic/BusinessLogics/WorkModeling.cs +++ b/LawFirm/LawFirmBusinessLogic/BusinessLogics/WorkModeling.cs @@ -54,6 +54,9 @@ namespace LawFirmBusinessLogic.BusinessLogics { return; } + + await RunWaitingOrder(implementer); + await RunOrderInWork(implementer, orders); await Task.Run(() => @@ -117,7 +120,7 @@ namespace LawFirmBusinessLogic.BusinessLogics // доделываем работу 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 + _orderLogic.DeliveryOrder(new OrderBindingModel { Id = runOrder.Id }); @@ -136,5 +139,40 @@ namespace LawFirmBusinessLogic.BusinessLogics throw; } } - } + + private async Task RunWaitingOrder(ImplementerViewModel implementer) + { + if (_orderLogic == null || implementer == null) + { + return; + } + try + { + var order = await Task.Run(() => _orderLogic.ReadElement(new OrderSearchModel + { + ImplementerId = implementer.Id, + Status = OrderStatus.Ожидание + })); + if (order == null) + { + return; + } + _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, order.Id); + _orderLogic.FinishOrder(new OrderBindingModel + { + Id = order.Id + }); + Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); + } + catch (InvalidOperationException ex) + { + _logger.LogWarning(ex, "Error try get work"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error while do work"); + throw; + } + } + } } diff --git a/LawFirm/LawFirmDataModels/Enums/OrderStatus.cs b/LawFirm/LawFirmDataModels/Enums/OrderStatus.cs index 06ea7e8..1b4ad5e 100644 --- a/LawFirm/LawFirmDataModels/Enums/OrderStatus.cs +++ b/LawFirm/LawFirmDataModels/Enums/OrderStatus.cs @@ -13,5 +13,6 @@ namespace LawFirmDataModels.Enums Выполняется = 1, Готов = 2, Выдан = 3, + Ожидание = 4 } }