67 lines
3.3 KiB
C#
67 lines
3.3 KiB
C#
using LCU.Library.Internal.IncentiveApiModels.Requests;
|
|
using LCU.Library.Internal.IncentiveApiModels.Results;
|
|
using LCU.Library.Internal.LCUServiceFactory.Configurations;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using LCU.API.Internal.Operations.IncentiveApi.Services.NightlyIncentiveProcesses;
|
|
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
|
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
|
using LCU.API.Internal.Operations.IncentiveApi.Services.AutoDecision;
|
|
|
|
namespace LCU.API.Internal.Operations.IncentiveApi.Services.NightlyDecisionServices;
|
|
|
|
public class AccountActivityDecisionService : NightlyIncentiveProcessesService, INightlyIncentiveProcessesService
|
|
{
|
|
private readonly IServiceScopeFactory _serviceScopeFactory;
|
|
private readonly ProcessResult _processResult;
|
|
|
|
public AccountActivityDecisionService(ServicesFactoryConfiguration servicesFactoryConfiguration,
|
|
IServiceScopeFactory serviceScopeFactory)
|
|
: base(servicesFactoryConfiguration)
|
|
{
|
|
_serviceScopeFactory = serviceScopeFactory;
|
|
_processResult = new ProcessResult();
|
|
}
|
|
|
|
public async Task<ProcessResult> RunProductDecisionProcess(NightlyIncentiveProcessRequest request)
|
|
{
|
|
try
|
|
{
|
|
var result = await UpdateAndDecideActivities();
|
|
var message = $"{result.Count()} activities were updated";
|
|
Log.Information(message);
|
|
_processResult.MessageStack.Add(message);
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
var message = $"There was an issue with the Account Update process. Exception Message: {exception.Message}.";
|
|
_processResult.MessageStack.Add(message);
|
|
_processResult.Success = false;
|
|
}
|
|
return _processResult;
|
|
}
|
|
|
|
public async Task<IReadOnlyCollection<ActivityStateChange>> UpdateAndDecideActivities()
|
|
{
|
|
var listChanges = new List<ActivityStateChange>();
|
|
using var scope = _serviceScopeFactory.CreateScope();
|
|
|
|
var changes = await Task.Run(async () => await scope.ServiceProvider.GetRequiredService<IActivityDecisionService>().DecisionActivityByState(ActivityState.Created));
|
|
Log.Information($"Auto-decisioned {changes.Count} activities in Created state.");
|
|
listChanges.AddRange(changes.ToList());
|
|
|
|
changes = await Task.Run(async () => await scope.ServiceProvider.GetRequiredService<IActivityDecisionService>().DecisionActivityByState(ActivityState.ManualReview));
|
|
Log.Information($"Auto-decisioned {changes.Count} activities in Manual Review state.");
|
|
listChanges.AddRange(changes.ToList());
|
|
|
|
changes = await Task.Run(async () => await scope.ServiceProvider.GetRequiredService<IActivityDecisionService>().UpdateAndDecideManualReviewActivities());
|
|
Log.Information($"Updated and Auto-Decisioned {changes.Count} Activities.");
|
|
listChanges.AddRange(changes.ToList());
|
|
|
|
changes = await Task.Run(async () => await scope.ServiceProvider.GetRequiredService<IActivityDecisionService>().UpdateAndDecideDpEligibleLoanActivities());
|
|
Log.Information($"Updated and Auto-Decisioned {changes.Count} Debt Protection Eligible Loan Activities.");
|
|
listChanges.AddRange(changes.ToList());
|
|
|
|
return listChanges;
|
|
}
|
|
}
|