You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.2 KiB
41 lines
1.2 KiB
using Connected.Middleware.Annotations;
|
|
using Connected.Notifications;
|
|
using Connected.Notifications.Events;
|
|
using Connected.ServiceModel;
|
|
using Logistics.Documents.Receive;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace Logistics.Documents.Listeners;
|
|
[Middleware<IReceiveDocumentService>(nameof(IReceiveDocumentService.ItemUpdated))]
|
|
internal sealed class ReceiveItemListener : EventListener<PrimaryKeyEventArgs<long>>
|
|
{
|
|
public ReceiveItemListener(ILogger<ReceiveItemListener> logger, IReceiveDocumentService documents)
|
|
{
|
|
Logger = logger;
|
|
Documents = documents;
|
|
}
|
|
|
|
private ILogger<ReceiveItemListener> Logger { get; }
|
|
private IReceiveDocumentService Documents { get; }
|
|
|
|
protected override async Task OnInvoke()
|
|
{
|
|
if (await Documents.SelectItem(Arguments.Id) is not IReceiveItem item)
|
|
{
|
|
Logger.LogWarning("The IReceiveItem not found ({id}}.", Arguments.Id);
|
|
return;
|
|
}
|
|
|
|
var items = await Documents.QueryItems(item.Document);
|
|
|
|
await Documents.Patch(new PatchArgs<int>
|
|
{
|
|
Id = item.Document,
|
|
Properties = new Dictionary<string, object>
|
|
{
|
|
{nameof(IReceiveDocument.OpenItemCount), items.Count(f=>f.PostedQuantity<f.Quantity)}
|
|
}
|
|
});
|
|
}
|
|
}
|