66 lines
2.7 KiB
C#
66 lines
2.7 KiB
C#
using Serilog;
|
|
using LCU.Library.Internal.DataCleanUpModel.Models;
|
|
using LCU.Api.Internal.DataCleanUp.Configuration;
|
|
|
|
namespace LCU.Api.Internal.DataCleanUp.Services;
|
|
|
|
public class UpdateAccountGroupForAnalysisService : IUpdateAccountGroupForAnalysisService
|
|
{
|
|
private readonly ICoreApiWrapperService _coreApiWrapperService;
|
|
private readonly DataCleanupDefaults _dataCleanupDefaults;
|
|
|
|
public UpdateAccountGroupForAnalysisService(ICoreApiWrapperService coreApiWrapperService, DataCleanupDefaults dataCleanupDefaults)
|
|
{
|
|
_coreApiWrapperService = coreApiWrapperService;
|
|
_dataCleanupDefaults = dataCleanupDefaults;
|
|
}
|
|
|
|
public async Task<DataCleanUpResult> CleanUp(DataCleanUpRequest dataCleanUpRequest)
|
|
{
|
|
Log.Information($"Starting Data CleanUp {dataCleanUpRequest.CleanUpType} at {DateTime.Now}");
|
|
var cleanUpResult = new DataCleanUpResult(dataCleanUpRequest, true, new List<string>());
|
|
|
|
try
|
|
{
|
|
var accountNumbers = await _coreApiWrapperService.GetGroupUpdateForAnalysisAccountNumbers();
|
|
ArgumentNullException.ThrowIfNull(accountNumbers);
|
|
Log.Information($"Data CleanUp # of Accounts {accountNumbers.Count()} at {DateTime.Now}");
|
|
foreach (var accountNumber in accountNumbers)
|
|
{
|
|
cleanUpResult = await HandleAccountGroupForAnalysis(cleanUpResult, accountNumber);
|
|
}
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
Log.Error(exception, "Error while updating Account for Group Analysis.");
|
|
cleanUpResult.Successful = false;
|
|
cleanUpResult.ResponseStack.Add($"Error while updating Account for Group Analysis. " +
|
|
$"Exception:{exception}");
|
|
}
|
|
|
|
Log.Information($"Ending Data CleanUp {dataCleanUpRequest.CleanUpType} at {DateTime.Now}");
|
|
return cleanUpResult;
|
|
}
|
|
|
|
public async Task<DataCleanUpResult> HandleAccountGroupForAnalysis(DataCleanUpResult cleanUpResult, string accountNumber)
|
|
{
|
|
try
|
|
{
|
|
var basicResponse = await _coreApiWrapperService.UpdateAccountGroupForAnalysis(accountNumber);
|
|
ArgumentNullException.ThrowIfNull(basicResponse);
|
|
if (!basicResponse.Success)
|
|
{
|
|
cleanUpResult.Successful = false;
|
|
cleanUpResult.ResponseStack.AddRange(basicResponse.Errors);
|
|
}
|
|
}
|
|
catch(Exception exception)
|
|
{
|
|
cleanUpResult.Successful = false;
|
|
cleanUpResult.ResponseStack.Add($"Error while updating Account for Group Analysis. " +
|
|
$"Exception:{exception}");
|
|
}
|
|
|
|
return cleanUpResult;
|
|
}
|
|
} |