Add notification import

This commit is contained in:
2025-08-28 12:25:22 +09:00
parent d6d27e502c
commit e115440c41
8 changed files with 236 additions and 22 deletions

View File

@ -0,0 +1,110 @@
using Hcs.Client.Api.Payload.HouseManagement;
using Hcs.Client.Api.Request.Exception;
using Hcs.Client.Internal;
using Hcs.Service.Async.HouseManagement;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace Hcs.Client.Api.Request.HouseManagement
{
internal class ImportNotificationDataRequest(ClientBase client) : HouseManagementRequestBase(client)
{
protected override bool CanBeRestarted => false;
internal async Task<bool> ExecuteAsync(ImportNotificationDataPayload payload, CancellationToken token)
{
// TODO: Добавить проверку пейлоада
var notification = new importNotificationRequestNotification()
{
TransportGUID = Guid.NewGuid().ToString(),
Item = GetNotificationFromPayload(payload)
};
// http://open-gkh.ru/HouseManagement/importNotificationRequest.html
var request = new importNotificationRequest
{
Id = Constants.SIGNED_XML_ELEMENT_ID,
version = "13.2.2.0",
notification = [notification]
};
var result = await SendAndWaitResultAsync(request, async asyncClient =>
{
var response = await asyncClient.importNotificationDataAsync(CreateRequestHeader(), request);
return response.AckRequest.Ack;
}, token);
result.Items.OfType<ErrorMessageType>().ToList().ForEach(error =>
{
throw RemoteException.CreateNew(error.ErrorCode, error.Description);
});
return true;
}
private importNotificationRequestNotificationCreate GetNotificationFromPayload(ImportNotificationDataPayload payload)
{
var notification = new importNotificationRequestNotificationCreate();
if (!string.IsNullOrEmpty(payload.topic))
{
notification.Item = payload.topic;
}
else
{
notification.Item = payload.topicFromRegistry;
}
if (payload.isImportant)
{
notification.IsImportant = true;
notification.IsImportantSpecified = true;
}
notification.content = payload.content;
var items = new List<object>();
var itemsElementName = new List<ItemsChoiceType29>();
foreach (var tuple in payload.destinations)
{
items.Add(tuple.Item2);
itemsElementName.Add(tuple.Item1);
}
notification.Items = [.. items];
notification.ItemsElementName = [.. itemsElementName];
if (payload.isNotLimit)
{
notification.Items1 = [true];
notification.Items1ElementName = [Items1ChoiceType.IsNotLimit];
}
else
{
notification.Items1 = [payload.startDate.Value, payload.endDate.Value];
notification.Items1ElementName = [Items1ChoiceType.StartDate, Items1ChoiceType.EndDate];
}
// TODO: Добавить добавление аттачмента
if (payload.isShipOff)
{
notification.IsShipOff = true;
notification.IsShipOffSpecified = true;
}
if (payload.isForPublishToMobileApp)
{
notification.IsForPublishToMobileApp = true;
notification.IsForPublishToMobileAppSpecified = true;
}
notification.MobileAppData = payload.mobileAppData;
return notification;
}
}
}

View File

@ -18,6 +18,7 @@ namespace Hcs.Client.Api.Request.HouseManagement
{
ThrowIfPayloadIncorrect(payload);
// http://open-gkh.ru/HouseManagement/SupplyResourceContractType.html
var contract = new importSupplyResourceContractRequestContract
{
TransportGUID = Guid.NewGuid().ToString(),
@ -172,6 +173,7 @@ namespace Hcs.Client.Api.Request.HouseManagement
private SupplyResourceContractType GetContractFromPayload(ImportSupplyResourceContractDataPayload payload)
{
// http://open-gkh.ru/HouseManagement/SupplyResourceContractType.html
var contract = new SupplyResourceContractType();
if (payload.isContract)