Add supply contract export results
This commit is contained in:
@ -11,7 +11,8 @@ namespace Hcs.WebApp.BackgroundServices.DataParsers
|
||||
Operation.OperationType.ParseHousesData_15_7_0_1 => new HousesDataParser_15_7_0_1(scope, operation, webHostEnvironment),
|
||||
|
||||
Operation.OperationType.NsiCommon_ExportNsiItem_15_7_0_1 or
|
||||
Operation.OperationType.Nsi_ExportNsiItem_15_7_0_1 => throw new ArgumentException($"Нельзя использовать операцию с типом {operation.Type} для парсинга")
|
||||
Operation.OperationType.Nsi_ExportNsiItem_15_7_0_1 or
|
||||
Operation.OperationType.HouseManagement_ExportSupplyResourceContractData_15_7_0_1 => throw new ArgumentException($"Нельзя использовать операцию с типом {operation.Type} для парсинга")
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,77 @@
|
||||
using Hcs.Broker;
|
||||
using Hcs.WebApp.Data.Hcs;
|
||||
using Hcs.WebApp.Services;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Hcs.WebApp.BackgroundServices.ResultGetters.HouseManagement
|
||||
{
|
||||
public class ExportSupplyResourceContractDataGetter_15_7_0_1(IClient client, IServiceScope scope, Operation operation) : ResultGetterBase(client, scope, operation)
|
||||
{
|
||||
public override async Task<ResultGetterResponse> GetAsync()
|
||||
{
|
||||
var result = await client.HouseManagement.GetExportSupplyResourceContractDataResultAsync(operation.MessageGuid!);
|
||||
if (!result.Ready)
|
||||
{
|
||||
return new ResultGetterResponse()
|
||||
{
|
||||
success = false
|
||||
};
|
||||
}
|
||||
|
||||
if (result.Success)
|
||||
{
|
||||
DateTime endedAt = default;
|
||||
|
||||
var headquartersService = scope.ServiceProvider.GetRequiredService<HeadquartersService>();
|
||||
var supplyContractService = scope.ServiceProvider.GetRequiredService<SupplyContractService>();
|
||||
|
||||
using var context = headquartersService.GetNewContext();
|
||||
var executionStrategy = context.Database.CreateExecutionStrategy();
|
||||
await executionStrategy.ExecuteAsync(async () =>
|
||||
{
|
||||
using var transaction = await context.Database.BeginTransactionAsync();
|
||||
try
|
||||
{
|
||||
var contracts = new List<SupplyContract>();
|
||||
foreach (var entry in result.Results)
|
||||
{
|
||||
contracts.Add(new SupplyContract()
|
||||
{
|
||||
HcsId = Guid.Parse(entry.ContractGUID),
|
||||
SyncedAt = DateTime.UtcNow,
|
||||
LastSyncOperationId = operation.Id
|
||||
});
|
||||
}
|
||||
|
||||
await supplyContractService.UpsertSupplyContracts(context, contracts);
|
||||
|
||||
endedAt = DateTime.UtcNow;
|
||||
await headquartersService.SetOperationEndedAsync(context, operation.Id, endedAt);
|
||||
|
||||
if (!string.IsNullOrEmpty(result.NextResultsGuid))
|
||||
{
|
||||
var operations = await headquartersService.InitiateOperationsAsync(context, 1, operation.CampaignId, Operation.OperationType.HouseManagement_ExportSupplyResourceContractData_15_7_0_1);
|
||||
await headquartersService.SetOperationExportGuidAsync(context, operations.First().Id, result.NextResultsGuid);
|
||||
}
|
||||
|
||||
await transaction.CommitAsync();
|
||||
}
|
||||
catch
|
||||
{
|
||||
await transaction.RollbackAsync();
|
||||
|
||||
throw;
|
||||
}
|
||||
});
|
||||
|
||||
return new ResultGetterResponse()
|
||||
{
|
||||
success = true,
|
||||
endedAt = endedAt
|
||||
};
|
||||
}
|
||||
|
||||
throw Failure(result.ErrorMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,5 @@
|
||||
using Hcs.Broker;
|
||||
using Hcs.WebApp.BackgroundServices.ResultGetters.HouseManagement;
|
||||
using Hcs.WebApp.BackgroundServices.ResultGetters.Nsi;
|
||||
using Hcs.WebApp.BackgroundServices.ResultGetters.NsiCommon;
|
||||
using Hcs.WebApp.Data.Hcs;
|
||||
@ -13,6 +14,7 @@ namespace Hcs.WebApp.BackgroundServices.ResultGetters
|
||||
{
|
||||
Operation.OperationType.Nsi_ExportNsiItem_15_7_0_1 => new ExportDataProviderNsiItemGetter_15_7_0_1(client, scope, operation),
|
||||
Operation.OperationType.NsiCommon_ExportNsiItem_15_7_0_1 => new ExportNsiItemGetter_15_7_0_1(client, scope, operation),
|
||||
Operation.OperationType.HouseManagement_ExportSupplyResourceContractData_15_7_0_1 => new ExportSupplyResourceContractDataGetter_15_7_0_1(client, scope, operation),
|
||||
|
||||
Operation.OperationType.ParseHousesData_15_7_0_1 => throw new ArgumentException($"Нельзя использовать операцию с типом {operation.Type} для получения результата с ГИС ЖКХ")
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user