Add metering device history export
This commit is contained in:
@ -1,5 +1,7 @@
|
||||
using Hcs.Client.Api.Request.DeviceMetering;
|
||||
using Hcs.Client.Api.Payload.DeviceMetering;
|
||||
using Hcs.Client.Api.Request.DeviceMetering;
|
||||
using Hcs.Service.Async.DeviceMetering;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@ -8,6 +10,18 @@ namespace Hcs.Client.Api
|
||||
// http://open-gkh.ru/DeviceMeteringServiceAsync/
|
||||
public class DeviceMeteringApi(ClientBase client) : ApiBase(client)
|
||||
{
|
||||
/// <summary>
|
||||
/// Экспорт истории показаний и поверок приборов учета пользователя, установленных в указанном доме
|
||||
/// </summary>
|
||||
/// <param name="payload">Пейлоад выборки ПУ</param>
|
||||
/// <param name="token">Токен отмены</param>
|
||||
/// <returns>Лицевые счета</returns>
|
||||
public async Task<IEnumerable<exportMeteringDeviceHistoryResultType>> ExportMeteringDeviceHistoryAsync(ExportMeteringDeviceHistoryPayload payload, CancellationToken token = default)
|
||||
{
|
||||
var request = new ExportMeteringDeviceHistory(client);
|
||||
return await request.ExecuteAsync(payload, token);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Импорт показаний приборов учета
|
||||
/// </summary>
|
||||
|
||||
@ -0,0 +1,91 @@
|
||||
using Hcs.Client.Api.Registry;
|
||||
using System;
|
||||
|
||||
namespace Hcs.Client.Api.Payload.DeviceMetering
|
||||
{
|
||||
// http://open-gkh.ru/DeviceMetering/exportMeteringDeviceHistoryRequest.html
|
||||
public class ExportMeteringDeviceHistoryPayload
|
||||
{
|
||||
/// <summary>
|
||||
/// Необязательное. Список из уникальных идентификаторов домов по ФИАС, в которых установлены ПУ
|
||||
/// пользователей. Если не указано, то будут экспортироваться данные по всем ПУ пользователей.
|
||||
/// </summary>
|
||||
public string[] fiasHouseGuid;
|
||||
|
||||
/// <summary>
|
||||
/// Выборочное. Выбор между <see cref="meteringDeviceType"/>, <see cref="municipalResource"/> и
|
||||
/// <see cref="meteringDeviceRootGUID"/>. Тип прибора учета (НСИ 27). Максимум 100 по выбранным.
|
||||
/// </summary>
|
||||
public RegistryElement[] meteringDeviceType;
|
||||
|
||||
/// <summary>
|
||||
/// Выборочное. Выбор между <see cref="meteringDeviceType"/>, <see cref="municipalResource"/> и
|
||||
/// <see cref="meteringDeviceRootGUID"/>. Вид коммунального ресурса (НСИ 2). Максимум 100 по выбранным.
|
||||
/// </summary>
|
||||
public RegistryElement[] municipalResource;
|
||||
|
||||
/// <summary>
|
||||
/// Выборочное. Выбор между <see cref="meteringDeviceType"/>, <see cref="municipalResource"/> и
|
||||
/// <see cref="meteringDeviceRootGUID"/>. Идентификатор ПУ. Максимум 100 по выбранным.
|
||||
/// </summary>
|
||||
public string[] meteringDeviceRootGUID;
|
||||
|
||||
/// <summary>
|
||||
/// Необязательное. Дата ввода в эксплуатацию "С".
|
||||
/// </summary>
|
||||
public DateTime? commissioningDateFrom;
|
||||
|
||||
/// <summary>
|
||||
/// Необязательное. Дата ввода в эксплуатацию "П".
|
||||
/// </summary>
|
||||
public DateTime? сommissioningDateTo;
|
||||
|
||||
/// <summary>
|
||||
/// Необязательное. Выгружать архивированные или нет.
|
||||
/// </summary>
|
||||
public bool? serchArchived;
|
||||
|
||||
/// <summary>
|
||||
/// Необязательное. Дата архивации "С".
|
||||
/// </summary>
|
||||
public DateTime? archiveDateFrom;
|
||||
|
||||
/// <summary>
|
||||
/// Необязательное. Дата архивации "По".
|
||||
/// </summary>
|
||||
public DateTime? archiveDateTo;
|
||||
|
||||
/// <summary>
|
||||
/// Необязательное. Дата начала периода, за который выгружаются показания и поверки ПУ (по дате
|
||||
/// снятия показаний). Период выгрузки показаний ПУ (определяемый элементами <see cref="inputDateFrom"/>
|
||||
/// и <see cref="inputDateTo"/>) не должен выходить за пределы двух последовательных календарных месяцев.
|
||||
/// </summary>
|
||||
public DateTime? inputDateFrom;
|
||||
|
||||
/// <summary>
|
||||
/// Необязательное. Дата окончания периода, за который выгружаются показания и поверки ПУ (по дате
|
||||
/// снятия показаний). Период выгрузки показаний ПУ (определяемый элементами <see cref="inputDateFrom"/>
|
||||
/// и <see cref="inputDateTo"/>) не должен выходить за пределы двух последовательных календарных месяцев.
|
||||
/// </summary>
|
||||
public DateTime? inputDateTo;
|
||||
|
||||
/// <summary>
|
||||
/// Необязательное. Если флаг сброшен или отсутствует, то показания, введенные в систему гражданином,
|
||||
/// включаются в выгрузку. Если флаг установлен, то такие показания в выгрузку не включаются.
|
||||
/// </summary>
|
||||
public bool? excludePersonAsDataSource;
|
||||
|
||||
/// <summary>
|
||||
/// Необязательное. Если флаг сброшен или отсутствует, то показания, введенные в систему текущей
|
||||
/// организацией, включаются в выгрузку. Если флаг установлен, то такие показания в выгрузку не включаются.
|
||||
/// </summary>
|
||||
public bool? excludeCurrentOrgAsDataSource;
|
||||
|
||||
/// <summary>
|
||||
/// Необязательное. Если флаг сброшен или отсутствует, то показания, введенные в систему организациями
|
||||
/// отличной от текущей, включаются в выгрузку. Если флаг установлен, то такие показания в выгрузку
|
||||
/// не включаются.
|
||||
/// </summary>
|
||||
public bool? excludeOtherOrgAsDataSource;
|
||||
}
|
||||
}
|
||||
16
Hcs.Client/Client/Api/Registry/Registry27.cs
Normal file
16
Hcs.Client/Client/Api/Registry/Registry27.cs
Normal file
@ -0,0 +1,16 @@
|
||||
namespace Hcs.Client.Api.Registry
|
||||
{
|
||||
/// <summary>
|
||||
/// НСИ "Тип прибора учета" (реестровый номер 27).
|
||||
/// Взято из https://dom.gosuslugi.ru/opendataapi/nsi-27/v1.
|
||||
/// </summary>
|
||||
public static class Registry27
|
||||
{
|
||||
/// <summary>
|
||||
/// Индивидуальный
|
||||
/// </summary>
|
||||
public static RegistryElement Element1 => new(
|
||||
"1",
|
||||
"3e86b303-62be-4837-91c1-ed2475702c65");
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,170 @@
|
||||
using Hcs.Client.Api.Payload.DeviceMetering;
|
||||
using Hcs.Client.Internal;
|
||||
using Hcs.Service.Async.DeviceMetering;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Hcs.Client.Api.Request.DeviceMetering
|
||||
{
|
||||
internal class ExportMeteringDeviceHistory(ClientBase client) : DeviceMeteringRequestBase(client)
|
||||
{
|
||||
protected override bool EnableMinimalResponseWaitDelay => false;
|
||||
|
||||
internal async Task<IEnumerable<exportMeteringDeviceHistoryResultType>> ExecuteAsync(ExportMeteringDeviceHistoryPayload payload, CancellationToken token)
|
||||
{
|
||||
ThrowIfPayloadIncorrect(payload);
|
||||
|
||||
var request = GetRequestFromPayload(payload);
|
||||
var result = await SendAndWaitResultAsync(request, async asyncClient =>
|
||||
{
|
||||
var response = await asyncClient.exportMeteringDeviceHistoryAsync(CreateRequestHeader(), request);
|
||||
return response.AckRequest.Ack;
|
||||
}, token);
|
||||
|
||||
return result.Items.OfType<exportMeteringDeviceHistoryResultType>();
|
||||
}
|
||||
|
||||
private void ThrowIfPayloadIncorrect(ExportMeteringDeviceHistoryPayload payload)
|
||||
{
|
||||
if (payload.meteringDeviceType?.Length <= 0 && payload.municipalResource?.Length <= 0 &&
|
||||
payload.meteringDeviceRootGUID?.Length <= 0)
|
||||
{
|
||||
throw new ArgumentException($"{nameof(payload.meteringDeviceType)}/{nameof(payload.municipalResource)}/{nameof(payload.meteringDeviceRootGUID)} are empty");
|
||||
}
|
||||
|
||||
if (payload.meteringDeviceType?.Length + payload.municipalResource?.Length +
|
||||
payload.meteringDeviceRootGUID?.Length > 100)
|
||||
{
|
||||
throw new ArgumentException($"Too much {nameof(payload.meteringDeviceType)}/{nameof(payload.municipalResource)}/{nameof(payload.meteringDeviceRootGUID)} values");
|
||||
}
|
||||
|
||||
if (payload.inputDateFrom.HasValue && payload.inputDateTo.HasValue)
|
||||
{
|
||||
if (payload.inputDateFrom.HasValue && payload.inputDateTo.HasValue &&
|
||||
payload.inputDateFrom.Value > payload.inputDateTo.Value)
|
||||
{
|
||||
throw new ArgumentException($"{nameof(payload.inputDateFrom)} must be earlier than {nameof(payload.inputDateTo)}");
|
||||
}
|
||||
|
||||
if (payload.inputDateTo.Value - payload.inputDateFrom.Value > TimeSpan.FromDays(
|
||||
DateTime.DaysInMonth(payload.inputDateTo.Value.Year, payload.inputDateTo.Value.Month) +
|
||||
DateTime.DaysInMonth(payload.inputDateFrom.Value.Year, payload.inputDateFrom.Value.Month)))
|
||||
{
|
||||
throw new ArgumentException($"Too big range from {nameof(payload.inputDateFrom)} to {nameof(payload.inputDateTo)}");
|
||||
}
|
||||
}
|
||||
else if (payload.inputDateFrom.HasValue && !payload.inputDateTo.HasValue)
|
||||
{
|
||||
throw new ArgumentException($"{nameof(payload.inputDateTo)} is null");
|
||||
}
|
||||
else if (!payload.inputDateFrom.HasValue && payload.inputDateTo.HasValue)
|
||||
{
|
||||
throw new ArgumentException($"{nameof(payload.inputDateFrom)} is null");
|
||||
}
|
||||
}
|
||||
|
||||
private exportMeteringDeviceHistoryRequest GetRequestFromPayload(ExportMeteringDeviceHistoryPayload payload)
|
||||
{
|
||||
var items = new List<object>();
|
||||
var itemsElementName = new List<ItemsChoiceType4>();
|
||||
foreach (var meteringDeviceType in payload.meteringDeviceType)
|
||||
{
|
||||
items.Add(new nsiRef()
|
||||
{
|
||||
Code = meteringDeviceType.Code,
|
||||
GUID = meteringDeviceType.GUID
|
||||
});
|
||||
itemsElementName.Add(ItemsChoiceType4.MeteringDeviceType);
|
||||
}
|
||||
foreach (var municipalResource in payload.municipalResource)
|
||||
{
|
||||
items.Add(new nsiRef()
|
||||
{
|
||||
Code = municipalResource.Code,
|
||||
GUID = municipalResource.GUID
|
||||
});
|
||||
itemsElementName.Add(ItemsChoiceType4.MunicipalResource);
|
||||
}
|
||||
foreach (var meteringDeviceRootGUID in payload.meteringDeviceRootGUID)
|
||||
{
|
||||
items.Add(meteringDeviceRootGUID);
|
||||
itemsElementName.Add(ItemsChoiceType4.MeteringDeviceRootGUID);
|
||||
}
|
||||
|
||||
// http://open-gkh.ru/DeviceMetering/exportMeteringDeviceHistoryRequest.html
|
||||
var request = new exportMeteringDeviceHistoryRequest
|
||||
{
|
||||
Id = Constants.SIGNED_XML_ELEMENT_ID,
|
||||
version = "15.7.0.1",
|
||||
FIASHouseGuid = payload.fiasHouseGuid,
|
||||
Items = [.. items],
|
||||
ItemsElementName = [.. itemsElementName]
|
||||
};
|
||||
|
||||
if (payload.commissioningDateFrom.HasValue)
|
||||
{
|
||||
request.CommissioningDateFrom = payload.commissioningDateFrom.Value;
|
||||
request.CommissioningDateFromSpecified = true;
|
||||
}
|
||||
|
||||
if (payload.сommissioningDateTo.HasValue)
|
||||
{
|
||||
request.CommissioningDateTo = payload.сommissioningDateTo.Value;
|
||||
request.CommissioningDateToSpecified = true;
|
||||
}
|
||||
|
||||
if (payload.serchArchived.HasValue)
|
||||
{
|
||||
request.SerchArchived = payload.serchArchived.Value;
|
||||
request.SerchArchivedSpecified = true;
|
||||
}
|
||||
|
||||
if (payload.archiveDateFrom.HasValue)
|
||||
{
|
||||
request.ArchiveDateFrom = payload.archiveDateFrom.Value;
|
||||
request.ArchiveDateFromSpecified = true;
|
||||
}
|
||||
|
||||
if (payload.archiveDateTo.HasValue)
|
||||
{
|
||||
request.ArchiveDateTo = payload.archiveDateTo.Value;
|
||||
request.ArchiveDateToSpecified = true;
|
||||
}
|
||||
|
||||
if (payload.inputDateFrom.HasValue)
|
||||
{
|
||||
request.inputDateFrom = payload.inputDateFrom.Value;
|
||||
request.inputDateFromSpecified = true;
|
||||
}
|
||||
|
||||
if (payload.inputDateTo.HasValue)
|
||||
{
|
||||
request.inputDateTo = payload.inputDateTo.Value;
|
||||
request.inputDateToSpecified = true;
|
||||
}
|
||||
|
||||
if (payload.excludePersonAsDataSource.HasValue)
|
||||
{
|
||||
request.ExcludePersonAsDataSource = payload.excludePersonAsDataSource.Value;
|
||||
request.ExcludePersonAsDataSourceSpecified = true;
|
||||
}
|
||||
|
||||
if (payload.excludeCurrentOrgAsDataSource.HasValue)
|
||||
{
|
||||
request.ExcludeCurrentOrgAsDataSource = payload.excludeCurrentOrgAsDataSource.Value;
|
||||
request.ExcludeCurrentOrgAsDataSourceSpecified = true;
|
||||
}
|
||||
|
||||
if (payload.excludeOtherOrgAsDataSource.HasValue)
|
||||
{
|
||||
request.ExcludeOtherOrgAsDataSource = payload.excludeOtherOrgAsDataSource.Value;
|
||||
request.ExcludeOtherOrgAsDataSourceSpecified = true;
|
||||
}
|
||||
|
||||
return request;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -70,6 +70,7 @@
|
||||
<Compile Include="Client\Api\NsiApi.cs" />
|
||||
<Compile Include="Client\Api\NsiCommonApi.cs" />
|
||||
<Compile Include="Client\Api\OrgRegistryCommonApi.cs" />
|
||||
<Compile Include="Client\Api\Payload\DeviceMetering\ExportMeteringDeviceHistoryPayload.cs" />
|
||||
<Compile Include="Client\Api\Payload\HouseManagement\ImportAccountDataPayload.cs" />
|
||||
<Compile Include="Client\Api\Payload\HouseManagement\ImportContractDataPayload.cs" />
|
||||
<Compile Include="Client\Api\Payload\HouseManagement\ImportLivingHouseUODataPayload.cs" />
|
||||
@ -78,6 +79,7 @@
|
||||
<Compile Include="Client\Api\Registry\Registry16.cs" />
|
||||
<Compile Include="Client\Api\Registry\Registry239.cs" />
|
||||
<Compile Include="Client\Api\Registry\Registry24.cs" />
|
||||
<Compile Include="Client\Api\Registry\Registry27.cs" />
|
||||
<Compile Include="Client\Api\Registry\Registry276.cs" />
|
||||
<Compile Include="Client\Api\Registry\Registry3.cs" />
|
||||
<Compile Include="Client\Api\Registry\Registry32.cs" />
|
||||
@ -88,6 +90,7 @@
|
||||
<Compile Include="Client\Api\Request\Adapter\IGetStateResultMany.cs" />
|
||||
<Compile Include="Client\Api\Request\Adapter\IGetStateResultOne.cs" />
|
||||
<Compile Include="Client\Api\Request\DeviceMetering\DeviceMeteringRequestBase.cs" />
|
||||
<Compile Include="Client\Api\Request\DeviceMetering\ExportMeteringDeviceHistory.cs" />
|
||||
<Compile Include="Client\Api\Request\DeviceMetering\ImportMeteringDeviceValuesRequest.cs" />
|
||||
<Compile Include="Client\Api\Request\Exception\NoResultsRemoteException.cs" />
|
||||
<Compile Include="Client\Api\Request\GostSigningEndpointBehavior.cs" />
|
||||
|
||||
@ -43,26 +43,20 @@ namespace Hcs.TestApp
|
||||
var orgRegistryCommonScenario = new OrgRegistryCommonScenario(client);
|
||||
try
|
||||
{
|
||||
//deviceMeteringScenario.ExportMeteringDeviceHistory();
|
||||
//deviceMeteringScenario.ImportMeteringDeviceValues();
|
||||
|
||||
//houseManagementScenario.ExportAccount();
|
||||
|
||||
//houseManagementScenario.ExportHouse();
|
||||
|
||||
//houseManagementScenario.ExportAllSupplyResourceContractData();
|
||||
//houseManagementScenario.ExportSupplyResourceContractDataByGuid();
|
||||
//houseManagementScenario.ExportSupplyResourceContractDataByNumber();
|
||||
|
||||
//houseManagementScenario.ExportSupplyResourceContractObjectAddressData();
|
||||
|
||||
//houseManagementScenario.ImportAccountData();
|
||||
|
||||
//houseManagementScenario.ImportContractData();
|
||||
|
||||
//houseManagementScenario.ImportLivingHouseUOData();
|
||||
|
||||
//houseManagementScenario.ImportNotificationData();
|
||||
|
||||
//houseManagementScenario.ImportSupplyResourceContractData();
|
||||
|
||||
//nsiScenario.ExportDataProviderNsiItem1();
|
||||
|
||||
@ -1,7 +1,9 @@
|
||||
using Hcs.Client;
|
||||
using Hcs.Client.Api.Payload.DeviceMetering;
|
||||
using Hcs.Client.Api.Registry;
|
||||
using Hcs.Service.Async.DeviceMetering;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace Hcs.TestApp.Scenario
|
||||
{
|
||||
@ -9,6 +11,16 @@ namespace Hcs.TestApp.Scenario
|
||||
{
|
||||
private readonly UniClient client = client;
|
||||
|
||||
internal void ExportMeteringDeviceHistory()
|
||||
{
|
||||
var result = client.DeviceMetering.ExportMeteringDeviceHistoryAsync(new ExportMeteringDeviceHistoryPayload()
|
||||
{
|
||||
fiasHouseGuid = ["c48e5025-f77a-494f-8aab-f773da623a25"],
|
||||
meteringDeviceType = [Registry27.Element1]
|
||||
}).Result;
|
||||
Console.WriteLine("Scenario execution " + (result != null && result.Count() > 0 ? "succeeded" : "failed"));
|
||||
}
|
||||
|
||||
internal void ImportMeteringDeviceValues()
|
||||
{
|
||||
var values = new importMeteringDeviceValuesRequestMeteringDevicesValues()
|
||||
|
||||
Reference in New Issue
Block a user