2023-05-18 21:57:00 +04:00
|
|
|
|
using UniversityContracts.BindingModels;
|
2023-04-07 17:34:20 +04:00
|
|
|
|
using UniversityContracts.BusinessLogicContracts;
|
|
|
|
|
using UniversityContracts.ViewModels;
|
|
|
|
|
using UniversityContracts.SearchModels;
|
|
|
|
|
using UniversityContracts.StoragesContracts;
|
2023-04-08 20:16:42 +04:00
|
|
|
|
using UniversityBusinessLogic.OfficePackage;
|
2023-05-18 21:57:00 +04:00
|
|
|
|
using System.Reflection.PortableExecutable;
|
|
|
|
|
using DocumentFormat.OpenXml.InkML;
|
|
|
|
|
using DocumentFormat.OpenXml.Wordprocessing;
|
2023-05-19 02:00:18 +04:00
|
|
|
|
using UniversityBusinessLogic.BusinessLogic.OfficePackage;
|
2023-04-07 17:34:20 +04:00
|
|
|
|
|
|
|
|
|
namespace UniversityBusinessLogic.BusinessLogics
|
|
|
|
|
{
|
|
|
|
|
public class ReportProviderLogic : IReportProviderLogic
|
|
|
|
|
{
|
|
|
|
|
private readonly IDocumentStorage _documentStorage;
|
2023-04-08 20:16:42 +04:00
|
|
|
|
private readonly IStudentStorage _studentStorage;
|
|
|
|
|
private readonly IEducationStatusStorage _educationStatusStorage;
|
|
|
|
|
private readonly IEducationGroupStorage _educationGroupStorage;
|
|
|
|
|
private readonly IDisciplineStorage _disciplineStorage;
|
|
|
|
|
private readonly IStreamStorage _streamStorage;
|
2023-05-19 02:00:18 +04:00
|
|
|
|
private readonly WordBuilderProvider _wordBuilder;
|
|
|
|
|
private readonly ExcelBuilderProvider _excelBuilder;
|
|
|
|
|
private readonly PdfBuilderProvider _pdfBuilder;
|
|
|
|
|
private readonly MailSender _mailSender;
|
2023-04-08 20:16:42 +04:00
|
|
|
|
|
|
|
|
|
public ReportProviderLogic(IDocumentStorage documentStorage,
|
|
|
|
|
IStudentStorage studentStorage,
|
|
|
|
|
IEducationStatusStorage educationStatusStorage,
|
|
|
|
|
IEducationGroupStorage educationGroupStorage,
|
|
|
|
|
IDisciplineStorage disciplineStorage,
|
2023-05-18 21:57:00 +04:00
|
|
|
|
IStreamStorage streamStorage,
|
|
|
|
|
WordBuilderProvider wordBuilder,
|
|
|
|
|
ExcelBuilderProvider excelBuilder,
|
2023-05-19 02:00:18 +04:00
|
|
|
|
PdfBuilderProvider pdfBuilder,
|
|
|
|
|
MailSender mailSender)
|
2023-04-08 20:16:42 +04:00
|
|
|
|
{
|
|
|
|
|
_documentStorage = documentStorage;
|
|
|
|
|
_studentStorage = studentStorage;
|
|
|
|
|
_educationStatusStorage = educationStatusStorage;
|
|
|
|
|
_educationGroupStorage = educationGroupStorage;
|
|
|
|
|
_disciplineStorage = disciplineStorage;
|
|
|
|
|
_streamStorage = streamStorage;
|
2023-05-19 02:00:18 +04:00
|
|
|
|
_wordBuilder = wordBuilder;
|
|
|
|
|
_excelBuilder = excelBuilder;
|
|
|
|
|
_pdfBuilder = pdfBuilder;
|
|
|
|
|
_mailSender = mailSender;
|
2023-04-08 20:16:42 +04:00
|
|
|
|
}
|
2023-04-07 17:34:20 +04:00
|
|
|
|
|
2023-04-08 23:59:00 +04:00
|
|
|
|
public List<ReportStudentsDisciplineViewModel> GetStudentsDiscipline(List<StudentViewModel> students)
|
2023-04-07 17:34:20 +04:00
|
|
|
|
{
|
2023-05-18 21:57:00 +04:00
|
|
|
|
var reportRecords = new List<ReportStudentsDisciplineViewModel>();
|
|
|
|
|
foreach (var student in students)
|
|
|
|
|
{
|
|
|
|
|
var disciplines = _studentStorage.GetStudentStreams(new() { Id = student.Id })
|
|
|
|
|
.SelectMany(stream => _streamStorage.GetStreamDisciplines(new() { Id = stream.Id }))
|
|
|
|
|
.Select(discipline => discipline.Name)
|
|
|
|
|
.ToList();
|
|
|
|
|
ReportStudentsDisciplineViewModel reportRecord = new()
|
2023-04-08 20:16:42 +04:00
|
|
|
|
{
|
2023-05-19 02:00:18 +04:00
|
|
|
|
Student = student.Name + " " + student.Surname + ", " + student.StudentCard,
|
2023-05-18 21:57:00 +04:00
|
|
|
|
Disciplines = disciplines
|
|
|
|
|
};
|
|
|
|
|
reportRecords.Add(reportRecord);
|
|
|
|
|
}
|
|
|
|
|
return reportRecords;
|
2023-04-07 17:34:20 +04:00
|
|
|
|
}
|
2023-05-18 21:57:00 +04:00
|
|
|
|
public List<ReportStreamStudentEdStatPeriodViewModel> GetStreamStudentEdStatPeriod(ReportBindingModel model)
|
2023-04-07 17:34:20 +04:00
|
|
|
|
{
|
2023-05-18 21:57:00 +04:00
|
|
|
|
List<ReportStreamStudentEdStatPeriodViewModel> reportRecords = new List<ReportStreamStudentEdStatPeriodViewModel>();
|
2023-04-07 17:34:20 +04:00
|
|
|
|
|
2023-05-19 21:25:56 +04:00
|
|
|
|
var streams = _streamStorage.GetFullList();
|
2023-05-18 21:57:00 +04:00
|
|
|
|
|
|
|
|
|
foreach (var stream in streams)
|
|
|
|
|
{
|
|
|
|
|
ReportStreamStudentEdStatPeriodViewModel reportData = new ReportStreamStudentEdStatPeriodViewModel();
|
|
|
|
|
reportData.StreamName = stream.Name;
|
|
|
|
|
|
2023-05-19 13:11:40 +04:00
|
|
|
|
var students = _streamStorage.GetStreamStudents(new() { Id = stream.Id, DateFrom = model.DateFrom, DateTo = model.DateTo })
|
2023-05-18 21:57:00 +04:00
|
|
|
|
.Select(s => new StudentStatusViewModel()
|
|
|
|
|
{
|
|
|
|
|
StudentName = s.Name + " " + s.Surname,
|
2023-05-19 02:00:18 +04:00
|
|
|
|
DateOfAddmission = s.DateOfAddmission,
|
2023-05-18 21:57:00 +04:00
|
|
|
|
EducationStatus = s.EducationStatusName
|
|
|
|
|
})
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
reportData.StudentStatus = students;
|
|
|
|
|
|
|
|
|
|
reportRecords.Add(reportData);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return reportRecords;
|
2023-04-07 17:34:20 +04:00
|
|
|
|
}
|
|
|
|
|
|
2023-05-18 21:57:00 +04:00
|
|
|
|
public byte[] SaveListFile(StudentDisciplineListBindingModel model)
|
2023-04-07 17:34:20 +04:00
|
|
|
|
{
|
2023-05-18 21:57:00 +04:00
|
|
|
|
byte[] file = Array.Empty<byte>();
|
2023-05-19 02:00:18 +04:00
|
|
|
|
|
|
|
|
|
string title = "Список дисциплин по выбранным студентам";
|
|
|
|
|
|
2023-05-18 21:57:00 +04:00
|
|
|
|
if (model.FileType == "docx")
|
|
|
|
|
{
|
2023-05-19 02:00:18 +04:00
|
|
|
|
_wordBuilder.CreateDocument();
|
|
|
|
|
_wordBuilder.CreateTitle(title);
|
|
|
|
|
_wordBuilder.CreateStudentsDisciplineTable(GetStudentsDiscipline(model.Students));
|
|
|
|
|
file = _wordBuilder.GetFile();
|
2023-05-18 21:57:00 +04:00
|
|
|
|
}
|
|
|
|
|
else if (model.FileType == "xlsx")
|
|
|
|
|
{
|
2023-05-19 02:00:18 +04:00
|
|
|
|
_excelBuilder.CreateDocument();
|
|
|
|
|
_excelBuilder.CreateTitle(title);
|
|
|
|
|
_excelBuilder.CreateStudentsDisciplineTable(GetStudentsDiscipline(model.Students));
|
|
|
|
|
file = _excelBuilder.GetFile();
|
2023-05-18 21:57:00 +04:00
|
|
|
|
}
|
|
|
|
|
return file;
|
2023-04-07 17:34:20 +04:00
|
|
|
|
}
|
|
|
|
|
|
2023-05-19 02:00:18 +04:00
|
|
|
|
public void SendByMailStatusReport(ReportBindingModel reportModel)
|
2023-04-07 17:34:20 +04:00
|
|
|
|
{
|
2023-05-19 02:00:18 +04:00
|
|
|
|
byte[] file = _pdfBuilder.GetEducationStatusReportFile(new()
|
2023-05-18 21:57:00 +04:00
|
|
|
|
{
|
2023-05-19 02:00:18 +04:00
|
|
|
|
Title = "Отчет по статусам обучения",
|
2023-05-18 21:57:00 +04:00
|
|
|
|
DateFrom = reportModel.DateFrom,
|
|
|
|
|
DateTo = reportModel.DateTo,
|
|
|
|
|
Records = GetStreamStudentEdStatPeriod(reportModel)
|
|
|
|
|
});
|
2023-05-19 02:00:18 +04:00
|
|
|
|
_mailSender.SendMailAsync(new ()
|
2023-05-18 21:57:00 +04:00
|
|
|
|
{
|
|
|
|
|
MailAddress = reportModel.UserEmail,
|
2023-05-19 13:11:40 +04:00
|
|
|
|
Subject = "Отчет по статусам обучения",
|
2023-05-18 21:57:00 +04:00
|
|
|
|
Text = $"За период с {reportModel.DateFrom.ToShortDateString()} " +
|
|
|
|
|
$"по {reportModel.DateTo.ToShortDateString()}.",
|
|
|
|
|
File = file
|
2023-05-19 02:00:18 +04:00
|
|
|
|
});
|
2023-04-07 17:34:20 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|