From 62ab8d442b59557a732f6301eba57881dba6949d Mon Sep 17 00:00:00 2001 From: DyCTaTOR <125912249+DyCTaTOR@users.noreply.github.com> Date: Wed, 29 May 2024 19:26:11 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=B5=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=D1=8E=D1=89=D0=B0=D1=8F=20=D0=BF=D0=BE=D1=87=D1=82=D0=B0?= =?UTF-8?q?,=20=D0=BD=D0=BE=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D1=8E?= =?UTF-8?q?=D1=89=D0=B5=D0=B5=20=D0=BF=D1=80=D0=B5=D0=B4=D1=81=D1=82=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/ReportLogic.cs | 28 +++++---- .../OfficePackage/AbstractSaveToPdfWorker.cs | 19 +++--- .../HelperModels/PdfInfoWorker.cs | 3 - .../Controllers/HomeController.cs | 34 ++++++++++ .../Home/ReportPlanOfStudyAndStudents.cshtml | 62 +++++++++++++++++++ .../Views/Shared/_Layout.cshtml | 4 ++ .../BusinessLogicsContracts/IReportLogic.cs | 5 +- .../ReportPlanOfStudyAndStudentViewModel.cs | 3 +- .../Controllers/PlanOfStudysController.cs | 27 ++++++++ University/UniversityRestApi/Program.cs | 1 + 10 files changed, 160 insertions(+), 26 deletions(-) create mode 100644 University/UniversityClientAppWorker/Views/Home/ReportPlanOfStudyAndStudents.cshtml diff --git a/University/UniversityBusinessLogic/BusinessLogics/ReportLogic.cs b/University/UniversityBusinessLogic/BusinessLogics/ReportLogic.cs index dfec7e2..e711904 100644 --- a/University/UniversityBusinessLogic/BusinessLogics/ReportLogic.cs +++ b/University/UniversityBusinessLogic/BusinessLogics/ReportLogic.cs @@ -47,7 +47,7 @@ public class ReportLogic : IReportLogic _saveToExcelWorker = saveToExcelWorker; _saveToWordWorker = saveToWordWorker; - // _saveToPdfWorker = saveToPdfWorker; + _saveToPdfWorker = saveToPdfWorker; _saveToWordStorekeeper = saveToWordStorekeeper; _saveToExcelStorekeeper = saveToExcelStorekeeper; @@ -180,7 +180,7 @@ public class ReportLogic : IReportLogic return reportPlanOfStudyViewModels; } - public List GetPlanOfStudyAndStudents(ReportDateRangeBindingModel model) + public List GetPlanOfStudyAndStudents() { var planOfStudies = _planOfStudyStorage.GetFullList(); var reportPlanOfStudyAndStudentViewModels = new List(); @@ -190,24 +190,26 @@ public class ReportLogic : IReportLogic // Получаем список студентов для текущего плана обучения var students = _studentStorage.GetFilteredList(new StudentSearchModel { Id = planOfStudy.Id }); - var studentsAndDisciplines = new List<(string Student, string Discipline)>(); + // Создаем списки имен студентов и дисциплин + var studentNames = students.Select(student => student.Name).ToList(); + var disciplineNames = new List(); foreach (var student in students) { // Получаем список дисциплин для текущего студента var disciplines = _disciplineStorage.GetFilteredList(new DisciplineSearchModel { Id = student.Id }); - foreach (var discipline in disciplines) - { - studentsAndDisciplines.Add((student.Name, discipline.Name)); - } + // Добавляем имена дисциплин в общий список + disciplineNames.AddRange(disciplines.Select(discipline => discipline.Name)); } // Создаем ReportPlanOfStudyAndStudentViewModel и добавляем его в список reportPlanOfStudyAndStudentViewModels.Add(new ReportPlanOfStudyAndStudentViewModel { + Id = planOfStudy.Id, // Добавляем идентификатор плана обучения PlanOfStudyName = planOfStudy.Profile, - StudentsAndDisciplines = studentsAndDisciplines + StudentName = studentNames, + DisciplineName = disciplineNames }); } @@ -258,11 +260,13 @@ public class ReportLogic : IReportLogic throw new NotImplementedException(); } - public void SendPlanOfStudyToEmail(ReportDateRangeBindingModel option, string email) + public void SendPlanOfStudyToEmail(ReportBindingModel option) { - /*_saveToPdfWorker.CreateDoc(new PdfInfoWorker + _saveToPdfWorker.CreateDoc(new PdfInfoWorker { - - });*/ + FileName = option.FileName, + Title = "Отчёт по заказам за период", + PlanOfStudyAndStudent = GetPlanOfStudyAndStudents() + }); } } \ No newline at end of file diff --git a/University/UniversityBusinessLogic/OfficePackage/AbstractSaveToPdfWorker.cs b/University/UniversityBusinessLogic/OfficePackage/AbstractSaveToPdfWorker.cs index 1ad7b83..7e49826 100644 --- a/University/UniversityBusinessLogic/OfficePackage/AbstractSaveToPdfWorker.cs +++ b/University/UniversityBusinessLogic/OfficePackage/AbstractSaveToPdfWorker.cs @@ -9,25 +9,30 @@ namespace UniversityBusinessLogic.OfficePackage { CreatePdf(info); CreateParagraph(new PdfParagraph { Text = info.Title, Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Center }); - CreateParagraph(new PdfParagraph { Text = $"с {info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Center }); CreateTable(new List { "2cm", "3cm", "6cm", "3cm", "4 cm" }); CreateRow(new PdfRowParameters { - Texts = new List { "Номер", "План обучения", "Студент - дисциплина" }, + Texts = new List { "Номер", "План обучения", "Студент", "Дисциплина" }, Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Center }); foreach (var item in info.PlanOfStudyAndStudent) { - CreateRow(new PdfRowParameters + foreach (var studentName in item.StudentName) { - Texts = new List { item.Id.ToString(), item.PlanOfStudyName, string.Join(", ", item.StudentsAndDisciplines.Select(sd => $"{sd.Student} - {sd.Discipline}")) }, - Style = "Normal", - ParagraphAlignment = PdfParagraphAlignmentType.Left - }); + foreach (var disciplineName in item.DisciplineName) + { + CreateRow(new PdfRowParameters + { + Texts = new List { item.Id.ToString(), item.PlanOfStudyName, studentName, disciplineName }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Left + }); + } + } } SavePdf(info); } diff --git a/University/UniversityBusinessLogic/OfficePackage/HelperModels/PdfInfoWorker.cs b/University/UniversityBusinessLogic/OfficePackage/HelperModels/PdfInfoWorker.cs index 393dd1b..99cd615 100644 --- a/University/UniversityBusinessLogic/OfficePackage/HelperModels/PdfInfoWorker.cs +++ b/University/UniversityBusinessLogic/OfficePackage/HelperModels/PdfInfoWorker.cs @@ -6,10 +6,7 @@ namespace UniversityBusinessLogic.OfficePackage.HelperModels { public string? FileName { get; set; } public Stream? Stream { get; set; } - public string Title { get; set; } = string.Empty; - public DateOnly DateFrom { get; set; } - public DateOnly DateTo { get; set; } public List ReportObjects { get; set; } = new(); public List PlanOfStudyAndStudent { get; set; } = new(); } diff --git a/University/UniversityClientAppWorker/Controllers/HomeController.cs b/University/UniversityClientAppWorker/Controllers/HomeController.cs index d1347dd..05e3ff0 100644 --- a/University/UniversityClientAppWorker/Controllers/HomeController.cs +++ b/University/UniversityClientAppWorker/Controllers/HomeController.cs @@ -6,6 +6,7 @@ using UniversityContracts.BindingModels; using UniversityContracts.ViewModels; using UniversityDataModels.Enums; using UniversityDataModels.Models; +using static System.Runtime.InteropServices.JavaScript.JSType; namespace UniversityClientAppWorker.Controllers { @@ -279,5 +280,38 @@ namespace UniversityClientAppWorker.Controllers return; } } + [HttpGet] + public IActionResult ReportPlanOfStudyAndStudents() + { + if (APIClient.User == null) + { + return Redirect("~/Home/Enter"); + } + return View("ReportPlanOfStudyAndStudents", APIClient.GetRequest>($"api/planofstudys/getplanofstudyandstudents")); + } + [HttpPost] + public void ReportPlanOfStudyAndStudents(string type) + { + if (APIClient.User == null) + { + Redirect("~/Home/Enter"); + throw new Exception(" "); + } + if (type == "pdf") + { + APIClient.PostRequest("api/planofstudys/createreporttopdffile", new ReportBindingModel + { + FileName = "C:\\Users\\{Environment.UserName}\\Desktop\\ .pdf" + }); + APIClient.PostRequest("api/order/sendpdftomail", new MailSendInfoBindingModel + { + MailAddress = APIClient.User.Email, + Subject = "", + Text = " " + }); + } + Response.Redirect("Index"); + return; + } } } diff --git a/University/UniversityClientAppWorker/Views/Home/ReportPlanOfStudyAndStudents.cshtml b/University/UniversityClientAppWorker/Views/Home/ReportPlanOfStudyAndStudents.cshtml new file mode 100644 index 0000000..c9225ec --- /dev/null +++ b/University/UniversityClientAppWorker/Views/Home/ReportPlanOfStudyAndStudents.cshtml @@ -0,0 +1,62 @@ +@using UniversityContracts.ViewModels +@model List +@{ + ViewData["Title"] = "Сведения по планам обучения"; +} + +
+

