Add supply contract export results

This commit is contained in:
2025-11-24 14:56:09 +09:00
parent 46ff771dd6
commit 3ccccd2467
5 changed files with 93 additions and 3 deletions

View File

@ -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.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.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} для парсинга")
}; };
} }
} }

View File

@ -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);
}
}
}

View File

@ -1,4 +1,5 @@
using Hcs.Broker; using Hcs.Broker;
using Hcs.WebApp.BackgroundServices.ResultGetters.HouseManagement;
using Hcs.WebApp.BackgroundServices.ResultGetters.Nsi; using Hcs.WebApp.BackgroundServices.ResultGetters.Nsi;
using Hcs.WebApp.BackgroundServices.ResultGetters.NsiCommon; using Hcs.WebApp.BackgroundServices.ResultGetters.NsiCommon;
using Hcs.WebApp.Data.Hcs; 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.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.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} для получения результата с ГИС ЖКХ") Operation.OperationType.ParseHousesData_15_7_0_1 => throw new ArgumentException($"Нельзя использовать операцию с типом {operation.Type} для получения результата с ГИС ЖКХ")
}; };

View File

@ -196,6 +196,17 @@ namespace Hcs.WebApp.Services
} }
} }
public async Task SetOperationExportGuidAsync(HcsDbContext context, int operationId, string exportGuid)
{
var operation = await context.Operations.FirstOrDefaultAsync(x => x.Id == operationId);
if (operation != null)
{
operation.ExportGuid = exportGuid;
await context.SaveChangesAsync();
}
}
public async Task UpdateCampaignStepAndProgressAsync(Campaign campaign) public async Task UpdateCampaignStepAndProgressAsync(Campaign campaign)
{ {
using var context = GetNewContext(); using var context = GetNewContext();

View File

@ -12,9 +12,8 @@ namespace Hcs.WebApp.Services
return await context.SupplyContracts.ToListAsync(); return await context.SupplyContracts.ToListAsync();
} }
public async Task UpsertSupplyContracts(IEnumerable<SupplyContract> supplyContracts) public async Task UpsertSupplyContracts(HcsDbContext context, IEnumerable<SupplyContract> supplyContracts)
{ {
using var context = GetNewContext();
await context.BulkInsertOrUpdateAsync(supplyContracts, new BulkConfig() await context.BulkInsertOrUpdateAsync(supplyContracts, new BulkConfig()
{ {
PropertiesToExcludeOnUpdate = PropertiesToExcludeOnUpdate =