diff --git a/CaseAccounting/CaseAccountingBusinessLogics/BusinessLogics/ReportProviderLogic.cs b/CaseAccounting/CaseAccountingBusinessLogics/BusinessLogics/ReportProviderLogic.cs index 74cdacf..773ba5d 100644 --- a/CaseAccounting/CaseAccountingBusinessLogics/BusinessLogics/ReportProviderLogic.cs +++ b/CaseAccounting/CaseAccountingBusinessLogics/BusinessLogics/ReportProviderLogic.cs @@ -1,4 +1,5 @@ -using CaseAccountingContracts.BindingModels; +using CaseAccountingBusinessLogic.OfficePackage; +using CaseAccountingContracts.BindingModels; using CaseAccountingContracts.BusinessLogicContracts; using CaseAccountingContracts.SearchModels; using CaseAccountingContracts.StoragesContracts; @@ -17,32 +18,66 @@ namespace CaseAccountingBusinessLogic.BusinessLogics private readonly ISpecializationStorage _specializationStorage; private readonly IHearingStorage _hearingStorage; private readonly ILawyerStorage _lawyerStorage; + private readonly WordBuilderProvider _wordBuilder; + private readonly ExcelBuilderProvider _excelBuilder; + /*private readonly PdfBuilderProvider _pdfBuilder; + private readonly MailSender _mailSender;*/ - public ReportProviderLogic(ICaseStorage caseStorage, ISpecializationStorage specializationStorage, IHearingStorage hearingStorage, ILawyerStorage lawyerStorage) + public ReportProviderLogic(ICaseStorage caseStorage, ISpecializationStorage specializationStorage, IHearingStorage hearingStorage, ILawyerStorage lawyerStorage, WordBuilderProvider wordBuilder, ExcelBuilderProvider excelBuilder) { _caseStorage = caseStorage ?? throw new ArgumentNullException(nameof(caseStorage)); _specializationStorage = specializationStorage ?? throw new ArgumentNullException(nameof(specializationStorage)); _hearingStorage = hearingStorage ?? throw new ArgumentNullException(nameof(hearingStorage)); _lawyerStorage = lawyerStorage ?? throw new ArgumentNullException(nameof(lawyerStorage)); + _wordBuilder = wordBuilder ?? throw new ArgumentNullException(nameof(wordBuilder)); + _excelBuilder = excelBuilder ?? throw new ArgumentNullException(nameof(excelBuilder)); } public List GetCaseSpecialization(List models) { - var сases = new List(); + List list = new(); foreach (var model in models) - сases.Add(_caseStorage.GetElement(new CaseSearchModel { Id = model.Id })); - return сases.Select(x => new ReportCaseSpecializationViewModel { - CaseName = x.Name, - Applicant = x.Applicant, - Defendant = x.Defendant, - Date = x.Date, - Specialization = x.Specialization, - }).ToList(); + { + var specialization = _specializationStorage.GetElement(new SpecializationSearchModel { Id = model.SpecializationId }); + var caseModel = _caseStorage.GetElement(new CaseSearchModel { Id = model.Id }); + if (specialization == null) + { + throw new Exception("Некоректные данные по специализации"); + } + if (caseModel == null) + { + throw new Exception("Некоректные данные по делу"); + } + + bool hasSpec = false; + if (list.Count > 0) + { + foreach (var report in list) + { + if (hasSpec = report.Specialization.Equals(specialization.Name)) + { + report.Cases.Add("Дело #" + caseModel.Id.ToString()); + break; + } + } + } + if (!hasSpec) + { + var newElement = new ReportCaseSpecializationViewModel + { + Specialization = specialization.Name, + Cases = new() + }; + newElement.Cases.Add("Дело #" + caseModel.Id.ToString()); + list.Add(newElement); + } + } + return list; } public List GetHearingLawyer(ReportBindingModel model) { - var hearings = _hearingStorage + /*var hearings = _hearingStorage .GetFilteredList(new HearingSearchModel { UserId = model.UserId}) .Where(x => model.DateFrom <= x.Date && model.DateTo >= x.Date); var list = new List(); @@ -60,25 +95,50 @@ namespace CaseAccountingBusinessLogic.BusinessLogics } list.Add(record); } - return list; + return list;*/ + return new(); } - public void SaveCaseSpecializationToExcelFile(ReportBindingModel model) + public byte[] SaveListFile(CaseSpecializationListBindingModel model) { - throw new NotImplementedException(); - //TODO + byte[] file = Array.Empty(); + + string title = "Список дисциплин по выбранным студентам"; + + if (model.FileType == "docx") + { + _wordBuilder.CreateDocument(); + _wordBuilder.CreateTitle(title); + _wordBuilder.CreateCaseSpecializationTable(GetCaseSpecialization(model.Cases)); + file = _wordBuilder.GetFile(); + } + else if (model.FileType == "xlsx") + { + _excelBuilder.CreateDocument(); + _excelBuilder.CreateTitle(title); + _excelBuilder.CreateCaseSpecializationTable(GetCaseSpecialization(model.Cases)); + file = _excelBuilder.GetFile(); + } + return file; } - public void SaveCaseSpecializationToWordFile(ReportBindingModel model) + /*public void SendByMailStatusReport(ReportBindingModel reportModel) { - throw new NotImplementedException(); - //TODO - } - - public void SaveHearingLawyerToPdfFile(ReportBindingModel model) - { - throw new NotImplementedException(); - //TODO - } + byte[] file = _pdfBuilder.GetEducationStatusReportFile(new() + { + Title = "Отчет по статусам обучения", + DateFrom = reportModel.DateFrom, + DateTo = reportModel.DateTo, + Records = GetStreamStudentEdStatPeriod(reportModel) + }); + _mailSender.SendMailAsync(new() + { + MailAddress = reportModel.UserEmail, + Subject = "Отчет по статусам обучения", + Text = $"За период с {reportModel.DateFrom.ToShortDateString()} " + + $"по {reportModel.DateTo.ToShortDateString()}.", + File = file + }); + }*/ } } diff --git a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/ExcelBuilderCustomer.cs b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/ExcelBuilderCustomer.cs index e29f4a5..0f943f2 100644 --- a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/ExcelBuilderCustomer.cs +++ b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/ExcelBuilderCustomer.cs @@ -291,7 +291,7 @@ namespace CaseAccountingBusinessLogic.OfficePackage }); } - public void CreateLawyersHearingsTable(List data) + /*public void CreateLawyersHearingsTable(List data) { if (worksheet == null || shareStringPart == null) { @@ -357,6 +357,6 @@ namespace CaseAccountingBusinessLogic.OfficePackage currentRow++; } } - } + }*/ } } diff --git a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/ExcelBuilderProvider.cs b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/ExcelBuilderProvider.cs index 1530ab6..e700285 100644 --- a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/ExcelBuilderProvider.cs +++ b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/ExcelBuilderProvider.cs @@ -1,5 +1,7 @@ using CaseAccountingBusinessLogic.OfficePackage; +using CaseAccountingBusinessLogic.OfficePackage.HelperModels; using CaseAccountingContracts.ViewModels; +using ComputersShopBusinessLogic.OfficePackage.HelperModels; using DocumentFormat.OpenXml; using DocumentFormat.OpenXml.Packaging; using DocumentFormat.OpenXml.Spreadsheet; @@ -285,7 +287,7 @@ namespace CaseAccountingBusinessLogic.OfficePackage }); } - public void CreateStudentsDisciplineTable(List data) + public void CreateCaseSpecializationTable(List data) { if (worksheet == null || shareStringPart == null) { @@ -303,25 +305,25 @@ namespace CaseAccountingBusinessLogic.OfficePackage { ColumnName = "A", RowIndex = 2, - Text = "Студент", + Text = "Специализация:", StyleIndex = 2 }); InsertCellInWorksheet(new ExcelCellData { ColumnName = "B", RowIndex = 2, - Text = "Дисциплина", + Text = "Дела:", StyleIndex = 2 }); uint currentRow = 3; - foreach (ReportStudentsDisciplineViewModel student in data) + foreach (ReportCaseSpecializationViewModel specialization in data) { InsertCellInWorksheet(new ExcelCellData { ColumnName = "A", RowIndex = currentRow, - Text = student.Student, + Text = specialization.Specialization, StyleIndex = 1 }); InsertCellInWorksheet(new ExcelCellData @@ -332,7 +334,7 @@ namespace CaseAccountingBusinessLogic.OfficePackage StyleIndex = 1 }); currentRow++; - foreach (string discipline in student.Disciplines) + foreach (string caseName in specialization.Cases) { InsertCellInWorksheet(new ExcelCellData { @@ -345,7 +347,7 @@ namespace CaseAccountingBusinessLogic.OfficePackage { ColumnName = "B", RowIndex = currentRow, - Text = discipline, + Text = caseName, StyleIndex = 1 }); currentRow++; diff --git a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/WordBuilderProvider.cs b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/WordBuilderProvider.cs index bc9633c..0343afc 100644 --- a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/WordBuilderProvider.cs +++ b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/WordBuilderProvider.cs @@ -1,5 +1,5 @@ -using UniversityBusinessLogic.OfficePackage.Models; -using UniversityContracts.ViewModels; +using CaseAccountingBusinessLogic.OfficePackage.HelperModels; +using CaseAccountingContracts.ViewModels; using DocumentFormat.OpenXml; using DocumentFormat.OpenXml.Packaging; using DocumentFormat.OpenXml.Wordprocessing; @@ -141,26 +141,26 @@ namespace CaseAccountingBusinessLogic.OfficePackage return file; } - public void CreateStudentsDisciplineTable(List data) + public void CreateCaseSpecializationTable(List data) { List> rows = new(); - foreach (ReportStudentsDisciplineViewModel student in data) + foreach (ReportCaseSpecializationViewModel specializationl in data) { - List studentCells = new() { student.Student, "" }; - rows.Add(studentCells); - List disciplineCells; - foreach (string discipline in student.Disciplines) + List specializationlCells = new() { specializationl.Specialization, "" }; + rows.Add(specializationlCells); + List caseCells; + foreach (string caseString in specializationl.Cases) { - disciplineCells = new() { "", discipline }; - rows.Add(disciplineCells); + caseCells = new() { "", caseString }; + rows.Add(caseCells); } } WordTableData wordTable = new() { Columns = new List<(string, int)>() { - ("Студент", 3000), - ("Дисциплина", 3000) + ("Специализация", 3000), + ("Дела", 3000) }, Rows = rows }; diff --git a/CaseAccounting/CaseAccountingContracts/BindingModels/CaseSpecializationListBindingModel.cs b/CaseAccounting/CaseAccountingContracts/BindingModels/CaseSpecializationListBindingModel.cs new file mode 100644 index 0000000..23f03b3 --- /dev/null +++ b/CaseAccounting/CaseAccountingContracts/BindingModels/CaseSpecializationListBindingModel.cs @@ -0,0 +1,15 @@ +using CaseAccountingContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CaseAccountingContracts.BindingModels +{ + public class CaseSpecializationListBindingModel + { + public string FileType { get; set; } = string.Empty; + public List Cases { get; set; } = new(); + } +} diff --git a/CaseAccounting/CaseAccountingContracts/BusinessLogicContracts/IReportProviderLogic.cs b/CaseAccounting/CaseAccountingContracts/BusinessLogicContracts/IReportProviderLogic.cs index 678ce92..6e309b7 100644 --- a/CaseAccounting/CaseAccountingContracts/BusinessLogicContracts/IReportProviderLogic.cs +++ b/CaseAccounting/CaseAccountingContracts/BusinessLogicContracts/IReportProviderLogic.cs @@ -14,10 +14,6 @@ namespace CaseAccountingContracts.BusinessLogicContracts List GetHearingLawyer(ReportBindingModel model); - void SaveCaseSpecializationToWordFile(ReportBindingModel model); - - void SaveCaseSpecializationToExcelFile(ReportBindingModel model); - - void SaveHearingLawyerToPdfFile(ReportBindingModel model); + byte[] SaveListFile(CaseSpecializationListBindingModel model); } } diff --git a/CaseAccounting/CaseAccountingContracts/ViewModels/ReportCaseSpecializationViewModel.cs b/CaseAccounting/CaseAccountingContracts/ViewModels/ReportCaseSpecializationViewModel.cs index 78b6a24..7e6e4c5 100644 --- a/CaseAccounting/CaseAccountingContracts/ViewModels/ReportCaseSpecializationViewModel.cs +++ b/CaseAccounting/CaseAccountingContracts/ViewModels/ReportCaseSpecializationViewModel.cs @@ -8,10 +8,7 @@ namespace CaseAccountingContracts.ViewModels { public class ReportCaseSpecializationViewModel { - public string CaseName { get; set; } = string.Empty; - public string Applicant { get; set; } = string.Empty; - public string Defendant { get; set; } = string.Empty; - public DateTime Date { get; set; } public string Specialization { get; set; } = string.Empty; + public List Cases { get; set; } = new(); } } diff --git a/CaseAccounting/CaseAccountingDataBaseImplement/CaseAccountingDatabase.cs b/CaseAccounting/CaseAccountingDataBaseImplement/CaseAccountingDatabase.cs index 55243a9..75477ba 100644 --- a/CaseAccounting/CaseAccountingDataBaseImplement/CaseAccountingDatabase.cs +++ b/CaseAccounting/CaseAccountingDataBaseImplement/CaseAccountingDatabase.cs @@ -18,8 +18,8 @@ namespace CaseAccountingDataBaseImplement Host=localhost; Port=5432; Database=CaseAccountingDatabase; - Username=postgres; - Password=postgres"); + Username=courseuser; + Password=courseuser"); } base.OnConfiguring(optionsBuilder); } diff --git a/CaseAccounting/CaseAccountingProviderView/APIUser.cs b/CaseAccounting/CaseAccountingProviderView/APIUser.cs index b162554..987c8c3 100644 --- a/CaseAccounting/CaseAccountingProviderView/APIUser.cs +++ b/CaseAccounting/CaseAccountingProviderView/APIUser.cs @@ -43,5 +43,25 @@ namespace CaseAccountingProviderView throw new Exception(result); } } - } + + public static O? PostRequestWithResult(string requestUrl, I model) + { + var json = JsonConvert.SerializeObject(model); + var data = new StringContent(json, Encoding.UTF8, "application/json"); + + var response = _user.PostAsync(requestUrl, data); + + var result = response.Result.Content.ReadAsStringAsync().Result; + + if (response.Result.IsSuccessStatusCode) + { + var temp = JsonConvert.DeserializeObject(result); + return temp; + } + else + { + return default; + } + } + } } diff --git a/CaseAccounting/CaseAccountingProviderView/Controllers/HomeController.cs b/CaseAccounting/CaseAccountingProviderView/Controllers/HomeController.cs index 241b445..a699a99 100644 --- a/CaseAccounting/CaseAccountingProviderView/Controllers/HomeController.cs +++ b/CaseAccounting/CaseAccountingProviderView/Controllers/HomeController.cs @@ -35,7 +35,25 @@ namespace CaseAccountingProviderView.Controllers return View(); } - [HttpPost] + public IActionResult SpecializationCaselist() + { + return View(); + } + + [HttpPost] + public int[]? SpecializationCaselist([FromBody] CaseSpecializationListBindingModel listModel) + { + if (APIUser.User == null) + { + return Array.Empty(); + } + byte[]? file = APIUser.PostRequestWithResult + ("api/reportprovider/specializationcaselist", listModel); + return file!.Select(b => (int)b).ToArray(); + } + + + [HttpPost] public void Login(string login, string password) { if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password)) @@ -73,15 +91,8 @@ namespace CaseAccountingProviderView.Controllers { return Redirect("~/Home/Enter"); } - /*if (page == 0) - { - page = 1; - }*/ ViewBag.Cases = APIUser.GetRequest> ($"api/case/getallbyuser?userId={APIUser.User.Id}"); - /*ViewBag.Page = page; - ViewBag.NumberOfPages = APIUser.GetRequest - ($"api/student/getnumberofpages?userId={APIUser.User.Id}");*/ return View(); } diff --git a/CaseAccounting/CaseAccountingProviderView/Views/Home/GetList.cshtml b/CaseAccounting/CaseAccountingProviderView/Views/Home/SpecializationCaselist.cshtml similarity index 61% rename from CaseAccounting/CaseAccountingProviderView/Views/Home/GetList.cshtml rename to CaseAccounting/CaseAccountingProviderView/Views/Home/SpecializationCaselist.cshtml index 8279fe3..2df0d95 100644 --- a/CaseAccounting/CaseAccountingProviderView/Views/Home/GetList.cshtml +++ b/CaseAccounting/CaseAccountingProviderView/Views/Home/SpecializationCaselist.cshtml @@ -10,16 +10,12 @@ - - - - @@ -28,11 +24,12 @@ - - - - - + + + + + + diff --git a/CaseAccounting/CaseAccountingProviderView/Views/Shared/_Layout.cshtml b/CaseAccounting/CaseAccountingProviderView/Views/Shared/_Layout.cshtml index eb9d159..2f647fa 100644 --- a/CaseAccounting/CaseAccountingProviderView/Views/Shared/_Layout.cshtml +++ b/CaseAccounting/CaseAccountingProviderView/Views/Shared/_Layout.cshtml @@ -21,7 +21,7 @@ ДелаДоговораСлушания - Получение список + Получение списокПолучение отчёта diff --git a/CaseAccounting/CaseAccountingProviderView/wwwroot/js/report/reportlist.js b/CaseAccounting/CaseAccountingProviderView/wwwroot/js/report/reportlist.js index e69de29..b5115ef 100644 --- a/CaseAccounting/CaseAccountingProviderView/wwwroot/js/report/reportlist.js +++ b/CaseAccounting/CaseAccountingProviderView/wwwroot/js/report/reportlist.js @@ -0,0 +1,91 @@ +const createBtn = document.getElementById("create-button") +const tbody = document.getElementById("scrollable-table__tbody") +const nameInput = document.getElementById("name-input") +var fileType = document.getElementById("file-type") +var cases = [] +var dataArray = []; +const wordMIME = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; +const excelMIME = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; + +window.addEventListener('load', async () => { + try { + await $.ajax({ + url: `/case/getallbyuser`, + type: "GET", + contentType: "json" + }).done((result) => { + cases = result; + cases.forEach((caseModel) => { + const { id, name, applicant, defendant, annotation, date, specialization } = caseModel; + const row = tbody.insertRow(); + row.setAttribute("data-id", id); + + const cells = [name, applicant, defendant, annotation, date, specialization]; + cells.forEach((value) => { + const cell = row.insertCell(); + cell.textContent = value; + }); + + row.addEventListener('click', () => addAndRemoveFromList(row)); + }); + }); + } catch (error) { + console.error(error); + } +}) + +createBtn.addEventListener('click', () => { + let listModel = { + "Cases": Array.from(dataArray), + "FileType": fileType.value + }; + $.ajax({ + url: "/home/specializationcaselist", + type: "POST", + contentType: "application/json", + data: JSON.stringify(listModel) + }).done((file) => { + let byteArray = new Uint8Array(file); + saveFile(byteArray, fileType); + }); +}) + +const saveFile = async function (bytes, fileType) { + if (window.showSaveFilePicker) { + let type; + if (fileType.value == "docx") { + type = { + description: "Microsoft Word (OpenXML)", + accept: { [wordMIME]: [".docx"] } + }; + } else if (fileType.value == "xlsx") { + type = { + description: "Microsoft Excel (OpenXML)", + accept: { [excelMIME]: [".xlsx"] } + }; + } + + const opts = { + suggestedName: `case-specialization-list.${fileType.value}`, + types: [type], + }; + const handle = await showSaveFilePicker(opts); + const writable = await handle.createWritable(); + await writable.write(bytes); + writable.close(); + } +} + +const addAndRemoveFromList = (row) => { + var id = parseInt(row.dataset.id); + console.log(cases.find(x => x.id === id)) + var index = dataArray.indexOf(cases.find(x => x.id === id)); + if (index === -1) { + dataArray.push(cases.find(x => x.id === id)); + row.classList.add("bg-primary"); + } else { + dataArray.splice(index, 1); + row.classList.remove("bg-primary"); + } + console.log(dataArray); +} diff --git a/CaseAccounting/CaseAccountingRestApi/Controllers/ReportProviderController.cs b/CaseAccounting/CaseAccountingRestApi/Controllers/ReportProviderController.cs new file mode 100644 index 0000000..76d1df6 --- /dev/null +++ b/CaseAccounting/CaseAccountingRestApi/Controllers/ReportProviderController.cs @@ -0,0 +1,25 @@ +using CaseAccountingContracts.BindingModels; +using CaseAccountingContracts.BusinessLogicContracts; +using Microsoft.AspNetCore.Mvc; + +namespace CaseAccountingRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class ReportProviderController : Controller + { + private readonly IReportProviderLogic reportLogic; + + public ReportProviderController(IReportProviderLogic reportLogic) + { + this.reportLogic = reportLogic; + } + + [HttpPost] + public byte[] SpecializationCaselist(CaseSpecializationListBindingModel listModel) + { + byte[] file = reportLogic.SaveListFile(listModel); + return file; + } + } +} diff --git a/CaseAccounting/CaseAccountingRestApi/Program.cs b/CaseAccounting/CaseAccountingRestApi/Program.cs index f0ee39e..6ed555e 100644 --- a/CaseAccounting/CaseAccountingRestApi/Program.cs +++ b/CaseAccounting/CaseAccountingRestApi/Program.cs @@ -1,4 +1,5 @@ using CaseAccountingBusinessLogic.BusinessLogics; +using CaseAccountingBusinessLogic.OfficePackage; using CaseAccountingContracts.BusinessLogicContracts; using CaseAccountingContracts.StoragesContracts; using CaseAccountingDataBaseImplement.Implements; @@ -26,6 +27,11 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); + +builder.Services.AddTransient(); +builder.Services.AddTransient(); + builder.Services.AddControllers().AddNewtonsoftJson(); builder.Services.AddControllers();
ИмяФамилияДата рожденияНомер студ. билетаСтатус обученияНомер дела:Истец:Ответчик:Дата составления:Примечание:Специализация: