Готово вроде как

This commit is contained in:
Artyom_Yashin 2024-05-07 22:46:46 +04:00
parent 4bdecd3b61
commit 98f1f4df67
4 changed files with 101 additions and 20 deletions

View File

@ -48,6 +48,9 @@
списокМагазиновToolStripMenuItem = new ToolStripMenuItem();
компьютерыПоМагазинамToolStripMenuItem = new ToolStripMenuItem();
заказыПоДатамToolStripMenuItem = new ToolStripMenuItem();
поставкиToolStripMenuItem = new ToolStripMenuItem();
продажиToolStripMenuItem = new ToolStripMenuItem();
магазиныToolStripMenuItem = new ToolStripMenuItem();
menuStrip.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
@ -64,7 +67,7 @@
//
// справочникиToolStripMenuItem
//
справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, компьютерыToolStripMenuItem, клиентыToolStripMenuItem, исполнителиToolStripMenuItem, запускРаботToolStripMenuItem });
справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, компьютерыToolStripMenuItem, клиентыToolStripMenuItem, исполнителиToolStripMenuItem, запускРаботToolStripMenuItem, поставкиToolStripMenuItem, продажиToolStripMenuItem, магазиныToolStripMenuItem });
справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
справочникиToolStripMenuItem.Size = new Size(117, 24);
справочникиToolStripMenuItem.Text = "Справочники";
@ -213,6 +216,27 @@
заказыПоДатамToolStripMenuItem.Text = "Заказы по датам";
заказыПоДатамToolStripMenuItem.Click += заказыПоДатамToolStripMenuItem_Click;
//
// поставкиToolStripMenuItem
//
поставкиToolStripMenuItem.Name = "поставкиToolStripMenuItem";
поставкиToolStripMenuItem.Size = new Size(224, 26);
поставкиToolStripMenuItem.Text = "Поставки";
поставкиToolStripMenuItem.Click += SupplyToolStripMenuItem_Click;
//
// продажиToolStripMenuItem
//
продажиToolStripMenuItem.Name = "продажиToolStripMenuItem";
продажиToolStripMenuItem.Size = new Size(224, 26);
продажиToolStripMenuItem.Text = "Продажи";
продажиToolStripMenuItem.Click += SellToolStripMenuItem_Click;
//
// магазиныToolStripMenuItem
//
магазиныToolStripMenuItem.Name = агазиныToolStripMenuItem";
магазиныToolStripMenuItem.Size = new Size(224, 26);
магазиныToolStripMenuItem.Text = "Магазины";
магазиныToolStripMenuItem.Click += ShopsToolStripMenuItem_Click;
//
// FormMain
//
AutoScaleDimensions = new SizeF(8F, 20F);
@ -258,5 +282,8 @@
private ToolStripMenuItem списокМагазиновToolStripMenuItem;
private ToolStripMenuItem компьютерыПоМагазинамToolStripMenuItem;
private ToolStripMenuItem заказыПоДатамToolStripMenuItem;
private ToolStripMenuItem поставкиToolStripMenuItem;
private ToolStripMenuItem продажиToolStripMenuItem;
private ToolStripMenuItem магазиныToolStripMenuItem;
}
}

View File

@ -19,15 +19,14 @@ namespace ComputersShopBusinessLogic.BusinessLogics
static readonly object locker = new object();
public OrderLogic(IOrderStorage orderStorage, IShopStorage shopStorage, IShopLogic shopLogic, IComputerStorage computerStorage, ILogger<OrderLogic> logger)
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
{
_logger = logger;
_orderStorage = orderStorage;
_shopStorage = shopStorage;
_logger = logger;
_shopLogic = shopLogic;
_computerStorage = computerStorage;
}
_logger = logger;
_orderStorage = orderStorage;
_shopStorage = shopStorage;
_logger = logger;
_shopLogic = shopLogic;
_computerStorage = computerStorage;
}
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
{
@ -140,23 +139,23 @@ namespace ComputersShopBusinessLogic.BusinessLogics
_logger.LogWarning("Read operation failed");
return false;
}
if (element.Status != status - 1)
if (element.Status != status - 1 || element.Status == OrderStatus.Готов)
{
_logger.LogWarning("Status change operation failed");
throw new InvalidOperationException("Текущий статус заказа не может быть переведен в выбранный");
}
if (element.Status == OrderStatus.Готов)
if (element.Status == OrderStatus.Готов || element.Status == OrderStatus.Ожидает)
{
var computer = _computerStorage.GetElement(new ComputerSearchModel() { Id = model.ComputerId });
var computer = _computerStorage.GetElement(new ComputerSearchModel() { Id = element.ComputerId });
if (computer == null)
{
_logger.LogWarning("Status update to " + status.ToString() + " operation failed. Document not found.");
return false;
}
if (CheckSupply(computer, model.Count) == false)
if (CheckSupply(computer, element.Count) == false)
{
_logger.LogWarning("Status update to " + status.ToString() + " operation failed. Shop supply error.");
return false;
status = OrderStatus.Ожидает;
}
}
model.Status = status;

View File

@ -32,19 +32,21 @@ namespace ComputersShopBusinessLogic.BusinessLogics
_logger.LogWarning("DoWork. Implementers is null");
return;
}
var orders = _orderLogic.ReadList(new OrderSearchModel
var deliveredOrders = _orderLogic.ReadList(new OrderSearchModel
{
Status = OrderStatus.Принят
Status = OrderStatus.Выдан
});
if (orders == null || orders.Count == 0)
var allOrders = _orderLogic.ReadList(null);
if (allOrders == null || deliveredOrders == null || deliveredOrders.Count == allOrders.Count)
{
_logger.LogWarning("DoWork. Orders is null or empty");
return;
}
_logger.LogDebug("DoWork for {Count} orders", orders.Count);
deliveredOrders.ForEach(x => allOrders.Remove(x));
_logger.LogDebug("DoWork for {Count} orders", allOrders.Count);
foreach (var implementer in implementers)
{
Task.Run(() => WorkerWorkAsync(implementer, orders));
Task.Run(() => WorkerWorkAsync(implementer, allOrders));
}
}
/// Иммитация работы исполнителя
@ -55,6 +57,7 @@ namespace ComputersShopBusinessLogic.BusinessLogics
{
return;
}
await DeliverWaitingOrder(implementer);
await RunOrderInWork(implementer);
await Task.Run(() =>
{
@ -77,6 +80,10 @@ namespace ComputersShopBusinessLogic.BusinessLogics
{
Id = order.Id
});
_orderLogic.DeliveryOrder(new OrderBindingModel
{
Id = order.Id
});
// отдыхаем
Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100));
}
@ -120,6 +127,10 @@ namespace ComputersShopBusinessLogic.BusinessLogics
{
Id = runOrder.Id
});
_orderLogic.DeliveryOrder(new OrderBindingModel
{
Id = runOrder.Id
});
// отдыхаем
Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100));
}
@ -135,5 +146,48 @@ namespace ComputersShopBusinessLogic.BusinessLogics
throw;
}
}
/// Обрабатываем заказ, которые в ожидании (вдруг место освободилось)
private async Task DeliverWaitingOrder(ImplementerViewModel implementer)
{
if (_orderLogic == null || implementer == null)
{
return;
}
var waitingOrders = await Task.Run(() => _orderLogic.ReadList(new OrderSearchModel
{
ImplementerId = implementer.Id,
Status = OrderStatus.Ожидает
}));
if (waitingOrders == null || waitingOrders.Count == 0)
{
return;
}
_logger.LogInformation("DeliverWaitingOrder. Find some waitig order for implementer:{id}.Count:{count}", implementer.Id, waitingOrders.Count);
foreach (var waitingOrder in waitingOrders)
{
try
{
_logger.LogInformation("DeliverWaitingOrder. Trying to deliver order id:{id}", waitingOrder.Id);
var res = _orderLogic.DeliveryOrder(new OrderBindingModel
{
Id = waitingOrder.Id
});
}
catch (ArgumentException ex)
{
_logger.LogWarning(ex, "DeliverWaitingOrder. Fault");
}
catch (InvalidOperationException ex)
{
_logger.LogWarning(ex, "Error try deliver order");
}
catch (Exception ex)
{
_logger.LogError(ex, "Error while do work");
throw;
}
}
}
}
}

View File

@ -6,6 +6,7 @@
Принят = 0,
Выполняется = 1,
Готов = 2,
Выдан = 3
Ожидает = 3,
Выдан = 4
}
}