Compare commits

..

4 Commits

Author SHA1 Message Date
a52922a883 merge fix 2023-04-22 10:24:27 +04:00
23f2fbf3eb fix 2023-04-21 12:23:35 +04:00
e13229f35d сдана лаб6хард 2023-04-21 11:30:22 +04:00
c0aa47fd2e fix 2023-04-21 09:13:38 +04:00
4 changed files with 39 additions and 24 deletions

View File

@ -85,7 +85,7 @@ namespace LawFirmBusinessLogic.BusinessLogics
return false; return false;
} }
if (newStatus == OrderStatus.Готов || newStatus == OrderStatus.Ожидание) if (newStatus == OrderStatus.Готов)
{ {
var document = _documentStorage.GetElement(new DocumentSearchModel() { Id = model.DocumentId}); var document = _documentStorage.GetElement(new DocumentSearchModel() { Id = model.DocumentId});
if (document == null) if (document == null)

View File

@ -62,7 +62,7 @@ namespace LawFirmBusinessLogic.BusinessLogics
await RunWaitingOrder(implementer); await RunWaitingOrder(implementer);
await RunOrderInWork(implementer, orders); await RunOrderInWork(implementer);
await Task.Run(() => await Task.Run(() =>
{ {
@ -106,16 +106,20 @@ namespace LawFirmBusinessLogic.BusinessLogics
}); });
} }
private async Task RunOrderInWork(ImplementerViewModel implementer, List<OrderViewModel> allOrders) private async Task RunOrderInWork(ImplementerViewModel implementer)
{ {
if (_orderLogic == null || implementer == null || allOrders == null || allOrders.Count == 0) if (_orderLogic == null || implementer == null)
{ {
return; return;
} }
try try
{ {
// Выбираем из всех заказов тот, который выполняется данным исполнителем // Выбираем из всех заказов тот, который выполняется данным исполнителем
var runOrder = await Task.Run(() => allOrders.FirstOrDefault(x => x.ImplementerId == implementer.Id && x.Status == OrderStatus.Выполняется)); var runOrder = await Task.Run(() => _orderLogic.ReadElement(new OrderSearchModel
{
ImplementerId = implementer.Id,
Status = OrderStatus.Выполняется
}));
if (runOrder == null) if (runOrder == null)
{ {
return; return;
@ -125,9 +129,10 @@ namespace LawFirmBusinessLogic.BusinessLogics
// доделываем работу // доделываем работу
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,
ImplementerId = implementer.Id
}); });
// отдыхаем // отдыхаем
Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100));
@ -163,9 +168,10 @@ namespace LawFirmBusinessLogic.BusinessLogics
return; return;
} }
_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.FinishOrder(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));
} }

View File

@ -16,11 +16,18 @@ namespace LawFirmDatabaseImplement.Implements
{ {
public OrderViewModel? GetElement(OrderSearchModel model) public OrderViewModel? GetElement(OrderSearchModel model)
{ {
if (!model.Id.HasValue)
{
return null;
}
using var context = new LawFirmDatabase(); using var context = new LawFirmDatabase();
if (model.ImplementerId != null && model.Status != null)
{
return context.Orders
.Include(x => x.Document)
.Include(x => x.Client)
.Include(x => x.Implementer)
.FirstOrDefault(x => x.Status.Equals(model.Status) && x.ImplementerId.Equals(model.ImplementerId))?.GetViewModel;
}
return context.Orders return context.Orders
.Include(x => x.Document) .Include(x => x.Document)
.Include(x => x.Client) .Include(x => x.Client)
@ -48,7 +55,7 @@ namespace LawFirmDatabaseImplement.Implements
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)
.ToList(); .ToList();
} }
if (model.Status!= null) if (model.Status != null)
{ {
return context.Orders return context.Orders
.Include(x => x.Document) .Include(x => x.Document)

View File

@ -1,4 +1,6 @@
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Migrations.Operations;
#nullable disable #nullable disable