@ViewData["Title"]

+
+ +
+
+
+
+ + + + +
+
+
+
+ + + + + + + + + + + @foreach (var item in Model) + { + + + + + + + } + +
IdПлан обученияСтудентыДисциплины
+ @Html.DisplayFor(modelItem => item.Id) + + @Html.DisplayFor(modelItem => item.PlanOfStudyName) + + @foreach (var student in item.StudentName) + { +
+ @Html.DisplayFor(modelItem => student) +
+ } +
+ @foreach (var discipline in item.DisciplineName) + { +
+ @Html.DisplayFor(modelItem => discipline) +
+ } +
+ \ No newline at end of file diff --git a/University/UniversityClientAppWorker/Views/Shared/_Layout.cshtml b/University/UniversityClientAppWorker/Views/Shared/_Layout.cshtml index e1cc0bb..f728a2d 100644 --- a/University/UniversityClientAppWorker/Views/Shared/_Layout.cshtml +++ b/University/UniversityClientAppWorker/Views/Shared/_Layout.cshtml @@ -41,6 +41,10 @@ Отчёт по планам обучения + diff --git a/University/UniversityContracts/BusinessLogicsContracts/IReportLogic.cs b/University/UniversityContracts/BusinessLogicsContracts/IReportLogic.cs index 66dc224..9be881f 100644 --- a/University/UniversityContracts/BusinessLogicsContracts/IReportLogic.cs +++ b/University/UniversityContracts/BusinessLogicsContracts/IReportLogic.cs @@ -19,14 +19,13 @@ namespace UniversityContracts.BusinessLogicContracts List GetTeachers(int userId); List GetDisciplines(ReportBindingModel model); List GetPlanOfStudyAndDisciplines(int userId); - List GetPlanOfStudyAndStudents(ReportDateRangeBindingModel model); + List GetPlanOfStudyAndStudents(); void SaveTeachersToWord(ReportBindingModel option); void SavePlanOfStudyToWord(ReportBindingModel option); void SaveTeachersToExcel(ReportBindingModel option); void SavePlanOfStudyToExcel(ReportBindingModel option); void SendDisciplinesToEmail(ReportDateRangeBindingModel option, string email); - public void SendPlanOfStudyToEmail(ReportDateRangeBindingModel option, string email); - + public void SendPlanOfStudyToEmail(ReportBindingModel option); } } diff --git a/University/UniversityContracts/ViewModels/ReportPlanOfStudyAndStudentViewModel.cs b/University/UniversityContracts/ViewModels/ReportPlanOfStudyAndStudentViewModel.cs index efe29ca..a044f5d 100644 --- a/University/UniversityContracts/ViewModels/ReportPlanOfStudyAndStudentViewModel.cs +++ b/University/UniversityContracts/ViewModels/ReportPlanOfStudyAndStudentViewModel.cs @@ -10,6 +10,7 @@ namespace UniversityContracts.ViewModels { public int Id { get; set; } public string PlanOfStudyName { get; set; } = string.Empty; - public List<(string Student, string Discipline)> StudentsAndDisciplines { get; set; } = new(); + public List StudentName { get; set; } = new(); + public List DisciplineName { get; set; } = new(); } } diff --git a/University/UniversityRestApi/Controllers/PlanOfStudysController.cs b/University/UniversityRestApi/Controllers/PlanOfStudysController.cs index 6acb154..d420613 100644 --- a/University/UniversityRestApi/Controllers/PlanOfStudysController.cs +++ b/University/UniversityRestApi/Controllers/PlanOfStudysController.cs @@ -63,6 +63,20 @@ namespace UniversityRestApi.Controllers throw; } } + [HttpGet] + public List? GetPlanOfStudyAndStudents() + { + try + { + var report = _reportLogic.GetPlanOfStudyAndStudents(); + return report; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка планов обучения"); + throw; + } + } [HttpPost] public void LoadReportToWord(ReportBindingModel model) { @@ -90,6 +104,19 @@ namespace UniversityRestApi.Controllers } } [HttpPost] + public void CreateReportToPDFFile(ReportBindingModel model) + { + try + { + _reportLogic.SendPlanOfStudyToEmail(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания отчета"); + throw; + } + } + [HttpPost] public void SendPDFToMail(MailSendInfoBindingModel model) { try diff --git a/University/UniversityRestApi/Program.cs b/University/UniversityRestApi/Program.cs index 170cfaa..72184a7 100644 --- a/University/UniversityRestApi/Program.cs +++ b/University/UniversityRestApi/Program.cs @@ -39,6 +39,7 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddSingleton(); builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer();