ну да было

This commit is contained in:
Danil 2024-05-01 00:35:00 +04:00
parent d5223d7463
commit 915d989fd2
4 changed files with 188 additions and 0 deletions

View File

@ -0,0 +1,133 @@
using UniversityBusinessLogics.MailWorker;
using UniversityBusinessLogics.OfficePackage;
using UniversityContracts.BindingModels;
using UniversityContracts.BusinessLogicContracts;
using UniversityContracts.StoragesContracts;
namespace UniversityBusinessLogics.BusinessLogics;
public class ReportLogic : IReportLogic
{
private readonly AbstractSaveToWord _saveToWord;
private readonly IDisciplineStorage _disciplineStorage;
private readonly IClientStorage _clientStorage;
private readonly AbstractSaveToExcel _saveToExcel;
private readonly IAccountStorage _accountStorage;
private readonly AbstractMailWorker _mailWorker;
private readonly AbstractSaveToPdf _saveToPdf;
public ReportLogic(AbstractSaveToWord saveToWord, IDisciplineStorage disciplineStorage, AbstractSaveToExcel saveToExcel,
AbstractMailWorker mailWorker, IAccountStorage accountStorage, AbstractSaveToPdf saveToPdf, IClientStorage clientStorage)
{
_mailWorker = mailWorker;
_accountStorage = accountStorage;
_saveToExcel = saveToExcel;
_saveToWord = saveToWord;
_disciplineStorage = disciplineStorage;
_saveToPdf = saveToPdf;
_clientStorage = clientStorage;
}
public void SaveDisciplinesToWord(ReportBindingModel option)
{
_saveToWord.CreateDoc(new()
{
FileName = option.FileName,
Stream = option.Stream,
Title = "Список дисциплин вместе с клиентами",
ReportObjects = _disciplineStorage.GetFilteredList(new() { ClientsIds = option.Ids?.ToList() })
.Select(x => (object)x).ToList(),
});
}
public void SaveDisciplinesToExcel(ReportBindingModel option)
{
var ids = option.Ids?.ToList();
_saveToExcel.CreateReportDisciplines(new()
{
FileName = option.FileName,
Stream = option.Stream,
Ids = ids,
Title = "Список дисциплин вместе с клиентами",
ReportObjects = _disciplineStorage.GetFilteredList(new() { ClientsIds = ids })
.Select(x => (object)x).ToList(),
Headers = new() { "Дисциплина", "Дата создания", "Дата прохождения" }
});
}
public void SendAccountsToEmail(ReportDateRangeBindingModel option, string email)
{
var accounts = _accountStorage.GetFilteredList(new()
{
DateFrom = option.DateFrom,
DateTo = option.DateTo,
});
option.Stream = new MemoryStream();
_saveToPdf.CreateDocForAccounts(new()
{
DateFrom = option.DateFrom,
DateTo = option.DateTo,
Stream = option.Stream,
Title = "Данные по клиентом с накопительными счетами за период",
ReportObjects = accounts.Select(x => (object)x).ToList()
});
_mailWorker.MailSendAsync(new()
{
FilesStreams = new() { new(option.Stream, "report.pdf") },
Subject = $"Отчет по накопительным счетам за {option.DateFrom.ToShortDateString()}-{option.DateTo.ToShortDateString()}",
MailAddress = email,
});
}
public void SaveClientsToWord(ReportBindingModel option)
{
_saveToWord.CreateDoc(new()
{
FileName = option.FileName,
Stream = option.Stream,
Title = "Список клиентов вместе с их дисциплинами",
ReportObjects = _clientStorage.GetFilteredList(new() { DisciplinesIds = option.Ids?.ToList() })
.Select(x => (object)x).ToList(),
});
}
public void SaveClientsToExcel(ReportBindingModel option)
{
_saveToExcel.CreateReportClients(new()
{
FileName = option.FileName,
Stream = option.Stream,
Ids = option.Ids?.ToList(),
Title = "Список клиентов вместе с их дисциплинами",
ReportObjects = _clientStorage.GetFilteredList(new() { DisciplinesIds = option.Ids?.ToList() })
.Select(x => (object)x).ToList(),
Headers = new() { "Клиент", "Дата", "Дисциплина", "Курс" }
});
}
public void SendRequirementsToEmail(ReportDateRangeBindingModel option, string email)
{
var dicscipline = _disciplineStorage.GetFilteredList(new()
{
DateFrom = option.DateFrom,
DateTo = option.DateTo,
});
option.Stream = new MemoryStream();
_saveToPdf.CreateDocForDisciplines(new()
{
DateFrom = option.DateFrom,
DateTo = option.DateTo,
Stream = option.Stream,
Title = "Данные по дисциплинам с требованиями за период",
ReportObjects = dicscipline.Select(x => (object)x).ToList()
});
_mailWorker.MailSendAsync(new()
{
FilesStreams = new() { new(option.Stream, "report.pdf") },
Subject = $"Отчет по требованиям за {option.DateFrom.ToShortDateString()}-{option.DateTo.ToShortDateString()}",
MailAddress = email,
});
}
}

View File

@ -0,0 +1,15 @@
namespace UniversityContracts.BindingModels;
/// <summary>
/// Опции для сохранения отчета, при сохранении указать одно из двух
/// </summary>
public class ReportBindingModel
{
public string? FileName { get; set; }
public Stream? Stream { get; set; }
/// <summary>
/// Массив айдишников по которым происходит выборка
/// </summary>
public int[]? Ids { get; set; }
}

View File

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace UniversityContracts.BindingModels
{
public class ReportDateRangeBindingModel
{
public string? FileName { get; set; }
public Stream? Stream { get; set; }
public DateOnly DateFrom { get; set; }
public DateOnly DateTo { get; set; }
}
}

View File

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UniversityContracts.BindingModels;
namespace UniversityContracts.BusinessLogicContracts
{
public interface IReportLogic
{
void SaveDisciplinesToWord(ReportBindingModel option);
void SaveDisciplinesToExcel(ReportBindingModel option);
void SendAccountsToEmail(ReportDateRangeBindingModel option, string email);
void SaveClientsToWord(ReportBindingModel option);
void SaveClientsToExcel(ReportBindingModel option);
void SendRequirementsToEmail(ReportDateRangeBindingModel option, string email);
}
}