PIbd-21. Rodionov I.A. Lab work 06. Hard #14
@ -6,6 +6,7 @@ using IceCreamShopContracts.ViewModels;
|
||||
using IceCreamShopDataModels.Enums;
|
||||
using IceCreamShopDataModels.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace IceCreamShopBusinessLogic.BusinessLogics
|
||||
{
|
||||
@ -137,12 +138,15 @@ namespace IceCreamShopBusinessLogic.BusinessLogics
|
||||
_logger.LogWarning("Change status operation failed. Order not found");
|
||||
return false;
|
||||
}
|
||||
if (order.Status + 1 != newStatus)
|
||||
if ((order.Status + 1 != newStatus && order.Status != OrderStatus.Ожидание) || (order.Status == OrderStatus.Ожидание && newStatus != OrderStatus.Выдан))
|
||||
{
|
||||
_logger.LogWarning("Change status operation failed. Incorrect new status: {newStatus}. Current status: {currStatus}",
|
||||
newStatus, order.Status);
|
||||
_logger.LogWarning("Change status operation failed");
|
||||
return false;
|
||||
}
|
||||
if (order.ImplementerId.HasValue)
|
||||
{
|
||||
model.ImplementerId = order.ImplementerId;
|
||||
}
|
||||
if (newStatus == OrderStatus.Выдан)
|
||||
{
|
||||
var iceCream = _iceCreamStorage.GetElement(new IceCreamSearchModel() { Id = order.IceCreamId });
|
||||
@ -154,14 +158,15 @@ namespace IceCreamShopBusinessLogic.BusinessLogics
|
||||
if (!DeliverIceCreams(iceCream, order.Count))
|
||||
{
|
||||
_logger.LogWarning("Change status operation failed. Ice creams delivery operation failed");
|
||||
model.Status = OrderStatus.Ожидание;
|
||||
if (_orderStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
model.Status = newStatus;
|
||||
if (order.ImplementerId.HasValue)
|
||||
{
|
||||
model.ImplementerId = order.ImplementerId;
|
||||
}
|
||||
if (model.Status == OrderStatus.Готов)
|
||||
{
|
||||
model.DateImplement = DateTime.Now;
|
||||
|
@ -30,12 +30,15 @@ namespace IceCreamShopBusinessLogic.BusinessLogics
|
||||
_logger.LogWarning("DoWork. Implementers is null");
|
||||
return;
|
||||
}
|
||||
var orders = _orderLogic.ReadList(new OrderSearchModel { Status = OrderStatus.Принят });
|
||||
if (orders == null || orders.Count == 0)
|
||||
List<OrderViewModel>? orders = new();
|
||||
orders.AddRange(_orderLogic.ReadList(new() { Status = OrderStatus.Принят }) ?? new());
|
||||
orders.AddRange(_orderLogic.ReadList(new() { Status = OrderStatus.Выполняется }) ?? new());
|
||||
orders.AddRange(_orderLogic.ReadList(new() { Status = OrderStatus.Ожидание }) ?? new());
|
||||
if (orders.Count == 0)
|
||||
{
|
||||
_logger.LogWarning("DoWork. Orders is null or empty");
|
||||
_logger.LogWarning("DoWork. Orders is empty");
|
||||
return;
|
||||
}
|
||||
}
|
||||
_logger.LogDebug("DoWork for {Count} orders", orders.Count);
|
||||
foreach (var implementer in implementers)
|
||||
{
|
||||
@ -54,6 +57,8 @@ namespace IceCreamShopBusinessLogic.BusinessLogics
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
await RunWaitingOrders(implementer);
|
||||
await RunOrderInWork(implementer);
|
||||
|
||||
await Task.Run(() =>
|
||||
@ -76,6 +81,11 @@ namespace IceCreamShopBusinessLogic.BusinessLogics
|
||||
{
|
||||
Id = order.Id
|
||||
});
|
||||
_logger.LogDebug("DoWork. Order {Order} delivery", order.Id);
|
||||
_orderLogic.DeliveryOrder(new OrderBindingModel
|
||||
{
|
||||
Id = order.Id
|
||||
});
|
||||
}
|
||||
// кто-то мог уже перехватить заказ, игнорируем ошибку
|
||||
catch (InvalidOperationException ex)
|
||||
@ -125,6 +135,13 @@ namespace IceCreamShopBusinessLogic.BusinessLogics
|
||||
{
|
||||
Id = runOrder.Id
|
||||
});
|
||||
// доставляем
|
||||
_logger.LogDebug("DoWork. Order {Order} delivery", runOrder.Id);
|
||||
_orderLogic.DeliveryOrder(new OrderBindingModel
|
||||
{
|
||||
Id = runOrder.Id
|
||||
});
|
||||
|
||||
// отдыхаем
|
||||
Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100));
|
||||
}
|
||||
@ -140,5 +157,43 @@ namespace IceCreamShopBusinessLogic.BusinessLogics
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task RunWaitingOrders(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.LogDebug("RunWaitingOrders for {Count} orders. Implementer: {id}.", waitingOrders.Count, implementer.Id);
|
||||
foreach (var waitingOrder in waitingOrders)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logger.LogInformation("RunWaitingOrders. Order {Order} delivery", waitingOrder.Id);
|
||||
_orderLogic.DeliveryOrder(new OrderBindingModel
|
||||
{
|
||||
Id = waitingOrder.Id
|
||||
});
|
||||
}
|
||||
catch (InvalidOperationException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "Error try get work");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error while do work");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -10,6 +10,8 @@
|
||||
|
||||
Готов = 2,
|
||||
|
||||
Выдан = 3
|
||||
Выдан = 3,
|
||||
|
||||
Ожидание = 4
|
||||
}
|
||||
}
|
@ -149,8 +149,9 @@
|
||||
Controls.Add(buttonSave);
|
||||
Controls.Add(textBoxFIO);
|
||||
Controls.Add(labelFIO);
|
||||
Margin = new Padding(2, 2, 2, 2);
|
||||
Margin = new Padding(2);
|
||||
Name = "FormImplementer";
|
||||
StartPosition = FormStartPosition.CenterScreen;
|
||||
Text = "Исполнитель";
|
||||
Load += FormImplementer_Load;
|
||||
ResumeLayout(false);
|
||||
|
@ -1,17 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
|
||||
Example:
|
||||
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
@ -26,36 +26,36 @@
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
|
Loading…
Reference in New Issue
Block a user