public bool StageDailyReport() { var transactions = _context.Transactions .Where(t => t.timestamp.Date >= DateTime.Today.Date && t.timestamp < DateTime.Today.AddDays(1).Date).ToList(); if (transactions == null || transactions.Count < 1) { return(false); } var timestamp = DateTime.Now; foreach (var channel in _channels) { var channelTransactions = transactions.Where(t => t.channel == channel.id).ToList(); if (channelTransactions == null || channelTransactions.Count < 1) { continue; } var report = new TransactionReport { channelId = channel.id, reportName = GetReportNameFromChannel(channel), dailyCount = channelTransactions.Count(), successCount = channelTransactions.Where(t => t.status == (int)TransactionStatus.Success).Count(), failureCount = channelTransactions.Where(t => t.status == (int)TransactionStatus.Failed).Count(), pendingCount = channelTransactions.Where(t => t.status == (int)TransactionStatus.Pending).Count(), systemFailureCount = channelTransactions .Where(t => t.status == (int)TransactionStatus.Failed && t.description == (int)StatusDescription.SystemError).Count(), userFailureCount = channelTransactions .Where(t => t.status == (int)TransactionStatus.Failed && t.description == (int)StatusDescription.InsufficientFund).Count(), successVolume = channelTransactions.Where(t => t.status == (int)TransactionStatus.Success).Sum(t => t.amount), failureVolume = channelTransactions.Where(t => t.status == (int)TransactionStatus.Failed).Sum(t => t.amount), pendingVolume = channelTransactions.Where(t => t.status == (int)TransactionStatus.Pending).Sum(t => t.amount), systemFailureVolume = channelTransactions .Where(t => t.status == (int)TransactionStatus.Failed && t.description == (int)StatusDescription.SystemError).Sum(t => t.amount), userFailureVolume = channelTransactions .Where(t => t.status == (int)TransactionStatus.Failed && t.description == (int)StatusDescription.InsufficientFund).Sum(t => t.amount), timestamp = timestamp }; report.successRate = Math.Round((decimal)report.successCount / report.dailyCount, 2) * 100; report.failureRate = Math.Round((decimal)report.failureCount / report.dailyCount, 2) * 100; if (report.failureRate > channel.threshold) { var serviceFailureRepo = new ServiceFailureRepository(_context); serviceFailureRepo.AlertServiceOwner(channel, report); } _context.TransactionReports.Add(report); } _context.SaveChanges(); return(true); }
public void CheckServiceStatus() { var reports = new ReportRepository(_context).GetDailyReport(); var channels = new ChannelRepository(_context).GetChannels(); reports.ForEach(report => { var channel = channels[report.channelId]; if (report.failureRate > channel.threshold) { var serviceFailureRepo = new ServiceFailureRepository(_context); serviceFailureRepo.AlertServiceOwner(channel, report); } }); }