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

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