From 520ea2f1d5834e5ee6311d837ca3f35d1ed3cbde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D1=8F=D1=80=20=D0=90=D0=B3=D0=BB?= =?UTF-8?q?=D0=B8=D1=83=D0=BB=D0=BB=D0=BE=D0=B2?= Date: Mon, 6 Mar 2023 19:44:23 +0400 Subject: [PATCH 1/3] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=B2=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6=D0=BD=D0=BE?= =?UTF-8?q?=D1=81=D1=82=D1=8C=20=D0=B2=D1=8B=D0=B1=D0=B8=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D1=8C=20=D0=B7=D0=B0=D0=BA=D0=B0=D0=B7=D1=8B=20=D0=BF=D0=BE=20?= =?UTF-8?q?=D0=BC=D0=BD=D0=BE=D0=B6=D0=B5=D1=81=D1=82=D0=B2=D1=83=20=D1=81?= =?UTF-8?q?=D1=82=D0=B0=D1=82=D1=83=D1=81=D0=BE=D0=B2=20=D0=BE=D0=B4=D0=BD?= =?UTF-8?q?=D0=BE=D0=B2=D1=80=D0=B5=D0=BC=D0=B5=D0=BD=D0=BD=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ConfectionaryFileImplement/OrderStorage.cs | 11 +++++++++-- ConfectionaryListImplement/OrderStorage.cs | 13 ++++++++++--- .../SearchModels/OrderSearchModel.cs | 2 +- ConfectioneryDatabaseImplement/OrderStorage.cs | 6 +++--- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/ConfectionaryFileImplement/OrderStorage.cs b/ConfectionaryFileImplement/OrderStorage.cs index ecd3a9b..160eae9 100644 --- a/ConfectionaryFileImplement/OrderStorage.cs +++ b/ConfectionaryFileImplement/OrderStorage.cs @@ -28,6 +28,13 @@ namespace ConfectioneryFileImplement public OrderViewModel? GetElement(OrderSearchModel model) { + if (model.ImplementerId.HasValue && model.Statusses != null) + { + return _source.Orders + .FirstOrDefault(x => x.ImplementerId == model.ImplementerId && + model.Statusses.Contains(x.Status)) + ?.GetViewModel; + } if (model.ImplementerId.HasValue) { return _source.Orders.FirstOrDefault(x => x.ImplementerId == model.ImplementerId)?.GetViewModel; @@ -55,10 +62,10 @@ namespace ConfectioneryFileImplement .Select(x => x.GetViewModel) .ToList(); } - if (!model.Id.HasValue && model.Status.HasValue) + if (!model.Id.HasValue && model.Statusses != null) { return _source.Orders - .Where(x => x.Status == model.Status) + .Where(x => model.Statusses.Contains(x.Status)) .Select(x => x.GetViewModel) .ToList(); } diff --git a/ConfectionaryListImplement/OrderStorage.cs b/ConfectionaryListImplement/OrderStorage.cs index 7159bf2..43fd901 100644 --- a/ConfectionaryListImplement/OrderStorage.cs +++ b/ConfectionaryListImplement/OrderStorage.cs @@ -30,7 +30,14 @@ namespace ConfectioneryListImplement public OrderViewModel? GetElement(OrderSearchModel model) { - if (model.ImplementerId.HasValue) + if (model.ImplementerId.HasValue && model.Statusses != null) + { + return _source.Orders + .FirstOrDefault(x => x.ImplementerId == model.ImplementerId && + model.Statusses.Contains(x.Status)) + ?.GetViewModel; + } + if (model.ImplementerId.HasValue) { return _source.Orders.FirstOrDefault(x => x.ImplementerId == model.ImplementerId)?.GetViewModel; } @@ -65,10 +72,10 @@ namespace ConfectioneryListImplement .Select(x => x.GetViewModel) .ToList(); } - if (!model.Id.HasValue && model.Status.HasValue) + if (!model.Id.HasValue && model.Statusses != null) { return _source.Orders - .Where(x => x.Status == model.Status) + .Where(x => model.Statusses.Contains(x.Status)) .Select(x => x.GetViewModel) .ToList(); } diff --git a/ConfectioneryContracts/SearchModels/OrderSearchModel.cs b/ConfectioneryContracts/SearchModels/OrderSearchModel.cs index 606260e..a593019 100644 --- a/ConfectioneryContracts/SearchModels/OrderSearchModel.cs +++ b/ConfectioneryContracts/SearchModels/OrderSearchModel.cs @@ -14,6 +14,6 @@ namespace ConfectioneryContracts.SearchModels public int? ImplementerId { get; set; } - public OrderStatus? Status { get; set; } + public List? Statusses { get; set; } } } diff --git a/ConfectioneryDatabaseImplement/OrderStorage.cs b/ConfectioneryDatabaseImplement/OrderStorage.cs index 14ef8b7..f1e161d 100644 --- a/ConfectioneryDatabaseImplement/OrderStorage.cs +++ b/ConfectioneryDatabaseImplement/OrderStorage.cs @@ -33,7 +33,7 @@ namespace ConfectioneryDatabaseImplement.Implements .Include(x => x.Client) .Include(x => x.Implementer) .FirstOrDefault(x => - (!model.Status.HasValue || model.Status.HasValue && x.Status == model.Status) && + (model.Statusses == null || model.Statusses != null && model.Statusses.Contains(x.Status)) && model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId || model.Id.HasValue && x.Id == model.Id ) @@ -57,9 +57,9 @@ namespace ConfectioneryDatabaseImplement.Implements .Where(x => model.DateFrom <= x.DateCreate.Date && x.DateCreate.Date <= model.DateTo); } - else if (model.Status.HasValue) + else if (model.Statusses != null) { - queryWhere = context.Orders.Where(x => x.Status == model.Status); + queryWhere = context.Orders.Where(x => model.Statusses.Contains(x.Status)); } else if (model.ClientId.HasValue) { From f1706a4e4251d597ce629805124308a89cd42954 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D1=8F=D1=80=20=D0=90=D0=B3=D0=BB?= =?UTF-8?q?=D0=B8=D1=83=D0=BB=D0=BB=D0=BE=D0=B2?= Date: Mon, 6 Mar 2023 19:51:08 +0400 Subject: [PATCH 2/3] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D0=B8=D0=BC=D0=B8=D1=82=D0=B0=D1=86=D0=B8?= =?UTF-8?q?=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D1=8B=20=D0=B8=D1=81?= =?UTF-8?q?=D0=BF=D0=BE=D0=BB=D0=BD=D0=B8=D1=82=D0=B5=D0=BB=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ConfectionaryBusinessLogic/WorkModeling.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ConfectionaryBusinessLogic/WorkModeling.cs b/ConfectionaryBusinessLogic/WorkModeling.cs index 5aee2dc..6402635 100644 --- a/ConfectionaryBusinessLogic/WorkModeling.cs +++ b/ConfectionaryBusinessLogic/WorkModeling.cs @@ -35,12 +35,12 @@ namespace ConfectioneryBusinessLogic _logger.LogWarning("DoWork. Implementers is null"); return; } - var orders = _orderLogic.ReadList(new OrderSearchModel { Status = OrderStatus.Принят }); + var orders = _orderLogic.ReadList(new OrderSearchModel { Statusses = new() { OrderStatus.Принят } }); if (orders == null || orders.Count == 0) { // Поскольку у нас могут быть заказы в работе мы не дожны заканчивать работы, если нет Принятых заказов // Поэтому находим заказы в работе и продолжаем работу, если они есть - var workingOrders = _orderLogic.ReadList(new() { Status = OrderStatus.Выполняется }); + var workingOrders = _orderLogic.ReadList(new() { Statusses = new() { OrderStatus.Выполняется } }); if (workingOrders == null || workingOrders.Count == 0) { _logger.LogWarning("DoWork. Orders is null or empty"); @@ -126,7 +126,7 @@ namespace ConfectioneryBusinessLogic var runOrder = await Task.Run(() => _orderLogic.ReadElement(new OrderSearchModel { ImplementerId = implementer.Id, - Status = OrderStatus.Выполняется + Statusses = new() { OrderStatus.Выполняется } })); if (runOrder == null) { From 1b06ae3d966677b06c098346816b81f2fa262870 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D1=8F=D1=80=20=D0=90=D0=B3=D0=BB?= =?UTF-8?q?=D0=B8=D1=83=D0=BB=D0=BB=D0=BE=D0=B2?= Date: Mon, 6 Mar 2023 19:51:33 +0400 Subject: [PATCH 3/3] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=20?= =?UTF-8?q?=D0=B8=D1=81=D0=BF=D0=BE=D0=BB=D0=BD=D0=B8=D1=82=D0=B5=D0=BB?= =?UTF-8?q?=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ConfectionaryBusinessLogic/WorkModeling.cs | 34 +++++++--------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/ConfectionaryBusinessLogic/WorkModeling.cs b/ConfectionaryBusinessLogic/WorkModeling.cs index 6402635..c9bba89 100644 --- a/ConfectionaryBusinessLogic/WorkModeling.cs +++ b/ConfectionaryBusinessLogic/WorkModeling.cs @@ -35,24 +35,15 @@ namespace ConfectioneryBusinessLogic _logger.LogWarning("DoWork. Implementers is null"); return; } - var orders = _orderLogic.ReadList(new OrderSearchModel { Statusses = new() { OrderStatus.Принят } }); + // Поскольку у нас могут быть заказы в работе мы не дожны заканчивать работы, если нет Принятых заказов + // Поэтому находим заказы в работе и продолжаем работу, если они есть + var orders = _orderLogic.ReadList(new OrderSearchModel { Statusses = new() { OrderStatus.Принят, OrderStatus.Выполняется } }); if (orders == null || orders.Count == 0) { - // Поскольку у нас могут быть заказы в работе мы не дожны заканчивать работы, если нет Принятых заказов - // Поэтому находим заказы в работе и продолжаем работу, если они есть - var workingOrders = _orderLogic.ReadList(new() { Statusses = new() { OrderStatus.Выполняется } }); - if (workingOrders == null || workingOrders.Count == 0) - { - _logger.LogWarning("DoWork. Orders is null or empty"); - return; - } - else - { - _logger.LogWarning("DoWork. Еще есть заказы в работе. для {Count} заказов", workingOrders.Count); - } + _logger.LogWarning("DoWork. Orders is null or empty"); + return; } - else - _logger.LogDebug("DoWork for {Count} orders", orders.Count); + _logger.LogDebug("DoWork for {Count} orders", orders.Count); foreach (var implementer in implementers) { Task.Run(() => WorkerWorkAsync(implementer, orders)); @@ -70,7 +61,7 @@ namespace ConfectioneryBusinessLogic { return; } - await RunOrderInWork(implementer); + await RunOrderInWork(implementer, orders); await Task.Run(() => { @@ -115,19 +106,16 @@ namespace ConfectioneryBusinessLogic /// /// /// - private async Task RunOrderInWork(ImplementerViewModel implementer) + private async Task RunOrderInWork(ImplementerViewModel implementer, List allOrders) { - if (_orderLogic == null || implementer == null) + if (_orderLogic == null || implementer == null || allOrders == null || allOrders.Count == 0) { return; } try { - var runOrder = await Task.Run(() => _orderLogic.ReadElement(new OrderSearchModel - { - ImplementerId = implementer.Id, - Statusses = new() { OrderStatus.Выполняется } - })); + // Выбираем из всех заказов тот, который выполняется данным исполнителем + var runOrder = await Task.Run(() => allOrders.FirstOrDefault(x => x.ImplementerId == implementer.Id && x.Status == OrderStatus.Выполняется)); if (runOrder == null) { return;