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;
}
if (newStatus == OrderStatus.Готов || newStatus == OrderStatus.Ожидание)
if (newStatus == OrderStatus.Готов)
{
var document = _documentStorage.GetElement(new DocumentSearchModel() { Id = model.DocumentId});
if (document == null)

View File

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

View File

@ -16,11 +16,18 @@ namespace LawFirmDatabaseImplement.Implements
{
public OrderViewModel? GetElement(OrderSearchModel model)
{
if (!model.Id.HasValue)
{
return null;
}
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
.Include(x => x.Document)
.Include(x => x.Client)
@ -48,16 +55,16 @@ namespace LawFirmDatabaseImplement.Implements
.Select(x => x.GetViewModel)
.ToList();
}
if (model.Status!= null)
if (model.Status != null)
{
return context.Orders
return context.Orders
.Include(x => x.Document)
.Include(x => x.Client)
.Include(x => x.Implementer)
.Where(x => model.Status.Equals(x.Status))
.Select(x => x.GetViewModel)
.ToList();
}
.Include(x => x.Implementer)
.Where(x => model.Status.Equals(x.Status))
.Select(x => x.GetViewModel)
.ToList();
}
return context.Orders
.Include(x => x.Document)
.Include(x => x.Client)

View File

@ -1,4 +1,6 @@
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Migrations.Operations;
#nullable disable
@ -10,7 +12,7 @@ namespace LawFirmDatabaseImplement.Migrations
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<int>(
migrationBuilder.AddColumn<int>(
name: "ImplementerId",
table: "Orders",
type: "int",