Add data provider nsi item result wait
This commit is contained in:
@ -9,16 +9,13 @@ namespace Hcs.WebApp.BackgroundServices.OperationExecutors
|
||||
{
|
||||
public IExecutor CreateExecutor(IServiceScope scope, IClient client, Operation operation)
|
||||
{
|
||||
switch (operation.Type)
|
||||
return operation.Type switch
|
||||
{
|
||||
case Operation.OperationType.Nsi_ExportNsiItem_15_7_0_1:
|
||||
return new ExportDataProviderNsiItemExecutor_15_7_0_1(client, scope, operation);
|
||||
Operation.OperationType.Nsi_ExportNsiItem_15_7_0_1 => new ExportDataProviderNsiItemExecutor_15_7_0_1(client, scope, operation),
|
||||
Operation.OperationType.NsiCommon_ExportNsiItem_15_7_0_1 => new ExportNsiItemExecutor_15_7_0_1(client, scope, operation),
|
||||
|
||||
case Operation.OperationType.NsiCommon_ExportNsiItem_15_7_0_1:
|
||||
return new ExportNsiItemExecutor_15_7_0_1(client, scope, operation);
|
||||
}
|
||||
|
||||
throw new NotImplementedException($"Не удалось создать выполнителя операции типа {operation.Type}");
|
||||
_ => throw new NotImplementedException($"Не удалось создать выполнителя операции типа {operation.Type}"),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -26,6 +26,7 @@ namespace Hcs.WebApp.BackgroundServices.OperationExecutors.Nsi
|
||||
272 => exportDataProviderNsiItemRequestRegistryNumber.Item272,
|
||||
302 => exportDataProviderNsiItemRequestRegistryNumber.Item302,
|
||||
337 => exportDataProviderNsiItemRequestRegistryNumber.Item337,
|
||||
|
||||
_ => throw new ArgumentException($"Не удалось получить номер справочника из значения {number}"),
|
||||
};
|
||||
}
|
||||
|
||||
@ -0,0 +1,68 @@
|
||||
using Hcs.Broker;
|
||||
using Hcs.WebApp.Data.Hcs;
|
||||
using Hcs.WebApp.Services;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Hcs.WebApp.BackgroundServices.ResultGetters.Nsi
|
||||
{
|
||||
public class ExportDataProviderNsiItemGetter_15_7_0_1(IClient client, IServiceScope scope, Operation operation) : ResultGetterBase(client, scope, operation)
|
||||
{
|
||||
public override async Task<bool> GetAsync()
|
||||
{
|
||||
var result = await client.Nsi.GetExportDataProviderNsiItemResultAsync(operation.MessageGuid!);
|
||||
if (!result.Ready)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (result.Success)
|
||||
{
|
||||
var headquartersService = scope.ServiceProvider.GetRequiredService<HeadquartersService>();
|
||||
var registryService = scope.ServiceProvider.GetRequiredService<RegistryService>();
|
||||
|
||||
using var context = headquartersService.GetNewContext();
|
||||
var executionStrategy = context.Database.CreateExecutionStrategy();
|
||||
await executionStrategy.ExecuteAsync(async () =>
|
||||
{
|
||||
using var transaction = await context.Database.BeginTransactionAsync();
|
||||
try
|
||||
{
|
||||
var registry = await registryService.GetRegistryByOperationIdAsync(context, operation.Id, true);
|
||||
registry.SyncedAt = DateTime.UtcNow;
|
||||
registry.Elements?.Clear();
|
||||
await context.SaveChangesAsync();
|
||||
|
||||
registry.Elements ??= [];
|
||||
|
||||
foreach (var element in result.Result!.NsiElement)
|
||||
{
|
||||
var registryElement = new RegistryElement()
|
||||
{
|
||||
Code = element.Code,
|
||||
GUID = element.GUID,
|
||||
Json = JsonConvert.SerializeObject(element)
|
||||
};
|
||||
registry.Elements.Add(registryElement);
|
||||
}
|
||||
await context.SaveChangesAsync();
|
||||
|
||||
await headquartersService.SetOperationEndedAsync(context, operation.Id);
|
||||
|
||||
await transaction.CommitAsync();
|
||||
}
|
||||
catch
|
||||
{
|
||||
await transaction.RollbackAsync();
|
||||
|
||||
throw;
|
||||
}
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
throw Failure(result.ErrorMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -30,9 +30,11 @@ namespace Hcs.WebApp.BackgroundServices.ResultGetters.NsiCommon
|
||||
{
|
||||
var registry = await registryService.GetRegistryByOperationIdAsync(context, operation.Id, true);
|
||||
registry.SyncedAt = DateTime.UtcNow;
|
||||
registry.Elements.Clear();
|
||||
registry.Elements?.Clear();
|
||||
await context.SaveChangesAsync();
|
||||
|
||||
registry.Elements ??= [];
|
||||
|
||||
foreach (var element in result.Result!.NsiElement)
|
||||
{
|
||||
var registryElement = new RegistryElement()
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using Hcs.Broker;
|
||||
using Hcs.WebApp.BackgroundServices.ResultGetters.Nsi;
|
||||
using Hcs.WebApp.BackgroundServices.ResultGetters.NsiCommon;
|
||||
using Hcs.WebApp.Data.Hcs;
|
||||
|
||||
@ -8,13 +9,13 @@ namespace Hcs.WebApp.BackgroundServices.ResultGetters
|
||||
{
|
||||
public IResultGetter CreateResultGetter(IServiceScope scope, IClient client, Operation operation)
|
||||
{
|
||||
switch (operation.Type)
|
||||
return operation.Type switch
|
||||
{
|
||||
case Operation.OperationType.NsiCommon_ExportNsiItem_15_7_0_1:
|
||||
return new ExportNsiItemGetter_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),
|
||||
|
||||
throw new NotImplementedException($"Не удалось создать получателя результата операции типа {operation.Type}");
|
||||
_ => throw new NotImplementedException($"Не удалось создать получателя результата операции типа {operation.Type}"),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user