예제 #1
0
        public async Task GenerateOverallReport(MessageContext context, AggregateOverallReportDataEvent inputEvent)
        {
            var filters = new Filters {
                TimestampFrom = inputEvent.TimestampFrom, TimestampTo = inputEvent.TimestampTo
            };
            var transactions = transactionsRepository.GetMany(inputEvent.Subject, new Filters {
                TimestampFrom = inputEvent.TimestampFrom, TimestampTo = inputEvent.TimestampTo
            });

            if (inputEvent.Subject == ReportSubject.Loans)
            {
                var accountsIds = transactions.Select(t => t.Sender).ToArray();
                var loans       = await reportsDataFetcher.GetLoans(context.FlowId + "_l", accountsIds);

                var loansPayments = loans.Select(l => l.PaymentId).ToHashSet();
                transactions = transactions.Where(t => loansPayments.Contains(t.PaymentId)).ToArray();
            }

            var data = new OverallReportData
            {
                From         = inputEvent.TimestampFrom,
                To           = inputEvent.TimestampTo,
                Granularity  = inputEvent.Granularity,
                Subject      = inputEvent.Subject,
                Aggregations = inputEvent.Aggregations,
                Transactions = transactions
            };

            var portions = ReportGenerator.AggregateOverall(data);

            publishingRouter.Publish(context.ReplyTo, new AggregatedOverallReportEvent
            {
                Portions = portions.ToArray()
            }, context.FlowId);
        }