Add refactored new supply contract import
This commit is contained in:
@ -0,0 +1,214 @@
|
||||
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 ImportSupplyResourceContractDataRequest(ClientBase client) : HouseManagementRequestBase(client)
|
||||
{
|
||||
protected override bool CanBeRestarted => false;
|
||||
|
||||
internal async Task<getStateResultImportResultCommonResultImportSupplyResourceContract> ExecuteAsync(ImportSupplyResourceContractDataPayload payload, CancellationToken token)
|
||||
{
|
||||
var contract = new importSupplyResourceContractRequestContract
|
||||
{
|
||||
TransportGUID = Guid.NewGuid().ToString(),
|
||||
Item1 = GetContractFromPayload(payload)
|
||||
};
|
||||
|
||||
// http://open-gkh.ru/HouseManagement/importSupplyResourceContractRequest.html
|
||||
var request = new importSupplyResourceContractRequest
|
||||
{
|
||||
Id = Constants.SIGNED_XML_ELEMENT_ID,
|
||||
version = "11.3.0.5",
|
||||
Contract = [contract]
|
||||
};
|
||||
|
||||
var result = await SendAndWaitResultAsync(request, async asyncClient =>
|
||||
{
|
||||
var response = await asyncClient.importSupplyResourceContractDataAsync(CreateRequestHeader(), request);
|
||||
return response.AckRequest.Ack;
|
||||
}, token);
|
||||
|
||||
result.Items.OfType<ErrorMessageType>().ToList().ForEach(error =>
|
||||
{
|
||||
throw RemoteException.CreateNew(error.ErrorCode, error.Description);
|
||||
});
|
||||
|
||||
var importResults = result.Items.OfType<getStateResultImportResult>();
|
||||
var commonResults = GetCommonResults(importResults);
|
||||
foreach (var commonResult in commonResults)
|
||||
{
|
||||
if (commonResult.ItemElementName == ItemChoiceType26.ImportSupplyResourceContract)
|
||||
{
|
||||
if (commonResult.Item is getStateResultImportResultCommonResultImportSupplyResourceContract importedContract)
|
||||
{
|
||||
return importedContract;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private SupplyResourceContractType GetContractFromPayload(ImportSupplyResourceContractDataPayload payload)
|
||||
{
|
||||
var contract = new SupplyResourceContractType();
|
||||
|
||||
if (payload.isContract)
|
||||
{
|
||||
var isContract = new SupplyResourceContractTypeIsContract()
|
||||
{
|
||||
ContractNumber = payload.contractNumber,
|
||||
SigningDate = payload.signingDate,
|
||||
EffectiveDate = payload.effectiveDate
|
||||
};
|
||||
contract.Item = isContract;
|
||||
}
|
||||
else
|
||||
{
|
||||
var isNotContract = new SupplyResourceContractTypeIsNotContract()
|
||||
{
|
||||
ContractNumber = payload.contractNumber,
|
||||
SigningDate = payload.signingDate,
|
||||
EffectiveDate = payload.effectiveDate
|
||||
};
|
||||
contract.Item = isNotContract;
|
||||
}
|
||||
|
||||
var items = new List<object>();
|
||||
var itemsElementName = new List<ItemsChoiceType9>();
|
||||
if (payload.indefiniteTerm.HasValue)
|
||||
{
|
||||
items.Add(payload.indefiniteTerm.Value);
|
||||
itemsElementName.Add(ItemsChoiceType9.IndefiniteTerm);
|
||||
}
|
||||
if (payload.automaticRollOverOneYear.HasValue)
|
||||
{
|
||||
items.Add(payload.automaticRollOverOneYear.Value);
|
||||
itemsElementName.Add(ItemsChoiceType9.AutomaticRollOverOneYear);
|
||||
|
||||
if (!payload.comptetionDate.HasValue)
|
||||
{
|
||||
throw new InvalidOperationException("comptetionDate is empty");
|
||||
}
|
||||
|
||||
items.Add(payload.comptetionDate.Value);
|
||||
itemsElementName.Add(ItemsChoiceType9.ComptetionDate);
|
||||
}
|
||||
if (items.Count > 0 && itemsElementName.Count > 0)
|
||||
{
|
||||
contract.Items = [.. items];
|
||||
contract.ItemsElementName = [.. itemsElementName];
|
||||
}
|
||||
|
||||
if (payload.period != null)
|
||||
{
|
||||
contract.Period = payload.period;
|
||||
}
|
||||
|
||||
if (payload.indicationsAnyDay.HasValue)
|
||||
{
|
||||
contract.IndicationsAnyDay = payload.indicationsAnyDay.Value;
|
||||
contract.IndicationsAnyDaySpecified = true;
|
||||
}
|
||||
|
||||
if (payload.contractBase != null && payload.contractBase.Length > 0)
|
||||
{
|
||||
contract.ContractBase = payload.contractBase;
|
||||
}
|
||||
|
||||
contract.Item1 = payload.counterparty;
|
||||
contract.IsPlannedVolume = payload.isPlannedVolume;
|
||||
|
||||
if (payload.plannedVolumeType.HasValue)
|
||||
{
|
||||
contract.PlannedVolumeType = payload.plannedVolumeType.Value;
|
||||
contract.PlannedVolumeTypeSpecified = true;
|
||||
}
|
||||
|
||||
contract.ContractSubject = payload.contractSubject;
|
||||
|
||||
if (payload.countingResource.HasValue)
|
||||
{
|
||||
contract.CountingResource = payload.countingResource.Value;
|
||||
contract.CountingResourceSpecified = true;
|
||||
}
|
||||
|
||||
contract.SpecifyingQualityIndicators = payload.specifyingQualityIndicators;
|
||||
|
||||
if (payload.noConnectionToWaterSupply.HasValue)
|
||||
{
|
||||
contract.NoConnectionToWaterSupply = payload.noConnectionToWaterSupply.Value;
|
||||
contract.NoConnectionToWaterSupplySpecified = true;
|
||||
}
|
||||
|
||||
contract.ObjectAddress = payload.objectAddress;
|
||||
contract.Quality = payload.quality;
|
||||
contract.OtherQualityIndicator = payload.otherQualityIndicator;
|
||||
contract.TemperatureChart = payload.temperatureChart;
|
||||
contract.BillingDate = payload.billingDate;
|
||||
contract.PaymentDate = payload.paymentDate;
|
||||
contract.ProvidingInformationDate = payload.providingInformationDate;
|
||||
|
||||
if (payload.meteringDeviceInformation.HasValue)
|
||||
{
|
||||
contract.MeteringDeviceInformation = payload.meteringDeviceInformation.Value;
|
||||
contract.MeteringDeviceInformationSpecified = true;
|
||||
}
|
||||
|
||||
if (payload.volumeDepends.HasValue)
|
||||
{
|
||||
contract.VolumeDepends = payload.volumeDepends.Value;
|
||||
contract.VolumeDependsSpecified = true;
|
||||
}
|
||||
|
||||
if (payload.oneTimePayment.HasValue)
|
||||
{
|
||||
contract.OneTimePayment = payload.oneTimePayment.Value;
|
||||
contract.OneTimePaymentSpecified = true;
|
||||
}
|
||||
|
||||
if (payload.accrualProcedure.HasValue)
|
||||
{
|
||||
contract.AccrualProcedure = payload.accrualProcedure.Value;
|
||||
contract.AccrualProcedureSpecified = true;
|
||||
}
|
||||
|
||||
contract.Tariff = payload.tariff;
|
||||
contract.Norm = payload.norm;
|
||||
|
||||
return contract;
|
||||
}
|
||||
|
||||
private getStateResultImportResultCommonResult[] GetCommonResults(IEnumerable<getStateResultImportResult> importResults)
|
||||
{
|
||||
var result = new List<getStateResultImportResultCommonResult>();
|
||||
foreach (var importResult in importResults)
|
||||
{
|
||||
importResult.Items.OfType<ErrorMessageType>().ToList().ForEach(error =>
|
||||
{
|
||||
throw RemoteException.CreateNew(error.ErrorCode, error.Description);
|
||||
});
|
||||
|
||||
var commonResults = importResult.Items.OfType<getStateResultImportResultCommonResult>();
|
||||
foreach (var commonResult in commonResults)
|
||||
{
|
||||
commonResult.Items.OfType<CommonResultTypeError>().ToList().ForEach(error =>
|
||||
{
|
||||
throw RemoteException.CreateNew(error.ErrorCode, error.Description);
|
||||
});
|
||||
}
|
||||
|
||||
result.AddRange(commonResults);
|
||||
}
|
||||
return [.. result];
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user