public override async Task GenerateReport(IReportServiceContext reportServiceContext, ZipArchive archive, CancellationToken cancellationToken) { var externalFileName = GetFilename(reportServiceContext); var fileName = GetZipFilename(reportServiceContext); var appsCoInvestmentIlrInfo = await _ilrPeriodEndProviderService.GetILRInfoForAppsCoInvestmentReportAsync(reportServiceContext.Ukprn, cancellationToken); var appsCoInvestmentRulebaseInfo = await _fm36PeriodEndProviderService.GetFM36DataForAppsCoInvestmentReportAsync(reportServiceContext.Ukprn, cancellationToken); var appsCoInvestmentPaymentsInfo = await _dasPaymentsProviderService.GetPaymentsInfoForAppsCoInvestmentReportAsync(reportServiceContext.Ukprn, cancellationToken); var paymentsAppsCoInvestmentUniqueKeys = await _dasPaymentsProviderService.GetUniqueCombinationsOfKeyFromPaymentsAsync(reportServiceContext.Ukprn, cancellationToken); var ilrAppsCoInvestmentUniqueKeys = await _ilrPeriodEndProviderService.GetUniqueAppsCoInvestmentRecordKeysAsync(reportServiceContext.Ukprn, cancellationToken); var apprenticeshipIds = appsCoInvestmentPaymentsInfo.Payments.Select(p => p.ApprenticeshipId); var apprenticeshipIdLegalEntityNameDictionary = await _dasPaymentsProviderService.GetLegalEntityNameApprenticeshipIdDictionaryAsync(apprenticeshipIds, cancellationToken); var appsCoInvestmentContributionsModels = _modelBuilder.BuildModel(appsCoInvestmentIlrInfo, appsCoInvestmentRulebaseInfo, appsCoInvestmentPaymentsInfo, paymentsAppsCoInvestmentUniqueKeys, ilrAppsCoInvestmentUniqueKeys, apprenticeshipIdLegalEntityNameDictionary, reportServiceContext.JobId, reportServiceContext.Ukprn).ToList(); string csv = await GetCsv(appsCoInvestmentContributionsModels, cancellationToken); await _streamableKeyValuePersistenceService.SaveAsync($"{externalFileName}.csv", csv, cancellationToken); await WriteZipEntry(archive, $"{fileName}.csv", csv); if (reportServiceContext.DataPersistFeatureEnabled) { Stopwatch stopWatchLog = new Stopwatch(); stopWatchLog.Start(); await _persistReportData.PersistReportDataAsync( appsCoInvestmentContributionsModels, reportServiceContext.Ukprn, reportServiceContext.ReturnPeriod, TableNameConstants.AppsCoInvestmentContributions, reportServiceContext.ReportDataConnectionString, cancellationToken); _logger.LogDebug($"Performance-AppsCoInvestmentContributionsReport logging took - {stopWatchLog.ElapsedMilliseconds} ms "); stopWatchLog.Stop(); } else { _logger.LogDebug(" Data Persist Feature is disabled."); } }
public override async Task GenerateReport( IReportServiceContext reportServiceContext, ZipArchive archive, CancellationToken cancellationToken) { DateTime dateTime = _dateTimeProvider.ConvertUtcToUk(reportServiceContext.SubmissionDateTimeUtc); var externalFileName = GetCustomFilename(reportServiceContext, $"{dateTime:yyyyMMdd-HHmmss}"); var summaryFileName = GetCustomFilename(reportServiceContext, "Summary"); var fileName = GetCustomFilename(reportServiceContext, "Download"); // get the main base DAS payments data var appsMonthlyPaymentDasInfo = await _dasPaymentsProviderService.GetPaymentsInfoForAppsMonthlyPaymentReportAsync( reportServiceContext.Ukprn, cancellationToken); // get the ILR data var appsMonthlyPaymentIlrInfo = await _ilrPeriodEndProviderService.GetILRInfoForAppsMonthlyPaymentReportAsync( reportServiceContext.Ukprn, cancellationToken); // Get the earning data var learnerLevelViewFM36Info = await _fm36ProviderService.GetFM36DataForLearnerLevelView( reportServiceContext.Ukprn, cancellationToken); // Get the employer investment info var appsCoInvestmentIlrInfo = await _ilrPeriodEndProviderService.GetILRInfoForAppsCoInvestmentReportAsync( reportServiceContext.Ukprn, cancellationToken); // Get the datalock information var learnerLevelDatalockInfo = await _dasPaymentsProviderService.GetDASDataLockInfoAsync( reportServiceContext.Ukprn, cancellationToken); // Get the HBCP information var learnerLevelHBCPInfo = await _dasPaymentsProviderService.GetHBCPInfoAsync( reportServiceContext.Ukprn, cancellationToken); var paymentsDictionary = BuildPaymentInfoDictionary(appsMonthlyPaymentDasInfo); var aECPriceEpisodeDictionary = BuildAECPriceEpisodeDictionary(learnerLevelViewFM36Info?.AECApprenticeshipPriceEpisodePeriodisedValues); var aECLearningDeliveryDictionary = BuildAECLearningDeliveryDictionary(learnerLevelViewFM36Info?.AECLearningDeliveryPeriodisedValuesInfo); // Get the employer name information var apprenticeshipIds = appsMonthlyPaymentDasInfo.Payments.Select(p => p.ApprenticeshipId); var apprenticeshipIdLegalEntityNameDictionary = await _dasPaymentsProviderService.GetLegalEntityNameApprenticeshipIdDictionaryAsync(apprenticeshipIds, cancellationToken); // Build the Learner level view Report var learnerLevelViewModel = _modelBuilder.BuildLearnerLevelViewModelList( reportServiceContext.Ukprn, appsMonthlyPaymentIlrInfo, appsCoInvestmentIlrInfo, learnerLevelDatalockInfo, learnerLevelHBCPInfo, learnerLevelViewFM36Info, paymentsDictionary, aECPriceEpisodeDictionary, aECLearningDeliveryDictionary, apprenticeshipIdLegalEntityNameDictionary, reportServiceContext.ReturnPeriod).ToList(); // Write the full file containing calculated data string learnerLevelViewCSV = await GetLearnerLevelViewCsv(learnerLevelViewModel, cancellationToken); await WriteAsync($"{externalFileName}.csv", learnerLevelViewCSV, reportServiceContext.Container, cancellationToken); // Write the abridged report file downloadable by the user string learnerLevelFinancialsRemovedCSV = await GetLearnerLevelFinancialsRemovedViewCsv(learnerLevelViewModel, cancellationToken); await WriteAsync($"{fileName}.csv", learnerLevelFinancialsRemovedCSV, reportServiceContext.Container, cancellationToken); // Create the summary file which will be used by the WebUI to display the summary view string summaryFile = CreateSummary(learnerLevelViewModel, cancellationToken); await WriteAsync($"{summaryFileName}.json", summaryFile, reportServiceContext.Container, cancellationToken); if (reportServiceContext.DataPersistFeatureEnabled) { Stopwatch stopWatchLog = new Stopwatch(); stopWatchLog.Start(); await _persistReportData.PersistReportDataAsync( learnerLevelViewModel, reportServiceContext.Ukprn, reportServiceContext.ReturnPeriod, TableNameConstants.LearnerLevelViewReport, reportServiceContext.ReportDataConnectionString, cancellationToken); _logger.LogDebug($"Performance-Learner Level View Report logging took - {stopWatchLog.ElapsedMilliseconds} ms "); stopWatchLog.Stop(); } else { _logger.LogDebug(" Data Persist Feature is disabled."); } }