Compare commits

..

4 Commits

Author SHA1 Message Date
7d7be6231f lab6hard is ready to go 2023-04-20 00:19:40 +04:00
5a541e540b работаем 2023-04-19 22:40:36 +04:00
bb689ff63b Merge branch 'LabWork06_Base' into LabWork06_Hard 2023-04-19 21:20:20 +04:00
dc680a0e1a fix 2023-04-19 21:19:29 +04:00
5 changed files with 52 additions and 7 deletions

View File

@ -266,7 +266,6 @@
private ToolStripMenuItem списокЗаказовПоДатеToolStripMenuItem;
private ToolStripMenuItem клиентыToolStripMenuItem;
private ToolStripMenuItem исполнителиToolStripMenuItem;
private ToolStripMenuItem запускРаботToolStripMenuItem;
private ToolStripMenuItem запускРаботыToolStripMenuItem;
}
}

View File

@ -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)
@ -96,6 +96,8 @@ namespace LawFirmBusinessLogic.BusinessLogics
if (CheckThenSupplyMany(document, model.Count) == false)
{
_logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Shop supply error.");
model.Status = OrderStatus.Ожидание;
_orderStorage.Update(model);
return false;
}
}

View File

@ -35,7 +35,12 @@ namespace LawFirmBusinessLogic.BusinessLogics
_logger.LogWarning("DoWork. Implementers is null");
return;
}
var orders = _orderLogic.ReadList(new OrderSearchModel { Status = OrderStatus.Принят });
if (orders != null) {
orders.AddRange(_orderLogic.ReadList(new OrderSearchModel { Status = OrderStatus.Выполняется }) ?? new());
orders.AddRange(_orderLogic.ReadList(new OrderSearchModel { Status = OrderStatus.Ожидание }) ?? new());
}
if (orders == null || orders.Count == 0)
{
_logger.LogWarning("DoWork. Orders is null or empty");
@ -54,6 +59,9 @@ namespace LawFirmBusinessLogic.BusinessLogics
{
return;
}
await RunWaitingOrder(implementer);
await RunOrderInWork(implementer, orders);
await Task.Run(() =>
@ -136,5 +144,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;
}
}
}
}

View File

@ -13,5 +13,6 @@ namespace LawFirmDataModels.Enums
Выполняется = 1,
Готов = 2,
Выдан = 3,
Ожидание = 4
}
}

View File

@ -48,7 +48,7 @@ namespace LawFirmRestApi.Controllers
{
return _order.ReadList(new OrderSearchModel
{
Statuses = new() { OrderStatus.Принят }
Status = OrderStatus.Принят
}) ;
}
catch (Exception ex)